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$widget = (new CWidget())
22	->setTitle(_('Actions'))
23	->setControls((new CForm('get'))
24		->cleanItems()
25		->addItem((new CList())
26			->addItem([
27				new CLabel(_('Event source'), 'eventsource'),
28				(new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN),
29				new CComboBox('eventsource', $data['eventsource'], 'submit()', [
30					EVENT_SOURCE_TRIGGERS => _('Triggers'),
31					EVENT_SOURCE_DISCOVERY => _('Discovery'),
32					EVENT_SOURCE_AUTO_REGISTRATION => _('Auto registration'),
33					EVENT_SOURCE_INTERNAL => _x('Internal', 'event source')
34				])
35			])
36			->addItem(new CSubmit('form', _('Create action')))
37		)
38	);
39
40// create form
41$actionForm = (new CForm())->setName('actionForm');
42
43// create table
44$actionTable = (new CTableInfo())
45	->setHeader([
46		(new CColHeader(
47			(new CCheckBox('all_items'))
48				->onClick("checkAll('".$actionForm->getName()."', 'all_items', 'g_actionid');")
49		))->addClass(ZBX_STYLE_CELL_WIDTH),
50		make_sorting_header(_('Name'), 'name', $data['sort'], $data['sortorder'], 'actionconf.php'),
51		_('Conditions'),
52		_('Operations'),
53		make_sorting_header(_('Status'), 'status', $data['sort'], $data['sortorder'], 'actionconf.php')
54	]);
55
56if ($this->data['actions']) {
57	$actionConditionStringValues = actionConditionValueToString($this->data['actions'], $this->data['config']);
58	$actionOperationDescriptions = getActionOperationDescriptions($this->data['actions']);
59
60	foreach ($this->data['actions'] as $aIdx => $action) {
61		$conditions = [];
62		$operations = [];
63
64		order_result($action['filter']['conditions'], 'conditiontype', ZBX_SORT_DOWN);
65
66		foreach ($action['filter']['conditions'] as $cIdx => $condition) {
67			$conditions[] = getConditionDescription($condition['conditiontype'], $condition['operator'],
68				$actionConditionStringValues[$aIdx][$cIdx]
69			);
70			$conditions[] = BR();
71		}
72
73		sortOperations($data['eventsource'], $action['operations']);
74
75		foreach ($action['operations'] as $oIdx => $operation) {
76			$operations[] = $actionOperationDescriptions[$aIdx][$oIdx];
77		}
78
79		if ($action['status'] == ACTION_STATUS_DISABLED) {
80			$status = (new CLink(_('Disabled'),
81				'actionconf.php?action=action.massenable&g_actionid[]='.$action['actionid'].url_param('eventsource'))
82			)
83				->addClass(ZBX_STYLE_LINK_ACTION)
84				->addClass(ZBX_STYLE_RED)
85				->addSID();
86		}
87		else {
88			$status = (new CLink(_('Enabled'),
89				'actionconf.php?action=action.massdisable&g_actionid[]='.$action['actionid'].url_param('eventsource'))
90			)
91				->addClass(ZBX_STYLE_LINK_ACTION)
92				->addClass(ZBX_STYLE_GREEN)
93				->addSID();
94		}
95
96		$actionTable->addRow([
97			new CCheckBox('g_actionid['.$action['actionid'].']', $action['actionid']),
98			new CLink($action['name'], 'actionconf.php?form=update&actionid='.$action['actionid']),
99			$conditions,
100			$operations,
101			$status
102		]);
103	}
104}
105
106// append table to form
107$actionForm->addItem([
108	$actionTable,
109	$this->data['paging'],
110	new CActionButtonList('action', 'g_actionid', [
111		'action.massenable' => ['name' => _('Enable'), 'confirm' => _('Enable selected actions?')],
112		'action.massdisable' => ['name' => _('Disable'), 'confirm' => _('Disable selected actions?')],
113		'action.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected actions?')]
114	])
115]);
116
117// append form to widget
118$widget->addItem($actionForm);
119
120return $widget;
121