owls
view Includes/Nav.inc.php @ 8:2672cd855fa2
added further doxygen-comments
author | Meillo r e t u r n s <meillo@marmaro.de> |
---|---|
date | Wed, 13 Dec 2006 23:08:55 +0100 |
parents | 92a8978e68c5 |
children | 144bc36a6c27 |
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 ?>
75 <li id="login">
76 <?php
77 if ($lsys->loggedIn()) {
78 echo ' <a href="'. $_GET['id'] .'logout" style="color: #c00;">logout</a>';
79 } else {
80 ?>
81 <form name="loginform" action="<?php echo $_GET['id']; ?>login" method="post" enctype="multipart/form-data">
82 <input name="login_loginname" type="text" />
83 <input name="login_password" type="password" />
84 <input name="login" type="submit" value="login" style="padding: 0; cursor: pointer;" />
85 </form>
86 <?php
87 }
88 ?>
89 </li>
91 </ul>
93 <?php
96 /**
97 * recursive function creates the output for the nav tree
98 *
99 * @param $root the id of the parent of the root node
100 * @return string HTML output that shows the nav tree
101 */
102 function navtree($root) {
103 // fetch subcategories
104 $sql = sprintf("
105 select
106 id, idParent, name
107 from %sOwls
108 where
109 idParent = $root
110 order by name asc
111 ",
112 DB_PREFIX
113 );
114 $result = mysql_query($sql) or die(mysql_error());
115 unset($sql);
117 $return = '';
118 while($row = mysql_fetch_array($result)) {
119 // add to list of displayed nodes
120 global $nodesDisplayed;
121 $nodesDisplayed .= ', '. $row['id'];
123 $return .= '<li><a href="'. $row['id'] .'"'. (($_GET['id'] == $row['id']) ? ' id="selected"' : '') .'>'. $row['name'] .'</a>';
124 if ($row['id'] != $row['idParent']) {
125 $subtree = navtree($row['id']);
126 if (!empty($subtree)) {
127 #$return .= ' <a href="javascript:toggleVisibility(\''. $row['id'] .'\')" id="ctrl'. $row['id'] .'" style="display: none;">-</a>';
128 $return .= '<ul id="node'. $row['id'] .'">'. $subtree .'</ul>';
129 }
130 unset($subtree);
131 }
132 $return .= '</li>';
133 }
134 unset($row);
135 mysql_free_result($result);
137 // return
138 return $return;
139 }
141 ?>
143 <!-- Content -->