owls
view 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 |
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>';
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>';
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
97 function navtree($root) {
98 // fetch subcategories
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);
112 $return = '';
113 while($row = mysql_fetch_array($result)) {
114 // add to list of displayed nodes
115 global $nodesDisplayed;
116 $nodesDisplayed .= ', '. $row['id'];
118 $return .= '<li><a href="'. $row['id'] .'"'. (($_GET['id'] == $row['id']) ? ' id="selected"' : '') .'>'. $row['name'] .'</a>';
119 if ($row['id'] != $row['idParent']) {
120 $subtree = navtree($row['id']);
121 if (!empty($subtree)) {
122 #$return .= ' <a href="javascript:toggleVisibility(\''. $row['id'] .'\')" id="ctrl'. $row['id'] .'" style="display: none;">-</a>';
123 $return .= '<ul id="node'. $row['id'] .'">'. $subtree .'</ul>';
124 }
125 unset($subtree);
126 }
127 $return .= '</li>';
128 }
129 unset($row);
130 mysql_free_result($result);
132 // return
133 return $return;
134 }
136 ?>
138 <!-- Content -->