Mercurial > owls
comparison Includes/Nav.inc.php @ 0:3021ce32ee14 owls-0.5
begin of using hg for owls
author | "Meillo r e t u r n s <meillo@marmaro.de>" |
---|---|
date | Sun, 03 Dec 2006 22:32:13 +0100 |
parents | |
children | ab74e95a8040 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3021ce32ee14 |
---|---|
1 <!-- Nav --> | |
2 <ul id="nav"> | |
3 | |
4 <?php | |
5 // build nav tree | |
6 echo ' '. navtree(0) ."\n"; | |
7 | |
8 | |
9 // find unmatched nodes (orphans) | |
10 $sql = sprintf(" | |
11 select distinct | |
12 idParent | |
13 from %sOwls | |
14 where | |
15 idParent not in (select id from %sOwls) | |
16 and idParent != 0 -- not the real root | |
17 -- and idParent != id -- avoid endless recursion | |
18 order by name asc | |
19 ", | |
20 DB_PREFIX, | |
21 DB_PREFIX | |
22 ); | |
23 $result = mysql_query($sql) or die(mysql_error()); | |
24 unset($sql); | |
25 | |
26 // output only if there are orphans | |
27 if (mysql_num_rows($result)) { | |
28 echo ' <li id="orphans">orphans<ul>'; | |
29 // output subtree for every orphan | |
30 while($row = mysql_fetch_array($result)) { | |
31 echo navtree($row['idParent']); | |
32 } | |
33 unset($row); | |
34 mysql_free_result($result); | |
35 | |
36 echo '</ul></li>'; | |
37 } | |
38 ?> | |
39 | |
40 <li id="login"> | |
41 <?php | |
42 if ($lsys->loggedIn()) { | |
43 echo ' <a href="'. $_GET['id'] .'logout" style="color: #c00;">logout</a>'; | |
44 } else { | |
45 ?> | |
46 <form name="loginform" action="<?php echo $_GET['id']; ?>login" method="post" enctype="multipart/form-data"> | |
47 <input name="login_loginname" type="text" /> | |
48 <input name="login_password" type="password" /> | |
49 <input name="login" type="submit" value="login" style="padding: 0; cursor: pointer;" /> | |
50 </form> | |
51 <?php | |
52 } | |
53 ?> | |
54 </li> | |
55 | |
56 </ul> | |
57 | |
58 <?php | |
59 | |
60 function navtree($root) { | |
61 // fetch subcategories | |
62 $result = mysql_query("select * from ". DB_PREFIX ."Owls where idParent = $root order by name asc"); | |
63 | |
64 $return = ''; | |
65 while($row = mysql_fetch_array($result)) { | |
66 $return .= '<li><a href="'. $row['id'] .'"'. (($_GET['id'] == $row['id']) ? ' id="selected"' : '') .'>'. $row['name'] .'</a>'; | |
67 if ($row['id'] != $row['idParent']) { | |
68 $subtree = navtree($row['id']); | |
69 if (!empty($subtree)) { | |
70 $return .= ' <a href="javascript:toggleVisibility(\''. $row[id] .'\')" id="ctrl'. $row['id'] .'" style="display: none;">-</a>'; | |
71 $return .= '<ul id="node'. $row['id'] .'">'. $subtree .'</ul>'; | |
72 } | |
73 unset($subtree); | |
74 } | |
75 $return .= '</li>'; | |
76 } | |
77 unset($row); | |
78 mysql_free_result($result); | |
79 | |
80 // return | |
81 return $return; | |
82 } | |
83 | |
84 ?> | |
85 | |
86 <!-- Content --> |