public function draw() { $start_time = microtime(true); set_image_header(); $this->selectData(); $this->shiftY = 30; $this->shiftYLegend = 20; $this->shiftXleft = 10; $this->shiftXright = 0; $this->fullSizeX = $this->sizeX; $this->fullSizeY = $this->sizeY; if ($this->sizeX < 300 || $this->sizeY < 200) { $this->showLegend(0); } if ($this->drawLegend == 1) { $this->sizeX -= $this->shiftXleft + $this->shiftXright + $this->shiftlegendright; $this->sizeY -= $this->shiftY + $this->shiftYLegend + 12 * $this->num + 8; } else { $this->sizeX -= $this->shiftXleft * 2; $this->sizeY -= $this->shiftY * 2; } $this->sizeX = min($this->sizeX, $this->sizeY); $this->sizeY = min($this->sizeX, $this->sizeY); $this->calc3dheight($this->sizeY); $this->exploderad = (int) $this->sizeX / 100; $this->exploderad3d = (int) $this->sizeX / 60; if (function_exists('ImageColorExactAlpha') && function_exists('ImageCreateTrueColor') && @imagecreatetruecolor(1, 1)) { $this->im = imagecreatetruecolor($this->fullSizeX, $this->fullSizeY); } else { $this->im = imagecreate($this->fullSizeX, $this->fullSizeY); } $this->initColors(); $this->drawRectangle(); $this->drawHeader(); // for each metric for ($item = 0; $item < $this->num; $item++) { $data =& $this->data[$this->items[$item]['itemid']][$this->items[$item]['calc_type']]; if (!isset($data)) { continue; } $calc_fnc = $this->items[$item]['calc_fnc']; switch ($calc_fnc) { case CALC_FNC_MAX: $values[$item] = abs($data->max); break; case CALC_FNC_MIN: $values[$item] = abs($data->min); break; case CALC_FNC_AVG: $values[$item] = abs($data->avg); break; case CALC_FNC_LST: $values[$item] = abs($data->lst); break; } } switch ($this->type) { case GRAPH_TYPE_EXPLODED: $this->drawElementPie($values); break; case GRAPH_TYPE_3D: $this->drawElementPie3D($values); break; case GRAPH_TYPE_3D_EXPLODED: $this->drawElementPie3D($values); break; default: $this->drawElementPie($values); break; } $this->drawLogo(); if ($this->drawLegend == 1) { $this->drawLegend(); } $str = sprintf('%0.2f', microtime(true) - $start_time); $str = _s('Data from %1$s. Generated in %2$s sec.', $this->dataFrom, $str); $strSize = imageTextSize(6, 0, $str); imageText($this->im, 6, 0, $this->fullSizeX - $strSize['width'] - 5, $this->fullSizeY - 5, $this->getColor('Gray'), $str); unset($this->items, $this->data); imageOut($this->im); }
$mapInfo = getSelementsInfo($map, array('severity_min' => get_request('severity_min'))); processAreasCoordinates($map, $areas, $mapInfo); $allLinks = false; } /* * Draw map */ drawMapConnectors($im, $map, $mapInfo, $allLinks); if (!isset($_REQUEST['noselements'])) { drawMapHighligts($im, $map, $mapInfo); drawMapSelements($im, $map, $mapInfo); } $expandMacros = get_request('expand_macros', true); drawMapLabels($im, $map, $mapInfo, $expandMacros); drawMapLinkLabels($im, $map, $mapInfo, $expandMacros); if (!isset($_REQUEST['noselements']) && $map['markelements'] == 1) { drawMapSelementsMarks($im, $map, $mapInfo); } show_messages(); if (get_request('base64image')) { ob_start(); imagepng($im); $imageSource = ob_get_contents(); ob_end_clean(); $json = new CJSON(); echo $json->encode(array('result' => base64_encode($imageSource))); imagedestroy($im); } else { imageOut($im); } require_once dirname(__FILE__) . '/include/page_footer.php';
function show_messages($bool = true, $okmsg = null, $errmsg = null) { global $page, $ZBX_MESSAGES; if (!defined('PAGE_HEADER_LOADED')) { return null; } if (defined('ZBX_API_REQUEST')) { return null; } if (!isset($page['type'])) { $page['type'] = PAGE_TYPE_HTML; } $message = array(); $width = 0; $height = 0; if (!$bool && !is_null($errmsg)) { $msg = _('ERROR') . ': ' . $errmsg; } elseif ($bool && !is_null($okmsg)) { $msg = $okmsg; } if (isset($msg)) { switch ($page['type']) { case PAGE_TYPE_IMAGE: array_push($message, array('text' => $msg, 'color' => !$bool ? array('R' => 255, 'G' => 0, 'B' => 0) : array('R' => 34, 'G' => 51, 'B' => 68), 'font' => 2)); $width = max($width, imagefontwidth(2) * zbx_strlen($msg) + 1); $height += imagefontheight(2) + 1; break; case PAGE_TYPE_XML: echo htmlspecialchars($msg) . "\n"; break; case PAGE_TYPE_HTML: default: $msg_tab = new CTable($msg, $bool ? 'msgok' : 'msgerr'); $msg_tab->setCellPadding(0); $msg_tab->setCellSpacing(0); $row = array(); $msg_col = new CCol(bold($msg), 'msg_main msg'); $msg_col->setAttribute('id', 'page_msg'); $row[] = $msg_col; if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) { $msg_details = new CDiv(_('Details'), 'blacklink'); $msg_details->setAttribute('onclick', 'javascript: showHide("msg_messages", IE ? "block" : "table");'); $msg_details->setAttribute('title', _('Maximize') . '/' . _('Minimize')); array_unshift($row, new CCol($msg_details, 'clr')); } $msg_tab->addRow($row); $msg_tab->show(); break; } } if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) { if ($page['type'] == PAGE_TYPE_IMAGE) { $msg_font = 2; foreach ($ZBX_MESSAGES as $msg) { if ($msg['type'] == 'error') { array_push($message, array('text' => $msg['message'], 'color' => array('R' => 255, 'G' => 55, 'B' => 55), 'font' => $msg_font)); } else { array_push($message, array('text' => $msg['message'], 'color' => array('R' => 155, 'G' => 155, 'B' => 55), 'font' => $msg_font)); } $width = max($width, imagefontwidth($msg_font) * zbx_strlen($msg['message']) + 1); $height += imagefontheight($msg_font) + 1; } } elseif ($page['type'] == PAGE_TYPE_XML) { foreach ($ZBX_MESSAGES as $msg) { echo '[' . $msg['type'] . '] ' . $msg['message'] . "\n"; } } else { $lst_error = new CList(null, 'messages'); foreach ($ZBX_MESSAGES as $msg) { $lst_error->addItem($msg['message'], $msg['type']); $bool = $bool && 'error' != zbx_strtolower($msg['type']); } $msg_show = 6; $msg_count = count($ZBX_MESSAGES); if ($msg_count > $msg_show) { $msg_count = $msg_show * 16; $lst_error->setAttribute('style', 'height: ' . $msg_count . 'px;'); } $tab = new CTable(null, $bool ? 'msgok' : 'msgerr'); $tab->setCellPadding(0); $tab->setCellSpacing(0); $tab->setAttribute('id', 'msg_messages'); $tab->setAttribute('style', 'width: 100%;'); if (isset($msg_tab) && $bool) { $tab->setAttribute('style', 'display: none;'); } $tab->addRow(new CCol($lst_error, 'msg')); $tab->show(); } $ZBX_MESSAGES = null; } if ($page['type'] == PAGE_TYPE_IMAGE && count($message) > 0) { $width += 2; $height += 2; $canvas = imagecreate($width, $height); imagefilledrectangle($canvas, 0, 0, $width, $height, imagecolorallocate($canvas, 255, 255, 255)); foreach ($message as $id => $msg) { $message[$id]['y'] = 1 + (isset($previd) ? $message[$previd]['y'] + $message[$previd]['h'] : 0); $message[$id]['h'] = imagefontheight($msg['font']); imagestring($canvas, $msg['font'], 1, $message[$id]['y'], $msg['text'], imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B'])); $previd = $id; } imageOut($canvas); imagedestroy($canvas); } }
if ($resize) { $ico = imageThumb($ico, $width, $height); } $w = imagesx($ico); $h = imagesy($ico); $css .= 'div.sysmap_iconid_' . $image['imageid'] . '{' . ' height: ' . $h . 'px;' . ' width: ' . $w . 'px;' . ' background: url("imgstore.php?iconid=' . $image['imageid'] . '&width=' . $w . '&height=' . $h . '") no-repeat center center;}' . "\n"; } echo $css; } elseif (isset($_REQUEST['iconid'])) { $iconid = get_request('iconid', 0); if ($iconid > 0) { $image = get_image_by_imageid($iconid); $image = $image['image']; $source = imageFromString($image); } else { $source = get_default_image(); } if ($resize) { $source = imageThumb($source, $width, $height); } imageOut($source); } elseif (isset($_REQUEST['imageid'])) { $imageid = get_request('imageid', 0); session_start(); if (isset($_SESSION['image_id'][$imageid])) { echo $_SESSION['image_id'][$imageid]; unset($_SESSION['image_id'][$imageid]); } session_write_close(); } require_once dirname(__FILE__) . '/include/page_footer.php';
public function draw() { $start_time = microtime(true); set_image_header(); $this->selectData(); $this->m_minY[GRAPH_YAXIS_SIDE_LEFT] = $this->calculateMinY(GRAPH_YAXIS_SIDE_LEFT); $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] = $this->calculateMinY(GRAPH_YAXIS_SIDE_RIGHT); $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT] = $this->calculateMaxY(GRAPH_YAXIS_SIDE_LEFT); $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT] = $this->calculateMaxY(GRAPH_YAXIS_SIDE_RIGHT); if ($this->m_minY[GRAPH_YAXIS_SIDE_LEFT] == $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT]) { if ($this->graphOrientation[GRAPH_YAXIS_SIDE_LEFT] == '-') { $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT] = 0; } elseif ($this->m_minY[GRAPH_YAXIS_SIDE_LEFT] == 0) { $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT] = 1; } else { $this->m_minY[GRAPH_YAXIS_SIDE_LEFT] = 0; } } elseif ($this->m_minY[GRAPH_YAXIS_SIDE_LEFT] > $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT]) { if ($this->graphOrientation[GRAPH_YAXIS_SIDE_LEFT] == '-') { $this->m_minY[GRAPH_YAXIS_SIDE_LEFT] = 0.2 * $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT]; } else { $this->m_minY[GRAPH_YAXIS_SIDE_LEFT] = 0; } } if ($this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] == $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT]) { if ($this->graphOrientation[GRAPH_YAXIS_SIDE_RIGHT] == '-') { $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT] = 0; } elseif ($this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] == 0) { $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT] = 1; } else { $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] = 0; } } elseif ($this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] > $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT]) { if ($this->graphOrientation[GRAPH_YAXIS_SIDE_RIGHT] == '-') { $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] = 0.2 * $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT]; } else { $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] = 0; } } $this->calcMinMaxInterval(); $this->updateShifts(); $this->calcTriggers(); $this->calcZero(); $this->calcPercentile(); $this->fullSizeX = $this->sizeX + $this->shiftXleft + $this->shiftXright + 1; $this->fullSizeY = $this->sizeY + $this->shiftY + $this->legendOffsetY - 40; //减去日期所占用的距离35 if ($this->drawLegend) { $this->fullSizeY += 14 * ($this->num + 1 + ($this->sizeY < 120 ? 0 : count($this->triggers))) + 8; } // if graph height is big enough, we reserve space for percent line legend if ($this->sizeY >= ZBX_GRAPH_LEGEND_HEIGHT) { foreach ($this->percentile as $percentile) { if ($percentile['percent'] > 0 && $percentile['value']) { $this->fullSizeY += 14; } } } if (function_exists('imagecolorexactalpha') && function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1, 1)) { $this->im = imagecreatetruecolor($this->fullSizeX, $this->fullSizeY); } else { $this->im = imagecreate($this->fullSizeX, $this->fullSizeY); } $this->initColors(); $this->drawRectangle(); $this->drawHeader(); $this->drawWorkPeriod(); $this->drawTimeGrid(); $this->drawVerticalGrid(); $this->drawXYAxisScale($this->graphtheme['gridbordercolor']); $maxX = $this->sizeX; // for each metric for ($item = 0; $item < $this->num; $item++) { $minY = $this->m_minY[$this->items[$item]['axisside']]; $maxY = $this->m_maxY[$this->items[$item]['axisside']]; $data =& $this->data[$this->items[$item]['itemid']][$this->items[$item]['calc_type']]; if (!isset($data)) { continue; } if ($this->type == GRAPH_TYPE_STACKED) { $drawtype = $this->items[$item]['drawtype']; $max_color = $this->getColor('ValueMax', GRAPH_STACKED_ALFA); $avg_color = $this->getColor($this->items[$item]['color'], GRAPH_STACKED_ALFA); $min_color = $this->getColor('ValueMin', GRAPH_STACKED_ALFA); $minmax_color = $this->getColor('ValueMinMax', GRAPH_STACKED_ALFA); $calc_fnc = $this->items[$item]['calc_fnc']; } else { $drawtype = $this->items[$item]['drawtype']; $max_color = $this->getColor('ValueMax', GRAPH_STACKED_ALFA); $avg_color = $this->getColor($this->items[$item]['color'], GRAPH_STACKED_ALFA); $min_color = $this->getColor('ValueMin', GRAPH_STACKED_ALFA); $minmax_color = $this->getColor('ValueMinMax', GRAPH_STACKED_ALFA); $calc_fnc = $this->items[$item]['calc_fnc']; } // for each X $draw = true; $prevDraw = true; for ($i = 1, $j = 0; $i < $maxX; $i++) { // new point if ($data['count'][$i] == 0 && $i != $maxX - 1) { continue; } $diff = abs($data['clock'][$i] - $data['clock'][$j]); $cell = ($this->to_time - $this->from_time) / $this->sizeX; $delay = $this->items[$item]['delay']; if ($cell > $delay) { $draw = (bool) ($diff < ZBX_GRAPH_MAX_SKIP_CELL * $cell); } else { $draw = (bool) ($diff < ZBX_GRAPH_MAX_SKIP_DELAY * $delay); } if ($this->items[$item]['type'] == ITEM_TYPE_TRAPPER) { $draw = true; } if (!$draw && !$prevDraw) { $draw = true; $valueDrawType = GRAPH_ITEM_DRAWTYPE_BOLD_DOT; } else { $valueDrawType = $drawtype; $prevDraw = $draw; } if ($draw) { $this->drawElement($data, $i, $j, 0, $this->sizeX, $minY, $maxY, $valueDrawType, $max_color, $avg_color, $min_color, $minmax_color, $calc_fnc, $this->items[$item]['axisside']); } $j = $i; } } $this->drawLeftSide(); $this->drawRightSide(); if ($this->drawLegend) { //画出时间 //$this->drawDate(); $this->drawTriggers(); $this->drawPercentile(); $this->drawLegend(); } /* $this->drawLogo(); $str = sprintf('%0.2f', microtime(true) - $start_time); $str = _s('Data from %1$s. Generated in %2$s sec.', $this->dataFrom, $str); $strSize = imageTextSize(6, 0, $str); imageText($this->im, 6, 0, $this->fullSizeX - $strSize['width'] - 5, $this->fullSizeY - 5, $this->getColor('Gray'), $str); */ $this->newData = $this->data; unset($this->items, $this->data); imageOut($this->im); }
public function draw() { $start_time = microtime(true); set_image_header(); $this->column = uint_in_array($this->type, array(GRAPH_TYPE_COLUMN, GRAPH_TYPE_COLUMN_STACKED)); $this->fullSizeX = $this->sizeX; $this->fullSizeY = $this->sizeY; if ($this->sizeX < 300 || $this->sizeY < 200) { $this->showLegend(0); } $this->calcShifts(); $this->sizeX -= $this->shiftXleft + $this->shiftXright + $this->shiftlegendright + $this->shiftXCaptionLeft + $this->shiftXCaptionRight; $this->sizeY -= $this->shiftY + $this->shiftYLegend + $this->shiftYCaptionBottom + $this->shiftYCaptionTop; $this->calcSeriesWidth(); $this->calcMiniMax(); $this->correctMiniMax(); if (function_exists('imagecolorexactalpha') && function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1, 1)) { $this->im = imagecreatetruecolor($this->fullSizeX, $this->fullSizeY); } else { $this->im = imagecreate($this->fullSizeX, $this->fullSizeY); } $this->initColors(); $this->drawRectangle(); $this->drawHeader(); $this->drawGrid(); $this->drawSideValues(); $this->drawLogo(); $this->drawLegend(); $count = 0; if ($this->column) { $start = $this->shiftXleft + $this->shiftXCaptionLeft + floor($this->seriesDistance / 2); } else { $start = $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - floor($this->seriesDistance / 2); } foreach ($this->series as $key => $series) { foreach ($series as $num => $serie) { $axis = $serie['axis']; $value = $serie['value']; $color = $this->getColor($this->seriesColor[$num], $this->opacity); if ($this->column) { imagefilledrectangle($this->im, $start, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - round($this->sizeY / $this->maxValue[$axis] * $value), $start + $this->columnWidth, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop, $color); imagerectangle($this->im, $start, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - round($this->sizeY / $this->maxValue[$axis] * $value), $start + $this->columnWidth, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop, $this->getColor('Black No Alpha')); } else { imagefilledrectangle($this->im, $this->shiftXleft + $this->shiftXCaptionLeft, $start - $this->columnWidth, $this->shiftXleft + $this->shiftXCaptionLeft + round($this->sizeX / $this->maxValue[$axis] * $value), $start, $color); imagerectangle($this->im, $this->shiftXleft + $this->shiftXCaptionLeft, $start - $this->columnWidth, $this->shiftXleft + $this->shiftXCaptionLeft + round($this->sizeX / $this->maxValue[$axis] * $value), $start, $this->getColor('Black No Alpha')); } $start = $this->column ? $start + $this->columnWidth : $start - $this->columnWidth; } $count++; if ($this->column) { $start = $count * ($this->seriesWidth + $this->seriesDistance) + $this->shiftXleft + $this->shiftXCaptionLeft + floor($this->seriesDistance / 2); } else { $start = $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - $count * ($this->seriesWidth + $this->seriesDistance) - floor($this->seriesDistance / 2); } } $str = sprintf('%0.2f', microtime(true) - $start_time); $str = _s('Generated in %s sec', $str); $strSize = imageTextSize(6, 0, $str); imageText($this->im, 6, 0, $this->fullSizeX - $strSize['width'] - 5, $this->fullSizeY - 5, $this->getColor('Gray'), $str); unset($this->items, $this->data); imageOut($this->im); }
function show_messages($bool = TRUE, $okmsg = NULL, $errmsg = NULL) { global $page, $ZBX_MESSAGES; if (!defined('PAGE_HEADER_LOADED')) { return; } if (defined('ZBX_API_REQUEST')) { return; } if (!isset($page['type'])) { $page['type'] = PAGE_TYPE_HTML; } $message = array(); $width = 0; $height = 0; $img_space = null; if (!$bool && !is_null($errmsg)) { $msg = S_CONFIG_ERROR_HEAD . ': ' . $errmsg; } else { if ($bool && !is_null($okmsg)) { $msg = $okmsg; } } $api_errors = CZBXAPI::resetErrors(); if (!empty($api_errors)) { error($api_errors); } if (isset($msg)) { switch ($page['type']) { case PAGE_TYPE_IMAGE: array_push($message, array('text' => $msg, 'color' => !$bool ? array('R' => 255, 'G' => 0, 'B' => 0) : array('R' => 34, 'G' => 51, 'B' => 68), 'font' => 2)); $width = max($width, ImageFontWidth(2) * zbx_strlen($msg) + 1); $height += imagefontheight(2) + 1; break; case PAGE_TYPE_XML: echo htmlspecialchars($msg) . "\n"; break; // case PAGE_TYPE_JS: break; // case PAGE_TYPE_JS: break; case PAGE_TYPE_HTML: default: $msg_tab = new CTable($msg, $bool ? 'msgok' : 'msgerr'); $msg_tab->setCellPadding(0); $msg_tab->setCellSpacing(0); $row = array(); $msg_col = new CCol(bold($msg), 'msg_main msg'); $msg_col->setAttribute('id', 'page_msg'); $row[] = $msg_col; if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) { $msg_details = new CDiv(S_DETAILS, 'blacklink'); $msg_details->setAttribute('onclick', "javascript: ShowHide('msg_messages', IE?'block':'table');"); $msg_details->setAttribute('title', S_MAXIMIZE . '/' . S_MINIMIZE); array_unshift($row, new CCol($msg_details, 'clr')); } $msg_tab->addRow($row); $msg_tab->show(); $img_space = new CImg('images/general/tree/zero.gif', 'space', '100', '2'); break; } } if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) { if ($page['type'] == PAGE_TYPE_IMAGE) { $msg_font = 2; foreach ($ZBX_MESSAGES as $msg) { if ($msg['type'] == 'error') { array_push($message, array('text' => $msg['message'], 'color' => array('R' => 255, 'G' => 55, 'B' => 55), 'font' => $msg_font)); } else { array_push($message, array('text' => $msg['message'], 'color' => array('R' => 155, 'G' => 155, 'B' => 55), 'font' => $msg_font)); } $width = max($width, imagefontwidth($msg_font) * zbx_strlen($msg['message']) + 1); $height += imagefontheight($msg_font) + 1; } } else { if ($page['type'] == PAGE_TYPE_XML) { foreach ($ZBX_MESSAGES as $msg) { echo '[' . $msg['type'] . '] ' . $msg['message'] . "\n"; } } else { $lst_error = new CList(null, 'messages'); foreach ($ZBX_MESSAGES as $msg) { $lst_error->addItem($msg['message'], $msg['type']); $bool = $bool && 'error' != zbx_strtolower($msg['type']); } //message scroll if needed $msg_show = 6; $msg_count = count($ZBX_MESSAGES); if ($msg_count > $msg_show) { $msg_count = $msg_show; $msg_count = $msg_count * 16; $lst_error->setAttribute('style', 'height: ' . $msg_count . 'px;'); } $tab = new CTable(null, $bool ? 'msgok' : 'msgerr'); $tab->setCellPadding(0); $tab->setCellSpacing(0); $tab->setAttribute('id', 'msg_messages'); $tab->setAttribute('style', 'width: 100%;'); if (isset($msg_tab) && $bool) { $tab->setAttribute('style', 'display: none;'); } $tab->addRow(new CCol($lst_error, 'msg')); $tab->Show(); //--- } } $ZBX_MESSAGES = null; } if (!is_null($img_space)) { print unpack_object($img_space); } if ($page['type'] == PAGE_TYPE_IMAGE && count($message) > 0) { $width += 2; $height += 2; $canvas = imagecreate($width, $height); imagefilledrectangle($canvas, 0, 0, $width, $height, imagecolorallocate($canvas, 255, 255, 255)); foreach ($message as $id => $msg) { $message[$id]['y'] = 1 + (isset($previd) ? $message[$previd]['y'] + $message[$previd]['h'] : 0); $message[$id]['h'] = imagefontheight($msg['font']); imagestring($canvas, $msg['font'], 1, $message[$id]['y'], $msg['text'], imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B'])); $previd = $id; } imageOut($canvas); imagedestroy($canvas); } }
public function draw() { $start_time = microtime(true); set_image_header(); $this->selectData(); if (isset($this->axis_valuetype[GRAPH_YAXIS_SIDE_RIGHT])) { $sides[] = GRAPH_YAXIS_SIDE_RIGHT; } if (isset($this->axis_valuetype[GRAPH_YAXIS_SIDE_LEFT]) || !isset($sides)) { $sides[] = GRAPH_YAXIS_SIDE_LEFT; } foreach ($sides as $graphSide) { $this->m_minY[$graphSide] = $this->calculateMinY($graphSide); $this->m_maxY[$graphSide] = $this->calculateMaxY($graphSide); if ($this->m_minY[$graphSide] === null) { $this->m_minY[$graphSide] = 0; } if ($this->m_maxY[$graphSide] === null) { $this->m_maxY[$graphSide] = 1; } if ($this->m_minY[$graphSide] == $this->m_maxY[$graphSide]) { if ($this->graphOrientation[$graphSide] == '-') { $this->m_maxY[$graphSide] = 0; } elseif ($this->m_minY[$graphSide] == 0) { $this->m_maxY[$graphSide] = 1; } else { $this->m_minY[$graphSide] = 0; } } elseif ($this->m_minY[$graphSide] > $this->m_maxY[$graphSide]) { if ($this->graphOrientation[$graphSide] == '-') { $this->m_minY[$graphSide] = bcmul($this->m_maxY[$graphSide], 0.2); } else { $this->m_minY[$graphSide] = 0; } } // If max Y-scale bigger min Y-scale only for 10% or less, then we don't allow Y-scale duplicate if ($this->m_maxY[$graphSide] && $this->m_minY[$graphSide]) { if ($this->m_minY[$graphSide] < 0) { $absMinY = bcmul($this->m_minY[$graphSide], '-1'); } else { $absMinY = $this->m_minY[$graphSide]; } if ($this->m_maxY[$graphSide] < 0) { $absMaxY = bcmul($this->m_maxY[$graphSide], '-1'); } else { $absMaxY = $this->m_maxY[$graphSide]; } if ($absMaxY < $absMinY) { $oldAbMaxY = $absMaxY; $absMaxY = $absMinY; $absMinY = $oldAbMaxY; } if (bcdiv(bcsub($absMaxY, $absMinY), $absMaxY) <= 0.1) { if ($this->m_minY[$graphSide] > 0) { $this->m_minY[$graphSide] = bcmul($this->m_minY[$graphSide], 0.95); } else { $this->m_minY[$graphSide] = bcmul($this->m_minY[$graphSide], 1.05); } if ($this->m_maxY[$graphSide] > 0) { $this->m_maxY[$graphSide] = bcmul($this->m_maxY[$graphSide], 1.05); } else { $this->m_maxY[$graphSide] = bcmul($this->m_maxY[$graphSide], 0.95); } } } } $this->calcMinMaxInterval(); $this->updateShifts(); $this->calcTriggers(); $this->calcZero(); $this->calcPercentile(); $this->fullSizeX = $this->sizeX + $this->shiftXleft + $this->shiftXright + 1; $this->fullSizeY = $this->sizeY + $this->shiftY + $this->legendOffsetY; if ($this->drawLegend) { $this->fullSizeY += 14 * ($this->num + 1 + ($this->sizeY < 120 ? 0 : count($this->triggers))) + 8; } // if graph height is big enough, we reserve space for percent line legend if ($this->sizeY >= ZBX_GRAPH_LEGEND_HEIGHT) { foreach ($this->percentile as $percentile) { if ($percentile['percent'] > 0 && $percentile['value']) { $this->fullSizeY += 14; } } } if (function_exists('imagecolorexactalpha') && function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1, 1)) { $this->im = imagecreatetruecolor($this->fullSizeX, $this->fullSizeY); } else { $this->im = imagecreate($this->fullSizeX, $this->fullSizeY); } $this->initColors(); $this->drawRectangle(); $this->drawHeader(); $this->drawWorkPeriod(); $this->drawTimeGrid(); $this->drawHorizontalGrid(); $this->drawXYAxisScale(); $maxX = $this->sizeX; // for each metric for ($item = 0; $item < $this->num; $item++) { $minY = $this->m_minY[$this->items[$item]['axisside']]; $maxY = $this->m_maxY[$this->items[$item]['axisside']]; $data =& $this->data[$this->items[$item]['itemid']][$this->items[$item]['calc_type']]; if (!isset($data)) { continue; } if ($this->type == GRAPH_TYPE_STACKED) { $drawtype = $this->items[$item]['drawtype']; $max_color = $this->getColor('ValueMax', GRAPH_STACKED_ALFA); $avg_color = $this->getColor($this->items[$item]['color'], GRAPH_STACKED_ALFA); $min_color = $this->getColor('ValueMin', GRAPH_STACKED_ALFA); $minmax_color = $this->getColor('ValueMinMax', GRAPH_STACKED_ALFA); $calc_fnc = $this->items[$item]['calc_fnc']; } else { $drawtype = $this->items[$item]['drawtype']; $max_color = $this->getColor('ValueMax', GRAPH_STACKED_ALFA); $avg_color = $this->getColor($this->items[$item]['color'], GRAPH_STACKED_ALFA); $min_color = $this->getColor('ValueMin', GRAPH_STACKED_ALFA); $minmax_color = $this->getColor('ValueMinMax', GRAPH_STACKED_ALFA); $calc_fnc = $this->items[$item]['calc_fnc']; } // for each X $prevDraw = true; for ($i = 1, $j = 0; $i < $maxX; $i++) { // new point if ($data['count'][$i] == 0 && $i != $maxX - 1) { continue; } $delay = $this->items[$item]['delay']; $has_scheduling = false; foreach ($this->items[$item]['intervals'] as $interval) { if ($interval['type'] == ITEM_DELAY_FLEX_TYPE_SCHEDULING) { $has_scheduling = true; break; } } if ($this->items[$item]['type'] == ITEM_TYPE_TRAPPER || $has_scheduling && $delay == 0) { $draw = true; } else { $diff = abs($data['clock'][$i] - $data['clock'][$j]); $cell = ($this->to_time - $this->from_time) / $this->sizeX; if ($cell > $delay) { $draw = $diff < ZBX_GRAPH_MAX_SKIP_CELL * $cell; } else { $draw = $diff < ZBX_GRAPH_MAX_SKIP_DELAY * $delay; } } if (!$draw && !$prevDraw) { $draw = true; $valueDrawType = GRAPH_ITEM_DRAWTYPE_BOLD_DOT; } else { $valueDrawType = $drawtype; $prevDraw = $draw; } if ($draw) { $this->drawElement($data, $i, $j, 0, $this->sizeX, $minY, $maxY, $valueDrawType, $max_color, $avg_color, $min_color, $minmax_color, $calc_fnc, $this->items[$item]['axisside']); } $j = $i; } } $this->drawSides(); if ($this->drawLegend) { $this->drawTriggers(); $this->drawPercentile(); $this->drawLegend(); } $this->drawLogo(); $str = sprintf('%0.2f', microtime(true) - $start_time); $str = _s('Data from %1$s. Generated in %2$s sec.', $this->dataFrom, $str); $strSize = imageTextSize(6, 0, $str); imageText($this->im, 6, 0, $this->fullSizeX - $strSize['width'] - 5, $this->fullSizeY - 5, $this->getColor('Gray'), $str); unset($this->items, $this->data); imageOut($this->im); }
function show_messages($bool = true, $okmsg = null, $errmsg = null) { global $page, $ZBX_MESSAGES; if (!defined('PAGE_HEADER_LOADED')) { return null; } if (defined('ZBX_API_REQUEST')) { return null; } if (!isset($page['type'])) { $page['type'] = PAGE_TYPE_HTML; } $imageMessages = array(); if (!$bool && !is_null($errmsg)) { $msg = _('ERROR') . ': ' . $errmsg; } elseif ($bool && !is_null($okmsg)) { $msg = $okmsg; } if (isset($msg)) { switch ($page['type']) { case PAGE_TYPE_IMAGE: // save all of the messages in an array to display them later in an image $imageMessages[] = array('text' => $msg, 'color' => !$bool ? array('R' => 255, 'G' => 0, 'B' => 0) : array('R' => 34, 'G' => 51, 'B' => 68)); break; case PAGE_TYPE_XML: echo htmlspecialchars($msg) . "\n"; break; case PAGE_TYPE_HTML: default: $msg_tab = new CTable($msg, $bool ? 'msgok' : 'msgerr'); $msg_tab->setCellPadding(0); $msg_tab->setCellSpacing(0); $row = array(); $msg_col = new CCol(bold($msg), 'msg_main msg'); $msg_col->setAttribute('id', 'page_msg'); $row[] = $msg_col; if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) { $msg_details = new CDiv(_('Details'), 'blacklink'); $msg_details->setAttribute('onclick', 'javascript: showHide("msg_messages", IE ? "block" : "table");'); $msg_details->setAttribute('title', _('Maximize') . '/' . _('Minimize')); array_unshift($row, new CCol($msg_details, 'clr')); } $msg_tab->addRow($row); $msg_tab->show(); break; } } if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) { if ($page['type'] == PAGE_TYPE_IMAGE) { foreach ($ZBX_MESSAGES as $msg) { // save all of the messages in an array to display them later in an image if ($msg['type'] == 'error') { $imageMessages[] = array('text' => $msg['message'], 'color' => array('R' => 255, 'G' => 55, 'B' => 55)); } else { $imageMessages[] = array('text' => $msg['message'], 'color' => array('R' => 155, 'G' => 155, 'B' => 55)); } } } elseif ($page['type'] == PAGE_TYPE_XML) { foreach ($ZBX_MESSAGES as $msg) { echo '[' . $msg['type'] . '] ' . $msg['message'] . "\n"; } } else { $lst_error = new CList(null, 'messages'); foreach ($ZBX_MESSAGES as $msg) { $lst_error->addItem($msg['message'], $msg['type']); $bool = $bool && 'error' !== strtolower($msg['type']); } $msg_show = 6; $msg_count = count($ZBX_MESSAGES); if ($msg_count > $msg_show) { $msg_count = $msg_show * 16; $lst_error->setAttribute('style', 'height: ' . $msg_count . 'px;'); } $tab = new CTable(null, $bool ? 'msgok' : 'msgerr'); $tab->setCellPadding(0); $tab->setCellSpacing(0); $tab->setAttribute('id', 'msg_messages'); $tab->setAttribute('style', 'width: 100%;'); if (isset($msg_tab) && $bool) { $tab->setAttribute('style', 'display: none;'); } $tab->addRow(new CCol($lst_error, 'msg')); $tab->show(); } $ZBX_MESSAGES = null; } // draw an image with the messages if ($page['type'] == PAGE_TYPE_IMAGE && count($imageMessages) > 0) { $imageFontSize = 8; // calculate the size of the text $imageWidth = 0; $imageHeight = 0; foreach ($imageMessages as &$msg) { $size = imageTextSize($imageFontSize, 0, $msg['text']); $msg['height'] = $size['height'] - $size['baseline']; // calculate the total size of the image $imageWidth = max($imageWidth, $size['width']); $imageHeight += $size['height'] + 1; } unset($msg); // additional padding $imageWidth += 2; $imageHeight += 2; // create the image $canvas = imagecreate($imageWidth, $imageHeight); imagefilledrectangle($canvas, 0, 0, $imageWidth, $imageHeight, imagecolorallocate($canvas, 255, 255, 255)); // draw each message $y = 1; foreach ($imageMessages as $msg) { $y += $msg['height']; imageText($canvas, $imageFontSize, 0, 1, $y, imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B']), $msg['text']); } imageOut($canvas); imagedestroy($canvas); } }
function show_messages($good = false, $okmsg = null, $errmsg = null) { global $page, $ZBX_MESSAGES; if (!defined('PAGE_HEADER_LOADED')) { // return null; } if (defined('ZBX_API_REQUEST')) { return null; } if (!isset($page['type'])) { $page['type'] = PAGE_TYPE_HTML; } $imageMessages = []; $title = $good ? $okmsg : $errmsg; $messages = isset($ZBX_MESSAGES) ? $ZBX_MESSAGES : []; $ZBX_MESSAGES = []; switch ($page['type']) { case PAGE_TYPE_IMAGE: if ($title !== null) { $imageMessages[] = ['text' => $title, 'color' => !$good ? ['R' => 255, 'G' => 0, 'B' => 0] : ['R' => 34, 'G' => 51, 'B' => 68]]; } foreach ($messages as $message) { $imageMessages[] = ['text' => $message['message'], 'color' => $message['type'] == 'error' ? ['R' => 255, 'G' => 55, 'B' => 55] : ['R' => 155, 'G' => 155, 'B' => 55]]; } break; case PAGE_TYPE_XML: if ($title !== null) { echo htmlspecialchars($title) . "\n"; } foreach ($messages as $message) { echo '[' . $message['type'] . '] ' . $message['message'] . "\n"; } break; case PAGE_TYPE_HTML: default: if ($title || $messages) { makeMessageBox($good, $messages, $title, true, !$good)->show(); } break; } // draw an image with the messages if ($imageMessages) { $imageFontSize = 8; // calculate the size of the text $imageWidth = 0; $imageHeight = 0; foreach ($imageMessages as &$msg) { $size = imageTextSize($imageFontSize, 0, $msg['text']); $msg['height'] = $size['height'] - $size['baseline']; // calculate the total size of the image $imageWidth = max($imageWidth, $size['width']); $imageHeight += $size['height'] + 1; } unset($msg); // additional padding $imageWidth += 2; $imageHeight += 2; // create the image $canvas = imagecreate($imageWidth, $imageHeight); imagefilledrectangle($canvas, 0, 0, $imageWidth, $imageHeight, imagecolorallocate($canvas, 255, 255, 255)); // draw each message $y = 1; foreach ($imageMessages as $msg) { $y += $msg['height']; imageText($canvas, $imageFontSize, 0, 1, $y, imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B']), $msg['text']); } imageOut($canvas); imagedestroy($canvas); } }
$color = array('red' => 255, 'green' => 255, 'blue' => 255); $shadow = array('red' => 105, 'green' => 105, 'blue' => 105); break; case 'black': default: $color = array('red' => 0, 'green' => 0, 'blue' => 0); $shadow = array('red' => 175, 'green' => 175, 'blue' => 175); } $size = imageTextSize($font, $angle, $text); $im = imagecreatetruecolor($size['width'] + 4, $size['height'] + 4); $width = imagesx($im); $height = imagesy($im); $white = imagecolorallocate($im, $shadow['red'], $shadow['green'], $shadow['blue']); imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $white); $text_color = imagecolorallocate($im, $color['red'], $color['green'], $color['blue']); imageText($im, $font, 0, 0, $size['height'], $text_color, $text); $newImage = imagecreatetruecolor($height, $width); $white = imagecolorallocate($newImage, $shadow['red'], $shadow['green'], $shadow['blue']); // imagealphablending($newImage, false); // imagesavealpha($newImage, true); for ($w = 0; $w < $width; $w++) { for ($h = 0; $h < $height; $h++) { $ref = imagecolorat($im, $w, $h); imagesetpixel($newImage, $h, $width - 1 - $w, $ref); } } imagecolortransparent($newImage, $white); imageOut($newImage); imagedestroy($newImage); imagedestroy($im); include_once 'include/page_footer.php';