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 CPartial $this
24 */
25
26$tag_filter_table = (new CTable())
27	->setId('tag-filter-table')
28	->setAttribute('style', 'width: 100%;')
29	->setHeader([_('Host group'), _('Tags'), _('Action')]);
30
31$previous_name = '';
32foreach ($data['tag_filters'] as $key => $tag_filter) {
33	if ($previous_name === $tag_filter['name']) {
34		$tag_filter['name'] = '';
35	}
36	else {
37		$previous_name = $tag_filter['name'];
38	}
39
40	if ($tag_filter['tag'] !== '' && $tag_filter['value'] !== '') {
41		$tag_value = $tag_filter['tag'].NAME_DELIMITER.$tag_filter['value'];
42	}
43	elseif ($tag_filter['tag'] !== '') {
44		$tag_value = $tag_filter['tag'];
45	}
46	else {
47		$tag_value = italic(_('All tags'));
48	}
49
50	$action = [
51		(new CSimpleButton(_('Remove')))->addClass(ZBX_STYLE_BTN_LINK)
52			->onClick('javascript: usergroups.removeTagFilterRow($(this));'),
53		(new CVar('tag_filters['.$key.'][groupid]', $tag_filter['groupid']))->removeId(),
54		(new CVar('tag_filters['.$key.'][tag]', $tag_filter['tag']))->removeId(),
55		(new CVar('tag_filters['.$key.'][value]', $tag_filter['value']))->removeId(),
56		(new CVar('tag_filter', json_encode([
57			'groupid' => $tag_filter['groupid'],
58			'tag' => $tag_filter['tag'],
59			'value' => $tag_filter['value']
60		])))->removeId()->setEnabled(false)
61	];
62
63	$tag_filter_table->addRow([$tag_filter['name'], $tag_value, $action]);
64}
65
66$tag_filter_table->show();
67