Source
* @param string $data['context'] Additional parameter in URL to identify main section.
<?php
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
function prepareSubfilterOutput($label, $data, $subfilter, $subfilterName) {
CArrayHelper::sort($data, ['value', 'name']);
$output = [new CTag('h3', true, $label)];
foreach ($data as $id => $element) {
// is activated
if (str_in_array($id, $subfilter)) {
$output[] = (new CSpan([
(new CLinkAction($element['name']))
->onClick('javascript: create_var("zbx_filter", "subfilter_set", "1", false);'.
'create_var("zbx_filter", '.json_encode($subfilterName.'['.$id.']').', null, true);'
),
' ',
new CSup($element['count'])
]))
->addClass(ZBX_STYLE_SUBFILTER)
->addClass(ZBX_STYLE_SUBFILTER_ENABLED);
}
// isn't activated
else {
// subfilter has 0 items
if ($element['count'] == 0) {
$output[] = (new CSpan([
(new CSpan($element['name']))->addClass(ZBX_STYLE_GREY),
' ',
new CSup($element['count'])
]))->addClass(ZBX_STYLE_SUBFILTER);
}
else {
$link = (new CLinkAction($element['name']))
->onClick('javascript: create_var("zbx_filter", "subfilter_set", "1", false);'.
'create_var("zbx_filter", '.
json_encode($subfilterName.'['.$id.']').', '.
json_encode($id).', '.
'true'.
');'
);
$output[] = (new CSpan([
$link,
' ',
new CSup(($subfilter ? '+' : '').$element['count'])
]))->addClass(ZBX_STYLE_SUBFILTER);
}
}
}
return $output;
}
/**
* Make subfilter for tags.
*
* @param array $data Array contains available subfilter tags.
* @param array $subfilter Array of already selected subfilter tags.
*
* @return array
*/
function prepareTagsSubfilterOutput(array $data, array &$subfilter): array {
$output = [new CTag('h3', true, _('Tags'))];
CArrayHelper::sort($data, ['tag', 'value']);
$i = 0;
foreach ($data as $tag_hash => $tag) {
$element_name = ($tag['value'] === '') ? $tag['tag'] : $tag['tag'].': '.$tag['value'];
$tag['tag'] = json_encode($tag['tag']);
$tag['value'] = json_encode($tag['value']);