// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION $fields = array('period' => array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(ZBX_MIN_PERIOD, ZBX_MAX_PERIOD), null), 'from' => array(T_ZBX_INT, O_OPT, P_NZERO, null, null), 'stime' => array(T_ZBX_INT, O_OPT, P_NZERO, null, null), 'border' => array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), 'name' => array(T_ZBX_STR, O_OPT, NULL, null, null), 'width' => array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0, 65535), null), 'height' => array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0, 65535), null), 'graphtype' => array(T_ZBX_INT, O_OPT, NULL, IN('2,3'), null), 'graph3d' => array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), 'legend' => array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), 'items' => array(T_ZBX_STR, O_OPT, NULL, null, null)); check_fields($fields); $items = get_request('items', array()); asort_by_key($items, 'sortorder'); $options = array('webitems' => 1, 'itemids' => zbx_objectValues($items, 'itemid'), 'nodeids' => get_current_nodeid(true)); $db_data = CItem::get($options); $db_data = zbx_toHash($db_data, 'itemid'); foreach ($items as $id => $gitem) { if (!isset($db_data[$gitem['itemid']])) { access_deny(); } } $effectiveperiod = navigation_bar_calc(); $graph = new CPie(get_request('graphtype', GRAPH_TYPE_NORMAL)); $graph->setHeader(get_request('name', '')); $graph3d = get_request('graph3d', 0); $legend = get_request('legend', 0); if ($graph3d == 1) { $graph->switchPie3D(); } $graph->showLegend($legend); unset($host); if (isset($_REQUEST['period'])) { $graph->SetPeriod($_REQUEST['period']); } if (isset($_REQUEST['from'])) { $graph->SetFrom($_REQUEST['from']); } if (isset($_REQUEST['stime'])) { $graph->SetSTime($_REQUEST['stime']);
if (!($host = DBfetch(DBselect('SELECT h.* FROM hosts h,items i WHERE h.hostid=i.hostid AND i.itemid=' . $gitem['itemid'])))) { fatal_error(S_NO_ITEM_DEFINED); } if (!isset($available_hosts[$host['hostid']])) { access_deny(); } } $effectiveperiod = navigation_bar_calc(); if (count($items) == 1) { $_REQUEST['period'] = get_request('period', get_profile('web.item.graph.period', ZBX_PERIOD_DEFAULT, null, $items['itemid'])); if ($_REQUEST['period'] >= ZBX_MIN_PERIOD) { update_profile('web.item.graph.period', $_REQUEST['period'], PROFILE_TYPE_INT, $items['itemid']); } } $graph = new CPie(get_request('graphtype', GRAPH_TYPE_NORMAL)); $graph->setHeader($host['host'] . ':' . get_request('name', '')); $graph3d = get_request('graph3d', 0); $legend = get_request('legend', 0); if ($graph3d == 1) { $graph->switchPie3D(); } $graph->switchLegend($legend); unset($host); if (isset($_REQUEST['period'])) { $graph->SetPeriod($_REQUEST['period']); } if (isset($_REQUEST['from'])) { $graph->SetFrom($_REQUEST['from']); } if (isset($_REQUEST['stime'])) { $graph->SetSTime($_REQUEST['stime']);
/* * Display */ $timeline = CScreenBase::calculateTime(array('profileIdx' => get_request('profileIdx', 'web.screens'), 'profileIdx2' => get_request('profileIdx2'), 'updateProfile' => get_request('updateProfile', true), 'period' => get_request('period'), 'stime' => get_request('stime'))); $graph = new CPie($db_data['graphtype']); $graph->setPeriod($timeline['period']); $graph->setSTime($timeline['stime']); if (isset($_REQUEST['border'])) { $graph->setBorder(0); } $width = get_request('width', 0); if ($width <= 0) { $width = $db_data['width']; } $height = get_request('height', 0); if ($height <= 0) { $height = $db_data['height']; } $graph->setWidth($width); $graph->setHeight($height); $graph->setHeader($host['host'] . ': ' . $db_data['name']); if ($db_data['show_3d']) { $graph->switchPie3D(); } $graph->showLegend($db_data['show_legend']); $result = DBselect('SELECT gi.*' . ' FROM graphs_items gi' . ' WHERE gi.graphid=' . $db_data['graphid'] . ' ORDER BY gi.sortorder,gi.itemid DESC'); while ($db_data = DBfetch($result)) { $graph->addItem($db_data['itemid'], $db_data['calc_fnc'], $db_data['color'], $db_data['type']); } $graph->draw(); require_once dirname(__FILE__) . '/include/page_footer.php';