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/maintenances.inc.php';
25require_once dirname(__FILE__).'/include/forms.inc.php';
26
27$page['title'] = _('Configuration of maintenance periods');
28$page['file'] = 'maintenance.php';
29$page['scripts'] = ['class.calendar.js', 'multiselect.js'];
30
31require_once dirname(__FILE__).'/include/page_header.php';
32
33// VAR	TYPE	OPTIONAL	FLAGS	VALIDATION	EXCEPTION
34$fields = [
35	'hostids' =>							[T_ZBX_INT, O_OPT, P_SYS,	DB_ID,		null],
36	'groupids' =>							[T_ZBX_INT, O_OPT, P_SYS,	DB_ID,		null],
37	'groupid' =>							[T_ZBX_INT, O_OPT, P_SYS,	DB_ID,		null],
38	// maintenance
39	'maintenanceid' =>						[T_ZBX_INT, O_OPT, P_SYS,	DB_ID,		'isset({form}) && {form} == "update"'],
40	'maintenanceids' =>						[T_ZBX_INT, O_OPT, P_SYS,	DB_ID, 		null],
41	'mname' =>								[T_ZBX_STR, O_OPT, null,	NOT_EMPTY,	'isset({add}) || isset({update})', _('Name')],
42	'maintenance_type' =>					[T_ZBX_INT, O_OPT, null,	null,		'isset({add}) || isset({update})'],
43	'description' =>						[T_ZBX_STR, O_OPT, null,	null,		'isset({add}) || isset({update})'],
44	'active_since' =>						[T_ZBX_ABS_TIME, O_OPT, null, NOT_EMPTY,
45												'isset({add}) || isset({update})', _('Active since')
46											],
47	'active_till' =>						[T_ZBX_ABS_TIME, O_OPT, null, NOT_EMPTY,
48												'isset({add}) || isset({update})', _('Active till')
49											],
50	'new_timeperiod_start_date' =>			[T_ZBX_ABS_TIME, O_OPT, null, 	NOT_EMPTY,	null, _('Date')],
51	'new_timeperiod' =>						[T_ZBX_STR, O_OPT, null,	null,		'isset({add_timeperiod})'],
52	'timeperiods' =>						[T_ZBX_STR, O_OPT, null,	null,		null],
53	'del_timeperiodid' =>					[T_ZBX_STR, O_OPT, P_ACT,	null,		null],
54	'edit_timeperiodid' =>					[T_ZBX_STR, O_OPT, P_ACT,	null,		null],
55	'tags_evaltype' =>						[T_ZBX_INT, O_OPT, null,	null,		null],
56	'tags' =>								[T_ZBX_STR, O_OPT, null,	null,		null],
57	// actions
58	'action' =>								[T_ZBX_STR, O_OPT, P_SYS|P_ACT, IN('"maintenance.massdelete"'), null],
59	'add_timeperiod' =>						[T_ZBX_STR, O_OPT, P_SYS|P_ACT, null,	null],
60	'cancel_new_timeperiod' =>				[T_ZBX_STR, O_OPT, P_SYS, null,	null],
61	'add' =>								[T_ZBX_STR, O_OPT, P_SYS|P_ACT, null,	null],
62	'update' =>								[T_ZBX_STR, O_OPT, P_SYS|P_ACT, null,	null],
63	'clone' =>								[T_ZBX_STR, O_OPT, P_SYS|P_ACT, null,	null],
64	'delete' =>								[T_ZBX_STR, O_OPT, P_SYS|P_ACT, null,	null],
65	'cancel' =>								[T_ZBX_STR, O_OPT, P_SYS,		 null,	null],
66	// form
67	'form' =>								[T_ZBX_STR, O_OPT, P_SYS,	null,		null],
68	'form_refresh' =>						[T_ZBX_INT, O_OPT, null,	null,		null],
69	// filter
70	'filter_set' =>							[T_ZBX_STR, O_OPT, P_SYS,	null,		null],
71	'filter_rst' =>							[T_ZBX_STR, O_OPT, P_SYS,	null,		null],
72	'filter_name' =>						[T_ZBX_STR, O_OPT, null,	null,		null],
73	'filter_status' =>						[T_ZBX_INT, O_OPT, null,	IN([-1, MAINTENANCE_STATUS_ACTIVE, MAINTENANCE_STATUS_APPROACH, MAINTENANCE_STATUS_EXPIRED]), null],
74	// sort and sortorder
75	'sort' =>								[T_ZBX_STR, O_OPT, P_SYS,
76												IN('"active_since","active_till","maintenance_type","name"'),
77												null
78											],
79	'sortorder' =>							[T_ZBX_STR, O_OPT, P_SYS, IN('"'.ZBX_SORT_DOWN.'","'.ZBX_SORT_UP.'"'),
80												null
81											]
82];
83
84check_fields($fields);
85
86/*
87 * Permissions
88 */
89if (getRequest('groupid') && !isWritableHostGroups([getRequest('groupid')])) {
90	access_deny();
91}
92if (isset($_REQUEST['maintenanceid'])) {
93	$dbMaintenance = API::Maintenance()->get([
94		'output' => API_OUTPUT_EXTEND,
95		'selectTimeperiods' => API_OUTPUT_EXTEND,
96		'selectTags' => API_OUTPUT_EXTEND,
97		'editable' => true,
98		'maintenanceids' => getRequest('maintenanceid')
99	]);
100	if (empty($dbMaintenance)) {
101		access_deny();
102	}
103}
104if (hasRequest('action') && (!hasRequest('maintenanceids') || !is_array(getRequest('maintenanceids')))) {
105	access_deny();
106}
107
108/*
109 * Actions
110 */
111if (isset($_REQUEST['clone']) && isset($_REQUEST['maintenanceid'])) {
112	unset($_REQUEST['maintenanceid']);
113	$_REQUEST['form'] = 'clone';
114}
115elseif (isset($_REQUEST['cancel_new_timeperiod'])) {
116	unset($_REQUEST['new_timeperiod']);
117}
118elseif (hasRequest('add') || hasRequest('update')) {
119	if (hasRequest('update')) {
120		$messageSuccess = _('Maintenance updated');
121		$messageFailed = _('Cannot update maintenance');
122	}
123	else {
124		$messageSuccess = _('Maintenance added');
125		$messageFailed = _('Cannot add maintenance');
126	}
127
128	$result = true;
129	$absolute_time_parser = new CAbsoluteTimeParser();
130
131	$absolute_time_parser->parse(getRequest('active_since'));
132	$active_since_date = $absolute_time_parser->getDateTime(true);
133
134	$absolute_time_parser->parse(getRequest('active_till'));
135	$active_till_date = $absolute_time_parser->getDateTime(true);
136
137	if (!validateDateInterval($active_since_date->format('Y'), $active_since_date->format('m'),
138			$active_since_date->format('d'))) {
139		info(_s('"%s" must be between 1970.01.01 and 2038.01.18.', _('Active since')));
140		$result = false;
141	}
142
143	if (!validateDateInterval($active_till_date->format('Y'), $active_till_date->format('m'),
144			$active_till_date->format('d'))) {
145		info(_s('"%s" must be between 1970.01.01 and 2038.01.18.', _('Active till')));
146		$result = false;
147	}
148
149	if ($result) {
150		$timeperiods = getRequest('timeperiods', []);
151
152		foreach ($timeperiods as &$timeperiod) {
153			if ($timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_ONETIME) {
154				$absolute_time_parser->parse($timeperiod['start_date']);
155				$timeperiod['start_date'] = $absolute_time_parser
156					->getDateTime(true)
157					->getTimestamp();
158			}
159		}
160		unset($timeperiod);
161
162		$maintenance = [
163			'name' => $_REQUEST['mname'],
164			'maintenance_type' => getRequest('maintenance_type'),
165			'description' => getRequest('description'),
166			'active_since' => $active_since_date->getTimestamp(),
167			'active_till' => $active_till_date->getTimestamp(),
168			'timeperiods' => $timeperiods,
169			'hostids' => getRequest('hostids', []),
170			'groupids' => getRequest('groupids', [])
171		];
172
173		if ($maintenance['maintenance_type'] != MAINTENANCE_TYPE_NODATA) {
174			$maintenance += [
175				'tags_evaltype' => getRequest('tags_evaltype', MAINTENANCE_TAG_EVAL_TYPE_AND_OR),
176				'tags' => getRequest('tags', [])
177			];
178
179			foreach ($maintenance['tags'] as $tnum => $tag) {
180				if ($tag['tag'] === '' && $tag['value'] === '') {
181					unset($maintenance['tags'][$tnum]);
182				}
183			}
184		}
185
186		if (isset($_REQUEST['maintenanceid'])) {
187			$maintenance['maintenanceid'] = $_REQUEST['maintenanceid'];
188			$result = API::Maintenance()->update($maintenance);
189		}
190		else {
191			$result = API::Maintenance()->create($maintenance);
192		}
193	}
194
195	if ($result) {
196		unset($_REQUEST['form']);
197		uncheckTableRows();
198	}
199
200	show_messages($result, $messageSuccess, $messageFailed);
201}
202elseif (hasRequest('delete') || (hasRequest('action') && getRequest('action') == 'maintenance.massdelete')) {
203	$maintenanceids = getRequest('maintenanceid', []);
204	if (hasRequest('maintenanceids')) {
205		$maintenanceids = getRequest('maintenanceids');
206	}
207
208	zbx_value2array($maintenanceids);
209
210	$result = API::Maintenance()->delete($maintenanceids);
211	if ($result) {
212		unset($_REQUEST['form'], $_REQUEST['maintenanceid']);
213		uncheckTableRows();
214	}
215	else {
216		$maintenances = API::Maintenance()->get([
217			'maintenanceids' => getRequest('maintenanceids'),
218			'output' => [],
219			'editable' => true
220		]);
221		uncheckTableRows(null, zbx_objectValues($maintenances, 'maintenanceid'));
222	}
223
224	show_messages($result, _('Maintenance deleted'), _('Cannot delete maintenance'));
225}
226elseif (hasRequest('add_timeperiod') && hasRequest('new_timeperiod')) {
227	$new_timeperiod = getRequest('new_timeperiod');
228
229	if ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_ONETIME) {
230		$new_timeperiod['start_date'] = getRequest('new_timeperiod_start_date');
231	}
232
233	// start time
234	$new_timeperiod['start_time'] = ($new_timeperiod['hour'] * SEC_PER_HOUR) + ($new_timeperiod['minute'] * SEC_PER_MIN);
235
236	// period
237	$new_timeperiod['period'] = ($new_timeperiod['period_days'] * SEC_PER_DAY) + ($new_timeperiod['period_hours'] * SEC_PER_HOUR) + ($new_timeperiod['period_minutes'] * SEC_PER_MIN);
238
239	// days of week
240	if (!isset($new_timeperiod['dayofweek'])) {
241		$dayofweek =  (!isset($new_timeperiod['dayofweek_su'])) ? '0' : '1';
242		$dayofweek .= (!isset($new_timeperiod['dayofweek_sa'])) ? '0' : '1';
243		$dayofweek .= (!isset($new_timeperiod['dayofweek_fr'])) ? '0' : '1';
244		$dayofweek .= (!isset($new_timeperiod['dayofweek_th'])) ? '0' : '1';
245		$dayofweek .= (!isset($new_timeperiod['dayofweek_we'])) ? '0' : '1';
246		$dayofweek .= (!isset($new_timeperiod['dayofweek_tu'])) ? '0' : '1';
247		$dayofweek .= (!isset($new_timeperiod['dayofweek_mo'])) ? '0' : '1';
248		$new_timeperiod['dayofweek'] = bindec($dayofweek);
249	}
250
251	// months
252	if (!isset($new_timeperiod['month'])) {
253		$month =  (!isset($new_timeperiod['month_dec'])) ? '0' : '1';
254		$month .= (!isset($new_timeperiod['month_nov'])) ? '0' : '1';
255		$month .= (!isset($new_timeperiod['month_oct'])) ? '0' : '1';
256		$month .= (!isset($new_timeperiod['month_sep'])) ? '0' : '1';
257		$month .= (!isset($new_timeperiod['month_aug'])) ? '0' : '1';
258		$month .= (!isset($new_timeperiod['month_jul'])) ? '0' : '1';
259		$month .= (!isset($new_timeperiod['month_jun'])) ? '0' : '1';
260		$month .= (!isset($new_timeperiod['month_may'])) ? '0' : '1';
261		$month .= (!isset($new_timeperiod['month_apr'])) ? '0' : '1';
262		$month .= (!isset($new_timeperiod['month_mar'])) ? '0' : '1';
263		$month .= (!isset($new_timeperiod['month_feb'])) ? '0' : '1';
264		$month .= (!isset($new_timeperiod['month_jan'])) ? '0' : '1';
265		$new_timeperiod['month'] = bindec($month);
266	}
267
268	if ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_MONTHLY) {
269		if ($new_timeperiod['month_date_type'] > 0) {
270			$new_timeperiod['day'] = 0;
271		}
272		else {
273			$new_timeperiod['every'] = 1;
274			$new_timeperiod['dayofweek'] = 0;
275		}
276	}
277
278	$_REQUEST['timeperiods'] = getRequest('timeperiods', []);
279
280	$result = true;
281
282	if ($new_timeperiod['period'] < 300) {
283		info(_('Incorrect maintenance period (minimum 5 minutes)'));
284		$result = false;
285	}
286	elseif ($new_timeperiod['hour'] > 23 || $new_timeperiod['minute'] > 59) {
287		info(_('Incorrect maintenance period'));
288		$result = false;
289	}
290	elseif ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_ONETIME) {
291		$absolute_time_parser = new CAbsoluteTimeParser();
292		$absolute_time_parser->parse($new_timeperiod['start_date']);
293		$start_date = $absolute_time_parser->getDateTime(true);
294		$new_timeperiod['start_date'] = $start_date->format(ZBX_DATE_TIME);
295
296		if (!validateDateInterval($start_date->format('Y'), $start_date->format('m'), $start_date->format('d'))) {
297			error(_('Incorrect maintenance - date must be between 1970.01.01 and 2038.01.18'));
298			$result = false;
299		}
300	}
301	elseif ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_DAILY && $new_timeperiod['every'] < 1) {
302		info(_('Incorrect maintenance day period'));
303		$result = false;
304	}
305	elseif ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_WEEKLY) {
306		if ($new_timeperiod['every'] < 1) {
307			info(_('Incorrect maintenance week period'));
308			$result = false;
309		}
310		elseif ($new_timeperiod['dayofweek'] < 1) {
311			info(_('Incorrect maintenance days of week'));
312			$result = false;
313		}
314	}
315	elseif ($new_timeperiod['timeperiod_type'] == TIMEPERIOD_TYPE_MONTHLY) {
316		if ($new_timeperiod['month'] < 1) {
317			info(_('Incorrect maintenance month period'));
318			$result = false;
319		}
320		elseif ($new_timeperiod['day'] == 0 && $new_timeperiod['dayofweek'] < 1) {
321			info(_('Incorrect maintenance days of week'));
322			$result = false;
323		}
324		elseif (($new_timeperiod['day'] < 1 || $new_timeperiod['day'] > 31) && $new_timeperiod['dayofweek'] == 0) {
325			info(_('Incorrect maintenance date'));
326			$result = false;
327		}
328	}
329
330	show_messages();
331
332	if ($result) {
333		if (!isset($new_timeperiod['id'])) {
334			if (!str_in_array($new_timeperiod, $_REQUEST['timeperiods'])) {
335				array_push($_REQUEST['timeperiods'], $new_timeperiod);
336			}
337		}
338		else {
339			$id = $new_timeperiod['id'];
340			unset($new_timeperiod['id']);
341			$_REQUEST['timeperiods'][$id] = $new_timeperiod;
342		}
343		unset($_REQUEST['new_timeperiod']);
344	}
345}
346elseif (isset($_REQUEST['del_timeperiodid'])) {
347	$_REQUEST['timeperiods'] = getRequest('timeperiods', []);
348	$delTimeperiodId = array_keys($_REQUEST['del_timeperiodid']);
349	$delTimeperiodId = reset($delTimeperiodId);
350	unset($_REQUEST['timeperiods'][$delTimeperiodId]);
351}
352elseif (isset($_REQUEST['edit_timeperiodid'])) {
353	$_REQUEST['edit_timeperiodid'] = array_keys($_REQUEST['edit_timeperiodid']);
354	$edit_timeperiodid = $_REQUEST['edit_timeperiodid'] = array_pop($_REQUEST['edit_timeperiodid']);
355	$_REQUEST['timeperiods'] = getRequest('timeperiods', []);
356
357	if (isset($_REQUEST['timeperiods'][$edit_timeperiodid])) {
358		$_REQUEST['new_timeperiod'] = $_REQUEST['timeperiods'][$edit_timeperiodid];
359		$_REQUEST['new_timeperiod']['id'] = $edit_timeperiodid;
360		$_REQUEST['new_timeperiod_start_date'] = $_REQUEST['new_timeperiod']['start_date'];
361	}
362}
363
364$options = [
365	'groups' => ['editable' => 1],
366	'groupid' => getRequest('groupid')
367];
368$pageFilter = new CPageFilter($options);
369$_REQUEST['groupid'] = $pageFilter->groupid;
370
371/*
372 * Display
373 */
374$data = [
375	'form' => getRequest('form'),
376	'new_timeperiod' => getRequest('new_timeperiod', []),
377	'add_timeperiod' => getRequest('add_timeperiod', 0),
378	'new_timeperiod_start_date' => getRequest('new_timeperiod_start_date')
379];
380
381if (!empty($data['form'])) {
382	$data['maintenanceid'] = getRequest('maintenanceid');
383	$data['form_refresh'] = getRequest('form_refresh', 0);
384
385	if (isset($data['maintenanceid']) && !hasRequest('form_refresh')) {
386		$dbMaintenance = reset($dbMaintenance);
387		$data['mname'] = $dbMaintenance['name'];
388		$data['maintenance_type'] = $dbMaintenance['maintenance_type'];
389		$data['active_since'] = date(ZBX_DATE_TIME, $dbMaintenance['active_since']);
390		$data['active_till'] = date(ZBX_DATE_TIME, $dbMaintenance['active_till']);
391		$data['description'] = $dbMaintenance['description'];
392
393		// time periods
394		$data['timeperiods'] = $dbMaintenance['timeperiods'];
395		CArrayHelper::sort($data['timeperiods'], ['timeperiod_type', 'start_date']);
396
397		foreach ($data['timeperiods'] as &$timeperiod) {
398			$timeperiod['start_date'] = date(ZBX_DATE_TIME, $timeperiod['start_date']);
399		}
400		unset($timeperiod);
401
402		// get hosts
403		$db_hosts = API::Host()->get([
404			'output' => ['hostid', 'name'],
405			'maintenanceids' => $data['maintenanceid'],
406			'editable' => true
407		]);
408
409		// get groups
410		$db_groups = API::HostGroup()->get([
411			'output' => ['groupid', 'name'],
412			'maintenanceids' => $data['maintenanceid'],
413			'editable' => true
414		]);
415
416		// tags
417		$data['tags_evaltype'] = $dbMaintenance['tags_evaltype'];
418		$data['tags'] = $dbMaintenance['tags'];
419		CArrayHelper::sort($data['tags'], ['tag', 'value']);
420	}
421	else {
422
423		if ($data['new_timeperiod'] != 1 && $data['new_timeperiod'] !== []
424				&& hasRequest('new_timeperiod_start_date')) {
425			$data['new_timeperiod']['start_date'] = getRequest('new_timeperiod_start_date');
426		}
427
428		$data += [
429			'mname' => getRequest('mname', ''),
430			'maintenance_type' => getRequest('maintenance_type', 0),
431			'active_since' => getRequest('active_since', date(ZBX_DATE_TIME, strtotime('today'))),
432			'active_till' => getRequest('active_till', date(ZBX_DATE_TIME, strtotime('tomorrow'))),
433			'description' => getRequest('description', ''),
434			'timeperiods' => getRequest('timeperiods', []),
435			'tags_evaltype' => getRequest('tags_evaltype', MAINTENANCE_TAG_EVAL_TYPE_AND_OR),
436			'tags' => getRequest('tags', [])
437		];
438
439		$hostids = getRequest('hostids', []);
440		$groupids = getRequest('groupids', []);
441
442		$db_hosts = $hostids
443			? API::Host()->get([
444				'output' => ['hostid', 'name'],
445				'hostids' => $hostids,
446				'editable' => true
447			])
448			: [];
449
450		$db_groups = $groupids
451			? API::HostGroup()->get([
452				'output' => ['groupid', 'name'],
453				'groupids' => $groupids,
454				'editable' => true
455			])
456			: [];
457	}
458
459	$data['hosts_ms'] = CArrayHelper::renameObjectsKeys($db_hosts, ['hostid' => 'id']);
460	CArrayHelper::sort($data['hosts_ms'], ['name']);
461
462	$data['groups_ms'] = CArrayHelper::renameObjectsKeys($db_groups, ['groupid' => 'id']);
463	CArrayHelper::sort($data['groups_ms'], ['name']);
464
465	// render view
466	$maintenanceView = new CView('configuration.maintenance.edit', $data);
467	$maintenanceView->render();
468	$maintenanceView->show();
469}
470else {
471	// get maintenances
472	$sortField = getRequest('sort', CProfile::get('web.'.$page['file'].'.sort', 'name'));
473	$sortOrder = getRequest('sortorder', CProfile::get('web.'.$page['file'].'.sortorder', ZBX_SORT_UP));
474
475	CProfile::update('web.'.$page['file'].'.sort', $sortField, PROFILE_TYPE_STR);
476	CProfile::update('web.'.$page['file'].'.sortorder', $sortOrder, PROFILE_TYPE_STR);
477
478	// filter
479	if (hasRequest('filter_set')) {
480		CProfile::update('web.maintenance.filter_name', getRequest('filter_name', ''), PROFILE_TYPE_STR);
481		CProfile::update('web.maintenance.filter_status', getRequest('filter_status', -1), PROFILE_TYPE_INT);
482	}
483	elseif (hasRequest('filter_rst')) {
484		CProfile::delete('web.maintenance.filter_name');
485		CProfile::delete('web.maintenance.filter_status');
486	}
487
488	$filter = [
489		'name' => CProfile::get('web.maintenance.filter_name', ''),
490		'status' => CProfile::get('web.maintenance.filter_status', -1)
491	];
492
493	$config = select_config();
494
495	$data = [
496		'sort' => $sortField,
497		'sortorder' => $sortOrder,
498		'filter' => $filter,
499		'profileIdx' => 'web.maintenance.filter',
500		'active_tab' => CProfile::get('web.maintenance.filter.active', 1)
501	];
502
503	// Get list of maintenances.
504	$options = [
505		'output' => ['maintenanceid', 'name', 'maintenance_type', 'active_since', 'active_till', 'description'],
506		'search' => [
507			'name' => ($filter['name'] === '') ? null : $filter['name']
508		],
509		'editable' => true,
510		'sortfield' => $sortField,
511		'sortorder' => $sortOrder,
512		'limit' => $config['search_limit'] + 1
513	];
514
515	if ($pageFilter->groupsSelected && $pageFilter->groupid > 0) {
516		$options['groupids'] = $pageFilter->groupids;
517	}
518	else {
519		$options['groupids'] = $config['dropdown_first_entry'] ? null : [];
520	}
521
522	$data['maintenances'] = API::Maintenance()->get($options);
523
524	foreach ($data['maintenances'] as $key => $maintenance) {
525		if ($maintenance['active_till'] < time()) {
526			$data['maintenances'][$key]['status'] = MAINTENANCE_STATUS_EXPIRED;
527		}
528		elseif ($maintenance['active_since'] > time()) {
529			$data['maintenances'][$key]['status'] = MAINTENANCE_STATUS_APPROACH;
530		}
531		else {
532			$data['maintenances'][$key]['status'] = MAINTENANCE_STATUS_ACTIVE;
533		}
534	}
535
536	// filter by status
537	if ($filter['status'] != -1) {
538		foreach ($data['maintenances'] as $key => $maintenance) {
539			if ($data['maintenances'][$key]['status'] != $filter['status']) {
540				unset($data['maintenances'][$key]);
541			}
542		}
543	}
544
545	order_result($data['maintenances'], $sortField, $sortOrder);
546
547	$url = (new CUrl('maintenance.php'))
548		->setArgument('groupid', $pageFilter->groupid);
549
550	$data['paging'] = getPagingLine($data['maintenances'], $sortOrder, $url);
551
552	$data['pageFilter'] = $pageFilter;
553
554	// render view
555	$maintenanceView = new CView('configuration.maintenance.list', $data);
556	$maintenanceView->render();
557	$maintenanceView->show();
558}
559
560require_once dirname(__FILE__).'/include/page_footer.php';
561