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$options = [
23	'resourcetype' => SCREEN_RESOURCE_PROBLEM,
24	'mode' => SCREEN_MODE_JS,
25	'dataId' => 'problem',
26	'page' => $data['page'],
27	'data' => [
28		'action' => $data['action'],
29		'sort' => $data['sort'],
30		'sortorder' => $data['sortorder'],
31		'page' => $data['page'],
32		'filter' => [
33			'show' => $data['filter']['show'],
34			'groupids' => $data['filter']['groupids'],
35			'hostids' => $data['filter']['hostids'],
36			'application' => $data['filter']['application'],
37			'triggerids' => $data['filter']['triggerids'],
38			'name' => $data['filter']['name'],
39			'severity' => $data['filter']['severity'],
40			'inventory' => $data['filter']['inventory'],
41			'evaltype' => $data['filter']['evaltype'],
42			'tags' => $data['filter']['tags'],
43			'show_tags' => $data['filter']['show_tags'],
44			'tag_name_format' => $data['filter']['tag_name_format'],
45			'tag_priority' => $data['filter']['tag_priority'],
46			'show_suppressed' => $data['filter']['show_suppressed'],
47			'unacknowledged' => $data['filter']['unacknowledged'],
48			'compact_view' => $data['filter']['compact_view'],
49			'show_timeline' => $data['filter']['show_timeline'],
50			'details' => $data['filter']['details'],
51			'highlight_row' => $data['filter']['highlight_row'],
52			'show_latest_values' => $data['filter']['show_latest_values']
53		]
54	]
55];
56
57switch ($data['filter']['show']) {
58	case TRIGGERS_OPTION_RECENT_PROBLEM:
59	case TRIGGERS_OPTION_IN_PROBLEM:
60		$options['data']['filter']['age_state'] = $data['filter']['age_state'];
61		$options['data']['filter']['age'] = $data['filter']['age'];
62		break;
63
64	case TRIGGERS_OPTION_ALL:
65		$options['profileIdx'] = $data['profileIdx'];
66		$options['profileIdx2'] = $data['profileIdx2'];
67		$options['from'] = $data['from'];
68		$options['to'] = $data['to'];
69		break;
70}
71
72$screen = CScreenBuilder::getScreen($options);
73
74if ($data['action'] == 'problem.view') {
75	if ($data['filter']['show'] == TRIGGERS_OPTION_ALL) {
76		$this->addJsFile('class.calendar.js');
77	}
78	$this->addJsFile('gtlc.js');
79	$this->addJsFile('flickerfreescreen.js');
80	$this->addJsFile('multiselect.js');
81	$this->addJsFile('layout.mode.js');
82	require_once dirname(__FILE__).'/monitoring.problem.view.js.php';
83
84	if ($data['uncheck']) {
85		uncheckTableRows('problem');
86	}
87
88	$filter_column1 = (new CFormList())
89		->addRow(_('Show'),
90			(new CRadioButtonList('filter_show', (int) $data['filter']['show']))
91				->addValue(_('Recent problems'), TRIGGERS_OPTION_RECENT_PROBLEM)
92				->addValue(_('Problems'), TRIGGERS_OPTION_IN_PROBLEM)
93				->addValue(_('History'), TRIGGERS_OPTION_ALL)
94				->setModern(true)
95		)
96		->addRow((new CLabel(_('Host groups'), 'filter_groupids__ms')),
97			(new CMultiSelect([
98				'name' => 'filter_groupids[]',
99				'object_name' => 'hostGroup',
100				'data' => $data['filter']['groups'],
101				'popup' => [
102					'parameters' => [
103						'srctbl' => 'host_groups',
104						'srcfld1' => 'groupid',
105						'dstfrm' => 'zbx_filter',
106						'dstfld1' => 'filter_groupids_',
107						'real_hosts' => true,
108						'enrich_parent_groups' => true
109					]
110				]
111			]))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH)
112		)
113		->addRow((new CLabel(_('Hosts'), 'filter_hostids__ms')),
114			(new CMultiSelect([
115				'name' => 'filter_hostids[]',
116				'object_name' => 'hosts',
117				'data' => $data['filter']['hosts'],
118				'popup' => [
119					'parameters' => [
120						'srctbl' => 'hosts',
121						'srcfld1' => 'hostid',
122						'dstfrm' => 'zbx_filter',
123						'dstfld1' => 'filter_hostids_'
124					]
125				]
126			]))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH)
127		)
128		->addRow(_('Application'), [
129			(new CTextBox('filter_application', $data['filter']['application']))
130				->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH),
131			(new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN),
132			(new CButton('filter_application_select', _('Select')))
133				->onClick('return PopUp("popup.generic",'.
134					CJs::encodeJson([
135						'srctbl' => 'applications',
136						'srcfld1' => 'name',
137						'dstfrm' => 'zbx_filter',
138						'dstfld1' => 'filter_application',
139						'with_applications' => '1',
140						'real_hosts' => '1'
141					]).', null, this);'
142				)
143				->addClass(ZBX_STYLE_BTN_GREY)
144		])
145		->addRow((new CLabel(_('Triggers'), 'filter_triggerids__ms')),
146			(new CMultiSelect([
147				'name' => 'filter_triggerids[]',
148				'object_name' => 'triggers',
149				'data' => $data['filter']['triggers'],
150				'popup' => [
151					'parameters' => [
152						'srctbl' => 'triggers',
153						'srcfld1' => 'triggerid',
154						'dstfrm' => 'zbx_filter',
155						'dstfld1' => 'filter_triggerids_',
156						'monitored_hosts' => true,
157						'with_monitored_triggers' => true,
158						'noempty' => true
159					]
160				]
161			]))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH)
162		)
163		->addRow(_('Problem'),
164			(new CTextBox('filter_name', $data['filter']['name']))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH)
165		)
166		->addRow(_('Minimum severity'),
167			new CComboBox('filter_severity', $data['filter']['severity'], null, $data['filter']['severities'])
168		);
169
170	$filter_age = (new CNumericBox('filter_age', $data['filter']['age'], 3, false, false, false))
171		->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH);
172	if ($data['filter']['age_state'] == 0) {
173		$filter_age->setAttribute('disabled', 'disabled');
174	}
175
176	$filter_column1
177		->addRow(_('Age less than'), [
178			(new CCheckBox('filter_age_state'))
179				->setChecked($data['filter']['age_state'] == 1)
180				->onClick('javascript: this.checked ? $("filter_age").enable() : $("filter_age").disable()'),
181			(new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN),
182			$filter_age,
183			(new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN),
184			_('days')
185		]);
186
187	$filter_inventory = $data['filter']['inventory'];
188	if (!$filter_inventory) {
189		$filter_inventory = [['field' => '', 'value' => '']];
190	}
191
192	$filter_inventory_table = new CTable();
193	$filter_inventory_table->setId('filter-inventory');
194	$i = 0;
195	foreach ($filter_inventory as $field) {
196		$filter_inventory_table->addRow([
197			new CComboBox('filter_inventory['.$i.'][field]', $field['field'], null, $data['filter']['inventories']),
198			(new CTextBox('filter_inventory['.$i.'][value]', $field['value']))->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH),
199			(new CCol(
200				(new CButton('filter_inventory['.$i.'][remove]', _('Remove')))
201					->addClass(ZBX_STYLE_BTN_LINK)
202					->addClass('element-table-remove')
203			))->addClass(ZBX_STYLE_NOWRAP)
204		], 'form_row');
205
206		$i++;
207	}
208	$filter_inventory_table->addRow(
209		(new CCol(
210			(new CButton('filter_inventory_add', _('Add')))
211				->addClass(ZBX_STYLE_BTN_LINK)
212				->addClass('element-table-add')
213		))->setColSpan(3)
214	);
215
216	$filter_tags = $data['filter']['tags'];
217	if (!$filter_tags) {
218		$filter_tags = [['tag' => '', 'value' => '', 'operator' => TAG_OPERATOR_LIKE]];
219	}
220
221	$filter_tags_table = new CTable();
222	$filter_tags_table->setId('filter-tags');
223
224	$filter_tags_table->addRow(
225		(new CCol(
226			(new CRadioButtonList('filter_evaltype', (int) $data['filter']['evaltype']))
227				->addValue(_('And/Or'), TAG_EVAL_TYPE_AND_OR)
228				->addValue(_('Or'), TAG_EVAL_TYPE_OR)
229				->setModern(true)
230		))->setColSpan(4)
231	);
232
233	$i = 0;
234	foreach ($filter_tags as $tag) {
235		$filter_tags_table->addRow([
236			(new CTextBox('filter_tags['.$i.'][tag]', $tag['tag']))
237				->setAttribute('placeholder', _('tag'))
238				->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH),
239			(new CRadioButtonList('filter_tags['.$i.'][operator]', (int) $tag['operator']))
240				->addValue(_('Contains'), TAG_OPERATOR_LIKE)
241				->addValue(_('Equals'), TAG_OPERATOR_EQUAL)
242				->setModern(true),
243			(new CTextBox('filter_tags['.$i.'][value]', $tag['value']))
244				->setAttribute('placeholder', _('value'))
245				->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH),
246			(new CCol(
247				(new CButton('filter_tags['.$i.'][remove]', _('Remove')))
248					->addClass(ZBX_STYLE_BTN_LINK)
249					->addClass('element-table-remove')
250			))->addClass(ZBX_STYLE_NOWRAP)
251		], 'form_row');
252
253		$i++;
254	}
255	$filter_tags_table->addRow(
256		(new CCol(
257			(new CButton('filter_tags_add', _('Add')))
258				->addClass(ZBX_STYLE_BTN_LINK)
259				->addClass('element-table-add')
260		))->setColSpan(3)
261	);
262
263	$tag_format_line = (new CHorList())
264		->addItem((new CRadioButtonList('filter_show_tags', (int) $data['filter']['show_tags']))
265				->addValue(_('None'), PROBLEMS_SHOW_TAGS_NONE)
266				->addValue(PROBLEMS_SHOW_TAGS_1, PROBLEMS_SHOW_TAGS_1)
267				->addValue(PROBLEMS_SHOW_TAGS_2, PROBLEMS_SHOW_TAGS_2)
268				->addValue(PROBLEMS_SHOW_TAGS_3, PROBLEMS_SHOW_TAGS_3)
269				->setModern(true)
270		)
271		->addItem((new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN))
272		->addItem(_('Tag name'))
273		->addItem((new CRadioButtonList('filter_tag_name_format', (int) $data['filter']['tag_name_format']))
274				->addValue(_('Full'), PROBLEMS_TAG_NAME_FULL)
275				->addValue(_('Shortened'), PROBLEMS_TAG_NAME_SHORTENED)
276				->addValue(_('None'), PROBLEMS_TAG_NAME_NONE)
277				->setModern(true)
278				->setEnabled((int) $data['filter']['show_tags'] !== PROBLEMS_SHOW_TAGS_NONE)
279		);
280
281	$filter_column2 = (new CFormList())
282		->addRow(_('Host inventory'), $filter_inventory_table)
283		->addRow(_('Tags'), $filter_tags_table)
284		->addRow(_('Show tags'), $tag_format_line)
285		->addRow(_('Tag display priority'),
286			(new CTextBox('filter_tag_priority', $data['filter']['tag_priority']))
287				->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH)
288				->setAttribute('placeholder', _('comma-separated list'))
289				->setEnabled((int) $data['filter']['show_tags'] !== PROBLEMS_SHOW_TAGS_NONE)
290		)
291		->addRow(_('Show suppressed problems'), [
292			(new CCheckBox('filter_show_suppressed'))
293				->setChecked($data['filter']['show_suppressed'] == ZBX_PROBLEM_SUPPRESSED_TRUE),
294			(new CDiv([
295				(new CLabel(_('Show unacknowledged only'), 'filter_unacknowledged'))
296					->addClass(ZBX_STYLE_SECOND_COLUMN_LABEL),
297				(new CCheckBox('filter_unacknowledged'))
298					->setChecked($data['filter']['unacknowledged'] == 1)
299			]))->addClass(ZBX_STYLE_TABLE_FORMS_SECOND_COLUMN)
300		])
301		->addRow(_('Compact view'), [
302			(new CCheckBox('filter_compact_view'))->setChecked($data['filter']['compact_view'] == 1),
303			(new CDiv([
304				(new CLabel(_('Show timeline'), 'filter_show_timeline'))->addClass(ZBX_STYLE_SECOND_COLUMN_LABEL),
305				(new CCheckBox('filter_show_timeline'))
306					->setChecked($data['filter']['show_timeline'] == 1)
307					->setEnabled($data['filter']['compact_view'] == 0)
308			]))->addClass(ZBX_STYLE_TABLE_FORMS_SECOND_COLUMN)
309		])
310		->addRow(_('Show details'), [
311			(new CCheckBox('filter_details'))
312				->setChecked($data['filter']['details'] == 1)
313				->setEnabled($data['filter']['compact_view'] == 0),
314			(new CDiv([
315				(new CLabel(_('Highlight whole row'), 'filter_highlight_row'))->addClass(ZBX_STYLE_SECOND_COLUMN_LABEL),
316				(new CCheckBox('filter_highlight_row'))
317					->setChecked($data['filter']['highlight_row'] == 1)
318					->setEnabled($data['filter']['compact_view'] == 1)
319			]))
320				->addClass(ZBX_STYLE_FILTER_HIGHLIGHT_ROW_CB)
321				->addClass(ZBX_STYLE_TABLE_FORMS_SECOND_COLUMN)
322		])
323		->addRow(_('Show latest values'), [
324			(new CCheckBox('filter_show_latest_values'))
325				->setChecked($data['filter']['show_latest_values'] == 1)
326				->setEnabled($data['filter']['compact_view'] == 0)
327		]);
328
329	$filter = (new CFilter((new CUrl('zabbix.php'))->setArgument('action', 'problem.view')))
330		->setProfile($data['profileIdx'])
331		->setActiveTab($data['active_tab'])
332		->addFormItem((new CVar('action', 'problem.view'))->removeId())
333		->addFormItem((new CVar('page', $data['page']))->removeId());
334
335	if ($data['filter']['show'] == TRIGGERS_OPTION_ALL) {
336		$filter->addTimeSelector($screen->timeline['from'], $screen->timeline['to']);
337	}
338
339	$filter->addFilterTab(_('Filter'), [$filter_column1, $filter_column2]);
340
341	$web_layout_mode = CView::getLayoutMode();
342
343	$widget = (new CWidget())
344		->setTitle(_('Problems'))
345		->setWebLayoutMode($web_layout_mode)
346		->setControls((new CTag('nav', true,
347			(new CForm('get'))
348				->cleanItems()
349				->addVar('action', 'problem.view')
350				->addVar('page', $data['page'])
351				->addItem((new CList())
352					->addItem(new CRedirectButton(_('Export to CSV'),
353						(new CUrl('zabbix.php'))
354							->setArgument('action', 'problem.view.csv')
355							->setArgument('page',  $data['page'])
356					))
357					->addItem(get_icon('fullscreen'))
358				)
359			))
360				->setAttribute('aria-label', _('Content controls'))
361		);
362
363	if (in_array($web_layout_mode, [ZBX_LAYOUT_NORMAL, ZBX_LAYOUT_FULLSCREEN])) {
364		$widget->addItem($filter);
365	}
366
367	$widget
368		->addItem($screen->get())
369		->show();
370
371	// activating blinking
372	$this->addPostJS('jqBlink.blink();');
373
374	if ($data['filter']['show'] == TRIGGERS_OPTION_ALL) {
375		$objData = [
376			'id' => 'timeline_1',
377			'loadSBox' => 0,
378			'loadImage' => 0,
379			'dynamic' => 0,
380			'mainObject' => 1
381		];
382
383		$this->addPostJS('timeControl.addObject("scroll_events_id", '.zbx_jsvalue($screen->timeline).', '.zbx_jsvalue($objData).');');
384		$this->addPostJS('timeControl.processObjects();');
385	}
386}
387else {
388	echo $screen->get();
389}
390