1<?php 2/* 3** Zabbix 4** Copyright (C) 2001-2021 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 22/** 23 * @var CView $this 24 */ 25 26$output = [ 27 'header' => $data['title'], 28 'body' => '', 29 'controls' => '', 30 'script_inline' => '', 31 'buttons' => null 32]; 33 34$options = $data['options']; 35$controls = []; 36$form = null; 37 38// Construct table header. 39$header_form = ($data['popup_type'] === 'help_items') ? (new CForm())->cleanItems() : new CDiv(); 40$header_form->setId('generic-popup-form'); 41 42// Make 'empty' button. 43if ($data['popup_type'] === 'triggers' && !array_key_exists('noempty', $options)) { 44 $value1 = (strpos($options['dstfld1'], 'id') !== false) ? 0 : ''; 45 $value2 = (strpos($options['dstfld2'], 'id') !== false) ? 0 : ''; 46 $value3 = (strpos($options['dstfld3'], 'id') !== false) ? 0 : ''; 47 48 $empty_script = get_window_opener($options['dstfld1'], $value1); 49 $empty_script .= get_window_opener($options['dstfld2'], $value2); 50 $empty_script .= get_window_opener($options['dstfld3'], $value3); 51 $empty_script .= 'overlayDialogueDestroy(jQuery(this).closest("[data-dialogueid]").attr("data-dialogueid"));'; 52 $empty_script .= 'return false;'; 53 54 $empty_btn = (new CButton('empty', _('Empty'))) 55 ->addStyle('float: right; margin-left: 5px;') 56 ->onClick($empty_script); 57} 58else { 59 $empty_btn = null; 60} 61 62// Add host group multiselect control. 63if (array_key_exists('groups', $data['filter'])) { 64 $multiselect_options = $data['filter']['groups']; 65 $multiselect_options['popup']['parameters']['dstfrm'] = $header_form->getId(); 66 67 $hostgroup_ms = (new CMultiSelect($multiselect_options))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH); 68 $controls[] = (new CFormList())->addRow(new CLabel(_('Host group'), 'popup_host_group_ms'), $hostgroup_ms); 69 70 $output['script_inline'] .= 71 $hostgroup_ms->getPostJS(). 72 'var overlay = overlays_stack.end();'. 73 'jQuery(".multiselect", overlay.$dialogue).each(function(i, ms) {'. 74 'jQuery(ms).on("change", {overlay: overlay}, function(e) {'. 75 'var groups = jQuery(this).multiSelect("getData").map(i => i.id),'. 76 'options = groups.length ? {groupid: groups[0]} : {filter_groupid_rst: 1, groupid: []};'. 77 'new_opts = jQuery.extend(e.data.overlay.options, options);'. 78 'PopUp(e.data.overlay.action, new_opts, e.data.overlay.dialogueid);'. 79 '});'. 80 '});'; 81} 82 83// Add host multiselect. 84if (array_key_exists('hosts', $data['filter'])) { 85 $multiselect_options = $data['filter']['hosts']; 86 $multiselect_options['popup']['parameters']['dstfrm'] = $header_form->getId(); 87 88 $host_ms = (new CMultiSelect($multiselect_options))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH); 89 if ($multiselect_options['disabled']) { 90 $host_ms->setTitle(_('You can not switch hosts for current selection.')); 91 } 92 $controls[] = (new CFormList())->addRow(new CLabel(_('Host'), 'popup_host_ms'), [$empty_btn, $host_ms]); 93 94 $output['script_inline'] .= 95 $host_ms->getPostJS(). 96 'var overlay = overlays_stack.end();'. 97 'jQuery(".multiselect", overlay.$dialogue).each(function(i, ms) {'. 98 'jQuery(ms).on("change", {overlay: overlay}, function(e) {'. 99 'var hosts = jQuery(this).multiSelect("getData").map(i => i.id),'. 100 'options = hosts.length ? {hostid: hosts[0]} : {filter_hostid_rst: 1, hostid: []};'. 101 'new_opts = jQuery.extend(e.data.overlay.options, options);'. 102 'PopUp(e.data.overlay.action, new_opts, e.data.overlay.dialogueid);'. 103 '});'. 104 '});'; 105} 106elseif ($empty_btn) { 107 $controls[] = (new CFormList())->addRow($empty_btn); 108} 109 110// Show Type dropdown in header for help items. 111if ($data['popup_type'] === 'help_items') { 112 $types_select = (new CSelect('itemtype')) 113 ->setId('itemtype') 114 ->setFocusableElementId('label-itemtype') 115 ->setAttribute('autofocus', 'autofocus') 116 ->setValue($options['itemtype']); 117 118 $output['script_inline'] .= '$("#itemtype").on("change", (e) => {'. 119 'reloadPopup($(e.target).closest("form").get(0));'. 120 '});'; 121 122 $header_form 123 ->addVar('srctbl', $data['popup_type']) 124 ->addVar('srcfld1', $options['srcfld1']) 125 ->addVar('dstfrm', $options['dstfrm']) 126 ->addVar('dstfld1', $options['dstfld1']); 127 128 foreach (CControllerPopupGeneric::ALLOWED_ITEM_TYPES as $type) { 129 $types_select->addOption(new CSelectOption($type, item_type2str($type))); 130 } 131 132 $controls[] = [ 133 new CLabel(_('Type'), $types_select->getFocusableElementId()), 134 (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), 135 $types_select 136 ]; 137} 138 139if ($controls) { 140 $header_form->addItem($controls); 141 $output['controls'] = $header_form->toString(); 142} 143 144// Create form. 145if ($data['form']) { 146 $form = (new CForm()) 147 ->cleanItems() 148 ->setName($data['form']['name']) 149 ->setId($data['form']['id']); 150} 151 152$table_columns = []; 153 154if ($data['multiselect'] && $form !== null) { 155 $ch_box = (new CColHeader( 156 (new CCheckBox('all_records'))->onClick("javascript: checkAll('".$form->getName()."', 'all_records', 'item');") 157 ))->addClass(ZBX_STYLE_CELL_WIDTH); 158 159 $table_columns[] = $ch_box; 160} 161 162$table = (new CTableInfo())->setHeader(array_merge($table_columns, $data['table_columns'])); 163 164if ($data['preselect_required']) { 165 $table->setNoDataMessage(_('Specify some filter condition to see the values.')); 166} 167 168$js_action_onclick = ' jQuery(this).removeAttr("onclick");'. 169 ' overlayDialogueDestroy(jQuery(this).closest("[data-dialogueid]").attr("data-dialogueid"));'. 170 ' return false;'; 171 172// Output table rows. 173switch ($data['popup_type']) { 174 case 'hosts': 175 case 'host_groups': 176 case 'proxies': 177 case 'host_templates': 178 case 'templates': 179 case 'drules': 180 case 'roles': 181 case 'api_methods': 182 case 'dashboard': 183 foreach ($data['table_records'] as $item) { 184 $check_box = $data['multiselect'] 185 ? new CCheckBox('item['.$item['id'].']', $item['id']) 186 : null; 187 188 if (array_key_exists('_disabled', $item)) { 189 if ($data['multiselect']) { 190 $check_box->setChecked(1); 191 $check_box->setEnabled(false); 192 } 193 $name = $item['name']; 194 195 unset($data['table_records'][$item['id']]); 196 } 197 else { 198 $js_action = 'javascript: addValue('.zbx_jsvalue($options['reference']).', '. 199 zbx_jsvalue($item['id']).', '.$options['parentid'].');'; 200 201 $name = (new CLink($item['name'], 'javascript:void(0);')) 202 ->setId('spanid'.$item['id']) 203 ->onClick($js_action.$js_action_onclick); 204 } 205 206 $table->addRow([$check_box, $name]); 207 } 208 break; 209 210 case 'users': 211 foreach ($data['table_records'] as &$user) { 212 $check_box = $data['multiselect'] 213 ? new CCheckBox('item['.$user['userid'].']', $user['userid']) 214 : null; 215 216 $js_action = 'javascript: addValue('.zbx_jsvalue($options['reference']).', '. 217 zbx_jsvalue($user['userid']).', '.$options['parentid'].');'; 218 219 $username = (new CLink($user['username'], 'javascript:void(0);')) 220 ->setId('spanid'.$user['userid']) 221 ->onClick($js_action.$js_action_onclick); 222 223 $table->addRow([$check_box, $username, $user['name'], $user['surname']]); 224 225 $entry = []; 226 $srcfld1 = $options['srcfld1']; 227 if ($srcfld1 === 'userid') { 228 $entry['id'] = $user['userid']; 229 } 230 elseif ($srcfld1 === 'username') { 231 $entry['name'] = $user['username']; 232 } 233 234 $srcfld2 = $options['srcfld2']; 235 if ($srcfld2 === 'fullname') { 236 $entry['name'] = getUserFullname($user); 237 } 238 elseif (array_key_exists($srcfld2, $user)) { 239 $entry[$srcfld2] = $user[$srcfld2]; 240 } 241 242 $user = $entry; 243 } 244 unset($user); 245 break; 246 247 case 'usrgrp': 248 foreach ($data['table_records'] as &$item) { 249 $check_box = $data['multiselect'] 250 ? new CCheckBox('item['.$item['usrgrpid'].']', $item['usrgrpid']) 251 : null; 252 253 $js_action = "javascript: addValue(".zbx_jsvalue($options['reference']).', '. 254 zbx_jsvalue($item['usrgrpid']).', '.$options['parentid'].');'; 255 256 $name = (new CLink($item['name'], 'javascript: void(0);')) 257 ->setId('spanid'.$item['usrgrpid']) 258 ->onClick($js_action.$js_action_onclick); 259 260 $table->addRow([$check_box, $name]); 261 262 $item['id'] = $item['usrgrpid']; 263 } 264 unset($item); 265 break; 266 267 case 'triggers': 268 case 'trigger_prototypes': 269 foreach ($data['table_records'] as &$trigger) { 270 $host = reset($trigger['hosts']); 271 $trigger['hostname'] = $host['name']; 272 273 $description = new CLink($trigger['description'], 'javascript:void(0);'); 274 $trigger['description'] = $trigger['hostname'].NAME_DELIMITER.$trigger['description']; 275 276 $check_box = $data['multiselect'] 277 ? new CCheckBox('item['.zbx_jsValue($trigger[$options['srcfld1']]).']', $trigger['triggerid']) 278 : null; 279 280 if ($data['multiselect']) { 281 $js_action = 'javascript: addValue('.zbx_jsvalue($options['reference']).', '. 282 zbx_jsvalue($trigger['triggerid']).', '.$options['parentid'].');'; 283 } 284 else { 285 $values = [ 286 $options['dstfld1'] => $trigger[$options['srcfld1']], 287 $options['dstfld2'] => $trigger[$options['srcfld2']] 288 ]; 289 if (array_key_exists('dstfld3', $options)) { 290 if (array_key_exists($options['srcfld3'], $trigger) && array_key_exists($trigger[$options['srcfld3']], $trigger)) { 291 $values[$options['dstfld3']] = $trigger[$trigger[$options['srcfld3']]]; 292 } 293 else { 294 $values[$options['dstfld3']] = null; 295 } 296 } 297 $js_action = 'javascript: addValues('.zbx_jsvalue($options['dstfrm']).','.zbx_jsvalue($values).');'; 298 } 299 300 $description->onClick($js_action.$js_action_onclick); 301 302 if ($trigger['dependencies']) { 303 $description = [$description, BR(), bold(_('Depends on')), BR()]; 304 305 $dependencies = CMacrosResolverHelper::resolveTriggerNames( 306 zbx_toHash($trigger['dependencies'], 'triggerid') 307 ); 308 309 foreach ($dependencies as $dependency) { 310 $description[] = $dependency['description']; 311 $description[] = BR(); 312 } 313 array_pop($description); 314 } 315 316 $table->addRow([ 317 $check_box, 318 $description, 319 getSeverityCell($trigger['priority']), 320 (new CSpan(triggerIndicator($trigger['status'], $trigger['state']))) 321 ->addClass(triggerIndicatorStyle($trigger['status'], $trigger['state'])) 322 ]); 323 324 if ($data['multiselect']) { 325 $trigger = [ 326 'id' => $trigger['triggerid'], 327 'name' => $trigger['description'], 328 'triggerid' => $trigger['triggerid'], 329 'description' => $trigger['description'], 330 'expression' => $trigger['expression'], 331 'priority' => $trigger['priority'], 332 'status' => $trigger['status'], 333 'host' => $trigger['hostname'] 334 ]; 335 } 336 } 337 unset($trigger); 338 break; 339 340 case 'sysmaps': 341 foreach ($data['table_records'] as $sysmap) { 342 if ($data['multiselect']) { 343 $check_box = new CCheckBox('item['.$sysmap['sysmapid'].']', $sysmap['sysmapid']); 344 } 345 346 if ($data['multiselect']) { 347 $js_action = "javascript: addValue(".zbx_jsvalue($options['reference']).', '. 348 zbx_jsvalue($sysmap['sysmapid']).', '.$options['parentid'].');'; 349 } 350 else { 351 $values = [ 352 $options['dstfld1'] => $sysmap[$options['srcfld1']], 353 $options['dstfld2'] => $sysmap[$options['srcfld2']] 354 ]; 355 $js_action = 'javascript: addValues('.zbx_jsvalue($options['dstfrm']).', '. 356 zbx_jsvalue($values).');'; 357 } 358 359 $name = (new CLink($sysmap['name'], 'javascript:void(0);')) 360 ->setId('spanid'.$sysmap['sysmapid']) 361 ->onClick($js_action.$js_action_onclick); 362 363 $table->addRow([$data['multiselect'] ? $check_box : null, $name]); 364 } 365 break; 366 367 case 'help_items': 368 foreach ($data['table_records'] as $item) { 369 $action = get_window_opener($options['dstfld1'], $item[$options['srcfld1']]); 370 $action .= 'updateItemFormElements();'; 371 $action .= $options['srcfld2'] 372 ? get_window_opener($options['dstfld2'], $item[$options['srcfld2']]) 373 : ''; 374 375 $name = (new CLink($item['key'], 'javascript:void(0);'))->onClick($action.$js_action_onclick); 376 $table->addRow([$name, $item['description']]); 377 } 378 unset($data['table_records']); 379 break; 380 381 case 'dchecks': 382 foreach ($data['table_records'] as $d_rule) { 383 foreach ($d_rule['dchecks'] as $d_check) { 384 $name = $d_rule['name']. 385 NAME_DELIMITER.discovery_check2str($d_check['type'], $d_check['key_'], $d_check['ports']); 386 387 $action = get_window_opener($options['dstfld1'], $d_check[$options['srcfld1']]); 388 $action .= $options['srcfld2'] 389 ? get_window_opener($options['dstfld2'], $name) 390 : ''; 391 392 $table->addRow( 393 (new CLink($name, 'javascript:void(0);'))->onClick($action.$js_action_onclick) 394 ); 395 } 396 } 397 unset($data['table_records']); 398 break; 399 400 case 'items': 401 case 'item_prototypes': 402 if ($options['srcfld2'] !== '' && $options['dstfld2'] !== '') { 403 // TODO: this condition must be removed after all item and item_prototype fields changing to multiselect 404 foreach ($data['table_records'] as &$item) { 405 $host = reset($item['hosts']); 406 $item['hostname'] = $host['name']; 407 408 $description = new CLink($item['name_expanded'], 'javascript:void(0);'); 409 $item['name'] = $item['hostname'].NAME_DELIMITER.$item['name_expanded']; 410 411 $checkbox_key = is_numeric($item[$options['srcfld1']]) 412 ? $item[$options['srcfld1']] 413 : zbx_jsValue($item[$options['srcfld1']]); 414 415 if ($data['multiselect']) { 416 $js_action = 'javascript: addValue('.zbx_jsvalue($options['reference']).', '. 417 zbx_jsvalue($item['itemid']).', '.$options['parentid'].');'; 418 } 419 else { 420 $values = []; 421 if ($options['dstfld1'] !== '' && $options['srcfld1'] !== '') { 422 $values[$options['dstfld1']] = $item[$options['srcfld1']]; 423 } 424 if ($options['dstfld2'] !== '' && $options['srcfld2'] !== '') { 425 $values[$options['dstfld2']] = $item[$options['srcfld2']]; 426 } 427 if ($options['dstfld3'] !== '' && $options['srcfld3'] !== '') { 428 $values[$options['dstfld3']] = $item[$options['srcfld3']]; 429 } 430 431 $submit_parent = array_key_exists('submit_parent', $options) ? 'true' : 'false'; 432 $js_action = 'javascript: addValues('.zbx_jsvalue($options['dstfrm']).', '. 433 zbx_jsvalue($values).', '.$submit_parent.');'; 434 } 435 436 $description->onClick($js_action.$js_action_onclick); 437 438 $table->addRow([ 439 $data['multiselect'] ? new CCheckBox('item['.$checkbox_key.']', $item['itemid']) : null, 440 $description, 441 (new CDiv($item['key_']))->addClass(ZBX_STYLE_WORDWRAP), 442 item_type2str($item['type']), 443 itemValueTypeString($item['value_type']), 444 ($data['popup_type'] === 'items') 445 ? (new CSpan(itemIndicator($item['status'], $item['state']))) 446 ->addClass(itemIndicatorStyle($item['status'], $item['state'])) 447 : null 448 ]); 449 450 if ($data['multiselect']) { 451 $item = [ 452 'id' => $item['itemid'], 453 'itemid' => $item['itemid'], 454 'name' => $item['name'], 455 'key_' => $item['key_'], 456 'flags' => $item['flags'], 457 'type' => $item['type'], 458 'value_type' => $item['value_type'], 459 'host' => $item['hostname'] 460 ]; 461 } 462 } 463 unset($item); 464 } 465 else { 466 foreach ($data['table_records'] as &$item) { 467 $host = reset($item['hosts']); 468 469 $table->addRow([ 470 $data['multiselect'] 471 ? new CCheckBox('item['.$item[$options['srcfld1']].']', $item['itemid']) 472 : null, 473 (new CLink($item['name_expanded'], 'javascript:void(0);')) 474 ->onClick('javascript: addValue('. 475 json_encode($options['reference']).', '. 476 json_encode($item['itemid']).', '. 477 $options['parentid']. 478 ');'.$js_action_onclick), 479 (new CDiv($item['key_']))->addClass(ZBX_STYLE_WORDWRAP), 480 item_type2str($item['type']), 481 itemValueTypeString($item['value_type']), 482 ($data['popup_type'] === 'items') 483 ? (new CSpan(itemIndicator($item['status'], $item['state']))) 484 ->addClass(itemIndicatorStyle($item['status'], $item['state'])) 485 : null 486 ]); 487 488 $item = [ 489 'id' => $item['itemid'], 490 'itemid' => $item['itemid'], 491 'name' => $options['patternselect'] 492 ? $item['name'] 493 : $host['name'].NAME_DELIMITER.$item['name_expanded'], 494 'name_expanded' => $item['name_expanded'], 495 'key_' => $item['key_'], 496 'flags' => $item['flags'], 497 'type' => $item['type'], 498 'value_type' => $item['value_type'], 499 'host' => $host['name'] 500 ]; 501 } 502 unset($item); 503 } 504 break; 505 506 case 'graphs': 507 case 'graph_prototypes': 508 foreach ($data['table_records'] as &$graph) { 509 switch ($graph['graphtype']) { 510 case GRAPH_TYPE_STACKED: 511 $graphtype = _('Stacked'); 512 break; 513 case GRAPH_TYPE_PIE: 514 $graphtype = _('Pie'); 515 break; 516 case GRAPH_TYPE_EXPLODED: 517 $graphtype = _('Exploded'); 518 break; 519 default: 520 $graphtype = _('Normal'); 521 break; 522 } 523 524 $table->addRow([ 525 // Multiselect checkbox. 526 $data['multiselect'] 527 ? new CCheckBox('item['.json_encode($graph[$options['srcfld1']]).']', $graph['graphid']) 528 : null, 529 530 // Clickable graph name. 531 (new CLink($graph['name'], 'javascript:void(0);')) 532 ->onClick('javascript: addValue('. 533 json_encode($options['reference']).', '. 534 json_encode($graph['graphid']).', '. 535 $options['parentid']. 536 ');'.$js_action_onclick 537 ), 538 539 // Graph type. 540 $graphtype 541 ]); 542 543 // For returned data array. 544 $graph = [ 545 'id' => $graph['graphid'], 546 'name' => $options['patternselect'] 547 ? $graph['name'] 548 : reset($graph['hosts'])['name'].NAME_DELIMITER.$graph['name'] 549 ]; 550 } 551 unset($graph); 552 break; 553 554 case 'valuemap_names': 555 $inline_js = 'addValue('.json_encode($options['reference']).',%1$s,'.$options['parentid'].');%2$s'; 556 557 foreach ($data['table_records'] as $valuemap) { 558 $table->addRow([ 559 new CCheckBox('item['.$valuemap['id'].']', $valuemap['id']), 560 (new CLink($valuemap['name'], '#')) 561 ->setId('spanid'.$valuemap['id']) 562 ->onClick(sprintf($inline_js, $valuemap['id'], $js_action_onclick)) 563 ]); 564 } 565 break; 566 567 case 'valuemaps': 568 $inline_js = 'addValue('.json_encode($options['reference']).',%1$s,'.$options['parentid'].');%2$s'; 569 570 foreach ($data['table_records'] as $valuemap) { 571 $name = []; 572 $check_box = $data['multiselect'] 573 ? new CCheckBox('item['.$valuemap['id'].']', $valuemap['id']) 574 : null; 575 576 $name[] = (new CSpan($valuemap['hostname']))->addClass(ZBX_STYLE_GREY); 577 $name[] = NAME_DELIMITER; 578 579 if (array_key_exists('_disabled', $valuemap) && $valuemap['_disabled']) { 580 if ($data['multiselect']) { 581 $check_box->setChecked(1); 582 $check_box->setEnabled(false); 583 } 584 $name[] = (new CSpan($valuemap['name']))->addClass(ZBX_STYLE_GREY); 585 586 unset($data['table_records'][$valuemap['id']]); 587 } 588 else { 589 $js_action = 'addValue('.json_encode($options['reference']).', '. 590 json_encode($valuemap['id']).', '.$options['parentid'].');'; 591 592 $name[] = (new CLink($valuemap['name'], '#')) 593 ->setId('spanid'.$valuemap['id']) 594 ->onClick(sprintf($inline_js, $valuemap['id'], $js_action_onclick)); 595 } 596 597 $mappings_table = []; 598 599 foreach (array_slice($valuemap['mappings'], 0, 3) as $mapping) { 600 switch ($mapping['type']) { 601 case VALUEMAP_MAPPING_TYPE_EQUAL: 602 $value = '='.$mapping['value']; 603 break; 604 605 case VALUEMAP_MAPPING_TYPE_GREATER_EQUAL: 606 $value = '>='.$mapping['value']; 607 break; 608 609 case VALUEMAP_MAPPING_TYPE_LESS_EQUAL: 610 $value = '<='.$mapping['value']; 611 break; 612 613 case VALUEMAP_MAPPING_TYPE_DEFAULT: 614 $value = new CTag('em', true, _('default')); 615 break; 616 617 default: 618 $value = $mapping['value']; 619 } 620 621 $mappings_table[] = new CDiv($value); 622 $mappings_table[] = new CDiv('⇒'); 623 $mappings_table[] = new CDiv($mapping['newvalue']); 624 } 625 626 $hellip = (count($valuemap['mappings']) > 3) ? '…' : null; 627 $table->addRow([$check_box, $name, [ 628 (new CDiv($mappings_table))->addClass(ZBX_STYLE_VALUEMAP_MAPPINGS_TABLE), $hellip 629 ]]); 630 } 631 break; 632} 633 634// Add submit button at footer. 635if ($data['multiselect'] && $form !== null) { 636 $output['buttons'] = [ 637 [ 638 'title' => _('Select'), 639 'class' => '', 640 'isSubmit' => true, 641 'action' => 'return addSelectedValues('.zbx_jsvalue($options['reference']).', '.$options['parentid'].');' 642 ] 643 ]; 644} 645 646// Types require results returned as array. 647$types = ['users', 'usrgrp', 'templates', 'hosts', 'host_templates', 'host_groups', 'proxies', 'items', 648 'item_prototypes', 'graphs', 'graph_prototypes', 'roles', 'api_methods', 'valuemaps', 'dashboard' 649]; 650 651if (array_key_exists('table_records', $data) && (in_array($data['popup_type'], $types) || $data['multiselect'])) { 652 $output['data'] = $data['table_records']; 653} 654 655$output['script_inline'] = 656 'jQuery(document).ready(function() {'. 657 $output['script_inline']. 658 'cookie.init();'. 659 'chkbxRange.init();'. 660 '});'; 661 662if ($form) { 663 $form->addItem([ 664 $table, 665 (new CInput('submit', 'submit')) 666 ->addStyle('display: none;') 667 ->removeId() 668 ]); 669 $output['body'] = (new CDiv([$data['messages'], $form]))->toString(); 670} 671else { 672 $output['body'] = (new CDiv([$data['messages'], $table]))->toString(); 673} 674 675if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) { 676 CProfiler::getInstance()->stop(); 677 $output['debug'] = CProfiler::getInstance()->make()->toString(); 678} 679 680echo json_encode($output); 681