function generate_tree($id, $mode = '') { # selected item # get childs $child_array = get_childs($id, $mode); # get information of selected item $query = 'SELECT DISTINCT attr_value as name,ItemLinks.fk_id_item AS item_id, (SELECT config_class FROM ConfigItems,ConfigClasses WHERE id_class=fk_id_class AND id_item=item_id) AS type, (SELECT attr_value FROM ConfigValues, ItemLinks, ConfigAttrs, ConfigClasses WHERE ConfigValues.fk_id_item = ItemLinks.fk_item_linked2 AND id_attr = ConfigValues.fk_id_attr AND attr_name = "icon_image" AND id_class = fk_id_class AND config_class = "os" AND ItemLinks.fk_id_item = item_id ) AS os_icon FROM ConfigValues,ItemLinks,ConfigAttrs,ConfigClasses WHERE ItemLinks.fk_id_item=ConfigValues.fk_id_item AND id_attr=ItemLinks.fk_id_attr AND ConfigAttrs.visible="yes" AND fk_id_class=id_class AND (SELECT naming_attr FROM ConfigAttrs WHERE id_attr=ConfigValues.fk_id_attr)="yes" AND ItemLinks.fk_id_item="' . $id . '" ORDER BY config_class DESC,attr_value'; $selected_item_info = db_handler($query, "assoc", "Get informations on selected item"); # get informations about host # prepend inforomation from selected host to the top of the list array_unshift($child_array, get_informations($id)); # set values of selected item AND put all childs (generated bevore) in it. $root_item = array($id => array("id" => $id, "selected" => TRUE, "status" => 'open', "name" => $selected_item_info["name"], "type" => $selected_item_info["type"], "os_icon" => $selected_item_info["os_icon"], "childs" => $child_array)); # get parents $parents_flat = get_parents($id); # make the parents array ordered top2down $parents_flat = array_reverse($parents_flat); # prepare list (if there are parents call the prepare function if (!empty($parents_flat)) { $tree = prepare_dependency($parents_flat, $root_item); } else { $tree = $root_item; } ## Display the top tree item # check for parent loop error if (isset($tree[0]["status"]) and $tree[0]["status"] == "loop_error") { # make a error item at the top $dependency_tree = array("root" => array("id" => "root", "status" => 'open', "name" => TXT_DEPVIEW_ERROR_LOOP, "type" => "warn", "childs" => $tree)); } else { # make a root tree at the top $dependency_tree = array("root" => array("id" => "root", "status" => 'open', "name" => "Top level", "type" => "parent", "childs" => $tree)); } //echo "<pre>"; //var_dump($tree); //echo "</pre>"; echo '<div>'; displayTree_list($dependency_tree); echo '</div>'; }
function displayTree_list($arr, $status = "open", $level = 0, $space = array(), &$unique_counter = 0) { $unique_counter++; # $array_size and $array_counter needed for locate the last item $array_size = count($arr); $array_counter = 0; $last_item = FALSE; echo '<div style="padding:0px; margin:0px;">'; foreach ($arr as $k => $v) { $array_counter++; if ($array_size == $array_counter) { $last_item = TRUE; array_push($space, $level); } # tree open / close? (else it would get status from function call) if (!empty($v["status"])) { $status = $v["status"]; } echo '<div style="margin-left: 0px; height:18px;">'; # make spaces or lines, $spaces gives the col numbers which are space $tree = ''; for ($i = 0; $i < $level; $i++) { if (in_array($i, $space)) { $tree .= '<img src="' . TREE_SPACE . '">'; } else { $tree .= '<img src="' . TREE_LINE . '">'; } } # go through childs if (!empty($v["childs"])) { # +/- if ($last_item) { $tree_plus = TREE_PLUS_LAST; $tree_minus = TREE_MINUS_LAST; } else { $tree_plus = TREE_PLUS; $tree_minus = TREE_MINUS; } if ($status == "open") { $tree_switch = '<a href="javascript:swap_tree(\'' . $v["id"] . $unique_counter . '\', \'' . $tree_plus . '\', \'' . $tree_minus . '\')">'; $tree_switch .= '<img src="' . $tree_minus . '" id="swap_icon_' . $v["id"] . $unique_counter . '" >'; $tree_switch .= '</a>'; } else { $tree_switch = '<a href="javascript:swap_tree(\'' . $v["id"] . $unique_counter . '\', \'' . $tree_plus . '\', \'' . $tree_minus . '\')">'; $tree_switch .= '<img src="' . $tree_plus . '" id="swap_icon_' . $v["id"] . $unique_counter . '" >'; $tree_switch .= '</a>'; } } else { if ($last_item) { $tree_item = TREE_ITEM_LAST; } else { $tree_item = TREE_ITEM; } $tree_switch = '<img src="' . $tree_item . '">'; } # standard size of logos in tree $icon_size = 'width="18" height="18"'; # check icon if (!empty($v["type"])) { # icon for different types if ($v["type"] == "service") { $icon_path = TREE_SERVICE; # service icons are only 16 } elseif ($v["type"] == "parent") { $icon_path = TREE_PARENT; } elseif ($v["type"] == "info") { $icon_path = TREE_INFO; } elseif ($v["type"] == "warn") { $icon_path = TREE_WARNING; } elseif ($v["type"] == "host" and !empty($v["os_icon"])) { $icon_path = OS_LOGO_PATH . '/' . $v["os_icon"]; } } else { # no type set, but perhaps still a icon path if (!empty($v["os_icon"])) { $icon_path = $v["os_icon"]; } else { } } # this variable holds the text (hostname, informations etc.) $tree_content_name = ''; # check if icon exists if (!empty($icon_path) and file_exists($icon_path)) { $tree_item_logo = '<img src="' . $icon_path . '" alt="' . $icon_path . '"' . $icon_size . '>'; } else { $tree_item_logo = ''; if (!empty($v["title"])) { $tree_content_name .= $v["title"]; } } # Text content of item $tree_content = '<span style="margin-left: 5px; height:18px; position: absolute">'; # mark selected host if (!empty($v["selected"]) and $v["selected"] == TRUE) { $tree_content_name .= '<b>' . $v["name"] . '</b>'; } else { $tree_content_name .= $v["name"]; } if (!empty($v["type"]) and $v["type"] == "host") { # link for hosts if (!empty($_GET["xmode"])) { $tree_content .= '<a href="dependency.php?xmode=' . $_GET["xmode"] . '&id=' . $v["id"]; if (!empty($_GET["pnp_link"])) { $tree_content .= '&pnp_link=' . $_GET["pnp_link"]; } if (!empty($_GET["service_link"])) { $tree_content .= '&service_link=' . $_GET["service_link"]; } $tree_content .= '" style="height:18px;">'; } else { $tree_content .= '<a href="dependency.php?id=' . $v["id"] . '" style="height:18px;">'; } $tree_content .= $tree_content_name; $tree_content .= '</a>'; } elseif (!empty($v["link"])) { # link for services if (!empty($_GET["xmode"]) and !empty($v["link"])) { $tree_content .= '<a href="' . $v["link"] . '" style="height:18px;">'; $tree_content .= $tree_content_name; $tree_content .= '</a>'; } else { $tree_content .= $tree_content_name; } } else { $tree_content .= $tree_content_name; } $tree_content .= '</span>'; # print content in choosen order echo $tree . $tree_switch . $tree_item_logo . $tree_content; echo '</div>'; if (!empty($v["childs"])) { echo '<div '; if ($status == "open") { echo 'style=""'; } else { echo 'style="display:none"'; } echo ' id="' . $v["id"] . $unique_counter . '">'; displayTree_list($v["childs"], $status, $level + 1, $space, $unique_counter); echo '</div>'; } } echo '</div>'; }
$entries[] = array("id" => $id, "name" => $item_name, "title" => $item_class . ": ", "status" => "open", "childs" => $services); } else { # for single (any other) classes $entries[] = array("id" => $id, "name" => $item_name, "title" => $item_class . ": ", "type" => $item_class); } } } //foreach # service deletion: sort the array on hostnames ksort($entries); # Modify text on top tree element (root) when deleting services if ($item_class == "service") { $items = "services"; } else { $items = "items"; } $tree_view = array("root" => array("id" => "root", "status" => 'open', "name" => "The following {$items} will be deleted", "type" => "parent", "childs" => $entries)); # display tree echo '<br><div>'; displayTree_list($tree_view); echo '</div>'; } else { NConf_DEBUG::set("No item to delete", "ERROR"); } if (NConf_DEBUG::status('ERROR')) { echo NConf_HTML::limit_space(NConf_HTML::show_error()); echo "<br><br>"; echo NConf_HTML::back_button($_SESSION["go_back_page"]); } mysql_close($dbh); require_once 'include/foot.php';