<?php declare(strict_types = 0);
class CControllerGraphCreate extends CController {
protected function init(): void {
$this->setPostContentType(self::POST_CONTENT_TYPE_JSON);
protected function checkInput(): bool {
'context' => 'required|in '.implode(',', ['host', 'template']),
'name' => 'required|db graphs.name|not_empty',
'width' => 'required|db graphs.width|not_empty|ge 20|le 65535',
'height' => 'required|db graphs.height|not_empty|ge 20|le 65535',
'graphtype' => 'required|db graphs.graphtype|in '.implode(',', [
GRAPH_TYPE_NORMAL, GRAPH_TYPE_STACKED, GRAPH_TYPE_PIE, GRAPH_TYPE_EXPLODED
'show_legend' => 'db graphs.show_legend|in 0,1',
'show_3d' => 'db graphs.show_3d|in 0,1',
'show_work_period' => 'db graphs.show_work_period|in 0,1',
'show_triggers' => 'db graphs.show_triggers|in 0,1',
'percent_left' => 'string',
'percent_right' => 'string',
'ymin_type' => 'db graphs.ymin_type|in '.implode(',', [
GRAPH_YAXIS_TYPE_CALCULATED, GRAPH_YAXIS_TYPE_FIXED, GRAPH_YAXIS_TYPE_ITEM_VALUE
'ymax_type' => 'db graphs.ymax_type|in '.implode(',', [
GRAPH_YAXIS_TYPE_CALCULATED, GRAPH_YAXIS_TYPE_FIXED, GRAPH_YAXIS_TYPE_ITEM_VALUE
'ymin_itemid' => 'db graphs.ymin_itemid',
'ymax_itemid' => 'db graphs.ymax_itemid',
'items' => 'required|array'
$ret = $this->validateInput($fields);
$graphtype = $this->getInput('graphtype');
if ($ret && $graphtype == GRAPH_TYPE_NORMAL) {
$ret = $this->validatePercentFields();
if ($ret && ($graphtype == GRAPH_TYPE_NORMAL || $graphtype == GRAPH_TYPE_STACKED)) {
$ret = $this->validateYAxisFields();