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