PageRenderTime 68ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

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

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