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$widget = (new CWidget())
23	->setTitle(_('Regular expressions'))
24	->setControls((new CTag('nav', true,
25		(new CForm())
26			->cleanItems()
27			->addItem((new CList())
28				->addItem(makeAdministrationGeneralMenu('adm.regexps.php'))
29				->addItem(new CSubmit('form', _('New regular expression')))
30			)
31		))
32			->setAttribute('aria-label', _('Content controls'))
33	);
34
35$form = (new CForm())->setName('regularExpressionsForm');
36
37$regExpTable = (new CTableInfo())
38	->setHeader([
39		(new CColHeader(
40			(new CCheckBox('all_regexps'))->onClick("checkAll('".$form->getName()."', 'all_regexps', 'regexpids');")
41		))->addClass(ZBX_STYLE_CELL_WIDTH),
42		_('Name'),
43		_('Expressions')
44	]);
45
46$expressions = [];
47$values = [];
48foreach($data['db_exps'] as $exp) {
49	if (!isset($expressions[$exp['regexpid']])) {
50		$values[$exp['regexpid']] = 1;
51	}
52	else {
53		$values[$exp['regexpid']]++;
54	}
55
56	if (!isset($expressions[$exp['regexpid']])) {
57		$expressions[$exp['regexpid']] = new CTable();
58	}
59
60	$expressions[$exp['regexpid']]->addRow([
61		new CCol($values[$exp['regexpid']]),
62		new CCol(' &raquo; '),
63		new CCol($exp['expression']),
64		new CCol(' ['.expression_type2str($exp['expression_type']).']')
65	]);
66}
67foreach($data['regexps'] as $regexpid => $regexp) {
68	$regExpTable->addRow([
69		new CCheckBox('regexpids['.$regexp['regexpid'].']', $regexp['regexpid']),
70		new CLink($regexp['name'], 'adm.regexps.php?form=update'.'&regexpid='.$regexp['regexpid']),
71		isset($expressions[$regexpid]) ? $expressions[$regexpid] : ''
72	]);
73}
74
75// append table to form
76$form->addItem([
77	$regExpTable,
78	new CActionButtonList('action', 'regexpids', [
79		'regexp.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected regular expressions?')]
80	])
81]);
82
83// append form to widget
84$widget->addItem($form);
85
86return $widget;
87