function grow_graph_tree($graph_tree_id, $start_branch, $user_id, $options) { global $colors, $current_user; require_once(CACTI_BASE_PATH . "/lib/sys/auth.php"); require_once(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_constants.php"); require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_info.php"); require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_utility.php"); $search_key = ""; $already_open = false; $hide_until_depth = false; $graph_ct = 0; $sql_where = ""; $sql_join = ""; /* get the "starting leaf" if the user clicked on a specific branch */ if (($start_branch != "") && ($start_branch != "0")) { $graph_tree = api_graph_tree_get($start_branch); $search_key = substr($graph_tree["order_key"], 0, (api_graph_tree_item_depth_get($graph_tree["order_key"]) * CHARS_PER_TIER)); } /* graph permissions */ if (read_config_option("auth_method") != "0") { /* get policy information for the sql where clause */ //$sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]); //$sql_where = (empty($sql_where) ? "" : "and (" . $sql_where . " OR graph_tree_items.local_graph_id=0)"); //$sql_join = "left join graph_local on (graph_templates_graph.local_graph_id=graph_local.id) // left join graph_templates on (graph_templates.id=graph_local.graph_template_id) // left join user_auth_perms on ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))"; } /* include time span selector */ if (read_graph_config_option("timespan_sel") == "on") { html_graph_start_box(3, false); require("./include/html/inc_timespan_selector.php"); html_graph_end_box(); print "<br>"; } /* NOTE: GRAPH PERMISSIONS HAVE NOT BEEN IMPLEMENTED */ $graph_tree_items = api_graph_tree_item_list($graph_tree_id, "", $start_branch, true, true); /* $heirarchy = db_fetch_assoc("select graph_tree_items.id, graph_tree_items.title, graph_tree_items.local_graph_id, graph_tree_items.rra_id, graph_tree_items.host_id, graph_tree_items.order_key, graph_templates_graph.title_cache as graph_title, CONCAT_WS('',host.description,' (',host.hostname,')') as hostname, settings_tree.status from graph_tree_items left 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) left join settings_tree on (graph_tree_items.id=settings_tree.graph_tree_item_id and settings_tree.user_id=$user_id) left join host on (graph_tree_items.host_id=host.id) $sql_join where graph_tree_items.graph_tree_id=$tree_id and graph_tree_items.order_key like '$search_key%' $sql_where order by graph_tree_items.order_key"); */ html_graph_start_box(0, true); print "<tr bgcolor='#" . $colors["header_panel_background"] . "'><td colspan='30'><table cellspacing='0' cellpadding='3' width='100%'><tr><td class='textHeaderDark'><strong><a class='linkOverDark' href='graph_view.php?action=tree&tree_id=" . $_SESSION["sess_view_tree_id"] . "'>[root]</a> - " . db_fetch_cell("select name from graph_tree where id=" . $_SESSION["sess_view_tree_id"]) . "</strong></td></tr></table></td></tr>"; $i = 0; /* loop through each tree item */ if (sizeof($graph_tree_items) > 0) { foreach ($graph_tree_items as $graph_tree_item) { /* find out how 'deep' this item is */ $current_depth = api_graph_tree_item_depth_get($graph_tree_item["order_key"]); /* find the type of the current branch */ //if ($leaf["title"] != "") { $current_leaf_type = "heading"; }elseif (!empty($leaf["local_graph_id"])) { $current_leaf_type = "graph"; }else{ $current_leaf_type = "host"; } /* find the type of the next branch. make sure the next item exists first */ if (isset($graph_tree_items{$i+1})) { $next_leaf_type = $graph_tree_items{$i+1}["item_type"]; }else{ $next_leaf_type = ""; } if ((($current_leaf_type == TREE_ITEM_TYPE_HEADER) || ($current_leaf_type == TREE_ITEM_TYPE_HOST)) && (($current_depth <= $hide_until_depth) || ($hide_until_depth == false))) { $current_title = (($current_leaf_type == TREE_ITEM_TYPE_HEADER) ? $graph_tree_item["item_value"] : $graph_tree_item["host_hostname"]); /* draw heading */ draw_tree_header_row($graph_tree_id, $graph_tree_item["id"], $current_depth, $current_title, true, "0", true); /* this is an open host, lets expand a bit */ if ($current_leaf_type == TREE_ITEM_TYPE_HOST) { /* get a list of all graph templates in use by this host */ $graph_templates = db_fetch_assoc("select graph_templates.id, graph_templates.name from graph_local,graph_templates,graph_templates_graph where graph_local.id=graph_templates_graph.local_graph_id and graph_templates_graph.graph_template_id=graph_templates.id and graph_local.host_id=" . $leaf["host_id"] . " group by graph_templates.id order by graph_templates.name"); if (sizeof($graph_templates) > 0) { foreach ($graph_templates as $graph_template) { draw_tree_header_row($tree_id, $leaf["id"], ($tier+1), $graph_template["name"], false, $leaf["status"], false); /* get a list of each graph using this graph template for this particular host */ $graphs = db_fetch_assoc("select graph_templates_graph.title_cache, graph_templates_graph.local_graph_id from graph_local,graph_templates,graph_templates_graph where graph_local.id=graph_templates_graph.local_graph_id and graph_templates_graph.graph_template_id=graph_templates.id and graph_local.graph_template_id=" . $graph_template["id"] . " and graph_local.host_id=" . $leaf["host_id"] . " order by graph_templates_graph.title_cache"); $graph_ct = 0; if (sizeof($graphs) > 0) { foreach ($graphs as $graph) { /* incriment graph counter so we know when to start a new row or not */ $graph_ct++; if (!isset($graphs[$graph_ct])) { $next_leaf_type = "heading"; }else{ $next_leaf_type = "graph"; } /* draw graph */ $already_open = draw_tree_graph_row($already_open, $graph_ct, $next_leaf_type, ($tier+2), $graph["local_graph_id"], 1, $graph["title_cache"]); } } } } } $graph_ct = 0; }elseif (($current_leaf_type == 'graph') && (($tier <= $hide_until_tier) || ($hide_until_tier == false))) { /* incriment graph counter so we know when to start a new row or not */ $graph_ct++; /* draw graph */ $already_open = draw_tree_graph_row($already_open, $graph_ct, $next_leaf_type, $tier, $leaf["local_graph_id"], $leaf["rra_id"], $leaf["graph_title"]); } /* if we have come back to the tier that was origionally flagged, then take away the flag */ if (($tier <= $hide_until_tier) && ($hide_until_tier != false)) { $hide_until_tier = false; } /* if we are supposed to hide this branch, flag it */ if (($leaf["status"] == "1") && ($hide_until_tier == false)) { $hide_until_tier = $tier; } $i++; } } print "</tr></table></td></tr>"; html_graph_end_box(); }
function api_graph_tree_item_save($graph_tree_item_id, &$_fields_graph_tree_item) { require_once(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_constants.php"); require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_utility.php"); require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_info.php"); /* sanity checks */ validate_id_die($graph_tree_item_id, "graph_tree_item_id", true); /* sanity check for $graph_tree_id */ if ((empty($graph_tree_item_id)) && (empty($_fields_graph_tree_item["graph_tree_id"]))) { log_save("Required graph_tree_id when graph_tree_item_id = 0", SEV_ERROR); return false; }else if ((isset($_fields_graph_tree_item["graph_tree_id"])) && (!db_integer_validate($_fields_graph_tree_item["graph_tree_id"]))) { return false; } /* sanity check for $item_type */ if ((!isset($_fields_graph_tree_item["item_type"])) || (!db_integer_validate($_fields_graph_tree_item["item_type"]))) { log_save("Missing required item_type", SEV_ERROR); return false; } /* sanity check for $item_value */ if ((empty($graph_tree_item_id)) && (empty($_fields_graph_tree_item["item_value"]))) { log_save("Required item_value when graph_tree_item_id = 0", SEV_ERROR); return false; }else if ((isset($_fields_graph_tree_item["item_value"])) && ( (($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_GRAPH) || ($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_HOST)) && (!db_integer_validate($_fields_graph_tree_item["item_value"])) )) { return false; } /* sanity check for $parent_item_id */ if ((!isset($_fields_graph_tree_item["parent_item_id"])) || (!db_integer_validate($_fields_graph_tree_item["parent_item_id"], true))) { log_save("Missing required parent_item_id", SEV_ERROR); return false; } /* field: id */ $_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $graph_tree_item_id); /* field: graph_tree_id */ if (isset($_fields_graph_tree_item["graph_tree_id"])) { $_fields["graph_tree_id"] = array("type" => DB_TYPE_INTEGER, "value" => $_fields_graph_tree_item["graph_tree_id"]); } /* get a copy of the parent tree item id */ if ($_fields_graph_tree_item["parent_item_id"] == "0") { $parent_order_key = ""; $parent_sort_type = TREE_ORDERING_NONE; }else{ $parent_graph_tree_item = api_graph_tree_item_get($_fields_graph_tree_item["parent_item_id"]); $parent_order_key = $parent_graph_tree_item["order_key"]; $parent_sort_type = $parent_graph_tree_item["sort_children_type"]; } /* generate a new order key if this is a new graph tree item */ if (empty($graph_tree_item_id)) { $_fields["order_key"] = array("type" => DB_TYPE_STRING, "value" => api_graph_tree_item_available_order_key_get($_fields_graph_tree_item["graph_tree_id"], $parent_order_key)); }else{ $graph_tree_item = api_graph_tree_item_get($graph_tree_item_id); $_fields["order_key"] = array("type" => DB_TYPE_STRING, "value" => $graph_tree_item["order_key"]); } /* if this item is a graph, make sure it is not being added to the same branch twice */ $search_key = substr($parent_order_key, 0, (api_graph_tree_item_depth_get($parent_order_key) * CHARS_PER_TIER)); if (($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_GRAPH) && (sizeof(db_fetch_assoc("select id from graph_tree_items where item_value = " . $_fields_graph_tree_item["item_value"] . " and item_type = " . TREE_ITEM_TYPE_GRAPH . " and graph_tree_id = " . $_fields_graph_tree_item["graph_tree_id"] . " and order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'")) > 0)) { return true; } /* convert the input array into something that is compatible with db_replace() */ $_fields += sql_get_database_field_array($_fields_graph_tree_item, api_graph_tree_item_form_list()); /* check for an empty field list */ if (sizeof($_fields) == 1) { return true; } if (db_replace("graph_tree_items", $_fields, array("id"))) { if (empty($graph_tree_item_id)) { $graph_tree_item_id = db_fetch_insert_id(); } /* re-parent the branch if the parent item has changed */ if ($_fields_graph_tree_item["parent_item_id"] != api_graph_tree_item_parent_get_bykey($_fields["order_key"]["value"], $_fields_graph_tree_item["graph_tree_id"])) { api_graph_tree_item_reparent($graph_tree_item_id, $_fields_graph_tree_item["parent_item_id"]); } $parent_tree = api_graph_tree_get($_fields_graph_tree_item["graph_tree_id"]); /* tree item ordering */ if ($parent_tree["sort_type"] == TREE_ORDERING_NONE) { /* resort our parent */ if ($parent_sort_type != TREE_ORDERING_NONE) { echo $parent_sort_type; api_graph_tree_item_sort(SORT_TYPE_TREE_ITEM, $_fields_graph_tree_item["parent_item_id"], $parent_sort_type); } /* if this is a header, sort direct children */ if (($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_HEADER) && ($parent_sort_type != TREE_ORDERING_NONE)) { api_graph_tree_item_sort(SORT_TYPE_TREE_ITEM, $graph_tree_item_id, $parent_sort_type); } /* tree ordering */ }else{ /* potential speed savings for large trees */ if (api_graph_tree_item_depth_get($_fields["order_key"]["value"]) == 1) { api_graph_tree_item_sort(SORT_TYPE_TREE, $_fields_graph_tree_item["graph_tree_id"], $parent_tree["sort_type"]); }else{ api_graph_tree_item_sort(SORT_TYPE_TREE_ITEM, $_fields_graph_tree_item["parent_item_id"], $parent_tree["sort_type"]); } } /* if the user checked the 'Propagate Changes' box */ if (($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_HEADER) && (isset($_fields_graph_tree_item["sort_children_type"])) && (!empty($_fields_graph_tree_item["propagate_changes"]))) { $graph_tree_items = api_graph_tree_item_list($_fields_graph_tree_item["graph_tree_id"], array("item_type" => TREE_ITEM_TYPE_HEADER), $graph_tree_item_id, false, false); if (is_array($graph_tree_items) > 0) { foreach ($graph_tree_items as $graph_tree_item) { db_update("graph_tree_items", array( "id" => array("type" => DB_TYPE_INTEGER, "value" => $graph_tree_item["id"]), "sort_children_type" => array("type" => DB_TYPE_INTEGER, "value" => $_fields_graph_tree_item["sort_children_type"]) ), array("id")); if ($_fields_graph_tree_item["sort_children_type"] != TREE_ORDERING_NONE) { api_graph_tree_item_sort(SORT_TYPE_TREE_ITEM, $graph_tree_item["id"], $_fields_graph_tree_item["sort_children_type"]); } } } } return $graph_tree_item_id; }else{ return false; } }
function tree_edit() { $menu_items = array("remove" => "Remove"); $_graph_tree_id = get_get_var_number("id"); if (empty($_graph_tree_id)) { $header_label = "[new]"; } else { $graph_tree = api_graph_tree_get($_graph_tree_id); $header_label = "[edit: " . $graph_tree["name"] . "]"; } form_start("graph_trees.php", "form_graph_tree"); html_start_box("<strong>" . _("Graph Trees") . "</strong> {$header_label}", ""); _graph_tree_field__name("name", isset($graph_tree["name"]) ? $graph_tree["name"] : "", empty($_graph_tree_id) ? 0 : $_graph_tree_id); _graph_tree_field__sort_type("sort_type", isset($graph_tree["sort_type"]) ? $graph_tree["sort_type"] : "", empty($_graph_tree_id) ? 0 : $_graph_tree_id); html_end_box(); form_hidden_box("id", $_graph_tree_id); form_hidden_box("action_post", "graph_tree_edit"); form_save_button("graph_trees.php"); if (!empty($_graph_tree_id)) { echo "<br />\n"; form_start("graph_trees_items.php", "form_graph_tree_item"); $box_id = "1"; html_start_box("<strong>" . _("Tree Items") . "</strong>", "graph_trees_items.php?action=edit&tree_id=" . $_graph_tree_id . "&parent_id=0"); html_header_checkbox(array(_("Item"), _("Type"), ""), $box_id, "1"); /* get a sorted list of all graph items inside of this tree */ $tree_items = api_graph_tree_item_list($_graph_tree_id); /* get a list of available types (header, host, graph, etc) */ $tree_item_types = api_graph_tree_item_type_list(); if (is_array($tree_items) > 0 && sizeof($tree_items) > 0) { foreach ($tree_items as $tree_item) { $current_depth = api_graph_tree_item_depth_get($tree_item["order_key"]); /* keep track of the current item's sort type so we know whether to display sort * arrays for items children or not */ $sort_cache[$current_depth] = $tree_item["sort_children_type"]; $transparent_indent = ""; if ($tree_item["item_type"] == TREE_ITEM_TYPE_GRAPH) { $item_text = $tree_item["graph_title"]; } else { if ($tree_item["item_type"] == TREE_ITEM_TYPE_HEADER) { $item_text = "<strong>" . $tree_item["item_value"] . "</strong></a> (<a href='graph_trees_items.php?action=edit&tree_id=" . $_graph_tree_id . "&parent_id=" . $tree_item["id"] . "'>Add</a>)"; } else { if ($tree_item["item_type"] == TREE_ITEM_TYPE_HOST) { $item_text = "<strong>Device:</strong> " . $tree_item["host_hostname"]; } } } ?> <tr class="item" id="box-<?php echo $box_id; ?> -row-<?php echo $tree_item["id"]; ?> " onClick="display_row_select('<?php echo $box_id; ?> ',document.forms[1],'box-<?php echo $box_id; ?> -row-<?php echo $tree_item["id"]; ?> ', 'box-<?php echo $box_id; ?> -chk-<?php echo $tree_item["id"]; ?> ')" onMouseOver="display_row_hover('box-<?php echo $box_id; ?> -row-<?php echo $tree_item["id"]; ?> ')" onMouseOut="display_row_clear('box-<?php echo $box_id; ?> -row-<?php echo $tree_item["id"]; ?> ')"> <td class="title"> <img width="<?php echo ($current_depth - 1) * 20; ?> " height="1" align="middle" alt=""> <a onClick="display_row_block('box-<?php echo $box_id; ?> -row-<?php echo $tree_item["id"]; ?> ')" href="graph_trees_items.php?action=edit&tree_id=<?php echo $_graph_tree_id; ?> &id=<?php echo $tree_item["id"]; ?> "><span id="box-<?php echo $box_id; ?> -text-<?php echo $tree_item["id"]; ?> "><?php echo html_highlight_words(get_get_var("search_filter"), $item_text); ?> </span></a> </td> <td> <?php echo $tree_item_types[$tree_item["item_type"]]; ?> </td> <?php if (isset($sort_cache[$current_depth - 1]) && $sort_cache[$current_depth - 1] != TREE_ORDERING_NONE || $graph_tree["sort_type"] != TREE_ORDERING_NONE) { ?> <td width="80"> </td> <?php } else { ?> <td width="80" align="center"> <a href="graph_trees_items.php?action=movedown&id=<?php echo $tree_item["id"]; ?> &graph_tree_id=<?php echo $_graph_tree_id; ?> "><img src="<?php echo html_get_theme_images_path("move_down.gif"); ?> " border="0" alt="Move Down"></a> <a href="graph_trees_items.php?action=moveup&id=<?php echo $tree_item["id"]; ?> &graph_tree_id=<?php echo $_graph_tree_id; ?> "><img src="<?php echo html_get_theme_images_path("move_up.gif"); ?> " border="0" alt="Move Up"></a> </td> <?php } ?> <td class="checkbox" align="center"> <input type='checkbox' name='box-<?php echo $box_id; ?> -chk-<?php echo $tree_item["id"]; ?> ' id='box-<?php echo $box_id; ?> -chk-<?php echo $tree_item["id"]; ?> ' title="<?php echo strip_tags($item_text); ?> "> </td> </tr> <?php } } else { ?> <tr class="empty"> <td colspan="6"> No graph tree items found. </td> </tr> <?php } html_box_toolbar_draw($box_id, "1", "3", HTML_BOX_SEARCH_NONE); html_end_box(false); html_box_actions_menu_draw($box_id, "1", $menu_items); form_hidden_box("graph_tree_id", $_graph_tree_id); form_hidden_box("action", "save"); form_hidden_box("action_post", "graph_tree_item_list"); form_end(); ?> <script language="JavaScript"> <!-- function action_area_handle_type(box_id, type, parent_div, parent_form) { if (type == 'remove') { parent_div.appendChild(document.createTextNode('Are you sure you want to remove these graph tree items?')); parent_div.appendChild(action_area_generate_selected_rows(box_id)); action_area_update_header_caption(box_id, 'Remove Graph Tree Item'); action_area_update_submit_caption(box_id, 'Remove'); action_area_update_selected_rows(box_id, parent_form); } } --> </script> <?php } }