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 | |
| 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')
| -rw-r--r-- | frontends/php/chart2.php | 2 | ||||
| -rw-r--r-- | frontends/php/chart3.php | 105 | ||||
| -rw-r--r-- | frontends/php/css.css | 70 | ||||
| -rw-r--r-- | frontends/php/graph.php | 242 | ||||
| -rw-r--r-- | frontends/php/graphs.php | 146 | ||||
| -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 | ||||
| -rw-r--r-- | frontends/php/popup.php | 20 | ||||
| -rw-r--r-- | frontends/php/popup_gitem.php | 186 |
18 files changed, 1119 insertions, 494 deletions
diff --git a/frontends/php/chart2.php b/frontends/php/chart2.php index fb564cfa..15c6a9c9 100644 --- a/frontends/php/chart2.php +++ b/frontends/php/chart2.php @@ -36,7 +36,7 @@ include_once "include/page_header.php"; "graphid"=> array(T_ZBX_INT, O_MAND, P_SYS, DB_ID, null), "period"=> array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(3600,12*31*24*3600), null), "from"=> array(T_ZBX_INT, O_OPT, P_NZERO, null, null), - "stime"=> array(T_ZBX_INT, O_OPT, P_NZERO, null, null), + "stime"=> array(T_ZBX_STR, O_OPT, P_SYS, null, null), "border"=> array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), "width"=> array(T_ZBX_INT, O_OPT, P_NZERO, '{}>0', null), "height"=> array(T_ZBX_INT, O_OPT, P_NZERO, '{}>0', null), diff --git a/frontends/php/chart3.php b/frontends/php/chart3.php new file mode 100644 index 00000000..a69898db --- /dev/null +++ b/frontends/php/chart3.php @@ -0,0 +1,105 @@ +<?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. +**/ +?> +<?php + require_once "include/config.inc.php"; + require_once "include/graphs.inc.php"; + require_once "include/classes/graph.inc.php"; + + $page["file"] = "chart2.php"; + $page["title"] = "S_CHART"; + $page["type"] = PAGE_TYPE_IMAGE; + +include_once "include/page_header.php"; + +?> +<?php +// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION + $fields=array( + "period"=> array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(3600,12*31*24*3600), 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), + "yaxistype"=> array(T_ZBX_INT, O_OPT, NULL, IN("0,1"), null), + "graphtype"=> array(T_ZBX_INT, O_OPT, NULL, IN("0,1"), null), + "yaxismin"=> array(T_ZBX_DBL, O_OPT, NULL, BETWEEN(-65535,65535), null), + "yaxismax"=> array(T_ZBX_DBL, O_OPT, NULL, BETWEEN(-65535,65535), null), + "yaxismax"=> array(T_ZBX_DBL, O_OPT, NULL, BETWEEN(-65535,65535), null), + "items"=> array(T_ZBX_STR, O_OPT, NULL, null, null) + ); + + check_fields($fields); +?> +<?php + $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_MODE_LT, PERM_RES_IDS_ARRAY); + + $items = get_request('items', array()); + + asort_by_key($items, 'sortorder'); + + foreach($items as $gitem) + { + $host = DBfetch(DBselect('select h.* from hosts h,items i where h.hostid=i.hostid and i.itemid='.$gitem['itemid'])); + if(in_array($host['hostid'], $denyed_hosts)) + { + access_deny(); + } + } + + $graph = new Graph(get_request("graphtype" ,GRAPH_TYPE_NORMAL)); + + $graph->SetHeader($host["host"].":".get_request("name","")); + + 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(isset($_REQUEST["border"])) $graph->SetBorder(0); + + $graph->SetWidth(get_request("width", 900)); + $graph->SetHeight(get_request("height", 200)); + + $graph->ShowWorkPeriod(get_request("showworkperiod" ,1)); + $graph->ShowTriggers(get_request("showtriggers" ,1)); + $graph->SetYAxisType(get_request("yaxistype" ,GRAPH_YAXIS_TYPE_CALCULATED)); + $graph->SetYAxisMin(get_request("yaxismin" ,0.00)); + $graph->SetYAxisMax(get_request("yaxismax" ,100.00)); + + foreach($items as $gitem) + { + $graph->AddItem( + $gitem["itemid"], + $gitem["yaxisside"], + $gitem["calc_fnc"], + $gitem["color"], + $gitem["drawtype"], + $gitem["type"], + $gitem["periods_cnt"] + ); + } + $graph->Draw(); +?> +<?php + +include_once "include/page_footer.php"; + +?> diff --git a/frontends/php/css.css b/frontends/php/css.css index 95a04e12..41d89cd5 100644 --- a/frontends/php/css.css +++ b/frontends/php/css.css @@ -125,7 +125,7 @@ table.formtable td.form_row_l { /* left cell */ border-color: #222255; text-align: left; white-space: nowrap; - word-spacing: nowrap; + word-spacing: 0px; width: 50%; } table.formtable td.form_row_c { /* center cell */ @@ -157,7 +157,7 @@ table.log_history_table { } table.log_history_table td { white-space: nowrap; - word-spacing: nowrap; + word-spacing: 0px; font-family:verdana, arial, helvetica, sans-serif; font-size:8pt; text-decoration: none; @@ -176,7 +176,7 @@ table.log_history_table tr.header td { padding-right: 5px; padding-left: 5px; white-space: nowrap; - word-spacing: nowrap; + word-spacing: 0px; text-align: center; font-weight: bold; background-color:#CCCCCC; @@ -275,7 +275,7 @@ table.tableinfo } table.tableinfo td { white-space: nowrap; - word-spacing: nowrap; + word-spacing: 0px; font-family:verdana, arial, helvetica, sans-serif; font-size:8pt; text-decoration: none; @@ -289,7 +289,7 @@ table.tableinfo td.message { } table.tableinfo tr.header td { white-space: nowrap; - word-spacing: nowrap; + word-spacing: 0px; font-weight: bold; background-color:#CCCCCC; } @@ -299,7 +299,7 @@ table.tableinfo tr.vertical_header td { padding-bottom: 5; margin: 0; white-space: nowrap; - word-spacing: nowrap; + word-spacing: 0px; font-weight: bold; background-color:#CCCCCC; vertical-align:text-top; @@ -309,7 +309,7 @@ table.tableinfo tr.vertical_header td { } table.tableinfo tr.header td { white-space: nowrap; - word-spacing: nowrap; + word-spacing: 0px; font-weight: bold; background-color:#CCCCCC; } @@ -419,7 +419,7 @@ table.header td.header_r table.header a { - color: #FFFFFF; !important + color: #FFFFFF; } /**************** Aknowledges ****************/ @@ -432,7 +432,7 @@ table.ack_msgs } table.ack_msgs tr.title { height: 14px; - vertical-align: center; + vertical-align: middle; color: #FFFFFF; background: #5C7099 url(images/gradients/table_head2.gif) repeat-x top left; } @@ -490,7 +490,7 @@ table.right_table td padding: 0px; text-align: right; white-space: nowrap; - word-spacing: nowrap; + word-spacing: 0px; } table.right_table select @@ -634,7 +634,7 @@ table.triggers_info { table.triggers_info td { border: 0px; white-space: nowrap; - word-spacing: nowrap; + word-spacing: 0px; padding-left: 5px; padding-right: 5px; font-weight: bold; @@ -666,7 +666,7 @@ table.hosts_info { table.hosts_info td { border: 0px; white-space: nowrap; - word-spacing: nowrap; + word-spacing: 0px; padding-left: 5px; padding-right: 5px; font-weight: bold; @@ -710,7 +710,7 @@ table.server_info td { font-size: 11px; background-color: #EFEFEF; white-space: nowrap; - word-spacing: nowrap; + word-spacing: 0px; } table.server_info td.header { @@ -719,7 +719,7 @@ table.server_info td.header { } table.server_info tr.status td{ white-space: nowrap; - word-spacing: nowrap; + word-spacing: 0px; } /**************** SETUP WIZARD ***********/ @@ -775,7 +775,7 @@ table.setup_wizard td.left padding-left: 10px; padding-right: 5px; white-space: nowrap; - word-spacing: nowrap; + word-spacing: 0px; text-align: left; } table.setup_wizard td.right @@ -837,7 +837,7 @@ table.setup_wizard div.text vertical-align: text-top; height: 100%; width: 100%; - overflow: none; + overflow: hidden; } /********** REQUIREMENTS TABLE *************/ @@ -951,7 +951,7 @@ A.footer color:#CCCCCC; } -A {font-family:Verdana, Arial, Helvetica, sans-serif;font-size:8pt} +A {font-family:Verdana, Arial, Helvetica, sans-serif;font-size:8pt;} A:link {color:black; text-decoration: none; } A:visited {color:black; text-decoration: none; } A:hover {color:black; text-decoration: underline; } @@ -1018,12 +1018,12 @@ ul .nowrap { white-space: nowrap; - word-spacing: nowrap; + word-spacing: 0px; } /**************** HINT BOX *****************/ -#hint_box{ +#hint_box { top: 0; z-index: 100; position: absolute; @@ -1037,6 +1037,38 @@ ul border-top: none; visibility: hidden; } + +/************** END OF HINT BOX ************/ + +/************** COLOR PICKER ***************/ + +#color_picker { + top: 0; + z-index: 100; + position: absolute; + background-color: white; + padding: 2px; + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 10px; + line-height:15px; + border: 1px solid black; +} + +#color_picker table tr td { + margin: 0px; + padding: 2px; +} + +#color_picker a { + text-decoration: none; + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 10px; + padding: 0px; + margin: 0px; +} + +/************ END OF COLOR PICKER ***********/ + .center { width: 100%; diff --git a/frontends/php/graph.php b/frontends/php/graph.php deleted file mode 100644 index dff97582..00000000 --- a/frontends/php/graph.php +++ /dev/null @@ -1,242 +0,0 @@ -<?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. -**/ -?> -<?php - require_once "include/config.inc.php"; - require_once "include/items.inc.php"; - require_once "include/graphs.inc.php"; - require_once "include/forms.inc.php"; - - $page["title"] = "S_CONFIGURATION_OF_GRAPH"; - $page["file"] = "graph.php"; - -include_once "include/page_header.php"; - - insert_confirm_javascript(); -?> -<?php - -// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION - $fields=array( - "graphid"=> array(T_ZBX_INT, O_MAND, P_SYS, DB_ID,NULL), - - "gitemid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), - "itemid"=> array(T_ZBX_INT, O_OPT, NULL, NULL, 'isset({save})'), - "color"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({save})'), - "drawtype"=> array(T_ZBX_INT, O_OPT, NULL, IN("0,1,2,3"), 'isset({save})'), - "sortorder"=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,65535), 'isset({save})'), - "yaxisside"=> array(T_ZBX_INT, O_OPT, NULL, IN("0,1"), 'isset({save})'), - "calc_fnc"=> array(T_ZBX_INT, O_OPT, NULL, IN("1,2,4,7"), 'isset({save})'), - "type"=> array(T_ZBX_INT, O_OPT, NULL, IN("0,1"), 'isset({save})'), - "periods_cnt"=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,360), 'isset({save})'), - - "register"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), - "save"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), - "delete"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), - "cancel"=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL), - "form"=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL), - "form_refresh"=> array(T_ZBX_INT, O_OPT, NULL, NULL, NULL) - ); - - check_fields($fields); -?> -<?php - show_table_header(S_CONFIGURATION_OF_GRAPH_BIG, - isset($_REQUEST['form']) ? null: new CButton("cancel",S_CANCEL,"return Redirect('graphs.php');")); -?> -<?php - - if(isset($_REQUEST["save"])) - { - if(isset($_REQUEST["gitemid"])) - { - $result=update_graph_item($_REQUEST["gitemid"],$_REQUEST["itemid"], - $_REQUEST["color"],$_REQUEST["drawtype"],$_REQUEST["sortorder"], - $_REQUEST["yaxisside"],$_REQUEST["calc_fnc"],$_REQUEST["type"],$_REQUEST["periods_cnt"]); - - $gitemid = $_REQUEST["gitemid"]; - $audit= AUDIT_ACTION_UPDATE; - $msg_ok = S_ITEM_UPDATED; - $msg_fail =S_CANNOT_UPDATE_ITEM; - $action = "Updated"; - } - else - { - $gitemid=add_item_to_graph($_REQUEST["graphid"],$_REQUEST["itemid"], - $_REQUEST["color"],$_REQUEST["drawtype"],$_REQUEST["sortorder"], - $_REQUEST["yaxisside"],$_REQUEST["calc_fnc"],$_REQUEST["type"],$_REQUEST["periods_cnt"]); - - $result = $gitemid; - $audit = AUDIT_ACTION_ADD; - $msg_ok = S_ITEM_ADDED; - $msg_fail = S_CANNOT_ADD_ITEM; - $action = "Added"; - } - if($result) - { - $graphitem = get_graphitem_by_gitemid($gitemid); - $graph = get_graph_by_graphid($graphitem["graphid"]); - $item = get_item_by_itemid($graphitem["itemid"]); - add_audit($audit, AUDIT_RESOURCE_GRAPH_ELEMENT, - "Graph ID [".$graphitem["graphid"]."] Name [".$graph["name"]."]". - " $action [".$item["description"]."]"); - show_messages($result, $msg_ok, $msg_fail); - unset($_REQUEST["form"]); - } - } - elseif(isset($_REQUEST["delete"])) - { - $graphitem=get_graphitem_by_gitemid($_REQUEST["gitemid"]); - $graph=get_graph_by_graphid($graphitem["graphid"]); - $item=get_item_by_itemid($graphitem["itemid"]); - - $result=delete_graph_item($_REQUEST["gitemid"]); - if($result) - { - add_audit(AUDIT_ACTION_DELETE,AUDIT_RESOURCE_GRAPH_ELEMENT, - "Graph ID [".$graphitem["graphid"]."] Name [".$graph["name"]."]". - " Deleted [".$item["description"]."]"); - } - show_messages($result, S_ITEM_DELETED, S_CANNOT_DELETE_ITEM); - unset($_REQUEST["gitemid"]); - } - elseif(isset($_REQUEST["register"])) - { - if($_REQUEST["register"]=="up") - { - $graphitem = get_graphitem_by_gitemid($gitemid); - $result = move_up_graph_item($_REQUEST["gitemid"]); - show_messages($result, S_SORT_ORDER_UPDATED, S_CANNOT_UPDATE_SORT_ORDER); - add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_GRAPH_ELEMENT, - "Graph ID [".$graphitem["graphid"]."] Name [".$graph["name"]."]". - " [".$item["description"]."] moved up."); - unset($_REQUEST["gitemid"]); - } - if($_REQUEST["register"]=="down") - { - $result = move_down_graph_item($_REQUEST["gitemid"]); - add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_GRAPH_ELEMENT, - "Graph ID [".$graphitem["graphid"]."] Name [".$graph["name"]."]". - " [".$item["description"]."] moved down."); - show_messages($result, S_SORT_ORDER_UPDATED, S_CANNOT_UPDATE_SORT_ORDER); - unset($_REQUEST["gitemid"]); - } - } -?> -<?php -/****** GRAPH ******/ - $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_MODE_LT); - - if(! ($db_graph = DBfetch(DBselect("select g.name from graphs g left join graphs_items gi on gi.graphid=g.graphid ". - " left join items i on gi.itemid=i.itemid". - " where g.graphid=".$_REQUEST["graphid"]. - " and ".DBid2nodeid("g.graphid")."=".$ZBX_CURNODEID. - " and ( i.hostid not in (".$denyed_hosts.") OR i.hostid is NULL )" - ) - ))) - { - access_deny(); - } - - show_table_header($db_graph["name"]); - - $table = new CTable(NULL,"graph"); - $table->AddRow(new CImg("chart2.php?graphid=".$_REQUEST["graphid"]."&period=3600&from=0")); - $table->Show(); - - if(isset($_REQUEST["form"])) - { -/****** FORM ******/ - echo BR; - insert_graphitem_form(); - } - else - { -/****** TABLE ******/ - $form = new CForm(); - $form->AddVar("graphid",$_REQUEST["graphid"]); - $form->AddItem(new CButton("form",S_ADD_ITEM)); - show_table_header(S_DISPLAYED_PARAMETERS_BIG,$form); - - $table = new CTableInfo("..."); - $table->SetHeader(array(S_SORT_ORDER,S_HOST,S_PARAMETER,S_FUNCTION,S_TYPE,S_DRAW_STYLE,S_COLOR,S_ACTIONS)); - - $result=DBselect("select i.itemid,h.host,i.description,gi.*,i.key_ ". - " from hosts h,graphs_items gi,items i where i.itemid=gi.itemid ". - " and gi.graphid=".$_REQUEST["graphid"]." and h.hostid=i.hostid ". - " order by gi.sortorder desc, i.description, i.itemid"); - while($row=DBfetch($result)) - { - - if($row["type"] == GRAPH_ITEM_AGGREGATED) - { - $type = S_AGGREGATED." (".$row["periods_cnt"].")"; - - $drawtype = "-"; - $fnc_name = "-"; - $color = "-"; - } - else - { - $type = S_SIMPLE; - - $drawtype = get_drawtype_description($row["drawtype"]); - $color = $row["color"]; - - switch($row["calc_fnc"]) - { - case CALC_FNC_ALL: $fnc_name = S_ALL_SMALL; break; - case CALC_FNC_MIN: $fnc_name = S_MIN_SMALL; break; - case CALC_FNC_MAX: $fnc_name = S_MAX_SMALL; break; - case CALC_FNC_AVG: - default: - $fnc_name = S_AVG_SMALL; break; - } - } - $table->AddRow(array( - $row["sortorder"], - $row["host"], - NEW CLink(item_description($row["description"],$row["key_"]), - 'chart.php?itemid='.$row["itemid"].'&period=3600&from=0', - 'action'), - $fnc_name, - $type, - $drawtype, - $color, - array( - new CLink(S_CHANGE,"graph.php?graphid=".$_REQUEST["graphid"]. - "&gitemid=".$row["gitemid"]."&form=update#form","action"), - SPACE."-".SPACE, - new CLink(S_UP,"graph.php?graphid=".$_REQUEST["graphid"]. - "&gitemid=".$row["gitemid"]."®ister=up","action"), - SPACE."-".SPACE, - new CLink(S_DOWN,"graph.php?graphid=".$_REQUEST["graphid"]. - "&gitemid=".$row["gitemid"]."®ister=down","action") - ) - )); - } - $table->Show(); - } -?> -<?php - -include_once "include/page_footer.php"; - -?> diff --git a/frontends/php/graphs.php b/frontends/php/graphs.php index 9cfac191..08ed9862 100644 --- a/frontends/php/graphs.php +++ b/frontends/php/graphs.php @@ -49,6 +49,13 @@ include_once "include/page_header.php"; "yaxismin"=> array(T_ZBX_DBL, O_OPT, NULL, BETWEEN(-65535,65535), 'isset({save})'), "yaxismax"=> array(T_ZBX_DBL, O_OPT, NULL, BETWEEN(-65535,65535), 'isset({save})'), "yaxismax"=> array(T_ZBX_DBL, O_OPT, NULL, BETWEEN(-65535,65535), 'isset({save})'), + + "items"=> array(T_ZBX_STR, O_OPT, NULL, null, null), + "new_graph_item"=> array(T_ZBX_STR, O_OPT, NULL, null, null), + "group_gid"=> array(T_ZBX_STR, O_OPT, NULL, null, null), + "move_up"=> array(T_ZBX_INT, O_OPT, NULL, null, null), + "move_down"=> array(T_ZBX_INT, O_OPT, NULL, null, null), + "showworkperiod"=> array(T_ZBX_INT, O_OPT, NULL, IN("1"), NULL), "showtriggers"=> array(T_ZBX_INT, O_OPT, NULL, IN("1"), NULL), @@ -56,6 +63,9 @@ include_once "include/page_header.php"; "copy_targetid"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID, NULL), "filter_groupid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({copy})&&{copy_type}==0'), /* actions */ + "add_item"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), + "delete_item"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), + "save"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), "copy"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), "delete"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), @@ -71,51 +81,63 @@ include_once "include/page_header.php"; validate_group_with_host(PERM_READ_WRITE,array("allow_all_hosts","always_select_first_host")); ?> <?php + $_REQUEST['items'] = get_request('items', array()); + $_REQUEST['group_gid'] = get_request('group_gid', array()); + $availiable_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, $ZBX_CURNODEID); $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, PERM_MODE_LT); if(isset($_REQUEST["save"])) { - $showworkperiod = 0; - if(isset($_REQUEST["showworkperiod"])) - $showworkperiod = 1; - $showtriggers = 0; - if(isset($_REQUEST["showtriggers"])) - $showtriggers = 1; - - if(isset($_REQUEST["graphid"])) + $items = get_request('items', array()); + foreach($items as $gitem) { - // TODO check permission by new value. - $result=update_graph($_REQUEST["graphid"], - $_REQUEST["name"],$_REQUEST["width"],$_REQUEST["height"], - $_REQUEST["yaxistype"],$_REQUEST["yaxismin"],$_REQUEST["yaxismax"], - $showworkperiod,$showtriggers,$_REQUEST["graphtype"]); - - if($result) + $host = DBfetch(DBselect('select h.* from hosts h,items i where h.hostid=i.hostid and i.itemid='.$gitem['itemid'])); + if(in_array($host['hostid'], explode(',',$denyed_hosts))) { - add_audit(AUDIT_ACTION_ADD,AUDIT_RESOURCE_GRAPH, - "Graph ID [".$_REQUEST["graphid"]."] Graph [". - $_REQUEST["name"]."]"); + access_deny(); } - show_messages($result, S_GRAPH_UPDATED, S_CANNOT_UPDATE_GRAPH); + } + if(count($items) <= 0) + { + info(S_REQUIRED_ITEMS_FOR_GRAPH); } else { - if(count(get_accessible_nodes_by_user($USER_DETAILS,PERM_READ_WRITE,PERM_MODE_LT,PERM_RES_IDS_ARRAY,$ZBX_CURNODEID))) - access_deny(); + $showworkperiod = isset($_REQUEST["showworkperiod"]) ? 1 : 0; + $showtriggers = isset($_REQUEST["showtriggers"]) ? 1 : 0; - $result=add_graph($_REQUEST["name"],$_REQUEST["width"],$_REQUEST["height"], - $_REQUEST["yaxistype"],$_REQUEST["yaxismin"],$_REQUEST["yaxismax"], - $showworkperiod,$showtriggers,$_REQUEST["graphtype"]); - if($result) + if(isset($_REQUEST["graphid"])) { - add_audit(AUDIT_ACTION_ADD,AUDIT_RESOURCE_GRAPH, - "Graph [".$_REQUEST["name"]."]"); + $result = update_graph_with_items($_REQUEST["graphid"], + $_REQUEST["name"],$_REQUEST["width"],$_REQUEST["height"], + $_REQUEST["yaxistype"],$_REQUEST["yaxismin"],$_REQUEST["yaxismax"], + $showworkperiod,$showtriggers,$_REQUEST["graphtype"],$items); + + if($result) + { + add_audit(AUDIT_ACTION_ADD,AUDIT_RESOURCE_GRAPH, + "Graph ID [".$_REQUEST["graphid"]."] Graph [". + $_REQUEST["name"]."]"); + } + show_messages($result, S_GRAPH_UPDATED, S_CANNOT_UPDATE_GRAPH); + } + else + { + $result = add_graph_with_items($_REQUEST["name"],$_REQUEST["width"],$_REQUEST["height"], + $_REQUEST["yaxistype"],$_REQUEST["yaxismin"],$_REQUEST["yaxismax"], + $showworkperiod,$showtriggers,$_REQUEST["graphtype"],$items); + + if($result) + { + add_audit(AUDIT_ACTION_ADD,AUDIT_RESOURCE_GRAPH, + "Graph [".$_REQUEST["name"]."]"); + } + show_messages($result, S_GRAPH_ADDED, S_CANNOT_ADD_GRAPH); + } + if($result){ + unset($_REQUEST["form"]); } - show_messages($result, S_GRAPH_ADDED, S_CANNOT_ADD_GRAPH); - } - if($result){ - unset($_REQUEST["form"]); } } elseif(isset($_REQUEST["delete"])&&isset($_REQUEST["graphid"])) @@ -177,6 +199,51 @@ include_once "include/page_header.php"; } show_messages(); } + elseif(isset($_REQUEST['delete_item']) && isset($_REQUEST['group_gid'])) + { + foreach($_REQUEST['items'] as $gid => $data) + { + if(!isset($_REQUEST['group_gid'][$gid])) continue; + unset($_REQUEST['items'][$gid]); + } + unset($_REQUEST['delete_item'], $_REQUEST['group_gid']); + } + elseif(isset($_REQUEST['new_graph_item'])) + { + $new_gitem = get_request('new_graph_item', array()); + foreach($_REQUEST['items'] as $gid => $data) + { + if( $new_gitem['itemid'] == $data['itemid'] && + $new_gitem['yaxisside'] == $data['yaxisside'] && + $new_gitem['calc_fnc'] == $data['calc_fnc'] && + $new_gitem['type'] == $data['type'] && + $new_gitem['periods_cnt'] == $data['periods_cnt']) + { + $already_exist = true; + break; + } + } + if(!isset($already_exist)) + { + array_push($_REQUEST['items'], $new_gitem); + } + } + elseif(isset($_REQUEST['move_up']) && isset($_REQUEST['items'])) + { + SDI($_REQUEST['items'][$_REQUEST['move_up']]['sortorder']); + if(isset($_REQUEST['items'][$_REQUEST['move_up']])) + if($_REQUEST['items'][$_REQUEST['move_up']]['sortorder'] > 0) + $_REQUEST['items'][$_REQUEST['move_up']]['sortorder'] + = ''.($_REQUEST['items'][$_REQUEST['move_up']]['sortorder'] - 1); + + SDI($_REQUEST['items'][$_REQUEST['move_up']]['sortorder']); + } + elseif(isset($_REQUEST['move_down']) && isset($_REQUEST['items'])) + { + if(isset($_REQUEST['items'][$_REQUEST['move_down']])) + if($_REQUEST['items'][$_REQUEST['move_down']]['sortorder'] < 1000) + $_REQUEST['items'][$_REQUEST['move_down']]['sortorder']++; + } ?> <?php $form = new CForm(); @@ -192,6 +259,13 @@ include_once "include/page_header.php"; else if(isset($_REQUEST["form"])) { insert_graph_form(); + echo BR; + $table = new CTable(NULL,"graph"); + $table->AddRow(new CImg('chart3.php?period=3600&from=0'.url_param('items'). + url_param('name').url_param('width').url_param('height').url_param('yaxistype'). + url_param('yaxismin').url_param('yaxismax').url_param('show_work_period'). + url_param('show_triggers').url_param('graphtype'))); + $table->Show(); } else { /* Table HEADER */ if(isset($_REQUEST["graphid"])&&($_REQUEST["graphid"]==0)) @@ -248,12 +322,12 @@ include_once "include/page_header.php"; $form->AddVar('hostid',$_REQUEST["hostid"]); $table = new CTableInfo(S_NO_GRAPHS_DEFINED); - $table->setHeader(array( + $table->SetHeader(array( $_REQUEST["hostid"] != 0 ? NULL : S_HOSTS, array( new CCheckBox("all_graphs",NULL, "CheckAll('".$form->GetName()."','all_graphs');"), S_NAME), - S_WIDTH,S_HEIGHT,S_GRAPH_TYPE,S_GRAPH)); + S_WIDTH,S_HEIGHT,S_GRAPH_TYPE)); if($_REQUEST["hostid"] > 0) { @@ -295,8 +369,6 @@ include_once "include/page_header.php"; $name = new CLink($row["name"], "graphs.php?graphid=".$row["graphid"]."&form=update". url_param("groupid").url_param("hostid"),'action'); - $edit = new CLink("Edit", - "graph.php?graphid=".$row["graphid"]); } else { $real_hosts = get_realhosts_by_graphid($row["templateid"]); $real_host = DBfetch($real_hosts); @@ -318,7 +390,6 @@ include_once "include/page_header.php"; expand_trigger_description($row["triggerid"]) ); } - $edit = SPACE; } $chkBox = new CCheckBox("group_graphid[]",NULL,NULL,$row["graphid"]); @@ -334,8 +405,7 @@ include_once "include/page_header.php"; array($chkBox, $name), $row["width"], $row["height"], - $graphtype, - $edit + $graphtype )); } 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; } diff --git a/frontends/php/popup.php b/frontends/php/popup.php index a0010271..59e397e8 100644 --- a/frontends/php/popup.php +++ b/frontends/php/popup.php @@ -110,7 +110,7 @@ include_once "include/page_header.php"; $srcfld1 = get_request("srcfld1", ''); // source table field [can be different from fields of source table] $srcfld2 = get_request("srcfld2", ''); // second source table field [can be different from fields of source table] - $monitored_hosts = get_request("monitored_hosts", ''); + $monitored_hosts = get_request("monitored_hosts", 0); $only_hostid = get_request("only_hostid", null); ?> <?php @@ -129,6 +129,10 @@ include_once "include/page_header.php"; ?> <?php $frmTitle = new CForm(); + + if($monitored_hosts) + $frmTitle->AddVar('monitored_hosts', 1); + $frmTitle->AddVar("dstfrm", $dstfrm); $frmTitle->AddVar("dstfld1", $dstfld1); $frmTitle->AddVar("dstfld2", $dstfld2); @@ -158,16 +162,18 @@ include_once "include/page_header.php"; validate_group(PERM_READ_LIST,$validation_param); } + $accessible_nodes = get_accessible_nodes_by_user($USER_DETAILS,PERM_READ_LIST); + $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_MODE_LT); + $accessible_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY); + $nodeid = $ZBX_CURNODEID; + if(isset($only_hostid)) { if(!isset($_REQUEST["hostid"]) || $_REQUEST["hostid"]!=$only_hostid) access_deny(); + $hostid = $only_hostid; } else { - $accessible_nodes = get_accessible_nodes_by_user($USER_DETAILS,PERM_READ_LIST); - $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_MODE_LT); - $accessible_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY); - if(in_array($srctbl,array("hosts","host_group","triggers","logitems","items"))) { if(ZBX_DISTRIBUTED) @@ -427,6 +433,10 @@ function add_template(formname,id,name) $table->SetFooter(new CButton('select',S_SELECT)); $form = new CForm(); $form->AddVar('existed_templates',$existed_templates); + + if($monitored_hosts) + $form->AddVar('monitored_hosts', 1); + $form->AddVar('dstfrm',$dstfrm); $form->AddVar('dstfld1',$dstfld1); $form->AddVar('srctbl',$srctbl); diff --git a/frontends/php/popup_gitem.php b/frontends/php/popup_gitem.php new file mode 100644 index 00000000..415a57df --- /dev/null +++ b/frontends/php/popup_gitem.php @@ -0,0 +1,186 @@ +<?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. +**/ +?> +<?php + require_once "include/config.inc.php"; + require_once "include/triggers.inc.php"; + require_once "include/forms.inc.php"; + + $dstfrm = get_request("dstfrm", 0); // destination form + + $page["title"] = "S_GRAPH_ITEM"; + $page["file"] = "popup_gitem.php"; + + define('ZBX_PAGE_NO_MENU', 1); + +include_once "include/page_header.php"; + + insert_confirm_javascript(); +?> +<?php +// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION + $fields=array( + "dstfrm"=> array(T_ZBX_STR, O_MAND,P_SYS, NOT_EMPTY, null), + + "gid"=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0,65535), null), + "list_name"=> array(T_ZBX_STR, O_OPT, P_SYS, NOT_EMPTY, 'isset({save})&&isset({gid})'), + "itemid"=> array(T_ZBX_INT, O_OPT, null, DB_ID.'({}!=0)', 'isset({save})'), + "color"=> array(T_ZBX_CLR, O_OPT, null, null, 'isset({save})'), + "drawtype"=> array(T_ZBX_INT, O_OPT, null, IN("0,1,2,3"), 'isset({save})'), + "sortorder"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(0,65535), 'isset({save})'), + "yaxisside"=> array(T_ZBX_INT, O_OPT, null, IN("0,1"), 'isset({save})'), + "calc_fnc"=> array(T_ZBX_INT, O_OPT, null, IN("1,2,4,7"), 'isset({save})'), + "type"=> array(T_ZBX_INT, O_OPT, null, IN("0,1"), 'isset({save})'), + "periods_cnt"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(0,360), 'isset({save})'), + "graphtype"=> array(T_ZBX_INT, O_OPT, null, IN("0,1"), 'isset({save})'), + + "only_hostid"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null), +/* actions */ + "add"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), + "save"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), +/* other */ + "form"=> array(T_ZBX_STR, O_OPT, P_SYS, null, null), + "form_refresh"=>array(T_ZBX_STR, O_OPT, null, null, null) + ); + + check_fields($fields); +?> +<script language="JavaScript" type="text/javascript"> +<!-- + +function add_var_to_opener_obj(obj,name,value) +{ + new_variable = window.opener.document.createElement('input'); + new_variable.type = 'hidden'; + new_variable.name = name; + new_variable.value = value; + + obj.appendChild(new_variable); +} + +function add_graph_item(formname,itemid,color,drawtype,sortorder,yaxisside,calc_fnc,type,periods_cnt) +{ + var form = window.opener.document.forms[formname]; + + if(!form) + { + window.close(); + return false; + } + + add_var_to_opener_obj(form,'new_graph_item[itemid]',itemid); + add_var_to_opener_obj(form,'new_graph_item[color]',color); + add_var_to_opener_obj(form,'new_graph_item[drawtype]',drawtype); + add_var_to_opener_obj(form,'new_graph_item[sortorder]',sortorder); + add_var_to_opener_obj(form,'new_graph_item[yaxisside]',yaxisside); + add_var_to_opener_obj(form,'new_graph_item[calc_fnc]',calc_fnc); + add_var_to_opener_obj(form,'new_graph_item[type]',type); + add_var_to_opener_obj(form,'new_graph_item[periods_cnt]',periods_cnt); + + form.submit(); + window.close(); + return true; +} + +function update_graph_item(formname,list_name,gid,itemid,color,drawtype,sortorder,yaxisside,calc_fnc,type,periods_cnt) +{ + var form = window.opener.document.forms[formname]; + + if(!form) + { + window.close(); + return false; + } + + add_var_to_opener_obj(form,list_name + '[' + gid + '][itemid]',itemid); + add_var_to_opener_obj(form,list_name + '[' + gid + '][color]',color); + add_var_to_opener_obj(form,list_name + '[' + gid + '][drawtype]',drawtype); + add_var_to_opener_obj(form,list_name + '[' + gid + '][sortorder]',sortorder); + add_var_to_opener_obj(form,list_name + '[' + gid + '][yaxisside]',yaxisside); + add_var_to_opener_obj(form,list_name + '[' + gid + '][calc_fnc]',calc_fnc); + add_var_to_opener_obj(form,list_name + '[' + gid + '][type]',type); + add_var_to_opener_obj(form,list_name + '[' + gid + '][periods_cnt]',periods_cnt); + + form.submit(); + window.close(); + return true; +} +--> +</script> +<?php + if(isset($_REQUEST['save']) && !isset($_REQUEST['gid'])) + { +?> +<script language="JavaScript" type="text/javascript"> +<!-- +<?php + echo "add_graph_item('". + $_REQUEST['dstfrm']."','". + $_REQUEST['itemid']."','". + $_REQUEST['color']."',". + $_REQUEST['drawtype'].",". + $_REQUEST['sortorder'].",". + $_REQUEST['yaxisside'].",". + $_REQUEST['calc_fnc'].",". + $_REQUEST['type'].",". + $_REQUEST['periods_cnt'].");\n"; +?> +--> +</script> +<?php + } + if(isset($_REQUEST['save']) && isset($_REQUEST['gid'])) + { +?> +<script language="JavaScript" type="text/javascript"> +<!-- +<?php + echo "update_graph_item('". + $_REQUEST['dstfrm']."','". + $_REQUEST['list_name']."','". + $_REQUEST['gid']."','". + $_REQUEST['itemid']."','". + $_REQUEST['color']."',". + $_REQUEST['drawtype'].",". + $_REQUEST['sortorder'].",". + $_REQUEST['yaxisside'].",". + $_REQUEST['calc_fnc'].",". + $_REQUEST['type'].",". + $_REQUEST['periods_cnt'].");\n"; +?> +--> +</script> +<?php + } + else + { +?> +<?php + echo BR; + + insert_graphitem_form(); + + } +?> +<?php + +include_once "include/page_footer.php"; + +?> |
