owls

view Nav.inc.php @ 14:cebc198276eb

more file moving
author meillo@marmaro.de
date Sun, 27 May 2007 03:01:16 +0200
parents 144bc36a6c27
children
line source
1 <!-- Nav -->
2 <ul id="nav">
4 <?php
5 // all nodes that are displayed in the nav
6 global $nodesDisplayed;
7 $nodesDisplayed = '';
10 // build nav tree
11 echo ' '. navtree(0) ."\n";
14 // find nodes without existing parent (orphans)
15 $sql = sprintf("
16 select distinct
17 idParent
18 from %sOwls
19 where
20 idParent not in (select id from %sOwls)
21 and idParent != 0 -- not the real root
22 order by name asc
23 ",
24 DB_PREFIX,
25 DB_PREFIX
26 );
27 $result = mysql_query($sql) or die(mysql_error());
28 unset($sql);
30 // output only if there are orphans
31 if (mysql_num_rows($result)) {
32 echo ' <li id="orphans">orphans<ul>';
33 // output subtree for every orphan
34 while($row = mysql_fetch_array($result)) {
35 echo navtree($row['idParent']);
36 }
37 unset($row);
38 mysql_free_result($result);
40 echo '</ul></li>'."\n";
41 }
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);
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);
70 echo '</ul></li>'."\n";
71 }
73 ?>
76 </ul>
78 <?php
81 /**
82 * recursive function creates the output for the nav tree
83 *
84 * @param $root the id of the parent of the root node
85 * @return string HTML output that shows the nav tree
86 */
87 function navtree($root) {
88 // fetch subcategories
89 $sql = sprintf("
90 select
91 id, idParent, name
92 from %sOwls
93 where
94 idParent = $root
95 order by name asc
96 ",
97 DB_PREFIX
98 );
99 $result = mysql_query($sql) or die(mysql_error());
100 unset($sql);
102 $return = '';
103 while($row = mysql_fetch_array($result)) {
104 // add to list of displayed nodes
105 global $nodesDisplayed;
106 $nodesDisplayed .= ', '. $row['id'];
108 $return .= '<li><a href="'. $row['id'] .'"'. (($_GET['id'] == $row['id']) ? ' id="selected"' : '') .'>'. $row['name'] .'</a>';
109 if ($row['id'] != $row['idParent']) {
110 $subtree = navtree($row['id']);
111 if (!empty($subtree)) {
112 #$return .= '&nbsp;&nbsp;<a href="javascript:toggleVisibility(\''. $row['id'] .'\')" id="ctrl'. $row['id'] .'" style="display: none;">-</a>';
113 $return .= '<ul id="node'. $row['id'] .'">'. $subtree .'</ul>';
114 }
115 unset($subtree);
116 }
117 $return .= '</li>';
118 }
119 unset($row);
120 mysql_free_result($result);
122 // return
123 return $return;
124 }
126 ?>
128 <!-- Content -->