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$web_layout_mode = CView::getLayoutMode();
23
24$screen_widget = (new CWidget())->setWebLayoutMode($web_layout_mode);
25
26if (empty($data['screen']) || empty($data['host'])) {
27	$screen_widget
28		->setTitle(_('Screens'))
29		->addItem(new CTableInfo());
30}
31else {
32	$screen_widget->setTitle([
33		$data['screen']['name'].' '._('on').' ',
34		new CSpan($data['host']['name'])
35	]);
36
37	$url = (new CUrl('host_screen.php'))
38		->setArgument('hostid', $data['hostid'])
39		->setArgument('screenid', $data['screenid']);
40
41	// host screen list
42	if (!empty($data['screens'])) {
43		$screen_combobox = new CComboBox('screenList', $url->toString(),
44			'javascript: redirect(this.options[this.selectedIndex].value);'
45		);
46		foreach ($data['screens'] as $screen) {
47			$screen_combobox->addItem(
48				$url
49					->setArgument('screenid', $screen['screenid'])
50					->toString(),
51				$screen['name']
52			);
53		}
54
55		$screen_widget->setControls((new CTag('nav', true,
56			(new CForm('get'))
57				->setAttribute('aria-label', _('Main filter'))
58				->addItem((new CList())
59					->addItem($screen_combobox)
60					->addItem(get_icon('fullscreen'))
61				)
62			))
63				->setAttribute('aria-label', _('Content controls'))
64		);
65	}
66
67	// append screens to widget
68	$screen_builder = new CScreenBuilder([
69		'screen' => $data['screen'],
70		'mode' => SCREEN_MODE_PREVIEW,
71		'hostid' => $data['hostid'],
72		'profileIdx' => $data['profileIdx'],
73		'profileIdx2' => $data['profileIdx2'],
74		'from' => $data['from'],
75		'to' => $data['to']
76	]);
77
78	$screen_widget->addItem(
79		(new CFilter(new CUrl()))
80			->setProfile($data['profileIdx'], $data['profileIdx2'])
81			->setActiveTab($data['active_tab'])
82			->addTimeSelector($screen_builder->timeline['from'], $screen_builder->timeline['to'],
83				$web_layout_mode != ZBX_LAYOUT_KIOSKMODE)
84	);
85
86	$screen_widget->addItem((new CDiv($screen_builder->show()))->addClass(ZBX_STYLE_TABLE_FORMS_CONTAINER));
87
88	CScreenBuilder::insertScreenStandardJs($screen_builder->timeline);
89}
90
91return $screen_widget;
92