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$this->addJsFile('multiselect.js');
27$this->addJsFile('layout.mode.js');
28
29$this->includeJsFile('monitoring.latest.view.js.php');
30
31$this->enableLayoutModes();
32$web_layout_mode = $this->getLayoutMode();
33
34$widget = (new CWidget())
35	->setTitle(_('Latest data'))
36	->setWebLayoutMode($web_layout_mode)
37	->setControls(
38		(new CTag('nav', true, (new CList())->addItem(get_icon('kioskmode', ['mode' => $web_layout_mode]))))
39			->setAttribute('aria-label', _('Content controls'))
40	);
41
42if ($web_layout_mode == ZBX_LAYOUT_NORMAL) {
43	$widget->addItem((new CFilter((new CUrl('zabbix.php'))->setArgument('action', 'latest.view')))
44		->setProfile('web.latest.filter')
45		->setActiveTab($data['active_tab'])
46		->addFormItem((new CVar('action', 'latest.view'))->removeId())
47		->addFilterTab(_('Filter'), [
48			(new CFormList())
49				->addRow((new CLabel(_('Host groups'), 'filter_groupids__ms')),
50					(new CMultiSelect([
51						'name' => 'filter_groupids[]',
52						'object_name' => 'hostGroup',
53						'data' => $data['multiselect_hostgroup_data'],
54						'popup' => [
55							'parameters' => [
56								'srctbl' => 'host_groups',
57								'srcfld1' => 'groupid',
58								'dstfrm' => 'zbx_filter',
59								'dstfld1' => 'filter_groupids_',
60								'real_hosts' => true,
61								'enrich_parent_groups' => true
62							]
63						]
64					]))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH)
65				)
66				->addRow((new CLabel(_('Hosts'), 'filter_hostids__ms')),
67					(new CMultiSelect([
68						'name' => 'filter_hostids[]',
69						'object_name' => 'hosts',
70						'data' => $data['multiselect_host_data'],
71						'popup' => [
72							'filter_preselect_fields' => [
73								'hostgroups' => 'filter_groupids_'
74							],
75							'parameters' => [
76								'srctbl' => 'hosts',
77								'srcfld1' => 'hostid',
78								'dstfrm' => 'zbx_filter',
79								'dstfld1' => 'filter_hostids_'
80							]
81						]
82					]))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH)
83				)
84				->addRow(_('Application'), [
85					(new CTextBox('filter_application', $data['filter']['application']))
86						->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH),
87					(new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN),
88					(new CButton('application_name', _('Select')))
89						->addClass(ZBX_STYLE_BTN_GREY)
90						->onClick('return PopUp("popup.generic", jQuery.extend('.
91							json_encode([
92								'srctbl' => 'applications',
93								'srcfld1' => 'name',
94								'dstfrm' => 'zbx_filter',
95								'dstfld1' => 'filter_application',
96								'real_hosts' => '1',
97								'with_applications' => '1'
98							]).', getFirstMultiselectValue("filter_hostids_")), null, this);'
99						)
100				]),
101			(new CFormList())
102				->addRow(_('Name'), (new CTextBox('filter_select', $data['filter']['select']))
103					->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH)
104				)
105				->addRow(_('Show items without data'),
106					(new CCheckBox('filter_show_without_data'))
107						->setChecked($data['filter']['show_without_data'] == 1)
108						->setAttribute('disabled', $data['filter']['hostids'] ? null : 'disabled')
109						->setUncheckedValue(0)
110				)
111				->addRow(_('Show details'),
112					(new CCheckBox('filter_show_details'))->setChecked($data['filter']['show_details'] == 1)
113				)
114		])
115	);
116}
117
118$widget->addItem(new CPartial('monitoring.latest.view.html', array_intersect_key($data, array_flip(['filter',
119	'sort_field', 'sort_order', 'view_curl', 'paging', 'rows', 'hosts', 'applications', 'applications_size',
120	'applications_index', 'items', 'history', 'collapsed_index', 'collapsed_all'
121]))));
122
123$widget->show();
124
125// Initialize page refresh.
126(new CScriptTag('latest_page.start();'))
127	->setOnDocumentReady()
128	->show();
129