diff options
-rw-r--r-- | frontends/php/css.css | 11 | ||||
-rw-r--r-- | frontends/php/graph.php | 298 | ||||
-rw-r--r-- | frontends/php/include/forms.inc.php | 90 | ||||
-rw-r--r-- | frontends/php/include/locales/en_gb.inc.php | 1 |
4 files changed, 218 insertions, 182 deletions
diff --git a/frontends/php/css.css b/frontends/php/css.css index 2736bc17..f13f8af4 100644 --- a/frontends/php/css.css +++ b/frontends/php/css.css @@ -342,6 +342,14 @@ td.header_r width: 100%; } +/**************** GRAPH ****************/ + +table.graph +{ + width: 100%; + text-align: center; +} + /**************** PAGE HEADER ****************/ table.page_header { @@ -448,6 +456,7 @@ table.home img.top { vertical-align:text-top } img.bottom { vertical-align:text-bottom } +/**************** FORM ELEMENTS ****************/ .biginput { font-family: Verdana, Helvetica, Geneva; @@ -472,6 +481,8 @@ img.bottom { vertical-align:text-bottom } } .button:hover { text-decoration: underline; border-color: black; } +/**************** OTHERS ****************/ + ul { margin-left: 0px; diff --git a/frontends/php/graph.php b/frontends/php/graph.php index 079201c0..db97e9e4 100644 --- a/frontends/php/graph.php +++ b/frontends/php/graph.php @@ -20,12 +20,37 @@ ?> <?php include "include/config.inc.php"; + include "include/forms.inc.php"; + $page["title"] = "S_CONFIGURATION_OF_GRAPH"; $page["file"] = "graph.php"; show_header($page["title"],0,0); 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})'), + + "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); echo BR; ?> @@ -39,63 +64,71 @@ ?> <?php - if(isset($_REQUEST["register"])) + if(isset($_REQUEST["save"])) { - if($_REQUEST["register"]=="add") + if(isset($_REQUEST["gitemid"])) { - add_graph_item_to_templates($_REQUEST["graphid"],$_REQUEST["itemid"], + update_graph_item_from_templates($_REQUEST["gitemid"],$_REQUEST["itemid"], $_REQUEST["color"],$_REQUEST["drawtype"],$_REQUEST["sortorder"], $_REQUEST["yaxisside"]); - $gitemid=add_item_to_graph($_REQUEST["graphid"],$_REQUEST["itemid"], + $result=update_graph_item($_REQUEST["gitemid"],$_REQUEST["itemid"], $_REQUEST["color"],$_REQUEST["drawtype"],$_REQUEST["sortorder"], $_REQUEST["yaxisside"]); - if($gitemid) - { - $graph=get_graph_by_graphid($_REQUEST["graphid"]); - $item=get_item_by_itemid($_REQUEST["itemid"]); - add_audit(AUDIT_ACTION_ADD,AUDIT_RESOURCE_GRAPH_ELEMENT, - "Graph ID [".$_REQUEST["graphid"]."] Name [".$graph["name"]."]". - " Added [".$item["description"]."]"); - } - show_messages($gitemid,S_ITEM_ADDED, S_CANNOT_ADD_ITEM); + + $gitemid = $_REQUEST["gitemid"]; + $audit= AUDIT_ACTION_UPDATE; + $msg_ok = S_ITEM_UPDATED; + $msg_fail =S_CANNOT_UPDATE_ITEM; + $action = "Added"; } - if($_REQUEST["register"]=="update") + else { - update_graph_item_from_templates($_REQUEST["gitemid"],$_REQUEST["itemid"], + add_graph_item_to_templates($_REQUEST["graphid"],$_REQUEST["itemid"], $_REQUEST["color"],$_REQUEST["drawtype"],$_REQUEST["sortorder"], $_REQUEST["yaxisside"]); - $result=update_graph_item($_REQUEST["gitemid"],$_REQUEST["itemid"], + $gitemid=add_item_to_graph($_REQUEST["graphid"],$_REQUEST["itemid"], $_REQUEST["color"],$_REQUEST["drawtype"],$_REQUEST["sortorder"], $_REQUEST["yaxisside"]); - if($result) - { - $graphitem=get_graphitem_by_gitemid($_REQUEST["gitemid"]); - $graph=get_graph_by_graphid($graphitem["graphid"]); - $item=get_item_by_itemid($graphitem["itemid"]); - add_audit(AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_GRAPH_ELEMENT, - "Graph ID [".$graphitem["graphid"]."] Name [".$graph["name"]."]". - " Updated [".$item["description"]."]"); - } - show_messages($result, S_ITEM_UPDATED, S_CANNOT_UPDATE_ITEM); + + $result = $gitemid; + $audit = AUDIT_ACTION_ADD; + $msg_ok = S_ITEM_ADDED; + $msg_fail = S_CANNOT_ADD_ITEM; + $action = "Updated"; } - if($_REQUEST["register"]=="delete") + if($result) { - delete_graph_item_from_templates($_REQUEST["gitemid"]); - $graphitem=get_graphitem_by_gitemid($_REQUEST["gitemid"]); - $graph=get_graph_by_graphid($graphitem["graphid"]); - $item=get_item_by_itemid($graphitem["itemid"]); - $result=delete_graphs_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"]); + $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"]); + + delete_graph_item_from_templates($_REQUEST["gitemid"]); + $result=delete_graphs_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") { move_up_graph_item_from_templates($_REQUEST["gitemid"]); @@ -113,158 +146,59 @@ } ?> <?php +/****** GRAPH ******/ - $result=DBselect("select name from graphs where graphid=".$_REQUEST["graphid"]); - $row=DBfetch($result); - show_table_header($row["name"]); - echo "<TABLE BORDER=0 COLS=4 align=center WIDTH=100% BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; - echo "<TR BGCOLOR=#DDDDDD>"; - echo "<TD ALIGN=CENTER>"; - echo "<IMG SRC=\"chart2.php?graphid=".$_REQUEST["graphid"]."&period=3600&from=0\">"; - echo "</TD>"; - echo "</TR>"; - echo "</TABLE>"; + $db_graphs = DBselect("select name from graphs where graphid=".$_REQUEST["graphid"]); + $db_graph = DBfetch($db_graphs); + show_table_header($db_graph["name"]); - show_table_header(S_DISPLAYED_PARAMETERS_BIG); - echo "<TABLE BORDER=0 COLS=4 WIDTH=100% BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; - echo "<TD WIDTH=5% NOSAVE><B>".S_SORT_ORDER."</B></TD>"; - echo "<TD WIDTH=10% NOSAVE><B>".S_HOST."</B></TD>"; - echo "<TD WIDTH=10% NOSAVE><B>".S_PARAMETER."</B></TD>"; - echo "<TD WIDTH=10% NOSAVE><B>".S_TYPE."</B></TD>"; - echo "<TD WIDTH=10% NOSAVE><B>".S_COLOR."</B></TD>"; - echo "<TD WIDTH=10% NOSAVE><B>".S_ACTIONS."</B></TD>"; - echo "</TR>"; + $table = new CTable(NULL,"graph"); + $table->AddRow(new CImg("chart2.php?graphid=".$_REQUEST["graphid"]."&period=3600&from=0")); + $table->Show(); - $sql="select i.itemid,h.host,i.description,gi.gitemid,gi.color,gi.drawtype,gi.sortorder,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"; - $result=DBselect($sql); - $col=0; - while($row=DBfetch($result)) + if(isset($_REQUEST["form"])) { - if($col++%2==0) { echo "<TR BGCOLOR=#EEEEEE>"; } - else { echo "<TR BGCOLOR=#DDDDDD>"; } - - echo "<TD>".$row["sortorder"]."</TD>"; - echo "<TD>".$row["host"]."</TD>"; - echo "<TD><a href=\"chart.php?itemid=".$row["itemid"]."&period=3600&from=0\">".item_description($row["description"],$row["key_"])."</a></TD>"; - echo "<TD>".get_drawtype_description($row["drawtype"])."</TD>"; - echo "<TD>".$row["color"]."</TD>"; - echo "<TD>"; - echo "<A HREF=\"graph.php?graphid=".$_REQUEST["graphid"]."&gitemid=".$row["gitemid"]."#form\">".S_CHANGE."</A>"; - echo " - "; - echo "<A HREF=\"graph.php?graphid=".$_REQUEST["graphid"]."&gitemid=".$row["gitemid"]."®ister=up\">".S_UP."</A>"; - echo " - "; - echo "<A HREF=\"graph.php?graphid=".$_REQUEST["graphid"]."&gitemid=".$row["gitemid"]."®ister=down\">".S_DOWN."</A>"; - echo "</TD>"; - echo "</TR>"; - } - echo "</TABLE>"; -?> -<?php - echo "<br>"; - echo "<a name=\"form\"></a>"; - - if(isset($_REQUEST["gitemid"])) - { - $sql="select itemid,color,drawtype,sortorder,yaxisside from graphs_items". - " where gitemid=".$_REQUEST["gitemid"]; - $result=DBselect($sql); - $row=DBfetch($result); - $itemid=$row["itemid"]; - $color=$row["color"]; - $drawtype=$row["drawtype"]; - $sortorder=$row["sortorder"]; - $yaxisside=$row["yaxisside"]; +/****** FORM ******/ + echo BR; + insert_graphitem_form(); } else { - $sortorder=0; - $yaxisside=1; - } - - show_form_begin("graph.item"); - echo S_NEW_ITEM_FOR_THE_GRAPH; - - show_table2_v_delimiter(); - echo "<form method=\"get\" action=\"graph.php\">"; - echo "<input name=\"graphid\" type=\"hidden\" value=".$_REQUEST["graphid"].">"; - if(isset($_REQUEST["gitemid"])) - { - echo "<input name=\"gitemid\" type=\"hidden\" value=".$_REQUEST["gitemid"].">"; - } - - echo S_PARAMETER; - show_table2_h_delimiter(); - $result=DBselect("select h.host,i.description,i.itemid,i.key_ from hosts h,items i". - " where h.hostid=i.hostid and h.status in(".HOST_STATUS_MONITORED.",".HOST_STATUS_TEMPLATE.")". - " and i.status=".ITEM_STATUS_ACTIVE." order by h.host,i.description"); - echo "<select name=\"itemid\" size=1>"; - while($row=DBfetch($result)) - { - $host_=$row["host"]; - $description_=item_description($row["description"],$row["key_"]); - $itemid_=$row["itemid"]; - if(isset($itemid)&&($itemid==$itemid_)) +/****** 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_TYPE,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"); + while($row=DBfetch($result)) { - echo "<OPTION VALUE='$itemid_' SELECTED>$host_: $description_"; - } - else - { - echo "<OPTION VALUE='$itemid_'>$host_: $description_"; + $table->AddRow(array( + $row["sortorder"], + $row["host"], + NEW CLink(item_description($row["description"],$row["key_"], + "chart.php?itemid=".$row["itemid"]."&period=3600&from=0")), + get_drawtype_description($row["drawtype"]), + $row["color"], + array( + new CLink(S_CHANGE,"graph.php?graphid=".$_REQUEST["graphid"]. + "&gitemid=".$row["gitemid"]."&form=update#form"), + SPACE."-".SPACE, + new CLink(S_UP,"graph.php?graphid=".$_REQUEST["graphid"]. + "&gitemid=".$row["gitemid"]."®ister=up"), + SPACE."-".SPACE, + new CLink(S_DOWN,"graph.php?graphid=".$_REQUEST["graphid"]. + "&gitemid=".$row["gitemid"]."®ister=down") + ) + )); } + $table->Show(); } - echo "</SELECT>"; - - show_table2_v_delimiter(); - echo S_TYPE; - show_table2_h_delimiter(); - echo "<select name=\"drawtype\" size=1>"; - echo "<OPTION VALUE='0' ".iif(isset($drawtype)&&($drawtype==0),"SELECTED","").">".get_drawtype_description(0); - echo "<OPTION VALUE='1' ".iif(isset($drawtype)&&($drawtype==1),"SELECTED","").">".get_drawtype_description(1); - echo "<OPTION VALUE='2' ".iif(isset($drawtype)&&($drawtype==2),"SELECTED","").">".get_drawtype_description(2); - echo "<OPTION VALUE='3' ".iif(isset($drawtype)&&($drawtype==3),"SELECTED","").">".get_drawtype_description(3); - echo "</SELECT>"; - - show_table2_v_delimiter(); - echo S_YAXIS_SIDE; - show_table2_h_delimiter(); - echo "<SELECT class=\"biginput\" NAME=\"yaxisside\" size=\"1\"\">"; - echo "<OPTION VALUE=\"1\" "; if($yaxisside==GRAPH_YAXIS_SIDE_RIGHT) echo "SELECTED"; echo ">".S_RIGHT; - echo "<OPTION VALUE=\"0\" "; if($yaxisside==GRAPH_YAXIS_SIDE_LEFT) echo "SELECTED"; echo ">".S_LEFT; - echo "</SELECT>"; - - show_table2_v_delimiter(); - echo S_COLOR; - show_table2_h_delimiter(); - echo "<select name=\"color\" size=1>"; - echo "<OPTION VALUE='Black' ".iif(isset($color)&&($color=="Black"),"SELECTED","").">".S_BLACK; - echo "<OPTION VALUE='Blue' ".iif(isset($color)&&($color=="Blue"),"SELECTED","").">".S_BLUE; - echo "<OPTION VALUE='Cyan' ".iif(isset($color)&&($color=="Cyan"),"SELECTED","").">".S_CYAN; - echo "<OPTION VALUE='Dark Blue' ".iif(isset($color)&&($color=="Dark Blue"),"SELECTED","").">".S_DARK_BLUE; - echo "<OPTION VALUE='Dark Green' ".iif(isset($color)&&($color=="Dark Green"),"SELECTED","").">".S_DARK_GREEN; - echo "<OPTION VALUE='Dark Red' ".iif(isset($color)&&($color=="Dark Red"),"SELECTED","").">".S_DARK_RED; - echo "<OPTION VALUE='Dark Yellow' ".iif(isset($color)&&($color=="Dark Yellow"),"SELECTED","").">".S_DARK_YELLOW; - echo "<OPTION VALUE='Green' ".iif(isset($color)&&($color=="Green"),"SELECTED","").">".S_GREEN; - echo "<OPTION VALUE='Red' ".iif(isset($color)&&($color=="Red"),"SELECTED","").">".S_RED; - echo "<OPTION VALUE='White' ".iif(isset($color)&&($color=="White"),"SELECTED","").">".S_WHITE; - echo "<OPTION VALUE='Yellow' ".iif(isset($color)&&($color=="Yellow"),"SELECTED","").">".S_YELLOW; - echo "</SELECT>"; - - show_table2_v_delimiter(); - echo nbsp(S_SORT_ORDER_1_100); - show_table2_h_delimiter(); - echo "<input class=\"biginput\" name=\"sortorder\" value=\"$sortorder\" size=3>"; - - show_table2_v_delimiter2(); - echo "<input class=\"button\" type=\"submit\" name=\"register\" value=\"add\">"; - if(isset($itemid)) - { - echo "<input class=\"button\" type=\"submit\" name=\"register\" value=\"update\">"; - echo "<input class=\"button\" type=\"submit\" name=\"register\" value=\"delete\" onClick=\"return Confirm('Delete graph element?');\">"; - } - - show_table2_header_end(); ?> <?php show_page_footer(); diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php index fb45b06c..1ff57644 100644 --- a/frontends/php/include/forms.inc.php +++ b/frontends/php/include/forms.inc.php @@ -836,6 +836,96 @@ $frmGraph->Show(); } + + function insert_graphitem_form() + { + $frmGItem = new CFormTable(S_NEW_ITEM_FOR_THE_GRAPH,"graph.php"); + $frmGItem->SetHelp("web.graph.item.php"); + + if(isset($_REQUEST["gitemid"])) + { + $result=DBselect("select itemid,color,drawtype,sortorder,yaxisside 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"]; + } + else + { + $itemid = get_request("itemid", 0); + $color = get_request("color", 0); + $drawtype = get_request("drawtype", 0); + $sortorder = get_request("sortorder", 0); + $yaxisside = get_request("yaxisside", 1); + } + + + show_table2_v_delimiter(); + echo "<form method=\"get\" action=\"graph.php\">"; + $frmGItem->AddVar("graphid",$_REQUEST["graphid"]); + if(isset($_REQUEST["gitemid"])) + { + $frmGItem->AddVar("gitemid",$_REQUEST["gitemid"]); + } + + $cmbItems = new CComboBox("itemid", $itemid); + $result=DBselect("select h.host,i.description,i.itemid,i.key_ from hosts h,items i". + " where h.hostid=i.hostid". + " and h.status in(".HOST_STATUS_MONITORED.",".HOST_STATUS_TEMPLATE.")". + " and i.status=".ITEM_STATUS_ACTIVE." order by h.host,i.description"); + while($row=DBfetch($result)) + { + $cmbItems->AddItem($row["itemid"], + $row["host"].":".SPACE.item_description($row["description"],$row["key_"])); + } + $frmGItem->AddRow(S_PARAMETER, $cmbItems); + + $cmbType = new CComboBox("drawtype",$drawtype); + $cmbType->AddItem(0,get_drawtype_description(0)); + $cmbType->AddItem(1,get_drawtype_description(1)); + $cmbType->AddItem(2,get_drawtype_description(2)); + $cmbType->AddItem(3,get_drawtype_description(3)); + $frmGItem->AddRow(S_TYPE, $cmbType); + + $cmbYax = new CComboBox("yaxisside",$yaxisside); + $cmbYax->AddItem(GRAPH_YAXIS_SIDE_RIGHT, S_RIGHT); + $cmbYax->AddItem(GRAPH_YAXIS_SIDE_LEFT, S_LEFT); + $frmGItem->AddRow(S_YAXIS_SIDE, $cmbYax); + + $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_SORT_ORDER_1_100, new CTextBox("sortorder",$sortorder,3)); + + $frmGItem->AddItemToBottomRow(new CButton("save",S_SAVE)); + $frmGItem->AddItemToBottomRow(SPACE); + if(isset($itemid)) + { + $frmGItem->AddItemToBottomRow(new CButtonDelete("Delete graph element?", + url_param("gitemid").url_param("graphid"))); + $frmGItem->AddItemToBottomRow(SPACE); + } + $frmGItem->AddItemToBottomRow(new CButtonCancel(url_param("graphid"))); + $frmGItem->Show(); + } /* # Insert escalation form function insert_escalation_form($escalationid) diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php index a14b7729..fdf4efa9 100644 --- a/frontends/php/include/locales/en_gb.inc.php +++ b/frontends/php/include/locales/en_gb.inc.php @@ -451,6 +451,7 @@ "S_SELECT_HOST_DOT_DOT_DOT"=> "Select host...", "S_LOG_TIME_FORMAT"=> "Log time format", "S_CREATE_ITEM"=> "Create Item", + "S_ADD_ITEM"=> "Add Item", // events.php "S_LATEST_EVENTS"=> "Latest events", |