function form_save() { if (isset($_POST["save_component_input"]) && !is_error_message()) { $graph_input_values = array(); $selected_graph_items = array(); $save["id"] = $_POST["graph_template_input_id"]; $save["hash"] = get_hash_graph_template($_POST["graph_template_input_id"], "graph_template_input"); $save["graph_template_id"] = $_POST["graph_template_id"]; $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3); $save["description"] = form_input_validate($_POST["description"], "description", "", true, 3); $save["column_name"] = form_input_validate($_POST["column_name"], "column_name", "", true, 3); if (!is_error_message()) { $graph_template_input_id = sql_save($save, "graph_template_input"); if ($graph_template_input_id) { raise_message(1); /* list all graph items from the db so we can compare them with the current form */ $db_selected_graph_item = array_rekey(db_fetch_assoc("select graph_template_item_id from graph_template_input_defs where graph_template_input_id={$graph_template_input_id}"), "graph_template_item_id", "graph_template_item_id"); /* list all select graph items for use down below */ while (list($var, $val) = each($_POST)) { if (preg_match("/^i_(\\d+)\$/", $var, $matches)) { /* ================= input validation ================= */ input_validate_input_number($matches[1]); /* ==================================================== */ $selected_graph_items[$matches[1]] = $matches[1]; if (isset($db_selected_graph_item[$matches[1]])) { /* is selected and exists in the db; old item */ $old_members[$matches[1]] = $matches[1]; } else { /* is selected and does not exist the db; new item */ $new_members[$matches[1]] = $matches[1]; } } } if (isset($new_members) && sizeof($new_members) > 0) { while (list($item_id, $item_id) = each($new_members)) { push_out_graph_input($graph_template_input_id, $item_id, isset($new_members) ? $new_members : array()); } } db_execute("delete from graph_template_input_defs where graph_template_input_id={$graph_template_input_id}"); if (sizeof($selected_graph_items) > 0) { foreach ($selected_graph_items as $graph_template_item_id) { db_execute("insert into graph_template_input_defs (graph_template_input_id,graph_template_item_id)\n\t\t\t\t\t\tvalues ({$graph_template_input_id},{$graph_template_item_id})"); } } } else { raise_message(2); } } if (is_error_message()) { header("Location: graph_templates_inputs.php?action=input_edit&graph_template_input_id=" . (empty($graph_template_input_id) ? $_POST["graph_template_input_id"] : $graph_template_input_id) . "&graph_template_id=" . $_POST["graph_template_id"]); exit; } else { header("Location: graph_templates.php?action=template_edit&id=" . $_POST["graph_template_id"]); exit; } } }
function form_save() { if (isset($_POST["save_component_item"])) { /* ================= input validation ================= */ input_validate_input_number(get_request_var_post("graph_template_id")); input_validate_input_number(get_request_var_post("task_item_id")); /* ==================================================== */ global $graph_item_types; $items[0] = array(); if ($graph_item_types{$_POST["graph_type_id"]} == "LEGEND") { /* this can be a major time saver when creating lots of graphs with the typical GPRINT LAST/AVERAGE/MAX legends */ $items = array( 0 => array( "color_id" => "0", "graph_type_id" => "9", "consolidation_function_id" => "4", "text_format" => "Current:", "hard_return" => "" ), 1 => array( "color_id" => "0", "graph_type_id" => "9", "consolidation_function_id" => "1", "text_format" => "Average:", "hard_return" => "" ), 2 => array( "color_id" => "0", "graph_type_id" => "9", "consolidation_function_id" => "3", "text_format" => "Maximum:", "hard_return" => "on" )); } foreach ($items as $item) { /* generate a new sequence if needed */ if (empty($_POST["sequence"])) { $_POST["sequence"] = get_sequence($_POST["sequence"], "sequence", "graph_templates_item", "graph_template_id=" . $_POST["graph_template_id"] . " and local_graph_id=0"); } $save["id"] = $_POST["graph_template_item_id"]; $save["hash"] = get_hash_graph_template($_POST["graph_template_item_id"], "graph_template_item"); $save["graph_template_id"] = $_POST["graph_template_id"]; $save["local_graph_id"] = 0; $save["task_item_id"] = form_input_validate($_POST["task_item_id"], "task_item_id", "", true, 3); $save["color_id"] = form_input_validate((isset($item["color_id"]) ? $item["color_id"] : $_POST["color_id"]), "color_id", "", true, 3); /* if alpha is disabled, use invisible_alpha instead */ if (!isset($_POST["alpha"])) {$_POST["alpha"] = $_POST["invisible_alpha"];} $save["alpha"] = form_input_validate((isset($item["alpha"]) ? $item["alpha"] : $_POST["alpha"]), "alpha", "", true, 3); $save["graph_type_id"] = form_input_validate((isset($item["graph_type_id"]) ? $item["graph_type_id"] : $_POST["graph_type_id"]), "graph_type_id", "", true, 3); $save["cdef_id"] = form_input_validate($_POST["cdef_id"], "cdef_id", "", true, 3); $save["consolidation_function_id"] = form_input_validate((isset($item["consolidation_function_id"]) ? $item["consolidation_function_id"] : $_POST["consolidation_function_id"]), "consolidation_function_id", "", true, 3); $save["text_format"] = form_input_validate((isset($item["text_format"]) ? $item["text_format"] : $_POST["text_format"]), "text_format", "", true, 3); $save["value"] = form_input_validate($_POST["value"], "value", "", true, 3); $save["hard_return"] = form_input_validate(((isset($item["hard_return"]) ? $item["hard_return"] : (isset($_POST["hard_return"]) ? $_POST["hard_return"] : ""))), "hard_return", "", true, 3); $save["gprint_id"] = form_input_validate($_POST["gprint_id"], "gprint_id", "", true, 3); $save["sequence"] = $_POST["sequence"]; if (!is_error_message()) { /* Before we save the item, let's get a look at task_item_id <-> input associations */ $orig_data_source_graph_inputs = db_fetch_assoc("select graph_template_input.id, graph_template_input.name, graph_templates_item.task_item_id from (graph_template_input,graph_template_input_defs,graph_templates_item) where graph_template_input.id=graph_template_input_defs.graph_template_input_id and graph_template_input_defs.graph_template_item_id=graph_templates_item.id and graph_template_input.graph_template_id=" . $save["graph_template_id"] . " and graph_template_input.column_name='task_item_id' group by graph_templates_item.task_item_id"); $orig_data_source_to_input = array_rekey($orig_data_source_graph_inputs, "task_item_id", "id"); $graph_template_item_id = sql_save($save, "graph_templates_item"); if ($graph_template_item_id) { raise_message(1); if (!empty($save["task_item_id"])) { /* old item clean-up. Don't delete anything if the item <-> task_item_id association remains the same. */ if ($_POST["_task_item_id"] != $_POST["task_item_id"]) { /* It changed. Delete any old associations */ db_execute("delete from graph_template_input_defs where graph_template_item_id=$graph_template_item_id"); /* Input for current data source exists and has changed. Update the association */ if (isset($orig_data_source_to_input{$save["task_item_id"]})) { db_execute("replace into graph_template_input_defs (graph_template_input_id, graph_template_item_id) values (" . $orig_data_source_to_input{$save["task_item_id"]} . ",$graph_template_item_id)"); } } /* an input for the current data source does NOT currently exist, let's create one */ if (!isset($orig_data_source_to_input{$save["task_item_id"]})) { $ds_name = db_fetch_cell("select data_source_name from data_template_rrd where id=" . $_POST["task_item_id"]); db_execute("replace into graph_template_input (hash,graph_template_id,name,column_name) values ( '" . get_hash_graph_template(0, "graph_template_input") . "'," . $save["graph_template_id"] . ", 'Data Source [$ds_name]','task_item_id')"); $graph_template_input_id = db_fetch_insert_id(); $graph_items = db_fetch_assoc("select id from graph_templates_item where graph_template_id=" . $save["graph_template_id"] . " and task_item_id=" . $_POST["task_item_id"]); if (sizeof($graph_items) > 0) { foreach ($graph_items as $graph_item) { db_execute("replace into graph_template_input_defs (graph_template_input_id,graph_template_item_id) values ($graph_template_input_id," . $graph_item["id"] . ")"); } } } } push_out_graph_item($graph_template_item_id); if (isset($orig_data_source_to_input{$_POST["task_item_id"]})) { /* make sure all current graphs using this graph input are aware of this change */ push_out_graph_input($orig_data_source_to_input{$_POST["task_item_id"]}, $graph_template_item_id, array($graph_template_item_id => $graph_template_item_id)); } }else{ raise_message(2); } } $_POST["sequence"] = 0; } if (is_error_message()) { header("Location: graph_templates_items.php?action=item_edit&graph_template_item_id=" . (empty($graph_template_item_id) ? $_POST["graph_template_item_id"] : $graph_template_item_id) . "&id=" . $_POST["graph_template_id"]); exit; }else{ header("Location: graph_templates.php?action=template_edit&id=" . $_POST["graph_template_id"]); exit; } } }
function form_save() { if (isset($_POST['save_component_input']) && !is_error_message()) { $graph_input_values = array(); $selected_graph_items = array(); /* ================= input validation ================= */ input_validate_input_number(get_request_var_post('graph_template_input_id')); input_validate_input_number(get_request_var_post('graph_template_id')); /* ==================================================== */ $save['id'] = $_POST['graph_template_input_id']; $save['hash'] = get_hash_graph_template($_POST['graph_template_input_id'], 'graph_template_input'); $save['graph_template_id'] = $_POST['graph_template_id']; $save['name'] = form_input_validate($_POST['name'], 'name', '', false, 3); $save['description'] = form_input_validate($_POST['description'], 'description', '', true, 3); $save['column_name'] = form_input_validate($_POST['column_name'], 'column_name', '', true, 3); if (!is_error_message()) { $graph_template_input_id = sql_save($save, 'graph_template_input'); if ($graph_template_input_id) { raise_message(1); /* list all graph items from the db so we can compare them with the current form */ $db_selected_graph_item = array_rekey(db_fetch_assoc_prepared('SELECT graph_template_item_id FROM graph_template_input_defs WHERE graph_template_input_id = ?', array($graph_template_input_id)), 'graph_template_item_id', 'graph_template_item_id'); /* list all select graph items for use down below */ while (list($var, $val) = each($_POST)) { if (preg_match("/^i_(\\d+)\$/", $var, $matches)) { /* ================= input validation ================= */ input_validate_input_number($matches[1]); /* ==================================================== */ $selected_graph_items[$matches[1]] = $matches[1]; if (isset($db_selected_graph_item[$matches[1]])) { /* is selected and exists in the db; old item */ $old_members[$matches[1]] = $matches[1]; } else { /* is selected and does not exist the db; new item */ $new_members[$matches[1]] = $matches[1]; } } } if (isset($new_members) && sizeof($new_members) > 0) { while (list($item_id, $item_id) = each($new_members)) { push_out_graph_input($graph_template_input_id, $item_id, isset($new_members) ? $new_members : array()); } } db_execute_prepared('DELETE FROM graph_template_input_defs WHERE graph_template_input_id = ?', array($graph_template_input_id)); if (sizeof($selected_graph_items) > 0) { foreach ($selected_graph_items as $graph_template_item_id) { db_execute_prepared('INSERT INTO graph_template_input_defs (graph_template_input_id, graph_template_item_id) VALUES (?, ?)', array($graph_template_input_id, $graph_template_item_id)); } } } else { raise_message(2); } } if (is_error_message()) { header('Location: graph_templates_inputs.php?action=input_edit&graph_template_input_id=' . (empty($graph_template_input_id) ? $_POST['graph_template_input_id'] : $graph_template_input_id) . '&graph_template_id=' . $_POST['graph_template_id']); exit; } else { header('Location: graph_templates.php?action=template_edit&id=' . $_POST['graph_template_id']); exit; } } }
function form_save() { require(CACTI_BASE_PATH . "/include/graph/graph_arrays.php"); if (isset($_POST["save_component_item"])) { /* ================= input validation ================= */ input_validate_input_number(get_request_var_post("graph_template_id")); input_validate_input_number(get_request_var_post("task_item_id")); /* ==================================================== */ $items[0] = array(); if (get_request_var_post("graph_type_id") == GRAPH_ITEM_TYPE_LEGEND) { /* this can be a major time saver when creating lots of graphs with the typical GPRINT LAST/AVERAGE/MAX legends */ $items = array( 0 => array( "color_id" => "0", "graph_type_id" => GRAPH_ITEM_TYPE_GPRINT_LAST, "consolidation_function_id" => RRA_CF_TYPE_AVERAGE, "text_format" => __("Current:"), "hard_return" => "" ), 1 => array( "color_id" => "0", "graph_type_id" => GRAPH_ITEM_TYPE_GPRINT_AVERAGE, "consolidation_function_id" => RRA_CF_TYPE_AVERAGE, "text_format" => __("Average:"), "hard_return" => "" ), 2 => array( "color_id" => "0", "graph_type_id" => GRAPH_ITEM_TYPE_GPRINT_MAX, "consolidation_function_id" => RRA_CF_TYPE_AVERAGE, "text_format" => __("Maximum:"), "hard_return" => CHECKED )); } if ($_POST["graph_type_id"] == GRAPH_ITEM_TYPE_CUSTOM_LEGEND) { /* this can be a major time saver when creating lots of graphs with the typical VDEFs */ $items = array( 0 => array( "color_id" => "0", "graph_type_id" => read_config_option("cl1_gt_id"), "consolidation_function_id" => read_config_option("cl1_cf_id"), "vdef_id" => read_config_option("cl1_vdef_id"), "text_format" => read_config_option("cl1_text_format"), "hard_return" => read_config_option("cl1_hard_return") ), 1 => array( "color_id" => "0", "graph_type_id" => read_config_option("cl2_gt_id"), "consolidation_function_id" => read_config_option("cl2_cf_id"), "vdef_id" => read_config_option("cl2_vdef_id"), "text_format" => read_config_option("cl2_text_format"), "hard_return" => read_config_option("cl2_hard_return") ), 2 => array( "color_id" => "0", "graph_type_id" => read_config_option("cl3_gt_id"), "consolidation_function_id" => read_config_option("cl3_cf_id"), "vdef_id" => read_config_option("cl3_vdef_id"), "text_format" => read_config_option("cl3_text_format"), "hard_return" => read_config_option("cl3_hard_return") ), 3 => array( "color_id" => "0", "graph_type_id" => read_config_option("cl4_gt_id"), "consolidation_function_id" => read_config_option("cl4_cf_id"), "vdef_id" => read_config_option("cl4_vdef_id"), "text_format" => read_config_option("cl4_text_format"), "hard_return" => read_config_option("cl4_hard_return") ), ); foreach ($items as $key => $item) { #drop "empty" custom legend items if (empty($item["text_format"])) unset($items[$key]); } } foreach ($items as $item) { $save["id"] = form_input_validate($_POST["graph_template_item_id"], "graph_template_item_id", "^[0-9]+$", false, 3); $save["hash"] = get_hash_graph_template($_POST["graph_template_item_id"], "graph_template_item"); $save["graph_template_id"] = form_input_validate($_POST["graph_template_id"], "graph_template_id", "^[0-9]+$", false, 3); $save["local_graph_id"] = 0; $save["task_item_id"] = form_input_validate(((isset($item["task_item_id"]) ? $item["task_item_id"] : (isset($_POST["task_item_id"]) ? $_POST["task_item_id"] : 0))), "task_item_id", "^[0-9]+$", true, 3); $save["color_id"] = form_input_validate(((isset($item["color_id"]) ? $item["color_id"] : (isset($_POST["color_id"]) ? $_POST["color_id"] : 0))), "color_id", "^[0-9]+$", true, 3); $save["alpha"] = form_input_validate(((isset($item["alpha"]) ? $item["alpha"] : (isset($_POST["alpha"]) ? $_POST["alpha"] : "FF"))), "alpha", "^[a-fA-F0-9]+$", true, 3); $save["graph_type_id"] = form_input_validate(((isset($item["graph_type_id"]) ? $item["graph_type_id"] : (isset($_POST["graph_type_id"]) ? $_POST["graph_type_id"] : 0))), "graph_type_id", "^[0-9]+$", true, 3); if (isset($_POST["line_width"]) || isset($item["line_width"])) { $save["line_width"] = form_input_validate((isset($item["line_width"]) ? $item["line_width"] : $_POST["line_width"]), "line_width", "^[0-9]+[\.,]+[0-9]+$", true, 3); }else { # make sure to transfer old LINEx style into line_width on save switch ($save["graph_type_id"]) { case GRAPH_ITEM_TYPE_LINE1: $save["line_width"] = 1; break; case GRAPH_ITEM_TYPE_LINE2: $save["line_width"] = 2; break; case GRAPH_ITEM_TYPE_LINE3: $save["line_width"] = 3; break; default: $save["line_width"] = 0; } } $save["dashes"] = form_input_validate((isset($_POST["dashes"]) ? $_POST["dashes"] : ""), "dashes", "^[0-9]+[,0-9]*$", true, 3); $save["dash_offset"] = form_input_validate((isset($_POST["dash_offset"]) ? $_POST["dash_offset"] : ""), "dash_offset", "^[0-9]+$", true, 3); $save["cdef_id"] = form_input_validate(((isset($item["cdef_id"]) ? $item["cdef_id"] : (isset($_POST["cdef_id"]) ? $_POST["cdef_id"] : 0))), "cdef_id", "^[0-9]+$", true, 3); $save["vdef_id"] = form_input_validate(((isset($item["vdef_id"]) ? $item["vdef_id"] : (isset($_POST["vdef_id"]) ? $_POST["vdef_id"] : 0))), "vdef_id", "^[0-9]+$", true, 3); $save["shift"] = form_input_validate((isset($_POST["shift"]) ? $_POST["shift"] : ""), "shift", "^((on)|)$", true, 3); $save["consolidation_function_id"] = form_input_validate(((isset($item["consolidation_function_id"]) ? $item["consolidation_function_id"] : (isset($_POST["consolidation_function_id"]) ? $_POST["consolidation_function_id"] : 0))), "consolidation_function_id", "^[0-9]+$", true, 3); $save["textalign"] = form_input_validate((isset($_POST["textalign"]) ? $_POST["textalign"] : ""), "textalign", "^[a-z]+$", true, 3); $save["text_format"] = form_input_validate(((isset($item["text_format"]) ? $item["text_format"] : (isset($_POST["text_format"]) ? $_POST["text_format"] : ""))), "text_format", "", true, 3); $save["value"] = form_input_validate((isset($_POST["value"]) ? $_POST["value"] : ""), "value", "", true, 3); $save["hard_return"] = form_input_validate(((isset($item["hard_return"]) ? $item["hard_return"] : (isset($_POST["hard_return"]) ? $_POST["hard_return"] : ""))), "hard_return", "", true, 3); $save["gprint_id"] = form_input_validate(((isset($item["gprint_id"]) ? $item["gprint_id"] : (isset($_POST["gprint_id"]) ? $_POST["gprint_id"] : 0))), "gprint_id", "^[0-9]+$", true, 3); /* generate a new sequence if needed */ if (empty($_POST["sequence"])) { $_POST["sequence"] = get_sequence($_POST["sequence"], "sequence", "graph_templates_item", "graph_template_id=" . $_POST["graph_template_id"] . " and local_graph_id=0"); } $save["sequence"] = form_input_validate($_POST["sequence"], "sequence", "^[0-9]+$", false, 3); if (!is_error_message()) { /* Before we save the item, let's get a look at task_item_id <-> input associations */ $orig_data_source_graph_inputs = db_fetch_assoc("select graph_template_input.id, graph_template_input.name, graph_templates_item.task_item_id from (graph_template_input,graph_template_input_defs,graph_templates_item) where graph_template_input.id=graph_template_input_defs.graph_template_input_id and graph_template_input_defs.graph_template_item_id=graph_templates_item.id and graph_template_input.graph_template_id=" . $save["graph_template_id"] . " and graph_template_input.column_name='task_item_id' group by graph_templates_item.task_item_id"); $orig_data_source_to_input = array_rekey($orig_data_source_graph_inputs, "task_item_id", "id"); $graph_template_item_id = sql_save($save, "graph_templates_item"); if ($graph_template_item_id) { raise_message(1); if (!empty($save["task_item_id"])) { /* old item clean-up. Don't delete anything if the item <-> task_item_id association remains the same. */ if ($_POST["hidden_task_item_id"] != $_POST["task_item_id"]) { /* It changed. Delete any old associations */ db_execute("delete from graph_template_input_defs where graph_template_item_id=$graph_template_item_id"); /* Input for current data source exists and has changed. Update the association */ if (isset($orig_data_source_to_input{$save["task_item_id"]})) { db_execute("REPLACE INTO graph_template_input_defs " . "(graph_template_input_id, graph_template_item_id) " . "VALUES (" . $orig_data_source_to_input{$save["task_item_id"]} . "," . $graph_template_item_id . ")"); } } /* an input for the current data source does NOT currently exist, let's create one */ if (!isset($orig_data_source_to_input{$save["task_item_id"]})) { $ds_name = db_fetch_cell("select data_source_name from data_template_rrd where id=" . $_POST["task_item_id"]); db_execute("REPLACE INTO graph_template_input " . "(hash,graph_template_id,name,column_name) " . "VALUES ('" . get_hash_graph_template(0, "graph_template_input") . "'," . $save["graph_template_id"] . "," . "'Data Source [" . $ds_name . "]'," . 'task_item_id' . ")"); $graph_template_input_id = db_fetch_insert_id(); $graph_items = db_fetch_assoc("select id from graph_templates_item where graph_template_id=" . $save["graph_template_id"] . " and task_item_id=" . $_POST["task_item_id"]); if (sizeof($graph_items) > 0) { foreach ($graph_items as $graph_item) { db_execute("REPLACE INTO graph_template_input_defs " . "(graph_template_input_id,graph_template_item_id) " . "VALUES (" . $graph_template_input_id . "," . $graph_item["id"] . ")"); } } } } push_out_graph_item($graph_template_item_id); if (isset($_POST["task_item_id"]) && isset($orig_data_source_to_input{$_POST["task_item_id"]})) { /* make sure all current graphs using this graph input are aware of this change */ push_out_graph_input($orig_data_source_to_input{$_POST["task_item_id"]}, $graph_template_item_id, array($graph_template_item_id => $graph_template_item_id)); } }else{ raise_message(2); } } $_POST["sequence"] = 0; } if (is_error_message()) { header("Location: graph_templates_items.php?action=item_edit&graph_template_item_id=" . (empty($graph_template_item_id) ? $_POST["graph_template_item_id"] : $graph_template_item_id) . "&id=" . $_POST["graph_template_id"]); }else{ header("Location: graph_templates.php?action=template_edit&id=" . $_POST["graph_template_id"] . "&template_id=" . $_POST["graph_template_id"] . "&tab=items"); } exit; } }
function form_save() { if (isset($_POST['save_component_item'])) { /* ================= input validation ================= */ input_validate_input_number(get_request_var_post('graph_template_id')); input_validate_input_number(get_request_var_post('graph_template_item_id')); input_validate_input_number(get_request_var_post('task_item_id')); /* ==================================================== */ global $graph_item_types; $items[0] = array(); if ($graph_item_types[$_POST['graph_type_id']] == 'LEGEND') { /* this can be a major time saver when creating lots of graphs with the typical GPRINT LAST/AVERAGE/MAX legends */ $items = array(0 => array('color_id' => '0', 'graph_type_id' => '9', 'consolidation_function_id' => '4', 'text_format' => 'Current:', 'hard_return' => ''), 1 => array('color_id' => '0', 'graph_type_id' => '9', 'consolidation_function_id' => '1', 'text_format' => 'Average:', 'hard_return' => ''), 2 => array('color_id' => '0', 'graph_type_id' => '9', 'consolidation_function_id' => '3', 'text_format' => 'Maximum:', 'hard_return' => 'on')); } foreach ($items as $item) { /* generate a new sequence if needed */ if (empty($_POST['sequence'])) { $_POST['sequence'] = get_sequence($_POST['sequence'], 'sequence', 'graph_templates_item', 'graph_template_id=' . $_POST['graph_template_id'] . ' AND local_graph_id=0'); } $save['id'] = $_POST['graph_template_item_id']; $save['hash'] = get_hash_graph_template($_POST['graph_template_item_id'], 'graph_template_item'); $save['graph_template_id'] = $_POST['graph_template_id']; $save['local_graph_id'] = 0; $save['task_item_id'] = form_input_validate($_POST['task_item_id'], 'task_item_id', '', true, 3); $save['color_id'] = form_input_validate(isset($item['color_id']) ? $item['color_id'] : $_POST['color_id'], 'color_id', '', true, 3); /* if alpha is disabled, use invisible_alpha instead */ if (!isset($_POST['alpha'])) { $_POST['alpha'] = $_POST['invisible_alpha']; } $save['alpha'] = form_input_validate(isset($item['alpha']) ? $item['alpha'] : $_POST['alpha'], 'alpha', '', true, 3); $save['graph_type_id'] = form_input_validate(isset($item['graph_type_id']) ? $item['graph_type_id'] : $_POST['graph_type_id'], 'graph_type_id', '', true, 3); $save['cdef_id'] = form_input_validate($_POST['cdef_id'], 'cdef_id', '', true, 3); $save['consolidation_function_id'] = form_input_validate(isset($item['consolidation_function_id']) ? $item['consolidation_function_id'] : $_POST['consolidation_function_id'], 'consolidation_function_id', '', true, 3); $save['text_format'] = form_input_validate(isset($item['text_format']) ? $item['text_format'] : $_POST['text_format'], 'text_format', '', true, 3); $save['value'] = form_input_validate($_POST['value'], 'value', '', true, 3); $save['hard_return'] = form_input_validate(isset($item['hard_return']) ? $item['hard_return'] : (isset($_POST['hard_return']) ? $_POST['hard_return'] : ''), 'hard_return', '', true, 3); $save['gprint_id'] = form_input_validate($_POST['gprint_id'], 'gprint_id', '', true, 3); $save['sequence'] = $_POST['sequence']; if (!is_error_message()) { /* Before we save the item, let's get a look at task_item_id <-> input associations */ $orig_data_source_graph_inputs = db_fetch_assoc_prepared("SELECT\n\t\t\t\t\tgraph_template_input.id,\n\t\t\t\t\tgraph_template_input.name,\n\t\t\t\t\tgraph_templates_item.task_item_id\n\t\t\t\t\tFROM (graph_template_input, graph_template_input_defs, graph_templates_item)\n\t\t\t\t\tWHERE graph_template_input.id = graph_template_input_defs.graph_template_input_id\n\t\t\t\t\tAND graph_template_input_defs.graph_template_item_id = graph_templates_item.id\n\t\t\t\t\tAND graph_template_input.graph_template_id = ?\n\t\t\t\t\tAND graph_template_input.column_name = 'task_item_id'\n\t\t\t\t\tGROUP BY graph_templates_item.task_item_id", array($save['graph_template_id'])); $orig_data_source_to_input = array_rekey($orig_data_source_graph_inputs, 'task_item_id', 'id'); $graph_template_item_id = sql_save($save, 'graph_templates_item'); if ($graph_template_item_id) { raise_message(1); if (!empty($save['task_item_id'])) { /* old item clean-up. Don't delete anything if the item <-> task_item_id association remains the same. */ if ($_POST['_task_item_id'] != $_POST['task_item_id']) { /* It changed. Delete any old associations */ db_execute_prepared('DELETE FROM graph_template_input_defs WHERE graph_template_item_id = ?', array($graph_template_item_id)); /* Input for current data source exists and has changed. Update the association */ if (isset($orig_data_source_to_input[$save['task_item_id']])) { db_execute_prepared('REPLACE INTO graph_template_input_defs (graph_template_input_id, graph_template_item_id) values (?, ?)', array($orig_data_source_to_input[$save['task_item_id']], $graph_template_item_id)); } } /* an input for the current data source does NOT currently exist, let's create one */ if (!isset($orig_data_source_to_input[$save['task_item_id']])) { $ds_name = db_fetch_cell_prepared('SELECT data_source_name FROM data_template_rrd WHERE id = ?', array($_POST['task_item_id'])); db_execute_prepared("REPLACE INTO graph_template_input (hash, graph_template_id, name, column_name) VALUES (?, ?, ?, 'task_item_id')", array(get_hash_graph_template(0, 'graph_template_input'), $save['graph_template_id'], 'Data Source [$ds_name]')); $graph_template_input_id = db_fetch_insert_id(); $graph_items = db_fetch_assoc_prepared('SELECT id FROM graph_templates_item WHERE graph_template_id = ? AND task_item_id = ?', array($save['graph_template_id'], $_POST['task_item_id'])); if (sizeof($graph_items) > 0) { foreach ($graph_items as $graph_item) { db_execute_prepared('REPLACE INTO graph_template_input_defs (graph_template_input_id, graph_template_item_id) VALUES (?, ?)', array($graph_template_input_id, $graph_item['id'])); } } } } push_out_graph_item($graph_template_item_id); if (isset($orig_data_source_to_input[$_POST['task_item_id']])) { /* make sure all current graphs using this graph input are aware of this change */ push_out_graph_input($orig_data_source_to_input[$_POST['task_item_id']], $graph_template_item_id, array($graph_template_item_id => $graph_template_item_id)); } } else { raise_message(2); } } $_POST['sequence'] = 0; } if (is_error_message()) { header('Location: graph_templates_items.php?action=item_edit&graph_template_item_id=' . (empty($graph_template_item_id) ? $_POST['graph_template_item_id'] : $graph_template_item_id) . '&id=' . $_POST['graph_template_id']); exit; } else { header('Location: graph_templates.php?action=template_edit&id=' . $_POST['graph_template_id']); exit; } } }