0) { foreach ($input_fields as $input_field) { /* save the data into the 'host_template_data' table */ $form_value = "value_" . $input_field["data_name"]; $form_value = $_POST[$form_value]; $form_is_templated_value = "t_value_" . $input_field["data_name"]; if (isset($_POST[$form_is_templated_value])) { if ((!empty($form_value)) || (!empty($_POST[$form_is_templated_value]))) { db_execute("insert into data_input_data (data_input_field_id,data_template_data_id,t_value,value) values (" . $input_field["id"] . ",$data_template_data_id,'" . $_POST[$form_is_templated_value] . "','$form_value')"); } } } } /* push out all "custom data" for this data source template */ push_out_data_template($data_template_id); } } if ((is_error_message()) || (empty($_POST["data_template_id"]))) { header ("Location: data_templates.php?action=template_edit&id=" . (empty($data_template_id) ? $_POST["data_template_id"] : $data_template_id)) . "&view_rrd=" . ($_POST["current_rrd"] ? $_POST["current_rrd"] : $data_template_rrd_id); }else{ header ("Location: data_templates.php"); } } } /* ---------------------------- template - Graph Templates ---------------------------- */ function template_remove() { if ((read_config_option("remove_verification") == "on") && (!isset($_GET["confirm"]))) { include ('include/top_header.php'); form_confirm("Are You Sure?", "Are you sure you want to delete the data template '" . db_fetch_cell("select name from data_template where id=" . $_GET["id"]) . "'? This is generally not a good idea if you have data sources attached to this template even though it should not affect any data sources.", getenv("HTTP_REFERER"), "data_templates.php?action=template_remove&id=" . $_GET["id"]); include ('include/bottom_footer.php'); exit; } if ((read_config_option("remove_verification") == "") || (isset($_GET["confirm"]))) { db_execute("delete from data_template_data_rra where data_template_data_id=" . db_fetch_cell("select id from data_template_data where data_template_id=" . $_GET["id"])); db_execute("delete from data_template_data where data_template_id=" . $_GET["id"] . " and local_graph_id=0"); db_execute("delete from data_template_rrd where data_template_id=" . $_GET["id"] . " and local_graph_id=0"); db_execute("delete from data_template where id=" . $_GET["id"]); /* "undo" any graph that is currently using this template */ db_execute("update data_template_data set local_data_template_data_id=0,data_template_id=0 where data_template_id=" . $_GET["id"]); db_execute("update data_template_rrd set local_data_template_rrd_id=0,data_template_id=0 where data_template_id=" . $_GET["id"]); } } function template_rrd_remove() { db_execute("delete from data_template_rrd where id=" . $_GET["id"]); header ("Location: data_templates.php?action=template_edit&id=" . $_GET["data_template_id"]); } function template_rrd_add() { db_execute("insert into data_template_rrd (data_template_id,rrd_maximum,rrd_minimum,rrd_heartbeat,data_source_type_id, data_source_name) values (" . $_GET["id"] . ",100,0,600,1,'ds')"); $data_template_rrd_id = db_fetch_insert_id(); header ("Location: data_templates.php?action=template_edit&id=" . $_GET["id"] . "&view_rrd=$data_template_rrd_id"); } function template_edit() { global $colors, $struct_data_source, $struct_data_source_item, $data_source_types; if (!empty($_GET["id"])) { $template_data = db_fetch_row("select * from data_template_data where data_template_id=" . $_GET["id"] . " and local_data_id=0"); $template = db_fetch_row("select * from data_template where id=" . $_GET["id"]); $header_label = "[edit: " . $template["name"] . "]"; }else{ $header_label = "[new]"; } start_box("Data Template $header_label", "98%", $colors["header"], "3", "center", ""); ?>
Name
The name given to this data template. Data Source", "98%", $colors["header"], "3", "center", ""); /* make sure 'data source path' doesn't show up for a template... we should NEVER template this field */ unset($struct_data_source["data_source_path"]); $i = 0; while (list($field_name, $field_array) = each($struct_data_source)) { form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++; print "" . $field_array["title"] . "
\n"; form_base_checkbox("t_" . $field_name,(isset($template_data{"t_" . $field_name}) ? $template_data{"t_" . $field_name} : ""),"Use Per-Graph Value (Ignore this Value)","",(isset($template_data) ? $template_data["data_template_id"] : "0"),false); print "\n"; if ($field_array["type"] == "custom") { $array_rra = array_rekey(db_fetch_assoc("select id,name from rra order by name"), "id", "name"); form_multi_dropdown("rra_id",$array_rra,db_fetch_assoc("select * from data_template_data_rra where data_template_data_id=" . (isset($template_data) ? $template_data["id"] : "0")), "rra_id"); }else{ draw_nontemplated_item($field_array, $field_name, (isset($template_data) ? $template_data[$field_name] : "")); } print "\n"; } end_box(); /* fetch ALL rrd's for this data source */ if (!empty($_GET["id"])) { $template_data_rrds = db_fetch_assoc("select id,data_source_name from data_template_rrd where data_template_id=" . $_GET["id"] . " and local_data_id=0 order by data_source_name"); } /* select the first "rrd" of this data source by default */ if (empty($_GET["view_rrd"])) { $_GET["view_rrd"] = (isset($template_data_rrds[0]["id"]) ? $template_data_rrds[0]["id"] : "0"); } /* get more information about the rrd we chose */ if (!empty($_GET["view_rrd"])) { $template_rrd = db_fetch_row("select * from data_template_rrd where id=" . $_GET["view_rrd"]); } start_box("", "98%", $colors["header"], "3", "center", ""); print " Data Source Item [" . (isset($template_rrd) ? $template_rrd["data_source_name"] : "") . "] " . (!empty($_GET["id"]) ? "New " : "") . " \n"; $i = 0; if (isset($template_data_rrds)) { if (sizeof($template_data_rrds) > 1) { ?>
&view_rrd="> &data_template_id=">Delete
"1")) { unset($struct_data_source_item["data_input_field_id"]); }else{ $struct_data_source_item["data_input_field_id"]["sql"] = "select id,CONCAT(data_name,' - ',name) as name from data_input_fields where data_input_id=" . $template_data["data_input_id"] . " and input_output='out' and update_rra='on' order by data_name,name"; } $i = 1; while (list($field_name, $field_array) = each($struct_data_source_item)) { form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++; print "" . $field_array["title"] . "
\n"; form_base_checkbox("t_" . $field_name,(isset($template_rrd) ? $template_rrd{"t_" . $field_name} : ""),"Use Per-Graph Value (Ignore this Value)","",(isset($template_data) ? $template_data["data_template_id"] : "0"),false); print "\n"; draw_nontemplated_item($field_array, $field_name, (isset($template_rrd) ? $template_rrd[$field_name] : "")); print "\n"; } end_box(); $i = 0; if (!empty($_GET["id"])) { /* get each INPUT field for this data input source */ $fields = db_fetch_assoc("select * from data_input_fields where data_input_id=" . $template_data["data_input_id"] . " and input_output='in' order by name"); start_box("Custom Data [data input: " . db_fetch_cell("select name from data_input where id=" . $template_data["data_input_id"]) . "]", "98%", $colors["header"], "3", "center", ""); /* loop through each field found */ if (sizeof($fields) > 0) { foreach ($fields as $field) { $data_input_data = db_fetch_row("select t_value,value from data_input_data where data_template_data_id=" . $template_data["id"] . " and data_input_field_id=" . $field["id"]); if (sizeof($data_input_data) > 0) { $old_value = $data_input_data["value"]; }else{ $old_value = ""; } form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); ?>
No Input Fields for the Selected Data Input Source"; } end_box(); } form_hidden_id("data_template_id",(isset($template_data) ? $template_data["data_template_id"] : "0")); form_hidden_id("data_template_data_id",(isset($template_data) ? $template_data["id"] : "0")); form_hidden_id("data_template_rrd_id",(isset($template_rrd) ? $template_rrd["id"] : "0")); form_hidden_id("current_rrd",(isset($_GET["view_rrd"]) ? $_GET["view_rrd"] : "0")); form_hidden_box("save_component_template","1",""); form_save_button("data_templates.php"); } function template() { global $colors; start_box("Data Template Management", "98%", $colors["header"], "3", "center", "data_templates.php?action=template_edit"); print ""; DrawMatrixHeaderItem("Template Title",$colors["header_text"],2); print ""; $template_list = db_fetch_assoc("select data_template.id, data_template.name from data_template order by data_template.name"); $i = 0; if (sizeof($template_list) > 0) { foreach ($template_list as $template) { form_alternate_row_color($colors["alternate"],$colors["light"],$i); ?> "> ">Delete