view 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
line wrap: on
line source

  <!-- Nav -->
  <ul id="nav">

<?php
    // build nav tree
    echo '    '. navtree(0) ."\n";


    // find unmatched nodes (orphans)
    $sql = sprintf("
      select distinct
        idParent
      from %sOwls 
      where 
        idParent not in (select id from %sOwls) 
        and idParent != 0    -- not the real root
--        and idParent != id   -- avoid endless recursion
      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>';
    }
?>

    <li id="login">
<?php
      if ($lsys->loggedIn()) {
        echo '    <a href="'. $_GET['id'] .'logout" style="color: #c00;">logout</a>';
      } else {
?>
      <form name="loginform" action="<?php echo $_GET['id']; ?>login" method="post" enctype="multipart/form-data">
        <input name="login_loginname" type="text" />
        <input name="login_password" type="password" />
        <input name="login" type="submit" value="login" style="padding: 0; cursor: pointer;" />
      </form>
<?php
      }
?>
    </li>

  </ul>

<?php

    function navtree($root) {
      // fetch subcategories
      $result = mysql_query("select * from ". DB_PREFIX ."Owls where idParent = $root order by name asc");

      $return = '';
      while($row = mysql_fetch_array($result)) {
        $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 -->