16
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.
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
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
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
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(); ?>
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);
64
64
fwrite($fp,"</td>\n");
65
65
fwrite($fp,"<td valign='top'>\n");
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");
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");
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 @@
89
89
- fwrite($fp,"foldersTree.treeID = \"t2\"
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 () {
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\");
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");
131
131
$tree_list = get_graph_tree_array_export();
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")) {
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
144
if (sizeof($hierarchy) > 0) {
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";
154
+ $dhtml_tree[$i] = "\t\t\t</ul>\n\t\t</li>\n\t</ul>\n";
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";
150
161
$dhtml_tree_id = $tree["id"];
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";
158
+ $dhtml_tree[$i] = "\t\t\t<ul>\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;
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) {
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 @@
210
array_push($data_queries, array(
212
- "name" => "Graph Template Based"
213
+ "name" => "Non Query Based"
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) {
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";
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)) {
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";
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";
218
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";
221
257
+ $dhtml_tree[$i] = "\t\t\t\t</li>\n";
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) {
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;
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";
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";
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";
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";
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>";
240
+ $dhtml_tree[$i] = "\t\t</li>\n";
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.
247
303
function create_export_directory_structure($cacti_root_path, $dir) {
266
322
copy("$cacti_root_path/include/main.css", "$dir/main.css");
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");
271
327
/* java scripts for the tree */
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>
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() {
313
367
include_once($config["library_path"] . "/data_query.php");
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() {
332
386
$dhtml_tree = $_SESSION['dhtml_tree'];
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");
374
@@ -543,8 +560,9 @@ function create_dhtml_tree() {
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";
380
435
+ $dhtml_tree[2] = "\n<div id=\"jtree\">\n";
381
+ $dhtml_tree[3] = "\t<ul>\n";
385
438
$tree_list = get_graph_tree_array();
386
@@ -567,7 +585,6 @@ function create_dhtml_tree() {
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");
398
452
- $dhtml_tree[$i] = "ou0 = insFld(foldersTree, gFld(\"" . htmlspecialchars($tree["name"]) . "\", \"" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree["id"]) . "\"))\n";
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";
403
457
if (sizeof($hierarchy) > 0) {
405
459
+ $dhtml_tree[$i] = "\t\t\t<ul>\n";
406
463
foreach ($hierarchy as $leaf) {
408
465
$tier = tree_tier($leaf["order_key"]);
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) {
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;
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() {
423
501
if (sizeof($graph_templates) > 0) {
424
502
foreach ($graph_templates as $graph_template) {
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))) {
461
539
+ $dhtml_tree[$i] = "\t\t\t\t\t\t</li>\n";
464
542
+ $dhtml_tree[$i] = "\t\t\t\t\t</ul>\n";
467
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";
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;
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";
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";
476
580
+ $dhtml_tree[$i] = "\t\t\t</ul>\n";
479
+ $dhtml_tree[$i] = "\t\t</li>\n";
583
+ $dhtml_tree[$i] = "\t\t</li>\n\t</ul>\n";
484
+ $dhtml_tree[$i] = "\t</ul>\n";
486
588
+ $dhtml_tree[$i] = "</div>\n";
488
590
return $dhtml_tree;
491
@@ -758,14 +789,6 @@ function grow_right_pane_tree($tree_id, $leaf_id, $host_group_data) {