diff options
| author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-12-05 12:15:43 +0000 |
|---|---|---|
| committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-12-05 12:15:43 +0000 |
| commit | 3265938a7cd0ef277bfc550ff47b60ed71b417de (patch) | |
| tree | 308a9561fd97e3a2b449d5a36ad33f9db3552fbd /frontends/php/include | |
| parent | f65cf979409619d9de7174926e51c995f145017a (diff) | |
| download | zabbix-3265938a7cd0ef277bfc550ff47b60ed71b417de.tar.gz zabbix-3265938a7cd0ef277bfc550ff47b60ed71b417de.tar.xz zabbix-3265938a7cd0ef277bfc550ff47b60ed71b417de.zip | |
- improved editing of graphs (Eugene)
- developed 'Color picker' (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3567 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
| -rw-r--r-- | frontends/php/include/classes/ccolor.inc.php | 219 | ||||
| -rw-r--r-- | frontends/php/include/classes/ctag.inc.php | 86 | ||||
| -rw-r--r-- | frontends/php/include/classes/graph.inc.php | 89 | ||||
| -rw-r--r-- | frontends/php/include/config.inc.php | 27 | ||||
| -rw-r--r-- | frontends/php/include/defines.inc.php | 7 | ||||
| -rw-r--r-- | frontends/php/include/forms.inc.php | 269 | ||||
| -rw-r--r-- | frontends/php/include/graphs.inc.php | 104 | ||||
| -rw-r--r-- | frontends/php/include/html.inc.php | 18 | ||||
| -rw-r--r-- | frontends/php/include/locales/en_gb.inc.php | 2 | ||||
| -rw-r--r-- | frontends/php/include/page_header.php | 2 | ||||
| -rw-r--r-- | frontends/php/include/validate.inc.php | 19 |
11 files changed, 653 insertions, 189 deletions
diff --git a/frontends/php/include/classes/ccolor.inc.php b/frontends/php/include/classes/ccolor.inc.php new file mode 100644 index 00000000..49d9d2af --- /dev/null +++ b/frontends/php/include/classes/ccolor.inc.php @@ -0,0 +1,219 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2005 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ + require_once "include/classes/clink.inc.php"; + +?> +<?php + + function insert_show_color_picker_javascript() + { + global $SHOW_COLOR_PICKER_SCRIPT_ISERTTED; + + if($SHOW_COLOR_PICKER_SCRIPT_ISERTTED) return; + $SHOW_COLOR_PICKER_SCRIPT_ISERTTED = true; +?> +<script language="JavaScript" type="text/javascript"> +<!-- + +var color_table = <?php + $table = ''; + + $table .= '<table cellspacing="0" cellpadding="1">'; + $table .= '<tr>'; + /* gray colors */ + foreach(array('0','3','6','8','9','A','C','E','F') as $c) + { + $color = $c.$c.$c.$c.$c.$c; + $table .= '<td>'.unpack_object(new CColorCell(null, $color, 'set_color(\''.$color.'\')')).'</td>'; + } + $table .= '</tr>'; + + /* other colors */ + $colors = array( + array('r' => 0, 'g' => 0, 'b' => 1), + array('r' => 0, 'g' => 1, 'b' => 0), + array('r' => 1, 'g' => 0, 'b' => 0), + array('r' => 0, 'g' => 1, 'b' => 1), + array('r' => 1, 'g' => 0, 'b' => 1), + array('r' => 1, 'g' => 1, 'b' => 0) + ); + + $brigs = array( + array(0 => '0', 1 => '3'), + array(0 => '0', 1 => '6'), + array(0 => '0', 1 => '9'), + array(0 => '0', 1 => 'C'), + array(0 => '0', 1 => 'F'), + array(0 => '3', 1 => 'F'), + array(0 => '6', 1 => 'F'), + array(0 => '9', 1 => 'F'), + array(0 => 'C', 1 => 'F') + ); + + foreach($colors as $c) + { + $table .= '<tr>'; + foreach($brigs as $br) + { + $r = $br[$c['r']]; + $g = $br[$c['g']]; + $b = $br[$c['b']]; + + $color = $r.$r.$g.$g.$b.$b; + + $table .= '<td>'.unpack_object(new CColorCell(null, $color, 'set_color(\''.$color.'\')')).'</td>'; + } + $table .= '</tr>'; + } + $table .= '</table>'; + $cancel = '<a href="javascript:hide_color_picker()">'.S_CANCEL.'</a>'; + echo '\''.addslashes($table).$cancel.'\''; + unset($table); +?> + +function GetPos(obj) +{ + var left = obj.offsetLeft; + var top = obj.offsetTop;; + while (obj = obj.offsetParent) + { + left += obj.offsetLeft + top += obj.offsetTop + } + return [left,top]; +} + +var color_picker = null; +var curr_lbl = null; +var curr_txt = null; + +function hide_color_picker() +{ + if(!color_picker) return; + + color_picker.style.visibility="hidden" + color_picker.style.left = "-" + ((color_picker.style.width) ? color_picker.style.width : 100) + "px"; + + curr_lbl = null; + curr_txt = null; +} + +function show_color_picker(name) +{ + if(!color_picker) return; + + curr_lbl = document.getElementById('lbl_' + name); + curr_txt = document.getElementById(name); + + var pos = GetPos(curr_lbl); + + color_picker.x = pos[0]; + color_picker.y = pos[1]; + + color_picker.style.left = color_picker.x + "px"; + color_picker.style.top = color_picker.y + "px"; + + color_picker.style.visibility = "visible"; +} + +function create_color_picker() +{ + if(color_picker) return; + + color_picker = document.createElement("div"); + color_picker.setAttribute("id", "color_picker"); + color_picker.innerHTML = color_table; + document.body.appendChild(color_picker); + + hide_color_picker(); +} + +function set_color(color) +{ + if(curr_lbl) curr_lbl.style.background = curr_lbl.style.color = '#' + color; + if(curr_txt) curr_txt.value = color; + + hide_color_picker(); +} + +function set_color_by_name(name, color) +{ + curr_lbl = document.getElementById('lbl_' + name); + curr_txt = document.getElementById(name); + + set_color(color); +} + +if (window.addEventListener) +{ + window.addEventListener("load", create_color_picker, false); +} +else if (window.attachEvent) +{ + window.attachEvent("onload", create_color_picker); +} +else if (document.getElementById) +{ + window.onload = create_color_picker; +} + +//--> +</script> +<?php + } + + class CColorCell extends CLink + { + function CColorCell($name, $value, $action=null) + { + parent::CLink(SPACE.SPACE.SPACE, null); + $this->SetName($name); + $this->AddOption('id', $name); + $this->AddOption('title', '#'.$value); + $this->AddOption('style', 'text-decoration: none; outline: 1px solid black; background-color: #'.$value); + $this->SetAction($action); + } + function SetAction($action=null) + { + if(!isset($action)) return false; + + return $this->SetUrl('javascript:'.$action); + } + } + + class CColor extends CObject + { +/* public */ + function CColor($name,$value) + { + parent::CObject(); + + $lbl = new CColorCell('lbl_'.$name, $value, 'show_color_picker(\''.$name.'\')'); + + $txt = new CTextBox($name,$value,7); + $txt->AddOption('id', $name); + $txt->AddOption('onChange', 'set_color_by_name(\''.$name.'\',this.value)'); + $txt->AddOption('style', 'margin: 0px'); + $this->AddItem(array($txt, $lbl)); + + insert_show_color_picker_javascript(); + } + } +?> diff --git a/frontends/php/include/classes/ctag.inc.php b/frontends/php/include/classes/ctag.inc.php index 33c00221..0be0f5f2 100644 --- a/frontends/php/include/classes/ctag.inc.php +++ b/frontends/php/include/classes/ctag.inc.php @@ -51,7 +51,52 @@ return $res; } - class CTag + class CObject + { + function CObject($items=null) + { + $this->items = array(); + if(isset($items)) + { + $this->AddItems($items); + } + } + + function ToString($destroy=true) + { + $res = implode('',$this->items); + if($destroy) $this->Destroy(); + return $res; + } + + function Show($destroy=true) { echo $this->ToString($destroy); } + + function Destroy() + { +### TODO Problem under PHP 5.0 "Fatal error: Cannot re-assign $this in ..." +# $this = null; + $this->CleanItems(); + } + + function CleanItems() { $this->items = array(); } + function ItemsCount() { return count($this->items); } + function AddItem($value) + { + if(is_array($value)) + { + foreach($value as $item) + { + array_push($this->items,unpack_object($item)); + } + } + elseif(!is_null($value)) + { + array_push($this->items,unpack_object($value)); + } + } + } + + class CTag extends CObject { /* private *//* var $tagname; @@ -68,8 +113,9 @@ /* public */ function CTag($tagname=NULL, $paired='no', $body=NULL, $class=null) { + parent::CObject(); + $this->options = array(); - $this->items = array(); if(!is_string($tagname)) { @@ -95,12 +141,6 @@ function ShowStart() { echo $this->StartToString(); } function ShowBody() { echo $this->BodyToString(); } function ShowEnd() { echo $this->EndToString(); } - function Show($destroy=true) { echo $this->ToString($destroy); } - - function Destroy() { -### TODO Problem under PHP 5.0 "Fatal error: Cannot re-assign $this in ..." -# $this = null; - } function StartToString() { @@ -115,9 +155,11 @@ function BodyToString() { $res = $this->tag_body_start; - foreach($this->items as $item) + return $res.parent::ToString(false); + + /*foreach($this->items as $item) $res .= $item; - return $res; + return $res;*/ } function EndToString() { @@ -137,6 +179,8 @@ } function SetName($value) { + if(is_null($value)) return $value; + if(!is_string($value)) { return $this->error("Incorrect value for SetName [$value]"); @@ -195,28 +239,6 @@ { $this->options[$name] = htmlspecialchars(strval($value)); } - function CleanItems() - { - $this->items = array(); - } - function ItemsCount() - { - return count($this->items); - } - function AddItem($value) - { - if(is_array($value)) - { - foreach($value as $item) - { - array_push($this->items,unpack_object($item)); - } - } - elseif(!is_null($value)) - { - array_push($this->items,unpack_object($value)); - } - } function SetEnabled($value='yes') { if((is_string($value) && ($value == 'yes' || $value == 'enabled' || $value=='on') || $value=='1') diff --git a/frontends/php/include/classes/graph.inc.php b/frontends/php/include/classes/graph.inc.php index 1493a929..83ecbb8e 100644 --- a/frontends/php/include/classes/graph.inc.php +++ b/frontends/php/include/classes/graph.inc.php @@ -220,7 +220,7 @@ if(isset($RGBA[3]) && function_exists("ImageColorExactAlpha") && function_exists("ImageCreateTrueColor") && - @imagecreatetruecolor(1,1) + @ImageCreateTrueColor(1,1) ) { $this->colors[$name] = ImageColorExactAlpha($this->im,$RGBA[0],$RGBA[1],$RGBA[2],$RGBA[3]); @@ -242,7 +242,7 @@ $this->m_showTriggers = $value == 1 ? 1 : 0;; } - function addItem($itemid, $axis, $calc_fnc = CALC_FNC_AVG, $color=null, $drawtype=null, $type=null, $periods_cnt=null) + function AddItem($itemid, $axis, $calc_fnc = CALC_FNC_AVG, $color=null, $drawtype=null, $type=null, $periods_cnt=null) { $this->items[$this->num] = get_item_by_itemid($itemid); $this->items[$this->num]["description"]=item_description($this->items[$this->num]["description"],$this->items[$this->num]["key_"]); @@ -283,7 +283,7 @@ $this->yaxistype=$yaxistype; } - function setSTime($stime) + function SetSTime($stime) { if($stime>200000000000 && $stime<220000000000) { @@ -345,7 +345,7 @@ $this->shiftY-1, $this->sizeX+$this->shiftXleft-1, $this->sizeY+$this->shiftY+1, - $this->colors["Black No Alpha"] + $this->GetColor("Black No Alpha") ); } @@ -353,12 +353,12 @@ { ImageFilledRectangle($this->im,0,0, $this->fullSizeX,$this->fullSizeY, - $this->colors["White"]); + $this->GetColor("White")); if($this->border==1) { - ImageRectangle($this->im,0,0,$this->fullSizeX-1,$this->fullSizeY-1,$this->colors["Black No Alpha"]); + ImageRectangle($this->im,0,0,$this->fullSizeX-1,$this->fullSizeY-1,$this->GetColor("Black No Alpha")); } } @@ -407,7 +407,7 @@ $fontnum = 4; } $x=$this->fullSizeX/2-ImageFontWidth($fontnum)*strlen($str)/2; - ImageString($this->im, $fontnum,$x,1, $str , $this->colors["Dark Red No Alpha"]); + ImageString($this->im, $fontnum,$x,1, $str , $this->GetColor("Dark Red No Alpha")); } function setHeader($header) @@ -420,24 +420,24 @@ $this->drawSmallRectangle(); for($i=1;$i<=5;$i++) { - DashedLine($this->im,$this->shiftXleft,$i*$this->sizeY/6+$this->shiftY,$this->sizeX+$this->shiftXleft,$i*$this->sizeY/6+$this->shiftY,$this->colors["Gray"]); + DashedLine($this->im,$this->shiftXleft,$i*$this->sizeY/6+$this->shiftY,$this->sizeX+$this->shiftXleft,$i*$this->sizeY/6+$this->shiftY,$this->GetColor("Gray")); } for($i=1;$i<=23;$i++) { - DashedLine($this->im,$i*$this->sizeX/24+$this->shiftXleft,$this->shiftY,$i*$this->sizeX/24+$this->shiftXleft,$this->sizeY+$this->shiftY,$this->colors["Gray"]); + DashedLine($this->im,$i*$this->sizeX/24+$this->shiftXleft,$this->shiftY,$i*$this->sizeX/24+$this->shiftXleft,$this->sizeY+$this->shiftY,$this->GetColor("Gray")); } $old_day=-1; for($i=0;$i<=24;$i++) { - ImageStringUp($this->im, 1,$i*$this->sizeX/24+$this->shiftXleft-3, $this->sizeY+$this->shiftY+57, date(" H:i",$this->from_time+$i*$this->period/24) , $this->colors["Black No Alpha"]); + ImageStringUp($this->im, 1,$i*$this->sizeX/24+$this->shiftXleft-3, $this->sizeY+$this->shiftY+57, date(" H:i",$this->from_time+$i*$this->period/24) , $this->GetColor("Black No Alpha")); $new_day=date("d",$this->from_time+$i*$this->period/24); if( ($old_day != $new_day) ||($i==24)) { $old_day=$new_day; - ImageStringUp($this->im, 1,$i*$this->sizeX/24+$this->shiftXleft-3, $this->sizeY+$this->shiftY+57, date("m.d H:i",$this->from_time+$i*$this->period/24) , $this->colors["Dark Red No Alpha"]); + ImageStringUp($this->im, 1,$i*$this->sizeX/24+$this->shiftXleft-3, $this->sizeY+$this->shiftY+57, date("m.d H:i",$this->from_time+$i*$this->period/24) , $this->GetColor("Dark Red No Alpha")); } } @@ -462,7 +462,7 @@ $this->shiftY, $this->sizeX+$this->shiftXleft, $this->sizeY+$this->shiftY, - $this->colors["Not Work Period"]); + $this->GetColor("Not Work Period")); $now = time(); if(isset($this->stime)) @@ -494,7 +494,7 @@ $this->shiftY, $x2, $this->sizeY+$this->shiftY, - $this->colors["White"]); + $this->GetColor("White")); $start = find_period_start($periods,$end); } @@ -559,16 +559,39 @@ $trigger['y'], $this->sizeX+$this->shiftXleft, $trigger['y'], - $this->colors[$trigger['color']]); + $this->GetColor($trigger['color'])); } } function drawLogo() { - ImageStringUp($this->im,0,$this->fullSizeX-10,$this->fullSizeY-50, "http://www.zabbix.com", $this->colors["Gray"]); + ImageStringUp($this->im,0,$this->fullSizeX-10,$this->fullSizeY-50, "http://www.zabbix.com", $this->GetColor("Gray")); } + function GetColor($color,$alfa=50) + { + if(isset($this->colors[$color])) + return $this->colors[$color]; + + $RGB = array( + hexdec('0x'.substr($color, 0,2)), + hexdec('0x'.substr($color, 2,2)), + hexdec('0x'.substr($color, 4,2)) + ); + + if(isset($alfa) && + function_exists("ImageColorExactAlpha") && + function_exists("ImageCreateTrueColor") && + @ImageCreateTrueColor(1,1) + ) + { + return ImageColorExactAlpha($this->im,$RGB[0],$RGB[1],$RGB[2],$alfa); + } + + return ImageColorAllocate($this->im,$RGB[0],$RGB[1],$RGB[2]); + } + function drawLegend() { $max_host_len=0; @@ -584,11 +607,11 @@ if($this->items[$i]["calc_type"] == GRAPH_ITEM_AGGREGATED) { $fnc_name = "agr(".$this->items[$i]["periods_cnt"].")"; - $color = $this->colors["HistoryMinMax"]; + $color = $this->GetColor("HistoryMinMax"); } else { - $color = $this->colors[$this->items[$i]["color"]]; + $color = $this->GetColor($this->items[$i]["color"]); switch($this->items[$i]["calc_fnc"]) { case CALC_FNC_MIN: $fnc_name = "min"; break; @@ -618,13 +641,13 @@ } ImageFilledRectangle($this->im,$this->shiftXleft,$this->sizeY+$this->shiftY+62+12*$i,$this->shiftXleft+5,$this->sizeY+$this->shiftY+5+62+12*$i,$color); - ImageRectangle($this->im,$this->shiftXleft,$this->sizeY+$this->shiftY+62+12*$i,$this->shiftXleft+5,$this->sizeY+$this->shiftY+5+62+12*$i,$this->colors["Black No Alpha"]); + ImageRectangle($this->im,$this->shiftXleft,$this->sizeY+$this->shiftY+62+12*$i,$this->shiftXleft+5,$this->sizeY+$this->shiftY+5+62+12*$i,$this->GetColor("Black No Alpha")); ImageString($this->im, 2, $this->shiftXleft+9, $this->sizeY+$this->shiftY+(62-5)+12*$i, $str, - $this->colors["Black No Alpha"]); + $this->GetColor("Black No Alpha")); } if($this->sizeY < 120) return; @@ -636,14 +659,14 @@ $this->sizeY+$this->shiftY+2+62+12*$i, 6, 6, - $this->colors[$trigger["color"]]); + $this->GetColor($trigger["color"])); ImageEllipse($this->im, $this->shiftXleft + 2, $this->sizeY+$this->shiftY+2+62+12*$i, 6, 6, - $this->colors["Black No Alpha"]); + $this->GetColor("Black No Alpha")); ImageString( $this->im, @@ -651,7 +674,7 @@ $this->shiftXleft+9, $this->sizeY+$this->shiftY+(62-5)+12*$i, $trigger['description'], - $this->colors["Black No Alpha"]); + $this->GetColor("Black No Alpha")); ++$i; } } @@ -1127,7 +1150,7 @@ for($i=0;$i<=6;$i++) { $str = str_pad(convert_units($this->sizeY*$i/6*($maxY-$minY)/$this->sizeY+$minY,$units),10," ", STR_PAD_LEFT); - ImageString($this->im, 1, 5, $this->sizeY-$this->sizeY*$i/6-4+$this->shiftY, $str, $this->colors["Dark Red No Alpha"]); + ImageString($this->im, 1, 5, $this->sizeY-$this->sizeY*$i/6-4+$this->shiftY, $str, $this->GetColor("Dark Red No Alpha")); } } } @@ -1150,7 +1173,7 @@ for($i=0;$i<=6;$i++) { $str = str_pad(convert_units($this->sizeY*$i/6*($maxY-$minY)/$this->sizeY+$minY,$units),10," "); - ImageString($this->im, 1, $this->sizeX+$this->shiftXleft+2, $this->sizeY-$this->sizeY*$i/6-4+$this->shiftY, $str, $this->colors["Dark Red No Alpha"]); + ImageString($this->im, 1, $this->sizeX+$this->shiftXleft+2, $this->sizeY-$this->sizeY*$i/6-4+$this->shiftY, $str, $this->GetColor("Dark Red No Alpha")); } } } @@ -1212,10 +1235,10 @@ { $drawtype = GRAPH_DRAW_TYPE_LINE; - $max_color = $this->colors["HistoryMax"]; - $avg_color = $this->colors["HistoryAvg"]; - $min_color = $this->colors["HistoryMin"]; - $minmax_color = $this->colors["HistoryMinMax"]; + $max_color = $this->GetColor("HistoryMax"); + $avg_color = $this->GetColor("HistoryAvg"); + $min_color = $this->GetColor("HistoryMin"); + $minmax_color = $this->GetColor("HistoryMinMax"); $calc_fnc = CALC_FNC_ALL; } @@ -1223,10 +1246,10 @@ { $drawtype = $this->items[$item]["drawtype"]; - $max_color = $this->colors["ValueMax"]; - $avg_color = $this->colors[$this->items[$item]["color"]]; - $min_color = $this->colors["ValueMin"]; - $minmax_color = $this->colors["ValueMinMax"]; + $max_color = $this->GetColor("ValueMax"); + $avg_color = $this->GetColor($this->items[$item]["color"]); + $min_color = $this->GetColor("ValueMin"); + $minmax_color = $this->GetColor("ValueMinMax"); $calc_fnc = $this->items[$item]["calc_fnc"]; } @@ -1282,7 +1305,7 @@ $end_time=getmicrotime(); $str=sprintf("%0.2f",($end_time-$start_time)); - ImageString($this->im, 0,$this->fullSizeX-120,$this->fullSizeY-12,"Generated in $str sec", $this->colors["Gray"]); + ImageString($this->im, 0,$this->fullSizeX-120,$this->fullSizeY-12,"Generated in $str sec", $this->GetColor("Gray")); ImageOut($this->im); ImageDestroy($this->im); diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php index eba0fdf1..4a9e0f96 100644 --- a/frontends/php/include/config.inc.php +++ b/frontends/php/include/config.inc.php @@ -47,6 +47,7 @@ function VDP($var, $msg=null) { echo "DEBUG DUMP: "; if(isset($msg)) echo '"'.$m require_once("include/classes/cvar.inc.php"); require_once("include/classes/cspan.inc.php"); require_once("include/classes/cimg.inc.php"); + require_once("include/classes/ccolor.inc.php"); require_once("include/classes/clink.inc.php"); require_once("include/classes/chelp.inc.php"); require_once("include/classes/cbutton.inc.php"); @@ -185,6 +186,17 @@ function VDP($var, $msg=null) { echo "DEBUG DUMP: "; if(isset($msg)) echo '"'.$m array_push($ZBX_MESSAGES, array('type' => 'error', 'message' => $msg)); } + function &asort_by_key(&$array, $key) + { + if(!is_array($array)) { + error('Incorrect type of asort_by_key'); + return array(); + } + $key = htmlspecialchars($key); + uasort($array, create_function('$a,$b', 'return $a[\''.$key.'\'] - $b[\''.$key.'\'];')); + return $array; + } + function fatal_error($msg) { include_once "include/page_header.php"; @@ -1273,21 +1285,6 @@ else } } - function get_drawtype_description($drawtype) - { - if($drawtype==0) - return "Line"; - if($drawtype==1) - return "Filled region"; - if($drawtype==2) - return "Bold line"; - if($drawtype==3) - return "Dot"; - if($drawtype==4) - return "Dashed line"; - return "Unknown"; - } - $SHOW_HINT_SCRIPT_ISERTTED = false; /* TODO rewrite with JS include */ function insert_showhint_javascript() diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php index 28dd140f..2849c62d 100644 --- a/frontends/php/include/defines.inc.php +++ b/frontends/php/include/defines.inc.php @@ -46,6 +46,7 @@ define("T_ZBX_DBL", 2); define("T_ZBX_PERIOD", 3); define("T_ZBX_IP", 4); + define("T_ZBX_CLR", 5); define("O_MAND", 0); define("O_OPT", 1); @@ -159,6 +160,12 @@ define("ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV",1); define("ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV",2); + define('GRAPH_ITEM_DRAWTYPE_LINE', 0); + define('GRAPH_ITEM_DRAWTYPE_FILLED_REGION', 1); + define('GRAPH_ITEM_DRAWTYPE_BOLD_LINE', 2); + define('GRAPH_ITEM_DRAWTYPE_DOT', 3); + define('GRAPH_ITEM_DRAWTYPE_DASHED_LINE', 4); + define("SERVICE_ALGORITHM_NONE",0); define("SERVICE_ALGORITHM_MAX",1); define("SERVICE_ALGORITHM_MIN",2); diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php index 635c82c7..ce56932c 100644 --- a/frontends/php/include/forms.inc.php +++ b/frontends/php/include/forms.inc.php @@ -1351,9 +1351,12 @@ { global $_REQUEST; - $frmGraph = new CFormTable(S_GRAPH,"graphs.php"); + $frmGraph = new CFormTable(S_GRAPH); + $frmGraph->SetName('frm_graph'); $frmGraph->SetHelp("web.graphs.graph.php"); + $items = get_request('items', array()); + if(isset($_REQUEST["graphid"])) { $frmGraph->AddVar("graphid",$_REQUEST["graphid"]); @@ -1363,7 +1366,7 @@ $frmGraph->SetTitle(S_GRAPH." \"".$row["name"]."\""); } - if(isset($_REQUEST["graphid"])&&!isset($_REQUEST["name"])) + if(isset($_REQUEST["graphid"]) && !isset($_REQUEST["form_refresh"])) { $name =$row["name"]; $width =$row["width"]; @@ -1374,23 +1377,65 @@ $showworkperiod = $row["show_work_period"]; $showtriggers = $row["show_triggers"]; $graphtype = $row["graphtype"]; + + $db_items = DBselect('select * from graphs_items where graphid='.$_REQUEST["graphid"]); + while($item = DBfetch($db_items)) + { + array_push($items, + array( + 'itemid' => $item['itemid'], + 'drawtype' => $item['drawtype'], + 'sortorder' => $item['sortorder'], + 'color' => $item['color'], + 'yaxisside' => $item['yaxisside'], + 'calc_fnc' => $item['calc_fnc'], + 'type' => $item['type'], + 'periods_cnt' => $item['periods_cnt'] + )); + } } else { - $name =get_request("name" ,""); - $width =get_request("width" ,900); - $height =get_request("height" ,200); - $yaxistype =get_request("yaxistype",GRAPH_YAXIS_TYPE_CALCULATED); - $yaxismin =get_request("yaxismin" ,0.00); - $yaxismax =get_request("yaxismax" ,100.00); - $showworkperiod = get_request("showworkperiod",1); - $showtriggers = get_request("showtriggers",1); - $graphtype = get_request("graphtype",GRAPH_TYPE_NORMAL); + $name = get_request("name" ,""); + $width = get_request("width" ,900); + $height = get_request("height" ,200); + $yaxistype = get_request("yaxistype" ,GRAPH_YAXIS_TYPE_CALCULATED); + $yaxismin = get_request("yaxismin" ,0.00); + $yaxismax = get_request("yaxismax" ,100.00); + $showworkperiod = get_request("showworkperiod" ,1); + $showtriggers = get_request("showtriggers" ,1); + $graphtype = get_request("graphtype" ,GRAPH_TYPE_NORMAL); + } + + /* reinit $_REQUEST */ + $_REQUEST['items'] = $items; + $_REQUEST['name'] = $name; + $_REQUEST['width'] = $width; + $_REQUEST['height'] = $height; + $_REQUEST['yaxistype'] = $yaxistype; + $_REQUEST['yaxismin'] = $yaxismin; + $_REQUEST['yaxismax'] = $yaxismax; + $_REQUEST['showworkperiod'] = $showworkperiod; + $_REQUEST['showtriggers'] = $showtriggers; + $_REQUEST['graphtype'] = $graphtype; + /********************/ + + if($graphtype == GRAPH_TYPE_STACKED) + { + foreach($items as $gid => $gitem) + { + if($gitem['type'] != GRAPH_ITEM_AGGREGATED) continue; + unset($items[$gid]); + } } + + asort_by_key($items, 'sortorder'); + + $group_gid = get_request('group_gid', array()); $frmGraph->AddRow(S_NAME,new CTextBox("name",$name,32)); $frmGraph->AddRow(S_WIDTH,new CTextBox("width",$width,5)); $frmGraph->AddRow(S_HEIGHT,new CTextBox("height",$height,5)); - $cmbGType = new CComboBox("graphtype",$graphtype); + $cmbGType = new CComboBox("graphtype",$graphtype,'submit()'); $cmbGType->AddItem(GRAPH_TYPE_NORMAL,S_NORMAL); $cmbGType->AddItem(GRAPH_TYPE_STACKED,S_STACKED); $frmGraph->AddRow(S_GRAPH_TYPE,$cmbGType); @@ -1414,6 +1459,73 @@ $frmGraph->AddVar("yaxismax",$yaxismax); } + $only_hostid = null; + if(count($items)) + { + $frmGraph->AddVar('items', $items); + + $items_table = new CTableInfo(); + foreach($items as $gid => $gitem) + { + if($graphtype == GRAPH_TYPE_STACKED && $gitem['type'] == GRAPH_ITEM_AGGREGATED) continue; + + $host = get_host_by_itemid($gitem['itemid']); + $item = get_item_by_itemid($gitem['itemid']); + + if($host['status'] == HOST_STATUS_TEMPLATE) $only_hostid = $host['hostid']; + + if($gitem["type"] == GRAPH_ITEM_AGGREGATED) + $color = "-"; + else + $color = new CColorCell(null,$gitem['color']); + + $do_up = new CLink(S_UP,'#','action'); + $do_up->OnClick("return create_var('".$frmGraph->GetName()."','move_up',".$gid.", true);"); + + $do_down = new CLink(S_DOWN,'#','action'); + $do_down->OnClick("return create_var('".$frmGraph->GetName()."','move_down',".$gid.", true);"); + + $description = new CLink($host['host'].': '.item_description($item["description"],$item["key_"]),'#','action'); + $description->OnClick( + 'return PopUp("popup_gitem.php?list_name=items&dstfrm='.$frmGraph->GetName(). + url_param($only_hostid, false, 'only_hostid'). + url_param($graphtype, false, 'graphtype'). + url_param($gitem, false). + url_param($gid,false,'gid'). + '","new_media",'. + '"width=550,height=400,resizable=1,scrollbars=1");'); + + $items_table->AddRow(array( + new CCheckBox('group_gid['.$gid.']',isset($group_gid[$gid])), + $gitem['sortorder'], + $description, + graph_item_calc_fnc2str($gitem["calc_fnc"],$gitem["type"]), + graph_item_type2str($gitem['type'],$gitem["periods_cnt"]), + graph_item_drawtype2str($gitem["drawtype"],$gitem["type"]), + $color, + array( $do_up, SPACE."|".SPACE, $do_down ) + )); + } + $dedlete_button = new CButton('delete_item', S_DELETE_SELECTED); + } + else + { + $items_table = $dedlete_button = null; + } + + $frmGraph->AddRow(S_ITEMS, + array( + $items_table, + new CButton('add_item',S_ADD, + 'return PopUp("popup_gitem.php?dstfrm='.$frmGraph->GetName(). + url_param($only_hostid, false, 'only_hostid'). + url_param($graphtype, false, 'graphtype'). + '","new_media",'. + '"width=550,height=400,resizable=1,scrollbars=1");'), + $dedlete_button + )); + unset($items_table, $dedlete_button); + $frmGraph->AddItemToBottomRow(new CButton("save",S_SAVE)); if(isset($_REQUEST["graphid"])) { @@ -1425,82 +1537,55 @@ $frmGraph->AddItemToBottomRow(new CButtonCancel(url_param("groupid").url_param("hostid"))); $frmGraph->Show(); - } function insert_graphitem_form() { - $frmGItem = new CFormTable(S_NEW_ITEM_FOR_THE_GRAPH,"graph.php"); + $frmGItem = new CFormTable(S_NEW_ITEM_FOR_THE_GRAPH); + $frmGItem->SetName('graph_item'); $frmGItem->SetHelp("web.graph.item.php"); - - - $db_graph = get_graph_by_graphid($_REQUEST["graphid"]); - - $db_host = DBfetch(get_hosts_by_graphid($_REQUEST["graphid"])); - - $host_condition = ""; - if($db_host) - { - if($db_host["status"]==HOST_STATUS_TEMPLATE) - {// graph for template must use only one host - $host_condition = "&only_hostid=".$db_host["hostid"]; - } - else - { - $host_condition = "&monitored_hosts=1"; - } - } - if(isset($_REQUEST["gitemid"])) - { - $result=DBselect("select itemid,color,drawtype,sortorder,yaxisside,calc_fnc,type,periods_cnt from graphs_items". - " where gitemid=".$_REQUEST["gitemid"]); - $row=DBfetch($result); - - } - - if(isset($_REQUEST["gitemid"]) && !isset($_REQUEST["form_refresh"])) - { - $itemid = $row["itemid"]; - $color = $row["color"]; - $drawtype = $row["drawtype"]; - $sortorder = $row["sortorder"]; - $yaxisside = $row["yaxisside"]; - $calc_fnc = $row["calc_fnc"]; - $type = $row["type"]; - $periods_cnt = $row["periods_cnt"]; - } - else - { - $itemid = get_request("itemid", 0); - $color = get_request("color", 'Dark Green'); - $drawtype = get_request("drawtype", 0); - $sortorder = get_request("sortorder", 0); - $yaxisside = get_request("yaxisside", 1); - $calc_fnc = get_request("calc_fnc", 2); - $type = get_request("type", 0); - $periods_cnt = get_request("periods_cnt", 5); - } - - - $frmGItem->AddVar("graphid",$_REQUEST["graphid"]); - if(isset($_REQUEST["gitemid"])) - { - $frmGItem->AddVar("gitemid",$_REQUEST["gitemid"]); - } + $frmGItem->AddVar('dstfrm',$_REQUEST['dstfrm']); + + $graphtype = get_request("graphtype", GRAPH_TYPE_NORMAL); + $gid = get_request("gid", null); + $list_name = get_request("list_name", null); + $itemid = get_request("itemid", 0); + $color = get_request("color", '009900'); + $drawtype = get_request("drawtype", 0); + $sortorder = get_request("sortorder", 0); + $yaxisside = get_request("yaxisside", 1); + $calc_fnc = get_request("calc_fnc", 2); + $type = get_request("type", 0); + $periods_cnt = get_request("periods_cnt", 5); + $only_hostid = get_request("only_hostid", null); $description = ''; if($itemid > 0) { $description = DBfetch(DBselect("select * from items where itemid=".$itemid)); - $description = $description['description']; + $description = item_description($description['description'],$description['key_']); } + $frmGItem->AddVar('gid',$gid); + $frmGItem->AddVar('list_name',$list_name); $frmGItem->AddVar('itemid',$itemid); + $frmGItem->AddVar('graphtype',$graphtype); + $frmGItem->AddVar('only_hostid',$only_hostid); $txtCondVal = new CTextBox('description',$description,50); $txtCondVal->SetReadonly('yes'); + $host_condition = ""; + if(isset($only_hostid)) + {// graph for template must use only one host + $host_condition = "&only_hostid=".$only_hostid; + } + else + { + $host_condition = "&monitored_hosts=1"; + } + $btnSelect = new CButton('btn1',S_SELECT, "return PopUp('popup.php?dstfrm=".$frmGItem->GetName(). "&dstfld1=itemid&dstfld2=description&". @@ -1510,7 +1595,7 @@ $btnSelect->SetAccessKey('T'); $frmGItem->AddRow(S_PARAMETER ,array($txtCondVal,$btnSelect)); - if($db_graph["graphtype"] == GRAPH_TYPE_NORMAL) + if($graphtype == GRAPH_TYPE_NORMAL) { $cmbType = new CComboBox("type",$type,"submit()"); $cmbType->AddItem(GRAPH_ITEM_SIMPLE, S_SIMPLE); @@ -1521,7 +1606,6 @@ { $frmGItem->AddVar("type",GRAPH_ITEM_SIMPLE); } - if($type == GRAPH_ITEM_AGGREGATED) { @@ -1537,7 +1621,7 @@ $cmbFnc = new CComboBox("calc_fnc",$calc_fnc,'submit();'); - if($db_graph["graphtype"] == GRAPH_TYPE_NORMAL) + if($graphtype == GRAPH_TYPE_NORMAL) $cmbFnc->AddItem(CALC_FNC_ALL, S_ALL_SMALL); $cmbFnc->AddItem(CALC_FNC_MIN, S_MIN_SMALL); @@ -1545,14 +1629,13 @@ $cmbFnc->AddItem(CALC_FNC_MAX, S_MAX_SMALL); $frmGItem->AddRow(S_FUNCTION, $cmbFnc); - if($db_graph["graphtype"] == GRAPH_TYPE_NORMAL) + if($graphtype == GRAPH_TYPE_NORMAL) { $cmbType = new CComboBox("drawtype",$drawtype); - $cmbType->AddItem(0,get_drawtype_description(0)); - if($calc_fnc != CALC_FNC_ALL) - $cmbType->AddItem(1,get_drawtype_description(1)); - $cmbType->AddItem(2,get_drawtype_description(2)); - $cmbType->AddItem(3,get_drawtype_description(3)); + for($i=0; $i < 5; ++$i) + { + $cmbType->AddItem($i,graph_item_drawtype2str($i)); + } $frmGItem->AddRow(S_DRAW_STYLE, $cmbType); } else @@ -1560,19 +1643,7 @@ $frmGItem->AddVar("drawtype", 1); } - $cmbColor = new CComboBox("color",$color); - $cmbColor->AddItem("Black", S_BLACK); - $cmbColor->AddItem("Blue", S_BLUE); - $cmbColor->AddItem("Cyan", S_CYAN); - $cmbColor->AddItem("Dark Blue", S_DARK_BLUE); - $cmbColor->AddItem("Dark Green", S_DARK_GREEN); - $cmbColor->AddItem("Dark Red", S_DARK_RED); - $cmbColor->AddItem("Dark Yellow", S_DARK_YELLOW); - $cmbColor->AddItem("Green", S_GREEN); - $cmbColor->AddItem("Red", S_RED); - $cmbColor->AddItem("White", S_WHITE); - $cmbColor->AddItem("Yellow", S_YELLOW); - $frmGItem->AddRow(S_COLOR, $cmbColor); + $frmGItem->AddRow(S_COLOR, new CColor('color',$color)); } $cmbYax = new CComboBox("yaxisside",$yaxisside); @@ -1582,15 +1653,9 @@ $frmGItem->AddRow(S_SORT_ORDER_1_100, new CTextBox("sortorder",$sortorder,3)); - $frmGItem->AddItemToBottomRow(new CButton("save",S_SAVE)); - $frmGItem->AddItemToBottomRow(SPACE); - if(isset($_REQUEST["gitemid"])) - { - $frmGItem->AddItemToBottomRow(new CButtonDelete("Delete graph element?", - url_param("gitemid").url_param("graphid"))); - $frmGItem->AddItemToBottomRow(SPACE); - } - $frmGItem->AddItemToBottomRow(new CButtonCancel(url_param("graphid"))); + $frmGItem->AddItemToBottomRow(new CButton("save", isset($gid) ? S_SAVE : S_ADD)); + + $frmGItem->AddItemToBottomRow(new CButton('cancel',S_CANCEL,'window.close();')); $frmGItem->Show(); } @@ -3424,7 +3489,7 @@ $cmbType_on = new CComboBox("drawtype_on",$drawtype_on); for($i=0; $i < 5; ++$i) { - $value = get_drawtype_description($i); + $value = graph_item_drawtype2str($i); $cmbType_off->AddItem($i, $value); $cmbType_on->AddItem($i, $value); } diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php index 66bc2bb5..50ab85de 100644 --- a/frontends/php/include/graphs.inc.php +++ b/frontends/php/include/graphs.inc.php @@ -19,6 +19,48 @@ **/ ?> <?php + function graph_item_type2str($type,$count=null) + { + switch($type) + { + case GRAPH_ITEM_AGGREGATED: $type = S_AGGREGATED.(isset($count) ? '('.$count.')' : ''); break; + case GRAPH_ITEM_SIMPLE: + default: $type = S_SIMPLE; break; + } + return $type; + } + + function graph_item_drawtype2str($drawtype,$type=null) + { + if($type == GRAPH_ITEM_AGGREGATED) return '-'; + + switch($drawtype) + { + case GRAPH_ITEM_DRAWTYPE_LINE: $drawtype = "Line"; break; + case GRAPH_ITEM_DRAWTYPE_FILLED_REGION: $drawtype = "Filled region"; break; + case GRAPH_ITEM_DRAWTYPE_BOLD_LINE: $drawtype = "Bold line"; break; + case GRAPH_ITEM_DRAWTYPE_DOT: $drawtype = "Dot"; break; + case GRAPH_ITEM_DRAWTYPE_DASHED_LINE: $drawtype = "Dashed line"; break; + default: $drawtype = S_UNKNOWN; break; + } + return $drawtype; + } + + function graph_item_calc_fnc2str($calc_fnc, $type=null) + { + if($type == GRAPH_ITEM_AGGREGATED) return '-'; + + switch($calc_fnc) + { + case CALC_FNC_ALL: $calc_fnc = S_ALL_SMALL; break; + case CALC_FNC_MIN: $calc_fnc = S_MIN_SMALL; break; + case CALC_FNC_MAX: $calc_fnc = S_MAX_SMALL; break; + case CALC_FNC_AVG: + default: $calc_fnc = S_AVG_SMALL; break; + } + return $calc_fnc; + } + function get_graph_by_gitemid($gitemid) { $db_graphs = DBselect("select distinct g.* from graphs g, graphs_items gi". @@ -108,10 +150,37 @@ if($result) { info("Graph '$name' added"); + $result = $graphid; } - return $graphid; + return $result; } + function add_graph_with_items($name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype=GRAPH_TYPE_NORMAL,$items=array(),$templateid=0) + { + if($result = add_graph($name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype,$templateid)) + { + foreach($items as $gitem) + { + if(!add_item_to_graph( + $result, + $gitem['itemid'], + $gitem['color'], + $gitem['drawtype'], + $gitem['sortorder'], + $gitem['yaxisside'], + $gitem['calc_fnc'], + $gitem['type'], + $gitem['periods_cnt'])) + { + delete_graph($result); + return false; + } + + } + } + return $result; + } + # Update Graph function update_graph($graphid,$name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype=GRAPH_TYPE_NORMAL,$templateid=0) @@ -143,6 +212,36 @@ return $result; } + function update_graph_with_items($graphid,$name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype=GRAPH_TYPE_NORMAL,$items=array(),$templateid=0) + { + $result = update_graph($graphid,$name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod, + $showtriggers,$graphtype,$templateid); + + if($result) $result = DBexecute("delete from graphs_items where graphid=$graphid"); + + if($result) + { + foreach($items as $gitem) + { + if(!add_item_to_graph( + $graphid, + $gitem['itemid'], + $gitem['color'], + $gitem['drawtype'], + $gitem['sortorder'], + $gitem['yaxisside'], + $gitem['calc_fnc'], + $gitem['type'], + $gitem['periods_cnt'])) + { + delete_graph($graphid); + return false; + } + } + } + return $result; + } + # Delete Graph function delete_graph($graphid) @@ -267,9 +366,10 @@ if($result) { info("Added Item '".$item["description"]."' for graph '".$graph["name"]."'"); + $result = $gitemid; } - return $gitemid; + return $result; } function update_graph_item($gitemid,$itemid,$color,$drawtype,$sortorder,$yaxisside,$calc_fnc,$type,$periods_cnt) diff --git a/frontends/php/include/html.inc.php b/frontends/php/include/html.inc.php index 2a57bb43..66b5a741 100644 --- a/frontends/php/include/html.inc.php +++ b/frontends/php/include/html.inc.php @@ -92,7 +92,9 @@ if(is_array($var)) { foreach($var as $id => $par) - $result .= prepare_url($par,$varname."[".$id."]"); + $result .= prepare_url($par, + isset($varname) ? $varname."[".$id."]": $id + ); } else { @@ -103,11 +105,19 @@ function url_param($parameter,$request=true,$name=null) { - if(!$request && !isset($name)) fatal_error('not request variable require url name [url_param]'); - $result = ""; - if(!isset($name)) $name = $parameter; + + if(!is_array($parameter)) + { + if(!isset($name)) + { + if(!$request) + fatal_error('not request variable require url name [url_param]'); + + $name = $parameter; + } + } if($request) { diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php index 8ec0ca66..0d29d698 100644 --- a/frontends/php/include/locales/en_gb.inc.php +++ b/frontends/php/include/locales/en_gb.inc.php @@ -388,6 +388,8 @@ "S_CREATE_GRAPH"=> "Create Graph", "S_SHOW_WORKING_TIME"=> "Show working time", "S_SHOW_TRIGGERS"=> "Show triggers", + "S_GRAPH_ITEM"=> "Graph item", + "S_REQUIRED_ITEMS_FOR_GRAPH"=> "Required items for graph", // history.php "S_LAST_HOUR_GRAPH"=> "Last hour graph", diff --git a/frontends/php/include/page_header.php b/frontends/php/include/page_header.php index f0afac3e..0baf504a 100644 --- a/frontends/php/include/page_header.php +++ b/frontends/php/include/page_header.php @@ -189,7 +189,7 @@ COpt::profiling_start("page"); "sub_pages"=>array("sysmap.php") ), array("url"=>"graphs.php" ,"label"=>S_GRAPHS , - "sub_pages"=>array("graph.php") + "sub_pages"=>array("popup_gitem.php") ), array("url"=>"screenconf.php" ,"label"=>S_SCREENS , "sub_pages"=>array("screenedit.php") diff --git a/frontends/php/include/validate.inc.php b/frontends/php/include/validate.inc.php index 95ba33d9..98ea357d 100644 --- a/frontends/php/include/validate.inc.php +++ b/frontends/php/include/validate.inc.php @@ -29,6 +29,11 @@ define('ZBX_VALID_ERROR', 1); define('ZBX_VALID_WARNING', 2); + function is_hex_color($value) + { + return eregi('[0-9,A-F]{6}', $value); + } + function BETWEEN($min,$max,$var=NULL) { return "({".$var."}>=".$min."&&{".$var."}<=".$max.")&&"; @@ -219,6 +224,20 @@ return ZBX_VALID_WARNING; } } + + if(($type == T_ZBX_CLR) && !is_hex_color($var)) { + $var = 'FFFFFF'; + if($flags&P_SYS) + { + info("Critical error. Field [".$field."] is not color"); + return ZBX_VALID_ERROR; + } + else + { + info("Warning. Field [".$field."] is not color"); + return ZBX_VALID_WARNING; + } + } return ZBX_VALID_OK; } |
