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
26if ($data['uncheck']) {
27	uncheckTableRows('dashboard');
28}
29$this->addJsFile('layout.mode.js');
30
31$this->enableLayoutModes();
32$web_layout_mode = $this->getLayoutMode();
33
34$widget = (new CWidget())
35	->setTitle(_('Dashboards'))
36	->setWebLayoutMode($web_layout_mode)
37	->setControls(
38		(new CTag('nav', true,
39			(new CList())
40				->addItem(
41					(new CRedirectButton(_('Create dashboard'),
42						(new CUrl('zabbix.php'))
43							->setArgument('action', 'dashboard.view')
44							->setArgument('new', '1')
45							->getUrl()
46					))->setEnabled($data['allowed_edit'])
47				)
48				->addItem(get_icon('kioskmode', ['mode' => $web_layout_mode]))
49			)
50		)->setAttribute('aria-label', _('Content controls'))
51	);
52
53if ($web_layout_mode == ZBX_LAYOUT_NORMAL) {
54	$widget
55		->addItem((new CFilter((new CUrl('zabbix.php'))->setArgument('action', 'dashboard.list')))
56		->setProfile($data['profileIdx'])
57		->setActiveTab($data['active_tab'])
58		->addFilterTab(_('Filter'), [
59			(new CFormList())->addRow(_('Name'),
60				(new CTextBox('filter_name', $data['filter']['name']))->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH)
61			),
62			(new CFormList())->addRow(_('Show'),
63				(new CRadioButtonList('filter_show', (int) $data['filter']['show']))
64					->addValue(_('All'), DASHBOARD_FILTER_SHOW_ALL)
65					->addValue(_('Created by me'), DASHBOARD_FILTER_SHOW_MY)
66					->setModern(true)
67			)
68		])
69		->addVar('action', 'dashboard.list')
70	);
71}
72
73$form = (new CForm())->setName('dashboardForm');
74
75// Create dashboard table.
76$table = (new CTableInfo())
77	->addClass(ZBX_STYLE_DASHBOARD_LIST)
78	->setHeader([
79		(new CColHeader(
80			(new CCheckBox('all_dashboards'))
81				->onClick("checkAll('".$form->getName()."', 'all_dashboards', 'dashboardids');")
82		))->addClass(ZBX_STYLE_CELL_WIDTH),
83		make_sorting_header(_('Name'), 'name', $data['sort'], $data['sortorder'],
84			(new CUrl('zabbix.php'))
85				->setArgument('action', 'dashboard.list')
86				->getUrl())
87	]);
88
89foreach ($data['dashboards'] as $dashboard) {
90	$tags = [];
91
92	if ($dashboard['userid'] == CWebUser::$data['userid']) {
93		$tags[] = (new CSpan(_('My')))->addClass(ZBX_STYLE_STATUS_GREEN);
94
95		if ($dashboard['private'] == PUBLIC_SHARING || count($dashboard['users']) > 0
96				|| count($dashboard['userGroups']) > 0) {
97			$tags[] = ' ';
98			$tags[] = (new CSpan(_('Shared')))->addClass(ZBX_STYLE_STATUS_YELLOW);
99		}
100	}
101
102	$table->addRow([
103		(new CCheckBox('dashboardids['.$dashboard['dashboardid'].']', $dashboard['dashboardid']))
104			->setEnabled($dashboard['editable']),
105		(new CDiv([
106			new CLink($dashboard['name'],
107				(new CUrl('zabbix.php'))
108					->setArgument('action', 'dashboard.view')
109					->setArgument('dashboardid', $dashboard['dashboardid'])
110					->getUrl()
111			),
112			$tags ? new CDiv($tags) : null
113		]))->addClass(ZBX_STYLE_DASHBOARD_LIST_ITEM)
114	]);
115}
116
117$form->addItem([
118	$table,
119	$data['paging'],
120	new CActionButtonList('action', 'dashboardids', [
121		'dashboard.delete' => [
122			'name' => _('Delete'),
123			'confirm' => _('Delete selected dashboards?'),
124			'disabled' => !$data['allowed_edit']
125		]
126	], 'dashboard')
127]);
128
129$widget->addItem($form);
130$widget->show();
131