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
22if (array_key_exists('error', $data)) {
23	show_error_message($data['error']);
24}
25else {
26	$this->addJsFile('flickerfreescreen.js');
27	$this->addJsFile('gtlc.js');
28	$this->addJsFile('dashboard.grid.js');
29	$this->addJsFile('class.calendar.js');
30	$this->addJsFile('multiselect.js');
31	$this->addJsFile('layout.mode.js');
32	$this->addJsFile('class.coverride.js');
33	$this->addJsFile('class.cverticalaccordion.js');
34	$this->addJsFile('class.crangecontrol.js');
35	$this->addJsFile('colorpicker.js');
36	$this->addJsFile('class.csvggraph.js');
37	$this->addJsFile('csvggraphwidget.js');
38	$this->addJsFile('class.cclock.js');
39	$this->addJsFile('class.cnavtree.js');
40	$this->addJsFile('class.mapwidget.js');
41	$this->addJsFile('class.svg.canvas.js');
42	$this->addJsFile('class.svg.map.js');
43
44	$this->includeJSfile('app/views/monitoring.dashboard.view.js.php');
45
46	$breadcrumbs = include 'monitoring.dashboard.breadcrumbs.php';
47
48	$main_filter_form = null;
49
50	if ($data['dynamic']['has_dynamic_widgets']) {
51		$main_filter_form = (new CForm('get'))
52			->cleanItems()
53			->setAttribute('aria-label', _('Main filter'))
54			->addVar('action', 'dashboard.view')
55			->addItem((new CList())
56				->addItem([
57					new CLabel(_('Group'), 'groupid'),
58					(new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN),
59					$data['pageFilter']->getGroupsCB()
60				])
61				->addItem([
62					new CLabel(_('Host'), 'hostid'),
63					(new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN),
64					$data['pageFilter']->getHostsCB()
65				])
66		);
67	}
68
69	$web_layout_mode = CView::getLayoutMode();
70
71	$widget = (new CWidget())
72		->setTitle($data['dashboard']['name'])
73		->setWebLayoutMode($web_layout_mode)
74		->setControls((new CList())
75			->setId('dashbrd-control')
76			->addItem($main_filter_form)
77			->addItem((new CTag('nav', true, [
78				(new CList())
79					->addItem((new CButton('dashbrd-edit', _('Edit dashboard')))
80						->setEnabled($data['dashboard']['editable'])
81						->setAttribute('aria-disabled', !$data['dashboard']['editable'] ? 'true' : null)
82					)
83					->addItem((new CButton('', '&nbsp;'))
84						->addClass(ZBX_STYLE_BTN_ACTION)
85						->setId('dashbrd-actions')
86						->setTitle(_('Actions'))
87						->setAttribute('aria-haspopup', true)
88						->setMenuPopup(CMenuPopupHelper::getDashboard($data['dashboard']['dashboardid']))
89					)
90					->addItem(get_icon('fullscreen'))
91			]))->setAttribute('aria-label', _('Content controls'))
92		)
93		->addItem((new CListItem([
94			(new CTag('nav', true, [
95				new CList([
96					(new CButton('dashbrd-config'))->addClass(ZBX_STYLE_BTN_DASHBRD_CONF),
97					(new CButton('dashbrd-add-widget', [(new CSpan())->addClass(ZBX_STYLE_PLUS_ICON), _('Add widget')]))
98						->addClass(ZBX_STYLE_BTN_ALT),
99					(new CButton('dashbrd-save', _('Save changes'))),
100					(new CLink(_('Cancel'), '#'))->setId('dashbrd-cancel'),
101					''
102				])
103			]))
104				->setAttribute('aria-label', _('Content controls'))
105				->addClass(ZBX_STYLE_DASHBRD_EDIT)
106			]))
107				->addStyle('display: none')
108	))
109		->setBreadcrumbs((new CList())
110			->setAttribute('role', 'navigation')
111			->setAttribute('aria-label', _x('Hierarchy', 'screen reader'))
112			->addItem($breadcrumbs)
113			->addClass(ZBX_STYLE_OBJECT_GROUP)
114			->addClass(ZBX_STYLE_FILTER_BREADCRUMB)
115		);
116
117	$timeline = null;
118	if ($data['show_timeselector']) {
119		$timeline = (new CFilter(new CUrl()))
120			->setProfile($data['timeline']['profileIdx'], $data['timeline']['profileIdx2'])
121			->setActiveTab($data['active_tab'])
122			->addTimeSelector($data['timeline']['from'], $data['timeline']['to'],
123				$web_layout_mode != ZBX_LAYOUT_KIOSKMODE);
124		}
125
126	$widget
127		->addItem($timeline)
128		->addItem((new CDiv())->addClass(ZBX_STYLE_DASHBRD_GRID_CONTAINER))
129		->show();
130
131	/*
132	 * Javascript
133	 */
134	// Activate blinking.
135	$this->addPostJS('jqBlink.blink();');
136
137	$dashboard_data = [
138		// Name is required for new dashboard creation.
139		'name'		=> $data['dashboard']['name'],
140		'userid'	=> $data['dashboard']['owner']['id'],
141		'dynamic'	=> $data['dynamic']
142	];
143
144	if (array_key_exists('sharing', $data['dashboard'])) {
145		$dashboard_data['sharing'] = $data['dashboard']['sharing'];
146	}
147
148	$dashboard_options = [
149		'max-rows' => DASHBOARD_MAX_ROWS,
150		'max-columns' => DASHBOARD_MAX_COLUMNS,
151		'widget-max-rows' => DASHBOARD_WIDGET_MAX_ROWS,
152		'editable' => $data['dashboard']['editable'],
153		'edit_mode' => $data['dashboard_edit_mode']
154	];
155	if ($data['dashboard']['dashboardid'] != 0) {
156		$dashboard_data['id'] = $data['dashboard']['dashboardid'];
157	}
158	else {
159		$dashboard_options['updated'] = true;
160	}
161
162	// must be done before adding widgets, because it causes dashboard to resize.
163	if ($data['show_timeselector']) {
164		$this->addPostJS(
165			'timeControl.addObject("scrollbar", '.CJs::encodeJson($data['timeline']).', '.
166				CJs::encodeJson($data['timeControlData']).
167			');'.
168			'timeControl.processObjects();'
169		);
170	}
171
172	if ($web_layout_mode === ZBX_LAYOUT_KIOSKMODE) {
173		$dashboard_options['kioskmode'] = true;
174	}
175
176	// Initialize dashboard grid.
177	$this->addPostJS(
178		'jQuery(".'.ZBX_STYLE_DASHBRD_GRID_CONTAINER.'")'.
179			'.dashboardGrid('.CJs::encodeJson($dashboard_options).')'.
180			'.dashboardGrid("setDashboardData", '.CJs::encodeJson($dashboard_data).')'.
181			'.dashboardGrid("setWidgetDefaults", '.CJs::encodeJson($data['widget_defaults']).')'.
182			'.dashboardGrid("addWidgets", '.CJs::encodeJson($data['grid_widgets']).
183		');'
184	);
185}
186