diff Includes/Nav.inc.php @ 2:ab74e95a8040

added display of broken nodes; Header and Footer in Owls.php now; added logos
author "Meillo r e t u r n s <meillo@marmaro.de>"
date Thu, 07 Dec 2006 21:04:30 +0100
parents 3021ce32ee14
children 92a8978e68c5
line wrap: on
line diff
--- a/Includes/Nav.inc.php	Sun Dec 03 22:32:33 2006 +0100
+++ b/Includes/Nav.inc.php	Thu Dec 07 21:04:30 2006 +0100
@@ -2,11 +2,16 @@
   <ul id="nav">
 
 <?php
+    // all nodes that are displayed in the nav
+    global $nodesDisplayed;
+    $nodesDisplayed = '';
+
+
     // build nav tree
     echo '    '. navtree(0) ."\n";
 
 
-    // find unmatched nodes (orphans)
+    // find nodes without existing parent (orphans)
     $sql = sprintf("
       select distinct
         idParent
@@ -14,7 +19,6 @@
       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,
@@ -35,6 +39,37 @@
 
       echo '</ul></li>';
     }
+
+
+
+    // 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>';
+    }
+
 ?>
 
     <li id="login">
@@ -57,17 +92,34 @@
 
 <?php
 
+
+
     function navtree($root) {
       // fetch subcategories
-      $result = mysql_query("select * from ". DB_PREFIX ."Owls where idParent = $root order by name asc");
+      $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 .= '&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);