function api_graph_template_item_duplicate($graph_template_item_id, $new_data_template_item_id) { require_once(CACTI_BASE_PATH . "/lib/sys/sequence.php"); $item = db_fetch_row("select * from graph_template_item where id = $graph_template_item_id"); if (sizeof($item) > 0) { api_graph_template_item_save(0, $item["graph_template_id"], $new_data_template_item_id, $item["color"], $item["graph_item_type"], $item["cdef"], $item["consolidation_function"], $item["gprint_format"], $item["legend_format"], $item["legend_value"], $item["hard_return"]); } }
function form_save() { if (isset($_POST["save_component_item"])) { /* cache all post field values */ init_post_field_cache(); /* step #1: field validation */ $form_graph_item["id"] = $_POST["graph_template_item_id"]; $form_graph_item["graph_template_id"] = $_POST["graph_template_id"]; $form_graph_item["data_template_item_id"] = $_POST["data_template_item_id"]; $form_graph_item["color"] = $_POST["color"]; $form_graph_item["graph_item_type"] = $_POST["graph_item_type"]; $form_graph_item["consolidation_function"] = $_POST["consolidation_function"]; $form_graph_item["cdef"] = $_POST["cdef"]; $form_graph_item["gprint_format"] = $_POST["gprint_format"]; $form_graph_item["legend_value"] = $_POST["legend_value"]; $form_graph_item["legend_format"] = $_POST["legend_format"]; $form_graph_item["hard_return"] = html_boolean(isset($_POST["hard_return"]) ? $_POST["hard_return"] : ""); field_register_error(api_graph_item_fields_validate($form_graph_item, "|field|")); /* step #2: field save */ if (!is_error_message()) { $graph_template_item_id = api_graph_template_item_save($_POST["graph_template_item_id"], $form_graph_item); } if (is_error_message()) { header("Location: graph_templates_items.php?action=edit" . (empty($graph_template_item_id) ? "" : "&id=" . $graph_template_item_id) . "&graph_template_id=" . $_POST["graph_template_id"]); } else { header("Location: graph_templates.php?action=edit&id=" . $_POST["graph_template_id"]); } } }
function package_graph_template_import(&$xml_array, $package_id, $object_hash) { require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php"); require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_info.php"); require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_update.php"); $save_fields = array(); /* tag the graph template as a package member */ $save_fields["package_id"] = $package_id; /* * XML Tag: <template> */ /* obtain a list of all graph template specific fields */ $graph_template_fields = api_graph_template_form_list(); if (isset($xml_array["template"])) { /* get the base fields from the xml */ foreach (array_keys($graph_template_fields) as $field_name) { if (isset($xml_array["template"][$field_name])) { $save_fields[$field_name] = xml_character_decode($xml_array["template"][$field_name]); } } } /* * XML Tag: <graph> */ /* obtain a list of all graph specific fields */ $graph_fields = api_graph_form_list(); if (isset($xml_array["graph"])) { /* get the base fields from the xml */ foreach (array_keys($graph_fields) as $field_name) { if (isset($xml_array["graph"][$field_name])) { $save_fields[$field_name] = xml_character_decode($xml_array["graph"][$field_name]); } } } /* make sure we got the required information before trying to save */ if ((isset($xml_array["template"])) && (isset($xml_array["graph"]))) { /* save the graph template field to the database and register its new id */ $graph_template_id = package_hash_update($object_hash, api_graph_template_save(0, $save_fields)); } /* make sure the save completed successfully */ if ($graph_template_id === false) { return; } /* * XML Tag: <items> */ /* obtain a list of all graph template item specific fields */ $graph_template_item_fields = api_graph_template_item_form_list(); if ((isset($xml_array["items"])) && (is_array($xml_array["items"]))) { $save_fields = array(); /* get the base fields from the xml */ foreach ($xml_array["items"] as $graph_template_item_hash => $graph_template_item) { $save_fields = array(); /* make sure that each field is associated with the new graph template */ $save_fields["graph_template_id"] = $graph_template_id; /* get the base fields from the xml */ foreach (array_keys($graph_template_item_fields) as $field_name) { if (isset($graph_template_item[$field_name])) { if ($field_name == "data_template_item_id") { $save_fields[$field_name] = package_hash_resolve($graph_template_item[$field_name]); }else{ $save_fields[$field_name] = xml_character_decode($graph_template_item[$field_name]); } } } /* save the data query field to the database and register its new id */ package_hash_update($graph_template_item_hash, api_graph_template_item_save(0, $save_fields)); } } /* * XML Tag: <suggested_values> */ if (isset($xml_array["suggested_values"])) { $save_fields = array(); /* get the base fields from the xml */ foreach ($xml_array["suggested_values"] as $field_array) { if ((isset($field_array["field_name"])) && (isset($field_array["sequence"])) && (isset($field_array["value"]))) { /* build an array containing each data input field */ $save_fields{$field_array["field_name"]}[] = array("id" => "0", "value" => xml_character_decode($field_array["value"])); } } /* save the suggested values to the database */ api_graph_template_suggested_values_save($graph_template_id, $save_fields); } }