示例#1
0
function form_save()
{
    global $registered_cacti_names;
    if (isset($_POST['save_component_data_input'])) {
        /* ================= input validation ================= */
        input_validate_input_number(get_request_var_post('id'));
        /* ==================================================== */
        $save['id'] = $_POST['id'];
        $save['hash'] = get_hash_data_input($_POST['id']);
        $save['name'] = form_input_validate($_POST['name'], 'name', '', false, 3);
        $save['input_string'] = form_input_validate($_POST['input_string'], 'input_string', '', true, 3);
        $save['type_id'] = form_input_validate($_POST['type_id'], 'type_id', '', true, 3);
        if (!is_error_message()) {
            $data_input_id = sql_save($save, 'data_input');
            if ($data_input_id) {
                raise_message(1);
                /* get a list of each field so we can note their sequence of occurance in the database */
                if (!empty($_POST['id'])) {
                    db_execute_prepared('UPDATE data_input_fields SET sequence = 0 WHERE data_input_id = ?', array(get_request_var_post('id')));
                    generate_data_input_field_sequences($_POST['input_string'], $_POST['id']);
                }
                push_out_data_input_method($data_input_id);
            } else {
                raise_message(2);
            }
        }
        header('Location: data_input.php?action=edit&id=' . (empty($data_input_id) ? $_POST['id'] : $data_input_id));
    } elseif (isset($_POST['save_component_field'])) {
        /* ================= input validation ================= */
        input_validate_input_number(get_request_var_post('id'));
        input_validate_input_number(get_request_var_post('data_input_id'));
        input_validate_input_regex(get_request_var_post('input_output'), '^(in|out)$');
        /* ==================================================== */
        $save['id'] = $_POST['id'];
        $save['hash'] = get_hash_data_input($_POST['id'], 'data_input_field');
        $save['data_input_id'] = $_POST['data_input_id'];
        $save['name'] = form_input_validate($_POST['name'], 'name', '', false, 3);
        $save['data_name'] = form_input_validate($_POST['data_name'], 'data_name', '', false, 3);
        $save['input_output'] = $_POST['input_output'];
        $save['update_rra'] = form_input_validate(isset($_POST['update_rra']) ? $_POST['update_rra'] : '', 'update_rra', '', true, 3);
        $save['sequence'] = $_POST['sequence'];
        $save['type_code'] = form_input_validate(isset($_POST['type_code']) ? $_POST['type_code'] : '', 'type_code', '', true, 3);
        $save['regexp_match'] = form_input_validate(isset($_POST['regexp_match']) ? $_POST['regexp_match'] : '', 'regexp_match', '', true, 3);
        $save['allow_nulls'] = form_input_validate(isset($_POST['allow_nulls']) ? $_POST['allow_nulls'] : '', 'allow_nulls', '', true, 3);
        if (!is_error_message()) {
            $data_input_field_id = sql_save($save, 'data_input_fields');
            if ($data_input_field_id) {
                raise_message(1);
                if (!empty($data_input_field_id) && $_POST['input_output'] == 'in') {
                    generate_data_input_field_sequences(db_fetch_cell_prepared('SELECT input_string FROM data_input WHERE id = ?', array(get_request_var_post('data_input_id'))), get_request_var_post('data_input_id'));
                }
            } else {
                raise_message(2);
            }
        }
        if (is_error_message()) {
            header('Location: data_input.php?action=field_edit&data_input_id=' . $_POST['data_input_id'] . '&id=' . (empty($data_input_field_id) ? $_POST['id'] : $data_input_field_id) . (!empty($_POST['input_output']) ? '&type=' . $_POST['input_output'] : ''));
        } else {
            header('Location: data_input.php?action=edit&id=' . $_POST['data_input_id']);
        }
    }
}
示例#2
0
function &xml_to_data_input_method($hash, &$xml_array, &$hash_cache)
{
    global $fields_data_input_edit, $fields_data_input_field_edit, $fields_data_input_field_edit_1;
    /* aggregate field arrays */
    $fields_data_input_field_edit += $fields_data_input_field_edit_1;
    /* import into: data_input */
    $_data_input_id = db_fetch_cell("select id from data_input where hash='{$hash}'");
    $save["id"] = empty($_data_input_id) ? "0" : $_data_input_id;
    $save["hash"] = $hash;
    reset($fields_data_input_edit);
    while (list($field_name, $field_array) = each($fields_data_input_edit)) {
        /* make sure this field exists in the xml array first */
        if (isset($xml_array[$field_name])) {
            /* fix issue with data input method importing and white spaces */
            if ($field_name == "input_string") {
                $xml_array[$field_name] = str_replace("><", "> <", $xml_array[$field_name]);
            }
            $save[$field_name] = addslashes(xml_character_decode($xml_array[$field_name]));
        }
    }
    $data_input_id = sql_save($save, "data_input");
    $hash_cache["data_input_method"][$hash] = $data_input_id;
    /* import into: data_input_fields */
    if (is_array($xml_array["fields"])) {
        while (list($item_hash, $item_array) = each($xml_array["fields"])) {
            /* parse information from the hash */
            $parsed_hash = parse_xml_hash($item_hash);
            /* invalid/wrong hash */
            if ($parsed_hash == false) {
                return false;
            }
            unset($save);
            $_data_input_field_id = db_fetch_cell("select id from data_input_fields where hash='" . $parsed_hash["hash"] . "' and data_input_id={$data_input_id}");
            $save["id"] = empty($_data_input_field_id) ? "0" : $_data_input_field_id;
            $save["hash"] = $parsed_hash["hash"];
            $save["data_input_id"] = $data_input_id;
            reset($fields_data_input_field_edit);
            while (list($field_name, $field_array) = each($fields_data_input_field_edit)) {
                /* make sure this field exists in the xml array first */
                if (isset($item_array[$field_name])) {
                    $save[$field_name] = addslashes(xml_character_decode($item_array[$field_name]));
                }
            }
            $data_input_field_id = sql_save($save, "data_input_fields");
            $hash_cache["data_input_field"][$parsed_hash["hash"]] = $data_input_field_id;
        }
    }
    /* update field use counter cache if possible */
    if (isset($xml_array["input_string"]) && !empty($data_input_id)) {
        generate_data_input_field_sequences($xml_array["input_string"], $data_input_id);
    }
    /* status information that will be presented to the user */
    $_SESSION["import_debug_info"]["type"] = empty($_data_input_id) ? "new" : "update";
    $_SESSION["import_debug_info"]["title"] = $xml_array["name"];
    $_SESSION["import_debug_info"]["result"] = empty($data_input_id) ? "fail" : "success";
    return $hash_cache;
}
示例#3
0
function form_save()
{
    global $registered_cacti_names;
    if (isset($_POST["save_component_data_input"])) {
        /* ================= input validation ================= */
        input_validate_input_number(get_request_var_post("id"));
        /* ==================================================== */
        $save["id"] = $_POST["id"];
        $save["hash"] = get_hash_data_input($_POST["id"]);
        $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
        $save["input_string"] = form_input_validate($_POST["input_string"], "input_string", "", true, 3);
        $save["type_id"] = form_input_validate($_POST["type_id"], "type_id", "", true, 3);
        if (!is_error_message()) {
            $data_input_id = sql_save($save, "data_input");
            if ($data_input_id) {
                raise_message(1);
                /* get a list of each field so we can note their sequence of occurance in the database */
                if (!empty($_POST["id"])) {
                    db_execute("update data_input_fields set sequence=0 where data_input_id=" . $_POST["id"]);
                    generate_data_input_field_sequences($_POST["input_string"], $_POST["id"]);
                }
                push_out_data_input_method($data_input_id);
            } else {
                raise_message(2);
            }
        }
        if (is_error_message() || empty($_POST["id"])) {
            header("Location: data_input.php?action=edit&id=" . (empty($data_input_id) ? $_POST["id"] : $data_input_id));
        } else {
            header("Location: data_input.php");
        }
    } elseif (isset($_POST["save_component_field"])) {
        /* ================= input validation ================= */
        input_validate_input_number(get_request_var_post("id"));
        input_validate_input_number(get_request_var_post("data_input_id"));
        input_validate_input_regex(get_request_var_post("input_output"), "^(in|out)\$");
        /* ==================================================== */
        $save["id"] = $_POST["id"];
        $save["hash"] = get_hash_data_input($_POST["id"], "data_input_field");
        $save["data_input_id"] = $_POST["data_input_id"];
        $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
        $save["data_name"] = form_input_validate($_POST["data_name"], "data_name", "", false, 3);
        $save["input_output"] = $_POST["input_output"];
        $save["update_rra"] = form_input_validate(isset($_POST["update_rra"]) ? $_POST["update_rra"] : "", "update_rra", "", true, 3);
        $save["sequence"] = $_POST["sequence"];
        $save["type_code"] = form_input_validate(isset($_POST["type_code"]) ? $_POST["type_code"] : "", "type_code", "", true, 3);
        $save["regexp_match"] = form_input_validate(isset($_POST["regexp_match"]) ? $_POST["regexp_match"] : "", "regexp_match", "", true, 3);
        $save["allow_nulls"] = form_input_validate(isset($_POST["allow_nulls"]) ? $_POST["allow_nulls"] : "", "allow_nulls", "", true, 3);
        if (!is_error_message()) {
            $data_input_field_id = sql_save($save, "data_input_fields");
            if ($data_input_field_id) {
                raise_message(1);
                if (!empty($data_input_field_id) && $_POST["input_output"] == "in") {
                    generate_data_input_field_sequences(db_fetch_cell("select input_string from data_input where id=" . $_POST["data_input_id"]), $_POST["data_input_id"]);
                }
            } else {
                raise_message(2);
            }
        }
        if (is_error_message()) {
            header("Location: data_input.php?action=field_edit&data_input_id=" . $_POST["data_input_id"] . "&id=" . (empty($data_input_field_id) ? $_POST["id"] : $data_input_field_id) . (!empty($_POST["input_output"]) ? "&type=" . $_POST["input_output"] : ""));
        } else {
            header("Location: data_input.php?action=edit&id=" . $_POST["data_input_id"]);
        }
    }
}