function grow_edit_graph_tree($tree_id, $user_id, $options) { global $config, $colors; include_once $config["library_path"] . "/tree.php"; $tree_sorting_type = db_fetch_cell("select sort_type from graph_tree where id='{$tree_id}'"); $tree = db_fetch_assoc("select\r\n\t\tgraph_tree_items.id,\r\n\t\tgraph_tree_items.title,\r\n\t\tgraph_tree_items.graph_tree_id,\r\n\t\tgraph_tree_items.local_graph_id,\r\n\t\tgraph_tree_items.host_id,\r\n\t\tgraph_tree_items.order_key,\r\n\t\tgraph_tree_items.sort_children_type,\r\n\t\tgraph_templates_graph.title_cache as graph_title,\r\n\t\tCONCAT_WS('',description,' (',hostname,')') as hostname\r\n\t\tfrom graph_tree_items\r\n\t\tleft join graph_templates_graph on (graph_tree_items.local_graph_id=graph_templates_graph.local_graph_id and graph_tree_items.local_graph_id>0)\r\n\t\tleft join host on (host.id=graph_tree_items.host_id)\r\n\t\twhere graph_tree_items.graph_tree_id={$tree_id}\r\n\t\torder by graph_tree_id, graph_tree_items.order_key"); print "<!-- <P>Building Hierarchy w/ " . sizeof($tree) . " leaves</P> -->\n"; ## Here we go. Starting the main tree drawing loop. /* change the visibility session variable if applicable */ set_tree_visibility_status(); $i = 0; if (sizeof($tree) > 0) { foreach ($tree as $leaf) { /* modify for multi user start */ $permission = check_tree_item($leaf["id"]); if ($permission == FALSE) { if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR && ($leaf["graph_tree_id"] != $_SESSION["public_tree_id"] && $leaf["graph_tree_id"] != $_SESSION["private_tree_id"])) { // administrator can view other private tree } else { continue; } } /* modify for multi user end */ $tier = tree_tier($leaf["order_key"]); $transparent_indent = "<img src='images/transparent_line.gif' style='padding-right:" . ($tier - 1) * 20 . "px;' style='height:1px;' align='middle' alt=''> "; $sort_cache[$tier] = $leaf["sort_children_type"]; if ($i % 2 == 0) { $row_color = $colors["form_alternate1"]; } else { $row_color = $colors["form_alternate2"]; } $i++; $visible = get_visibility($leaf); if ($leaf["local_graph_id"] > 0) { if ($visible) { /* modify for multi user start */ if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR || $permission == TREE_ITEM_PRIVATE) { print "<td bgcolor='#{$row_color}'>{$transparent_indent}<a href='" . htmlspecialchars("tree.php?action=item_edit&tree_id=" . $_GET["id"] . "&id=" . $leaf["id"]) . "'>" . $leaf["graph_title"] . "</a></td>\n"; } elseif ($permission == TREE_ITEM_PUBLIC) { $local_graph_id = db_fetch_cell("SELECT local_graph_id FROM graph_tree_items WHERE id = '" . $leaf["id"] . "'"); print "<td bgcolor='#{$row_color}'><a href='graph.php?action=properties&local_graph_id=" . $local_graph_id . "&rra_id=0&view_type=tree'>{$transparent_indent}" . $leaf["graph_title"] . "</a></td>\n"; } else { print "<td bgcolor='#{$row_color}'>{$transparent_indent}" . $leaf["graph_title"] . "</td>\n"; } /* modify for multi user end */ print "<td bgcolor='#{$row_color}'>Graph</td>"; } } elseif ($leaf["title"] != "") { $icon = get_icon($leaf["graph_tree_id"], $leaf["order_key"]); if ($visible) { /* modify for multi user start */ if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR || $permission == TREE_ITEM_PRIVATE) { print "<td bgcolor='#{$row_color}'>{$transparent_indent}<a href='" . htmlspecialchars("tree.php?action=edit&id=" . $_GET["id"] . "&leaf_id=" . $leaf["id"] . "&subaction=change") . "'><img src='" . $icon . "' border='0'></a><a href='" . htmlspecialchars("tree.php?action=item_edit&tree_id=" . $_GET["id"] . "&id=" . $leaf["id"]) . "'> <strong>" . htmlspecialchars($leaf["title"]) . "</strong></a> (<a href='" . htmlspecialchars("tree.php?action=item_edit&tree_id=" . $_GET["id"] . "&parent_id=" . $leaf["id"]) . "'>Add</a>)</td>\n"; } else { print "<td bgcolor='#{$row_color}'>{$transparent_indent}<a href='" . htmlspecialchars("tree.php?action=edit&id=" . $_GET["id"] . "&leaf_id=" . $leaf["id"] . "&subaction=change") . "'><img src='" . $icon . "' border='0'></a> <strong>" . htmlspecialchars($leaf["title"]) . "</strong></td>\n"; } /* modify for multi user end */ print "<td bgcolor='#{$row_color}'>Heading</td>"; } } elseif ($leaf["host_id"] > 0) { if ($visible) { /* modify for multi user start */ if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR || $permission == TREE_ITEM_PRIVATE) { print "<td bgcolor='#{$row_color}'>{$transparent_indent}<a href='" . htmlspecialchars("tree.php?action=item_edit&tree_id=" . $_GET["id"] . "&id=" . $leaf["id"]) . "'><strong>Host:</strong> " . htmlspecialchars($leaf["hostname"]) . "</a> <a href='" . htmlspecialchars("host.php?action=edit&id=" . $leaf["host_id"]) . "'>(Edit host)</a></td>\n"; } else { print "<td bgcolor='#{$row_color}'>{$transparent_indent}<strong>Host:</strong> " . htmlspecialchars($leaf["hostname"]) . "</td>\n"; } /* modify for multi user end */ print "<td bgcolor='#{$row_color}'>Host</td>"; } } if ($visible) { /* modify for multi user start */ if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR || ($permission == TREE_ITEM_PRIVATE || $permission == TREE_ITEM_OTHER)) { if (isset($sort_cache[$tier - 1]) && $sort_cache[$tier - 1] != TREE_ORDERING_NONE || $tree_sorting_type != TREE_ORDERING_NONE) { print "<td bgcolor='#{$row_color}' width='80'></td>\n"; } else { print "<td bgcolor='#{$row_color}' width='80' align='center'>\n\r\n\t\t\t\t\t<a href='" . htmlspecialchars("tree.php?action=item_movedown&id=" . $leaf["id"] . "&tree_id=" . $_GET["id"]) . "'><img src='images/move_down.gif' border='0' alt='Move Down'></a>\n\r\n\t\t\t\t\t<a href='" . htmlspecialchars("tree.php?action=item_moveup&id=" . $leaf["id"] . "&tree_id=" . $_GET["id"]) . "'><img src='images/move_up.gif' border='0' alt='Move Up'></a>\n\r\n\t\t\t\t\t</td>\n"; } } else { print "<td bgcolor='#{$row_color}' width='80'></td>\n"; } if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR || $leaf["local_graph_id"] != 0 && $permission == TREE_ITEM_PUBLIC || $leaf["local_graph_id"] != 0 && $permission == TREE_ITEM_OTHER && $tier > 1 || $leaf["host_id"] != 0 && $permission == TREE_ITEM_PRIVATE && $tier > 1 || $leaf["host_id"] == 0 && $permission == TREE_ITEM_PRIVATE) { // private header or graph print "<td bgcolor='#{$row_color}' align='right'>\n\r\n\t\t\t\t<a href='" . htmlspecialchars("tree.php?action=item_remove&id=" . $leaf["id"] . "&tree_id={$tree_id}") . "'><img src='images/delete_icon.gif' style='height:10px;width:10px;' border='0' alt='Delete'></a>\n\r\n\t\t\t\t</td></tr>\n"; } else { print "<td bgcolor='#{$row_color}' align='right'></td></tr>\n"; } /* modify for multi user end */ } } } else { print "<tr><td><em>No Graph Tree Items</em></td></tr>"; } }
function item_remove() { /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("tree_id")); /* ==================================================== */ /* modify for multi user start */ if (!check_tree_item($_GET["id"])) { access_denied(); } /* modify for multi user end */ if (read_config_option("deletion_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, htmlspecialchars("tree.php?action=edit&id=" . $_GET["tree_id"]), htmlspecialchars("tree.php?action=item_remove&id=" . $_GET["id"] . "&tree_id=" . $_GET["tree_id"])); include "./include/bottom_footer.php"; exit; } if (read_config_option("deletion_verification") == "" || isset($_GET["confirm"])) { /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { $tree_item = db_fetch_row("SELECT graph_tree_id,local_graph_id,title,host_id,order_key FROM graph_tree_items WHERE id = '" . $_GET["id"] . "'"); // public graph if ($tree_item["graph_tree_id"] == $_SESSION["public_tree_id"] && $tree_item["local_graph_id"] > 0) { db_execute("DELETE FROM user_auth_perms WHERE user_id = '" . $_SESSION["sess_user_id"] . "' AND item_id = '" . $tree_item["local_graph_id"] . "' AND type = '1'"); // remove all reference favorites graph $rows = db_fetch_assoc("SELECT graph_tree_items.id FROM graph_tree_items WHERE graph_tree_id != '" . $_SESSION["private_tree_id"] . "' AND local_graph_id = '" . $tree_item["local_graph_id"] . "'"); foreach ($rows as $row) { delete_branch($row["id"]); } // private device (re-entry host tree_item) } elseif ($tree_item["graph_tree_id"] == $_SESSION["private_tree_id"] && $tree_item["host_id"] > 0) { exec("php ./cli/add_tree.php --type=node --node-type=host --tree-id=" . $_SESSION["private_tree_id"] . " --host-id=" . $tree_item["host_id"] . " --host-group-style=1"); // private header (re-entry host tree_item) } elseif ($tree_item["graph_tree_id"] == $_SESSION["private_tree_id"] && $tree_item["title"] != "") { $tier = tree_tier($tree_item["order_key"]); $order_key = substr($tree_item["order_key"], 0, $tier * CHARS_PER_TIER); $rows = db_fetch_assoc("SELECT host_id FROM graph_tree_items WHERE graph_tree_id = '" . $_SESSION["private_tree_id"] . "' AND host_id > 0 AND order_key LIKE '" . $order_key . "%'"); foreach ($rows as $row) { exec("php ./cli/add_tree.php --type=node --node-type=host --tree-id=" . $_SESSION["private_tree_id"] . " --host-id=" . $row["host_id"] . " --host-group-style=1"); } } } /* modify for multi user end */ delete_branch($_GET["id"]); } /* clear graph tree cache on save - affects current user only, other users should see changes in <5 minutes */ if (isset($_SESSION['dhtml_tree'])) { unset($_SESSION['dhtml_tree']); } header("Location: tree.php?action=edit&id=" . $_GET["tree_id"]); exit; }