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'] = 'chart6.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 'graphid' => [T_ZBX_INT, O_MAND, P_SYS, DB_ID, null], 33 'period' => [T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(ZBX_MIN_PERIOD, ZBX_MAX_PERIOD), null], 34 'stime' => [T_ZBX_STR, O_OPT, P_SYS, null, null], 35 'profileIdx' => [T_ZBX_STR, O_OPT, null, null, null], 36 'profileIdx2' => [T_ZBX_STR, O_OPT, null, null, null], 37 'updateProfile' => [T_ZBX_STR, O_OPT, null, null, null], 38 'width' => [T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(20, 65535), null], 39 'height' => [T_ZBX_INT, O_OPT, P_NZERO, '{} > 0', null], 40 'graph3d' => [T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null], 41 'legend' => [T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null] 42]; 43if (!check_fields($fields)) { 44 exit(); 45} 46 47/* 48 * Permissions 49 */ 50$dbGraph = API::Graph()->get([ 51 'output' => API_OUTPUT_EXTEND, 52 'selectGraphItems' => ['itemid', 'sortorder', 'color', 'calc_fnc', 'type'], 53 'selectHosts' => ['name'], 54 'graphids' => $_REQUEST['graphid'] 55]); 56 57if (!$dbGraph) { 58 access_deny(); 59} 60else { 61 $dbGraph = reset($dbGraph); 62} 63 64/* 65 * Display 66 */ 67$timeline = CScreenBase::calculateTime([ 68 'profileIdx' => getRequest('profileIdx', 'web.screens'), 69 'profileIdx2' => getRequest('profileIdx2'), 70 'updateProfile' => getRequest('updateProfile', true), 71 'period' => getRequest('period'), 72 'stime' => getRequest('stime') 73]); 74 75$graph = new CPieGraphDraw($dbGraph['graphtype']); 76$graph->setPeriod($timeline['period']); 77$graph->setSTime($timeline['stime']); 78 79$width = getRequest('width', 0); 80if ($width <= 0) { 81 $width = $dbGraph['width']; 82} 83 84$height = getRequest('height', 0); 85if ($height <= 0) { 86 $height = $dbGraph['height']; 87} 88 89$graph->setWidth($width); 90$graph->setHeight($height); 91 92// array sorting 93CArrayHelper::sort($dbGraph['gitems'], [ 94 ['field' => 'sortorder', 'order' => ZBX_SORT_UP] 95]); 96 97// get graph items 98foreach ($dbGraph['gitems'] as $gItem) { 99 $graph->addItem( 100 $gItem['itemid'], 101 $gItem['calc_fnc'], 102 $gItem['color'], 103 $gItem['type'] 104 ); 105} 106 107$hostName = ''; 108 109foreach ($dbGraph['hosts'] as $gItemHost) { 110 if ($hostName === '') { 111 $hostName = $gItemHost['name']; 112 } 113 elseif ($hostName !== $gItemHost['name']) { 114 $hostName = ''; 115 break; 116 } 117} 118 119$graph->setHeader(($hostName === '') ? $dbGraph['name'] : $hostName.NAME_DELIMITER.$dbGraph['name']); 120 121if ($dbGraph['show_3d']) { 122 $graph->switchPie3D(); 123} 124$graph->showLegend($dbGraph['show_legend']); 125$graph->draw(); 126 127require_once dirname(__FILE__).'/include/page_footer.php'; 128