1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004 Ian Berry |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| cacti: a php-based graphing solution |
+-------------------------------------------------------------------------+
| Most of this code has been designed, written and is maintained by |
| Ian Berry. See about.php for specific developer credit. Any questions |
| or comments regarding this code should be directed to: |
| - iberry@raxnet.net |
+-------------------------------------------------------------------------+
| - raXnet - http://www.raxnet.net/ |
+-------------------------------------------------------------------------+
*/
include("./include/auth.php");
include_once("./lib/template.php");
/* set default action */
if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }
switch ($_REQUEST["action"]) {
case 'save':
form_save();
break;
case 'input_remove':
input_remove();
header("Location: graph_templates.php?action=template_edit&id=" . $_GET["graph_template_id"]);
break;
case 'input_edit':
include_once("./include/top_header.php");
input_edit();
include_once("./include/bottom_footer.php");
break;
}
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)
values ($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;
}
}
}
/* ------------------------------------
input - Graph Template Item Inputs
------------------------------------ */
function input_remove() {
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
input_validate_input_number(get_request_var("graph_template_id"));
/* ==================================================== */
if ((read_config_option("remove_verification") == "on") && (!isset($_GET["confirm"]))) {
include("./include/top_header.php");
form_confirm("Are You Sure?", "Are you sure you want to delete the input item <strong>'" . db_fetch_cell("select name from graph_template_input where id=" . $_GET["id"]) . "'</strong>? NOTE: Deleting this item will NOT affect graphs that use this template.", "graph_templates.php?action=template_edit&id=" . $_GET["graph_template_id"], "graph_templates_inputs.php?action=input_remove&id=" . $_GET["id"] . "&graph_template_id=" . $_GET["graph_template_id"]);
include("./include/bottom_footer.php");
exit;
}
if ((read_config_option("remove_verification") == "") || (isset($_GET["confirm"]))) {
db_execute("delete from graph_template_input where id=" . $_GET["id"]);
db_execute("delete from graph_template_input_defs where graph_template_input_id=" . $_GET["id"]);
}
}
function input_edit() {
global $colors, $consolidation_functions, $graph_item_types, $struct_graph_item, $fields_graph_template_input_edit;
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
input_validate_input_number(get_request_var("graph_template_id"));
/* ==================================================== */
$header_label = "[edit graph: " . db_fetch_cell("select name from graph_templates where id=" . $_GET["graph_template_id"]) . "]";
/* get a list of all graph item field names and populate an array for user display */
while (list($field_name, $field_array) = each($struct_graph_item)) {
if ($field_array["method"] != "view") {
$graph_template_items[$field_name] = $field_array["friendly_name"];
}
}
if (!empty($_GET["id"])) {
$graph_template_input = db_fetch_row("select * from graph_template_input where id=" . $_GET["id"]);
}
html_start_box("<strong>Graph Item Inputs</strong> $header_label", "98%", $colors["header"], "3", "center", "");
draw_edit_form(array(
"config" => array(),
"fields" => inject_form_variables($fields_graph_template_input_edit, (isset($graph_template_input) ? $graph_template_input : array()), (isset($graph_template_items) ? $graph_template_items : array()), $_GET)
));
if (!(isset($_GET["id"]))) { $_GET["id"] = 0; }
$item_list = db_fetch_assoc("select
CONCAT_WS(' - ',data_template_data.name,data_template_rrd.data_source_name) as data_source_name,
graph_templates_item.text_format,
graph_templates_item.id as graph_templates_item_id,
graph_templates_item.graph_type_id,
graph_templates_item.consolidation_function_id,
graph_template_input_defs.graph_template_input_id
from graph_templates_item
left join graph_template_input_defs on (graph_template_input_defs.graph_template_item_id=graph_templates_item.id and graph_template_input_defs.graph_template_input_id=" . $_GET["id"] . ")
left join data_template_rrd on (graph_templates_item.task_item_id=data_template_rrd.id)
left join data_local on (data_template_rrd.local_data_id=data_local.id)
left join data_template_data on (data_local.id=data_template_data.local_data_id)
where graph_templates_item.local_graph_id=0
and graph_templates_item.graph_template_id=" . $_GET["graph_template_id"] . "
order by graph_templates_item.sequence");
form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],1); ?>
<td width="50%">
<font class="textEditTitle">Associated Graph Items</font><br>
Select the graph items that you want to accept user input for.
</td>
<td>
<?php
$i = 0; $any_selected_item = "";
if (sizeof($item_list) > 0) {
foreach ($item_list as $item) {
if ($item["graph_template_input_id"] == "") {
$old_value = "";
}else{
$old_value = "on";
$any_selected_item = $item["graph_templates_item_id"];
}
if ($graph_item_types{$item["graph_type_id"]} == "GPRINT") {
$start_bold = "";
$end_bold = "";
}else{
$start_bold = "<strong>";
$end_bold = "</strong>";
}
$name = "$start_bold Item #" . ($i+1) . ": " . $graph_item_types{$item["graph_type_id"]} . " (" . $consolidation_functions{$item["consolidation_function_id"]} . ")$end_bold";
form_checkbox("i_" . $item["graph_templates_item_id"], $old_value, $name,"",$_GET["graph_template_id"],true); print "<br>";
$i++;
}
}else{
print "<em>No Items</em>";
}
?>
</td>
</tr>
<?php
html_end_box();
form_hidden_box("any_selected_item", $any_selected_item, "");
form_save_button("graph_templates.php?action=template_edit&id=" . $_GET["graph_template_id"]);
}
|