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_item_id"]; $form_graph_item["graph_id"] = $_POST["graph_id"]; $form_graph_item["data_source_item_id"] = $_POST["data_source_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_item_id = api_graph_item_save($_POST["graph_item_id"], $form_graph_item); } if (is_error_message()) { header("Location: graph_items.php?action=edit" . (empty($graph_item_id) ? "" : "&id=" . $graph_item_id) . "&graph_id=" . $_POST["graph_id"]); } else { header("Location: graphs.php?action=edit&id=" . $_POST["graph_id"]); } } }
function copy_graph_template_to_graph($graph_template_id, $host_id = 0, $data_query_id = 0, $data_query_index = "") { require_once(CACTI_BASE_PATH . "/lib/sys/variable.php"); require_once(CACTI_BASE_PATH . "/lib/graph/graph_update.php"); require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php"); require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_info.php"); /* sanity check for $graph_template_id */ if ((!is_numeric($graph_template_id)) || (empty($graph_template_id))) { return false; } /* sanity check for $host_id */ if (!is_numeric($host_id)) { return false; } /* fetch field lists */ $fields_graph = api_graph_form_list(); $fields_graph_item = api_graph_item_form_list(); $graph_template = api_graph_template_get($graph_template_id); if (sizeof($graph_template) > 0) { /* copy down per-graph only fields */ $_fields = array(); $_fields["id"] = "0"; $_fields["graph_template_id"] = $graph_template_id; $_fields["host_id"] = $host_id; /* evaluate suggested values: data query-based graphs */ if ((!empty($data_query_id)) && ($data_query_index != "")) { $_fields["title"] = evaluate_data_query_suggested_values($host_id, $data_query_id, $data_query_index, "graph_template_suggested_value", "graph_template_id = " . sql_sanitize($graph_template_id) . " and field_name = 'title'", 0); /* evaluate suggested values: non-data query-based graphs */ }else{ $_fields["title"] = db_fetch_cell("select value from graph_template_suggested_value where graph_template_id = " . sql_sanitize($graph_template_id) . " and field_name = 'title' order by sequence limit 1"); } /* copy down all visible fields */ foreach (array_keys($fields_graph) as $field_name) { if (isset($graph_template[$field_name])) { $_fields[$field_name] = $graph_template[$field_name]; } } if (api_graph_save(0, $_fields, true)) { $graph_id = db_fetch_insert_id(); log_save("Cloning graph [ID#$graph_id] from template [ID#$graph_template_id]", SEV_DEBUG); /* move onto the graph items */ $graph_template_items = api_graph_template_item_list($graph_template_id); if (sizeof($graph_template_items) > 0) { foreach ($graph_template_items as $graph_template_item) { /* copy down per-graph only fields */ $_fields = array(); $_fields["id"] = "0"; $_fields["graph_id"] = $graph_id; $_fields["graph_template_item_id"] = $graph_template_item["id"]; /* this allows us to connect the dots later */ foreach (array_keys($fields_graph_item) as $field_name) { if (isset($graph_template_item[$field_name])) { $_fields[$field_name] = $graph_template_item[$field_name]; } } if (!api_graph_item_save(0, $_fields)) { log_save("Save error in api_graph_item_save()", SEV_ERROR); } } } return $graph_id; }else{ log_save("Save error in api_graph_save()", SEV_ERROR); return false; } } return false; }