Mercurial > owls
view Nav.inc.php @ 16:22243e7c7dc5
Name of banner pic is now configurable
author | meillo@marmaro.de |
---|---|
date | Sun, 27 May 2007 14:06:42 +0200 |
parents | 3e3fa7725abb |
children |
line wrap: on
line source
<!-- Nav --> <ul id="nav"> <?php // all nodes that are displayed in the nav global $nodesDisplayed; $nodesDisplayed = ''; // build nav tree echo ' '. navtree(0) ."\n"; // find nodes without existing parent (orphans) $sql = sprintf(" select distinct idParent from %sOwls where idParent not in (select id from %sOwls) and idParent != 0 -- not the real root order by name asc ", DB_PREFIX, DB_PREFIX ); $result = mysql_query($sql) or die(mysql_error()); unset($sql); // output only if there are orphans if (mysql_num_rows($result)) { echo ' <li id="orphans">orphans<ul>'; // output subtree for every orphan while($row = mysql_fetch_array($result)) { echo navtree($row['idParent']); } unset($row); mysql_free_result($result); echo '</ul></li>'."\n"; } // find broken nodes - nodes not displayed in nav or orphans (i.e. rings) $sql = sprintf(" select id, name from %sOwls where id not in ( %s ) order by name asc ", DB_PREFIX, substr($nodesDisplayed, 2) ); $result = mysql_query($sql) or die(mysql_error()); unset($sql); // output only if there are broken nodes if (mysql_num_rows($result)) { echo ' <li id="broken">broken<ul>'; // output list of nodes (no tree, cause there may be rings!) while($row = mysql_fetch_array($result)) { echo '<li><a href="'. $row['id'] .'"'. (($_GET['id'] == $row['id']) ? ' id="selected"' : '') .'>'. $row['name'] .'</a></li>'; } unset($row); mysql_free_result($result); echo '</ul></li>'."\n"; } ?> </ul> <?php /** * recursive function creates the output for the nav tree * * @param $root the id of the parent of the root node * @return string HTML output that shows the nav tree */ function navtree($root) { // fetch subcategories $sql = sprintf(" select id, idParent, name from %sOwls where idParent = $root order by name asc ", DB_PREFIX ); $result = mysql_query($sql) or die(mysql_error()); unset($sql); $return = ''; while($row = mysql_fetch_array($result)) { // add to list of displayed nodes global $nodesDisplayed; $nodesDisplayed .= ', '. $row['id']; $return .= '<li><a href="'. $row['id'] .'"'. (($_GET['id'] == $row['id']) ? ' id="selected"' : '') .'>'. $row['name'] .'</a>'; if ($row['id'] != $row['idParent']) { $subtree = navtree($row['id']); if (!empty($subtree)) { #$return .= ' <a href="javascript:toggleVisibility(\''. $row['id'] .'\')" id="ctrl'. $row['id'] .'" style="display: none;">-</a>'; $return .= '<ul id="node'. $row['id'] .'">'. $subtree .'</ul>'; } unset($subtree); } $return .= '</li>'; } unset($row); mysql_free_result($result); // return return $return; } ?> <!-- Content -->