<?php declare(strict_types = 0);
class CControllerChartsView extends CControllerCharts {
protected function init() {
$this->disableCsrfValidation();
}
protected function checkInput() {
$fields = [
'from' => 'range_time',
'to' => 'range_time',
'view_as' => 'in '.HISTORY_GRAPH.','.HISTORY_VALUES,
'filter_set' => 'in 1',
'filter_rst' => 'in 1',
'filter_hostids' => 'array_id',
'filter_name' => 'string',
'filter_show' => 'in '.GRAPH_FILTER_ALL.','.GRAPH_FILTER_HOST.','.GRAPH_FILTER_SIMPLE,
'subfilter_set' => 'in 1',
'subfilter_tagnames' => 'array',
'subfilter_tags' => 'array',
'page' => 'ge 1'
];
$ret = $this->validateInput($fields) && $this->validateTimeSelectorPeriod();
if ($ret && $this->hasInput('subfilter_tagnames')) {
$tagnames = $this->getInput('subfilter_tagnames', []);
$ret = !$tagnames || count($tagnames) == count(array_filter($tagnames, 'is_string'));
}
if ($ret && $this->hasInput('subfilter_tags')) {
$tags = $this->getInput('subfilter_tags', []);
foreach ($tags as $tag => $values) {
if (!is_scalar($tag) || !is_array($values)
|| count($values) != count(array_filter($values, 'is_string'))) {
$ret = false;
break;
}
}
}
if (!$ret) {
$this->setResponse(new CControllerResponseFatal());
}
return $ret;
}
protected function checkPermissions() {
return $this->checkAccess(CRoleHelper::UI_MONITORING_HOSTS);
}
protected function doAction() {
if ($this->hasInput('filter_rst')) {
CProfile::deleteIdx('web.charts.filter.hostids');
CProfile::deleteIdx('web.charts.filter.name');
CProfile::deleteIdx('web.charts.filter.show');
CProfile::deleteIdx('web.charts.subfilter.tagnames');
CProfile::deleteIdx('web.charts.subfilter.tags');
}
elseif ($this->hasInput('subfilter_set')) {
CProfile::updateArray('web.charts.subfilter.tagnames', $this->getInput('subfilter_tagnames', []), PROFILE_TYPE_STR);
CProfile::update('web.charts.subfilter.tags', json_encode($this->getInput('subfilter_tags', [])), PROFILE_TYPE_STR);
}
elseif ($this->hasInput('filter_set')) {
CProfile::updateArray('web.charts.filter.hostids', $this->getInput('filter_hostids', []), PROFILE_TYPE_ID);
CProfile::update('web.charts.filter.name', $this->getInput('filter_name', ''), PROFILE_TYPE_STR);
CProfile::update('web.charts.filter.show',
$this->getInput('filter_show', GRAPH_FILTER_ALL), PROFILE_TYPE_INT
);
}
$filter_hostids = CProfile::getArray('web.charts.filter.hostids', []);