function xaxis_form_save() { if (isset($_POST["save_component_xaxis"])) { $save["id"] = $_POST["id"]; $save["hash"] = get_hash_xaxis($_POST["id"]); $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3); if (!is_error_message()) { $xaxis_id = sql_save($save, "graph_templates_xaxis"); if ($xaxis_id) { raise_message(1); }else{ raise_message(2); } } if ((is_error_message()) || (empty($_POST["id"]))) { header("Location: xaxis_presets.php?action=edit&id=" . (empty($xaxis_id) ? $_POST["id"] : $xaxis_id)); }else{ header("Location: xaxis_presets.php"); } exit; } if ((isset($_POST["save_component_item"]))) { $save["id"] = $_POST["id"]; $save["hash"] = get_hash_xaxis($_POST["id"], "xaxis_item"); $save["item_name"] = form_input_validate($_POST["item_name"], "item_name", "", true, 3); $save["xaxis_id"] = form_input_validate($_POST["xaxis_id"], "xaxis_id", "^[0-9]+$", false, 3); $save["timespan"] = form_input_validate($_POST["timespan"], "timespan", "^[0-9]+$", false, 3); $save["gtm"] = form_input_validate($_POST["gtm"], "gtm", "", false, 3); $save["gst"] = form_input_validate($_POST["gst"], "gst", "^[0-9]+$", false, 3); $save["mtm"] = form_input_validate($_POST["mtm"], "mtm", "", false, 3); $save["mst"] = form_input_validate($_POST["mst"], "mst", "^[0-9]+$", false, 3); $save["ltm"] = form_input_validate($_POST["ltm"], "ltm", "", false, 3); $save["lst"] = form_input_validate($_POST["lst"], "lst", "^[0-9]+$", false, 3); $save["lpr"] = form_input_validate($_POST["lpr"], "lpr", "^[0-9]+$", false, 3); $save["lfm"] = form_input_validate($_POST["lfm"], "lfm", "", true, 3); if (!is_error_message()) { $xaxis_item_id = sql_save($save, "graph_templates_xaxis_items"); if ($xaxis_item_id) { raise_message(1); }else{ raise_message(2); } } if ((is_error_message()) || (empty($_POST["id"]))) { header("Location: xaxis_presets.php?action=item_edit&xaxis_id=" . $_POST["xaxis_id"] . "&id=" . (empty($xaxis_item_id) ? $_POST["id"] : $xaxis_item_id)); }else{ header("Location: xaxis_presets.php?action=edit&id=" . (!empty($_POST["xaxis_id"]) ? $_POST["xaxis_id"] : 0)); } exit; } }
function duplicate_xaxis($_xaxis_id, $xaxis_title) { require(CACTI_BASE_PATH . "/include/presets/preset_xaxis_forms.php"); $xaxis = db_fetch_row("select * from graph_templates_xaxis where id=$_xaxis_id"); $xaxis_items = db_fetch_assoc("select * from graph_templates_xaxis_items where xaxis_id=$_xaxis_id ORDER BY timespan"); /* create new entry: device_template */ $save["id"] = 0; $save["hash"] = get_hash_xaxis(0); /* substitute the title variable */ $save["name"] = str_replace(__("<xaxis_title>"), $xaxis["name"], $xaxis_title); $xaxis_id = sql_save($save, "graph_templates_xaxis"); /* create new entry(s): xaxis_items */ if (sizeof($xaxis_items) > 0) { foreach ($xaxis_items as $xaxis_item) { unset($save); $save["id"] = 0; $save["hash"] = get_hash_xaxis(0, "xaxis_item"); $save["xaxis_id"] = $xaxis_id; reset($fields_xaxis_item_edit); while (list($field, $array) = each($fields_xaxis_item_edit)) { if (!preg_match("/^hidden/", $array["method"])) { $save[$field] = $xaxis_item[$field]; } } sql_save($save, "graph_templates_xaxis_items"); } } }
function xaxis_to_xml($xaxis_id) { require_once(CACTI_BASE_PATH . "/lib/presets/preset_xaxis_info.php"); $hash["xaxis"] = get_hash_version("xaxis") . get_hash_xaxis($xaxis_id); $xml_text = ""; $xaxis = db_fetch_row("SELECT * FROM graph_templates_xaxis WHERE id=$xaxis_id"); $xaxis_items = db_fetch_assoc("SELECT * FROM graph_templates_xaxis_items WHERE xaxis_id=$xaxis_id ORDER BY timespan"); if (empty($xaxis["id"])) { $err_msg = "Invalid X-Axis."; return $err_msg; } $xml_text .= "<hash_" . $hash["xaxis"] . ">\n"; /* XML Branch: <> */ $fields_xaxis_edit = preset_xaxis_form_list(); reset($fields_xaxis_edit); while (list($field_name, $field_array) = each($fields_xaxis_edit)) { if (($field_array["method"] != "hidden_zero") && ($field_array["method"] != "hidden") && ($field_array["method"] != "spacer")) { $xml_text .= "\t<$field_name>" . xml_character_encode($xaxis{$field_name}) . "</$field_name>\n"; } } /* XML Branch: <items> */ $xml_text .= "\t<items>\n"; $i = 0; if (sizeof($xaxis_items) > 0) { foreach ($xaxis_items as $item) { $hash["xaxis_item"] = get_hash_version("xaxis_item") . get_hash_xaxis($item["id"], "xaxis_item"); $xml_text .= "\t\t<hash_" . $hash["xaxis_item"] . ">\n"; $fields_xaxis_item_edit = preset_xaxis_item_form_list(); reset($fields_xaxis_item_edit); while (list($field_name, $field_array) = each($fields_xaxis_item_edit)) { 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["xaxis_item"] . ">\n"; $i++; } } $xml_text .= "\t</items>\n"; $xml_text .= "</hash_" . $hash["xaxis"] . ">"; return $xml_text; }