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())->setTitle(_('Screens'));
22
23$controls = new CList();
24
25if (!$data['templateid']) {
26	$controls->addItem(
27		new CComboBox('config', 'screens.php', 'redirect(this.options[this.selectedIndex].value);', [
28			'screens.php' => _('Screens'),
29			'slides.php' => _('Slide shows')
30		])
31	);
32}
33
34$controls->addItem(new CSubmit('form', _('Create screen')));
35
36$createForm = (new CForm('get'))->cleanItems();
37
38if ($data['templateid']) {
39	$createForm->addVar('templateid', $data['templateid']);
40	$widget->addItem(get_header_host_table('screens', $data['templateid']));
41}
42else {
43	$controls->addItem((new CButton('form', _('Import')))->onClick('redirect("screen.import.php?rules_preset=screen")'));
44}
45
46$createForm->addItem($controls);
47$widget->setControls($createForm);
48
49// filter
50if (!$data['templateid']) {
51	$widget->addItem(
52		(new CFilter('web.screenconf.filter.state'))
53			->addColumn((new CFormList())->addRow(_('Name like'),
54				(new CTextBox('filter_name', $data['filter']['name']))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH)
55			))
56	);
57}
58
59// create form
60$screenForm = (new CForm())
61	->setName('screenForm')
62	->addVar('templateid', $data['templateid']);
63
64// create table
65$screenTable = (new CTableInfo())
66	->setHeader([
67		(new CColHeader(
68			(new CCheckBox('all_screens'))->onClick("checkAll('".$screenForm->getName()."', 'all_screens', 'screens');")
69		))->addClass(ZBX_STYLE_CELL_WIDTH),
70		make_sorting_header(_('Name'), 'name', $data['sort'], $data['sortorder']),
71		_('Dimension (cols x rows)'),
72		_('Actions')
73	]);
74
75foreach ($data['screens'] as $screen) {
76	$user_type = CWebUser::getType();
77
78	if ($data['templateid'] || $user_type == USER_TYPE_SUPER_ADMIN || $user_type == USER_TYPE_ZABBIX_ADMIN
79			|| $screen['editable']) {
80		$checkbox = new CCheckBox('screens['.$screen['screenid'].']', $screen['screenid']);
81		$action = new CLink(_('Properties'), '?form=update&screenid='.$screen['screenid'].url_param('templateid'));
82		$constructor = new CLink(_('Constructor'),
83			'screenedit.php?screenid='.$screen['screenid'].url_param('templateid')
84		);
85	}
86	else {
87		$checkbox = (new CCheckBox('screens['.$screen['screenid'].']', $screen['screenid']))
88			->setAttribute('disabled', 'disabled');
89		$action = '';
90		$constructor = '';
91	}
92
93	$screenTable->addRow([
94		$checkbox,
95		$data['templateid']
96			? $screen['name']
97			: new CLink($screen['name'], 'screens.php?elementid='.$screen['screenid']),
98		$screen['hsize'].' x '.$screen['vsize'],
99		new CHorList([$action, $constructor])
100	]);
101}
102
103// buttons
104$buttons = [];
105
106if (!$data['templateid']) {
107	$buttons['screen.export'] = ['name' => _('Export')];
108}
109
110$buttons['screen.massdelete'] = ['name' => _('Delete'), 'confirm' => _('Delete selected screens?')];
111
112// append table to form
113$screenForm->addItem([$screenTable, $data['paging'], new CActionButtonList('action', 'screens', $buttons)]);
114
115// append form to widget
116$widget->addItem($screenForm);
117
118return $widget;
119