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