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 * @var CView $this
24 */
25
26if ($data['uncheck']) {
27	uncheckTableRows();
28}
29
30$widget = (new CWidget())
31	->setTitle(_('Regular expressions'))
32	->setTitleSubmenu(getAdministrationGeneralSubmenu())
33	->setControls((new CTag('nav', true,
34		(new CForm())
35			->cleanItems()
36			->addItem(new CRedirectButton(_('New regular expression'), (new CUrl('zabbix.php'))
37				->setArgument('action', 'regex.edit')
38			))
39		))
40			->setAttribute('aria-label', _('Content controls'))
41	);
42
43$form = (new CForm())->setName('regularExpressionsForm');
44
45$table = (new CTableInfo())
46	->setHeader([
47		(new CColHeader(
48			(new CCheckBox('all-regexes'))->onClick("checkAll('".$form->getName()."', 'all-regexes', 'regexids');")
49		))->addClass(ZBX_STYLE_CELL_WIDTH),
50		_('Name'),
51		_('Expressions')
52	]);
53
54$expressions = [];
55$values = [];
56
57foreach($data['db_exps'] as $exp) {
58	if (!isset($expressions[$exp['regexid']])) {
59		$values[$exp['regexid']] = 1;
60	}
61	else {
62		$values[$exp['regexid']] ++;
63	}
64
65	if (!isset($expressions[$exp['regexid']])) {
66		$expressions[$exp['regexid']] = new CTable();
67	}
68
69	$expressions[$exp['regexid']]->addRow([
70		new CCol($values[$exp['regexid']]),
71		new CCol(' &raquo; '),
72		new CCol($exp['expression']),
73		new CCol(' ['.expression_type2str($exp['expression_type']).']')
74	]);
75}
76
77foreach($data['regexes'] as $regexid => $regex) {
78	$table->addRow([
79		new CCheckBox('regexids['.$regexid.']', $regexid),
80		new CLink($regex['name'], (new CUrl('zabbix.php'))
81			->setArgument('action', 'regex.edit')
82			->setArgument('regexid', $regexid)
83		),
84		array_key_exists($regexid, $expressions) ? $expressions[$regexid] : ''
85	]);
86}
87
88$form->addItem([
89	$table,
90	new CActionButtonList('action', 'regexids', [
91		'regex.delete' => ['name' => _('Delete'), 'confirm' => _('Delete selected regular expressions?')]
92	])
93]);
94
95$widget->addItem($form)->show();
96