function api_graph_template_list($filter_array = "", $current_page = 0, $rows_per_page = 0) { require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_form.php"); $sql_where = ""; /* validation and setup for the WHERE clause */ if ((is_array($filter_array)) && (sizeof($filter_array) > 0)) { /* validate each field against the known master field list */ $field_errors = api_graph_template_fields_validate(sql_filter_array_to_field_array($filter_array)); /* if a field input error has occured, register the error in the session and return */ if (sizeof($field_errors) > 0) { field_register_error($field_errors); return false; /* otherwise, form an SQL WHERE string using the filter fields */ }else{ $sql_where = sql_filter_array_to_where_string($filter_array, api_graph_template_form_list(), true); } } $sql_limit = ""; /* validation and setup for the LIMIT clause */ if ((is_numeric($current_page)) && (is_numeric($rows_per_page)) && (!empty($current_page)) && (!empty($rows_per_page))) { $sql_limit = "limit " . ($rows_per_page * ($current_page - 1)) . ",$rows_per_page"; } return db_fetch_assoc("select graph_template.id, graph_template.template_name from graph_template $sql_where " . ($sql_where == "" ? "where" : "and") . " graph_template.package_id = 0 order by template_name $sql_limit"); }
function api_graph_template_save($graph_template_id, $_fields_graph) { 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_push.php"); /* sanity checks */ validate_id_die($graph_template_id, "graph_template_id", true); /* make sure that there is at least one field to save */ if (sizeof($_fields_graph) == 0) { return false; } /* field: id */ $_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $graph_template_id); /* convert the input array into something that is compatible with db_replace() */ $_fields += sql_get_database_field_array($_fields_graph, api_graph_template_form_list()); $_fields += sql_get_database_field_array($_fields_graph, api_graph_form_list()); if (db_replace("graph_template", $_fields, array("id"))) { if (empty($graph_template_id)) { $graph_template_id = db_fetch_insert_id(); }else{ /* push out graph template fields */ api_graph_template_propagate($graph_template_id); } return $graph_template_id; }else{ return false; } }
function api_graph_template_fields_validate(&$_fields_graph_template, $graph_template_field_name_format = "|field|") { require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_info.php"); if (sizeof($_fields_graph_template) == 0) { return array(); } /* array containing errored fields */ $error_fields = array(); /* get a complete field list */ $fields_graph_template = api_graph_template_form_list(); /* base fields */ while (list($_field_name, $_field_array) = each($fields_graph_template)) { if ((isset($_fields_graph_template[$_field_name])) && (isset($_field_array["validate_regexp"])) && (isset($_field_array["validate_empty"]))) { $form_field_name = str_replace("|field|", $_field_name, $graph_template_field_name_format); if (!form_input_validate($_fields_graph_template[$_field_name], $form_field_name, $_field_array["validate_regexp"], $_field_array["validate_empty"])) { $error_fields[] = $form_field_name; } } } return $error_fields; }
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); } }
function &package_graph_template_export($graph_template_id, $indent = 3) { require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_info.php"); require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php"); $xml = ""; /* * XML Tag: <template> */ /* obtain a list of all graph template specific fields */ $graph_template_fields = api_graph_template_form_list(); /* obtain a copy of this specfic graph template */ $graph_template = api_graph_template_get($graph_template_id); $_xml = ""; foreach (array_keys($graph_template_fields) as $field_name) { /* create an XML key for each graph template field */ $_xml .= package_xml_tag_get($field_name, xml_character_encode($graph_template[$field_name]), $indent + 2); } /* append the result onto the final XML string */ $xml .= package_xml_tag_get("template", $_xml, $indent + 1, true); /* * XML Tag: <graph> */ /* obtain a list of all graph specific fields */ $graph_fields = api_graph_form_list(); $_xml = ""; foreach (array_keys($graph_fields) as $field_name) { /* check because the 'title' column does not exist */ if (isset($graph_template[$field_name])) { /* create an XML key for each graph field */ $_xml .= package_xml_tag_get($field_name, xml_character_encode($graph_template[$field_name]), $indent + 2); } /* create an XML key for each "template" graph field */ $_xml .= package_xml_tag_get("t_" . $field_name, xml_character_encode($graph_template{"t_" . $field_name}), $indent + 2); } /* append the result onto the final XML string */ $xml .= package_xml_tag_get("graph", $_xml, $indent + 1, true); /* * XML Tag: <items> */ /* obtain a list of all graph template item specific fields */ $graph_template_items_fields = api_graph_template_item_form_list(); /* obtain a list of all graph template items associated with this graph template */ $graph_template_items = api_graph_template_item_list($graph_template_id); $_xml = ""; if (sizeof($graph_template_items) > 0) { foreach ($graph_template_items as $graph_template_item) { $__xml = ""; foreach (array_keys($graph_template_items_fields) as $field_name) { if ($field_name == "data_template_item_id") { /* create an XML key for the 'data_template_item_id' field, making sure to resolve internal ID's */ $__xml .= package_xml_tag_get($field_name, xml_character_encode(package_hash_get($graph_template_item[$field_name], "data_template_item")), $indent + 3); }else{ /* create an XML key for each graph template item field */ $__xml .= package_xml_tag_get($field_name, xml_character_encode($graph_template_item[$field_name]), $indent + 3); } } /* append the result onto a temporary XML string */ $_xml .= package_xml_tag_get(package_hash_get($graph_template_item["id"], "graph_template_item"), $__xml, $indent + 2, true); } } /* append the result onto the final XML string */ $xml .= package_xml_tag_get("items", $_xml, $indent + 1, true); /* * XML Tag: <inputs> */ /* obtain a list of all graph template item input specific fields */ $graph_template_inputs_fields = api_graph_template_item_input_form_list(); /* obtain a list of all graph template item inputs associated with this graph template */ $graph_template_inputs = api_graph_template_item_input_list($graph_template_id); $_xml = ""; if (sizeof($graph_template_inputs) > 0) { foreach ($graph_template_inputs as $graph_template_input) { $__xml = ""; foreach (array_keys($graph_template_inputs_fields) as $field_name) { /* create an XML key for each graph template item input field */ $__xml .= package_xml_tag_get($field_name, xml_character_encode($graph_template_input[$field_name]), $indent + 3); } /* obtain a list of each item associated with this graph template item input */ $graph_template_input_items = api_graph_template_item_input_item_list($graph_template_id); if (sizeof($graph_template_input_items) > 0) { $i = 0; $items_list = ""; foreach ($graph_template_input_items as $graph_template_item_id) { /* create a delimited list of each item, making sure to resolve internal ID's */ $items_list .= package_hash_get($graph_template_item_id, "graph_template_item") . (($i + 1) < sizeof($graph_template_input_items) ? "|" : ""); $i++; } } /* add the items list that we created above */ $__xml .= package_xml_tag_get("items", $items_list, $indent + 3); /* append the result onto a temporary XML string */ $_xml .= package_xml_tag_get(package_hash_get($graph_template_input["id"], "graph_template_input"), $__xml, $indent + 2, true); } } /* append the result onto the final XML string */ $xml .= package_xml_tag_get("inputs", $_xml, $indent + 1, true); /* * XML Tag: <suggested_values> */ /* obtain a list of all suggested values associated with this graph template */ $graph_template_suggested_values = api_graph_template_suggested_values_list($graph_template_id); $_xml = ""; if (sizeof($graph_template_suggested_values) > 0) { $i = 0; foreach ($graph_template_suggested_values as $graph_template_suggested_value) { $__xml = ""; /* create an XML key for each suggested value field */ $__xml .= package_xml_tag_get("field_name", xml_character_encode($graph_template_suggested_value["field_name"]), $indent + 3); $__xml .= package_xml_tag_get("sequence", xml_character_encode($graph_template_suggested_value["sequence"]), $indent + 3); $__xml .= package_xml_tag_get("value", xml_character_encode($graph_template_suggested_value["value"]), $indent + 3); /* break out each row into its own key */ $_xml .= package_xml_tag_get("item_" . str_pad($i, 5, "0", STR_PAD_LEFT), $__xml, $indent + 2, true); $i++; } } /* append the result onto the final XML string */ $xml .= package_xml_tag_get("suggested_values", $_xml, $indent + 1, true); /* wrap the whole XML string into a 'graph_template' tag and return it */ $xml = package_xml_tag_get(package_hash_get($graph_template_id, "graph_template"), $xml, $indent, true); return $xml; }