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