PageRenderTime 77ms CodeModel.GetById 3ms app.highlight 62ms RepoModel.GetById 1ms app.codeStats 1ms

/zabbix-2.0.1/frontends/php/popup.php

#
PHP | 2044 lines | 1702 code | 223 blank | 119 comment | 228 complexity | ca305a6257d1ff2298a7c87b77aaa51b MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2/*
   3** Zabbix
   4** Copyright (C) 2000-2012 Zabbix SIA
   5**
   6** This program is free software; you can redistribute it and/or modify
   7** it under the terms of the GNU General Public License as published by
   8** the Free Software Foundation; either version 2 of the License, or
   9** (at your option) any later version.
  10**
  11** This program is distributed in the hope that it will be useful,
  12** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14** GNU General Public License for more details.
  15**
  16** You should have received a copy of the GNU General Public License
  17** along with this program; if not, write to the Free Software
  18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  19**/
  20
  21
  22require_once dirname(__FILE__).'/include/config.inc.php';
  23require_once dirname(__FILE__).'/include/hosts.inc.php';
  24require_once dirname(__FILE__).'/include/triggers.inc.php';
  25require_once dirname(__FILE__).'/include/items.inc.php';
  26require_once dirname(__FILE__).'/include/users.inc.php';
  27require_once dirname(__FILE__).'/include/nodes.inc.php';
  28require_once dirname(__FILE__).'/include/js.inc.php';
  29require_once dirname(__FILE__).'/include/discovery.inc.php';
  30
  31$srctbl = get_request('srctbl', ''); // source table name
  32
  33// set page title
  34switch ($srctbl) {
  35	case 'host_templates':
  36	case 'templates':
  37		$page['title'] = _('Templates');
  38		$min_user_type = USER_TYPE_ZABBIX_ADMIN;
  39		break;
  40	case 'hosts_and_templates':
  41		$page['title'] = _('Hosts and templates');
  42		$min_user_type = USER_TYPE_ZABBIX_ADMIN;
  43		break;
  44	case 'hosts':
  45		$page['title'] = _('Hosts');
  46		$min_user_type = USER_TYPE_ZABBIX_ADMIN;
  47		break;
  48	case 'proxies':
  49		$page['title'] = _('Proxies');
  50		$min_user_type = USER_TYPE_ZABBIX_ADMIN;
  51		break;
  52	case 'applications':
  53		$page['title'] = _('Applications');
  54		$min_user_type = USER_TYPE_ZABBIX_USER;
  55		break;
  56	case 'host_group':
  57		$page['title'] = _('Host groups');
  58		$min_user_type = USER_TYPE_ZABBIX_USER;
  59		break;
  60	case 'triggers':
  61		$page['title'] = _('Triggers');
  62		$min_user_type = USER_TYPE_ZABBIX_USER;
  63		break;
  64	case 'usrgrp':
  65		$page['title'] = _('User groups');
  66		$min_user_type = USER_TYPE_ZABBIX_ADMIN;
  67		break;
  68	case 'users':
  69		$page['title'] = _('Users');
  70		$min_user_type = USER_TYPE_ZABBIX_ADMIN;
  71		break;
  72	case 'items':
  73		$page['title'] = _('Items');
  74		$min_user_type = USER_TYPE_ZABBIX_USER;
  75		break;
  76	case 'prototypes':
  77		$page['title'] = _('Prototypes');
  78		$min_user_type = USER_TYPE_ZABBIX_ADMIN;
  79		break;
  80	case 'help_items':
  81		$page['title'] = _('Standard items');
  82		$min_user_type = USER_TYPE_ZABBIX_USER;
  83		break;
  84	case 'screens':
  85		$page['title'] = _('Screens');
  86		$min_user_type = USER_TYPE_ZABBIX_USER;
  87		break;
  88	case 'slides':
  89		$page['title'] = _('Slide shows');
  90		$min_user_type = USER_TYPE_ZABBIX_USER;
  91		break;
  92	case 'graphs':
  93		$page['title'] = _('Graphs');
  94		$min_user_type = USER_TYPE_ZABBIX_USER;
  95		break;
  96	case 'simple_graph':
  97		$page['title'] = _('Simple graph');
  98		$min_user_type = USER_TYPE_ZABBIX_USER;
  99		break;
 100	case 'sysmaps':
 101		$page['title'] = _('Maps');
 102		$min_user_type = USER_TYPE_ZABBIX_USER;
 103		break;
 104	case 'plain_text':
 105		$page['title'] = _('Plain text');
 106		$min_user_type = USER_TYPE_ZABBIX_ADMIN;
 107		break;
 108	case 'screens2':
 109		$page['title'] = _('Screens');
 110		$min_user_type = USER_TYPE_ZABBIX_ADMIN;
 111		break;
 112	case 'overview':
 113		$page['title'] = _('Overview');
 114		$min_user_type = USER_TYPE_ZABBIX_ADMIN;
 115		break;
 116	case 'host_group_scr':
 117		$page['title'] = _('Host groups');
 118		$min_user_type = USER_TYPE_ZABBIX_ADMIN;
 119		break;
 120	case 'nodes':
 121		if (ZBX_DISTRIBUTED) {
 122			$page['title'] = _('Nodes');
 123			$min_user_type = USER_TYPE_ZABBIX_USER;
 124			break;
 125		}
 126	case 'drules':
 127		$page['title'] = _('Discovery rules');
 128		$min_user_type = USER_TYPE_ZABBIX_ADMIN;
 129		break;
 130	case 'dchecks':
 131		$page['title'] = _('Discovery checks');
 132		$min_user_type = USER_TYPE_ZABBIX_ADMIN;
 133		break;
 134	case 'scripts':
 135		$page['title'] = _('Global scripts');
 136		$min_user_type = USER_TYPE_ZABBIX_ADMIN;
 137		break;
 138	default:
 139		$page['title'] = _('Error');
 140		$error = true;
 141		break;
 142}
 143$page['file'] = 'popup.php';
 144$page['scripts'] = array();
 145
 146define('ZBX_PAGE_NO_MENU', 1);
 147
 148require_once dirname(__FILE__).'/include/page_header.php';
 149
 150global $USER_DETAILS;
 151if ($min_user_type > $USER_DETAILS['type']) {
 152	access_deny();
 153}
 154if (isset($error)) {
 155	invalid_url();
 156}
 157
 158/*
 159 * Fields
 160 */
 161// allowed 'srcfld*' parameter values for each 'srctbl' value
 162$allowedSrcFields = array(
 163	'users'					=> '"usergrpid", "alias", "userid"',
 164	'triggers'				=> '"description", "triggerid"',
 165	'items'					=> '"itemid", "name"',
 166	'prototypes'			=> '"itemid", "name", "flags"',
 167	'graphs'				=> '"graphid", "name"',
 168	'sysmaps'				=> '"sysmapid", "name"',
 169	'slides'				=> '"slideshowid"',
 170	'host_group'			=> '"groupid", "name"',
 171	'hosts_and_templates'	=> '"name", "hostid", "group"',
 172	'help_items'			=> '"key_"',
 173	'simple_graph'			=> '"itemid", "name"',
 174	'plain_text'			=> '"itemid", "name"',
 175	'hosts'					=> '"name", "hostid"',
 176	'overview'				=> '"groupid", "name"',
 177	'screens'				=> '"screenid"',
 178	'screens2'				=> '"screenid", "name"',
 179	'host_group_scr'		=> '"groupid", "name"',
 180	'host_templates'		=> '"templateid", "name"',
 181	'nodes'					=> '"nodeid", "name"',
 182	'drules'				=> '"druleid", "name"',
 183	'dchecks'				=> '"dcheckid", "name"',
 184	'proxies'				=> '"hostid", "host"',
 185	'usrgrp'				=> '"usrgrpid", "name"',
 186	'templates'				=> '"hostid", "host"',
 187	'applications'			=> '"name"',
 188	'scripts'				=> '"scriptid", "name"'
 189);
 190
 191// VAR	TYPE	OPTIONAL	FLAGS	VALIDATION	EXCEPTION
 192$fields = array(
 193	'dstfrm' =>				array(T_ZBX_STR, O_OPT, P_SYS,	NOT_EMPTY,	'!isset({multiselect})'),
 194	'dstfld1' =>			array(T_ZBX_STR, O_OPT, P_SYS,	NOT_EMPTY,	'!isset({multiselect})'),
 195	'srctbl' =>				array(T_ZBX_STR, O_MAND, P_SYS,	NOT_EMPTY,	null),
 196	'srcfld1' =>			array(T_ZBX_STR, O_MAND, P_SYS,	IN($allowedSrcFields[$_REQUEST['srctbl']]), null),
 197	'nodeid' =>				array(T_ZBX_INT, O_OPT, null,	DB_ID,		null),
 198	'groupid' =>			array(T_ZBX_INT, O_OPT, null,	DB_ID,		null),
 199	'group' =>				array(T_ZBX_STR, O_OPT, null,	null,		null),
 200	'hostid' =>				array(T_ZBX_INT, O_OPT, null,	DB_ID,		null),
 201	'host' =>				array(T_ZBX_STR, O_OPT, null,	null,		null),
 202	'parent_discoveryid' => array(T_ZBX_INT, O_OPT, null,	DB_ID,		null),
 203	'screenid' =>			array(T_ZBX_INT, O_OPT, null,	DB_ID,		null),
 204	'templates' =>			array(T_ZBX_STR, O_OPT, null,	NOT_EMPTY,	null),
 205	'host_templates' =>		array(T_ZBX_STR, O_OPT, null,	NOT_EMPTY,	null),
 206	'existed_templates' =>	array(T_ZBX_STR, O_OPT, null,	NOT_EMPTY,	null),
 207	'multiselect' =>		array(T_ZBX_INT, O_OPT, null,	null,		null),
 208	'submit' =>				array(T_ZBX_STR, O_OPT, null,	null,		null),
 209	'excludeids' =>			array(T_ZBX_STR, O_OPT, null,	null,		null),
 210	'only_hostid' =>		array(T_ZBX_INT, O_OPT, null,	DB_ID,		null),
 211	'monitored_hosts' =>	array(T_ZBX_INT, O_OPT, null,	IN('0,1'),	null),
 212	'templated_hosts' =>	array(T_ZBX_INT, O_OPT, null,	IN('0,1'),	null),
 213	'real_hosts' =>			array(T_ZBX_INT, O_OPT, null,	IN('0,1'),	null),
 214	'normal_only' =>		array(T_ZBX_INT, O_OPT, null,	IN('0,1'),	null),
 215	'simpleName' =>			array(T_ZBX_INT, O_OPT, null,	IN('0,1'),	null),
 216	'with_applications' =>	array(T_ZBX_INT, O_OPT, null,	IN('0,1'),	null),
 217	'with_graphs' =>		array(T_ZBX_INT, O_OPT, null,	IN('0,1'),	null),
 218	'with_items' =>			array(T_ZBX_INT, O_OPT, null,	IN('0,1'),	null),
 219	'with_simple_graph_items' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null),
 220	'with_triggers' =>		array(T_ZBX_INT, O_OPT, null,	IN('0,1'),	null),
 221	'itemtype' =>			array(T_ZBX_INT, O_OPT, null,	null,		null),
 222	'value_types' =>		array(T_ZBX_INT, O_OPT, null,	BETWEEN(0, 15), null),
 223	'reference' =>			array(T_ZBX_STR, O_OPT, null,	null,		null),
 224	'writeonly' =>			array(T_ZBX_STR, O_OPT, null,	null,		null),
 225	'noempty' =>			array(T_ZBX_STR, O_OPT, null,	null,		null),
 226	'select' =>				array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null,	null),
 227	'submitParent' =>		array(T_ZBX_INT, O_OPT, null,	IN('0,1'),	null)
 228);
 229
 230// unset disabled item types
 231$allowed_item_types = array(ITEM_TYPE_ZABBIX, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_SIMPLE, ITEM_TYPE_INTERNAL, ITEM_TYPE_AGGREGATE, ITEM_TYPE_SNMPTRAP);
 232if (isset($_REQUEST['itemtype']) && !str_in_array($_REQUEST['itemtype'], $allowed_item_types)) {
 233	unset($_REQUEST['itemtype']);
 234}
 235
 236// set destination/source fields
 237$dstfldCount = countRequest('dstfld');
 238for ($i = 2; $i <= $dstfldCount; $i++) {
 239	$fields['dstfld'.$i] = array(T_ZBX_STR, O_OPT, P_SYS, null, null);
 240}
 241$srcfldCount = countRequest('srcfld');
 242for ($i = 2; $i <= $srcfldCount; $i++) {
 243	$fields['srcfld'.$i] = array(T_ZBX_STR, O_OPT, P_SYS, IN($allowedSrcFields[$_REQUEST['srctbl']]), null);
 244}
 245
 246check_fields($fields);
 247
 248$dstfrm = get_request('dstfrm', ''); // destination form
 249$dstfld1 = get_request('dstfld1', ''); // output field on destination form
 250$dstfld2 = get_request('dstfld2', ''); // second output field on destination form
 251$srcfld1 = get_request('srcfld1', ''); // source table field [can be different from fields of source table]
 252$srcfld2 = get_request('srcfld2', null); // second source table field [can be different from fields of source table]
 253$multiselect = get_request('multiselect', 0); // if create popup with checkboxes
 254$dstact = get_request('dstact', '');
 255$writeonly = get_request('writeonly');
 256$simpleName = get_request('simpleName');
 257$with_applications = get_request('with_applications', 0);
 258$with_graphs = get_request('with_graphs', 0);
 259$with_items = get_request('with_items', 0);
 260$noempty = get_request('noempty'); // display/hide "Empty" button
 261$existed_templates = get_request('existed_templates', null);
 262$excludeids = get_request('excludeids', null);
 263$reference = get_request('reference', get_request('srcfld1', 'unknown'));
 264$real_hosts = get_request('real_hosts', 0);
 265$monitored_hosts = get_request('monitored_hosts', 0);
 266$templated_hosts = get_request('templated_hosts', 0);
 267$with_simple_graph_items = get_request('with_simple_graph_items', 0);
 268$with_triggers = get_request('with_triggers', 0);
 269$value_types = get_request('value_types', null);
 270$submitParent = get_request('submitParent', 0);
 271$normal_only = get_request('normal_only');
 272$nodeid = get_request('nodeid', get_current_nodeid(false));
 273$group = get_request('group', '');
 274$host = get_request('host', '');
 275$only_hostid = get_request('only_hostid', null);
 276if (isset($only_hostid)) {
 277	$_REQUEST['hostid'] = $only_hostid;
 278	unset($_REQUEST['groupid'], $_REQUEST['nodeid']);
 279}
 280
 281
 282$url = new CUrl();
 283$path = $url->getPath();
 284insert_js('cookie.eraseArray(\''.$path.'\')');
 285
 286function get_window_opener($frame, $field, $value) {
 287	if (empty($field)) {
 288		return '';
 289	}
 290	return '
 291		try {'.
 292			"window.opener.document.getElementById('".addslashes($field)."').value='".addslashes($value)."'; ".
 293		'} catch(e) {'.
 294			'throw("Error: Target not found")'.
 295		'}'."\n";
 296}
 297
 298/*
 299 * Page filter
 300 */
 301if (!empty($group)) {
 302	$dbGroup = DBfetch(DBselect('SELECT g.groupid FROM groups g WHERE g.name='.zbx_dbstr($group)));
 303	if (!empty($dbGroup) && !empty($dbGroup['groupid'])) {
 304		$_REQUEST['groupid'] = $dbGroup['groupid'];
 305	}
 306	unset($dbGroup);
 307}
 308if (!empty($host)) {
 309	$dbHost = DBfetch(DBselect('SELECT h.hostid FROM hosts h WHERE h.name='.zbx_dbstr($host)));
 310	if (!empty($dbHost) && !empty($dbHost['hostid'])) {
 311		$_REQUEST['hostid'] = $dbHost['hostid'];
 312	}
 313	unset($dbHost);
 314}
 315
 316$options = array(
 317	'config' => array('select_latest' => true, 'deny_all' => true, 'popupDD' => true),
 318	'groups' => array('nodeids' => $nodeid),
 319	'hosts' => array('nodeids' => $nodeid),
 320	'groupid' => get_request('groupid', null),
 321	'hostid' => get_request('hostid', null)
 322);
 323
 324if (!is_null($writeonly)) {
 325	$options['groups']['editable'] = true;
 326	$options['hosts']['editable'] = true;
 327}
 328
 329$host_status = null;
 330$templated = null;
 331
 332if ($monitored_hosts) {
 333	$options['groups']['monitored_hosts'] = true;
 334	$options['hosts']['monitored_hosts'] = true;
 335	$host_status = 'monitored_hosts';
 336}
 337elseif ($real_hosts) {
 338	$options['groups']['real_hosts'] = true;
 339	$templated = 0;
 340}
 341elseif ($templated_hosts) {
 342	$options['hosts']['templated_hosts'] = true;
 343	$options['groups']['templated_hosts'] = true;
 344	$templated = 1;
 345	$host_status = 'templated_hosts';
 346}
 347else {
 348	$options['groups']['with_hosts_and_templates'] = true;
 349	$options['hosts']['templated_hosts'] = true; // for hosts templated_hosts comes with monitored and not monitored hosts
 350}
 351
 352if ($with_applications) {
 353	$options['groups']['with_applications'] = true;
 354	$options['hosts']['with_applications'] = true;
 355}
 356elseif ($with_graphs) {
 357	$options['groups']['with_graphs'] = true;
 358	$options['hosts']['with_graphs'] = true;
 359}
 360elseif ($with_simple_graph_items) {
 361	$options['groups']['with_simple_graph_items'] = true;
 362	$options['hosts']['with_simple_graph_items'] = true;
 363}
 364elseif ($with_triggers) {
 365	$options['groups']['with_triggers'] = true;
 366	$options['hosts']['with_triggers'] = true;
 367}
 368$pageFilter = new CPageFilter($options);
 369
 370// get groupid
 371$groupid = null;
 372if ($pageFilter->groupsSelected) {
 373	if ($pageFilter->groupid > 0) {
 374		$groupid = $pageFilter->groupid;
 375	}
 376}
 377else {
 378	$groupid = 0;
 379}
 380
 381// get hostid
 382$hostid = null;
 383if ($pageFilter->hostsSelected) {
 384	if ($pageFilter->hostid > 0) {
 385		$hostid = $pageFilter->hostid;
 386	}
 387}
 388else {
 389	$hostid = 0;
 390}
 391if (isset($only_hostid)) {
 392	$hostid = $only_hostid;
 393}
 394
 395/*
 396 * Display table header
 397 */
 398$frmTitle = new CForm();
 399if ($monitored_hosts) {
 400	$frmTitle->addVar('monitored_hosts', 1);
 401}
 402if ($real_hosts) {
 403	$frmTitle->addVar('real_hosts', 1);
 404}
 405if ($templated_hosts) {
 406	$frmTitle->addVar('templated_hosts', 1);
 407}
 408if ($with_applications) {
 409	$frmTitle->addVar('with_applications', 1);
 410}
 411if ($with_graphs) {
 412	$frmTitle->addVar('with_graphs', 1);
 413}
 414if ($with_items) {
 415	$frmTitle->addVar('with_items', 1);
 416}
 417if ($with_simple_graph_items) {
 418	$frmTitle->addVar('with_simple_graph_items', 1);
 419}
 420if ($with_triggers) {
 421	$frmTitle->addVar('with_triggers', 1);
 422}
 423if ($value_types) {
 424	$frmTitle->addVar('value_types', $value_types);
 425}
 426if ($normal_only) {
 427	$frmTitle->addVar('normal_only', $normal_only);
 428}
 429if (!is_null($existed_templates)) {
 430	$frmTitle->addVar('existed_templates', $existed_templates);
 431}
 432if (!is_null($excludeids)) {
 433	$frmTitle->addVar('excludeids', $excludeids);
 434}
 435if (isset($only_hostid)) {
 436	$frmTitle->addVar('only_hostid', $only_hostid);
 437}
 438
 439// adding param to a form, so that it would remain when page is refreshed
 440$frmTitle->addVar('dstfrm', $dstfrm);
 441$frmTitle->addVar('dstact', $dstact);
 442$frmTitle->addVar('srctbl', $srctbl);
 443$frmTitle->addVar('multiselect', $multiselect);
 444$frmTitle->addVar('writeonly', $writeonly);
 445$frmTitle->addVar('reference', $reference);
 446$frmTitle->addVar('submitParent', $submitParent);
 447$frmTitle->addVar('noempty', $noempty);
 448
 449for ($i = 1; $i <= $dstfldCount; $i++) {
 450	$frmTitle->addVar('dstfld'.$i, get_request('dstfld'.$i));
 451}
 452for ($i = 1; $i <= $srcfldCount; $i++) {
 453	$frmTitle->addVar('srcfld'.$i, get_request('srcfld'.$i));
 454}
 455
 456if (isset($only_hostid)) {
 457	$only_hosts = API::Host()->get(array(
 458		'hostids' => $hostid,
 459		'templated_hosts' => true,
 460		'output' => array('hostid', 'host'),
 461		'limit' => 1
 462	));
 463	$host = reset($only_hosts);
 464
 465	if (empty($host)) {
 466		access_deny();
 467	}
 468
 469	$cmbHosts = new CComboBox('hostid', $hostid);
 470	$cmbHosts->addItem($hostid, get_node_name_by_elid($hostid, null, ': ').$host['host']);
 471	$cmbHosts->setEnabled('disabled');
 472	$cmbHosts->setAttribute('title', _('You can not switch hosts for current selection.'));
 473	$frmTitle->addItem(array(SPACE, _('Host'), SPACE, $cmbHosts));
 474}
 475else {
 476	if (str_in_array($srctbl, array('hosts', 'host_group', 'triggers', 'items', 'simple_graph', 'applications',
 477			'screens', 'slides', 'graphs', 'sysmaps', 'plain_text', 'screens2', 'overview', 'host_group_scr'))) {
 478		if (ZBX_DISTRIBUTED) {
 479			$cmbNode = new CComboBox('nodeid', $nodeid, 'submit()');
 480
 481			$db_nodes = DBselect('SELECT n.* FROM nodes n WHERE '.DBcondition('n.nodeid', get_accessible_nodes_by_user($USER_DETAILS, PERM_READ_LIST)));
 482			while ($node_data = DBfetch($db_nodes)) {
 483				$cmbNode->addItem($node_data['nodeid'], $node_data['name']);
 484				if (bccomp($nodeid , $node_data['nodeid']) == 0) {
 485					$ok = true;
 486				}
 487			}
 488			$frmTitle->addItem(array(SPACE, _('Node'), SPACE, $cmbNode, SPACE));
 489		}
 490	}
 491
 492	if (!isset($ok)) {
 493		$nodeid = get_current_nodeid();
 494	}
 495	unset($ok);
 496
 497	if (str_in_array($srctbl, array('hosts_and_templates', 'hosts', 'templates', 'triggers', 'items', 'applications', 'host_templates', 'graphs', 'simple_graph', 'plain_text'))) {
 498		$frmTitle->addItem(array(_('Group'), SPACE, $pageFilter->getGroupsCB(true)));
 499	}
 500	if (str_in_array($srctbl, array('help_items'))) {
 501		$itemtype = get_request('itemtype', CProfile::get('web.popup.itemtype', 0));
 502		$cmbTypes = new CComboBox('itemtype', $itemtype, 'javascript: submit();');
 503
 504		foreach ($allowed_item_types as $type) {
 505			$cmbTypes->addItem($type, item_type2str($type));
 506		}
 507		$frmTitle->addItem(array(_('Type'), SPACE, $cmbTypes));
 508	}
 509	if (str_in_array($srctbl, array('triggers', 'items', 'applications', 'graphs', 'simple_graph', 'plain_text'))) {
 510		$frmTitle->addItem(array(SPACE, _('Host'), SPACE, $pageFilter->getHostsCB(true)));
 511	}
 512	if (str_in_array($srctbl, array('triggers', 'hosts', 'host_group', 'hosts_and_templates'))) {
 513		if (zbx_empty($noempty)) {
 514			$value1 = isset($_REQUEST['dstfld1']) && zbx_strpos($_REQUEST['dstfld1'], 'id') !== false ? 0 : '';
 515			$value2 = isset($_REQUEST['dstfld2']) && zbx_strpos($_REQUEST['dstfld2'], 'id') !== false ? 0 : '';
 516
 517			$epmtyScript = get_window_opener($dstfrm, $dstfld1, $value1);
 518			$epmtyScript .= get_window_opener($dstfrm, $dstfld2, $value2);
 519			$epmtyScript .= ' close_window(); return false;';
 520
 521			$frmTitle->addItem(array(SPACE, new CButton('empty', _('Empty'), $epmtyScript)));
 522		}
 523	}
 524}
 525
 526show_table_header($page['title'], $frmTitle);
 527
 528insert_js_function('addSelectedValues');
 529insert_js_function('addValues');
 530insert_js_function('addValue');
 531
 532/*
 533 * Hosts
 534 */
 535if ($srctbl == 'hosts') {
 536	$table = new CTableInfo(_('No hosts defined.'));
 537	$table->setHeader(array(_('Name'), _('DNS'), _('IP'), _('Port'), _('Status'), _('Availability')));
 538
 539	$options = array(
 540		'nodeids' => $nodeid,
 541		'groupids' => $groupid,
 542		'output' => array('hostid', 'name', 'status', 'available'),
 543		'selectInterfaces' => array('dns', 'ip', 'useip', 'port')
 544	);
 545	if (!is_null($writeonly)) {
 546		$options['editable'] = 1;
 547	}
 548	if (!is_null($host_status)) {
 549		$options[$host_status] = 1;
 550	}
 551
 552	$hosts = API::Host()->get($options);
 553	order_result($hosts, 'name');
 554
 555	foreach ($hosts as $host) {
 556		$name = new CSpan($host['name'], 'link');
 557		$action = get_window_opener($dstfrm, $dstfld1, $host[$srcfld1]).(isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $host[$srcfld2]) : '');
 558		$name->attr('onclick', $action.' close_window();');
 559		$name->attr('id', 'spanid'.$host['hostid']);
 560
 561		if ($host['status'] == HOST_STATUS_MONITORED) {
 562			$status = new CSpan(_('Monitored'), 'off');
 563		}
 564		elseif ($host['status'] == HOST_STATUS_NOT_MONITORED) {
 565			$status = new CSpan(_('Not monitored'), 'on');
 566		}
 567		else {
 568			$status = _('Unknown');
 569		}
 570
 571		$interface = reset($host['interfaces']);
 572
 573		$dns = $interface['dns'];
 574		$ip = $interface['ip'];
 575
 576		$tmp = $interface['useip'] == 1 ? 'ip' : 'dns';
 577		$tmp = bold($tmp);
 578
 579		if ($host['available'] == HOST_AVAILABLE_TRUE) {
 580			$available = new CSpan(_('Available'), 'off');
 581		}
 582		elseif ($host['available'] == HOST_AVAILABLE_FALSE) {
 583			$available = new CSpan(_('Not available'), 'on');
 584		}
 585		elseif ($host['available'] == HOST_AVAILABLE_UNKNOWN) {
 586			$available = new CSpan(_('Unknown'), 'unknown');
 587		}
 588
 589		$table->addRow(array(
 590			$name,
 591			$dns,
 592			$ip,
 593			$interface['port'],
 594			$status,
 595			$available
 596		));
 597		unset($host);
 598	}
 599	$table->show();
 600}
 601/*
 602 * Templates
 603 */
 604elseif ($srctbl == 'templates') {
 605	$existed_templates = get_request('existed_templates', array());
 606	$excludeids = get_request('excludeids', array());
 607	$templates = get_request('templates', array());
 608	$templates = $templates + $existed_templates;
 609	if (!validate_templates(array_keys($templates))) {
 610		show_error_message(_('Conflict between selected templates.'));
 611	}
 612	elseif (isset($_REQUEST['select'])) {
 613		$new_templates = array_diff($templates, $existed_templates);
 614		$script = '';
 615		if (count($new_templates) > 0) {
 616			foreach ($new_templates as $id => $name) {
 617				$script .= 'add_variable(null, "templates['.$id.']", '.zbx_jsvalue($name).', '.zbx_jsvalue($dstfrm).', window.opener.document);'."\n";
 618			}
 619		}
 620		$script .= 'var form = window.opener.document.forms['.zbx_jsvalue($dstfrm).']; if (form) { form.submit(); } close_window();';
 621		insert_js($script);
 622		unset($new_templates);
 623	}
 624
 625	$table = new CTableInfo(_('No templates defined.'));
 626	$table->setHeader(array(_('Name')));
 627
 628	$options = array(
 629		'nodeids' => $nodeid,
 630		'groupids' => $groupid,
 631		'output' => API_OUTPUT_EXTEND,
 632		'sortfield' => 'name'
 633	);
 634	if (!is_null($writeonly)) {
 635		$options['editable'] = 1;
 636	}
 637
 638	$dbTemplates = API::Template()->get($options);
 639	foreach ($dbTemplates as $host) {
 640		$chk = new CCheckBox('templates['.$host['hostid'].']', isset($templates[$host['hostid']]), null, $host['name']);
 641		$chk->setEnabled(!isset($existed_templates[$host['hostid']]) && !isset($excludeids[$host['hostid']]));
 642		$table->addRow(array(array($chk, $host['name'])));
 643	}
 644
 645	$table->setFooter(new CSubmit('select', _('Select')));
 646	$form = new CForm();
 647	$form->addVar('existed_templates', $existed_templates);
 648
 649	if ($monitored_hosts) {
 650		$form->addVar('monitored_hosts', 1);
 651	}
 652	if ($real_hosts) {
 653		$form->addVar('real_hosts', 1);
 654	}
 655	$form->addVar('dstfrm', $dstfrm);
 656	$form->addVar('dstfld1', $dstfld1);
 657	$form->addVar('srctbl', $srctbl);
 658	$form->addVar('srcfld1', $srcfld1);
 659	$form->addVar('srcfld2', $srcfld2);
 660	$form->addItem($table);
 661	$form->show();
 662}
 663/*
 664 * Host group
 665 */
 666elseif ($srctbl == 'host_group') {
 667	$form = new CForm();
 668	$form->setName('groupform');
 669	$form->setAttribute('id', 'groups');
 670
 671	$table = new CTableInfo(_('No host groups defined.'));
 672	$table->setHeader(array(
 673		$multiselect ? new CCheckBox('all_groups', null, "javascript: checkAll('".$form->getName()."', 'all_groups', 'groups');") : null,
 674		_('Name')
 675	));
 676
 677	$options = array(
 678		'nodeids' => $nodeid,
 679		'output' => array('groupid', 'name'),
 680		'preservekeys' => true
 681	);
 682	if (!is_null($writeonly)) {
 683		$options['editable'] = true;
 684	}
 685	$hostgroups = API::HostGroup()->get($options);
 686	order_result($hostgroups, 'name');
 687
 688	foreach ($hostgroups as $gnum => $group) {
 689		$nodeName = get_node_name_by_elid($group['groupid'], true);
 690		$group['node_name'] = isset($nodeName) ? '('.$nodeName.') ' : '';
 691		$hostgroups[$gnum]['node_name'] = $group['node_name'];
 692
 693		$name = new CSpan(get_node_name_by_elid($group['groupid'], null, ': ').$group['name'], 'link');
 694		$name->attr('id', 'spanid'.$group['groupid']);
 695
 696		if ($multiselect) {
 697			$js_action = 'javascript: addValue('.zbx_jsvalue($reference).', '.zbx_jsvalue($group['groupid']).');';
 698		}
 699		else {
 700			$values = array($dstfld1 => $group[$srcfld1]);
 701			if (isset($srcfld2)) {
 702				$values[$dstfld2] = $group[$srcfld2];
 703			}
 704			$js_action = 'javascript: addValues('.zbx_jsvalue($dstfrm).', '.zbx_jsvalue($values).'); return false;';
 705		}
 706		$name->setAttribute('onclick', $js_action);
 707
 708		$table->addRow(array(
 709			$multiselect ? new CCheckBox('groups['.zbx_jsValue($group[$srcfld1]).']', null, null, $group['groupid']) : null,
 710			$name
 711		));
 712	}
 713
 714	if ($multiselect) {
 715		$button = new CButton('select', _('Select'), "javascript: addSelectedValues('groups', ".zbx_jsvalue($reference).');');
 716		$table->setFooter(new CCol($button, 'right'));
 717		insert_js('var popupReference = '.zbx_jsvalue($hostgroups, true).';');
 718	}
 719	zbx_add_post_js('chkbxRange.pageGoName = "groups";');
 720
 721	$form->addItem($table);
 722	$form->show();
 723}
 724/*
 725 * Host templates
 726 */
 727elseif ($srctbl == 'host_templates') {
 728	$form = new CForm();
 729	$form->setName('tplform');
 730	$form->setAttribute('id', 'templates');
 731
 732	$table = new CTableInfo(_('No templates defined.'));
 733	$table->setHeader(array(
 734		$multiselect ? new CCheckBox('all_templates', null, "javascript: checkAll('".$form->getName()."', 'all_templates', 'templates');") : null,
 735		_('Name')
 736	));
 737
 738	$options = array(
 739		'nodeids' => $nodeid,
 740		'groupids' => $groupid,
 741		'output' => array('templateid', 'name'),
 742		'preservekeys' => true
 743	);
 744	if (!is_null($writeonly)) {
 745		$options['editable'] = true;
 746	}
 747	$templates = API::Template()->get($options);
 748	order_result($templates, 'name');
 749
 750	foreach ($templates as $template) {
 751		$name = new CSpan(get_node_name_by_elid($template['templateid'], null, ': ').$template['name'], 'link');
 752
 753		if ($multiselect) {
 754			$js_action = 'javascript: addValue('.zbx_jsvalue($reference).', '.zbx_jsvalue($template['templateid']).');';
 755		}
 756		else {
 757			$values = array(
 758				$dstfld1 => $template[$srcfld1],
 759				$dstfld2 => $template[$srcfld2]
 760			);
 761			$js_action = 'javascript: addValues('.zbx_jsvalue($dstfrm).', '.zbx_jsvalue($values).'); close_window(); return false;';
 762		}
 763		$name->setAttribute('onclick', $js_action);
 764
 765		$table->addRow(array(
 766			$multiselect ? new CCheckBox('templates['.zbx_jsValue($template[$srcfld1]).']', null, null, $template['templateid']) : null,
 767			$name
 768		));
 769	}
 770
 771	if ($multiselect) {
 772		$button = new CButton('select', _('Select'), "javascript: addSelectedValues('templates', ".zbx_jsvalue($reference).');');
 773		$table->setFooter(new CCol($button, 'right'));
 774
 775		insert_js('var popupReference = '.zbx_jsvalue($templates, true).';');
 776	}
 777	zbx_add_post_js('chkbxRange.pageGoName = "templates";');
 778
 779	$form->addItem($table);
 780	$form->show();
 781}
 782/*
 783 * Hosts and templates
 784 */
 785elseif ($srctbl == 'hosts_and_templates') {
 786	$table = new CTableInfo(_('No templates defined.'));
 787	$table->setHeader(array(_('Name')));
 788
 789	$options = array(
 790		'nodeids' => $nodeid,
 791		'groupids' => $groupid,
 792		'output' => array('hostid', 'name')
 793	);
 794	if (!is_null($writeonly)) {
 795		$options['editable'] = true;
 796	}
 797
 798	// get templates
 799	$templates = API::Template()->get($options);
 800	foreach ($templates as $number => $template) {
 801		$templates[$number]['hostid'] = $template['templateid'];
 802	}
 803	order_result($templates, 'name');
 804
 805	// get hosts
 806	$hosts = API::Host()->get($options);
 807	order_result($hosts, 'name');
 808
 809	$hostsAndTemplates = array_merge($templates, $hosts);
 810	foreach ($hostsAndTemplates as $row) {
 811		$action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]).(isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
 812		if ($submitParent) {
 813			$action .= ' var form = window.opener.document.forms['.zbx_jsvalue($dstfrm).']; if (form) { form.submit(); }';
 814		}
 815		$name = new CSpan($row['name'], 'link');
 816		$name->setAttribute('onclick', $action.' close_window(); return false;');
 817		$table->addRow($name);
 818	}
 819	$table->show();
 820}
 821/*
 822 * User group
 823 */
 824elseif ($srctbl == 'usrgrp') {
 825	$form = new CForm();
 826	$form->setName('usrgrpform');
 827	$form->setAttribute('id', 'usrgrps');
 828
 829	$table = new CTableInfo(_('No user groups defined.'));
 830	$table->setHeader(array(
 831		$multiselect ? new CCheckBox('all_usrgrps', null, "javascript: checkAll('".$form->getName()."', 'all_usrgrps', 'usrgrps');") : null,
 832		_('Name')
 833	));
 834
 835	$options = array(
 836		'nodeids' => $nodeid,
 837		'output' => API_OUTPUT_EXTEND,
 838		'preservekeys' => true
 839	);
 840	if (!is_null($writeonly)) {
 841		$options['editable'] = true;
 842	}
 843	$userGroups = API::UserGroup()->get($options);
 844	order_result($userGroups, 'name');
 845
 846	foreach ($userGroups as $userGroup) {
 847		$name = new CSpan(get_node_name_by_elid($userGroup['usrgrpid'], null, ': ').$userGroup['name'], 'link');
 848		$name->attr('id', 'spanid'.$userGroup['usrgrpid']);
 849
 850		if ($multiselect) {
 851			$js_action = "javascript: addValue(".zbx_jsvalue($reference).', '.zbx_jsvalue($userGroup['usrgrpid']).');';
 852		}
 853		else {
 854			$values = array(
 855				$dstfld1 => $userGroup[$srcfld1],
 856				$dstfld2 => $userGroup[$srcfld2]
 857			);
 858			$js_action = 'javascript: addValues('.zbx_jsvalue($dstfrm).', '.zbx_jsvalue($values).'); close_window(); return false;';
 859		}
 860		$name->setAttribute('onclick', $js_action);
 861
 862		$table->addRow(array(
 863			$multiselect ? new CCheckBox('usrgrps['.$userGroup['usrgrpid'].']', null, null, $userGroup['usrgrpid']) : null,
 864			$name,
 865		));
 866	}
 867
 868	if ($multiselect) {
 869		$button = new CButton('select', _('Select'), "javascript: addSelectedValues('usrgrps', ".zbx_jsvalue($reference).');');
 870		$table->setFooter(new CCol($button, 'right'));
 871
 872		insert_js('var popupReference = '.zbx_jsvalue($userGroups, true).';');
 873	}
 874	zbx_add_post_js('chkbxRange.pageGoName = "usrgrps";');
 875
 876	$form->addItem($table);
 877	$form->show();
 878}
 879/*
 880 * Users
 881 */
 882elseif ($srctbl == 'users') {
 883	$form = new CForm();
 884	$form->setName('userform');
 885	$form->setAttribute('id', 'users');
 886
 887	$table = new CTableInfo(_('No users defined.'));
 888	$table->setHeader(array(
 889		($multiselect ? new CCheckBox('all_users', null, "javascript: checkAll('".$form->getName()."', 'all_users', 'users');") : null),
 890		_('Alias'),
 891		_('Name'),
 892		_('Surname')
 893	));
 894
 895	$options = array(
 896		'nodeids' => $nodeid,
 897		'output' => array('alias', 'name', 'surname', 'type', 'theme', 'lang'),
 898		'preservekeys' => true
 899	);
 900	if (!is_null($writeonly)) {
 901		$options['editable'] = true;
 902	}
 903	$users = API::User()->get($options);
 904	order_result($users, 'alias');
 905
 906	foreach ($users as $unum => $user) {
 907		$alias = new CSpan(get_node_name_by_elid($user['userid'], null, ': ').$user['alias'], 'link');
 908		$alias->attr('id', 'spanid'.$user['userid']);
 909
 910		if ($multiselect) {
 911			$js_action = 'javascript: addValue('.zbx_jsvalue($reference).', '.zbx_jsvalue($user['userid']).');';
 912		}
 913		else {
 914			$values = array(
 915				$dstfld1 => $user[$srcfld1],
 916				$dstfld2 => isset($srcfld2) ? $user[$srcfld2] : null,
 917			);
 918			$js_action = 'javascript: addValues('.zbx_jsvalue($dstfrm).', '.zbx_jsvalue($values).'); close_window(); return false;';
 919		}
 920		$alias->setAttribute('onclick', $js_action);
 921
 922		$table->addRow(array(
 923			$multiselect ? new CCheckBox('users['.zbx_jsValue($user[$srcfld1]).']', null, null, $user['userid']) : null,
 924			$alias,
 925			$user['name'],
 926			$user['surname']
 927		));
 928	}
 929
 930	if ($multiselect) {
 931		$button = new CButton('select', _('Select'), "javascript: addSelectedValues('users', ".zbx_jsvalue($reference).');');
 932		$table->setFooter(new CCol($button, 'right'));
 933
 934		insert_js('var popupReference = '.zbx_jsvalue($users, true).';');
 935	}
 936	zbx_add_post_js('chkbxRange.pageGoName = "users";');
 937
 938	$form->addItem($table);
 939	$form->show();
 940}
 941/*
 942 * Help items
 943 */
 944elseif ($srctbl == 'help_items') {
 945	$table = new CTableInfo(_('No items defined.'));
 946	$table->setHeader(array(_('Key'), _('Name')));
 947
 948	$result = DBselect('SELECT hi.* FROM help_items hi WHERE hi.itemtype='.$itemtype.' ORDER BY hi.key_');
 949	while ($row = DBfetch($result)) {
 950		$action = get_window_opener($dstfrm, $dstfld1, html_entity_decode($row[$srcfld1])).(isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
 951		$name = new CSpan($row['key_'], 'link');
 952		$name->setAttribute('onclick', $action.' close_window(); return false;');
 953		$table->addRow(array($name, $row['description']));
 954	}
 955	$table->show();
 956}
 957/*
 958 * Triggers
 959 */
 960elseif ($srctbl == 'triggers') {
 961	$form = new CForm();
 962	$form->setName('triggerform');
 963	$form->setAttribute('id', 'triggers');
 964
 965	$table = new CTableInfo(_('No triggers defined.'));
 966
 967	$table->setHeader(array(
 968		$multiselect ? new CCheckBox('all_triggers', null, "checkAll('".$form->getName()."', 'all_triggers', 'triggers');") : null,
 969		_('Name'),
 970		_('Severity'),
 971		_('Status')
 972	));
 973
 974	$options = array(
 975		'nodeids' => $nodeid,
 976		'hostids' => $hostid,
 977		'output' => array('triggerid', 'description', 'expression', 'priority', 'status'),
 978		'selectHosts' => array('hostid', 'name'),
 979		'selectDependencies' => API_OUTPUT_EXTEND,
 980		'expandDescription' => true
 981	);
 982	if (is_null($hostid)) {
 983		$options['groupids'] = $groupid;
 984	}
 985	if (!is_null($writeonly)) {
 986		$options['editable'] = true;
 987	}
 988	if (!is_null($templated)) {
 989		$options['templated'] = $templated;
 990	}
 991	$triggers = API::Trigger()->get($options);
 992	order_result($triggers, 'description');
 993
 994	if ($multiselect) {
 995		$jsTriggers = array();
 996	}
 997
 998	foreach ($triggers as $trigger) {
 999		$host = reset($trigger['hosts']);
1000		$trigger['hostname'] = $host['name'];
1001
1002		$description = new CSpan($trigger['description'], 'link');
1003		$trigger['description'] = $trigger['hostname'].': '.$trigger['description'];
1004
1005		if ($multiselect) {
1006			$js_action = 'addValue('.zbx_jsvalue($reference).', '.zbx_jsvalue($trigger['triggerid']).');';
1007		}
1008		else {
1009			$values = array(
1010				$dstfld1 => $trigger[$srcfld1],
1011				$dstfld2 => $trigger[$srcfld2]
1012			);
1013			$js_action = 'addValues('.zbx_jsvalue($dstfrm).', '.zbx_jsvalue($values).'); return false;';
1014		}
1015		$description->setAttribute('onclick', $js_action);
1016
1017		if (count($trigger['dependencies']) > 0) {
1018			$description = array(
1019				$description,
1020				BR(),
1021				bold(_('Depends on')),
1022				BR()
1023			);
1024
1025			foreach ($trigger['dependencies'] as $val) {
1026				$description[] = array(expand_trigger_description_by_data($val), BR());
1027			}
1028		}
1029
1030		switch ($trigger['status']) {
1031			case TRIGGER_STATUS_DISABLED:
1032				$status = new CSpan(_('Disabled'), 'disabled');
1033				break;
1034			case TRIGGER_STATUS_ENABLED:
1035				$status = new CSpan(_('Enabled'), 'enabled');
1036				break;
1037		}
1038		$table->addRow(array(
1039			$multiselect ? new CCheckBox('triggers['.zbx_jsValue($trigger[$srcfld1]).']', null, null, $trigger['triggerid']) : null,
1040			$description,
1041			getSeverityCell($trigger['priority']),
1042			$status
1043		));
1044
1045		// made to save memmory usage
1046		if ($multiselect) {
1047			$jsTriggers[$trigger['triggerid']] = array(
1048				'triggerid' => $trigger['triggerid'],
1049				'description' => $trigger['description'],
1050				'expression' => $trigger['expression'],
1051				'priority' => $trigger['priority'],
1052				'status' => $trigger['status'],
1053				'host' => $trigger['hostname']
1054			);
1055		}
1056	}
1057
1058	if ($multiselect) {
1059		$button = new CButton('select', _('Select'), "addSelectedValues('triggers', ".zbx_jsvalue($reference).');');
1060		$table->setFooter(new CCol($button, 'right'));
1061
1062		insert_js('var popupReference = '.zbx_jsValue($jsTriggers, true).';');
1063	}
1064	zbx_add_post_js('chkbxRange.pageGoName = "triggers";');
1065
1066	$form->addItem($table);
1067	$form->show();
1068}
1069/*
1070 * Items
1071 */
1072elseif ($srctbl == 'items') {
1073	$form = new CForm();
1074	$form->setName('itemform');
1075	$form->setAttribute('id', 'items');
1076
1077	$table = new CTableInfo(_('No items defined.'));
1078
1079	$header = array(
1080		$pageFilter->hostsAll ? _('Host') : null,
1081		$multiselect ? new CCheckBox('all_items', null, "javascript: checkAll('".$form->getName()."', 'all_items', 'items');") : null,
1082		_('Name'),
1083		_('Key'),
1084		_('Type'),
1085		_('Type of information'),
1086		_('Status')
1087	);
1088	$table->setHeader($header);
1089
1090	$options = array(
1091		'nodeids' => $nodeid,
1092		'hostids' => $hostid,
1093		'webitems' => true,
1094		'filter' => array('flags' => array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)),
1095		'output' => API_OUTPUT_EXTEND,
1096		'selectHosts' => array('hostid', 'name'),
1097		'preservekeys' => true
1098	);
1099	if (!is_null($normal_only)) {
1100		$options['filter']['flags'] = ZBX_FLAG_DISCOVERY_NORMAL;
1101	}
1102	if (!is_null($writeonly)) {
1103		$options['editable'] = true;
1104	}
1105	if (!is_null($templated) && $templated == 1) {
1106		$options['templated'] = $templated;
1107	}
1108	if (!is_null($value_types)) {
1109		$options['filter']['value_type'] = $value_types;
1110	}
1111	$items = API::Item()->get($options);
1112	order_result($items, 'name', ZBX_SORT_UP);
1113
1114	if ($multiselect) {
1115		$jsItems = array();
1116	}
1117
1118	foreach ($items as $item) {
1119		$host = reset($item['hosts']);
1120		$item['hostname'] = $host['name'];
1121
1122		$item['name'] = itemName($item);
1123		$description = new CLink($item['name'], '#');
1124		$item['name'] = $item['hostname'].': '.$item['name'];
1125
1126		if ($multiselect) {
1127			$js_action = 'javascript: addValue('.zbx_jsvalue($reference).', '.zbx_jsvalue($item['itemid']).');';
1128		}
1129		else {
1130			$values = array();
1131			for ($i = 1; $i <= $dstfldCount; $i++) {
1132				$dstfld = get_request('dstfld'.$i);
1133				$srcfld = get_request('srcfld'.$i);
1134
1135				if (!empty($dstfld) && !empty($item[$srcfld])) {
1136					$values[$dstfld] = $item[$srcfld];
1137				}
1138			}
1139
1140			// if we need to submit parent window
1141			$js_action = 'javascript: addValues('.zbx_jsvalue($dstfrm).', '.zbx_jsvalue($values).', '.($submitParent ? 'true' : 'false').'); return false;';
1142		}
1143		$description->setAttribute('onclick', $js_action);
1144
1145		$table->addRow(array(
1146			$hostid > 0 ? null : $item['hostname'],
1147			$multiselect ? new CCheckBox('items['.zbx_jsValue($item[$srcfld1]).']', null, null, $item['itemid']) : null,
1148			$description,
1149			$item['key_'],
1150			item_type2str($item['type']),
1151			item_value_type2str($item['value_type']),
1152			new CSpan(item_status2str($item['status']), item_status2style($item['status']))
1153		));
1154
1155		// made to save memory usage
1156		if ($multiselect) {
1157			$jsItems[$item['itemid']] = array(
1158				'itemid' => $item['itemid'],
1159				'name' => $item['name'],
1160				'key_' => $item['key_'],
1161				'type' => $item['type'],
1162				'value_type' => $item['value_type'],
1163				'host' => $item['hostname']
1164			);
1165		}
1166	}
1167
1168	if ($multiselect) {
1169		$button = new CButton('select', _('Select'), "javascript: addSelectedValues('items', ".zbx_jsvalue($reference).');');
1170		$table->setFooter(new CCol($button, 'right'));
1171
1172		insert_js('var popupReference = '.zbx_jsvalue($jsItems, true).';');
1173	}
1174	zbx_add_post_js('chkbxRange.pageGoName = "items";');
1175
1176	$form->addItem($table);
1177	$form->show();
1178}
1179/*
1180 * Prototypes
1181 */
1182elseif ($srctbl == 'prototypes') {
1183	$form = new CForm();
1184	$form->setName('itemform');
1185	$form->setAttribute('id', 'items');
1186
1187	$table = new CTableInfo(_('No item prototypes defined.'));
1188
1189	if ($multiselect) {
1190		$header = array(
1191			array(new CCheckBox('all_items', null, "javascript: checkAll('".$form->getName()."', 'all_items', 'items');"), _('Name')),
1192			_('Key'),
1193			_('Type'),
1194			_('Type of information'),
1195			_('Status')
1196		);
1197	}
1198	else {
1199		$header = array(
1200			_('Name'),
1201			_('Key'),
1202			_('Type'),
1203			_('Type of information'),
1204			_('Status')
1205		);
1206	}
1207	$table->setHeader($header);
1208
1209	$items = API::Item()->get(array(
1210		'nodeids' => $nodeid,
1211		'selectHosts' => array('name'),
1212		'discoveryids' => get_request('parent_discoveryid'),
1213		'filter' => array('flags' => ZBX_FLAG_DISCOVERY_CHILD),
1214		'output' => API_OUTPUT_EXTEND,
1215		'preservekeys' => true
1216	));
1217	order_result($items, 'name');
1218
1219	foreach ($items as &$item) {
1220		$host = reset($item['hosts']);
1221
1222		$description = new CSpan(itemName($item), 'link');
1223		$item['name'] = $host['name'].': '.$item['name'];
1224
1225		if ($multiselect) {
1226			$js_action = 'javascript: addValue('.zbx_jsvalue($reference).', '.zbx_jsvalue($item['itemid']).');';
1227		}
1228		else {
1229			$values = array();
1230			for ($i = 1; $i <= $dstfldCount; $i++) {
1231				$dstfld = get_request('dstfld'.$i);
1232				$srcfld = get_request('srcfld'.$i);
1233
1234				if (!empty($dstfld) && !empty($item[$srcfld])) {
1235					$values[$dstfld] = $item[$srcfld];
1236				}
1237			}
1238
1239			// if we need to submit parent window
1240			$js_action = 'javascript: addValues('.zbx_jsvalue($dstfrm).', '.zbx_jsvalue($values).', '.($submitParent ? 'true' : 'false').'); return false;';
1241		}
1242		$description->setAttribute('onclick', $js_action);
1243
1244		if ($multiselect) {
1245			$description = new CCol(array(new CCheckBox('items['.zbx_jsValue($item[$srcfld1]).']', null, null, $item['itemid']), $description));
1246		}
1247
1248		$table->addRow(array(
1249			$description,
1250			$item['key_'],
1251			item_type2str($item['type']),
1252			item_value_type2str($item['value_type']),
1253			new CSpan(item_status2str($item['status']), item_status2style($item['status']))
1254		));
1255	}
1256
1257	if ($multiselect) {
1258		$button = new CButton('select', _('Select'), "javascript: addSelectedValues('items', ".zbx_jsvalue($reference).');');
1259		$table->setFooter(new CCol($button, 'right'));
1260
1261		insert_js('var popupReference = '.zbx_jsvalue($items, true).';');
1262	}
1263	unset($items);
1264
1265	zbx_add_post_js('chkbxRange.pageGoName = "items";');
1266
1267	$form->addItem($table);
1268	$form->show();
1269}
1270/*
1271 * Applications
1272 */
1273elseif ($srctbl == 'applications') {
1274	$table = new CTableInfo(_('No applications defined.'));
1275	$table->setHeader(array(
1276		$hostid > 0 ? null : _('Host'),
1277		_('Name')
1278	));
1279
1280	$options = array(
1281		'nodeids' => $nodeid,
1282		'hostids' => $hostid,
1283		'output' => API_OUTPUT_EXTEND,
1284		'expandData' => true
1285	);
1286	if (is_null($hostid)) {
1287		$options['groupids'] = $groupid;
1288	}
1289	if (!is_null($writeonly)) {
1290		$options['editable'] = true;
1291	}
1292	if (!is_null($templated)) {
1293		$options['templated'] = $templated;
1294	}
1295	$apps = API::Application()->get($options);
1296	CArrayHelper::sort($apps, array('host', 'name'));
1297
1298	foreach ($apps as $app) {
1299		$action = get_window_opener($dstfrm, $dstfld1, $app[$srcfld1]).(isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $app[$srcfld2]) : '');
1300		$name = new CSpan($app['name'], 'link');
1301		$name->setAttribute('onclick', $action.' close_window(); return false;');
1302
1303		$table->addRow(array($hostid > 0 ? null : $app['host'], $name));
1304	}
1305	$table->show();
1306}
1307/*
1308 * Nodes
1309 */
1310elseif ($srctbl == 'nodes') {
1311	$table = new CTableInfo(_('No nodes defined.'));
1312	$table->setHeader(_('Name'));
1313
1314	$result = DBselect('SELECT DISTINCT n.* FROM nodes n WHERE '.DBcondition('n.nodeid', get_accessible_nodes_by_user($USER_DETAILS, PERM_READ_LIST)));
1315	while ($row = DBfetch($result)) {
1316		$action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]).(isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
1317		$name = new CSpan($row['name'], 'link');
1318		$name->setAttribute('onclick', $action.' close_window(); return false;');
1319		$table->addRow($name);
1320	}
1321	$table->show();
1322}
1323/*
1324 * Graphs
1325 */
1326elseif ($srctbl == 'graphs') {
1327	$form = new CForm();
1328	$form->setName('graphform');
1329	$form->setAttribute('id', 'graphs');
1330
1331	$table = new CTableInfo(_('No graphs defined.'));
1332
1333	if ($multiselect) {
1334		$header = array(
1335			array(new CCheckBox('all_graphs', null, "javascript: checkAll('".$form->getName()."', 'all_graphs', 'graphs');"), _('Description')),
1336			_('Graph type')
1337		);
1338	}
1339	else {
1340		$header = array(
1341			_('Name'),
1342			_('Graph type')
1343		);
1344	}
1345
1346	$table->setHeader($header);
1347
1348	if ($pageFilter->hostsSelected) {
1349		if ($pageFilter->hostsAll) {
1350			$hostid = array_keys($pageFilter->hosts);
1351		}
1352		else {
1353			$hostid = $pageFilter->hostid;
1354		}
1355		$options = array(
1356			'hostids' => $hostid,
1357			'output' => API_OUTPUT_EXTEND,
1358			'nodeids' => $nodeid,
1359			'selectHosts' => API_OUTPUT_EXTEND,
1360			'preservekeys' => true
1361		);
1362
1363		if (!is_null($writeonly)) {
1364			$options['editable'] = true;
1365		}
1366		if (!is_null($templated)) {
1367			$options['templated'] = $templated;
1368		}
1369		$graphs = API::Graph()->get($options);
1370		order_result($graphs, 'name');
1371	}
1372	else {
1373		$graphs = array();
1374	}
1375
1376	foreach ($graphs as $graph) {
1377		$host = reset($graph['hosts']);
1378		$graph['hostname'] = $host['name'];
1379		$graph['node_name'] = get_node_name_by_elid($graph['graphid'], null, ': ');
1380
1381		if (!$simpleName) {
1382			$graph['name'] = $graph['node_name'].$graph['hostname'].': '.$graph['name'];
1383		}
1384		$description = new CSpan($graph['name'], 'link');
1385
1386		if ($multiselect) {
1387			$js_action = 'javascript: addValue('.zbx_jsvalue($reference).', '.zbx_jsvalue($graph['graphid']).');';
1388		}
1389		else {
1390			$values = array(
1391				$dstfld1 => $graph[$srcfld1],
1392				$dstfld2 => $graph[$srcfld2]
1393			);
1394			$js_action = 'javascript: addValues('.zbx_jsvalue($dstfrm).', '.zbx_jsvalue($values).'); close_window(); return false;';
1395		}
1396		$description->setAttribute('onclick', $js_action);
1397
1398		if ($multiselect) {
1399			$description = new CCol(array(new CCheckBox('graphs['.zbx_jsValue($graph[$srcfld1]).']', null, null, $graph['graphid']), $description));
1400		}
1401
1402		switch ($graph['graphtype']) {
1403			case GRAPH_TYPE_STACKED:
1404				$graphtype = _('Stacked');
1405				break;
1406			case GRAPH_TYPE_PIE:
1407				$graphtype = _('Pie');
1408				break;
1409			case GRAPH_TYPE_EXPLODED:
1410				$graphtype = _('Exploded');
1411				break;
1412			default:
1413				$graphtype = _('Normal');
1414				break;
1415		}
1416		$table->addRow(array(
1417			$description,
1418			$graphtype
1419		));
1420		unset($description);
1421	}
1422
1423	if ($multiselect) {
1424		$button = new CButton('select', _('Select'), "javascript: addSelectedValues('graphs', ".zbx_jsvalue($reference).');');
1425		$table->setFooter(new CCol($button, 'right'));
1426
1427		insert_js('var popupReference = '.zbx_jsvalue($graphs, true).';');
1428	}
1429	zbx_add_post_js('chkbxRange.pageGoName = "graphs";');
1430
1431	$form->addItem($table);
1432	$form->show();
1433}
1434/*
1435 * Simple graph
1436 */
1437elseif ($srctbl == 'simple_graph') {
1438	$form = new CForm();
1439	$form->setName('itemform');
1440	$form->setAttribute('id', 'items');
1441
1442	$table = new CTableInfo(_('No items defined.'));
1443
1444	if ($pageFilter->hostsSelected) {
1445		if ($pageFilter->hostsAll) {
1446			$hostid = array_keys($pageFilter->hosts);
1447		}
1448		else {
1449			$hostid = $pageFilter->hostid;
1450		}
1451
1452		$options = array(
1453			'nodeids' => $nodeid,
1454			'hostids' => $hostid,
1455			'output' => API_OUTPUT_EXTEND,
1456			'selectHosts' => API_OUTPUT_EXTEND,
1457			'webitems' => true,
1458			'templated' => false,
1459			'filter' => array(
1460				'value_type' => array(ITEM_VALUE_TYPE_FLOAT,ITEM_VALUE_TYPE_UINT64),
1461				'status' => ITEM_STATUS_ACTIVE,
1462				'flags' => array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)
1463			),
1464			'preservekeys' => true
1465		);
1466		if (!is_null($writeonly)) {
1467			$options['editable'] = true;
1468		}
1469		if (!is_null($templated)) {
1470			$options['templated'] = $templated;
1471		}
1472		$items = API::Item()->get($options);
1473		order_result($items, 'name');
1474	}
1475	else {
1476		$items = array();
1477	}
1478
1479	if ($multiselect) {
1480		$header = array(
1481			is_array($hostid) ? _('Host') : null,
1482			array(new CCheckBox('all_items', null, "javascript: checkAll('".$form->getName()."', 'all_items', 'items');"), _('Name')),
1483			_('Type'),
1484			_('Type of information')
1485		);
1486	}
1487	else {
1488		$header = array(
1489			is_array($hostid) ? _('Host') : null,
1490			_('Name'),
1491			_('Type'),
1492			_('Type of information')
1493		);
1494	}
1495	$table->setHeader($header);
1496
1497	foreach ($items as $item) {
1498		$host = reset($item['hosts']);
1499		$item['hostname'] = $host['name'];
1500		$item['name'] = itemName($item);
1501		$description = new CLink($item['name'], '#');
1502
1503		if (!$simpleName) {
1504			$item['name'] = $item['hostname'].': '.$item['name'];
1505		}
1506
1507		if ($multiselect) {
1508			$js_action ='javascript: addValue('.zbx_jsvalue($reference).', '.zbx_jsvalue($item['itemid']).');';
1509		}
1510		else {
1511			$values = array(
1512				$dstfld1 => $item[$srcfld1],
1513				$dstfld2 => $item[$srcfld2]
1514			);
1515			$js_action = 'javascript: addValues('.zbx_jsvalue($dstfrm).', '.zbx_jsvalue($values).'); close_window(); return false;';
1516		}
1517		$description->setAttribute('onclick', $js_action);
1518
1519		if ($multiselect) {
1520			$description = new CCol(array(new CCheckBox('items['.zbx_jsValue($item[$srcfld1]).']', null, null, $item['itemid']), $description));
1521		}
1522
1523		$table->addRow(array(
1524			$hostid > 0 ? null : $item['hostname'],
1525			$description,
1526			item_type2str($item['type']),
1527			item_value_type2str($item['value_type'])
1528		));
1529	}
1530
1531	if ($multiselect) {
1532		$button = new CButton('select', _('Select'), "javascript: addSelectedValues('items', ".zbx_jsvalue($reference).');');
1533		$table->setFooter(new CCol($button, 'right'));
1534
1535		insert_js('var popupReference = '.zbx_jsvalue($items, true).';');
1536	}
1537	zbx_add_post_js('chkbxRange.pageGoName = "items";');
1538
1539	$form->addItem($table);
1540	$form->show();
1541}
1542/*
1543 * Sysmaps
1544 */
1545elseif ($srctbl == 'sysmaps') {
1546	$form = new CForm();
1547	$form->setName('sysmapform');
1548	$form->setAttribute('id', 'sysmaps');
1549
1550	$table = new CTableInfo(_('No maps defined.'));
1551
1552	if ($multiselect) {
1553		$header = array(array(new CCheckBox('all_sysmaps', null, "javascript: checkAll('".$form->getName()."', 'all_sysmaps', 'sysmaps');"), _('Name')));
1554	}
1555	else {
1556		$header = array(_('Name'));
1557	}
1558
1559	$table->setHeader($header);
1560
1561	$excludeids = get_request('excludeids', array());
1562	$excludeids = zbx_toHash($excludeids);
1563
1564	$options = array(
1565		'nodeids' => $nodeid,
1566		'output' => API_OUTPUT_EXTEND,
1567		'preservekeys' => true
1568	);
1569	if (!is_null($writeonly)) {
1570		$options['editable'] = true;
1571	}
1572	$sysmaps = API::Map()->get($options);
1573	order_result($sysmaps, 'name');
1574
1575	foreach ($sysmaps as $sysmap) {
1576		if (isset($excludeids[$sysmap['sysmapid']])) {
1577			continue;
1578		}
1579		$sysmap['node_name'] = isset($sysmap['node_name']) ? '('.$sysmap['node_name'].') ' : '';
1580		$name = $sysmap['node_name'].$sysmap['name'];
1581		$description = new CSpan($sysmap['name'], 'link');
1582
1583		if ($multiselect) {
1584			$js_action = 'javascript: addValue('.zbx_jsvalue($reference).', '.zbx_jsvalue($sysmap['sysmapid']).');';
1585		}
1586		else {
1587			$values = array(
1588				$dstfld1 => $sysmap[$srcfld1],
1589				$dstfld2 => $sysmap[$srcfld2]
1590			);
1591			$js_action = 'javascript: addValues('.zbx_jsvalue($dstfrm).', '.zbx_jsvalue($values).'); close_window(); return false;';
1592		}
1593		$description->setAttribute('onclick', $js_action);
1594
1595		if ($multiselect) {
1596			$description = new CCol(array(new CCheckBox('sysmaps['.zbx_jsValue($sysmap[$srcfld1]).']', null, null, $sysmap['sysmapid']), $description));
1597		}
1598		$table->addRow($description);
1599		unset($description);
1600	}
1601
1602	if ($multiselect) {
1603		$button = new CButton('select', _('Select'), "javascript: addSelectedValues('sysmaps', ".zbx_jsvalue($reference).');');
1604		$table->setFooter(new CCol($button, 'right'));
1605
1606		insert_js('var popupReference = '.zbx_jsvalue($sysmaps, true).';');
1607	}
1608	zbx_add_post_js('chkbxRange.pageGoName = "sysmaps";');
1609
1610	$form->addItem($table);
1611	$form->show();
1612}
1613/*
1614 * Plain text
1615 */
1616elseif ($srctbl == 'plain_text') {
1617	$table = new CTableInfo(_('No items defined.'));
1618	$table->setHeader(array(
1619		$hostid > 0 ? null : _('Host'),
1620		_('Name'),
1621		_('Key'),
1622		_('Type'),
1623		_('Type of information'),
1624		_('Status')
1625	));
1626
1627	$options = array(
1628		'nodeids' => $nodeid,
1629		'hostids' => $hostid,
1630		'output' => API_OUTPUT_EXTEND,
1631		'selectHosts' => API_OUTPUT_EXTEND,
1632		'templated' => 0,
1633		'filter' => array(
1634			'flags' => array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED),
1635			'status' => ITEM_STATUS_ACTIVE
1636		),
1637		'sortfield' => 'name'
1638	);
1639	if (!is_null($writeonly)) {
1640		$options['editable'] = true;
1641	}
1642	if (!is_null($templated)) {
1643		$options['templated'] = $templated;
1644	}
1645	$items = API::Item()->get($options);
1646
1647	foreach ($items as $item) {
1648		$host = reset($item['hosts']);
1649		$item['host'] = $host['name'];
1650		$item['name'] = itemName($item);
1651		$description = new CSpan($item['name'], 'link');
1652		$item['name'] = $item['host'].': '.$item['name'];
1653
1654		$action = get_window_opener($dstfrm, $dstfld1, $item[$srcfld1]).get_window_opener($dstfrm, $dstfld2, $item[$srcfld2]);
1655		$description->setAttribute('onclick',

Large files files are truncated, but you can click here to view the full file