0) { $selected_graphs["cg"]{$_POST["cg_g"]}{$_POST["cg_g"]} = true; } }elseif (preg_match('/^sg_\d+_\S+$/', $var)) { $snmp_query_id = preg_replace('/^sg_(\d+)_(\S+)$/', "\\1", $var); $snmp_query_graph_id = $_POST{"sgg_" . $snmp_query_id}; $snmp_index = preg_replace('/^sg_(\d+)_(\S+)$/', "\\2", $var); $selected_graphs["sg"][$snmp_query_id][$snmp_query_graph_id][$snmp_index] = true; } } if (isset($selected_graphs)) { host_new_graphs($_POST["host_id"], $_POST["host_template_id"], $selected_graphs); exit; } header("Location: graphs_new.php?host_id=" . $_POST["host_id"]); } if (isset($_POST["save_component_new_graphs"])) { host_new_graphs_save(); header("Location: graphs_new.php?host_id=" . $_POST["host_id"]); } } /* --------------------- Misc Functions --------------------- */ function draw_edit_form_row($field_array, $field_name, $previous_value) { $field_array["value"] = $previous_value; draw_edit_form( array( "config" => array( "no_form_tag" => true, "force_row_color" => "F5F5F5" ), "fields" => array( $field_name => $field_array ) ) ); } /* ------------------- Data Query Functions ------------------- */ function host_reload_query() { data_query($_GET["host_id"], $_GET["id"]); } /* ------------------- New Graph Functions ------------------- */ function host_new_graphs_save() { global $struct_graph, $struct_data_source, $struct_graph_item, $struct_data_source_item, $paths; $selected_graphs_array = unserialize(stripslashes($_POST["selected_graphs_array"])); /* form an array that contains all of the data on the previous form */ while (list($var, $val) = each($_POST)) { if (preg_match("/^g_(\d+)_(\d+)_([^_]+)_(\w+)/", $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: (opt) snmp index, 4: field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values["cg"]{$matches[2]}["graph_template"]{$matches[4]} = $val; }else{ /* this is a data query field */ $values["sg"]{$matches[1]}{$matches[2]}["graph_template"]{$matches[4]} = $val; } }elseif (preg_match("/^gi_(\d+)_(\d+)_(\d+)_(\w+)/", $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: graph_template_input_id, 4:field_name */ /* we need to find out which graph items will be affected by saving this particular item */ $item_list = db_fetch_assoc("select graph_template_item_id from graph_template_input_defs where graph_template_input_id=" . $matches[3]); /* loop through each item affected and update column data */ if (sizeof($item_list) > 0) { foreach ($item_list as $item) { if (empty($matches[1])) { /* this is a new graph from template field */ $values["cg"]{$matches[2]}["graph_template_item"]{$item["graph_template_item_id"]}{$matches[4]} = $val; }else{ /* this is a data query field */ $values["sg"]{$matches[1]}{$matches[2]}["graph_template_item"]{$item["graph_template_item_id"]}{$matches[4]} = $val; } } } }elseif (preg_match("/^d_(\d+)_(\d+)_(\d+)_([^_]+)_(\w+)/", $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4: (opt) snmp_index, 5:field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values["cg"]{$matches[3]}["data_template"]{$matches[5]} = $val; }else{ /* this is a data query field */ $values["sg"]{$matches[1]}{$matches[2]}["data_template"]{$matches[5]} = $val; } }elseif (preg_match("/^di_(\d+)_(\d+)_(\d+)_(\d+)_(\w+)/", $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:local_data_template_rrd_id, 5:field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values["cg"]{$matches[2]}["data_template_item"]{$matches[4]}{$matches[5]} = $val; }else{ /* this is a data query field */ $values["sg"]{$matches[1]}{$matches[2]}["data_template_item"]{$matches[4]}{$matches[5]} = $val; } } } while (list($form_type, $form_array) = each($selected_graphs_array)) { $current_form_type = $form_type; while (list($form_id1, $form_array2) = each($form_array)) { /* enumerate information from the arrays stored in post variables */ if ($form_type == "cg") { $graph_template_id = $form_id1; }elseif ($form_type == "sg") { while (list($form_id2, $form_array3) = each($form_array2)) { $snmp_index_array = $form_array3; $snmp_query_array["snmp_query_id"] = $form_id1; $snmp_query_array["snmp_index_on"] = $_POST{"sg_" . $form_id1}; $snmp_query_array["snmp_query_graph_id"] = $form_id2; } $graph_template_id = db_fetch_cell("select graph_template_id from snmp_query_graph where id=" . $snmp_query_array["snmp_query_graph_id"]); } if ($current_form_type == "cg") { $return_array = create_complete_graph_from_template($graph_template_id, $_POST["host_id"], "", $values["cg"]); }elseif ($current_form_type == "sg") { while (list($snmp_index, $true) = each($snmp_index_array)) { $snmp_query_array["snmp_index"] = $snmp_index; $return_array = create_complete_graph_from_template($graph_template_id, $_POST["host_id"], $snmp_query_array, $values["sg"]{$snmp_query_array["snmp_query_id"]}); } } } } /* lastly push host-specific information to our data sources */ push_out_host($_POST["host_id"],0); } function host_new_graphs($host_id, $host_template_id, $selected_graphs_array) { include_once("./include/top_header.php"); global $colors, $paths, $struct_graph, $row_counter, $struct_data_source, $struct_graph_item, $struct_data_source_item; print "