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 26if (array_key_exists('error', $data)) { 27 show_error_message($data['error']); 28} 29 30if (array_key_exists('no_data', $data)) { 31 (new CWidget()) 32 ->setTitle(_('Dashboards')) 33 ->addItem(new CTableInfo()) 34 ->show(); 35 36 return; 37} 38 39$this->addJsFile('flickerfreescreen.js'); 40$this->addJsFile('gtlc.js'); 41$this->addJsFile('class.calendar.js'); 42$this->addJsFile('class.dashboard.js'); 43$this->addJsFile('class.dashboard.page.js'); 44$this->addJsFile('class.dashboard.widget.placeholder.js'); 45$this->addJsFile('class.widget.js'); 46$this->addJsFile('class.widget.iterator.js'); 47$this->addJsFile('class.widget.clock.js'); 48$this->addJsFile('class.widget.graph.js'); 49$this->addJsFile('class.widget.graph-prototype.js'); 50$this->addJsFile('class.widget.map.js'); 51$this->addJsFile('class.widget.navtree.js'); 52$this->addJsFile('class.widget.paste-placeholder.js'); 53$this->addJsFile('class.widget.problems.js'); 54$this->addJsFile('class.widget.problemsbysv.js'); 55$this->addJsFile('class.widget.svggraph.js'); 56$this->addJsFile('class.widget.trigerover.js'); 57$this->addJsFile('layout.mode.js'); 58$this->addJsFile('class.sortable.js'); 59 60$this->includeJsFile('monitoring.host.dashboard.view.js.php'); 61 62$this->enableLayoutModes(); 63$web_layout_mode = $this->getLayoutMode(); 64 65$widget = (new CWidget()) 66 ->setTitle($data['dashboard']['name']) 67 ->setWebLayoutMode($web_layout_mode) 68 ->setControls((new CTag('nav', true, 69 (new CList()) 70 ->addItem( 71 (new CForm('get')) 72 ->cleanItems() 73 ->addVar('action', 'host.dashboard.view') 74 ->addVar('hostid', $data['host']['hostid']) 75 ->addItem((new CLabel(_('Dashboard'), 'label-dashboard'))->addClass(ZBX_STYLE_FORM_INPUT_MARGIN)) 76 ->addItem( 77 (new CSelect('dashboardid')) 78 ->setId('dashboardid') 79 ->setFocusableElementId('label-dashboard') 80 ->setValue($data['dashboard']['dashboardid']) 81 ->addOptions(CSelect::createOptionsFromArray($data['host_dashboards'])) 82 ->addClass(ZBX_STYLE_HEADER_Z_SELECT) 83 ) 84 ) 85 ->addItem(get_icon('kioskmode', ['mode' => $web_layout_mode])) 86 ))->setAttribute('aria-label', _('Content controls'))) 87 ->setKioskModeControls( 88 (count($data['dashboard']['pages']) > 1) 89 ? (new CList()) 90 ->addClass(ZBX_STYLE_DASHBOARD_KIOSKMODE_CONTROLS) 91 ->addItem( 92 (new CSimpleButton(null)) 93 ->addClass(ZBX_STYLE_BTN_DASHBOARD_KIOSKMODE_PREVIOUS_PAGE) 94 ->setTitle(_('Previous page')) 95 ) 96 ->addItem( 97 (new CSimpleButton(null)) 98 ->addClass(ZBX_STYLE_BTN_DASHBOARD_KIOSKMODE_TOGGLE_SLIDESHOW) 99 ->setTitle(($data['dashboard']['dashboardid'] !== null && $data['dashboard']['auto_start'] == 1) 100 ? _s('Stop slideshow') 101 : _s('Start slideshow') 102 ) 103 ->addClass( 104 ($data['dashboard']['dashboardid'] !== null && $data['dashboard']['auto_start'] == 1) 105 ? 'slideshow-state-started' 106 : 'slideshow-state-stopped' 107 ) 108 ) 109 ->addItem( 110 (new CSimpleButton(null)) 111 ->addClass(ZBX_STYLE_BTN_DASHBOARD_KIOSKMODE_NEXT_PAGE) 112 ->setTitle(_('Next page')) 113 ) 114 : null 115 ) 116 ->setNavigation((new CList())->addItem(new CBreadcrumbs([ 117 (new CSpan())->addItem(new CLink(_('All hosts'), (new CUrl('zabbix.php'))->setArgument('action', 'host.view'))), 118 (new CSpan())->addItem($data['host']['name']), 119 (new CSpan()) 120 ->addItem(new CLink($data['dashboard']['name'], 121 (new CUrl('zabbix.php')) 122 ->setArgument('action', 'host.dashboard.view') 123 ->setArgument('hostid', $data['host']['hostid']) 124 )) 125 ->addClass(ZBX_STYLE_SELECTED) 126 ]))); 127 128if ($data['has_time_selector']) { 129 $widget->addItem( 130 (new CFilter(new CUrl())) 131 ->setProfile($data['time_period']['profileIdx'], $data['time_period']['profileIdx2']) 132 ->setActiveTab($data['active_tab']) 133 ->addTimeSelector($data['time_period']['from'], $data['time_period']['to'], 134 $web_layout_mode != ZBX_LAYOUT_KIOSKMODE 135 ) 136 ); 137} 138 139if (count($data['dashboard']['pages']) > 1 140 || (count($data['dashboard']['pages']) == 1 && $data['dashboard']['pages'][0]['widgets'])) { 141 $dashboard = (new CDiv())->addClass(ZBX_STYLE_DASHBOARD); 142 143 if (count($data['dashboard']['pages']) > 1) { 144 $dashboard->addClass(ZBX_STYLE_DASHBOARD_IS_MULTIPAGE); 145 } 146 147 if ($web_layout_mode != ZBX_LAYOUT_KIOSKMODE) { 148 $dashboard->addItem( 149 (new CDiv()) 150 ->addClass(ZBX_STYLE_DASHBOARD_NAVIGATION) 151 ->addItem((new CDiv())->addClass(ZBX_STYLE_DASHBOARD_NAVIGATION_TABS)) 152 ->addItem( 153 (new CDiv()) 154 ->addClass(ZBX_STYLE_DASHBOARD_NAVIGATION_CONTROLS) 155 ->addItem([ 156 (new CSimpleButton()) 157 ->addClass(ZBX_STYLE_DASHBOARD_PREVIOUS_PAGE) 158 ->addClass('btn-iterator-page-previous') 159 ->setEnabled(false), 160 (new CSimpleButton()) 161 ->addClass(ZBX_STYLE_DASHBOARD_NEXT_PAGE) 162 ->addClass('btn-iterator-page-next') 163 ->setEnabled(false), 164 (new CSimpleButton([ 165 (new CSpan(_s('Start slideshow')))->addClass('slideshow-state-stopped'), 166 (new CSpan(_s('Stop slideshow')))->addClass('slideshow-state-started') 167 ])) 168 ->addClass(ZBX_STYLE_BTN_ALT) 169 ->addClass(ZBX_STYLE_DASHBOARD_TOGGLE_SLIDESHOW) 170 ->addClass( 171 ($data['dashboard']['dashboardid'] !== null && $data['dashboard']['auto_start'] == 1) 172 ? 'slideshow-state-started' 173 : 'slideshow-state-stopped' 174 ) 175 ]) 176 ) 177 ); 178 } 179 180 $dashboard->addItem((new CDiv())->addClass(ZBX_STYLE_DASHBOARD_GRID)); 181 182 $widget 183 ->addItem($dashboard) 184 ->show(); 185 186 (new CScriptTag(' 187 initializeView( 188 '.json_encode($data['host']).', 189 '.json_encode($data['dashboard']).', 190 '.json_encode($data['widget_defaults']).', 191 '.json_encode($data['time_period']).', 192 '.json_encode($web_layout_mode).' 193 ); 194 ')) 195 ->setOnDocumentReady() 196 ->show(); 197} 198else { 199 $widget 200 ->addItem(new CTableInfo()) 201 ->show(); 202} 203