comparison Includes/Nav.inc.php @ 2:ab74e95a8040

added display of broken nodes; Header and Footer in Owls.php now; added logos
author "Meillo r e t u r n s <meillo@marmaro.de>"
date Thu, 07 Dec 2006 21:04:30 +0100
parents 3021ce32ee14
children 92a8978e68c5
comparison
equal deleted inserted replaced
1:6268cdb5fc0b 2:ab74e95a8040
1 <!-- Nav --> 1 <!-- Nav -->
2 <ul id="nav"> 2 <ul id="nav">
3 3
4 <?php 4 <?php
5 // all nodes that are displayed in the nav
6 global $nodesDisplayed;
7 $nodesDisplayed = '';
8
9
5 // build nav tree 10 // build nav tree
6 echo ' '. navtree(0) ."\n"; 11 echo ' '. navtree(0) ."\n";
7 12
8 13
9 // find unmatched nodes (orphans) 14 // find nodes without existing parent (orphans)
10 $sql = sprintf(" 15 $sql = sprintf("
11 select distinct 16 select distinct
12 idParent 17 idParent
13 from %sOwls 18 from %sOwls
14 where 19 where
15 idParent not in (select id from %sOwls) 20 idParent not in (select id from %sOwls)
16 and idParent != 0 -- not the real root 21 and idParent != 0 -- not the real root
17 -- and idParent != id -- avoid endless recursion
18 order by name asc 22 order by name asc
19 ", 23 ",
20 DB_PREFIX, 24 DB_PREFIX,
21 DB_PREFIX 25 DB_PREFIX
22 ); 26 );
33 unset($row); 37 unset($row);
34 mysql_free_result($result); 38 mysql_free_result($result);
35 39
36 echo '</ul></li>'; 40 echo '</ul></li>';
37 } 41 }
42
43
44
45 // find broken nodes - nodes not displayed in nav or orphans (i.e. rings)
46 $sql = sprintf("
47 select
48 id, name
49 from %sOwls
50 where
51 id not in ( %s )
52 order by name asc
53 ",
54 DB_PREFIX,
55 substr($nodesDisplayed, 2)
56 );
57 $result = mysql_query($sql) or die(mysql_error());
58 unset($sql);
59
60 // output only if there are broken nodes
61 if (mysql_num_rows($result)) {
62 echo ' <li id="broken">broken<ul>';
63 // output list of nodes (no tree, cause there may be rings!)
64 while($row = mysql_fetch_array($result)) {
65 echo '<li><a href="'. $row['id'] .'"'. (($_GET['id'] == $row['id']) ? ' id="selected"' : '') .'>'. $row['name'] .'</a></li>';
66 }
67 unset($row);
68 mysql_free_result($result);
69
70 echo '</ul></li>';
71 }
72
38 ?> 73 ?>
39 74
40 <li id="login"> 75 <li id="login">
41 <?php 76 <?php
42 if ($lsys->loggedIn()) { 77 if ($lsys->loggedIn()) {
55 90
56 </ul> 91 </ul>
57 92
58 <?php 93 <?php
59 94
95
96
60 function navtree($root) { 97 function navtree($root) {
61 // fetch subcategories 98 // fetch subcategories
62 $result = mysql_query("select * from ". DB_PREFIX ."Owls where idParent = $root order by name asc"); 99 $sql = sprintf("
100 select
101 id, idParent, name
102 from %sOwls
103 where
104 idParent = $root
105 order by name asc
106 ",
107 DB_PREFIX
108 );
109 $result = mysql_query($sql) or die(mysql_error());
110 unset($sql);
63 111
64 $return = ''; 112 $return = '';
65 while($row = mysql_fetch_array($result)) { 113 while($row = mysql_fetch_array($result)) {
114 // add to list of displayed nodes
115 global $nodesDisplayed;
116 $nodesDisplayed .= ', '. $row['id'];
117
66 $return .= '<li><a href="'. $row['id'] .'"'. (($_GET['id'] == $row['id']) ? ' id="selected"' : '') .'>'. $row['name'] .'</a>'; 118 $return .= '<li><a href="'. $row['id'] .'"'. (($_GET['id'] == $row['id']) ? ' id="selected"' : '') .'>'. $row['name'] .'</a>';
67 if ($row['id'] != $row['idParent']) { 119 if ($row['id'] != $row['idParent']) {
68 $subtree = navtree($row['id']); 120 $subtree = navtree($row['id']);
69 if (!empty($subtree)) { 121 if (!empty($subtree)) {
70 $return .= '&nbsp;&nbsp;<a href="javascript:toggleVisibility(\''. $row[id] .'\')" id="ctrl'. $row['id'] .'" style="display: none;">-</a>'; 122 #$return .= '&nbsp;&nbsp;<a href="javascript:toggleVisibility(\''. $row['id'] .'\')" id="ctrl'. $row['id'] .'" style="display: none;">-</a>';
71 $return .= '<ul id="node'. $row['id'] .'">'. $subtree .'</ul>'; 123 $return .= '<ul id="node'. $row['id'] .'">'. $subtree .'</ul>';
72 } 124 }
73 unset($subtree); 125 unset($subtree);
74 } 126 }
75 $return .= '</li>'; 127 $return .= '</li>';