owls

annotate Nav.inc.php @ 13:3e3fa7725abb

reorganized filesystem strukture
author meillo@marmaro.de
date Sun, 27 May 2007 02:37:55 +0200
parents Includes/Nav.inc.php@144bc36a6c27
children
rev   line source
meillo@0 1 <!-- Nav -->
meillo@0 2 <ul id="nav">
meillo@0 3
meillo@0 4 <?php
meillo@2 5 // all nodes that are displayed in the nav
meillo@2 6 global $nodesDisplayed;
meillo@2 7 $nodesDisplayed = '';
meillo@2 8
meillo@2 9
meillo@0 10 // build nav tree
meillo@0 11 echo ' '. navtree(0) ."\n";
meillo@0 12
meillo@0 13
meillo@2 14 // find nodes without existing parent (orphans)
meillo@0 15 $sql = sprintf("
meillo@0 16 select distinct
meillo@0 17 idParent
meillo@0 18 from %sOwls
meillo@0 19 where
meillo@0 20 idParent not in (select id from %sOwls)
meillo@0 21 and idParent != 0 -- not the real root
meillo@0 22 order by name asc
meillo@0 23 ",
meillo@0 24 DB_PREFIX,
meillo@0 25 DB_PREFIX
meillo@0 26 );
meillo@0 27 $result = mysql_query($sql) or die(mysql_error());
meillo@0 28 unset($sql);
meillo@0 29
meillo@0 30 // output only if there are orphans
meillo@0 31 if (mysql_num_rows($result)) {
meillo@0 32 echo ' <li id="orphans">orphans<ul>';
meillo@0 33 // output subtree for every orphan
meillo@0 34 while($row = mysql_fetch_array($result)) {
meillo@0 35 echo navtree($row['idParent']);
meillo@0 36 }
meillo@0 37 unset($row);
meillo@0 38 mysql_free_result($result);
meillo@0 39
meillo@3 40 echo '</ul></li>'."\n";
meillo@0 41 }
meillo@2 42
meillo@2 43
meillo@2 44
meillo@2 45 // find broken nodes - nodes not displayed in nav or orphans (i.e. rings)
meillo@2 46 $sql = sprintf("
meillo@2 47 select
meillo@2 48 id, name
meillo@2 49 from %sOwls
meillo@2 50 where
meillo@2 51 id not in ( %s )
meillo@2 52 order by name asc
meillo@2 53 ",
meillo@2 54 DB_PREFIX,
meillo@2 55 substr($nodesDisplayed, 2)
meillo@2 56 );
meillo@2 57 $result = mysql_query($sql) or die(mysql_error());
meillo@2 58 unset($sql);
meillo@2 59
meillo@2 60 // output only if there are broken nodes
meillo@2 61 if (mysql_num_rows($result)) {
meillo@2 62 echo ' <li id="broken">broken<ul>';
meillo@2 63 // output list of nodes (no tree, cause there may be rings!)
meillo@2 64 while($row = mysql_fetch_array($result)) {
meillo@2 65 echo '<li><a href="'. $row['id'] .'"'. (($_GET['id'] == $row['id']) ? ' id="selected"' : '') .'>'. $row['name'] .'</a></li>';
meillo@2 66 }
meillo@2 67 unset($row);
meillo@2 68 mysql_free_result($result);
meillo@2 69
meillo@3 70 echo '</ul></li>'."\n";
meillo@2 71 }
meillo@2 72
meillo@0 73 ?>
meillo@0 74
meillo@0 75
meillo@0 76 </ul>
meillo@0 77
meillo@0 78 <?php
meillo@0 79
meillo@2 80
meillo@8 81 /**
meillo@8 82 * recursive function creates the output for the nav tree
meillo@8 83 *
meillo@8 84 * @param $root the id of the parent of the root node
meillo@8 85 * @return string HTML output that shows the nav tree
meillo@8 86 */
meillo@0 87 function navtree($root) {
meillo@0 88 // fetch subcategories
meillo@2 89 $sql = sprintf("
meillo@2 90 select
meillo@2 91 id, idParent, name
meillo@2 92 from %sOwls
meillo@2 93 where
meillo@2 94 idParent = $root
meillo@2 95 order by name asc
meillo@2 96 ",
meillo@2 97 DB_PREFIX
meillo@2 98 );
meillo@2 99 $result = mysql_query($sql) or die(mysql_error());
meillo@2 100 unset($sql);
meillo@0 101
meillo@0 102 $return = '';
meillo@0 103 while($row = mysql_fetch_array($result)) {
meillo@2 104 // add to list of displayed nodes
meillo@2 105 global $nodesDisplayed;
meillo@2 106 $nodesDisplayed .= ', '. $row['id'];
meillo@2 107
meillo@0 108 $return .= '<li><a href="'. $row['id'] .'"'. (($_GET['id'] == $row['id']) ? ' id="selected"' : '') .'>'. $row['name'] .'</a>';
meillo@0 109 if ($row['id'] != $row['idParent']) {
meillo@0 110 $subtree = navtree($row['id']);
meillo@0 111 if (!empty($subtree)) {
meillo@2 112 #$return .= '&nbsp;&nbsp;<a href="javascript:toggleVisibility(\''. $row['id'] .'\')" id="ctrl'. $row['id'] .'" style="display: none;">-</a>';
meillo@0 113 $return .= '<ul id="node'. $row['id'] .'">'. $subtree .'</ul>';
meillo@0 114 }
meillo@0 115 unset($subtree);
meillo@0 116 }
meillo@0 117 $return .= '</li>';
meillo@0 118 }
meillo@0 119 unset($row);
meillo@0 120 mysql_free_result($result);
meillo@0 121
meillo@0 122 // return
meillo@0 123 return $return;
meillo@0 124 }
meillo@0 125
meillo@0 126 ?>
meillo@0 127
meillo@0 128 <!-- Content -->