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
22/**
23 * Event correlation new condition popup.
24 */
25class CControllerPopupConditionEventCorr extends CControllerPopupConditionCommon {
26
27	protected function getCheckInputs() {
28		return [
29			'type' =>			'required|in '.ZBX_POPUP_CONDITION_TYPE_EVENT_CORR,
30			'validate' =>		'in 1',
31			'condition_type' =>	'not_empty|in '.implode(',', [ZBX_CORR_CONDITION_OLD_EVENT_TAG, ZBX_CORR_CONDITION_NEW_EVENT_TAG, ZBX_CORR_CONDITION_NEW_EVENT_HOSTGROUP, ZBX_CORR_CONDITION_EVENT_TAG_PAIR, ZBX_CORR_CONDITION_OLD_EVENT_TAG_VALUE, ZBX_CORR_CONDITION_NEW_EVENT_TAG_VALUE]),
32			'operator' =>		'not_empty|in '.implode(',', [CONDITION_OPERATOR_EQUAL, CONDITION_OPERATOR_NOT_EQUAL, CONDITION_OPERATOR_LIKE, CONDITION_OPERATOR_NOT_LIKE])
33		];
34	}
35
36	protected function getConditionLastType() {
37		$last_type = CProfile::get('popup.condition.events_last_type', ZBX_CORR_CONDITION_OLD_EVENT_TAG);
38
39		if ($this->hasInput('condition_type') && $this->getInput('condition_type') != $last_type) {
40			CProfile::update('popup.condition.events_last_type', $this->getInput('condition_type'), PROFILE_TYPE_INT);
41			$last_type = $this->getInput('condition_type');
42		}
43
44		return $last_type;
45	}
46
47	protected function validateFieldsManually() {
48		$validator = new CEventCorrCondValidator();
49		$is_valid = $validator->validate([
50			'type' => $this->getInput('condition_type'),
51			'operator' => $this->getInput('operator'),
52			'tag' => getRequest('tag'),
53			'oldtag' => getRequest('oldtag'),
54			'newtag' => getRequest('newtag'),
55			'value' => getRequest('value'),
56			'groupids' => getRequest('groupids')
57		]);
58
59		if (!$is_valid) {
60			error($validator->getError());
61		}
62
63		return $is_valid;
64	}
65
66	protected function getManuallyValidatedFields() {
67		return [
68			'form' => [
69				'name' => 'correlation.edit',
70				'param' => 'add_condition',
71				'input_name' => 'new_condition'
72			],
73			'inputs' => [
74				'type' => $this->getInput('condition_type'),
75				'operator' => $this->getInput('operator'),
76				'tag' => getRequest('tag'),
77				'groupids' => getRequest('groupids'),
78				'oldtag' => getRequest('oldtag'),
79				'newtag' => getRequest('newtag'),
80				'value' => getRequest('value')
81			]
82		];
83	}
84
85	protected function getControllerResponseData() {
86		return [
87			'title' => _('New condition'),
88			'command' => '',
89			'message' => '',
90			'errors' => null,
91			'action' => $this->getAction(),
92			'type' => $this->getInput('type'),
93			'last_type' => $this->getConditionLastType(),
94			'user' => [
95				'debug_mode' => $this->getDebugMode()
96			]
97		];
98	}
99}
100