<?php
class CControllerDashboardUpdate extends CController {
private $dashboard_pages;
protected function init() {
$this->setPostContentType(self::POST_CONTENT_TYPE_JSON);
}
protected function checkInput() {
$fields = [
'dashboardid' => 'db dashboard.dashboardid',
'name' => 'required|db dashboard.name|not_empty',
'userid' => 'required|db dashboard.userid',
'display_period' => 'required|db dashboard.display_period|in '.implode(',', DASHBOARD_DISPLAY_PERIODS),
'auto_start' => 'required|db dashboard.auto_start|in 0,1',
'pages' => 'array',
'page' => 'ge 2',
'sharing' => 'array'
];
$ret = $this->validateInput($fields);
if ($ret) {
$sharing_errors = $this->validateSharing();
[
'dashboard_pages' => $this->dashboard_pages,
'errors' => $dashboard_pages_errors
] = CDashboardHelper::validateDashboardPages($this->getInput('pages', []), null);
$errors = array_merge($sharing_errors, $dashboard_pages_errors);
foreach ($errors as $error) {
error($error);
}
$ret = !$errors;
}
if (!$ret) {
$this->setResponse(new CControllerResponseData([
'main_block' => json_encode(['errors' => getMessages()->toString()])
]));
}
return $ret;
}
protected function checkPermissions() {
return $this->checkAccess(CRoleHelper::UI_MONITORING_DASHBOARD)
&& $this->checkAccess(CRoleHelper::ACTIONS_EDIT_DASHBOARDS);
}
protected function doAction() {
$data = [];
$save_dashboard = [
'name' => $this->getInput('name'),
'userid' => $this->getInput('userid', 0),
'display_period' => $this->getInput('display_period'),
'auto_start' => $this->getInput('auto_start'),
'pages' => []
];
if ($this->hasInput('dashboardid')) {
$save_dashboard['dashboardid'] = $this->getInput('dashboardid');
}
foreach ($this->dashboard_pages as $dashboard_page) {
$save_dashboard_page = [
'name' => $dashboard_page['name'],