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 22require_once dirname(__FILE__).'/include/config.inc.php'; 23require_once dirname(__FILE__).'/include/graphs.inc.php'; 24 25$page['file'] = 'chart7.php'; 26$page['type'] = PAGE_TYPE_IMAGE; 27 28require_once dirname(__FILE__).'/include/page_header.php'; 29 30// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION 31$fields = [ 32 'from' => [T_ZBX_RANGE_TIME, O_OPT, P_SYS, null, null], 33 'to' => [T_ZBX_RANGE_TIME, O_OPT, P_SYS, null, null], 34 'profileIdx' => [T_ZBX_STR, O_OPT, null, null, null], 35 'profileIdx2' => [T_ZBX_STR, O_OPT, null, null, null], 36 'name' => [T_ZBX_STR, O_OPT, null, null, null], 37 'width' => [T_ZBX_INT, O_OPT, null, BETWEEN(CPieGraphDraw::GRAPH_WIDTH_MIN, 65535), null], 38 'height' => [T_ZBX_INT, O_OPT, null, BETWEEN(CPieGraphDraw::GRAPH_HEIGHT_MIN, 65535), null], 39 'graphtype' => [T_ZBX_INT, O_OPT, null, IN('2,3'), null], 40 'graph3d' => [T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null], 41 'legend' => [T_ZBX_INT, O_OPT, null, IN('0,1'), null], 42 'i' => [T_ZBX_STR, O_OPT, null, null, null], 43 'items' => [T_ZBX_STR, O_OPT, null, null, null], 44 'widget_view' => [T_ZBX_INT, O_OPT, null, IN('0,1'), null] 45]; 46if (!check_fields($fields)) { 47 exit(); 48} 49validateTimeSelectorPeriod(getRequest('from'), getRequest('to')); 50 51$items = hasRequest('i') 52 ? array_map('expandShortGraphItem', getRequest('i', [])) 53 : getRequest('items', []); 54 55if (!$items) { 56 show_error_message(_('No items defined.')); 57 exit(); 58} 59 60CArrayHelper::sort($items, ['sortorder']); 61 62/* 63 * Permissions 64 */ 65$dbItems = API::Item()->get([ 66 'itemids' => zbx_objectValues($items, 'itemid'), 67 'filter' => [ 68 'flags' => [ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_PROTOTYPE, ZBX_FLAG_DISCOVERY_CREATED] 69 ], 70 'output' => ['itemid'], 71 'webitems' => true, 72 'preservekeys' => true 73]); 74 75foreach ($items as $item) { 76 if (!isset($dbItems[$item['itemid']])) { 77 access_deny(); 78 } 79} 80 81/* 82 * Validation 83 */ 84$types = []; 85foreach ($items as $item) { 86 if ($item['type'] == GRAPH_ITEM_SUM) { 87 if (!in_array($item['type'], $types)) { 88 array_push($types, $item['type']); 89 } 90 else { 91 show_error_message(_('Cannot display more than one item with type "Graph sum".')); 92 break; 93 } 94 } 95} 96 97/* 98 * Display 99 */ 100$timeline = getTimeSelectorPeriod([ 101 'profileIdx' => getRequest('profileIdx'), 102 'profileIdx2' => getRequest('profileIdx2'), 103 'from' => getRequest('from'), 104 'to' => getRequest('to') 105]); 106 107$graph = new CPieGraphDraw(getRequest('graphtype', GRAPH_TYPE_NORMAL)); 108$graph->setHeader(getRequest('name', '')); 109$graph->setPeriod($timeline['to_ts'] - $timeline['from_ts']); 110$graph->setSTime($timeline['from_ts']); 111 112if (!empty($_REQUEST['graph3d'])) { 113 $graph->switchPie3D(); 114} 115 116if (getRequest('widget_view') === '1') { 117 $graph->draw_header = false; 118 $graph->with_vertical_padding = false; 119} 120 121$graph->showLegend(getRequest('legend', 0)); 122$graph->setWidth(getRequest('width', 400)); 123$graph->setHeight(getRequest('height', 300)); 124 125foreach ($items as $item) { 126 $graph->addItem($item['itemid'], $item['calc_fnc'], $item['color'], $item['type']); 127} 128$graph->draw(); 129 130require_once dirname(__FILE__).'/include/page_footer.php'; 131