~ubuntu-branches/ubuntu/utopic/cacti/utopic-security

« back to all changes in this revision

Viewing changes to debian/patches/replace_treeview_by_jquery.jstree.patch

  • Committer: Package Import Robot
  • Author(s): Paul Gevers
  • Date: 2013-04-01 08:03:11 UTC
  • Revision ID: package-import@ubuntu.com-20130401080311-wr3b6nkjpo9dnhvc
Tags: 0.8.8a+dfsg-4
Improve jquery tree patch to show trees multilevel (Closes: #702690)

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 .
16
16
 This patch does NOT implement the changes needed for the Debian package of
17
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. 
18
22
Bug: http://bugs.cacti.net/view.php?id=2228
19
23
Bug-Debian: http://bugs.debian.org/679980
20
24
Author: Paul Gevers <elbrus@debian.org>
21
 
Date: Wed, 21 Nov 2012 23:19:40 +0100
 
25
Date: Sun, 31 Mar 2013 11:59:05 +0200
22
26
 
23
 
diff --git a/include/top_graph_header.php b/include/top_graph_header.php
24
 
index 86bba4b..97766f4 100644
25
27
--- a/include/top_graph_header.php
26
28
+++ b/include/top_graph_header.php
27
 
@@ -84,8 +84,9 @@ $page_title = api_plugin_hook_function('page_title', draw_navigation_text("title
 
29
@@ -84,8 +84,9 @@
28
30
        <link href="<?php echo $config['url_path']; ?>include/main.css" type="text/css" rel="stylesheet">
29
31
        <link href="<?php echo $config['url_path']; ?>images/favicon.ico" rel="shortcut icon"/>
30
32
        <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/layout.js"></script>
36
38
        <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/jscalendar/calendar.js"></script>
37
39
        <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/jscalendar/lang/calendar-en.js"></script>
38
40
        <script type="text/javascript" src="<?php echo $config['url_path']; ?>include/jscalendar/calendar-setup.js"></script>
39
 
@@ -178,7 +179,6 @@ $page_title = api_plugin_hook_function('page_title', draw_navigation_text("title
 
41
@@ -178,7 +179,6 @@
40
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'>
41
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>
42
44
                        <?php grow_dhtml_trees(); ?>
44
46
 
45
47
                        <?php if (isset($_GET["select_first"])) { ?>
46
48
                        <script type="text/javascript">
47
 
diff --git a/lib/graph_export.php b/lib/graph_export.php
48
 
index fd57041..0f1558f 100644
49
49
--- a/lib/graph_export.php
50
50
+++ b/lib/graph_export.php
51
 
@@ -1365,15 +1365,6 @@ function draw_html_left_tree($fp, $tree_id)  {
 
51
@@ -1365,15 +1365,6 @@
52
52
        /* create the treeview representation for the html data */
53
53
        grow_dhtml_trees_export($fp,$tree_id);
54
54
 
64
64
        fwrite($fp,"</td>\n");
65
65
        fwrite($fp,"<td valign='top'>\n");
66
66
 }
67
 
@@ -1383,16 +1374,7 @@ function grow_dhtml_trees_export($fp, $tree_id) {
 
67
@@ -1383,16 +1374,7 @@
68
68
        include_once($config["library_path"] . "/tree.php");
69
69
        include_once($config["library_path"] . "/data_query.php");
70
70
 
78
78
-                       ICONPATH = 'treeview/'
79
79
-                       PERSERVESTATE = 1
80
80
-                       HIGHLIGHT = 1\n");
81
 
+       fwrite($fp, "<div id=\"jtree\">\n\t<ul>\n");
 
81
+       fwrite($fp, "<div id=\"jtree\">\n");
82
82
 
83
83
        if (read_config_option("export_tree_isolation") == "off") {
84
84
                $dhtml_tree_base = 0;
85
 
@@ -1413,9 +1395,34 @@ function grow_dhtml_trees_export($fp, $tree_id) {
 
85
@@ -1413,9 +1395,34 @@
86
86
                }
87
87
        }
88
88
 
89
89
-       fwrite($fp,"foldersTree.treeID = \"t2\"
90
90
-                       //-->\n
91
91
-                       </script>\n");
92
 
+       fwrite($fp, "\t</ul>\n</div>\n");
 
92
+       fwrite($fp, "</div>\n");
93
93
+       fwrite($fp, "<script type=\"text/javascript\">\n");
94
94
+       fwrite($fp, "$(function () {
95
95
+       $(\"#jtree\")
107
107
+                // Make sure that the nodes are actually used as links
108
108
+                // We need reselect to prevent endless loops
109
109
+                // https://groups.google.com/d/topic/jstree/j6XNq9hQdeA/discussion
110
 
+                .bind(\"reselect.jstree\", function (e, data) { 
 
110
+                .bind(\"reselect.jstree\", function (e, data) {
111
111
+                      data.inst.get_container().bind(\"select_node.jstree\", function (e, data) {
112
112
+                           // data.rstl.obj is the object that was selected.
113
113
+                           document.location.href = data.rslt.obj.children(\"a\").attr(\"href\");
120
120
 }
121
121
 
122
122
 /* get_graph_tree_array_export - returns a list of graph trees taking permissions into account if
123
 
@@ -1478,8 +1485,7 @@ function create_dhtml_tree_export($tree_id) {
 
123
@@ -1478,8 +1485,7 @@
124
124
        $dhtml_tree = array();
125
125
        $dhtml_tree[0] = $start;
126
126
        $dhtml_tree[1] = read_graph_config_option("expand_hosts");
130
130
 
131
131
        $tree_list = get_graph_tree_array_export();
132
132
 
133
 
@@ -1499,7 +1505,6 @@ function create_dhtml_tree_export($tree_id) {
 
133
@@ -1499,7 +1505,6 @@
134
134
                if (((read_config_option("export_tree_isolation") == "on") && ($tree_id == $tree["id"])) ||
135
135
                        (read_config_option("export_tree_isolation") == "off")) {
136
136
 
138
138
 
139
139
                        $hier_sql = "SELECT DISTINCT
140
140
                                        graph_tree_items.id,
141
 
@@ -1524,17 +1529,24 @@ function create_dhtml_tree_export($tree_id) {
 
141
@@ -1522,19 +1527,53 @@
 
142
                        $dhtml_tree_id = 0;
 
143
 
142
144
                        if (sizeof($hierarchy) > 0) {
 
145
+                               $last_tier = 1;
 
146
+                               $openli = false;
 
147
+                               $lasthost = false;
 
148
+                               $opentree = false;
143
149
                                foreach ($hierarchy as $leaf) {
144
150
                                        if ($dhtml_tree_id <> $tree["id"]) {
145
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
+                                               }
146
156
+                                               $i++;
147
157
+                                               $clean_id = clean_up_export_name(get_tree_name($tree["id"]));
148
 
+                                               $dhtml_tree[$i] = "\t\t<li id=\"" . $clean_id . "\"><a href=\"" . $clean_id . "_leaf.html\">" . get_tree_name($tree["id"]) . "</a>\n";
 
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;
149
160
                                        }
150
161
                                        $dhtml_tree_id = $tree["id"];
151
162
 
154
165
 
155
166
                                        if ($leaf["host_id"] > 0) {  //It's a host
156
167
-                                               $dhtml_tree[$i] = "ou" . ($tier) . " = insFld(ou" . ($tier-1) . ", gFld(\"Host: " . $leaf["hostname"] . "\", \"" . clean_up_export_name($leaf["hostname"] . "_" . $leaf["id"]) . ".html\"))\n";
157
 
+                                               $i++;
158
 
+                                               $dhtml_tree[$i] = "\t\t\t<ul>\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;
159
188
+                                               $i++;
160
189
+                                               $clean_id = clean_up_export_name($leaf["hostname"] . "_" . $leaf["id"]);
161
190
+                                               $dhtml_tree[$i] = "\t\t\t\t<li id=\"" . $clean_id . "\"><a href=\"" . $clean_id . ".html\">Host: " . htmlspecialchars($leaf["hostname"]) . "</a>\n";
166
195
                                                        if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) {
167
196
                                                                $graph_templates = db_fetch_assoc("SELECT
168
197
                                                                        graph_templates.id,
169
 
@@ -1552,7 +1564,8 @@ function create_dhtml_tree_export($tree_id) {
 
198
@@ -1552,7 +1591,8 @@
170
199
                                                                if (sizeof($graph_templates) > 0) {
171
200
                                                                        foreach ($graph_templates as $graph_template) {
172
201
                                                                                $i++;
176
205
                                                                        }
177
206
                                                                }
178
207
                                                        }else if ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
179
 
@@ -1571,34 +1584,52 @@ function create_dhtml_tree_export($tree_id) {
 
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"
180
214
                                                                        ));
181
215
 
182
216
                                                                if (sizeof($data_queries) > 0) {
197
231
-                                                                       if ($data_query["id"] > 0) {
198
232
-                                                                               while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
199
233
+                                                                               if ($data_query["id"] > 0) {
200
 
                                                                                        $i++;
201
 
-                                                                                       $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";
 
234
+                                                                                       $i++;
202
235
+                                                                                       $dhtml_tree[$i] = "\t\t\t\t\t\t\t<ul>\n";
203
236
+                                                                                       while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
204
237
+                                                                                               $i++;
205
238
+                                                                                               $clean_id = clean_up_export_name($leaf["hostname"] . "_dqi_" . $leaf["id"] . "_" . $data_query["id"] . "_" . $snmp_index);
206
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";
207
240
+                                                                                       }
208
 
+                                                                                       $i++;
 
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";
209
243
+                                                                                       $dhtml_tree[$i] = "\t\t\t\t\t\t\t</ul>\n";
210
244
                                                                                }
211
245
+                                                                               $i++;
217
251
+                                                       $i++;
218
252
+                                                       $dhtml_tree[$i] = "\t\t\t\t\t</ul>\n";
219
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";
220
256
+                                               $i++;
221
257
+                                               $dhtml_tree[$i] = "\t\t\t\t</li>\n";
222
 
                                        }else {
223
 
-                                               $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";
 
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;
224
278
+                                               $i++;
225
279
+                                               $clean_id = clean_up_export_name(get_tree_name($tree["id"]) . "_" . $leaf["title"] . "_" . $leaf["id"]);
226
 
+                                               $dhtml_tree[$i] = "\t\t\t\t<li id=\"" . $clean_id . "\"><a href=\"" . $clean_id . "_leaf.html\">" . htmlspecialchars($leaf["title"]) . "</a></li>\n";
 
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;
227
283
                                        }
228
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
+                               }
229
289
+                               $i++;
230
 
+                               $dhtml_tree[$i] = "\t\t\t</ul>\n";
 
290
+                               $dhtml_tree[$i] = "\t\t\t</ul>\n\t\t</li>\n\t</ul>\n";
231
291
                        }else{
232
292
                                if ($dhtml_tree_id <> $tree["id"]) {
233
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";
234
294
                                        $i++;
235
295
+                                       $clean_id = clean_up_export_name(get_tree_name($tree["id"]));
236
 
+                                       $dhtml_tree[$i] = "\t\t<li id=\"" . $clean_id . "_leaf\"><a href=\"" . $clean_id . "_leaf.html\">" . get_tree_name($tree["id"]) . "</a></li>\n";
 
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>";
237
297
                                }
238
298
                        }
239
 
+                       $i++;
240
 
+                       $dhtml_tree[$i] = "\t\t</li>\n";
241
299
                }
242
 
        }
243
 
        }
244
 
@@ -1612,10 +1643,10 @@ function create_dhtml_tree_export($tree_id) {
 
300
@@ -1612,10 +1693,10 @@
245
301
         $dir - the export directory where graphs will either be staged or located.
246
302
 */
247
303
 function create_export_directory_structure($cacti_root_path, $dir) {
256
312
                }
257
313
        }
258
314
 
259
 
@@ -1626,8 +1657,6 @@ function create_export_directory_structure($cacti_root_path, $dir) {
 
315
@@ -1626,8 +1707,6 @@
260
316
                }
261
317
        }
262
318
 
265
321
        /* css */
266
322
        copy("$cacti_root_path/include/main.css", "$dir/main.css");
267
323
 
268
 
@@ -1639,18 +1668,15 @@ function create_export_directory_structure($cacti_root_path, $dir) {
 
324
@@ -1639,18 +1718,15 @@
269
325
        copy("$cacti_root_path/images/shadow_gray.gif", "$dir/shadow_gray.gif");
270
326
 
271
327
        /* java scripts for the tree */
293
349
 }
294
350
 
295
351
 function get_host_description($host_id) {
296
 
@@ -1738,8 +1764,9 @@ define("HTML_HEADER_TREE",
 
352
@@ -1738,8 +1814,9 @@
297
353
        <meta http-equiv=refresh content='300'; url='index.html'>
298
354
        <meta http-equiv=Pragma content=no-cache>
299
355
        <meta http-equiv=cache-control content=no-cache>
305
361
 </head>
306
362
 <body>
307
363
 <table style='width:100%;height:100%;' cellspacing='0' cellpadding='0'>
308
 
diff --git a/lib/html_tree.php b/lib/html_tree.php
309
 
index 861c6cc..a5bd796 100644
310
364
--- a/lib/html_tree.php
311
365
+++ b/lib/html_tree.php
312
 
@@ -495,17 +495,9 @@ function grow_dhtml_trees() {
 
366
@@ -495,17 +495,9 @@
313
367
        include_once($config["library_path"] . "/data_query.php");
314
368
 
315
369
        ?>
328
382
        list($micro,$seconds) = explode(" ", microtime());
329
383
        $current_time = $seconds + $micro;
330
384
        $expand_hosts = read_graph_config_option("expand_hosts");
331
 
@@ -522,6 +514,8 @@ function grow_dhtml_trees() {
 
385
@@ -522,6 +514,8 @@
332
386
                        $dhtml_tree = $_SESSION['dhtml_tree'];
333
387
                }
334
388
        }
337
391
 
338
392
        $total_tree_items = sizeof($dhtml_tree) - 1;
339
393
 
340
 
@@ -529,8 +523,31 @@ function grow_dhtml_trees() {
 
394
@@ -529,8 +523,31 @@
341
395
                print $dhtml_tree[$i];
342
396
        }
343
397
        ?>
359
413
+               // Make sure that the nodes are actually used as links
360
414
+               // We need reselect to prevent endless loops
361
415
+               // https://groups.google.com/d/topic/jstree/j6XNq9hQdeA/discussion
362
 
+               .bind("reselect.jstree", function (e, data) { 
 
416
+               .bind("reselect.jstree", function (e, data) {
363
417
+                       data.inst.get_container().bind("select_node.jstree", function (e, data) {
364
418
+                               // data.rstl.obj is the object that was selected.
365
419
+                               document.location.href = data.rslt.obj.children("a").attr("href");
371
425
        <?php
372
426
 }
373
427
 
374
 
@@ -543,8 +560,9 @@ function create_dhtml_tree() {
 
428
@@ -543,9 +560,8 @@
375
429
 
376
430
        $dhtml_tree[0] = $start;
377
431
        $dhtml_tree[1] = read_graph_config_option("expand_hosts");
378
432
-       $dhtml_tree[2] = "foldersTree = gFld(\"\", \"\")\n";
379
433
-       $dhtml_tree[3] = "foldersTree.xID = \"root\"\n";
 
434
-       $i = 3;
380
435
+       $dhtml_tree[2] = "\n<div id=\"jtree\">\n";
381
 
+       $dhtml_tree[3] = "\t<ul>\n";
382
 
+
383
 
        $i = 3;
 
436
+       $i = 2;
384
437
 
385
438
        $tree_list = get_graph_tree_array();
386
 
@@ -567,7 +585,6 @@ function create_dhtml_tree() {
 
439
 
 
440
@@ -567,7 +583,6 @@
387
441
 
388
442
        if (sizeof($tree_list) > 0) {
389
443
                foreach ($tree_list as $tree) {
391
445
                        $hierarchy = db_fetch_assoc("select
392
446
                                graph_tree_items.id,
393
447
                                graph_tree_items.title,
394
 
@@ -583,21 +600,22 @@ function create_dhtml_tree() {
 
448
@@ -583,21 +598,45 @@
395
449
                                and graph_tree_items.local_graph_id = 0
396
450
                                order by graph_tree_items.order_key");
397
451
 
398
452
-                       $dhtml_tree[$i] = "ou0 = insFld(foldersTree, gFld(\"" . htmlspecialchars($tree["name"]) . "\", \"" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree["id"]) . "\"))\n";
399
453
                        $i++;
400
454
-                       $dhtml_tree[$i] = "ou0.xID = \"tree_" . $tree["id"] . "\"\n";
401
 
+                       $dhtml_tree[$i] = "\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";
 
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";
402
456
 
403
457
                        if (sizeof($hierarchy) > 0) {
404
458
+                               $i++;
405
459
+                               $dhtml_tree[$i] = "\t\t\t<ul>\n";
 
460
+                               $last_tier = 1;
 
461
+                               $openli = false;
 
462
+                               $lasthost = false;
406
463
                                foreach ($hierarchy as $leaf) {
407
464
-                                       $i++;
408
465
                                        $tier = tree_tier($leaf["order_key"]);
409
466
 
410
 
                                        if ($leaf["host_id"] > 0) {
 
467
-                                       if ($leaf["host_id"] > 0) {
411
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;
412
490
                                                $i++;
413
491
-                                               $dhtml_tree[$i] = "ou" . ($tier) . ".xID = \"tree_" . $tree["id"] . "_leaf_" . $leaf["id"] . "\"\n";
414
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";
419
497
                                                        if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) {
420
498
                                                                $graph_templates = db_fetch_assoc("select
421
499
                                                                        graph_templates.id,
422
 
@@ -612,9 +630,7 @@ function create_dhtml_tree() {
 
500
@@ -612,9 +651,7 @@
423
501
                                                                if (sizeof($graph_templates) > 0) {
424
502
                                                                        foreach ($graph_templates as $graph_template) {
425
503
                                                                                $i++;
430
508
                                                                        }
431
509
                                                                }
432
510
                                                        }else if ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
433
 
@@ -645,33 +661,48 @@ function create_dhtml_tree() {
 
511
@@ -645,33 +682,71 @@
434
512
                                                                                if ((($data_query["id"] == 0) && ($non_template_graphs > 0)) ||
435
513
                                                                                        (($data_query["id"] > 0) && (sizeof($sort_field_data) > 0))) {
436
514
                                                                                        $i++;
459
537
                                                                }
460
538
+                                                       $i++;
461
539
+                                                       $dhtml_tree[$i] = "\t\t\t\t\t\t</li>\n";
462
 
                                                        }
 
540
+                                                       }
463
541
+                                               $i++;
464
542
+                                               $dhtml_tree[$i] = "\t\t\t\t\t</ul>\n";
465
 
                                                }
 
543
+                                               }
466
544
+                                       $i++;
467
545
+                                       $dhtml_tree[$i] = "\t\t\t\t</li>\n";
468
 
                                        }else{
 
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{
469
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;
470
568
                                                $i++;
471
569
-                                               $dhtml_tree[$i] = "ou" . ($tier) . ".xID = \"tree_" . $tree["id"] . "_leaf_" . $leaf["id"] . "\"\n";
472
 
+                                               $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></li>\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;
473
573
                                        }
474
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
+                               }
475
579
+                               $i++;
476
580
+                               $dhtml_tree[$i] = "\t\t\t</ul>\n";
477
581
                        }
478
582
+                       $i++;
479
 
+                       $dhtml_tree[$i] = "\t\t</li>\n";
 
583
+                       $dhtml_tree[$i] = "\t\t</li>\n\t</ul>\n";
480
584
                }
481
585
        }
482
586
 
483
587
+       $i++;
484
 
+       $dhtml_tree[$i] = "\t</ul>\n";
485
 
+       $i++;
486
588
+       $dhtml_tree[$i] = "</div>\n";
487
589
+
488
590
        return $dhtml_tree;
489
591
 }
490
592
 
491
 
@@ -758,14 +789,6 @@ function grow_right_pane_tree($tree_id, $leaf_id, $host_group_data) {
 
593
@@ -758,14 +833,6 @@
492
594
                }
493
595
        }
494
596
 
503
605
        /* ================= input validation ================= */
504
606
        input_validate_input_number(get_request_var_post("graphs"));
505
607
        input_validate_input_number(get_request_var_post("page"));
506
 
1.7.10.4
507