function html_tree_dropdown_draw($graph_tree_id, $field_name, $field_value) { 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"); $tree_items = api_graph_tree_item_list($graph_tree_id, array("item_type" => TREE_ITEM_TYPE_HEADER)); echo "<select name='$field_name'>\n<option value='0'>[root]</option>\n"; if ((is_array($tree_items)) && (sizeof($tree_items) > 0)) { foreach ($tree_items as $tree_item) { $current_depth = api_graph_tree_item_depth_get($tree_item["order_key"]); $indent = str_repeat("---", ($current_depth)); if ($field_value == $tree_item["id"]) { $html_selected = " selected"; }else{ $html_selected = ""; } echo "<option value='" . $tree_item["id"] . "'$html_selected>$indent " . $tree_item["item_value"] . "</option>\n"; } } echo "</select>\n"; }
function api_graph_tree_item_remove($graph_tree_item_id) { 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"); /* sanity checks */ validate_id_die($graph_tree_item_id, "graph_tree_item_id"); /* obtain a copy of the current graph tree item */ $graph_tree_item = api_graph_tree_item_get($graph_tree_item_id); /* find the id of the parent */ $parent_graph_tree_item_id = api_graph_tree_item_parent_get($graph_tree_item_id); /* because deleting a parent branch deletes all of its children, it is very possible that * the branch we are trying to delete has already been removed. */ if (!isset($graph_tree_item["id"])) { return true; } /* if this item is a graph or host, it will have NO children, so we can just delete the * item and exit. */ if (($graph_tree_item["item_type"] == TREE_ITEM_TYPE_GRAPH) || ($graph_tree_item["item_type"] == TREE_ITEM_TYPE_HOST)) { return db_delete("graph_tree_items", array( "id" => array("type" => DB_TYPE_INTEGER, "value" => $graph_tree_item_id) )); } /* make sure nothing bad happens */ if (!api_graph_tree_item_order_key_validate($graph_tree_item["order_key"])) { return false; } $graph_tree_items = api_graph_tree_item_list($graph_tree_item["graph_tree_id"], "", $graph_tree_item_id, true, true); if (is_array($graph_tree_items) > 0) { /* remove all child items */ foreach ($graph_tree_items as $_graph_tree_item) { db_delete("graph_tree_items", array( "id" => array("type" => DB_TYPE_INTEGER, "value" => $_graph_tree_item["id"]) )); } } /* CLEANUP - reorder the tier that this branch lies in */ $base_order_key = substr($graph_tree_item["order_key"], 0, (CHARS_PER_TIER * (api_graph_tree_item_depth_get($graph_tree_item["order_key"]) - 1))); /* refetch the graph tree item list now that the selected item has been removed */ $graph_tree_items = api_graph_tree_item_list($graph_tree_item["graph_tree_id"], "", $parent_graph_tree_item_id, true, true); if ((is_array($graph_tree_items)) && (sizeof($graph_tree_items) > 0)) { $old_key_part = substr($graph_tree_items[0]["order_key"], strlen($base_order_key), CHARS_PER_TIER); /* we key tier==0 off of '1' and tier>0 off of '0' */ if (api_graph_tree_item_depth_get($base_order_key) == 0) { $i = 1; }else{ $i = 0; } foreach ($graph_tree_items as $_graph_tree_item) { /* this is the key column we are going to 'rekey' */ $new_key_part = substr($_graph_tree_item["order_key"], strlen($base_order_key), CHARS_PER_TIER); /* incriment a counter for the new key column */ if ($old_key_part != $new_key_part) { $i++; } /* build the new order key string */ $key = $base_order_key . str_pad(strval($i), CHARS_PER_TIER, '0', STR_PAD_LEFT) . substr($_graph_tree_item["order_key"], (strlen($base_order_key) + CHARS_PER_TIER)); db_update("graph_tree_items", array( "order_key" => array("type" => DB_TYPE_STRING, "value" => $key), "id" => array("type" => DB_TYPE_INTEGER, "value" => $_graph_tree_item["id"]) ), array("id")); $old_key_part = $new_key_part; } } }
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 } }