]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/patches/cacti/cacti-0.8.8a-replace_treeview_by_jquery.jstree.patch
cacti: Update to 0.8.8b.
[people/teissler/ipfire-2.x.git] / src / patches / cacti / cacti-0.8.8a-replace_treeview_by_jquery.jstree.patch
1 Description: treeview has a license issue, cacti upstream is going to replace it
2 with functionality from jquery.jstree.
3 .
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.
7 .
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
15 .
16 This patch does NOT implement the changes needed for the Debian package of
17 cacti.
18 .
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
26
27 --- a/include/top_graph_header.php
28 +++ b/include/top_graph_header.php
29 @@ -84,8 +84,9 @@
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>
41 @@ -178,7 +179,6 @@
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>
46
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);
54
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");
61 - fwrite($fp,"}\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");
66 }
67 @@ -1383,16 +1374,7 @@
68 include_once($config["library_path"] . "/tree.php");
69 include_once($config["library_path"] . "/data_query.php");
70
71 - fwrite($fp, "<script type='text/javascript'>\n");
72 - fwrite($fp, "<!--
73 - USETEXTLINKS = 1
74 - STARTALLOPEN = 0
75 - USEFRAMES = 0
76 - USEICONS = 0
77 - WRAPTEXT = 1
78 - ICONPATH = 'treeview/'
79 - PERSERVESTATE = 1
80 - HIGHLIGHT = 1\n");
81 + fwrite($fp, "<div id=\"jtree\">\n");
82
83 if (read_config_option("export_tree_isolation") == "off") {
84 $dhtml_tree_base = 0;
85 @@ -1413,9 +1395,34 @@
86 }
87 }
88
89 - fwrite($fp,"foldersTree.treeID = \"t2\"
90 - //-->\n
91 - </script>\n");
92 + fwrite($fp, "</div>\n");
93 + fwrite($fp, "<script type=\"text/javascript\">\n");
94 + fwrite($fp, "$(function () {
95 + $(\"#jtree\")
96 + .jstree({
97 + \"plugins\" : [\"ui\",\"themes\",\"html_data\",\"cookies\"],
98 + \"themes\" : {\"icons\" : false,
99 + \"url\" : \"./js/style.css\"},
100 + \"cookies\" : {
101 + \"save_opened\" : \"Cacti_jstree_open\",
102 + \"save_selected\" : \"Cacti_jstree_select\"
103 + }
104 +
105 + })
106 +
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\");
114 + });
115 + });
116 +
117 +});\n");
118 + fwrite($fp, "</script>\n");
119 +
120 }
121
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";
128 - $i = 2;
129 + $i = 1;
130
131 $tree_list = get_graph_tree_array_export();
132
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")) {
136
137 - $i++;
138
139 $hier_sql = "SELECT DISTINCT
140 graph_tree_items.id,
141 @@ -1522,19 +1527,53 @@
142 $dhtml_tree_id = 0;
143
144 if (sizeof($hierarchy) > 0) {
145 + $last_tier = 1;
146 + $openli = false;
147 + $lasthost = false;
148 + $opentree = false;
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";
152 + if ($opentree) {
153 + $i++;
154 + $dhtml_tree[$i] = "\t\t\t</ul>\n\t\t</li>\n\t</ul>\n";
155 + }
156 + $i++;
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";
159 + $opentree = true;
160 }
161 $dhtml_tree_id = $tree["id"];
162
163 - $i++;
164 $tier = tree_tier($leaf["order_key"]);
165
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) {
169 + $i++;
170 + $dhtml_tree[$i] = "\t\t\t<ul>\n";
171 + } elseif ($tier < $last_tier) {
172 + if (!$lasthost) {
173 + $i++;
174 + $dhtml_tree[$i] = "\t\t\t\t</li>\n";
175 + }
176 + for ($x = $tier; $x < $last_tier; $x++) {
177 + $i++;
178 + $dhtml_tree[$i] = "\t\t\t</ul>\n\t\t\t\t</li>\n";
179 + $openli = false;
180 + }
181 + } elseif ($openli && !$lasthost) {
182 + $i++;
183 + $dhtml_tree[$i] = "\t\t\t\t</li>\n";
184 + $openli = false;
185 + }
186 + $last_tier = $tier;
187 + $lasthost = true;
188 + $i++;
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";
191
192 if (read_config_option("export_tree_expand_hosts") == "on") {
193 + $i++;
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
197 graph_templates.id,
198 @@ -1552,7 +1591,8 @@
199 if (sizeof($graph_templates) > 0) {
200 foreach ($graph_templates as $graph_template) {
201 $i++;
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";
205 }
206 }
207 }else if ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
208 @@ -1567,36 +1607,77 @@
209
210 array_push($data_queries, array(
211 "id" => "0",
212 - "name" => "Graph Template Based"
213 + "name" => "Non Query Based"
214 ));
215
216 if (sizeof($data_queries) > 0) {
217 - foreach ($data_queries as $data_query) {
218 - $i++;
219 -
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) {
222 + $i++;
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";
225
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"]);
230
231 - if ($data_query["id"] > 0) {
232 - while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
233 + if ($data_query["id"] > 0) {
234 + $i++;
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)) {
237 + $i++;
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";
240 + }
241 $i++;
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";
244 }
245 + $i++;
246 + $dhtml_tree[$i] = "\t\t\t\t\t\t</li>\n";
247 }
248 }
249 - }
250 }
251 + $i++;
252 + $dhtml_tree[$i] = "\t\t\t\t\t</ul>\n";
253 }
254 - }else {
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";
256 + $i++;
257 + $dhtml_tree[$i] = "\t\t\t\t</li>\n";
258 + }else { //It's not a host
259 + if ($tier > $last_tier) {
260 + $i++;
261 + $dhtml_tree[$i] = "\t\t\t<ul>\n";
262 + } elseif ($tier < $last_tier) {
263 + if (!$lasthost) {
264 + $i++;
265 + $dhtml_tree[$i] = "</li>\n";
266 + }
267 + for ($x = $tier; $x < $last_tier; $x++) {
268 + $i++;
269 + $dhtml_tree[$i] = "\t\t\t\t</ul>\n\t\t\t\t</li>\n";
270 + $openli = false;
271 + }
272 + } elseif ($openli && !$lasthost) {
273 + $i++;
274 + $dhtml_tree[$i] = "</li>\n";
275 + $openli = false;
276 + }
277 + $last_tier = $tier;
278 + $i++;
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";
281 + $openli = true;
282 + $lasthost = false;
283 }
284 }
285 + for ($x = $last_tier; $x > 1; $x--) {
286 + $i++;
287 + $dhtml_tree[$i] = "\t\t\t\t\t</ul>\n\t\t\t\t</li>\n";
288 + }
289 + $i++;
290 + $dhtml_tree[$i] = "\t\t\t</ul>\n\t\t</li>\n\t</ul>\n";
291 }else{
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";
294 $i++;
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>";
297 }
298 }
299 }
300 @@ -1612,10 +1693,10 @@
301 $dir - the export directory where graphs will either be staged or located.
302 */
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");
312 }
313 }
314
315 @@ -1626,8 +1707,6 @@
316 }
317 }
318
319 - $treeview_dir = $dir . "/treeview";
320 -
321 /* css */
322 copy("$cacti_root_path/include/main.css", "$dir/main.css");
323
324 @@ -1639,18 +1718,15 @@
325 copy("$cacti_root_path/images/shadow_gray.gif", "$dir/shadow_gray.gif");
326
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");
330 -
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");
343 +
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");
349 }
350
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>
361 </head>
362 <body>
363 <table style='width:100%;height:100%;' cellspacing='0' cellpadding='0'>
364 --- a/lib/html_tree.php
365 +++ b/lib/html_tree.php
366 @@ -495,17 +495,9 @@
367 include_once($config["library_path"] . "/data_query.php");
368
369 ?>
370 - <script type="text/javascript">
371 - <!--
372 - USETEXTLINKS = 1
373 - STARTALLOPEN = 0
374 - USEFRAMES = 0
375 - USEICONS = 0
376 - WRAPTEXT = 1
377 - PERSERVESTATE = 1
378 - HIGHLIGHT = 1
379 <?php
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");
385 @@ -522,6 +514,8 @@
386 $dhtml_tree = $_SESSION['dhtml_tree'];
387 }
388 }
389 +*/
390 + $dhtml_tree = create_dhtml_tree();
391
392 $total_tree_items = sizeof($dhtml_tree) - 1;
393
394 @@ -529,8 +523,31 @@
395 print $dhtml_tree[$i];
396 }
397 ?>
398 - //-->
399 - </script>
400 +<script type="text/javascript">
401 +$(function () {
402 + $("#jtree")
403 + .jstree({
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"},
407 + "cookies" : {
408 + "save_opened" : "Cacti_jstree_open",
409 + "save_selected" : "Cacti_jstree_select"
410 + }
411 + })
412 +
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");
420 + });
421 + });
422 +
423 +});
424 +</script>
425 <?php
426 }
427
428 @@ -543,9 +560,8 @@
429
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";
434 - $i = 3;
435 + $dhtml_tree[2] = "\n<div id=\"jtree\">\n";
436 + $i = 2;
437
438 $tree_list = get_graph_tree_array();
439
440 @@ -567,7 +583,6 @@
441
442 if (sizeof($tree_list) > 0) {
443 foreach ($tree_list as $tree) {
444 - $i++;
445 $hierarchy = db_fetch_assoc("select
446 graph_tree_items.id,
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");
451
452 - $dhtml_tree[$i] = "ou0 = insFld(foldersTree, gFld(\"" . htmlspecialchars($tree["name"]) . "\", \"" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree["id"]) . "\"))\n";
453 $i++;
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";
456
457 if (sizeof($hierarchy) > 0) {
458 + $i++;
459 + $dhtml_tree[$i] = "\t\t\t<ul>\n";
460 + $last_tier = 1;
461 + $openli = false;
462 + $lasthost = false;
463 foreach ($hierarchy as $leaf) {
464 - $i++;
465 $tier = tree_tier($leaf["order_key"]);
466
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) {
471 + $i++;
472 + $dhtml_tree[$i] = "\t\t\t<ul>\n";
473 + } elseif ($tier < $last_tier) {
474 + if (!$lasthost) {
475 + $i++;
476 + $dhtml_tree[$i] = "\t\t\t\t</li>\n";
477 + }
478 + for ($x = $tier; $x < $last_tier; $x++) {
479 + $i++;
480 + $dhtml_tree[$i] = "\t\t\t</ul>\n\t\t\t\t</li>\n";
481 + $openli = false;
482 + }
483 + } elseif ($openli && !$lasthost) {
484 + $i++;
485 + $dhtml_tree[$i] = "\t\t\t\t</li>\n";
486 + $openli = false;
487 + }
488 + $last_tier = $tier;
489 + $lasthost = true;
490 $i++;
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";
493
494 if (read_graph_config_option("expand_hosts") == "on") {
495 + $i++;
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
499 graph_templates.id,
500 @@ -612,9 +651,7 @@
501 if (sizeof($graph_templates) > 0) {
502 foreach ($graph_templates as $graph_template) {
503 $i++;
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";
505 - $i++;
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";
508 }
509 }
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))) {
514 $i++;
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";
516 - $i++;
517 - $dhtml_tree[$i] = "ou" . ($tier+1) . ".xID = \"tree_" . $tree["id"] . "_leaf_" . $leaf["id"] . "_hgd_dq_" . $data_query["id"] . "\"\n";
518 -
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) {
521 + $i++;
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)) {
524 $i++;
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";
526 - $i++;
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";
529 }
530 + $i++;
531 + $dhtml_tree[$i] = "\t\t\t\t\t\t\t</ul>\n";
532 + $i++;
533 + $dhtml_tree[$i] = "\t\t\t\t\t\t</li>\n";
534 }
535 }
536 }
537 }
538 + $i++;
539 + $dhtml_tree[$i] = "\t\t\t\t\t\t</li>\n";
540 + }
541 + $i++;
542 + $dhtml_tree[$i] = "\t\t\t\t\t</ul>\n";
543 + }
544 + $i++;
545 + $dhtml_tree[$i] = "\t\t\t\t</li>\n";
546 + }else{ //It's not a host
547 + if ($tier > $last_tier) {
548 + $i++;
549 + $dhtml_tree[$i] = "\t\t\t<ul>\n";
550 + } elseif ($tier < $last_tier) {
551 + if (!$lasthost) {
552 + $i++;
553 + $dhtml_tree[$i] = "</li>\n";
554 }
555 + for ($x = $tier; $x < $last_tier; $x++) {
556 + $i++;
557 + $dhtml_tree[$i] = "\t\t\t\t</ul>\n\t\t\t\t</li>\n";
558 + $openli = false;
559 + }
560 + } elseif ($openli && !$lasthost) {
561 + $i++;
562 + $dhtml_tree[$i] = "</li>\n";
563 + $openli = false;
564 }
565 - }else{
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;
568 $i++;
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";
571 + $openli = true;
572 + $lasthost = false;
573 }
574 }
575 + for ($x = $last_tier; $x > 1; $x--) {
576 + $i++;
577 + $dhtml_tree[$i] = "\t\t\t\t\t</ul>\n\t\t\t\t</li>\n";
578 + }
579 + $i++;
580 + $dhtml_tree[$i] = "\t\t\t</ul>\n";
581 }
582 + $i++;
583 + $dhtml_tree[$i] = "\t\t</li>\n\t</ul>\n";
584 }
585 }
586
587 + $i++;
588 + $dhtml_tree[$i] = "</div>\n";
589 +
590 return $dhtml_tree;
591 }
592
593 @@ -758,14 +833,6 @@
594 }
595 }
596
597 - print "<script type=\"text/javascript\">\n";
598 - print "<!--\n";
599 - print "myNode = findObj(\"$nodeid\")\n";
600 - print "myNode.forceOpeningOfAncestorFolders();\n";
601 - print "highlightObjLink(myNode)\n";
602 - print "//-->\n";
603 - print "</script>";
604 -
605 /* ================= input validation ================= */
606 input_validate_input_number(get_request_var_post("graphs"));
607 input_validate_input_number(get_request_var_post("page"));