function field_edit() { global $colors, $registered_cacti_names; require_once(CACTI_BASE_PATH . "/lib/data_input/data_input_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("data_input_id")); input_validate_input_regex(get_request_var("type"), "/^(in|out)$/"); /* ==================================================== */ if (!empty($_GET["id"])) { $field = db_fetch_row("select * from data_input_fields where id=" . $_GET["id"]); } if (!empty($_GET["type"])) { $current_field_type = $_GET["type"]; }else{ $current_field_type = $field["input_output"]; } if ($current_field_type == "out") { $header_name = "Output"; }elseif ($current_field_type == "in") { $header_name = "Input"; } $data_input = db_fetch_row("select type_id,name from data_input where id=" . $_GET["data_input_id"]); /* obtain a list of available fields for this given field type (input/output) */ if (($current_field_type == "in") && (preg_match_all("/<([_a-zA-Z0-9]+)>/", db_fetch_cell("select input_string from data_input where id=" . (get_request_var("data_input_id") ? get_request_var("data_input_id") : $field["data_input_id"])), $matches))) { for ($i=0; ($i < count($matches[1])); $i++) { if (in_array($matches[1][$i], $registered_cacti_names) == false) { $current_field_name = $matches[1][$i]; $array_field_names[$current_field_name] = $current_field_name; } } } /* if there are no input fields to choose from, complain */ if ((!isset($array_field_names)) && (isset($_GET["type"]) ? $_GET["type"] == "in" : false) && ($data_input["type_id"] == "1")) { display_custom_error_message(__("This script appears to have no input values, therefore there is nothing to add.")); return; } html_start_box("<strong>$header_name " . __("Fields") . "</strong> " . __("[edit: ") . $data_input["name"] . "]", "100", $colors["header"], "3", "center", ""); $form_array = array(); /* field name */ if ((($data_input["type_id"] == "1") || ($data_input["type_id"] == "5")) && ($current_field_type == "in")) { /* script */ $form_array = inject_form_variables(data_input_field1_form_list(), $header_name, $array_field_names, (isset($field) ? $field : array())); }elseif (($data_input["type_id"] == "2") || ($data_input["type_id"] == "3") || ($data_input["type_id"] == "4") || ($data_input["type_id"] == "6") || ($data_input["type_id"] == "7") || ($data_input["type_id"] == "8") || ($current_field_type == "out")) { /* snmp */ $form_array = inject_form_variables(data_input_field2_form_list(), $header_name, (isset($field) ? $field : array())); } $fields_data_input_field_edit = data_input_field_form_list(); /* ONLY if the field is an input */ if ($current_field_type == "in") { unset($fields_data_input_field_edit["update_rra"]); }elseif ($current_field_type == "out") { unset($fields_data_input_field_edit["regexp_match"]); unset($fields_data_input_field_edit["allow_nulls"]); unset($fields_data_input_field_edit["type_code"]); } draw_edit_form(array( "config" => array(), "fields" => $form_array + inject_form_variables($fields_data_input_field_edit, (isset($field) ? $field : array()), $current_field_type, $_GET) )); html_end_box(); form_save_button_alt("path!data_input.php|action!edit|id!" . get_request_var("data_input_id")); }
function data_input_method_to_xml($data_input_id) { require_once(CACTI_BASE_PATH . "/lib/data_input/data_input_info.php"); /* aggregate field arrays */ $fields_data_input_field_edit = data_input_field_form_list() + data_input_field1_form_list(); $hash["data_input_method"] = get_hash_version("data_input_method") . get_hash_data_input($data_input_id); $xml_text = ""; $data_input = db_fetch_row("select * from data_input where id=$data_input_id"); $data_input_fields = db_fetch_assoc("select * from data_input_fields where data_input_id=$data_input_id"); if (empty($data_input["id"])) { $err_msg = "Invalid data input method."; return $err_msg; } $xml_text .= "<hash_" . $hash["data_input_method"] . ">\n"; /* XML Branch: <> */ $fields_data_input_edit = data_input_form_list(); reset($fields_data_input_edit); while (list($field_name, $field_array) = each($fields_data_input_edit)) { if (($field_array["method"] != "hidden_zero") && ($field_array["method"] != "hidden") && ($field_array["method"] != "spacer")) { $xml_text .= "\t<$field_name>" . xml_character_encode($data_input{$field_name}) . "</$field_name>\n"; } } /* XML Branch: <fields> */ $xml_text .= "\t<fields>\n"; if (sizeof($data_input_fields) > 0) { foreach ($data_input_fields as $item) { $hash["data_input_field"] = get_hash_version("data_input_field") . get_hash_data_input($item["id"], "data_input_field"); $xml_text .= "\t\t<hash_" . $hash["data_input_field"] . ">\n"; reset($fields_data_input_field_edit); while (list($field_name, $field_array) = each($fields_data_input_field_edit)) { if (($field_name == "input_output") && (!empty($item{$field_name}))) { $xml_text .= "\t\t\t<$field_name>" . xml_character_encode($item{$field_name}) . "</$field_name>\n"; }else{ if (($field_array["method"] != "hidden_zero") && ($field_array["method"] != "hidden") && ($field_array["method"] != "spacer")) { $xml_text .= "\t\t\t<$field_name>" . xml_character_encode($item{$field_name}) . "</$field_name>\n"; } } } $xml_text .= "\t\t</hash_" . $hash["data_input_field"] . ">\n"; } } $xml_text .= "\t</fields>\n"; $xml_text .= "</hash_" . $hash["data_input_method"] . ">"; return $xml_text; }