view Includes/Nav.inc.php @ 10:144bc36a6c27

moved login form from nav to top of content added last modified date
author meillo@marmaro.de
date Sun, 27 May 2007 02:13:46 +0200
parents 2672cd855fa2
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 .= '&nbsp;&nbsp;<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 -->