1<?php 2/* 3** Zabbix 4** Copyright (C) 2001-2021 Zabbix SIA 5** 6** This program is free software; you can redistribute it and/or modify 7** it under the terms of the GNU General Public License as published by 8** the Free Software Foundation; either version 2 of the License, or 9** (at your option) any later version. 10** 11** This program is distributed in the hope that it will be useful, 12** but WITHOUT ANY WARRANTY; without even the implied warranty of 13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14** GNU General Public License for more details. 15** 16** You should have received a copy of the GNU General Public License 17** along with this program; if not, write to the Free Software 18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19**/ 20 21 22class CControllerTrigDisplayUpdate extends CController { 23 24 protected function checkInput() { 25 $fields = [ 26 'custom_color' => 'required|db config.custom_color|in '.EVENT_CUSTOM_COLOR_DISABLED.','.EVENT_CUSTOM_COLOR_ENABLED, 27 'problem_unack_color' => 'db config.problem_unack_color|rgb', 28 'problem_ack_color' => 'db config.problem_ack_color|rgb', 29 'ok_unack_color' => 'db config.ok_unack_color|rgb', 30 'ok_ack_color' => 'db config.ok_ack_color|rgb', 31 'problem_unack_style' => 'required|db config.problem_unack_style|in 0,1', 32 'problem_ack_style' => 'required|db config.problem_ack_style|in 0,1', 33 'ok_unack_style' => 'required|db config.ok_unack_style|in 0,1', 34 'ok_ack_style' => 'required|db config.ok_ack_style|in 0,1', 35 'ok_period' => 'required|db config.ok_period|not_empty|time_unit '.implode(':', [0, SEC_PER_DAY]), 36 'blink_period' => 'required|db config.blink_period|not_empty|time_unit '.implode(':', [0, SEC_PER_DAY]), 37 'severity_name_0' => 'required|db config.severity_name_0|not_empty', 38 'severity_color_0' => 'required|db config.severity_color_0|rgb', 39 'severity_name_1' => 'required|db config.severity_name_1|not_empty', 40 'severity_color_1' => 'required|db config.severity_color_1|rgb', 41 'severity_name_2' => 'required|db config.severity_name_2|not_empty', 42 'severity_color_2' => 'required|db config.severity_color_2|rgb', 43 'severity_name_3' => 'required|db config.severity_name_3|not_empty', 44 'severity_color_3' => 'required|db config.severity_color_3|rgb', 45 'severity_name_4' => 'required|db config.severity_name_4|not_empty', 46 'severity_color_4' => 'required|db config.severity_color_4|rgb', 47 'severity_name_5' => 'required|db config.severity_name_5|not_empty', 48 'severity_color_5' => 'required|db config.severity_color_5|rgb' 49 ]; 50 51 $ret = $this->validateInput($fields); 52 53 if (!$ret) { 54 $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) 55 ->setArgument('action', 'trigdisplay.edit') 56 ); 57 58 $response->setFormData($this->getInputAll()); 59 CMessageHelper::setErrorTitle(_('Cannot update configuration')); 60 61 $this->setResponse($response); 62 } 63 64 return $ret; 65 } 66 67 protected function checkPermissions() { 68 return $this->checkAccess(CRoleHelper::UI_ADMINISTRATION_GENERAL); 69 } 70 71 protected function doAction() { 72 $settings = [ 73 CSettingsHelper::CUSTOM_COLOR => $this->getInput('custom_color', EVENT_CUSTOM_COLOR_DISABLED), 74 CSettingsHelper::PROBLEM_UNACK_STYLE => $this->getInput('problem_unack_style'), 75 CSettingsHelper::PROBLEM_ACK_STYLE => $this->getInput('problem_ack_style'), 76 CSettingsHelper::OK_UNACK_STYLE => $this->getInput('ok_unack_style'), 77 CSettingsHelper::OK_ACK_STYLE => $this->getInput('ok_ack_style'), 78 CSettingsHelper::OK_PERIOD => trim($this->getInput('ok_period')), 79 CSettingsHelper::BLINK_PERIOD => trim($this->getInput('blink_period')), 80 CSettingsHelper::SEVERITY_NAME_0 => $this->getInput('severity_name_0'), 81 CSettingsHelper::SEVERITY_COLOR_0 => $this->getInput('severity_color_0'), 82 CSettingsHelper::SEVERITY_NAME_1 => $this->getInput('severity_name_1'), 83 CSettingsHelper::SEVERITY_COLOR_1 => $this->getInput('severity_color_1'), 84 CSettingsHelper::SEVERITY_NAME_2 => $this->getInput('severity_name_2'), 85 CSettingsHelper::SEVERITY_COLOR_2 => $this->getInput('severity_color_2'), 86 CSettingsHelper::SEVERITY_NAME_3 => $this->getInput('severity_name_3'), 87 CSettingsHelper::SEVERITY_COLOR_3 => $this->getInput('severity_color_3'), 88 CSettingsHelper::SEVERITY_NAME_4 => $this->getInput('severity_name_4'), 89 CSettingsHelper::SEVERITY_COLOR_4 => $this->getInput('severity_color_4'), 90 CSettingsHelper::SEVERITY_NAME_5 => $this->getInput('severity_name_5'), 91 CSettingsHelper::SEVERITY_COLOR_5 => $this->getInput('severity_color_5') 92 ]; 93 94 if ($settings[CSettingsHelper::CUSTOM_COLOR] == EVENT_CUSTOM_COLOR_ENABLED) { 95 $settings[CSettingsHelper::PROBLEM_UNACK_COLOR] = $this->getInput('problem_unack_color'); 96 $settings[CSettingsHelper::PROBLEM_ACK_COLOR] = $this->getInput('problem_ack_color'); 97 $settings[CSettingsHelper::OK_UNACK_COLOR] = $this->getInput('ok_unack_color'); 98 $settings[CSettingsHelper::OK_ACK_COLOR] = $this->getInput('ok_ack_color'); 99 } 100 101 $result = API::Settings()->update($settings); 102 103 $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) 104 ->setArgument('action', 'trigdisplay.edit') 105 ); 106 107 if ($result) { 108 CMessageHelper::setSuccessTitle(_('Configuration updated')); 109 } 110 else { 111 CMessageHelper::setErrorTitle(_('Cannot update configuration')); 112 $response->setFormData($this->getInputAll()); 113 } 114 115 $this->setResponse($response); 116 } 117} 118