function form_save() { if ($_POST["action_post"] == "package_new") { header("Location: packages.php?action=edit"); }else if ($_POST["action_post"] == "package_edit") { /* the "Add" associated graph template button was pressed */ if (isset($_POST["assoc_graph_template_add_y"])) { api_package_package_template_add($_POST["package_id"], $_POST["assoc_graph_template_id"]); header("Location: packages.php?action=edit&id=" . $_POST["package_id"]); exit; } /* cache all post field values */ init_post_field_cache(); /* step #2: field validation */ $form_package["id"] = $_POST["package_id"]; $form_package["name"] = $_POST["name"]; $form_package["description"] = $_POST["description"]; $form_package["description_install"] = $_POST["description_install"]; $form_package["category"] = ($_POST["category"] == "new" ? $_POST["category_txt"] : api_data_preset_package_category_get($_POST["category_drp"])); $form_package["subcategory"] = ($_POST["subcategory"] == "new" ? $_POST["subcategory_txt"] : api_data_preset_package_subcategory_get($_POST["subcategory_drp"])); $form_package["vendor"] = ($_POST["vendor"] == "new" ? $_POST["vendor_txt"] : api_data_preset_package_vendor_get($_POST["vendor_drp"])); $form_package["model"] = $_POST["model"]; /* the author field values may either come from the form or from the database */ if ($_POST["author_type"] == "new") { $form_package["author_name"] = $_POST["author_name"]; $form_package["author_email"] = $_POST["author_email"]; $form_package["author_user_repository"] = $_POST["author_user_repository"]; $form_package["author_user_forum"] = $_POST["author_user_forum"]; }else if ($_POST["author_type"] == "existing") { $package_author = api_package_author_get($_POST["author_type_drp"]); $form_package["author_name"] = $package_author["name"]; $form_package["author_email"] = $package_author["email"]; $form_package["author_user_repository"] = $package_author["user_repository"]; $form_package["author_user_forum"] = $package_author["user_forum"]; } field_register_error(api_package_field_validate($form_package, "|field|")); /* the custom category textbox goes by a different name on the form */ if (field_error_isset("category")) { field_register_error("category_txt"); } /* the custom subcategory textbox goes by a different name on the form */ if (field_error_isset("subcategory")) { field_register_error("subcategory_txt"); } /* step #3: field save */ $package_id = false; if (is_error_message()) { log_save("User input validation error for package [ID#" . $_POST["package_id"] . "]", SEV_DEBUG); }else{ $package_id = api_package_save($_POST["package_id"], $form_package); if ($package_id === false) { log_save("Save error for package [ID#" . $_POST["package_id"] . "]", SEV_ERROR); } } if (($package_id === false) || (empty($_POST["package_id"]))) { header("Location: packages.php?action=edit" . (empty($_POST["package_id"]) ? "" : "&id=" . $_POST["package_id"])); }else{ header("Location: packages.php"); } }else if ($_POST["action_post"] == "package_edit_metadata") { /* cache all post field values */ init_post_field_cache(); /* step #2: field validation */ $form_package_metadata["id"] = $_POST["package_metadata_id"]; $form_package_metadata["package_id"] = $_POST["package_id"]; $form_package_metadata["type"] = $_POST["type"]; $form_package_metadata["name"] = $_POST["name"]; $form_package_metadata["description"] = $_POST["description"]; if ($_POST["type"] == PACKAGE_METADATA_TYPE_SCREENSHOT) { /* make sure there is a valid file that was uploaded via an HTTP POST */ if ((isset($_FILES["payload_upl"])) && (is_uploaded_file($_FILES["payload_upl"]["tmp_name"]))) { $fp = fopen($_FILES["payload_upl"]["tmp_name"], "r"); $raw_data = fread($fp, $_FILES["payload_upl"]["size"]); fclose($fp); $form_package_metadata["mime_type"] = $_FILES["payload_upl"]["type"]; $form_package_metadata["payload"] = $raw_data; } }else if ($_POST["type"] == PACKAGE_METADATA_TYPE_SCRIPT) { $form_package_metadata["description_install"] = $_POST["description_install"]; $form_package_metadata["required"] = html_boolean(isset($_POST["required"]) ? $_POST["required"] : ""); $form_package_metadata["mime_type"] = "text/plain"; $form_package_metadata["payload"] = $_POST["payload_txt"]; } field_register_error(api_package_field_validate($form_package_metadata, "|field|")); /* step #3: field save */ $package_metadata_id = false; if (is_error_message()) { log_save("User input validation error for package metadata [ID#" . $_POST["package_metadata_id"] . "], package [ID#" . $_POST["package_id"] . "]", SEV_DEBUG); }else{ $package_metadata_id = api_package_metadata_save($_POST["package_metadata_id"], $form_package_metadata); if ($package_metadata_id === false) { log_save("Save error for package metadata [ID#" . $_POST["package_metadata_id"] . "], package [ID#" . $_POST["package_id"] . "]", SEV_ERROR); } } if ($package_metadata_id === false) { header("Location: packages.php?action=edit_metadata&package_id=" . $_POST["package_id"] . (empty($_POST["package_metadata_id"]) ? "" : "&id=" . $_POST["package_metadata_id"])); }else{ /* the cache will not be purged in time unless to do it here */ kill_post_field_cache(); header("Location: packages.php?action=edit&id=" . $_POST["package_id"]); } }else if ($_POST["action_post"] == "package_import") { /* first, see if there is any XML in the textbox */ if (trim($_POST["import_package_text"] != "")) { $xml_data = $_POST["import_package_text"]; /* next, check if the user uploaded a file */ }else if ((isset($_FILES["import_package_file"])) && (is_uploaded_file($_FILES["import_package_file"]["tmp_name"]))) { $fp = fopen($_FILES["import_package_file"]["tmp_name"], "r"); $xml_data = fread($fp, $_FILES["import_package_file"]["size"]); fclose($fp); } package_import($xml_data); } }
function package_header_import(&$xml_array) { require_once(CACTI_BASE_PATH . "/lib/package/package_info.php"); require_once(CACTI_BASE_PATH . "/lib/package/package_update.php"); /* * XML Tag: <package> */ /* obtain a list of all package specific fields */ $package_fields = api_package_form_list(); if (isset($xml_array["package"])) { $save_fields = array(); /* get the base fields from the xml */ foreach (array_keys($package_fields) as $field_name) { if (isset($xml_array["package"][$field_name])) { $save_fields[$field_name] = xml_character_decode($xml_array["package"][$field_name]); } } /* save the package to the database */ $package_id = api_package_save(0, $save_fields); if ($package_id === false) { return false; } } /* * XML Tag: <metadata> */ /* obtain a list of all package metadata specific fields */ $package_metadata_fields = api_package_metadata_form_list(); if ((isset($xml_array["metadata"])) && (is_array($xml_array["metadata"]))) { /* loop through each available package metadata field */ foreach ($xml_array["metadata"] as $package_metadata_hash => $package_metadata) { $save_fields = array(); /* make sure that each metadata item is associated with the new package */ $save_fields["package_id"] = $package_id; /* get the base fields from the xml */ foreach (array_keys($package_metadata_fields) as $field_name) { if (isset($package_metadata[$field_name])) { if ($field_name == "payload") { /* decode any binary payload data */ $save_fields[$field_name] = base64_decode(str_replace("\n", "", $package_metadata[$field_name])); }else{ $save_fields[$field_name] = xml_character_decode($package_metadata[$field_name]); } } } /* save the package metadata item to the database */ api_package_metadata_save(0, $save_fields); } } return $package_id; }