--- img_assist.module.previous	2006-01-08 16:20:48.000000000 +1100
+++ modules/img_assist/img_assist.module	2006-01-08 17:09:02.000000000 +1100
@@ -8,7 +8,7 @@
  */
 
 /********************************************************************
- * Drupal Hooksimg_assist_menu()
+ * Drupal Hooks
  ********************************************************************/
 
 /**
@@ -554,7 +554,7 @@
   }
 
   if (!$image) {
-    $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, f.* FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid INNER JOIN {files} f ON n.nid = f.nid AND n.type = 'image' ". $where ." ORDER BY n.changed DESC"));
+    $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, f.* FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {files} f ON n.nid = f.nid AND n.type = 'image' ". $where ." ORDER BY n.changed DESC"));
     while ($node = db_fetch_object($result)) {
       $node->filepath = file_create_path($node->filepath);
       $dim = getimagesize($node->filepath, $info);
@@ -577,7 +577,7 @@
     // NOTE: If we didn't use "LIKE 'image/%%'" here we could load other files.
     // Might be interesting to expand on this someday.
     if ($image) {
-      $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, f.* FROM {files} f, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid WHERE f.nid = n.nid AND f.filemime LIKE 'image/%%' AND n.nid NOT IN (". implode(array_keys($image), ', ') .") ". $where ." ORDER BY n.changed DESC"));
+      $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, f.* FROM {files} f, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid WHERE f.nid = n.nid AND f.filemime LIKE 'image/%%' AND n.nid NOT IN (". implode(array_keys($image), ', ') .") ". $where ." ORDER BY n.changed DESC"));
       while ($node = db_fetch_object($result)) {
         $node->filepath = file_create_path($node->filepath);
         $dim = getimagesize($node->filepath, $info);
@@ -608,7 +608,7 @@
  * Load an image from the database
  */
 function img_assist_load_image($id, $derivatives = TRUE) {
-  $node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.title, r.teaser, f.* FROM {files} f, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid WHERE f.nid = n.nid AND f.fid = %d'), $id));
+  $node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.title, r.teaser, f.* FROM {files} f, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid WHERE f.nid = n.nid AND f.fid = %d'), $id));
   $node->filepath = file_create_path($node->filepath);
 
   if (!$derivatives) {
@@ -623,7 +623,7 @@
       foreach (_image_get_sizes() as $size) {
         if ($size['label'] == $node->filename) {
           $image_module_image = TRUE;
-          $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, r.teaser, f.* FROM {files} f, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid WHERE f.nid = n.nid AND n.nid = %d'), $node->nid);
+          $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, r.teaser, f.* FROM {files} f, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid WHERE f.nid = n.nid AND n.nid = %d'), $node->nid);
           while ($node = db_fetch_object($result)) {
             $node->filepath = file_create_path($node->filepath);
             $dim = getimagesize($node->filepath, $info);
@@ -655,11 +655,8 @@
  */
 function img_assist_load_directory() {
   global $user;
-
-  if ($_POST['edit']) {
-    $tid = $_POST['edit']['taxonomy'];
-  }
-
+  
+  $tid = NULL;
   if ($_GET['user']) {
     $user_images = true;
   }
@@ -675,7 +672,7 @@
         $has_tid = true;
       }
       $voc = taxonomy_get_vocabulary($vid);
-      $form[$voc->name] = _taxonomy_term_select($voc->name, 'taxonomy', $tid[$i], $vid, '', 0, '<'. t('none') .'>');
+      $form['taxonomy']['taxonomy_'. $voc->vid] = _taxonomy_term_select($voc->name, 'taxonomy', NULL, $vid, '', 0, '<'. t('none') .'>');
       $i++;
     }
     $form['submit'] = array(
@@ -685,6 +682,7 @@
       '#value' => t('Go')
     );
     $filterbar .= drupal_get_form('img_assist_filters', $form). '</table>';
+    $tid = _img_assist_filters_get_tids();
   }
 
   $resize = '<a title="' . t('Smaller thumbnails') . '" href="javascript: resizeImgs(-25);">[-]</a> <a title="' . t('Larger thumbnails') . '" href="javascript: resizeImgs(25);">[+]</a>';
@@ -750,6 +748,38 @@
 }
 
 /**
+ * Grabs all filter values that have been submitted, and store them in a 
+ * temporary cache.
+ */
+function img_assist_filters_submit($form_id, $form_values) {
+  $tids = array();
+  foreach ($form_values as $key => $value) {
+    if (substr($key, 0, 9) == 'taxonomy_') {
+      $tids[] = $value;
+    }
+  }
+  _img_assist_filters_get_tids($tids);
+}
+
+/**
+ * Stores filter values in a temporary cache, and returns the contents of the 
+ * cache.
+ */
+function _img_assist_filters_get_tids($tids = array()) {
+  static $tid_cache;
+  
+  if (!isset($tid_cache)) {
+    $tid_cache = array();
+  }
+  
+  if (!empty($tids) && is_array($tids)) {
+    $tid_cache = $tids;
+  }
+  
+  return $tid_cache;
+}
+
+/**
  * Load the preview pane.
  */
 function img_assist_load_preview($id = null) {
