<?php declare(strict_types = 0);
class CControllerHostDashboardView extends CController {
private $host;
protected function init() {
$this->disableCsrfValidation();
}
protected function checkInput(): bool {
$fields = [
'hostid' => 'required|db hosts.hostid',
'dashboardid' => 'db dashboard.dashboardid',
'from' => 'range_time',
'to' => 'range_time'
];
$ret = $this->validateInput($fields) && $this->validateTimeSelectorPeriod();
if (!$ret) {
$this->setResponse(new CControllerResponseFatal());
}
return $ret;
}
protected function checkPermissions(): bool {
if (!$this->checkAccess(CRoleHelper::UI_MONITORING_HOSTS)) {
return false;
}
$db_hosts = API::Host()->get([
'output' => ['hostid', 'name'],
'selectParentTemplates' => ['templateid'],
'hostids' => [$this->getInput('hostid')]
]);
if (!$db_hosts) {
return false;
}
$this->host = $db_hosts[0];
return true;
}
protected function doAction() {
$host_dashboards = $this->getSortedHostDashboards();
if (!$host_dashboards) {
$data = ['no_data' => true];
}
else {
$dashboardid = $this->hasInput('dashboardid')
? $this->getInput('dashboardid')
: CProfile::get('web.host.dashboard.dashboardid', null, $this->getInput('hostid'));
if (!in_array($dashboardid, array_column($host_dashboards, 'dashboardid'))) {
$dashboardid = $host_dashboards[0]['dashboardid'];
}
$db_dashboards = API::TemplateDashboard()->get([
'output' => ['dashboardid', 'name', 'templateid', 'display_period', 'auto_start'],
'selectPages' => ['dashboard_pageid', 'name', 'display_period', 'widgets'],
'dashboardids' => [$dashboardid]
]);
if ($db_dashboards) {
$dashboard = $db_dashboards[0];
CProfile::update('web.host.dashboard.dashboardid', $dashboard['dashboardid'], PROFILE_TYPE_ID,
$this->getInput('hostid')
);
$widget_defaults = APP::ModuleManager()->getWidgetsDefaults();