owls

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Includes/Nav.inc.php	Sun Dec 03 22:32:13 2006 +0100
     1.3 @@ -0,0 +1,86 @@
     1.4 +  <!-- Nav -->
     1.5 +  <ul id="nav">
     1.6 +
     1.7 +<?php
     1.8 +    // build nav tree
     1.9 +    echo '    '. navtree(0) ."\n";
    1.10 +
    1.11 +
    1.12 +    // find unmatched nodes (orphans)
    1.13 +    $sql = sprintf("
    1.14 +      select distinct
    1.15 +        idParent
    1.16 +      from %sOwls 
    1.17 +      where 
    1.18 +        idParent not in (select id from %sOwls) 
    1.19 +        and idParent != 0    -- not the real root
    1.20 +--        and idParent != id   -- avoid endless recursion
    1.21 +      order by name asc
    1.22 +      ",
    1.23 +      DB_PREFIX,
    1.24 +      DB_PREFIX
    1.25 +    );
    1.26 +    $result = mysql_query($sql) or die(mysql_error());
    1.27 +    unset($sql);
    1.28 +
    1.29 +    // output only if there are orphans
    1.30 +    if (mysql_num_rows($result)) {
    1.31 +      echo '    <li id="orphans">orphans<ul>';
    1.32 +      // output subtree for every orphan
    1.33 +      while($row = mysql_fetch_array($result)) {
    1.34 +        echo navtree($row['idParent']);
    1.35 +      }
    1.36 +      unset($row);
    1.37 +      mysql_free_result($result);
    1.38 +
    1.39 +      echo '</ul></li>';
    1.40 +    }
    1.41 +?>
    1.42 +
    1.43 +    <li id="login">
    1.44 +<?php
    1.45 +      if ($lsys->loggedIn()) {
    1.46 +        echo '    <a href="'. $_GET['id'] .'logout" style="color: #c00;">logout</a>';
    1.47 +      } else {
    1.48 +?>
    1.49 +      <form name="loginform" action="<?php echo $_GET['id']; ?>login" method="post" enctype="multipart/form-data">
    1.50 +        <input name="login_loginname" type="text" />
    1.51 +        <input name="login_password" type="password" />
    1.52 +        <input name="login" type="submit" value="login" style="padding: 0; cursor: pointer;" />
    1.53 +      </form>
    1.54 +<?php
    1.55 +      }
    1.56 +?>
    1.57 +    </li>
    1.58 +
    1.59 +  </ul>
    1.60 +
    1.61 +<?php
    1.62 +
    1.63 +    function navtree($root) {
    1.64 +      // fetch subcategories
    1.65 +      $result = mysql_query("select * from ". DB_PREFIX ."Owls where idParent = $root order by name asc");
    1.66 +
    1.67 +      $return = '';
    1.68 +      while($row = mysql_fetch_array($result)) {
    1.69 +        $return .= '<li><a href="'. $row['id'] .'"'. (($_GET['id'] == $row['id']) ? ' id="selected"' : '') .'>'. $row['name'] .'</a>';
    1.70 +        if ($row['id'] != $row['idParent']) {
    1.71 +          $subtree = navtree($row['id']);
    1.72 +          if (!empty($subtree)) {
    1.73 +            $return .= '&nbsp;&nbsp;<a href="javascript:toggleVisibility(\''. $row[id] .'\')" id="ctrl'. $row['id'] .'" style="display: none;">-</a>';
    1.74 +            $return .= '<ul id="node'. $row['id'] .'">'. $subtree .'</ul>';
    1.75 +          }
    1.76 +          unset($subtree);
    1.77 +        }
    1.78 +        $return .= '</li>';
    1.79 +      }
    1.80 +      unset($row);
    1.81 +      mysql_free_result($result);
    1.82 +
    1.83 +      // return
    1.84 +      return $return;
    1.85 +    }
    1.86 +
    1.87 +?>
    1.88 +
    1.89 +  <!-- Content -->