";
diff --git a/data_sources.php b/data_sources.php
index 44d366126..bf3d2ffda 100644
--- a/data_sources.php
+++ b/data_sources.php
@@ -31,9 +31,8 @@ include_once ('include/form.php');
switch ($_REQUEST["action"]) {
case 'save':
- $redirect_location = form_save();
+ form_save();
- header ("Location: $redirect_location"); exit;
break;
case 'data_edit':
include_once ("include/top_header.php");
@@ -69,27 +68,145 @@ switch ($_REQUEST["action"]) {
-------------------------- */
function form_save() {
- if ((isset($_POST["save_component_data_source"])) && (isset($_POST["save_component_data"]))) {
- $url = ds_save();
- data_save();
+ include_once ("include/utility_functions.php");
+
+ if (isset($_POST["save_component_data_source"])) {
+ $save["id"] = $_POST["local_data_id"];
+ $save["data_template_id"] = $_POST["data_template_id"];
+ $save["host_id"] = $_POST["host_id"];
- if (is_error_message()) {
- return $_SERVER["HTTP_REFERER"];
- }elseif (($_POST["data_template_id"] != $_POST["_data_template_id"]) || ($_POST["host_id"] != $_POST["_host_id"])) {
- return $url;
- }else{
- return "data_sources.php";
- }
- }elseif (isset($_POST["save_component_data_source"])) {
- return ds_save();
- }elseif (isset($_POST["save_component_data"])) {
- data_save();
+ $local_data_id = sql_save($save, "data_local");
+ unset($save);
- if (read_config_option("full_view_data_source") == "") {
- return "data_sources.php?action=ds_edit&local_data_id=" . $_POST["local_data_id"] . "&view_rrd=" . $_POST["current_rrd"];
- }elseif (read_config_option("full_view_data_source") == "on") {
- return "data_sources.php";
+ $save["id"] = $_POST["data_template_data_id"];
+ $save["local_data_template_data_id"] = $_POST["local_data_template_data_id"];
+ $save["local_data_id"] = $local_data_id;
+ $save["data_template_id"] = form_input_validate($_POST["data_template_id"], "data_template_id", "", true, 3);
+ $save["data_input_id"] = form_input_validate($_POST["data_input_id"], "data_input_id", "", true, 3);
+ $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
+ $save["data_source_path"] = form_input_validate($_POST["data_source_path"], "data_source_path", "", true, 3);
+ $save["active"] = form_input_validate($_POST["active"], "active", "", true, 3);
+ $save["rrd_step"] = form_input_validate($_POST["rrd_step"], "rrd_step", "^[0-9]+$", false, 3);
+
+ if (!is_error_message()) {
+ $data_template_data_id = sql_save($save, "data_template_data");
+
+ if ($data_template_data_id) {
+ raise_message(1);
+
+ /* if no data source path has been entered, generate one */
+ if (empty($_POST["data_source_path"])) {
+ generate_data_source_path($local_data_id);
+ }
+
+ /* save entried in 'selected rras' field */
+ db_execute("delete from data_template_data_rra where data_template_data_id=$data_template_data_id");
+
+ for ($i=0; ($i < count($_POST["rra_id"])); $i++) {
+ db_execute("insert into data_template_data_rra (rra_id,data_template_data_id)
+ values (" . $_POST["rra_id"][$i] . ",$data_template_data_id)");
+ }
+ }else{
+ raise_message(2);
+ }
}
+
+ unset($save);
+
+ /* if this is a new data source and a template has been selected, skip item creation this time
+ otherwise it throws off the templatate creation because of the NULL data */
+ if ($_POST["data_template_id"] == $_POST["_data_template_id"]) {
+ $save["id"] = $_POST["data_template_rrd_id"];
+ $save["local_data_template_rrd_id"] = $_POST["local_data_template_rrd_id"];
+ $save["local_data_id"] = $local_data_id;
+ $save["data_template_id"] = form_input_validate($_POST["data_template_id"], "data_template_id", "", true, 3);
+ $save["rrd_maximum"] = form_input_validate($_POST["rrd_maximum"], "rrd_maximum", "^[0-9]+$", false, 3);
+ $save["rrd_minimum"] = form_input_validate($_POST["rrd_minimum"], "rrd_minimum", "^[0-9]+$", false, 3);
+ $save["rrd_heartbeat"] = form_input_validate($_POST["rrd_heartbeat"], "rrd_heartbeat", "^[0-9]+$", false, 3);
+ $save["data_source_type_id"] = $_POST["data_source_type_id"];
+ $save["data_source_name"] = form_input_validate($_POST["data_source_name"], "data_source_name", "^[a-zA-Z0-9_]{1,19}$", false, 3);
+ $save["data_input_field_id"] = $_POST["data_input_field_id"];
+
+ if (!is_error_message()) {
+ $data_template_rrd_id = sql_save($save, "data_template_rrd");
+
+ if ($data_template_rrd_id) {
+ raise_message(1);
+ }else{
+ raise_message(2);
+ }
+ }
+ }
+
+ if (!is_error_message()) {
+ update_poller_cache($local_data_id);
+
+ if ($_POST["host_id"] != $_POST["_host_id"]) {
+ /* push out all nessesary host information */
+ push_out_host($_POST["host_id"]);
+
+ /* reset current host for display purposes */
+ $_SESSION["sess_data_source_current_host_id"] = $_POST["host_id"];
+ }
+
+ if ($_POST["data_template_id"] != $_POST["_data_template_id"]) {
+ /* update all nessesary template information */
+ change_data_template($local_data_id, $_POST["data_template_id"]);
+ }
+ }
+ }
+
+ if ((isset($_POST["save_component_data"])) && (!is_error_message())) {
+ /* ok, first pull out all 'input' values so we know how much to save */
+ $input_fields = db_fetch_assoc("select
+ data_template_data.data_input_id,
+ data_local.host_id
+ data_input_fields.id,
+ data_input_fields.input_output,
+ data_input_fields.data_name,
+ data_input_fields.regexp_match,
+ data_input_fields.allow_nulls,
+ data_input_fields.type_code
+ from data_template_data
+ left join data_input_fields on data_input_fields.data_input_id=data_template_data.data_input_id
+ left join data_local on data_template_data.local_data_id=data_local.id
+ where data_template_data.id=" . $_POST["data_template_data_id"] . "
+ and data_input_fields.input_output='in'");
+
+ if (sizeof($input_fields) > 0) {
+ foreach ($input_fields as $input_field) {
+ /* save the data into the 'data_input_data' table */
+ $form_name = "value_" . $input_field["data_name"];
+ $form_value = $_POST[$form_name];
+
+ if (isset($_POST[$form_name])) {
+ if ($input_field["allow_nulls"] == "on") {
+ $allow_nulls = true;
+ }elseif (empty($input_field["allow_nulls"])) {
+ $allow_nulls = false;
+ }
+
+ /* run regexp match on input string */
+ $form_value = form_input_validate($form_value, $form_name, $input_field["regexp_match"], $allow_nulls, 3);
+
+ /* make sure we don't overwrite 'host fields' */
+ if ((!is_error_message()) && ((empty($input_field["host_id"]) || (empty($input_field["type_code"]))))) {
+ db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,t_value,value) values
+ (" . $input_field["id"] . "," . $_POST["data_template_data_id"] . ",'" . db_fetch_cell("select t_value from data_input_data where data_input_field_id=" . $input_field["id"] . " and data_template_data_id=" . $_POST["data_template_data_id"]) . "','$form_value')");
+ }
+ }
+ }
+ }
+
+ if ((read_config_option("full_view_data_source") == "") && (is_error_message())) {
+ /* ds data edit page */
+ }
+ }
+
+ if ((is_error_message()) || ($_POST["data_template_id"] != $_POST["_data_template_id"]) || ($_POST["host_id"] != $_POST["_host_id"])) {
+ header ("Location: data_sources.php?action=ds_edit&local_data_id=" . (empty($local_data_id) ? $_POST["local_data_id"] : $local_data_id) . "&host_id=" . $_POST["host_id"] . "&view_rrd=" . $_POST["view_rrd"]);
+ }else{
+ header ("Location: data_sources.php");
}
}
@@ -125,54 +242,9 @@ function draw_data_form_select($main_action) {
data - Custom Data
---------------------------- */
-function data_save() {
- /* ok, first pull out all 'input' values so we know how much to save */
- $input_fields = db_fetch_assoc("select
- data_template_data.data_input_id,
- data_local.host_id
- data_input_fields.id,
- data_input_fields.input_output,
- data_input_fields.data_name,
- data_input_fields.regexp_match,
- data_input_fields.allow_nulls,
- data_input_fields.type_code
- from data_template_data
- left join data_input_fields on data_input_fields.data_input_id=data_template_data.data_input_id
- left join data_local on data_template_data.local_data_id=data_local.id
- where data_template_data.id=" . $_POST["data_template_data_id"] . "
- and data_input_fields.input_output='in'");
-
- if (sizeof($input_fields) > 0) {
- foreach ($input_fields as $input_field) {
- /* save the data into the 'data_input_data' table */
- $form_name = "value_" . $input_field["data_name"];
- $form_value = $_POST[$form_name];
-
- if (isset($_POST[$form_name])) {
- if ($input_field["allow_nulls"] == "on") {
- $allow_nulls = true;
- }elseif (empty($input_field["allow_nulls"])) {
- $allow_nulls = false;
- }
-
- /* run regexp match on input string */
- $form_value = form_input_validate($form_value, $form_name, $input_field["regexp_match"], $allow_nulls, 3);
-
- /* make sure we don't overwrite 'host fields' */
- if ((!is_error_message()) && ((empty($input_field["host_id"]) || (empty($input_field["type_code"]))))) {
- db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,t_value,value) values
- (" . $input_field["id"] . "," . $_POST["data_template_data_id"] . ",'" . db_fetch_cell("select t_value from data_input_data where data_input_field_id=" . $input_field["id"] . " and data_template_data_id=" . $_POST["data_template_data_id"]) . "','$form_value')");
- }
- }
- }
- }
-}
-
function data_edit() {
global $config, $colors;
- display_output_messages();
-
if (isset($_GET["local_data_id"])) {
$data = db_fetch_row("select id,data_input_id,data_template_id,name from data_template_data where local_data_id=" . $_GET["local_data_id"]);
$template_data = db_fetch_row("select id,data_input_id from data_template_data where data_template_id=" . $data["data_template_id"] . " and local_data_id=0");
@@ -246,16 +318,7 @@ function data_edit() {
form_hidden_box("save_component_data","1","");
if (read_config_option("full_view_data_source") == "") {
- start_box("", "98%", $colors["header"], "3", "center", "");
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
- Data Sources", "98%", $colors["header"], "3", "center", "data_sources.php?action=ds_edit");
?>
diff --git a/data_templates.php b/data_templates.php
index 10a0aee50..7d9f72200 100644
--- a/data_templates.php
+++ b/data_templates.php
@@ -30,9 +30,8 @@ include_once ("include/config_arrays.php");
switch ($_REQUEST["action"]) {
case 'save':
- $redirect_location = form_save();
+ form_save();
- header ("Location: $redirect_location"); exit;
break;
case 'template_remove':
template_remove();
@@ -60,10 +59,128 @@ switch ($_REQUEST["action"]) {
-------------------------- */
function form_save() {
- global $config;
+ include_once ("include/utility_functions.php");
if (isset($_POST["save_component_template"])) {
- return template_save();
+ /* save: data_template */
+ $save["id"] = $_POST["data_template_id"];
+ $save["name"] = form_input_validate($_POST["template_name"], "template_name", "", false, 3);
+ $save["graph_template_id"] = 0;
+
+ if (!is_error_message()) {
+ $data_template_id = sql_save($save, "data_template");
+
+ if ($data_template_id) {
+ raise_message(1);
+ }else{
+ raise_message(2);
+ }
+ }
+
+ unset ($save);
+
+ /* save: data_template_data */
+ $save["id"] = $_POST["data_template_data_id"];
+ $save["local_data_template_data_id"] = 0;
+ $save["local_data_id"] = 0;
+ $save["data_template_id"] = $data_template_id;
+ $save["data_input_id"] = form_input_validate($_POST["data_input_id"], "data_input_id", "", true, 3);
+ $save["t_name"] = form_input_validate($_POST["t_name"], "t_name", "", true, 3);
+ $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
+ $save["t_active"] = form_input_validate($_POST["t_active"], "t_active", "", true, 3);
+ $save["active"] = form_input_validate($_POST["active"], "active", "", true, 3);
+ $save["t_rrd_step"] = form_input_validate($_POST["t_rrd_step"], "t_rrd_step", "", true, 3);
+ $save["rrd_step"] = form_input_validate($_POST["rrd_step"], "rrd_step", "^[0-9]+$", false, 3);
+ $save["t_rra_id"] = form_input_validate($_POST["t_rra_id"], "t_rra_id", "", true, 3);
+
+ if (!is_error_message()) {
+ $data_template_data_id = sql_save($save, "data_template_data");
+
+ if ($data_template_data_id) {
+ raise_message(1);
+ }else{
+ raise_message(2);
+ }
+ }
+
+ unset ($save);
+
+ /* save: data_template_rrd */
+ $save["id"] = $_POST["data_template_rrd_id"];
+ $save["local_data_template_rrd_id"] = 0;
+ $save["local_data_id"] = 0;
+ $save["data_template_id"] = $data_template_id;
+ $save["t_rrd_maximum"] = form_input_validate($_POST["t_rrd_maximum"], "t_rrd_maximum", "", true, 3);
+ $save["rrd_maximum"] = form_input_validate($_POST["rrd_maximum"], "rrd_maximum", "^[0-9]+$", false, 3);
+ $save["t_rrd_minimum"] = form_input_validate($_POST["t_rrd_minimum"], "t_rrd_minimum", "", true, 3);
+ $save["rrd_minimum"] = form_input_validate($_POST["rrd_minimum"], "rrd_minimum", "^[0-9]+$", false, 3);
+ $save["t_rrd_heartbeat"] = form_input_validate($_POST["t_rrd_heartbeat"], "t_rrd_heartbeat", "", true, 3);
+ $save["rrd_heartbeat"] = form_input_validate($_POST["rrd_heartbeat"], "rrd_heartbeat", "^[0-9]+$", false, 3);
+ $save["t_data_source_type_id"] = form_input_validate($_POST["t_data_source_type_id"], "t_data_source_type_id", "", true, 3);
+ $save["data_source_type_id"] = form_input_validate($_POST["data_source_type_id"], "data_source_type_id", "", true, 3);
+ $save["t_data_source_name"] = form_input_validate($_POST["t_data_source_name"], "t_data_source_name", "", true, 3);
+ $save["data_source_name"] = form_input_validate($_POST["data_source_name"], "data_source_name", "^[a-zA-Z0-9_]{1,19}$", false, 3);
+ $save["data_input_field_id"] = $_POST["data_input_field_id"];
+
+ if (!is_error_message()) {
+ $data_template_rrd_id = sql_save($save, "data_template_rrd");
+
+ if ($data_template_rrd_id) {
+ raise_message(1);
+ }else{
+ raise_message(2);
+ }
+ }
+
+ if (!is_error_message()) {
+ /* save entried in 'selected rras' field */
+ db_execute("delete from data_template_data_rra where data_template_data_id=$data_template_data_id");
+
+ for ($i=0; ($i < count($_POST["rra_id"])); $i++) {
+ db_execute("insert into data_template_data_rra (rra_id,data_template_data_id)
+ values (" . $_POST["rra_id"][$i] . ",$data_template_data_id)");
+ }
+
+ /* push out all data source settings to child data source using this template */
+ push_out_data_source($data_template_data_id);
+ push_out_data_source_item($data_template_rrd_id);
+
+ /* ok, first pull out all 'input' values so we know how much to save */
+ $input_fields = db_fetch_assoc("select
+ id,
+ input_output,
+ data_name
+ from data_input_fields
+ where data_input_id=" . $_POST["data_input_id"] . "
+ and input_output='in'");
+
+ db_execute("delete from data_input_data where data_template_data_id=$data_template_data_id");
+
+ if (sizeof($input_fields) > 0) {
+ foreach ($input_fields as $input_field) {
+ /* save the data into the 'host_template_data' table */
+ $form_value = "value_" . $input_field["data_name"];
+ $form_value = $_POST[$form_value];
+
+ $form_is_templated_value = "t_value_" . $input_field["data_name"];
+ $form_is_templated_value = $_POST[$form_is_templated_value];
+
+ if ((!empty($form_value)) || (!empty($form_is_templated_value))) {
+ db_execute("insert into data_input_data (data_input_field_id,data_template_data_id,t_value,value)
+ values (" . $input_field["id"] . ",$data_template_data_id,'$form_is_templated_value','$form_value')");
+ }
+ }
+ }
+
+ /* push out all "custom data" for this data source template */
+ push_out_data_template($data_template_id);
+ }
+
+ if ((is_error_message()) || (empty($_POST["data_template_id"]))) {
+ header ("Location: data_templates.php?action=template_edit&data_template_id=" . (empty($data_template_id) ? $_POST["data_template_id"] : $data_template_id)) . "&view_rrd=" . ($_POST["current_rrd"] ? $_POST["current_rrd"] : $data_template_rrd_id);
+ }else{
+ header ("Location: data_templates.php");
+ }
}
}
@@ -72,8 +189,6 @@ function form_save() {
---------------------------- */
function template_remove() {
- global $config;
-
if ((read_config_option("remove_verification") == "on") && ($_GET["confirm"] != "yes")) {
include ('include/top_header.php');
form_confirm("Are You Sure?", "Are you sure you want to delete the data template '" . db_fetch_cell("select name from data_template where id=" . $_GET["data_template_id"]) . "'? This is generally not a good idea if you have data sources attached to this template even though it should not affect any data sources.", getenv("HTTP_REFERER"), "data_templates.php?action=template_remove&data_template_id=" . $_GET["data_template_id"]);
@@ -93,105 +208,6 @@ function template_remove() {
}
}
-function template_save() {
- include_once ("include/utility_functions.php");
-
- if ($_POST["rrd_maximum"] == "") { $_POST["rrd_maximum"] = 0; }
- if ($_POST["rrd_minimum"] == "") { $_POST["rrd_minimum"] = 0; }
-
- /* save: data_template */
- $save["id"] = $_POST["data_template_id"];
- $save["name"] = $_POST["template_name"];
- $save["graph_template_id"] = 0;
-
- $data_template_id = sql_save($save, "data_template");
- unset ($save);
-
- /* save: data_template_data */
- $save["id"] = $_POST["data_template_data_id"];
- $save["local_data_template_data_id"] = 0;
- $save["local_data_id"] = 0;
- $save["data_template_id"] = $data_template_id;
- $save["data_input_id"] = $_POST["data_input_id"];
- $save["t_name"] = $_POST["t_name"];
- $save["name"] = $_POST["name"];
- $save["t_active"] = $_POST["t_active"];
- $save["active"] = $_POST["active"];
- $save["t_rrd_step"] = $_POST["t_rrd_step"];
- $save["rrd_step"] = $_POST["rrd_step"];
- $save["t_rra_id"] = $_POST["t_rra_id"];
-
- $data_template_data_id = sql_save($save, "data_template_data");
- unset ($save);
-
- /* save: data_template_rrd */
- $save["id"] = $_POST["data_template_rrd_id"];
- $save["local_data_template_rrd_id"] = 0;
- $save["local_data_id"] = 0;
- $save["data_template_id"] = $data_template_id;
- $save["t_rrd_maximum"] = $_POST["t_rrd_maximum"];
- $save["rrd_maximum"] = $_POST["rrd_maximum"];
- $save["t_rrd_minimum"] = $_POST["t_rrd_minimum"];
- $save["rrd_minimum"] = $_POST["rrd_minimum"];
- $save["t_rrd_heartbeat"] = $_POST["t_rrd_heartbeat"];
- $save["rrd_heartbeat"] = $_POST["rrd_heartbeat"];
- $save["t_data_source_type_id"] = $_POST["t_data_source_type_id"];
- $save["data_source_type_id"] = $_POST["data_source_type_id"];
- $save["t_data_source_name"] = $_POST["t_data_source_name"];
- $save["data_source_name"] = $_POST["data_source_name"];
- $save["data_input_field_id"] = $_POST["data_input_field_id"];
-
- $data_template_rrd_id = sql_save($save, "data_template_rrd");
-
- /* save entried in 'selected rras' field */
- db_execute("delete from data_template_data_rra where data_template_data_id=$data_template_data_id");
-
- for ($i=0; ($i < count($_POST["rra_id"])); $i++) {
- db_execute("insert into data_template_data_rra (rra_id,data_template_data_id)
- values (" . $_POST["rra_id"][$i] . ",$data_template_data_id)");
- }
-
- /* push out all data source settings to child data source using this template */
- push_out_data_source($data_template_data_id);
- push_out_data_source_item($data_template_rrd_id);
-
- /* ok, first pull out all 'input' values so we know how much to save */
- $input_fields = db_fetch_assoc("select
- id,
- input_output,
- data_name
- from data_input_fields
- where data_input_id=" . $_POST["data_input_id"] . "
- and input_output='in'");
-
- db_execute("delete from data_input_data where data_template_data_id=$data_template_data_id");
-
- if (sizeof($input_fields) > 0) {
- foreach ($input_fields as $input_field) {
- /* save the data into the 'host_template_data' table */
- $form_value = "value_" . $input_field["data_name"];
- $form_value = $_POST[$form_value];
-
- $form_is_templated_value = "t_value_" . $input_field["data_name"];
- $form_is_templated_value = $_POST[$form_is_templated_value];
-
- if ((!empty($form_value)) || (!empty($form_is_templated_value))) {
- db_execute("insert into data_input_data (data_input_field_id,data_template_data_id,t_value,value)
- values (" . $input_field["id"] . ",$data_template_data_id,'$form_is_templated_value','$form_value')");
- }
- }
- }
-
- /* push out all "custom data" for this data source template */
- push_out_data_template($data_template_id);
-
- if (empty($_POST["data_template_id"])) {
- return "data_templates.php?action=template_edit&data_template_id=" . $data_template_id . "&view_rrd=" . ($_POST["current_rrd"] ? $_POST["current_rrd"] : $data_template_rrd_id);
- }else{
- return "data_templates.php";
- }
-}
-
function template_edit() {
global $colors, $struct_data_source, $struct_data_source_item, $data_source_types;
@@ -343,16 +359,7 @@ function template_edit() {
form_hidden_id("current_rrd",$_GET["view_rrd"]);
form_hidden_box("save_component_template","1","");
- start_box("", "98%", $colors["header"], "3", "center", "");
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/graphs.php b/graphs.php
index f1f426ad3..5be92076a 100644
--- a/graphs.php
+++ b/graphs.php
@@ -32,9 +32,8 @@ define("ROWS_PER_PAGE", 30);
switch ($_REQUEST["action"]) {
case 'save':
- $redirect_location = form_save();
+ form_save();
- header ("Location: $redirect_location"); exit;
break;
case 'graph_diff':
include_once ("include/top_header.php");
@@ -133,28 +132,142 @@ function draw_graph_form_select($main_action) {
-------------------------- */
function form_save() {
- if ((isset($_POST["save_component_input"])) && (isset($_POST["save_component_graph"]))) {
- graph_save();
- input_save();
- return "graphs.php?action=graph_edit&local_graph_id=" . $_POST["local_graph_id"];
- }elseif (isset($_POST["save_component_graph"])) {
- graph_save();
- return "graphs.php?action=graph_edit&local_graph_id=" . $_POST["local_graph_id"];
- }elseif (isset($_POST["save_component_input"])) {
- input_save();
- return "graphs.php?action=item&local_graph_id=" . $_POST["local_graph_id"];
- }elseif (isset($_POST["save_component_graph_diff"])) {
- graph_diff_save();
- return "graphs.php?action=graph_edit&local_graph_id=" . $_POST["local_graph_id"];
- }elseif (isset($_POST["save_component_item"])) {
- item_save();
+ include_once ("include/utility_functions.php");
+
+ if (isset($_POST["save_component_graph"])) {
+ $save["id"] = $_POST["local_graph_id"];
+ $save["graph_template_id"] = $_POST["graph_template_id"];
- if (read_config_option("full_view_graph") == "") {
- return "graphs.php?action=item&local_graph_id=" . $_POST["local_graph_id"];
- }else{
- return "graphs.php?action=graph_edit&local_graph_id=" . $_POST["local_graph_id"];
+ $local_graph_id = sql_save($save, "graph_local");
+ unset($save);
+
+ $save["id"] = $_POST["graph_template_graph_id"];
+ $save["local_graph_template_graph_id"] = $_POST["local_graph_template_graph_id"];
+ $save["local_graph_id"] = $local_graph_id;
+ $save["graph_template_id"] = $_POST["graph_template_id"];
+ $save["image_format_id"] = form_input_validate($_POST["image_format_id"], "image_format_id", "", true, 3);
+ $save["title"] = form_input_validate($_POST["title"], "title", "", false, 3);
+ $save["height"] = form_input_validate($_POST["height"], "height", "^[0-9]+$", false, 3);
+ $save["width"] = form_input_validate($_POST["width"], "width", "^[0-9]+$", false, 3);
+ $save["upper_limit"] = form_input_validate($_POST["upper_limit"], "upper_limit", "^[0-9]+$", false, 3);
+ $save["lower_limit"] = form_input_validate($_POST["lower_limit"], "lower_limit", "^[0-9]+$", false, 3);
+ $save["vertical_label"] = form_input_validate($_POST["vertical_label"], "vertical_label", "", true, 3);
+ $save["auto_scale"] = form_input_validate($_POST["auto_scale"], "auto_scale", "", true, 3);
+ $save["auto_scale_opts"] = form_input_validate($_POST["auto_scale_opts"], "auto_scale_opts", "", true, 3);
+ $save["auto_scale_log"] = form_input_validate($_POST["auto_scale_log"], "auto_scale_log", "", true, 3);
+ $save["auto_scale_rigid"] = form_input_validate($_POST["auto_scale_rigid"], "auto_scale_rigid", "", true, 3);
+ $save["auto_padding"] = form_input_validate($_POST["auto_padding"], "auto_padding", "", true, 3);
+ $save["base_value"] = form_input_validate($_POST["base_value"], "base_value", "^[0-9]+$", false, 3);
+ $save["export"] = form_input_validate($_POST["export"], "export", "", true, 3);
+ $save["unit_value"] = form_input_validate($_POST["unit_value"], "unit_value", "", true, 3);
+ $save["unit_exponent_value"] = form_input_validate($_POST["unit_exponent_value"], "unit_exponent_value", "^[0-9]+$", false, 3);
+
+ if (!is_error_message()) {
+ $graph_templates_graph_id = sql_save($save, "graph_templates_graph");
+
+ if ($graph_templates_graph_id) {
+ raise_message(1);
+
+ /* if template information chanegd, update all nessesary template information */
+ if ($_POST["graph_template_id"] != $_POST["_graph_template_id"]) {
+ /* check to see if the number of graph items differs, if it does; we need user input */
+ if ((!empty($_POST["graph_template_id"])) && (sizeof(db_fetch_assoc("select id from graph_templates_item where local_graph_id=$local_graph_id")) != sizeof(db_fetch_assoc("select id from graph_templates_item where local_graph_id=0 and graph_template_id=" . $_POST["graph_template_id"])))) {
+ /* set the template back, since the user may choose not to go through with the change
+ at this point */
+ db_execute("update graph_local set graph_template_id=" . $_POST["_graph_template_id"] . " where id=$local_graph_id");
+ db_execute("update graph_templates_graph set graph_template_id=" . $_POST["_graph_template_id"] . " where local_graph_id=$local_graph_id");
+
+ header("Location: graphs.php?action=graph_diff&local_graph_id=$local_graph_id&graph_template_id=" . $_POST["graph_template_id"]);
+ exit;
+ }
+
+ change_graph_template($local_graph_id, $_POST["graph_template_id"], true);
+ }
+ }else{
+ raise_message(2);
+ }
}
}
+
+ if (isset($_POST["save_component_input"])) {
+ /* first; get the current graph template id */
+ $graph_template_id = db_fetch_cell("select graph_template_id from graph_local where id=" . $_POST["local_graph_id"]);
+
+ /* get all inputs that go along with this graph template */
+ $input_list = db_fetch_assoc("select id,column_name from graph_template_input where graph_template_id=$graph_template_id");
+
+ if (sizeof($input_list) > 0) {
+ foreach ($input_list as $input) {
+ /* we need to find out which graph items will be affected by saving this particular item */
+ $item_list = db_fetch_assoc("select
+ graph_templates_item.id
+ from graph_template_input_defs,graph_templates_item
+ where graph_template_input_defs.graph_template_item_id=graph_templates_item.local_graph_template_item_id
+ and graph_templates_item.local_graph_id=" . $_POST["local_graph_id"] . "
+ and graph_template_input_defs.graph_template_input_id=" . $input["id"]);
+
+ /* loop through each item affected and update column data */
+ if (sizeof($item_list) > 0) {
+ foreach ($item_list as $item) {
+ db_execute("update graph_templates_item set " . $input["column_name"] . "='" . $_POST{$column_name . "_" . $input["id"]} . "' where id=" . $item["id"]);
+ }
+ }
+ }
+ }
+ }
+
+ if (isset($_POST["save_component_graph_diff"])) {
+ if ($_POST["type"] == "1") {
+ $intrusive = true;
+ }elseif ($_POST["type"] == "2") {
+ $intrusive = false;
+ }
+
+ change_graph_template($_POST["local_graph_id"], $_POST["graph_template_id"], $intrusive);
+ }
+
+ if (isset($_POST["save_component_item"])) {
+ $save["id"] = $_POST["graph_template_item_id"];
+ $save["graph_template_id"] = $_POST["graph_template_id"];
+ $save["local_graph_id"] = $_POST["local_graph_id"];
+ $save["task_item_id"] = form_input_validate($_POST["task_item_id"], "task_item_id", "", true, 3);
+ $save["color_id"] = form_input_validate($_POST["color_id"], "color_id", "", true, 3);
+ $save["graph_type_id"] = form_input_validate($_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($_POST["consolidation_function_id"], "consolidation_function_id", "", true, 3);
+ $save["text_format"] = form_input_validate($_POST["text_format"], "text_format", "", true, 3);
+ $save["value"] = form_input_validate($_POST["value"], "value", "", true, 3);
+ $save["hard_return"] = form_input_validate($_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()) {
+ $graph_template_item_id = sql_save($save, "graph_templates_item");
+
+ if ($graph_template_item_id) {
+ raise_message(1);
+ }else{
+ raise_message(2);
+ }
+ }
+
+ if (is_error_message()) {
+ header ("Location: graphs.php?action=item_edit&graph_template_item_id=" . (empty($graph_template_item_id) ? $_POST["graph_template_item_id"] : $graph_template_item_id) . "&local_graph_id=" . $_POST["local_graph_id"]);
+ exit;
+ }elseif (read_config_option("full_view_graph") == "") {
+ header ("Location: graphs.php?action=item&local_graph_id=" . $_POST["local_graph_id"]);
+ exit;
+ }elseif (read_config_option("full_view_graph") == "on") {
+ header ("Location: graphs.php?action=graph_edit&local_graph_id=" . $_POST["local_graph_id"]);
+ exit;
+ }
+ }
+
+ if ((is_error_message()) || (empty($_POST["local_graph_id"])) || (isset($_POST["save_component_input"])) || (isset($_POST["save_component_graph_diff"]))) {
+ header ("Location: graphs.php?action=graph_edit&local_graph_id=" . (empty($local_graph_id) ? $_POST["local_graph_id"] : $local_graph_id));
+ }else{
+ header ("Location: graphs.php");
+ }
}
/* -----------------------
@@ -329,16 +442,7 @@ function item() {
form_hidden_box("save_component_input","1","");
if ((read_config_option("full_view_graph") == "") && (sizeof($input_item_list) > 0)) {
- start_box("", "98%", $colors["header"], "3", "center", "");
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
- 0) {
- foreach ($input_list as $input) {
- /* we need to find out which graph items will be affected by saving this particular item */
- $item_list = db_fetch_assoc("select
- graph_templates_item.id
- from graph_template_input_defs,graph_templates_item
- where graph_template_input_defs.graph_template_item_id=graph_templates_item.local_graph_template_item_id
- and graph_templates_item.local_graph_id=" . $_POST["local_graph_id"] . "
- and graph_template_input_defs.graph_template_input_id=" . $input["id"]);
-
- /* get some variables */
- $column_name = $input["column_name"];
- $column_value = $_POST{$column_name . "_" . $input["id"]};
-
- /* loop through each item affected and update column data */
- if (sizeof($item_list) > 0) {
- foreach ($item_list as $item) {
- db_execute("update graph_templates_item set $column_name='$column_value' where id=" . $item["id"]);
- }
- }
- }
- }
+ form_save_button( $_SERVER["HTTP_REFERER"]);
}
/* ------------------------------------
graph - Graphs
------------------------------------ */
-function graph_save() {
- include_once ("include/utility_functions.php");
-
- if ($_POST["lower_limit"] == "") { $_POST["lower_limit"] = 0; }
- if ($_POST["upper_limit"] == "") { $_POST["upper_limit"] = 0; }
- if ($_POST["unit_exponent_value"] == "") { $_POST["unit_exponent_value"] = 0; }
-
- $save["id"] = $_POST["local_graph_id"];
- $save["graph_template_id"] = $_POST["graph_template_id"];
-
- $local_graph_id = sql_save($save, "graph_local");
- unset($save);
-
- $save["id"] = $_POST["graph_template_graph_id"];
- $save["local_graph_template_graph_id"] = $_POST["local_graph_template_graph_id"];
- $save["local_graph_id"] = $local_graph_id;
- $save["graph_template_id"] = $_POST["graph_template_id"];
- $save["image_format_id"] = $_POST["image_format_id"];
- $save["title"] = $_POST["title"];
- $save["height"] = $_POST["height"];
- $save["width"] = $_POST["width"];
- $save["upper_limit"] = $_POST["upper_limit"];
- $save["lower_limit"] = $_POST["lower_limit"];
- $save["vertical_label"] = $_POST["vertical_label"];
- $save["auto_scale"] = $_POST["auto_scale"];
- $save["auto_scale_opts"] = $_POST["auto_scale_opts"];
- $save["auto_scale_log"] = $_POST["auto_scale_log"];
- $save["auto_scale_rigid"] = $_POST["auto_scale_rigid"];
- $save["auto_padding"] = $_POST["auto_padding"];
- $save["base_value"] = $_POST["base_value"];
- $save["export"] = $_POST["export"];
- $save["unit_value"] = $_POST["unit_value"];
- $save["unit_exponent_value"] = $_POST["unit_exponent_value"];
-
- sql_save($save, "graph_templates_graph");
-
- /* if template information chanegd, update all nessesary template information */
- if ($_POST["graph_template_id"] != $_POST["_graph_template_id"]) {
- /* check to see if the number of graph items differs, if it does; we need user input */
- if ((!empty($_POST["graph_template_id"])) && (sizeof(db_fetch_assoc("select id from graph_templates_item where local_graph_id=$local_graph_id")) != sizeof(db_fetch_assoc("select id from graph_templates_item where local_graph_id=0 and graph_template_id=" . $_POST["graph_template_id"])))) {
- /* set the template back, since the user may choose not to go through with the change
- at this point */
- db_execute("update graph_local set graph_template_id=" . $_POST["_graph_template_id"] . " where id=$local_graph_id");
- db_execute("update graph_templates_graph set graph_template_id=" . $_POST["_graph_template_id"] . " where local_graph_id=$local_graph_id");
-
- header("Location: graphs.php?action=graph_diff&local_graph_id=$local_graph_id&graph_template_id=" . $_POST["graph_template_id"]);
- exit;
- }
-
- change_graph_template($local_graph_id, $_POST["graph_template_id"], true);
- }
-
- /* so we get redirected to the correct page, not '&local_graph_id=0' */
- $_POST["local_graph_id"] = $local_graph_id;
-}
-
-function graph_diff_save() {
- include_once ("include/utility_functions.php");
-
- if ($_POST["type"] == "1") {
- $intrusive = true;
- }elseif ($_POST["type"] == "2") {
- $intrusive = false;
- }
-
- change_graph_template($_POST["local_graph_id"], $_POST["graph_template_id"], $intrusive);
-}
-
function graph_diff() {
global $colors;
include("include/config_arrays.php");
@@ -760,19 +734,14 @@ function graph_diff() {
-
-
-
-
-
-
-
+
">
">
-
-
-
-
-
-
-
- \n";
@@ -428,7 +430,7 @@ function host_new_graphs($host_id, $host_template_id, $selected_graphs_array) {
if (sizeof($fields) > 0) {
foreach ($fields as $field) {
- print "
+ print "
" . $field["name"] . " -> " . $field["field_name"] . "
When these graphs are created, the following data input field will be filled with data from
@@ -499,7 +501,7 @@ function host_new_graphs($host_id, $host_template_id, $selected_graphs_array) {
entry here might might 20 graphs... so we can't automatically fill in the
values */
if ((!empty($snmp_query_id)) && ($snmp_queries["suggested_values"][0]["graph"][0][$field_name])) {
- print "