"Delete", 2 => "Change Data Template", 3 => "Change Host", 4 => "Duplicate" ); /* set default action */ if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; } switch ($_REQUEST["action"]) { case 'save': form_save(); break; case 'actions': form_actions(); break; case 'rrd_add': ds_rrd_add(); break; case 'rrd_remove': ds_rrd_remove(); break; case 'data_edit': include_once ("include/top_header.php"); data_edit(); include_once ("include/bottom_footer.php"); break; case 'ds_remove': ds_remove(); header ("Location: data_sources.php"); break; case 'ds_edit': include_once ("include/top_header.php"); ds_edit(); include_once ("include/bottom_footer.php"); break; default: include_once ("include/top_header.php"); ds(); include_once ("include/bottom_footer.php"); break; } /* -------------------------- The Save Function -------------------------- */ function form_save() { include_once ("include/utility_functions.php"); if (isset($_POST["save_component_data_source"])) { $save1["id"] = $_POST["local_data_id"]; $save1["data_template_id"] = $_POST["data_template_id"]; $save1["host_id"] = $_POST["host_id"]; $save2["id"] = $_POST["data_template_data_id"]; $save2["local_data_template_data_id"] = $_POST["local_data_template_data_id"]; $save2["data_template_id"] = $_POST["data_template_id"]; $save2["data_input_id"] = form_input_validate($_POST["data_input_id"], "data_input_id", "", true, 3); $save2["name"] = form_input_validate($_POST["name"], "name", "", false, 3); $save2["data_source_path"] = form_input_validate($_POST["data_source_path"], "data_source_path", "", true, 3); $save2["active"] = form_input_validate((isset($_POST["active"]) ? $_POST["active"] : ""), "active", "", true, 3); $save2["rrd_step"] = form_input_validate($_POST["rrd_step"], "rrd_step", "^[0-9]+$", false, 3); /* if this is a new data source and a template has been selected, skip item creation this time otherwise it throws off the templatate creation because of the NULL data */ if ($_POST["data_template_id"] == $_POST["_data_template_id"]) { $save3["id"] = $_POST["data_template_rrd_id"]; $save3["local_data_template_rrd_id"] = $_POST["local_data_template_rrd_id"]; $save3["data_template_id"] = $_POST["data_template_id"]; $save3["rrd_maximum"] = form_input_validate($_POST["rrd_maximum"], "rrd_maximum", "^[0-9]+$", false, 3); $save3["rrd_minimum"] = form_input_validate($_POST["rrd_minimum"], "rrd_minimum", "^[0-9]+$", false, 3); $save3["rrd_heartbeat"] = form_input_validate($_POST["rrd_heartbeat"], "rrd_heartbeat", "^[0-9]+$", false, 3); $save3["data_source_type_id"] = $_POST["data_source_type_id"]; $save3["data_source_name"] = form_input_validate($_POST["data_source_name"], "data_source_name", "^[a-zA-Z0-9_]{1,19}$", false, 3); $save3["data_input_field_id"] = form_input_validate((isset($_POST["data_input_field_id"]) ? $_POST["data_input_field_id"] : "0"), "data_input_field_id", "", true, 3); } if (!is_error_message()) { $local_data_id = sql_save($save1, "data_local"); } if (!is_error_message()) { $save2["local_data_id"] = $local_data_id; $data_template_data_id = sql_save($save2, "data_template_data"); if ($data_template_data_id) { raise_message(1); }else{ raise_message(2); } } /* if this is a new data source and a template has been selected, skip item creation this time otherwise it throws off the templatate creation because of the NULL data */ if ($_POST["data_template_id"] == $_POST["_data_template_id"]) { if (!is_error_message()) { $save3["local_data_id"] = $local_data_id; $data_template_rrd_id = sql_save($save3, "data_template_rrd"); if ($data_template_rrd_id) { raise_message(1); }else{ raise_message(2); } } } if (!is_error_message()) { if ($_POST["host_id"] != $_POST["_host_id"]) { /* push out all nessesary host information */ push_out_host($_POST["host_id"], $local_data_id); /* reset current host for display purposes */ $_SESSION["sess_data_source_current_host_id"] = $_POST["host_id"]; } if ($_POST["data_template_id"] != $_POST["_data_template_id"]) { /* update all nessesary template information */ change_data_template($local_data_id, $_POST["data_template_id"]); } /* if no data source path has been entered, generate one */ if (empty($_POST["data_source_path"])) { generate_data_source_path($local_data_id); } update_poller_cache($local_data_id); /* save entried in 'selected rras' field */ db_execute("delete from data_template_data_rra where data_template_data_id=$data_template_data_id"); for ($i=0; ($i < count($_POST["rra_id"])); $i++) { db_execute("insert into data_template_data_rra (rra_id,data_template_data_id) values (" . $_POST["rra_id"][$i] . ",$data_template_data_id)"); } } } if ((isset($_POST["save_component_data"])) && (!is_error_message())) { /* ok, first pull out all 'input' values so we know how much to save */ $input_fields = db_fetch_assoc("select data_template_data.data_input_id, data_local.host_id data_input_fields.id, data_input_fields.input_output, data_input_fields.data_name, data_input_fields.regexp_match, data_input_fields.allow_nulls, data_input_fields.type_code from data_template_data left join data_input_fields on data_input_fields.data_input_id=data_template_data.data_input_id left join data_local on data_template_data.local_data_id=data_local.id where data_template_data.id=" . $_POST["data_template_data_id"] . " and data_input_fields.input_output='in'"); if (sizeof($input_fields) > 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&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; ?>