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$form = (new CForm())
27	->cleanItems()
28	->setName('dashboard_properties_form')
29	->addItem(getMessages());
30
31// Submit button is needed to enable submit event on Enter on inputs.
32$form->addItem((new CInput('submit', 'dashboard_properties_submit'))->addStyle('display: none;'));
33
34$form_list = new CFormList();
35
36$script_inline = '';
37
38if (!$data['dashboard']['template']) {
39	$owner_select = (new CMultiSelect([
40		'name' => 'userid',
41		'object_name' => 'users',
42		'data' => [$data['dashboard']['owner']],
43		'disabled' => in_array(CWebUser::getType(), [USER_TYPE_ZABBIX_USER, USER_TYPE_ZABBIX_ADMIN]),
44		'multiple' => false,
45		'popup' => [
46			'parameters' => [
47				'srctbl' => 'users',
48				'srcfld1' => 'userid',
49				'srcfld2' => 'fullname',
50				'dstfrm' => $form->getName(),
51				'dstfld1' => 'userid'
52			]
53		]
54	]))
55		->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
56		->setAriaRequired();
57
58	$form_list->addRow((new CLabel(_('Owner'), 'userid_ms'))->setAsteriskMark(), $owner_select);
59
60	$script_inline .= $owner_select->getPostJS();
61}
62
63$form_list->addRow((new CLabel(_('Name'), 'name'))->setAsteriskMark(),
64	(new CTextBox('name', $data['dashboard']['name'], false, DB::getFieldLength('dashboard', 'name')))
65		->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
66		->setAriaRequired()
67		->setAttribute('autofocus', 'autofocus')
68);
69
70$display_period_select = (new CSelect('display_period'))
71	->setValue($data['dashboard']['display_period'])
72	->setFocusableElementId('display_period')
73	->setWidth(ZBX_TEXTAREA_SMALL_WIDTH);
74
75foreach (DASHBOARD_DISPLAY_PERIODS as $period) {
76	$display_period_select->addOption(new CSelectOption($period, secondsToPeriod($period)));
77}
78
79$form_list->addRow(new CLabel(_('Default page display period'), 'display_period'), $display_period_select);
80
81$form_list->addRow(new CLabel(_('Start slideshow automatically'), 'auto_start'),
82	(new CCheckBox('auto_start'))->setChecked($data['dashboard']['auto_start'] == 1)
83);
84
85$form->addItem($form_list);
86
87$output = [
88	'header' => _('Dashboard properties'),
89	'body' => $form->toString(),
90	'buttons' => [
91		[
92			'title' => _('Apply'),
93			'keepOpen' => true,
94			'isSubmit' => true,
95			'action' => 'ZABBIX.Dashboard.applyProperties();'
96		]
97	]
98];
99
100if ($script_inline !== '') {
101	$output['script_inline'] = $script_inline;
102}
103
104if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) {
105	CProfiler::getInstance()->stop();
106	$output['debug'] = CProfiler::getInstance()->make()->toString();
107}
108
109echo json_encode($output);
110