Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CControllerTrigDisplayUpdate.php « controllers « app « ui - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 638f8bbbcd05c4f8c3e1d373fcf3410b88ead3b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/*
** Zabbix
** Copyright (C) 2001-2020 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/


class CControllerTrigDisplayUpdate extends CController {

	protected function checkInput() {
		$fields = [
			'custom_color' =>			'required|db config.custom_color|in '.EVENT_CUSTOM_COLOR_DISABLED.','.EVENT_CUSTOM_COLOR_ENABLED,
			'problem_unack_color' =>	'db config.problem_unack_color|rgb',
			'problem_ack_color' =>		'db config.problem_ack_color|rgb',
			'ok_unack_color' =>			'db config.ok_unack_color|rgb',
			'ok_ack_color' =>			'db config.ok_ack_color|rgb',
			'problem_unack_style' =>	'required|db config.problem_unack_style|in 0,1',
			'problem_ack_style' =>		'required|db config.problem_ack_style|in 0,1',
			'ok_unack_style' =>			'required|db config.ok_unack_style|in 0,1',
			'ok_ack_style' =>			'required|db config.ok_ack_style|in 0,1',
			'ok_period' =>				'required|db config.ok_period|not_empty|time_unit '.implode(':', [0, SEC_PER_DAY]),
			'blink_period' =>			'required|db config.blink_period|not_empty|time_unit '.implode(':', [0, SEC_PER_DAY]),
			'severity_name_0' =>		'required|db config.severity_name_0|not_empty',
			'severity_color_0' =>		'required|db config.severity_color_0|rgb',
			'severity_name_1' =>		'required|db config.severity_name_1|not_empty',
			'severity_color_1' =>		'required|db config.severity_color_1|rgb',
			'severity_name_2' =>		'required|db config.severity_name_2|not_empty',
			'severity_color_2' =>		'required|db config.severity_color_2|rgb',
			'severity_name_3' =>		'required|db config.severity_name_3|not_empty',
			'severity_color_3' =>		'required|db config.severity_color_3|rgb',
			'severity_name_4' =>		'required|db config.severity_name_4|not_empty',
			'severity_color_4' =>		'required|db config.severity_color_4|rgb',
			'severity_name_5' =>		'required|db config.severity_name_5|not_empty',
			'severity_color_5' =>		'required|db config.severity_color_5|rgb'
		];

		$ret = $this->validateInput($fields);

		if (!$ret) {
			$response = new CControllerResponseRedirect((new CUrl('zabbix.php'))
				->setArgument('action', 'trigdisplay.edit')
			);

			$response->setFormData($this->getInputAll());
			CMessageHelper::setErrorTitle(_('Cannot update configuration'));

			$this->setResponse($response);
		}

		return $ret;
	}

	protected function checkPermissions() {
		return $this->checkAccess(CRoleHelper::UI_ADMINISTRATION_GENERAL);
	}

	protected function doAction() {
		$settings = [
			CSettingsHelper::CUSTOM_COLOR => $this->getInput('custom_color', EVENT_CUSTOM_COLOR_DISABLED),
			CSettingsHelper::PROBLEM_UNACK_STYLE => $this->getInput('problem_unack_style'),
			CSettingsHelper::PROBLEM_ACK_STYLE => $this->getInput('problem_ack_style'),
			CSettingsHelper::OK_UNACK_STYLE => $this->getInput('ok_unack_style'),
			CSettingsHelper::OK_ACK_STYLE => $this->getInput('ok_ack_style'),
			CSettingsHelper::OK_PERIOD => trim($this->getInput('ok_period')),
			CSettingsHelper::BLINK_PERIOD => trim($this->getInput('blink_period')),
			CSettingsHelper::SEVERITY_NAME_0 => $this->getInput('severity_name_0'),
			CSettingsHelper::SEVERITY_COLOR_0 => $this->getInput('severity_color_0'),
			CSettingsHelper::SEVERITY_NAME_1 => $this->getInput('severity_name_1'),
			CSettingsHelper::SEVERITY_COLOR_1 => $this->getInput('severity_color_1'),
			CSettingsHelper::SEVERITY_NAME_2 => $this->getInput('severity_name_2'),
			CSettingsHelper::SEVERITY_COLOR_2 => $this->getInput('severity_color_2'),
			CSettingsHelper::SEVERITY_NAME_3 => $this->getInput('severity_name_3'),
			CSettingsHelper::SEVERITY_COLOR_3 => $this->getInput('severity_color_3'),
			CSettingsHelper::SEVERITY_NAME_4 => $this->getInput('severity_name_4'),
			CSettingsHelper::SEVERITY_COLOR_4 => $this->getInput('severity_color_4'),
			CSettingsHelper::SEVERITY_NAME_5 => $this->getInput('severity_name_5'),
			CSettingsHelper::SEVERITY_COLOR_5 => $this->getInput('severity_color_5')
		];

		if ($settings[CSettingsHelper::CUSTOM_COLOR] == EVENT_CUSTOM_COLOR_ENABLED) {
			$settings[CSettingsHelper::PROBLEM_UNACK_COLOR] = $this->getInput('problem_unack_color');
			$settings[CSettingsHelper::PROBLEM_ACK_COLOR] = $this->getInput('problem_ack_color');
			$settings[CSettingsHelper::OK_UNACK_COLOR] = $this->getInput('ok_unack_color');
			$settings[CSettingsHelper::OK_ACK_COLOR] = $this->getInput('ok_ack_color');
		}

		$result = API::Settings()->update($settings);

		$response = new CControllerResponseRedirect((new CUrl('zabbix.php'))
			->setArgument('action', 'trigdisplay.edit')
		);

		if ($result) {
			CMessageHelper::setSuccessTitle(_('Configuration updated'));
		}
		else {
			CMessageHelper::setErrorTitle(_('Cannot update configuration'));
			$response->setFormData($this->getInputAll());
		}

		$this->setResponse($response);
	}
}