mirror of
https://github.com/Cacti/cacti.git
synced 2026-11-09 05:26:50 +09:00
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/trunk/cacti@1315 860744bd-22fc-0310-8c96-e9fe5004b5ca
339 lines
12 KiB
PHP
339 lines
12 KiB
PHP
<?php
|
|
/*
|
|
+-------------------------------------------------------------------------+
|
|
| Copyright (C) 2003 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/tree.php');
|
|
include_once('./lib/tree_view.php');
|
|
|
|
/* set default action */
|
|
if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }
|
|
|
|
switch ($_REQUEST["action"]) {
|
|
case 'save':
|
|
form_save();
|
|
|
|
break;
|
|
case 'item_movedown':
|
|
item_movedown();
|
|
|
|
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
|
break;
|
|
case 'item_moveup':
|
|
item_moveup();
|
|
|
|
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
|
break;
|
|
case 'item_edit':
|
|
include_once("./include/top_header.php");
|
|
|
|
item_edit();
|
|
|
|
include_once("./include/bottom_footer.php");
|
|
break;
|
|
case 'item_remove':
|
|
item_remove();
|
|
|
|
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
|
break;
|
|
case 'remove':
|
|
tree_remove();
|
|
|
|
header("Location: tree.php");
|
|
break;
|
|
case 'edit':
|
|
include_once("./include/top_header.php");
|
|
|
|
tree_edit();
|
|
|
|
include_once("./include/bottom_footer.php");
|
|
break;
|
|
default:
|
|
include_once("./include/top_header.php");
|
|
|
|
tree();
|
|
|
|
include_once("./include/bottom_footer.php");
|
|
break;
|
|
}
|
|
|
|
/* --------------------------
|
|
The Save Function
|
|
-------------------------- */
|
|
|
|
function form_save() {
|
|
if (isset($_POST["save_component_tree"])) {
|
|
$save["id"] = $_POST["id"];
|
|
$save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
|
|
|
|
if (!is_error_message()) {
|
|
$tree_id = sql_save($save, "graph_tree");
|
|
|
|
if ($tree_id) {
|
|
raise_message(1);
|
|
}else{
|
|
raise_message(2);
|
|
}
|
|
}
|
|
|
|
if ((is_error_message()) || (empty($_POST["id"]))) {
|
|
header("Location: tree.php?action=edit&id=" . (empty($tree_id) ? $_POST["id"] : $tree_id));
|
|
}else{
|
|
header("Location: tree.php");
|
|
}
|
|
}elseif (isset($_POST["save_component_tree_item"])) {
|
|
if (empty($_POST["id"])) {
|
|
/* new/save - generate new order key */
|
|
$order_key = get_next_tree_id(db_fetch_cell("select order_key from graph_tree_items where id=" . $_POST["parent_item_id"]),"graph_tree_items","order_key","graph_tree_id=" . $_POST["graph_tree_id"]);
|
|
}else{
|
|
/* edit/save - use old order_key */
|
|
$order_key = db_fetch_cell("select order_key from graph_tree_items where id=" . $_POST["id"]);
|
|
}
|
|
|
|
$save["id"] = $_POST["id"];
|
|
$save["graph_tree_id"] = $_POST["graph_tree_id"];
|
|
$save["title"] = form_input_validate($_POST["title"], "title", "", true, 3);
|
|
$save["order_key"] = $order_key;
|
|
$save["local_graph_id"] = form_input_validate($_POST["local_graph_id"], "local_graph_id", "", true, 3);
|
|
$save["rra_id"] = form_input_validate($_POST["rra_id"], "rra_id", "", true, 3);
|
|
$save["host_id"] = form_input_validate($_POST["host_id"], "host_id", "", true, 3);
|
|
|
|
/* the user did not select anything; raise an error */
|
|
if (($save["title"] == "") && (empty($save["local_graph_id"])) && (empty($save["host_id"]))) {
|
|
raise_message(5);
|
|
}
|
|
|
|
if (!is_error_message()) {
|
|
$tree_item_id = sql_save($save, "graph_tree_items");
|
|
|
|
if ($tree_item_id) {
|
|
raise_message(1);
|
|
|
|
/* only re-parent headings */
|
|
if ($save["title"] != "") {
|
|
reparent_branch($_POST["parent_item_id"], $_POST["id"]);
|
|
}
|
|
}else{
|
|
raise_message(2);
|
|
}
|
|
}
|
|
|
|
if (is_error_message()) {
|
|
header("Location: tree.php?action=item_edit&tree_item_id=" . (empty($tree_item_id) ? $_POST["id"] : $tree_item_id) . "&tree_id=" . $_POST["graph_tree_id"] . "&parent_id=" . $_POST["parent_item_id"]);
|
|
}else{
|
|
header("Location: tree.php?action=edit&id=" . $_POST["graph_tree_id"]);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* -----------------------
|
|
Tree Item Functions
|
|
----------------------- */
|
|
|
|
function item_edit() {
|
|
global $colors, $fields_tree_item_edit_header, $fields_tree_item_edit_graph, $fields_tree_item_edit_host;
|
|
|
|
$color_graph = $colors["header"];
|
|
$color_header = $colors["header"];
|
|
$color_host = $colors["header"];
|
|
|
|
if (!empty($_GET["id"])) {
|
|
$tree_item = db_fetch_row("select * from graph_tree_items where id=" . $_GET["id"]);
|
|
|
|
/* bold the active "type" */
|
|
if ($tree_item["local_graph_id"] > 0) { $color_graph = $colors["header_panel"]; }
|
|
|
|
/* bold the active "type" */
|
|
if ($tree_item["title"] != "") { $color_header = $colors["header_panel"]; }
|
|
|
|
/* bold the active "type" */
|
|
if ($tree_item["host_id"] > 0) { $color_host = $colors["header_panel"]; }
|
|
}
|
|
|
|
start_box("<strong>Tree Items</strong>", "98%", $colors["header"], "3", "center", "");
|
|
|
|
draw_edit_form(
|
|
array(
|
|
"config" => array(
|
|
),
|
|
"fields" => array(
|
|
"parent_item_id" => array(
|
|
"method" => "drop_tree",
|
|
"friendly_name" => "Parent Item",
|
|
"description" => "Choose the parent for this header/graph.",
|
|
"value" => (isset($_GET["parent_id"]) ? $_GET["parent_id"] : get_parent_id($tree_item["id"], "graph_tree_items", "graph_tree_id=" . $_GET["tree_id"])),
|
|
"tree_id" => $_GET["tree_id"]
|
|
)
|
|
)
|
|
)
|
|
);
|
|
|
|
end_box();
|
|
|
|
start_box("Tree Items [header]", "98%", $color_header, "3", "center", "");
|
|
|
|
draw_edit_form(array(
|
|
"config" => array("no_form_tag" => true),
|
|
"fields" => inject_form_variables($fields_tree_item_edit_header, (isset($tree_item) ? $tree_item : array()))
|
|
));
|
|
|
|
end_box();
|
|
|
|
start_box("Tree Items [graph]", "98%", $color_graph, "3", "center", "");
|
|
|
|
draw_edit_form(array(
|
|
"config" => array("no_form_tag" => true),
|
|
"fields" => inject_form_variables($fields_tree_item_edit_graph, (isset($tree_item) ? $tree_item : array()))
|
|
));
|
|
|
|
end_box();
|
|
|
|
start_box("Tree Items [host]", "98%", $color_host, "3", "center", "");
|
|
|
|
draw_edit_form(array(
|
|
"config" => array("no_form_tag" => true),
|
|
"fields" => inject_form_variables($fields_tree_item_edit_host, (isset($tree_item) ? $tree_item : array()), $_GET)
|
|
));
|
|
|
|
end_box();
|
|
|
|
form_save_button("tree.php?action=edit&id=" . $_GET["tree_id"]);
|
|
}
|
|
|
|
function item_moveup() {
|
|
$order_key = db_fetch_cell("SELECT order_key FROM graph_tree_items WHERE id=" . $_GET["id"]);
|
|
if ($order_key > 0) { branch_up($order_key, 'graph_tree_items', 'order_key', 'graph_tree_id=' . $_GET["tree_id"]); }
|
|
}
|
|
|
|
function item_movedown() {
|
|
$order_key = db_fetch_cell("SELECT order_key FROM graph_tree_items WHERE id=" . $_GET["id"]);
|
|
if ($order_key > 0) { branch_down($order_key, 'graph_tree_items', 'order_key', 'graph_tree_id=' . $_GET["tree_id"]); }
|
|
}
|
|
|
|
function item_remove() {
|
|
if ((read_config_option("remove_verification") == "on") && (!isset($_GET["confirm"]))) {
|
|
$graph_tree_item = db_fetch_row("select title,local_graph_id,host_id from graph_tree_items where id=" . $_GET["id"]);
|
|
|
|
if (!empty($graph_tree_item["local_graph_id"])) {
|
|
$text = "Are you sure you want to delete the graph item <strong>'" . db_fetch_cell("select title_cache from graph_templates_graph where local_graph_id=" . $graph_tree_item["local_graph_id"]) . "'</strong>?";
|
|
}elseif ($graph_tree_item["title"] != "") {
|
|
$text = "Are you sure you want to delete the header item <strong>'" . $graph_tree_item["title"] . "'</strong>?";
|
|
}elseif (!empty($graph_tree_item["host_id"])) {
|
|
$text = "Are you sure you want to delete the host item <strong>'" . db_fetch_cell("select CONCAT_WS('',description,' (',hostname,')') as hostname from host where id=" . $graph_tree_item["host_id"]) . "'</strong>?";
|
|
}
|
|
|
|
include("./include/top_header.php");
|
|
form_confirm("Are You Sure?", $text, $_SERVER["HTTP_REFERER"], "tree.php?action=item_remove&id=" . $_GET["id"] . "&tree_id=" . $_GET["tree_id"]);
|
|
include("./include/bottom_footer.php");
|
|
exit;
|
|
}
|
|
|
|
if ((read_config_option("remove_verification") == "") || (isset($_GET["confirm"]))) {
|
|
delete_branch($_GET["id"]);
|
|
}
|
|
|
|
header("Location: tree.php?action=edit&id=" . $_GET["tree_id"]); exit;
|
|
}
|
|
|
|
|
|
/* ---------------------
|
|
Tree Functions
|
|
--------------------- */
|
|
|
|
function tree_remove() {
|
|
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 tree <strong>'" . db_fetch_cell("select name from graph_tree where id=" . $_GET["id"]) . "'</strong>?", $_SERVER["HTTP_REFERER"], "tree.php?action=remove&id=" . $_GET["id"]);
|
|
include("./include/bottom_footer.php");
|
|
exit;
|
|
}
|
|
|
|
if ((read_config_option("remove_verification") == "") || (isset($_GET["confirm"]))) {
|
|
db_execute("delete from graph_tree where id=" . $_GET["id"]);
|
|
db_execute("delete from graph_tree_items where graph_tree_id=" . $_GET["id"]);
|
|
}
|
|
}
|
|
|
|
function tree_edit() {
|
|
global $colors, $fields_tree_edit;
|
|
|
|
if (!empty($_GET["id"])) {
|
|
$tree = db_fetch_row("select * from graph_tree where id=" . $_GET["id"]);
|
|
$header_label = "[edit: " . $tree["name"] . "]";
|
|
}else{
|
|
$header_label = "[new]";
|
|
}
|
|
|
|
start_box("<strong>Graph Trees</strong> $header_label", "98%", $colors["header"], "3", "center", "");
|
|
|
|
draw_edit_form(array(
|
|
"config" => array(),
|
|
"fields" => inject_form_variables($fields_tree_edit, (isset($tree) ? $tree : array()))
|
|
));
|
|
|
|
end_box();
|
|
|
|
if (!empty($_GET["id"])) {
|
|
start_box("<strong>Tree Items</strong>", "98%", $colors["header"], "3", "center", "tree.php?action=item_edit&tree_id=" . $tree["id"] . "&parent_id=0");
|
|
grow_edit_graph_tree($_GET["id"], "", "");
|
|
end_box();
|
|
}
|
|
|
|
form_save_button("tree.php");
|
|
}
|
|
|
|
function tree() {
|
|
global $colors;
|
|
|
|
start_box("<strong>Graph Trees</strong>", "98%", $colors["header"], "3", "center", "tree.php?action=edit");
|
|
|
|
print "<tr bgcolor='#" . $colors["header_panel"] . "'>";
|
|
DrawMatrixHeaderItem("Name",$colors["header_text"],1);
|
|
DrawMatrixHeaderItem(" ",$colors["header_text"],1);
|
|
print "</tr>";
|
|
|
|
$trees = db_fetch_assoc("select * from graph_tree order by name");
|
|
|
|
$i = 0;
|
|
if (sizeof($trees) > 0) {
|
|
foreach ($trees as $tree) {
|
|
form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++;
|
|
?>
|
|
<td>
|
|
<a class="linkEditMain" href="tree.php?action=edit&id=<?php print $tree["id"];?>"><?php print $tree["name"];?></a>
|
|
</td>
|
|
<td width="1%" align="right">
|
|
<a href="tree.php?action=remove&id=<?php print $tree["id"];?>"><img src="images/delete_icon.gif" width="10" height="10" border="0" alt="Delete"></a>
|
|
</td>
|
|
</tr>
|
|
<?php
|
|
}
|
|
}else{
|
|
print "<tr><td><em>No Graphs Trees</em></td></tr>\n";
|
|
}
|
|
end_box();
|
|
}
|
|
?>
|