0 && !DBfetch($graph_items)) { return delete_graph($graph["graphid"]); } } return $result; } function move_up_graph_item($gitemid) { if($gitemid<=0) return; $gitem = get_graphitem_by_gitemid($gitemid); $graph = get_graph_by_gitemid($gitemid); $childs = get_graphs_by_templateid($graph["graphid"]); while($child = DBfetch($childs)) { $chd_gitems = get_graphitems_by_graphid($child["graphid"]); while($chd_gitem = DBfetch($chd_gitems)) { if(cmp_graphitems($gitem, $chd_gitem)) continue; // recursion $result = move_up_graph_item($chd_gitem["gitemid"]); if(!$result) return $reslut; break; } } $result = DBexecute("update graphs_items set sortorder=sortorder-1". " where sortorder>0 and gitemid=$gitemid"); if($result) { $item = get_item_by_itemid($gitem["itemid"]); info("Sort order updated for item '".$item["description"]."'". " in graph '".$graph["name"]."'"); } return $result; } function move_down_graph_item($gitemid) { if($gitemid<=0) return; $gitem = get_graphitem_by_gitemid($gitemid); $graph = get_graph_by_gitemid($gitemid); $childs = get_graphs_by_templateid($graph["graphid"]); while($child = DBfetch($childs)) { $chd_gitems = get_graphitems_by_graphid($child["graphid"]); while($chd_gitem = DBfetch($chd_gitems)) { if(cmp_graphitems($gitem, $chd_gitem)) continue; // recursion $result = move_down_graph_item($chd_gitem["gitemid"]); if(!$result) return $reslut; break; } } $result = DBexecute("update graphs_items set sortorder=sortorder+1". " where sortorder<100 and gitemid=$gitemid"); if($result) { $item = get_item_by_itemid($gitem["itemid"]); info("Sort order updated for item '".$item["description"]."'". " in graph '".$graph["name"]."'"); } return $result; } function delete_template_graphs($hostid, $templateid = null /* array format 'arr[id]=name' */, $unlink_mode = false) { $db_graphs = get_graphs_by_hostid($hostid); while($db_graph = DBfetch($db_graphs)) { if($db_graph["templateid"] == 0) continue; if($templateid != null) { $tmp_graph = get_graph_by_graphid($db_graph["templateid"]); if(is_array($templateid)) { if(!isset($templateid[$tmp_graph["hostid"]])) continue; } elseif($tmp_graph["hostid"] != $templateid) continue; } if($unlink_mode) { if(DBexecute("update graphs set templateid=0 where graphid=".$db_graph["graphid"])) { info("Graph '".$db_graph["name"]."' unlinked"); } } else { delete_graph($db_graph["graphid"]); } } } function copy_template_graphs($hostid, $templateid = null /* array format 'arr[id]=name' */, $copy_mode = false) { if($templateid == null) { $templateid = get_templates_by_hostid($hostid); } if(is_array($templateid)) { foreach($templateid as $id => $name) copy_template_graphs($hostid, $id, $copy_mode); // attention recursion return; } $db_graphs = get_graphs_by_hostid($templateid); while($db_graph = DBfetch($db_graphs)) { copy_graph_to_host($db_graph["graphid"], $hostid, $copy_mode); } } function copy_graph_to_host($graphid, $hostid, $copy_mode = false) { $db_graph = get_graph_by_graphid($graphid); $new_graphid = add_graph($db_graph["name"],$db_graph["width"],$db_graph["height"],$db_graph["yaxistype"], $db_graph["yaxismin"],$db_graph["yaxismax"],$db_graph["show_work_period"],$db_graph["show_triggers"], $db_graph["graphtype"],$copy_mode ? 0 : $graphid ); if(!$new_graphid) return $new_graphid; $result = copy_graphitems_for_host($graphid, $new_graphid, $hostid); if(!$result) { delete_graph($new_graphid); } return $result; } function copy_graphitems_for_host($src_graphid,$dist_graphid,$hostid) { $src_graphitems=get_graphitems_by_graphid($src_graphid); while($src_graphitem=DBfetch($src_graphitems)) { $src_item=get_item_by_itemid($src_graphitem["itemid"]); $host_items=get_items_by_hostid($hostid); $item_exist=0; while($host_item=DBfetch($host_items)) { if($src_item["key_"]!=$host_item["key_"]) continue; $item_exist=1; $host_itemid=$host_item["itemid"]; $result = add_item_to_graph($dist_graphid,$host_itemid,$src_graphitem["color"], $src_graphitem["drawtype"],$src_graphitem["sortorder"], $src_graphitem["yaxisside"],$src_graphitem["calc_fnc"], $src_graphitem["type"],$src_graphitem["periods_cnt"]); if(!$result) return $result; break; } if($item_exist==0) return FALSE; } return TRUE; } function navigation_bar_calc() { // $workingperiod = 3600; if(!isset($_REQUEST["period"])) $_REQUEST["period"]=3600; if(!isset($_REQUEST["from"])) $_REQUEST["from"]=0; if(!isset($_REQUEST["stime"])) $_REQUEST["stime"]=null; // if(isset($_REQUEST["inc"])) $workingperiod= $_REQUEST["period"]+$_REQUEST["inc"]; // if(isset($_REQUEST["dec"])) $workingperiod= $workingperiod-$_REQUEST["dec"]; if(isset($_REQUEST["inc"])) $_REQUEST["period"] += $_REQUEST["inc"]; if(isset($_REQUEST["dec"])) $_REQUEST["period"] -= $_REQUEST["dec"]; if(isset($_REQUEST["left"])) $_REQUEST["from"] += $_REQUEST["left"]; if(isset($_REQUEST["right"])) $_REQUEST["from"] -= $_REQUEST["right"]; //unset($_REQUEST["inc"]); //unset($_REQUEST["dec"]); unset($_REQUEST["left"]); unset($_REQUEST["right"]); if($_REQUEST["from"] <= 0) $_REQUEST["from"] = 0; if($_REQUEST["period"] <= 3600) $_REQUEST["period"] = 3600; if(isset($_REQUEST["reset"])) { $_REQUEST["period"] = 3600; $_REQUEST["from"] = 0; // $workingperiod = 3600; } return $_REQUEST["period"]; // return $workingperiod; } function navigation_bar($url,$ext_saved_request=NULL) { $saved_request = array("graphid","screenid","itemid","action","from","fullscreen"); if(is_array($ext_saved_request)) $saved_request = array_merge($saved_request, $ext_saved_request); elseif(is_string($ext_saved_request)) array_push($saved_request,$ext_saved_request); $form = new CForm($url); $form->AddItem(S_PERIOD.SPACE); $period = get_request('period', 3600); if(in_array($period,array(3600,2*3600,4*3600,8*3600,12*3600,24*3600,7*24*3600,31*24*3600,365*24*3600))) $custom_per = 3*3600; else $custom_per = $period; $cmbPeriod = new CComboBox("period",$period,"submit()"); $cmbPeriod->AddItem($custom_per,"custom"); $cmbPeriod->AddItem(3600,"1h"); $cmbPeriod->AddItem(2*3600,"2h"); $cmbPeriod->AddItem(4*3600,"4h"); $cmbPeriod->AddItem(8*3600,"8h"); $cmbPeriod->AddItem(12*3600,"12h"); $cmbPeriod->AddItem(24*3600,"24h"); $cmbPeriod->AddItem(7*24*3600,"week"); $cmbPeriod->AddItem(31*24*3600,"month"); $cmbPeriod->AddItem(365*24*3600,"year"); $form->AddItem($cmbPeriod); $cmbDec = new CComboBox("dec",0,"submit()"); $cmbDec->AddItem(0,S_DECREASE); $cmbDec->AddItem(3600,"-1h"); $cmbDec->AddItem(4*3600,"-4h"); $cmbDec->AddItem(24*3600,"-24h"); $cmbDec->AddItem(7*24*3600,"-week"); $cmbDec->AddItem(31*24*3600,"-month"); $cmbDec->AddItem(365*24*3600,"-year"); $form->AddItem($cmbDec); $cmbInc = new CComboBox("inc",0,"submit()"); $cmbInc->AddItem(0,S_INCREASE); $cmbInc->AddItem(3600,"+1h"); $cmbInc->AddItem(4*3600,"+4h"); $cmbInc->AddItem(24*3600,"+24h"); $cmbInc->AddItem(7*24*3600,"+week"); $cmbInc->AddItem(31*24*3600,"+month"); $cmbInc->AddItem(365*24*3600,"+year"); $form->AddItem($cmbInc); $form->AddItem(SPACE.S_MOVE.SPACE); $cmbLeft = new CComboBox("left",0,"submit()"); $cmbLeft->AddItem(0,S_LEFT_DIR); $cmbLeft->AddItem(1,"-1h"); $cmbLeft->AddItem(4,"-4h"); $cmbLeft->AddItem(24,"-24h"); $cmbLeft->AddItem(7*24,"-week"); $cmbLeft->AddItem(31*24,"-month"); $cmbLeft->AddItem(365*24,"-year"); $form->AddItem($cmbLeft); $cmbRight = new CComboBox("right",0,"submit()"); $cmbRight->AddItem(0,S_RIGHT_DIR); $cmbRight->AddItem(1,"+1h"); $cmbRight->AddItem(4,"+4h"); $cmbRight->AddItem(24,"+24h"); $cmbRight->AddItem(7*24,"+week"); $cmbRight->AddItem(31*24,"+month"); $cmbRight->AddItem(365*24,"+year"); $form->AddItem($cmbRight); $form->AddItem(array(SPACE, new CTextBox("stime","yyyymmddhhmm",12),SPACE, new CButton("action","go"), new CButton("reset","reset"))); foreach($saved_request as $item) if(isset($_REQUEST[$item])) $form->AddVar($item,$_REQUEST[$item]); show_table_header( S_NAVIGATE, $form); return; } ?>