--- /Users/wmostrey/Desktop/simplenews/simplenews.module	2007-02-20 18:14:28.000000000 +0100
+++ /Applications/MAMP/pias/sites/all/modules/simplenews/simplenews.module	2007-03-19 14:25:34.000000000 +0100
@@ -326,7 +326,7 @@
 function simplenews_validate($node) {
   global $valid_mails;
   if ($node->taxonomy && $node->send == 1) {
-    if (!simplenews_validate_taxonomy($node->taxonomy)) {
+    if (!simplenews_validate_taxonomy($node->nid)) {
       form_set_error('', t('You should select a newsletter if you want to send this newsletter.'));
     }
   }
@@ -362,17 +362,10 @@
   }
 }
 
-function simplenews_validate_taxonomy($taxonomy) {
+function simplenews_validate_taxonomy($nid) {
   $vid = _simplenews_get_vid();
-  $result = db_query('SELECT tid FROM {term_data} WHERE vid = %d', $vid);
-  while ($tid = db_fetch_object($result)) {
-    $tids[] = $tid->tid;
-  }
-  $taxes = array();
-  foreach ($taxonomy as $tax) {
-    $taxes[] = $tax;
-  }
-  return array_intersect($tids, $taxes);
+  $arraycheck = taxonomy_node_get_terms_by_vocabulary($nid, $vid);
+  return $arraycheck;
 }
 
 /**
@@ -790,6 +783,7 @@
     $options[$newsletter->tid] = $newsletter->name;
   }
   $form['subscriptions'] = array('#type' => 'fieldset', '#description' => t('Select the newsletter(s) to which you want to subscribe or unsubscribe.'));
+  
   $form['subscriptions']['newsletters'] = array('#type' => 'checkboxes',
     '#options' => $options,
     '#default_value' => $subscription->tids,
@@ -829,6 +823,7 @@
  * Forms API callback; validates the settings form.
  */
 function simplenews_subscription_manager_form_validate($form_id, $form_values) {
+	
   $valid_email = valid_email_address($form_values['mail']);
   if (!$valid_email) {
     form_set_error('mail', t('The e-mail address you supplied is not valid.'));
@@ -843,16 +838,18 @@
  * Forms API callback; submit handler for subscription form.
  */
 function simplenews_subscription_manager_form_submit($form_id, $form_values) {
+
   switch ($form_values['op']) {
     case t('Update'):
       foreach($form_values['newsletters'] as $tid => $checked) {
-        if ($checked) {
+        if ($checked) {;
           simplenews_subscribe_user($form_values['mail'], $tid, FALSE);
         }
         else {
           simplenews_unsubscribe_user($form_values['mail'], $tid, FALSE);
         }
       }
+      
       drupal_set_message(t('The newsletter subscriptions for %mail have been updated.', array('%mail' => $form_values['mail'])));
       break;
     case t('Subscribe'):
@@ -861,6 +858,7 @@
           simplenews_subscribe_user($form_values['mail'], $tid);
         }
       }
+
       drupal_set_message(t('You will receive a confirmation e-mail shortly containing further instructions on how to complete your subscription.'));
       break;
     case t('Unsubscribe'):
@@ -1031,58 +1029,63 @@
     $throttle = variable_get('simplenews_throttle', 20);
     static $counter = 0;
   }
-  $result = db_query(db_rewrite_sql('SELECT n.nid, s.tid, n.created FROM {node} n INNER JOIN {simplenews_newsletters} s ON n.nid = s.nid WHERE s.s_status = %d ORDER BY n.created ASC'), 1);
+  $result = db_query(db_rewrite_sql('SELECT n.nid n.created FROM {node} n INNER JOIN {simplenews_newsletters} s ON n.nid = s.nid WHERE s.s_status = %d ORDER BY n.created ASC'), 1);
+  
   while ($nid = db_fetch_object($result)) {
-    $term = taxonomy_get_term($nid->tid);
-    $node = simplenews_node_prepare($nid->nid, $nid->tid);
-
-    $result2 = db_query('SELECT s.mail, s.snid FROM {simplenews_subscriptions} s INNER JOIN {simplenews_snid_tid} t ON s.snid = t.snid WHERE s.s_status = %d AND s.a_status = %d AND t.tid = %d ORDER BY s.snid ASC', 0, 1, $nid->tid);
-    while ($mail = db_fetch_object($result2)) {
-      $hash = _simplenews_generate_hash($mail->mail, $mail->snid, $nid->tid);
-
-      // Add themable footer to message as this changes per user.
-      $user_node = drupal_clone($node);
-      $user_node = theme('simplenews_newsletter_footer', $user_node, $hash);
-
-      $user_node->to = $mail->mail;
-      if (simplenews_mail_send($user_node)) {
-        // TODO: This looks like it may choke if you were sending multiple
-        // newsletters through cron. Should move s_status to snid_tid table
-        // or somewhere else to see which newsletter has been sent.
-        db_query('UPDATE {simplenews_subscriptions} SET s_status = %d WHERE snid = %d', 1, $mail->snid);
-        $counter++;
-        // don't send mails too fast, servers may choke. Wait for 10 ms.
-        usleep(10000);
-      }
-      else {
-        watchdog('newsletter', t('Newsletter %title could not be sent to %email.', array('%title'=> $user_node->title, '%email' => $mail->mail)), WATCHDOG_ERROR);
+    $terms = taxonomy_node_get_terms($nid->nid);
+    foreach($terms as $tid) {
+      $term = taxonomy_get_term($tid);
+      $node = simplenews_node_prepare($nid->nid, $tid);
+
+      $result2 = db_query('SELECT s.mail, s.snid FROM {simplenews_subscriptions} s INNER JOIN {simplenews_snid_tid} t ON s.snid = t.snid WHERE s.s_status = %d AND s.a_status = %d AND t.tid = %d ORDER BY s.snid ASC', 0, 1, $nid->tid);
+    
+      while ($mail = db_fetch_object($result2)) {
+        $hash = _simplenews_generate_hash($mail->mail, $mail->snid, $nid->tid);
+
+        // Add themable footer to message as this changes per user.
+        $user_node = drupal_clone($node);
+        $user_node = theme('simplenews_newsletter_footer', $user_node, $hash);
+
+        $user_node->to = $mail->mail;
+        if (simplenews_mail_send($user_node)) {
+          // TODO: This looks like it may choke if you were sending multiple
+          // newsletters through cron. Should move s_status to snid_tid table
+          // or somewhere else to see which newsletter has been sent.
+          db_query('UPDATE {simplenews_subscriptions} SET s_status = %d WHERE snid = %d', 1, $mail->snid);
+          $counter++;
+          // don't send mails too fast, servers may choke. Wait for 10 ms.
+          usleep(10000);
+        }
+        else {
+          watchdog('newsletter', t('Newsletter %title could not be sent to %email.', array('%title'=> $user_node->title, '%email' => $mail->mail)), WATCHDOG_ERROR);
+        }
+        if ($timer) {
+          $int_time = simplenews_time();
+        }
+        else {
+          if ($counter < $throttle) {
+            $int_time = $start_time;
+          }
+          else {
+            return;
+          }
+        }
+        if (!($int_time - $start_time < $max_time)) {
+          return;
+        }
       }
+      db_query('UPDATE {simplenews_subscriptions} SET s_status = %d', 0);
+      db_query('UPDATE {simplenews_newsletters} SET s_status = %d WHERE nid = %d', 2, $node->nid);
       if ($timer) {
         $int_time = simplenews_time();
       }
       else {
-        if ($counter < $throttle) {
-          $int_time = $start_time;
-        }
-        else {
-          return;
-        }
+        $int_time = $start_time;
       }
       if (!($int_time - $start_time < $max_time)) {
         return;
       }
-    }
-    db_query('UPDATE {simplenews_subscriptions} SET s_status = %d', 0);
-    db_query('UPDATE {simplenews_newsletters} SET s_status = %d WHERE nid = %d', 2, $node->nid);
-    if ($timer) {
-      $int_time = simplenews_time();
-    }
-    else {
-      $int_time = $start_time;
-    }
-    if (!($int_time - $start_time < $max_time)) {
-      return;
-    }
+    }  
   }
 }
 
@@ -2364,4 +2367,5 @@
 
   $mail->body .= $footer;
   return $mail;
-}
\ No newline at end of file
+}
+?>
\ No newline at end of file
