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