1 Description: treeview has a license issue, cacti upstream is going to replace it
2 with functionality from jquery.jstree.
4 This patch implements the changes needed for an upstream layout where the
5 necessary code is in cacti/include/js/jquery/ but the code in that path is
6 not included in this patch.
8 The necessary jquery scripts and theme info can come from cacti upstream and from
9 debian packages (libjs-jquery and libjs-jquery-cookie) The version used when
10 creating this patch can be found here:
11 http://svn.cacti.net/viewvc/cacti/branches/0.8.9/include/js/jquery/jquery.js?pathrev=7324
12 http://svn.cacti.net/viewvc/cacti/branches/0.8.9/include/js/jquery/jquery.jstree.js?pathrev=7324
13 http://svn.cacti.net/viewvc/cacti/branches/main/include/js/jquery/themes/default/?pathrev=7324
14 http://anonscm.debian.org/gitweb/?p=pkg-javascript/jquery-goodies.git;a=blob;f=cookie/jquery.cookie.js;hb=c50e1a2d599cb48893e8d77470e71e83e44dfdb5
16 This patch does NOT implement the changes needed for the Debian package of
19 This patch was updated with the patch from Jan Zalesak <zalesak@jaw.cz> in
20 http://bugs.debian.org/702690 which was further improved to also cover
21 lib/graph_export.php and to keep tag alignment consistent.
22 Bug: http://bugs.cacti.net/view.php?id=2228
23 Bug-Debian: http://bugs.debian.org/679980
24 Author: Paul Gevers <elbrus@debian.org>
25 Date: Sun, 31 Mar 2013 11:59:05 +0200
27 --- a/include/top_graph_header.php
28 +++ b/include/top_graph_header.php
30 <link href="<?php echo $config['url_path']; ?>include/main.css" type="text/css" rel="stylesheet">
31 <link href="<?php echo $config['url_path']; ?>images/favicon.ico" rel="shortcut icon"/>
32 <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/layout.js"></script>
33 - <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/treeview/ua.js"></script>
34 - <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/treeview/ftiens4.js"></script>
35 + <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/js/jquery/jquery.js" language="javascript"></script>
36 + <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/js/jquery/jquery.cookie.js" language="javascript"></script>
37 + <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/js/jquery/jquery.jstree.js"></script>
38 <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/jscalendar/calendar.js"></script>
39 <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/jscalendar/lang/calendar-en.js"></script>
40 <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/jscalendar/calendar-setup.js"></script>
42 <td valign="top" style="padding: 5px; border-right: #aaaaaa 1px solid;background-repeat:repeat-y;background-color:#efefef;" bgcolor='#efefef' width='<?php print htmlspecialchars(read_graph_config_option("default_dual_pane_width"));?>' class='noprint'>
43 <table border=0 cellpadding=0 cellspacing=0><tr><td><a style="font-size:7pt;text-decoration:none;color:silver" href="http://www.treemenu.net/" target=_blank></a></td></tr></table>
44 <?php grow_dhtml_trees(); ?>
45 - <script type="text/javascript">initializeDocument();</script>
47 <?php if (isset($_GET["select_first"])) { ?>
48 <script type="text/javascript">
49 --- a/lib/graph_export.php
50 +++ b/lib/graph_export.php
51 @@ -1365,15 +1365,6 @@
52 /* create the treeview representation for the html data */
53 grow_dhtml_trees_export($fp,$tree_id);
55 - fwrite($fp,"<script type='text/javascript'>initializeDocument();</script>\n");
56 - fwrite($fp,"<script type='text/javascript'>\n");
57 - fwrite($fp,"var obj;\n");
58 - fwrite($fp,"obj = findObj(1);\n");
59 - fwrite($fp,"if (!obj.isOpen) {\n");
60 - fwrite($fp,"clickOnNode(1);\n");
62 - fwrite($fp,"clickOnLink(2,'','main');\n");
63 - fwrite($fp,"</script>\n");
64 fwrite($fp,"</td>\n");
65 fwrite($fp,"<td valign='top'>\n");
67 @@ -1383,16 +1374,7 @@
68 include_once($config["library_path"] . "/tree.php");
69 include_once($config["library_path"] . "/data_query.php");
71 - fwrite($fp, "<script type='text/javascript'>\n");
78 - ICONPATH = 'treeview/'
81 + fwrite($fp, "<div id=\"jtree\">\n");
83 if (read_config_option("export_tree_isolation") == "off") {
85 @@ -1413,9 +1395,34 @@
89 - fwrite($fp,"foldersTree.treeID = \"t2\"
92 + fwrite($fp, "</div>\n");
93 + fwrite($fp, "<script type=\"text/javascript\">\n");
94 + fwrite($fp, "$(function () {
97 + \"plugins\" : [\"ui\",\"themes\",\"html_data\",\"cookies\"],
98 + \"themes\" : {\"icons\" : false,
99 + \"url\" : \"./js/style.css\"},
101 + \"save_opened\" : \"Cacti_jstree_open\",
102 + \"save_selected\" : \"Cacti_jstree_select\"
107 + // Make sure that the nodes are actually used as links
108 + // We need reselect to prevent endless loops
109 + // https://groups.google.com/d/topic/jstree/j6XNq9hQdeA/discussion
110 + .bind(\"reselect.jstree\", function (e, data) {
111 + data.inst.get_container().bind(\"select_node.jstree\", function (e, data) {
112 + // data.rstl.obj is the object that was selected.
113 + document.location.href = data.rslt.obj.children(\"a\").attr(\"href\");
118 + fwrite($fp, "</script>\n");
122 /* get_graph_tree_array_export - returns a list of graph trees taking permissions into account if
123 @@ -1478,8 +1485,7 @@
124 $dhtml_tree = array();
125 $dhtml_tree[0] = $start;
126 $dhtml_tree[1] = read_graph_config_option("expand_hosts");
127 - $dhtml_tree[2] = "foldersTree = gFld(\"\", \"\")\n";
131 $tree_list = get_graph_tree_array_export();
133 @@ -1499,7 +1505,6 @@
134 if (((read_config_option("export_tree_isolation") == "on") && ($tree_id == $tree["id"])) ||
135 (read_config_option("export_tree_isolation") == "off")) {
139 $hier_sql = "SELECT DISTINCT
141 @@ -1522,19 +1527,53 @@
144 if (sizeof($hierarchy) > 0) {
149 foreach ($hierarchy as $leaf) {
150 if ($dhtml_tree_id <> $tree["id"]) {
151 - $dhtml_tree[$i] = "ou0 = insFld(foldersTree, gFld(\"" . get_tree_name($tree["id"]) . "\", \"" . clean_up_export_name(get_tree_name($tree["id"])) . "_leaf.html\"))\n";
154 + $dhtml_tree[$i] = "\t\t\t</ul>\n\t\t</li>\n\t</ul>\n";
157 + $clean_id = clean_up_export_name(get_tree_name($tree["id"]));
158 + $dhtml_tree[$i] = "\t<ul>\n\t\t<li id=\"" . $clean_id . "\"><a href=\"" . $clean_id . "_leaf.html\">" . get_tree_name($tree["id"]) . "</a>\n\t\t\t<ul>\n";
161 $dhtml_tree_id = $tree["id"];
164 $tier = tree_tier($leaf["order_key"]);
166 if ($leaf["host_id"] > 0) { //It's a host
167 - $dhtml_tree[$i] = "ou" . ($tier) . " = insFld(ou" . ($tier-1) . ", gFld(\"Host: " . $leaf["hostname"] . "\", \"" . clean_up_export_name($leaf["hostname"] . "_" . $leaf["id"]) . ".html\"))\n";
168 + if ($tier > $last_tier) {
170 + $dhtml_tree[$i] = "\t\t\t<ul>\n";
171 + } elseif ($tier < $last_tier) {
174 + $dhtml_tree[$i] = "\t\t\t\t</li>\n";
176 + for ($x = $tier; $x < $last_tier; $x++) {
178 + $dhtml_tree[$i] = "\t\t\t</ul>\n\t\t\t\t</li>\n";
181 + } elseif ($openli && !$lasthost) {
183 + $dhtml_tree[$i] = "\t\t\t\t</li>\n";
186 + $last_tier = $tier;
189 + $clean_id = clean_up_export_name($leaf["hostname"] . "_" . $leaf["id"]);
190 + $dhtml_tree[$i] = "\t\t\t\t<li id=\"" . $clean_id . "\"><a href=\"" . $clean_id . ".html\">Host: " . htmlspecialchars($leaf["hostname"]) . "</a>\n";
192 if (read_config_option("export_tree_expand_hosts") == "on") {
194 + $dhtml_tree[$i] = "\t\t\t\t\t<ul>\n";
195 if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) {
196 $graph_templates = db_fetch_assoc("SELECT
198 @@ -1552,7 +1591,8 @@
199 if (sizeof($graph_templates) > 0) {
200 foreach ($graph_templates as $graph_template) {
202 - $dhtml_tree[$i] = "ou" . ($tier+1) . " = insFld(ou" . ($tier) . ", gFld(\" " . $graph_template["name"] . "\", \"" . clean_up_export_name($leaf["hostname"] . "_gt_" . $leaf["id"]) . "_" . $graph_template["id"] . ".html\"))\n";
203 + $clean_id = clean_up_export_name($leaf["hostname"] . "_gt_" . $leaf["id"] . "_" . $graph_template["id"]);
204 + $dhtml_tree[$i] = "\t\t\t\t\t\t<li id=\"" . $clean_id . "\"><a href=\"" . $clean_id . ".html\">" . htmlspecialchars($graph_template["name"]) . "</a></li>\n";
207 }else if ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
208 @@ -1567,36 +1607,77 @@
210 array_push($data_queries, array(
212 - "name" => "Graph Template Based"
213 + "name" => "Non Query Based"
216 if (sizeof($data_queries) > 0) {
217 - foreach ($data_queries as $data_query) {
220 - $dhtml_tree[$i] = "ou" . ($tier+1) . " = insFld(ou" . ($tier) . ", gFld(\" " . $data_query["name"] . "\", \"" . clean_up_export_name($leaf["hostname"] . "_dq_" . $leaf["title"] . "_" . $leaf["id"]) . "_" . $data_query["id"] . ".html\"))\n";
221 + foreach ($data_queries as $data_query) {
223 + $clean_id = clean_up_export_name($leaf["hostname"] . "_dq_" . $leaf["title"] . "_" . $leaf["id"] . "_" . $data_query["id"]);
224 + $dhtml_tree[$i] = "\t\t\t\t\t\t<li id=\"" . $clean_id . "\"><a href=\"" . $clean_id . ".html\">" . htmlspecialchars($data_query["name"]) . "</a>\n";
226 - /* fetch a list of field names that are sorted by the preferred sort field */
227 - $sort_field_data = get_formatted_data_query_indexes($leaf["host_id"], $data_query["id"]);
228 + /* fetch a list of field names that are sorted by the preferred sort field */
229 + $sort_field_data = get_formatted_data_query_indexes($leaf["host_id"], $data_query["id"]);
231 - if ($data_query["id"] > 0) {
232 - while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
233 + if ($data_query["id"] > 0) {
235 + $dhtml_tree[$i] = "\t\t\t\t\t\t\t<ul>\n";
236 + while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
238 + $clean_id = clean_up_export_name($leaf["hostname"] . "_dqi_" . $leaf["id"] . "_" . $data_query["id"] . "_" . $snmp_index);
239 + $dhtml_tree[$i] = "\t\t\t\t\t\t\t\t<li id=\"" . $clean_id . "\"><a href=\"" . $clean_id . ".html\">" . htmlspecialchars($sort_field_value) . "</a></li>\n";
242 - $dhtml_tree[$i] = "ou" . ($tier+2) . " = insFld(ou" . ($tier+1) . ", gFld(\" " . $sort_field_value . "\", \"" . clean_up_export_name($leaf["hostname"] . "_dqi_" . $leaf["title"] . "_" . $leaf["id"]) . "_" . $data_query["id"] . "_" . $snmp_index . ".html\"))\n";
243 + $dhtml_tree[$i] = "\t\t\t\t\t\t\t</ul>\n";
246 + $dhtml_tree[$i] = "\t\t\t\t\t\t</li>\n";
252 + $dhtml_tree[$i] = "\t\t\t\t\t</ul>\n";
255 - $dhtml_tree[$i] = "ou" . ($tier) . " = insFld(ou" . ($tier-1) . ", gFld(\"" . $leaf["title"] . "\", \"" . clean_up_export_name(get_tree_name($tree["id"]) . "_" . $leaf["title"] . "_" . $leaf["id"]) . "_leaf.html\"))\n";
257 + $dhtml_tree[$i] = "\t\t\t\t</li>\n";
258 + }else { //It's not a host
259 + if ($tier > $last_tier) {
261 + $dhtml_tree[$i] = "\t\t\t<ul>\n";
262 + } elseif ($tier < $last_tier) {
265 + $dhtml_tree[$i] = "</li>\n";
267 + for ($x = $tier; $x < $last_tier; $x++) {
269 + $dhtml_tree[$i] = "\t\t\t\t</ul>\n\t\t\t\t</li>\n";
272 + } elseif ($openli && !$lasthost) {
274 + $dhtml_tree[$i] = "</li>\n";
277 + $last_tier = $tier;
279 + $clean_id = clean_up_export_name(get_tree_name($tree["id"]) . "_" . $leaf["title"] . "_" . $leaf["id"]);
280 + $dhtml_tree[$i] = "\t\t\t\t<li id=\"" . $clean_id . "\"><a href=\"" . $clean_id . "_leaf.html\">" . htmlspecialchars($leaf["title"]) . "</a>\n";
285 + for ($x = $last_tier; $x > 1; $x--) {
287 + $dhtml_tree[$i] = "\t\t\t\t\t</ul>\n\t\t\t\t</li>\n";
290 + $dhtml_tree[$i] = "\t\t\t</ul>\n\t\t</li>\n\t</ul>\n";
292 if ($dhtml_tree_id <> $tree["id"]) {
293 - $dhtml_tree[$i] = "ou0 = insFld(foldersTree, gFld(\"" . get_tree_name($tree["id"]) . "\", \"" . clean_up_export_name(get_tree_name($tree["id"])) . "_leaf.html\"))\n";
295 + $clean_id = clean_up_export_name(get_tree_name($tree["id"]));
296 + $dhtml_tree[$i] = "\t<ul>\n\t\t<li id=\"" . $clean_id . "_leaf\"><a href=\"" . $clean_id . "_leaf.html\">" . get_tree_name($tree["id"]) . "</a></li>\n\t</ul>";
300 @@ -1612,10 +1693,10 @@
301 $dir - the export directory where graphs will either be staged or located.
303 function create_export_directory_structure($cacti_root_path, $dir) {
304 - /* create the treeview sub-directory */
305 - if (!is_dir("$dir/treeview")) {
306 - if (!mkdir("$dir/treeview", 0755)) {
307 - export_fatal("Create directory '" . $dir . "/treeview' failed. Can not continue");
308 + /* create the jquery sub-directory */
309 + if (!is_dir("$dir/js")) {
310 + if (!mkdir("$dir/js", 0755)) {
311 + export_fatal("Create directory '" . $dir . "/js' failed. Can not continue");
315 @@ -1626,8 +1707,6 @@
319 - $treeview_dir = $dir . "/treeview";
322 copy("$cacti_root_path/include/main.css", "$dir/main.css");
324 @@ -1639,18 +1718,15 @@
325 copy("$cacti_root_path/images/shadow_gray.gif", "$dir/shadow_gray.gif");
327 /* java scripts for the tree */
328 - copy("$cacti_root_path/include/treeview/ftiens4_export.js", "$treeview_dir/ftiens4.js");
329 - copy("$cacti_root_path/include/treeview/ua.js", "$treeview_dir/ua.js");
331 - /* images for the tree */
332 - copy("$cacti_root_path/include/treeview/ftv2blank.gif", "$treeview_dir/ftv2blank.gif");
333 - copy("$cacti_root_path/include/treeview/ftv2lastnode.gif", "$treeview_dir/ftv2lastnode.gif");
334 - copy("$cacti_root_path/include/treeview/ftv2mlastnode.gif", "$treeview_dir/ftv2mlastnode.gif");
335 - copy("$cacti_root_path/include/treeview/ftv2mnode.gif", "$treeview_dir/ftv2mnode.gif");
336 - copy("$cacti_root_path/include/treeview/ftv2node.gif", "$treeview_dir/ftv2node.gif");
337 - copy("$cacti_root_path/include/treeview/ftv2plastnode.gif", "$treeview_dir/ftv2plastnode.gif");
338 - copy("$cacti_root_path/include/treeview/ftv2pnode.gif", "$treeview_dir/ftv2pnode.gif");
339 - copy("$cacti_root_path/include/treeview/ftv2vertline.gif", "$treeview_dir/ftv2vertline.gif");
340 + copy("$cacti_root_path/include/js/jquery/jquery.js", "$dir/js/jquery.js");
341 + copy("$cacti_root_path/include/js/jquery/jquery.jstree.js", "$dir/js/jquery.jstree.js");
342 + copy("$cacti_root_path/include/js/jquery/jquery.cookie.js", "$dir/js/jquery.cookie.js");
344 + /* theme info for java scripts */
345 + copy("$cacti_root_path/include/js/jquery/themes/default/style.css", "$dir/js/style.css");
346 + copy("$cacti_root_path/include/js/jquery/themes/default/d.png", "$dir/js/d.png");
347 + copy("$cacti_root_path/include/js/jquery/themes/default/d.gif", "$dir/js/d.gif");
348 + copy("$cacti_root_path/include/js/jquery/themes/default/throbber.gif", "$dir/js/throbber.gif");
351 function get_host_description($host_id) {
352 @@ -1738,8 +1814,9 @@
353 <meta http-equiv=refresh content='300'; url='index.html'>
354 <meta http-equiv=Pragma content=no-cache>
355 <meta http-equiv=cache-control content=no-cache>
356 - <script type=\"text/javascript\" src=\"./treeview/ua.js\"></script>
357 - <script type=\"text/javascript\" src=\"./treeview/ftiens4.js\"></script>
358 + <script type=\"text/javascript\" src=\"./js/jquery.js\" language=\"javascript\"></script>
359 + <script type=\"text/javascript\" src=\"./js/jquery.cookie.js\" language=\"javascript\"></script>
360 + <script type=\"text/javascript\" src=\"./js/jquery.jstree.js\" language=\"javascript\"></script>
363 <table style='width:100%;height:100%;' cellspacing='0' cellpadding='0'>
364 --- a/lib/html_tree.php
365 +++ b/lib/html_tree.php
367 include_once($config["library_path"] . "/data_query.php");
370 - <script type="text/javascript">
380 /* get current time */
381 +/* Probably not needed anymore as jstree uses jquery.cookies
382 list($micro,$seconds) = explode(" ", microtime());
383 $current_time = $seconds + $micro;
384 $expand_hosts = read_graph_config_option("expand_hosts");
386 $dhtml_tree = $_SESSION['dhtml_tree'];
390 + $dhtml_tree = create_dhtml_tree();
392 $total_tree_items = sizeof($dhtml_tree) - 1;
395 print $dhtml_tree[$i];
400 +<script type="text/javascript">
404 + "plugins" : ["ui","themes","html_data","cookies"],
405 + "themes" : {"icons" : false,
406 + "url" : "<?php echo $config['url_path']; ?>include/js/jquery/themes/default/style.css"},
408 + "save_opened" : "Cacti_jstree_open",
409 + "save_selected" : "Cacti_jstree_select"
413 + // Make sure that the nodes are actually used as links
414 + // We need reselect to prevent endless loops
415 + // https://groups.google.com/d/topic/jstree/j6XNq9hQdeA/discussion
416 + .bind("reselect.jstree", function (e, data) {
417 + data.inst.get_container().bind("select_node.jstree", function (e, data) {
418 + // data.rstl.obj is the object that was selected.
419 + document.location.href = data.rslt.obj.children("a").attr("href");
430 $dhtml_tree[0] = $start;
431 $dhtml_tree[1] = read_graph_config_option("expand_hosts");
432 - $dhtml_tree[2] = "foldersTree = gFld(\"\", \"\")\n";
433 - $dhtml_tree[3] = "foldersTree.xID = \"root\"\n";
435 + $dhtml_tree[2] = "\n<div id=\"jtree\">\n";
438 $tree_list = get_graph_tree_array();
442 if (sizeof($tree_list) > 0) {
443 foreach ($tree_list as $tree) {
445 $hierarchy = db_fetch_assoc("select
447 graph_tree_items.title,
448 @@ -583,21 +598,45 @@
449 and graph_tree_items.local_graph_id = 0
450 order by graph_tree_items.order_key");
452 - $dhtml_tree[$i] = "ou0 = insFld(foldersTree, gFld(\"" . htmlspecialchars($tree["name"]) . "\", \"" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree["id"]) . "\"))\n";
454 - $dhtml_tree[$i] = "ou0.xID = \"tree_" . $tree["id"] . "\"\n";
455 + $dhtml_tree[$i] = "\t<ul>\n\t\t<li id=\"" . htmlspecialchars("tree_" . $tree["id"]) . "\"><a href=\"" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree["id"]) . "\">" . htmlspecialchars($tree["name"]) . "</a>\n";
457 if (sizeof($hierarchy) > 0) {
459 + $dhtml_tree[$i] = "\t\t\t<ul>\n";
463 foreach ($hierarchy as $leaf) {
465 $tier = tree_tier($leaf["order_key"]);
467 - if ($leaf["host_id"] > 0) {
468 - $dhtml_tree[$i] = "ou" . ($tier) . " = insFld(ou" . abs(($tier-1)) . ", gFld(\"" . "Host: " . htmlspecialchars($leaf["hostname"]) . "\", \"" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree["id"] . "&leaf_id=" . $leaf["id"]) . "\"))\n";
469 + if ($leaf["host_id"] > 0) { //It's a host
470 + if ($tier > $last_tier) {
472 + $dhtml_tree[$i] = "\t\t\t<ul>\n";
473 + } elseif ($tier < $last_tier) {
476 + $dhtml_tree[$i] = "\t\t\t\t</li>\n";
478 + for ($x = $tier; $x < $last_tier; $x++) {
480 + $dhtml_tree[$i] = "\t\t\t</ul>\n\t\t\t\t</li>\n";
483 + } elseif ($openli && !$lasthost) {
485 + $dhtml_tree[$i] = "\t\t\t\t</li>\n";
488 + $last_tier = $tier;
491 - $dhtml_tree[$i] = "ou" . ($tier) . ".xID = \"tree_" . $tree["id"] . "_leaf_" . $leaf["id"] . "\"\n";
492 + $dhtml_tree[$i] = "\t\t\t\t<li id=\"" . htmlspecialchars("tree_" . $tree["id"] . "_leaf_" . $leaf["id"]) . "\"><a href=\"" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree["id"] . "&leaf_id=" . $leaf["id"]) . "\">Host: " . htmlspecialchars($leaf["hostname"]) . "</a>\n";
494 if (read_graph_config_option("expand_hosts") == "on") {
496 + $dhtml_tree[$i] = "\t\t\t\t\t<ul>\n";
497 if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) {
498 $graph_templates = db_fetch_assoc("select
501 if (sizeof($graph_templates) > 0) {
502 foreach ($graph_templates as $graph_template) {
504 - $dhtml_tree[$i] = "ou" . ($tier+1) . " = insFld(ou" . ($tier) . ", gFld(\" " . htmlspecialchars($graph_template["name"]) . "\", \"graph_view.php?action=tree&tree_id=" . $tree["id"] . "&leaf_id=" . $leaf["id"] . "&host_group_data=graph_template:" . $graph_template["id"] . "\"))\n";
506 - $dhtml_tree[$i] = "ou" . ($tier+1) . ".xID = \"tree_" . $tree["id"] . "_leaf_" . $leaf["id"] . "_hgd_gt_" . $graph_template["id"] . "\"\n";
507 + $dhtml_tree[$i] = "\t\t\t\t\t\t<li id=\"" . htmlspecialchars("tree_" . $tree["id"] . "_leaf_" . $leaf["id"] . "_hgd_gt_" . $graph_template["id"]) . "\"><a href=\"" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree["id"] . "&leaf_id=" . $leaf["id"] . "&host_group_data=graph_template:" . $graph_template["id"]) . "\">" . htmlspecialchars($graph_template["name"]) . "</a></li>\n";
510 }else if ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
511 @@ -645,33 +682,71 @@
512 if ((($data_query["id"] == 0) && ($non_template_graphs > 0)) ||
513 (($data_query["id"] > 0) && (sizeof($sort_field_data) > 0))) {
515 - $dhtml_tree[$i] = "ou" . ($tier+1) . " = insFld(ou" . ($tier) . ", gFld(\" " . htmlspecialchars($data_query["name"]) . "\", \"" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree["id"] . "&leaf_id=" . $leaf["id"] . "&host_group_data=data_query:" . $data_query["id"]) . "\"))\n";
517 - $dhtml_tree[$i] = "ou" . ($tier+1) . ".xID = \"tree_" . $tree["id"] . "_leaf_" . $leaf["id"] . "_hgd_dq_" . $data_query["id"] . "\"\n";
519 + $dhtml_tree[$i] = "\t\t\t\t\t\t<li id=\"" . htmlspecialchars("tree_" . $tree["id"] . "_leaf_" . $leaf["id"] . "_hgd_dq_" . $data_query["id"]) . "\"><a href=\"" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree["id"] . "&leaf_id=" . $leaf["id"] . "&host_group_data=data_query:" . $data_query["id"]) . "\">" . htmlspecialchars($data_query["name"]) . "</a>\n";
520 if ($data_query["id"] > 0) {
522 + $dhtml_tree[$i] = "\t\t\t\t\t\t\t<ul>\n";
523 while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
525 - $dhtml_tree[$i] = "ou" . ($tier+2) . " = insFld(ou" . ($tier+1) . ", gFld(\" " . htmlspecialchars($sort_field_value) . "\", \"" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree["id"] . "&leaf_id=" . $leaf["id"] . "&host_group_data=data_query_index:" . $data_query["id"] . ":" . urlencode($snmp_index)) . "\"))\n";
527 - $dhtml_tree[$i] = "ou" . ($tier+2) . ".xID = \"tree_" . $tree["id"] . "_leaf_" . $leaf["id"] . "_hgd_dqi" . $data_query["id"] . "_" . urlencode($snmp_index) . "\"\n";
528 + $dhtml_tree[$i] = "\t\t\t\t\t\t\t\t<li id=\"" . htmlspecialchars("tree_" . $tree["id"] . "_leaf_" . $leaf["id"] . "_hgd_dqi" . $data_query["id"]) . "_" . urlencode($snmp_index) . "\"><a href=\"" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree["id"] . "&leaf_id=" . $leaf["id"] . "&host_group_data=data_query_index:" . $data_query["id"] . ":" . urlencode($snmp_index)) . "\">" . htmlspecialchars($sort_field_value) . "</a></li>\n";
531 + $dhtml_tree[$i] = "\t\t\t\t\t\t\t</ul>\n";
533 + $dhtml_tree[$i] = "\t\t\t\t\t\t</li>\n";
539 + $dhtml_tree[$i] = "\t\t\t\t\t\t</li>\n";
542 + $dhtml_tree[$i] = "\t\t\t\t\t</ul>\n";
545 + $dhtml_tree[$i] = "\t\t\t\t</li>\n";
546 + }else{ //It's not a host
547 + if ($tier > $last_tier) {
549 + $dhtml_tree[$i] = "\t\t\t<ul>\n";
550 + } elseif ($tier < $last_tier) {
553 + $dhtml_tree[$i] = "</li>\n";
555 + for ($x = $tier; $x < $last_tier; $x++) {
557 + $dhtml_tree[$i] = "\t\t\t\t</ul>\n\t\t\t\t</li>\n";
560 + } elseif ($openli && !$lasthost) {
562 + $dhtml_tree[$i] = "</li>\n";
566 - $dhtml_tree[$i] = "ou" . ($tier) . " = insFld(ou" . abs(($tier-1)) . ", gFld(\"" . htmlspecialchars($leaf["title"]) . "\", \"" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree["id"] . "&leaf_id=" . $leaf["id"]) . "\"))\n";
567 + $last_tier = $tier;
569 - $dhtml_tree[$i] = "ou" . ($tier) . ".xID = \"tree_" . $tree["id"] . "_leaf_" . $leaf["id"] . "\"\n";
570 + $dhtml_tree[$i] = "\t\t\t\t<li id=\"" . htmlspecialchars("tree_" . $tree["id"] . "_leaf_" . $leaf["id"]) . "\"><a href=\"" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree["id"] . "&leaf_id=" . $leaf["id"]) . "\">" . htmlspecialchars($leaf["title"]) . "</a>\n";
575 + for ($x = $last_tier; $x > 1; $x--) {
577 + $dhtml_tree[$i] = "\t\t\t\t\t</ul>\n\t\t\t\t</li>\n";
580 + $dhtml_tree[$i] = "\t\t\t</ul>\n";
583 + $dhtml_tree[$i] = "\t\t</li>\n\t</ul>\n";
588 + $dhtml_tree[$i] = "</div>\n";
597 - print "<script type=\"text/javascript\">\n";
599 - print "myNode = findObj(\"$nodeid\")\n";
600 - print "myNode.forceOpeningOfAncestorFolders();\n";
601 - print "highlightObjLink(myNode)\n";
605 /* ================= input validation ================= */
606 input_validate_input_number(get_request_var_post("graphs"));
607 input_validate_input_number(get_request_var_post("page"));