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 * @var CView $this
24 */
25
26$auditWidget = (new CWidget())->setTitle(_('Action log'));
27
28// create filter
29$filterColumn = new CFormList();
30$filterColumn->addRow(new CLabel(_('Recipients'), 'filter_userids__ms'), [
31	(new CMultiSelect([
32		'name' => 'filter_userids[]',
33		'object_name' => 'users',
34		'data' => $data['filter_userids'],
35		'placeholder' => '',
36		'popup' => [
37			'parameters' => [
38				'srctbl' => 'users',
39				'srcfld1' => 'userid',
40				'srcfld2' => 'fullname',
41				'dstfrm' => 'zbx_filter',
42				'dstfld1' => 'filter_userids_'
43			]
44		]
45	]))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH)
46]);
47
48$auditWidget->addItem(
49	(new CFilter(new CUrl('auditacts.php')))
50		->setProfile($data['timeline']['profileIdx'])
51		->setActiveTab($data['active_tab'])
52		->addTimeSelector($data['timeline']['from'], $data['timeline']['to'])
53		->addFilterTab(_('Filter'), [$filterColumn])
54);
55
56// create form
57$auditForm = (new CForm('get'))->setName('auditForm');
58
59// create table
60$auditTable = (new CTableInfo())
61	->setHeader([
62		_('Time'),
63		_('Action'),
64		_('Type'),
65		_('Recipient'),
66		_('Message'),
67		_('Status'),
68		_('Info')
69	]);
70
71foreach ($this->data['alerts'] as $alert) {
72	$mediatype = array_pop($alert['mediatypes']);
73
74	if ($alert['status'] == ALERT_STATUS_SENT) {
75		$status = ($alert['alerttype'] == ALERT_TYPE_MESSAGE)
76			? (new CSpan(_('Sent')))->addClass(ZBX_STYLE_GREEN)
77			: (new CSpan(_('Executed')))->addClass(ZBX_STYLE_GREEN);
78	}
79	elseif ($alert['status'] == ALERT_STATUS_NOT_SENT || $alert['status'] == ALERT_STATUS_NEW) {
80		$status = (new CSpan([
81			_('In progress').':',
82			BR(),
83			_n('%1$s retry left', '%1$s retries left', $mediatype['maxattempts'] - $alert['retries'])
84		]))->addClass(ZBX_STYLE_YELLOW);
85	}
86	else {
87		$status = (new CSpan(_('Failed')))->addClass(ZBX_STYLE_RED);
88	}
89
90	$message = ($alert['alerttype'] == ALERT_TYPE_MESSAGE)
91		? [
92			bold(_('Subject').':'),
93			BR(),
94			$alert['subject'],
95			BR(),
96			BR(),
97			bold(_('Message').':'),
98			BR(),
99			zbx_nl2br($alert['message'])
100		]
101		: [
102			bold(_('Command').':'),
103			BR(),
104			zbx_nl2br($alert['message'])
105		];
106
107	$info_icons = [];
108	if ($alert['error'] !== '') {
109		$info_icons[] = makeErrorIcon($alert['error']);
110	}
111
112	$recipient = (isset($alert['userid']) && $alert['userid'])
113		? makeEventDetailsTableUser($alert + ['action_type' => ZBX_EVENT_HISTORY_ALERT], $data['users'])
114		: zbx_nl2br($alert['sendto']);
115
116	$auditTable->addRow([
117		zbx_date2str(DATE_TIME_FORMAT_SECONDS, $alert['clock']),
118		$this->data['actions'][$alert['actionid']]['name'],
119		($mediatype) ? $mediatype['name'] : '',
120		$recipient,
121		$message,
122		$status,
123		makeInformationList($info_icons)
124	]);
125}
126
127// append table to form
128$auditForm->addItem([$auditTable, $this->data['paging']]);
129
130// append navigation bar js
131$objData = [
132	'id' => 'timeline_1',
133	'domid' => 'events',
134	'loadSBox' => 0,
135	'loadImage' => 0,
136	'dynamic' => 0,
137	'mainObject' => 1
138];
139zbx_add_post_js('timeControl.addObject("events", '.zbx_jsvalue($data['timeline']).', '.zbx_jsvalue($objData).');');
140zbx_add_post_js('timeControl.processObjects();');
141
142// append form to widget
143$auditWidget->addItem($auditForm);
144
145$auditWidget->show();
146