owls

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Nav.inc.php	Sun May 27 02:37:55 2007 +0200
     1.3 @@ -0,0 +1,128 @@
     1.4 +  <!-- Nav -->
     1.5 +  <ul id="nav">
     1.6 +
     1.7 +<?php
     1.8 +    // all nodes that are displayed in the nav
     1.9 +    global $nodesDisplayed;
    1.10 +    $nodesDisplayed = '';
    1.11 +
    1.12 +
    1.13 +    // build nav tree
    1.14 +    echo '    '. navtree(0) ."\n";
    1.15 +
    1.16 +
    1.17 +    // find nodes without existing parent (orphans)
    1.18 +    $sql = sprintf("
    1.19 +      select distinct
    1.20 +        idParent
    1.21 +      from %sOwls 
    1.22 +      where 
    1.23 +        idParent not in (select id from %sOwls) 
    1.24 +        and idParent != 0    -- not the real root
    1.25 +      order by name asc
    1.26 +      ",
    1.27 +      DB_PREFIX,
    1.28 +      DB_PREFIX
    1.29 +    );
    1.30 +    $result = mysql_query($sql) or die(mysql_error());
    1.31 +    unset($sql);
    1.32 +
    1.33 +    // output only if there are orphans
    1.34 +    if (mysql_num_rows($result)) {
    1.35 +      echo '    <li id="orphans">orphans<ul>';
    1.36 +      // output subtree for every orphan
    1.37 +      while($row = mysql_fetch_array($result)) {
    1.38 +        echo navtree($row['idParent']);
    1.39 +      }
    1.40 +      unset($row);
    1.41 +      mysql_free_result($result);
    1.42 +
    1.43 +      echo '</ul></li>'."\n";
    1.44 +    }
    1.45 +
    1.46 +
    1.47 +
    1.48 +    // find broken nodes - nodes not displayed in nav or orphans (i.e. rings)
    1.49 +    $sql = sprintf("
    1.50 +      select
    1.51 +        id, name
    1.52 +      from %sOwls 
    1.53 +      where 
    1.54 +        id not in ( %s )
    1.55 +      order by name asc
    1.56 +      ",
    1.57 +      DB_PREFIX,
    1.58 +      substr($nodesDisplayed, 2)
    1.59 +    );
    1.60 +    $result = mysql_query($sql) or die(mysql_error());
    1.61 +    unset($sql);
    1.62 +
    1.63 +    // output only if there are broken nodes
    1.64 +    if (mysql_num_rows($result)) {
    1.65 +      echo '    <li id="broken">broken<ul>';
    1.66 +      // output list of nodes (no tree, cause there may be rings!)
    1.67 +      while($row = mysql_fetch_array($result)) {
    1.68 +        echo '<li><a href="'. $row['id'] .'"'. (($_GET['id'] == $row['id']) ? ' id="selected"' : '') .'>'. $row['name'] .'</a></li>';
    1.69 +      }
    1.70 +      unset($row);
    1.71 +      mysql_free_result($result);
    1.72 +
    1.73 +      echo '</ul></li>'."\n";
    1.74 +    }
    1.75 +
    1.76 +?>
    1.77 +
    1.78 +
    1.79 +  </ul>
    1.80 +
    1.81 +<?php
    1.82 +
    1.83 +
    1.84 +    /**
    1.85 +     * recursive function creates the output for the nav tree
    1.86 +     *
    1.87 +     * @param $root the id of the parent of the root node
    1.88 +     * @return string HTML output that shows the nav tree
    1.89 +     */
    1.90 +    function navtree($root) {
    1.91 +      // fetch subcategories
    1.92 +      $sql = sprintf("
    1.93 +        select
    1.94 +          id, idParent, name
    1.95 +        from %sOwls
    1.96 +        where
    1.97 +          idParent = $root
    1.98 +        order by name asc
    1.99 +        ",
   1.100 +        DB_PREFIX
   1.101 +      );
   1.102 +      $result = mysql_query($sql) or die(mysql_error());
   1.103 +      unset($sql);
   1.104 +
   1.105 +      $return = '';
   1.106 +      while($row = mysql_fetch_array($result)) {
   1.107 +        // add to list of displayed nodes
   1.108 +        global $nodesDisplayed;
   1.109 +        $nodesDisplayed .= ', '. $row['id'];
   1.110 +
   1.111 +        $return .= '<li><a href="'. $row['id'] .'"'. (($_GET['id'] == $row['id']) ? ' id="selected"' : '') .'>'. $row['name'] .'</a>';
   1.112 +        if ($row['id'] != $row['idParent']) {
   1.113 +          $subtree = navtree($row['id']);
   1.114 +          if (!empty($subtree)) {
   1.115 +            #$return .= '&nbsp;&nbsp;<a href="javascript:toggleVisibility(\''. $row['id'] .'\')" id="ctrl'. $row['id'] .'" style="display: none;">-</a>';
   1.116 +            $return .= '<ul id="node'. $row['id'] .'">'. $subtree .'</ul>';
   1.117 +          }
   1.118 +          unset($subtree);
   1.119 +        }
   1.120 +        $return .= '</li>';
   1.121 +      }
   1.122 +      unset($row);
   1.123 +      mysql_free_result($result);
   1.124 +
   1.125 +      // return
   1.126 +      return $return;
   1.127 +    }
   1.128 +
   1.129 +?>
   1.130 +
   1.131 +  <!-- Content -->