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 * Problems widget form.
24 */
25class CWidgetFormProblems extends CWidgetForm {
26
27	public function __construct($data) {
28		parent::__construct($data, WIDGET_PROBLEMS);
29
30		$this->data = self::convertDottedKeys($this->data);
31
32		// Output information option.
33		$field_show = (new CWidgetFieldRadioButtonList('show', _('Show'), [
34			TRIGGERS_OPTION_RECENT_PROBLEM => _('Recent problems'),
35			TRIGGERS_OPTION_IN_PROBLEM => _('Problems'),
36			TRIGGERS_OPTION_ALL => _('History')
37		]))
38			->setDefault(TRIGGERS_OPTION_RECENT_PROBLEM)
39			->setModern(true);
40
41		if (array_key_exists('show', $this->data)) {
42			$field_show->setValue($this->data['show']);
43		}
44
45		$this->fields[$field_show->getName()] = $field_show;
46
47		// Host groups.
48		$field_groups = new CWidgetFieldMsGroup('groupids', _('Host groups'));
49
50		if (array_key_exists('groupids', $this->data)) {
51			$field_groups->setValue($this->data['groupids']);
52		}
53
54		$this->fields[$field_groups->getName()] = $field_groups;
55
56		// Exclude host groups.
57		$field_exclude_groups = new CWidgetFieldMsGroup('exclude_groupids', _('Exclude host groups'));
58
59		if (array_key_exists('exclude_groupids', $this->data)) {
60			$field_exclude_groups->setValue($this->data['exclude_groupids']);
61		}
62
63		$this->fields[$field_exclude_groups->getName()] = $field_exclude_groups;
64
65		// Hosts field.
66		$field_hosts = new CWidgetFieldMsHost('hostids', _('Hosts'));
67		$field_hosts->filter_preselect_host_group_field = 'groupids_';
68
69		if (array_key_exists('hostids', $this->data)) {
70			$field_hosts->setValue($this->data['hostids']);
71		}
72
73		$this->fields[$field_hosts->getName()] = $field_hosts;
74
75		// Problem field.
76		$field_problem = new CWidgetFieldTextBox('problem', _('Problem'));
77
78		if (array_key_exists('problem', $this->data)) {
79			$field_problem->setValue($this->data['problem']);
80		}
81
82		$this->fields[$field_problem->getName()] = $field_problem;
83
84		// Severity field.
85		$field_severities = new CWidgetFieldSeverities('severities', _('Severity'));
86
87		if (array_key_exists('severities', $this->data)) {
88			$field_severities->setValue($this->data['severities']);
89		}
90
91		$this->fields[$field_severities->getName()] = $field_severities;
92
93		// Tag evaltype (And/Or).
94		$field_evaltype = (new CWidgetFieldRadioButtonList('evaltype', _('Tags'), [
95			TAG_EVAL_TYPE_AND_OR => _('And/Or'),
96			TAG_EVAL_TYPE_OR => _('Or')
97		]))
98			->setDefault(TAG_EVAL_TYPE_AND_OR)
99			->setModern(true);
100
101		if (array_key_exists('evaltype', $this->data)) {
102			$field_evaltype->setValue($this->data['evaltype']);
103		}
104
105		$this->fields[$field_evaltype->getName()] = $field_evaltype;
106
107		// Tags array: tag, operator and value. No label, because it belongs to previous group.
108		$field_tags = new CWidgetFieldTags('tags', '');
109
110		if (array_key_exists('tags', $this->data)) {
111			$field_tags->setValue($this->data['tags']);
112		}
113
114		$this->fields[$field_tags->getName()] = $field_tags;
115
116		// Show tags.
117		$field_show_tags = (new CWidgetFieldRadioButtonList('show_tags', _('Show tags'), [
118			PROBLEMS_SHOW_TAGS_NONE => _('None'),
119			PROBLEMS_SHOW_TAGS_1 => PROBLEMS_SHOW_TAGS_1,
120			PROBLEMS_SHOW_TAGS_2 => PROBLEMS_SHOW_TAGS_2,
121			PROBLEMS_SHOW_TAGS_3 => PROBLEMS_SHOW_TAGS_3
122		]))
123			->setDefault(PROBLEMS_SHOW_TAGS_NONE)
124			->setModern(true)
125			->setAction('var disabled = jQuery(this).filter("[value=\''.PROBLEMS_SHOW_TAGS_NONE.'\']").is(":checked");'.
126				'jQuery("#tag_priority").prop("disabled", disabled);'.
127				'jQuery("#tag_name_format input").prop("disabled", disabled)'
128			);
129
130		if (array_key_exists('show_tags', $this->data)) {
131			$field_show_tags->setValue($this->data['show_tags']);
132		}
133
134		$this->fields[$field_show_tags->getName()] = $field_show_tags;
135
136		// Tag name.
137		$tag_format_line = (new CWidgetFieldRadioButtonList('tag_name_format', _('Tag name'), [
138			PROBLEMS_TAG_NAME_FULL => _('Full'),
139			PROBLEMS_TAG_NAME_SHORTENED => _('Shortened'),
140			PROBLEMS_TAG_NAME_NONE => _('None')
141		]))
142			->setDefault(PROBLEMS_TAG_NAME_FULL)
143			->setModern(true);
144
145		if (array_key_exists('tag_name_format', $this->data)) {
146			$tag_format_line->setValue($this->data['tag_name_format']);
147		}
148		$this->fields[$tag_format_line->getName()] = $tag_format_line;
149
150		// Tag display priority.
151		$tag_priority = (new CWidgetFieldTextBox('tag_priority', _('Tag display priority')));
152
153		if (array_key_exists('tag_priority', $this->data)) {
154			$tag_priority->setValue($this->data['tag_priority']);
155		}
156		$this->fields[$tag_priority->getName()] = $tag_priority;
157
158		// Show operational data.
159		$field_show_opdata = (new CWidgetFieldRadioButtonList('show_opdata', _('Show operational data'), [
160			OPERATIONAL_DATA_SHOW_NONE => _('None'),
161			OPERATIONAL_DATA_SHOW_SEPARATELY => _('Separately'),
162			OPERATIONAL_DATA_SHOW_WITH_PROBLEM => _('With problem name')
163		]))
164			->setDefault(OPERATIONAL_DATA_SHOW_NONE)
165			->setModern(true);
166
167		if (array_key_exists('show_opdata', $this->data)) {
168			$field_show_opdata->setValue($this->data['show_opdata']);
169		}
170
171		$this->fields[$field_show_opdata->getName()] = $field_show_opdata;
172
173		// Show suppressed problems.
174		$field_show_suppressed = (new CWidgetFieldCheckBox('show_suppressed', _('Show suppressed problems')))
175			->setDefault(ZBX_PROBLEM_SUPPRESSED_FALSE);
176
177		if (array_key_exists('show_suppressed', $this->data)) {
178			$field_show_suppressed->setValue($this->data['show_suppressed']);
179		}
180
181		$this->fields[$field_show_suppressed->getName()] = $field_show_suppressed;
182
183		// Show unacknowledged only.
184		$field_unacknowledged = (new CWidgetFieldCheckBox('unacknowledged', _('Show unacknowledged only')))
185			->setFlags(CWidgetField::FLAG_ACKNOWLEDGES);
186
187		if (array_key_exists('unacknowledged', $this->data)) {
188			$field_unacknowledged->setValue($this->data['unacknowledged']);
189		}
190
191		$this->fields[$field_unacknowledged->getName()] = $field_unacknowledged;
192
193		$sort_with_enabled_show_timeline = [
194			SCREEN_SORT_TRIGGERS_TIME_DESC => true,
195			SCREEN_SORT_TRIGGERS_TIME_ASC => true
196		];
197
198		// Sort entries by.
199		$field_sort = (new CWidgetFieldSelect('sort_triggers', _('Sort entries by'), [
200			SCREEN_SORT_TRIGGERS_TIME_DESC => _('Time').' ('._('descending').')',
201			SCREEN_SORT_TRIGGERS_TIME_ASC => _('Time').' ('._('ascending').')',
202			SCREEN_SORT_TRIGGERS_SEVERITY_DESC => _('Severity').' ('._('descending').')',
203			SCREEN_SORT_TRIGGERS_SEVERITY_ASC => _('Severity').' ('._('ascending').')',
204			SCREEN_SORT_TRIGGERS_NAME_DESC => _('Problem').' ('._('descending').')',
205			SCREEN_SORT_TRIGGERS_NAME_ASC => _('Problem').' ('._('ascending').')',
206			SCREEN_SORT_TRIGGERS_HOST_NAME_DESC => _('Host').' ('._('descending').')',
207			SCREEN_SORT_TRIGGERS_HOST_NAME_ASC => _('Host').' ('._('ascending').')'
208		]))
209			->setDefault(SCREEN_SORT_TRIGGERS_TIME_DESC);
210
211		if (array_key_exists('sort_triggers', $this->data)) {
212			$field_sort->setValue($this->data['sort_triggers']);
213		}
214
215		$this->fields[$field_sort->getName()] = $field_sort;
216
217		// Show timeline.
218		$field_show_timeline = (new CWidgetFieldCheckBox('show_timeline', _('Show timeline')))->setDefault(1);
219
220		if (array_key_exists('show_timeline', $this->data)) {
221			$field_show_timeline->setValue($this->data['show_timeline']);
222		}
223
224		if (!array_key_exists($field_sort->getValue(), $sort_with_enabled_show_timeline)) {
225			$field_show_timeline->setFlags(CWidgetField::FLAG_DISABLED);
226		}
227
228		$this->fields[$field_show_timeline->getName()] = $field_show_timeline;
229
230		// Show lines.
231		$field_lines = (new CWidgetFieldIntegerBox('show_lines', _('Show lines'), ZBX_MIN_WIDGET_LINES,
232			ZBX_MAX_WIDGET_LINES
233		))
234			->setFlags(CWidgetField::FLAG_LABEL_ASTERISK)
235			->setDefault(ZBX_DEFAULT_WIDGET_LINES);
236
237		if (array_key_exists('show_lines', $this->data)) {
238			$field_lines->setValue($this->data['show_lines']);
239		}
240
241		$this->fields[$field_lines->getName()] = $field_lines;
242	}
243}
244