--- tac_lite.module	2009-04-18 05:28:26.000000000 +1200
+++ tac_lite.module	2009-05-13 17:02:47.800374900 +1200
@@ -461,40 +461,45 @@
     return $grants;
 }
 
+
+/**
+ * Implementation of hook_db_rewrite_sql().
+ */
 function tac_lite_db_rewrite_sql($query, $primary_table, $primary_field, $args) {
   global $user;
-  
+
   if (user_access('administer tac_lite')) {
     // Only for tac_lite administrators.
     return;
   }
   
-  // the vocabularies containing protected info.
-  $vids = variable_get('tac_lite_categories', array(0));
-  
-  // the terms this user is allowed to see
-  $tids = array();
-  for ($i = 1; $i <= variable_get('tac_lite_schemes', 1); $i++) {
-    $config = _tac_lite_config($i);
-    if (in_array('grant_view', $config['perms'])) {
-      $tids = array_merge($tids, _tac_lite_user_tids($user, $i));
-    }
-  }
-  
-  // Note that if tac_lite is configured, but no schemes support grant_view,
-  // we assume everyone can view all terms.
-
-  if (count($tids) && is_array($vids) && count($vids)) {
-    switch ($primary_field) {
+  switch ($primary_field) {
     case 'tid':
-      // prevent users from seeing terms they do not have permission to read.
-      $join = "LEFT JOIN {term_data} tac_td ON $primary_table.tid = tac_td.tid";
-      $where = "$primary_table.tid IN (". implode(', ', $tids) .") OR tac_td.vid NOT IN (". implode(',', $vids) .")"; 
-      
-      return array('join' => $join, 'where' => $where);
+      // the vocabularies containing protected info.
+      $vids = variable_get('tac_lite_categories', array(0));
+
+      // the terms this user is allowed to see
+      $tids = array();
+      for ($i = 1; $i <= variable_get('tac_lite_schemes', 1); $i++) {
+        $config = _tac_lite_config($i);
+        if (in_array('grant_view', $config['perms'])) {
+          $tids = array_merge($tids, _tac_lite_user_tids($user, $i));
+        }
+      }
+
+      // Note that if tac_lite is configured, but no schemes support grant_view,
+      // we assume everyone can view all terms.
+
+      if (count($tids) && is_array($vids) && count($vids)) {
+        // prevent users from seeing terms they do not have permission to read.
+        $join = "LEFT JOIN {term_data} tac_td ON $primary_table.tid = tac_td.tid";
+        $where = "$primary_table.tid IN (". implode(', ', $tids) .") OR tac_td.vid NOT IN (". implode(',', $vids) .")"; 
+
+        return array('join' => $join, 'where' => $where);
+      }
       break;
+
     case 'vid':
-      
       break;
     }
   }
