function form_save() { if (isset($_POST["save_data_query_x"])) { /* cache all post field values */ init_post_field_cache(); /* step #2: field validation */ $form_data_query["id"] = $_POST["data_query_id"]; $form_data_query["input_type"] = $_POST["input_type"]; $form_data_query["name"] = $_POST["name"]; $form_data_query["index_order_type"] = $_POST["index_order_type"]; $form_data_query["index_title_format"] = $_POST["index_title_format"]; /* these fields are only displayed when editing a data query field */ if (!empty($_POST["data_query_id"])) { $form_data_query["index_order"] = $_POST["index_order"]; $form_data_query["index_field_id"] = $_POST["index_field_id"]; } if ($form_data_query["input_type"] == DATA_QUERY_INPUT_TYPE_SNMP_QUERY) { $form_data_query["snmp_oid_num_rows"] = $_POST["snmp_oid_num_rows"]; } if ($form_data_query["input_type"] == DATA_QUERY_INPUT_TYPE_SCRIPT_QUERY || $form_data_query["input_type"] == DATA_QUERY_INPUT_TYPE_PHP_SCRIPT_SERVER_QUERY) { $form_data_query["script_path"] = $_POST["script_path"]; } if ($form_data_query["input_type"] == DATA_QUERY_INPUT_TYPE_PHP_SCRIPT_SERVER_QUERY) { $form_data_query["script_server_function"] = $_POST["script_server_function"]; } field_register_error(validate_data_query_fields($form_data_query, "|field|")); /* step #3: field save */ $data_query_id = false; if (is_error_message()) { log_save("User input validation error for data query [ID#" . $_POST["data_query_id"] . "]", SEV_DEBUG); } else { $data_query_id = api_data_query_save($_POST["data_query_id"], $form_data_query); if ($data_query_id === false) { log_save("Save error for data query [ID#" . $_POST["data_query_id"] . "]", SEV_ERROR); } } if ($data_query_id === false) { header("Location: data_queries.php?action=edit" . (empty($_POST["data_query_id"]) ? "" : "&id=" . $_POST["data_query_id"])); } else { if (empty($_POST["data_query_id"])) { header("Location: data_queries.php?action=edit&id={$data_query_id}"); } else { header("Location: data_queries.php"); } } } else { if (isset($_POST["save_data_query_field_x"])) { /* cache all post field values */ init_post_field_cache(); /* step #2: field validation */ $form_data_query["id"] = $_POST["data_query_field_id"]; $form_data_query["data_query_id"] = $_POST["data_query_id"]; $form_data_query["type"] = $_POST["field_type"]; $form_data_query["name"] = $_POST["name"]; $form_data_query["name_desc"] = $_POST["name_desc"]; $form_data_query["source"] = $_POST["source"]; /* determine the correct values for the method type/value fields */ if (isset($_POST["method_group"])) { /* value */ if ($_POST["method_group"] == DATA_QUERY_FIELD_METHOD_GROUP_VALUE) { $form_data_query["method_type"] = $_POST["method_type_v"]; if ($_POST["method_type_v"] == DATA_QUERY_FIELD_METHOD_VALUE_PARSE) { $form_data_query["method_value"] = $_POST["method_value_v_parse"]; } /* snmp oid */ } else { if ($_POST["method_group"] == DATA_QUERY_FIELD_METHOD_GROUP_OID) { $form_data_query["method_type"] = $_POST["method_type_s"]; if ($_POST["method_type_s"] == DATA_QUERY_FIELD_METHOD_OID_OCTET) { $form_data_query["method_value"] = $_POST["method_value_s_octet"]; } else { if ($_POST["method_type_s"] == DATA_QUERY_FIELD_METHOD_OID_PARSE) { $form_data_query["method_value"] = $_POST["method_value_s_parse"]; } } } } } field_register_error(validate_data_query_field_fields($form_data_query, "|field|")); /* since the 'method_value' field name is abstracted above, we need to pass any input field errors * on to the correct form field */ if (isset($_SESSION["sess_error_fields"]["method_value"]) && $_POST["method_group"] == DATA_QUERY_FIELD_METHOD_GROUP_VALUE && $_POST["method_type_v"] == DATA_QUERY_FIELD_METHOD_VALUE_PARSE) { $_SESSION["sess_error_fields"]["method_value_v_parse"] = 1; } else { if (isset($_SESSION["sess_error_fields"]["method_value"]) && $_POST["method_group"] == DATA_QUERY_FIELD_METHOD_GROUP_OID && $_POST["method_type_s"] == DATA_QUERY_FIELD_METHOD_OID_OCTET) { $_SESSION["sess_error_fields"]["method_value_s_octet"] = 1; } else { if (isset($_SESSION["sess_error_fields"]["method_value"]) && $_POST["method_group"] == DATA_QUERY_FIELD_METHOD_GROUP_OID && $_POST["method_type_s"] == DATA_QUERY_FIELD_METHOD_OID_PARSE) { $_SESSION["sess_error_fields"]["method_value_s_parse"] = 1; } } } /* step #3: field save */ $data_query_field_id = false; if (is_error_message()) { log_save("User input validation error for data query field [ID#" . $_POST["data_query_field_id"] . "], data query [ID#" . $_POST["data_query_id"] . "]", SEV_DEBUG); } else { $data_query_field_id = api_data_query_field_save($_POST["data_query_field_id"], $form_data_query); if ($data_query_field_id === false) { log_save("Save error for data query field [ID#" . $_POST["data_query_field_id"] . "], data query [ID#" . $_POST["data_query_id"] . "]", SEV_ERROR); } } if ($data_query_field_id === false) { header("Location: data_queries.php?action=field_edit" . (empty($_POST["data_query_field_id"]) ? "" : "&id=" . $_POST["data_query_field_id"]) . "&data_query_id=" . $_POST["data_query_id"]); } else { header("Location: data_queries.php?action=edit&id=" . $_POST["data_query_id"]); } } else { if (isset($_POST["box-1-action-area-button"])) { $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]); if ($_POST["box-1-action-area-type"] == "remove") { foreach ($selected_rows as $data_query_id) { api_data_query_remove($data_query_id); } } header("Location: data_queries.php"); } } } }
function package_data_query_import(&$xml_array, $package_id, $object_hash) { require_once(CACTI_BASE_PATH . "/lib/data_query/data_query_info.php"); require_once(CACTI_BASE_PATH . "/lib/data_query/data_query_update.php"); /* * XML Tag: <data_query> */ /* obtain a list of all data query specific fields */ $data_query_fields = api_data_query_form_list(); if (isset($xml_array["data_query"])) { $save_fields = array(); /* tag the data query as a package member */ $save_fields["package_id"] = $package_id; /* get the base fields from the xml */ foreach (array_keys($data_query_fields) as $field_name) { if (isset($xml_array["data_query"][$field_name])) { $save_fields[$field_name] = xml_character_decode($xml_array["data_query"][$field_name]); } } /* save the data query to the database and register its new id */ $data_query_id = package_hash_update($object_hash, api_data_query_save(0, $save_fields)); if ($data_query_id === false) { return; } } /* * XML Tag: <fields> */ /* obtain a list of all data query field specific fields */ $data_query_field_fields = api_data_query_field_form_list(); if ((isset($xml_array["fields"])) && (is_array($xml_array["fields"]))) { /* loop through each available data query field */ foreach ($xml_array["fields"] as $data_query_field_hash => $data_query_field) { $save_fields = array(); /* make sure that each field is associated with the new data query */ $save_fields["data_query_id"] = $data_query_id; /* get the base fields from the xml */ foreach (array_keys($data_query_field_fields) as $field_name) { if (isset($data_query_field[$field_name])) { $save_fields[$field_name] = xml_character_decode($data_query_field[$field_name]); } } /* save the data query field to the database and register its new id */ api_data_query_field_save(0, $save_fields); } } }