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$this->includeJsFile('monitoring.screen.js.php');
27
28$web_layout_mode = CViewHelper::loadLayoutMode();
29
30$widget = (new CWidget())->setWebLayoutMode($web_layout_mode);
31
32if ($web_layout_mode == ZBX_LAYOUT_NORMAL) {
33	$widget
34		->setTitle(_('Screens'))
35		->setTitleSubmenu([
36			'main_section' => [
37				'items' => [
38					'screens.php' => _('Screens'),
39					'slides.php' => _('Slide shows')
40				]
41			]
42		])
43		->addItem((new CList())
44			->setAttribute('role', 'navigation')
45			->setAttribute('aria-label', _x('Hierarchy', 'screen reader'))
46			->addClass(ZBX_STYLE_OBJECT_GROUP)
47			->addClass(ZBX_STYLE_FILTER_BREADCRUMB)
48			->addItem([
49				(new CSpan())->addItem(new CLink(_('All screens'), 'screenconf.php')),
50				'/',
51				(new CSpan())
52					->addClass(ZBX_STYLE_SELECTED)
53					->addItem(
54						new CLink($data['screen']['name'], (new CUrl('screens.php'))
55							->setArgument('elementid', $data['screen']['screenid'])
56					))
57		]));
58}
59
60$controls = new CList();
61
62if ($data['has_dynamic_widgets']) {
63	$controls
64		->addItem(new CLabel(_('Host'), 'hostid'))
65		->addItem(
66			(new CMultiSelect([
67				'name' => 'dynamic_hostid',
68				'object_name' => 'hosts',
69				'data' => $data['host'],
70				'multiple' => false,
71				'popup' => [
72					'parameters' => [
73						'srctbl' => 'hosts',
74						'srcfld1' => 'hostid',
75						'dstfld1' => 'dynamic_hostid',
76						'dstfrm' => 'headerForm',
77						'monitored_hosts' => 1,
78						'with_items' => 1
79					]
80				]
81			]))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH)
82		);
83
84	zbx_add_post_js(
85		'jQuery("#dynamic_hostid").on("change", function() {'.
86			'var hosts = jQuery(this).multiSelect("getData"),'.
87				'url = new Curl("screens.php", false);'.
88
89			// Make URL.
90			'url.setArgument("elementid", '.$data['screen']['screenid'].');'.
91			'if (hosts.length) {'.
92				'url.setArgument("hostid", hosts[0].id);'.
93			'}'.
94			'else {'.
95				'url.setArgument("reset", "reset");'.
96			'}'.
97
98			// Push URL change.
99			'return redirect(url.getUrl(), "get", "", false, false);'.
100		'});'
101	);
102}
103
104$controls
105	->addItem($data['screen']['editable']
106		? (new CButton('edit', _('Edit screen')))
107			->onClick('redirect("screenedit.php?screenid='.$data['screen']['screenid'].'", "get", "", false, false)')
108		: null
109	)
110	->addItem(get_icon('favourite', [
111			'fav' => 'web.favorite.screenids',
112			'elname' => 'screenid',
113			'elid' => $data['screen']['screenid']
114		]
115	))
116	->addItem(get_icon('kioskmode', ['mode' => $web_layout_mode]));
117
118$widget->setControls((new CTag('nav', true, (new CList())
119	->addItem((new CForm('get'))
120		->setName('headerForm')
121		->addItem($controls)
122	)))
123		->setAttribute('aria-label', _('Content controls'))
124);
125
126// Append screens to widget.
127$screenBuilder = new CScreenBuilder([
128	'screenid' => $data['screen']['screenid'],
129	'mode' => SCREEN_MODE_PREVIEW,
130	'hostid' => array_key_exists('hostid', $data) ? $data['hostid'] : null,
131	'profileIdx' => $data['profileIdx'],
132	'profileIdx2' => $data['profileIdx2'],
133	'from' => $data['from'],
134	'to' => $data['to']
135]);
136
137$widget->addItem(
138	(new CFilter(new CUrl()))
139		->setProfile($data['profileIdx'], $data['profileIdx2'])
140		->setActiveTab($data['active_tab'])
141		->addTimeSelector($screenBuilder->timeline['from'], $screenBuilder->timeline['to'],
142			$web_layout_mode != ZBX_LAYOUT_KIOSKMODE)
143);
144
145$widget->addItem((new CDiv($screenBuilder->show()))->addClass(ZBX_STYLE_TABLE_FORMS_CONTAINER));
146
147CScreenBuilder::insertScreenStandardJs($screenBuilder->timeline);
148
149$widget->show();
150