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
22require_once dirname(__FILE__).'/include/config.inc.php';
23require_once dirname(__FILE__).'/include/hosts.inc.php';
24require_once dirname(__FILE__).'/include/triggers.inc.php';
25require_once dirname(__FILE__).'/include/html.inc.php';
26
27$page['title'] = _('Dashboard configuration');
28$page['file'] = 'dashconf.php';
29$page['scripts'] = ['multiselect.js'];
30$page['type'] = detect_page_type(PAGE_TYPE_HTML);
31
32ob_start();
33
34require_once dirname(__FILE__).'/include/page_header.php';
35
36//	VAR						 TYPE		 OPTIONAL FLAGS	VALIDATION		EXCEPTION
37$fields = [
38	'filterEnable' =>	[T_ZBX_INT, O_OPT, P_SYS,			null,			null],
39	'grpswitch' =>		[T_ZBX_INT, O_OPT, P_SYS,			BETWEEN(0, 1),	null],
40	'groupids' =>		[T_ZBX_INT, O_OPT, P_SYS,			null,			null],
41	'hidegroupids' =>	[T_ZBX_INT, O_OPT, P_SYS,			null,			null],
42	'trgSeverity' =>	[T_ZBX_INT, O_OPT, P_SYS,			null,			null],
43	'trigger_name' =>	[T_ZBX_STR, O_OPT, P_SYS,			null,			null],
44	'maintenance' =>	[T_ZBX_INT, O_OPT, P_SYS,			BETWEEN(0, 1),	null],
45	'extAck' =>			[T_ZBX_INT, O_OPT, P_SYS,			null,			null],
46	'form_refresh' =>	[T_ZBX_INT, O_OPT, P_SYS,			null,			null],
47	'update' =>			[T_ZBX_STR, O_OPT, P_SYS|P_ACT,	null,			null],
48	'cancel' =>			[T_ZBX_STR, O_OPT, P_SYS,			null,			null]
49];
50check_fields($fields);
51
52/*
53 * Actions
54 */
55if (hasRequest('update')) {
56	// filter
57	$filterEnable = getRequest('filterEnable', 0);
58	CProfile::update('web.dashconf.filter.enable', $filterEnable, PROFILE_TYPE_INT);
59
60	if ($filterEnable == 1) {
61		// groups
62		CProfile::update('web.dashconf.groups.grpswitch', $_REQUEST['grpswitch'], PROFILE_TYPE_INT);
63
64		if ($_REQUEST['grpswitch'] == 1) {
65			// show groups
66			$groupIds = getRequest('groupids', []);
67
68			$result = true;
69
70			DBstart();
71
72			$result &= CFavorite::remove('web.dashconf.groups.groupids');
73			foreach ($groupIds as $groupId) {
74				$result &= CFavorite::add('web.dashconf.groups.groupids', $groupId);
75			}
76
77			// hide groups
78			$hideGroupIds = getRequest('hidegroupids', []);
79
80			$result &= CFavorite::remove('web.dashconf.groups.hide.groupids');
81			foreach ($hideGroupIds as $hideGroupId) {
82				$result &= CFavorite::add('web.dashconf.groups.hide.groupids', $hideGroupId);
83			}
84
85			DBend($result);
86		}
87
88		// hosts
89		CProfile::update('web.dashconf.hosts.maintenance', getRequest('maintenance', 0), PROFILE_TYPE_INT);
90
91		// triggers
92		CProfile::update('web.dashconf.triggers.severity',
93			implode(';', array_keys(getRequest('trgSeverity', []))), PROFILE_TYPE_STR
94		);
95		CProfile::update('web.dashconf.triggers.name', getRequest('trigger_name', ''), PROFILE_TYPE_STR);
96
97		// events
98		$config = select_config();
99		if ($config['event_ack_enable']) {
100			CProfile::update('web.dashconf.events.extAck', getRequest('extAck', 0), PROFILE_TYPE_INT);
101		}
102	}
103
104	jSredirect(ZBX_DEFAULT_URL);
105}
106elseif (hasRequest('cancel')) {
107	ob_end_clean();
108	redirect(ZBX_DEFAULT_URL);
109}
110
111ob_end_flush();
112
113/*
114 * Display
115 */
116$data = [
117	'config' => select_config()
118];
119
120if (hasRequest('form_refresh')) {
121	$data['isFilterEnable'] = getRequest('filterEnable', 0);
122	$data['maintenance'] = getRequest('maintenance', 0);
123	$data['extAck'] = getRequest('extAck', 0);
124
125	$data['severity'] = getRequest('trgSeverity', []);
126	$data['severity'] = array_keys($data['severity']);
127	$data['trigger_name'] = getRequest('trigger_name', '');
128
129	// groups
130	$data['grpswitch'] = getRequest('grpswitch', 0);
131	$data['groupIds'] = getRequest('groupids', []);
132	$data['groupIds'] = zbx_toHash($data['groupIds']);
133	$data['hideGroupIds'] = getRequest('hidegroupids', []);
134	$data['hideGroupIds'] = zbx_toHash($data['hideGroupIds']);
135}
136else {
137	$data['isFilterEnable'] = CProfile::get('web.dashconf.filter.enable', 0);
138	$data['maintenance'] = CProfile::get('web.dashconf.hosts.maintenance', 1);
139	$data['extAck'] = CProfile::get('web.dashconf.events.extAck', 0);
140
141	$data['severity'] = CProfile::get('web.dashconf.triggers.severity', '0;1;2;3;4;5');
142	$data['severity'] = zbx_empty($data['severity']) ? [] : explode(';', $data['severity']);
143	$data['trigger_name'] = CProfile::get('web.dashconf.triggers.name', '');
144
145	// groups
146	$data['grpswitch'] = CProfile::get('web.dashconf.groups.grpswitch', 0);
147	$data['groupIds'] = CFavorite::get('web.dashconf.groups.groupids');
148	$data['groupIds'] = zbx_objectValues($data['groupIds'], 'value');
149	$data['groupIds'] = zbx_toHash($data['groupIds']);
150	$data['hideGroupIds'] = CFavorite::get('web.dashconf.groups.hide.groupids');
151	$data['hideGroupIds'] = zbx_objectValues($data['hideGroupIds'], 'value');
152	$data['hideGroupIds'] = zbx_toHash($data['hideGroupIds']);
153}
154
155$data['severity'] = zbx_toHash($data['severity']);
156$data['severities'] = [
157	TRIGGER_SEVERITY_NOT_CLASSIFIED,
158	TRIGGER_SEVERITY_INFORMATION,
159	TRIGGER_SEVERITY_WARNING,
160	TRIGGER_SEVERITY_AVERAGE,
161	TRIGGER_SEVERITY_HIGH,
162	TRIGGER_SEVERITY_DISASTER
163];
164
165if ($data['grpswitch']) {
166	// show groups
167	$data['groups'] = API::HostGroup()->get([
168		'groupids' => $data['groupIds'],
169		'output' => ['groupid', 'name']
170	]);
171
172	CArrayHelper::sort($data['groups'], [
173		['field' => 'name', 'order' => ZBX_SORT_UP]
174	]);
175
176	foreach ($data['groups'] as &$group) {
177		$group['id'] = $group['groupid'];
178
179		unset($group['groupid']);
180	}
181	unset($group);
182
183	// hide groups
184	$data['hideGroups'] = API::HostGroup()->get([
185		'groupids' => $data['hideGroupIds'],
186		'output' => ['groupid', 'name']
187	]);
188
189	CArrayHelper::sort($data['hideGroups'], [
190		['field' => 'name', 'order' => ZBX_SORT_UP]
191	]);
192
193	foreach ($data['hideGroups'] as &$group) {
194		$group['id'] = $group['groupid'];
195
196		unset($group['groupid']);
197	}
198	unset($group);
199}
200
201// render view
202$dashconfView = new CView('monitoring.dashconf', $data);
203$dashconfView->render();
204$dashconfView->show();
205
206require_once dirname(__FILE__).'/include/page_footer.php';
207