0) { foreach ($input_fields as $input_field) { /* save the data into the 'data_input_data' table */ $form_name = "value_" . $input_field["data_name"]; $form_value = $_POST[$form_name]; if (isset($_POST[$form_name])) { if ($input_field["allow_nulls"] == "on") { $allow_nulls = true; }elseif (empty($input_field["allow_nulls"])) { $allow_nulls = false; } /* run regexp match on input string */ $form_value = form_input_validate($form_value, $form_name, $input_field["regexp_match"], $allow_nulls, 3); /* make sure we don't overwrite 'host fields' */ if ((!is_error_message()) && ((empty($input_field["host_id"]) || (empty($input_field["type_code"]))))) { db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,t_value,value) values (" . $input_field["id"] . "," . $_POST["data_template_data_id"] . ",'" . db_fetch_cell("select t_value from data_input_data where data_input_field_id=" . $input_field["id"] . " and data_template_data_id=" . $_POST["data_template_data_id"]) . "','$form_value')"); } } } } if ((read_config_option("full_view_data_source") == "") && (is_error_message())) { /* ds data edit page */ } } if ((is_error_message()) || ($_POST["data_template_id"] != $_POST["_data_template_id"]) || ($_POST["host_id"] != $_POST["_host_id"])) { header ("Location: data_sources.php?action=ds_edit&local_data_id=" . (empty($local_data_id) ? $_POST["local_data_id"] : $local_data_id) . "&host_id=" . $_POST["host_id"] . "&view_rrd=" . (isset($_POST["view_rrd"]) ? $_POST["view_rrd"] : "0")); }else{ header ("Location: data_sources.php"); } } /* -------------------------- Global Form Functions -------------------------- */ function draw_data_form_select($main_action) { global $colors; ?> ">
 Go
Data Sources $header_label", "98%", $colors["header"], "3", "center", ""); draw_data_form_select("?action=data_edit&local_data_id=" . $_GET["local_data_id"]); end_box(); } print "
\n"; $i = 0; if (!empty($data["data_input_id"])) { /* get each INPUT field for this data input source */ $fields = db_fetch_assoc("select * from data_input_fields where data_input_id=" . $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=" . $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 * from data_input_data where data_template_data_id=" . $data["id"] . " and data_input_field_id=" . $field["id"]); if (sizeof($data_input_data) > 0) { $old_value = $data_input_data["value"]; }else{ $old_value = ""; } /* if data template then get t_value from template, else always allow user input */ if (empty($data["data_template_id"])) { $can_template = "on"; }else{ $can_template = db_fetch_cell("select t_value from data_input_data where data_template_data_id=" . $template_data["id"] . " and data_input_field_id=" . $field["id"]); } form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); if ((!empty($host["id"])) && (eregi('^(hostname|management_ip|snmp_community|snmp_username|snmp_password|snmp_version)$', $field["type_code"]))) { print "" . $field["name"] . " (From Host: " . $host["hostname"] . ")\n"; print "$old_value\n"; }elseif (empty($can_template)) { print "" . $field["name"] . " (From Data Template)\n"; print "" . (empty($old_value) ? "Nothing Entered" : $old_value) . "\n"; }else{ print "" . $field["name"] . "\n"; form_text_box("value_" . $field["data_name"],$old_value,"",""); } print "\n"; $i++; } }else{ print "No Input Fields for the Selected Data Input Source"; } end_box(); } form_hidden_id("local_data_id",(isset($data) ? $data["local_data_id"] : "0")); form_hidden_id("data_template_data_id",(isset($data) ? $data["id"] : "0")); form_hidden_box("save_component_data","1",""); if (read_config_option("full_view_data_source") == "") { form_save_button("data_sources.php"); } } /* ------------------------ Data Source Functions ------------------------ */ function ds_remove() { global $config; if ((read_config_option("remove_verification") == "on") && (!isset($_GET["confirm"]))) { include ('include/top_header.php'); print "
"; start_box("Are You Sure?", "60%", "B61D22", "3", "center", ""); form_area("Are you sure you want to delete the data source '" . db_fetch_cell("select name from data_template_data where local_data_id=" . $_GET["local_data_id"]) . "'?"); /* find out what (if any) graphs are using this data source, so we can complain to the user */ $graphs = db_fetch_assoc("select graph_templates_graph.title from data_template_rrd left join graph_templates_item on graph_templates_item.task_item_id=data_template_rrd.id left join graph_templates_graph on graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id where data_template_rrd.local_data_id=" . $_GET["local_data_id"] . " and graph_templates_item.local_graph_id>0 and graph_templates_graph.local_graph_id>0 group by graph_templates_graph.title order by graph_templates_graph.title"); if (sizeof($graphs) > 0) { print "

The following graphs are using this data source:

\n"; foreach ($graphs as $graph) { print "" . $graph["title"] . "
\n"; } print "
"; form_base_radio_button("delete_type", "1", "1", "Leave the graphs untouched.", "1", true); form_base_radio_button("delete_type", "1", "2", "Delete all graph items that reference to this data source.", "1", true); print ""; } form_confirm_buttons("data_sources.php?action=ds_remove&local_data_id=" . $_GET["local_data_id"], "data_sources.php"); end_box(); include ('include/bottom_footer.php'); exit; } if ((read_config_option("remove_verification") == "") || ($_GET["confirm"] == "yes")) { db_execute("delete from data_template_data_rra where data_template_data_id=" . db_fetch_cell("select id from data_template_data where local_data_id=" . $_GET["local_data_id"])); db_execute("delete from data_template_data where local_data_id=" . $_GET["local_data_id"]); db_execute("delete from data_template_rrd where local_data_id=" . $_GET["local_data_id"]); db_execute("delete from data_input_data_cache where local_data_id=" . $_GET["local_data_id"]); db_execute("delete from data_local where id=" . $_GET["local_data_id"]); } } function ds_edit() { include_once ("include/rrd_functions.php"); global $colors, $struct_data_source, $struct_data_source_item, $data_source_types; $use_data_template = true; $host_id = 0; if (!empty($_GET["local_data_id"])) { $local_data_template_data_id = db_fetch_cell("select local_data_template_data_id from data_template_data where local_data_id=" . $_GET["local_data_id"]); $data = db_fetch_row("select * from data_template_data where local_data_id=" . $_GET["local_data_id"]); $data_template = db_fetch_row("select * from data_template_data where id=$local_data_template_data_id"); $host_id = db_fetch_cell("select host_id from data_local where id=" . $_GET["local_data_id"]); $data_template_name = db_fetch_cell("select name from data_template where id=" . $data["data_template_id"]); $header_label = "[edit: " . $data["name"] . "]"; if ($data["data_template_id"] == "0") { $use_data_template = false; } }else{ $header_label = "[new]"; $use_data_template = false; } if (read_config_option("full_view_data_source") == "") { start_box("Data Sources $header_label", "98%", $colors["header"], "3", "center", ""); draw_data_form_select("?action=ds_edit&local_data_id=" . $_GET["local_data_id"]); end_box(); } //start_box("", "98%", "aaaaaa", "3", "center", ""); //print "
";
	//print rrdtool_function_create($_GET["local_data_id"], true);
	//print "
"; //end_box(); start_box("Data Templation Selection $header_label", "98%", $colors["header"], "3", "center", ""); print "\n"; form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],0); ?> Selected Data Template
The name given to this data template. Host
Choose the host that this data source belongs to. Data Source", "98%", $colors["header"], "3", "center", ""); $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"; if (($use_data_template == false) || (!empty($data_template{"t_" . $field_name})) || ($field_array["flags"] == "NOTEMPLATE")) { print $field_array["description"]; } 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($data) ? $data["id"] : "0")), "rra_id"); }else{ if (($use_data_template == false) || (!empty($data_template{"t_" . $field_name})) || ($field_array["flags"] == "NOTEMPLATE")) { draw_nontemplated_item($field_array, $field_name, (isset($data) ? $data[$field_name] : "")); }else{ draw_templated_item($field_array, $field_name, (isset($data) ? $data[$field_name] : "")); } } print "\n"; } end_box(); /* fetch ALL rrd's for this data source */ if (!empty($_GET["local_data_id"])) { $template_data_rrds = db_fetch_assoc("select id,data_source_name from data_template_rrd where local_data_id=" . $_GET["local_data_id"] . " 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"])) { $local_data_template_rrd_id = db_fetch_cell("select local_data_template_rrd_id from data_template_rrd where id=" . $_GET["view_rrd"]); $rrd = db_fetch_row("select * from data_template_rrd where id=" . $_GET["view_rrd"]); $rrd_template = db_fetch_row("select * from data_template_rrd where id=$local_data_template_rrd_id"); } start_box("Data Source Item [edit: " . (isset($rrd) ? $rrd["data_source_name"] : "") . "]", "98%", $colors["header"], "3", "center", ""); $i = 0; if (isset($template_data_rrds)) { if (sizeof($template_data_rrds) > 1) { ?>
&view_rrd=">
"; $i = 0; 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"; if (($use_data_template == false) || ($rrd_template{"t_" . $field_name} == "on")) { print $field_array["description"]; } print "\n"; if (($use_data_template == false) || ($rrd_template{"t_" . $field_name} == "on")) { draw_nontemplated_item($field_array, $field_name, (isset($rrd) ? $rrd[$field_name] : "")); }else{ draw_templated_item($field_array, $field_name, (isset($rrd) ? $rrd[$field_name] : "")); } print "\n"; } end_box(); if (read_config_option("full_view_data_source") == "on") { data_edit(); } form_hidden_id("_data_template_id",(isset($data) ? $data["data_template_id"] : "0")); form_hidden_box("_host_id",$host_id,(isset($_GET["host_id"]) ? $_GET["host_id"] : "0")); form_hidden_id("data_template_data_id",(isset($data) ? $data["id"] : "0")); form_hidden_id("data_template_rrd_id",(isset($rrd) ? $rrd["id"] : "0")); form_hidden_id("local_data_template_data_id",(isset($data) ? $data["local_data_template_data_id"] : "0")); form_hidden_id("local_data_template_rrd_id",(isset($rrd) ? $rrd["local_data_template_rrd_id"] : "0")); form_hidden_id("local_data_id",(isset($data) ? $data["local_data_id"] : "0")); form_hidden_id("current_rrd",$_GET["view_rrd"]); form_hidden_box("save_component_data_source","1",""); form_save_button("data_sources.php"); } function ds() { global $colors; include_once ('include/tree_view_functions.php'); /* if no host_id is specified, use the session one */ if (!isset($_GET["host_id"])) { $_GET["host_id"] = (empty($_SESSION["sess_data_source_current_host_id"]) ? 0 : $_SESSION["sess_data_source_current_host_id"]); } /* remember the last used host_id */ $_SESSION["sess_data_source_current_host_id"] = $_GET["host_id"]; start_box("Data Sources", "98%", $colors["header"], "3", "center", "data_sources.php?action=ds_edit"); ?> ">
Select a host:   Go
Data Sources [host: " . (empty($host["hostname"]) ? "No Host" : $host["hostname"]) . "]", "98%", $colors["header"], "3", "center", "data_sources.php?action=ds_edit&host_id=" . $_GET["host_id"]); print " Name Data Input Method Template Name \n"; $data_sources = db_fetch_assoc("select data_template_data.local_data_id, data_template_data.name, data_input.name as data_input_name, data_template.name as data_template_name from data_local left join data_template_data on data_local.id=data_template_data.local_data_id left join data_input on data_input.id=data_template_data.data_input_id left join data_template on data_local.data_template_id=data_template.id where data_local.host_id=" . $_GET["host_id"] . " order by data_template_data.name"); $i = 0; if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++; print "" . $data_source["name"] . ""; print "" . $data_source["data_input_name"] . ""; print "" . ((empty($data_source["data_template_name"])) ? "None" : $data_source["data_template_name"]) . ""; print "Delete "; print ""; } }else{ print "No Data Sources"; } end_box(); } ?>