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 ($data['error']) { 27 show_error_message($data['error']); 28} 29 30$this->addJsFile('multiselect.js'); 31$this->addJsFile('layout.mode.js'); 32$this->addJsFile('class.calendar.js'); 33$this->addJsFile('gtlc.js'); 34 35$this->enableLayoutModes(); 36$web_layout_mode = $this->getLayoutMode(); 37 38$widget = (new CWidget()) 39 ->setTitle(_('Graphs')) 40 ->setWebLayoutMode($web_layout_mode) 41 ->setControls( 42 (new CTag('nav', true, (new CList()) 43 ->addItem((new CForm('get')) 44 ->cleanItems() 45 ->setName('main_filter') 46 ->addVar('action', 'charts.view') 47 ->setAttribute('aria-label', _('Main filter')) 48 ->addItem((new CList()) 49 ->addItem([ 50 new CLabel(_('View as'), 'label-view-as'), 51 (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), 52 (new CSelect('view_as')) 53 ->setId('view-as') 54 ->setFocusableElementId('label-view-as') 55 ->setValue($data['view_as']) 56 ->addOption(new CSelectOption(HISTORY_GRAPH, _('Graph'))) 57 ->addOption(new CSelectOption(HISTORY_VALUES, _('Values'))) 58 ]) 59 ) 60 ) 61 ->addItem(($data['filter_search_type'] == ZBX_SEARCH_TYPE_STRICT && count($data['graphids']) == 1) 62 ? get_icon('favourite', [ 63 'fav' => 'web.favorite.graphids', 64 'elname' => 'graphid', 65 'elid' => $data['graphids'][0] 66 ]) 67 : null 68 ) 69 ->addItem(get_icon('kioskmode', ['mode' => $web_layout_mode])) 70 ))->setAttribute('aria-label', _('Content controls')) 71 ); 72 73$filter = (new CFilter((new CUrl('zabbix.php'))->setArgument('action', 'charts.view'))) 74 ->setProfile($data['timeline']['profileIdx'], $data['timeline']['profileIdx2']) 75 ->setActiveTab($data['active_tab']) 76 ->addTimeSelector($data['timeline']['from'], $data['timeline']['to'], 77 $web_layout_mode != ZBX_LAYOUT_KIOSKMODE 78 ) 79 ->addFormItem((new CVar('view_as', $data['view_as']))->removeId()) 80 ->addFormItem((new CVar('action', 'charts.view'))->removeId()); 81 82if ($web_layout_mode == ZBX_LAYOUT_NORMAL) { 83 $filter->addFilterTab(_('Filter'), [ 84 (new CFormList()) 85 ->addRow((new CLabel(_('Host'), 'filter_hostids__ms')), 86 (new CMultiSelect([ 87 'multiple' => false, 88 'name' => 'filter_hostids[]', 89 'object_name' => 'hosts', 90 'data' => $data['ms_hosts'], 91 'popup' => [ 92 'parameters' => [ 93 'srctbl' => 'hosts', 94 'srcfld1' => 'hostid', 95 'dstfrm' => 'zbx_filter', 96 'dstfld1' => 'filter_hostids_', 97 'real_hosts' => true, 98 'with_graphs' => true 99 ] 100 ] 101 ]))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH) 102 ) 103 ->addRow((new CLabel(_('Search type'), 'filter_search_type')), 104 (new CRadioButtonList('filter_search_type', $data['filter_search_type'])) 105 ->addValue(_('Strict'), ZBX_SEARCH_TYPE_STRICT) 106 ->addValue(_('Pattern'), ZBX_SEARCH_TYPE_PATTERN) 107 ->setModern(true) 108 ) 109 ->addRow( 110 (new CLabel(_('Graphs'), 'filter_graphids__ms')), 111 (new CMultiSelect([ 112 'multiple' => true, 113 'name' => 'filter_graphids[]', 114 'object_name' => 'graphs', 115 'data' => $data['ms_graphs'], 116 'autosuggest' => [ 117 'filter_preselect_fields' => [ 118 'hosts' => 'filter_hostids_' 119 ] 120 ], 121 'popup' => [ 122 'filter_preselect_fields' => [ 123 'hosts' => 'filter_hostids_' 124 ], 125 'parameters' => [ 126 'srctbl' => 'graphs', 127 'srcfld1' => 'graphid', 128 'dstfrm' => 'zbx_filter', 129 'dstfld1' => 'filter_graphids_', 130 'real_hosts' => true 131 ] 132 ] 133 ]))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH), 134 'ms_graphids', 135 ($data['filter_search_type'] == ZBX_SEARCH_TYPE_STRICT) ? '' : ZBX_STYLE_DISPLAY_NONE 136 ) 137 ->addRow( 138 (new CLabel(_('Graphs'), 'filter_graph_patterns__ms')), 139 (new CPatternSelect([ 140 'placeholder' => _('graph pattern'), 141 'name' => 'filter_graph_patterns[]', 142 'object_name' => 'graphs', 143 'data' => $data['ms_graph_patterns'], 144 'autosuggest' => [ 145 'filter_preselect_fields' => [ 146 'hosts' => 'filter_hostids_' 147 ] 148 ], 149 'popup' => [ 150 'filter_preselect_fields' => [ 151 'hosts' => 'filter_hostids_' 152 ], 153 'parameters' => [ 154 'srctbl' => 'graphs', 155 'srcfld1' => 'graphid', 156 'dstfrm' => 'zbx_filter', 157 'dstfld1' => 'filter_graph_patterns_', 158 'real_hosts' => true 159 ] 160 ], 161 'add_post_js' => true 162 ]))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH), 163 'ms_graph_patterns', 164 ($data['filter_search_type'] == ZBX_SEARCH_TYPE_STRICT) ? ZBX_STYLE_DISPLAY_NONE : '' 165 ) 166 ]); 167} 168 169$widget->addItem($filter); 170 171if ($data['must_specify_host']) { 172 $widget->addItem((new CTableInfo())->setNoDataMessage(_('Specify host to see the graphs.'))); 173} 174elseif ($data['graphids']) { 175 $table = (new CTable())->setAttribute('style', 'width: 100%;'); 176 177 if ($data['view_as'] === HISTORY_VALUES) { 178 $this->addJsFile('flickerfreescreen.js'); 179 $screen = CScreenBuilder::getScreen([ 180 'resourcetype' => SCREEN_RESOURCE_HISTORY, 181 'action' => HISTORY_VALUES, 182 'itemids' => $data['itemids'], 183 'pageFile' => (new CUrl('zabbix.php')) 184 ->setArgument('action', 'charts.view') 185 ->setArgument('filter_graph_patterns', $data['filter_graph_patterns']) 186 ->setArgument('filter_graphids', $data['filter_graphids']) 187 ->setArgument('filter_hostids', $data['filter_hostids']) 188 ->setArgument('view_as', $data['view_as']) 189 ->getUrl(), 190 'profileIdx' => $data['timeline']['profileIdx'], 191 'profileIdx2' => $data['timeline']['profileIdx2'], 192 'from' => $data['timeline']['from'], 193 'to' => $data['timeline']['to'], 194 'page' => $data['page'] 195 ]); 196 197 CScreenBuilder::insertScreenStandardJs($screen->timeline); 198 199 $table->addRow($screen->get()); 200 } 201 else { 202 $table->setId('charts'); 203 } 204 205 $widget->addItem($table); 206} 207else { 208 $widget->addItem(new CTableInfo()); 209} 210 211$widget->show(); 212 213$this->includeJsFile('monitoring.charts.view.js.php', [ 214 'charts' => $data['charts'], 215 'timeline' => $data['timeline'], 216 'config' => [ 217 'refresh_interval' => (int) CWebUser::getRefresh(), 218 'refresh_list' => $data['filter_search_type'] == ZBX_SEARCH_TYPE_PATTERN, 219 'filter_graph_patterns' => $data['filter_graph_patterns'], 220 'filter_hostids' => $data['filter_hostids'] 221 ] 222]); 223