? simplenews_new.patch
Index: simplenews.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/simplenews.admin.inc,v
retrieving revision 1.59.2.4
diff -u -p -r1.59.2.4 simplenews.admin.inc
--- simplenews.admin.inc	2 Jan 2010 21:04:51 -0000	1.59.2.4
+++ simplenews.admin.inc	12 Jan 2010 21:29:50 -0000
@@ -465,7 +465,7 @@ function simplenews_subscription_list_ad
       '#title' => t('Anonymous user preferred language'),
       '#default_value' => '',
       '#options' => $options,
-      '#description' => t('Anonymous users will be subscribed with the selected preferred language. They will receive newsletters in this language if available. Registered users will be subscribed with their preferred language as set on their account page.'),
+      '#description' => t('New subscriptions will be subscribed with the selected preferred language. The language of existing subscribers is unchanged.'),
     );
   }
   else {
@@ -711,7 +711,8 @@ function simplenews_subscription_list_fo
     array('data' => t('Email'), 'field' => 'ss.mail', 'sort' => 'asc'),
     array('data' => t('Username'), 'field' => 'u.name'),
     array('data' => t('Status'), 'field' => 'ss.activated'),
-    t('Operations')
+    array('data' => t('Language'), 'field' => 'ss.language'),
+    t('Operations'),
   );
 
   // Data collection with filter and sorting applied
@@ -747,11 +748,13 @@ function simplenews_subscription_list_fo
 
   $snids = array();
   // Subscription table and table pager
+  $languages = language_list();
   while ($subscription = db_fetch_object($result)) {
     $snids[$subscription->snid] = '';
     $form['mail'][$subscription->snid] = array('#value' => $subscription->mail);
     $form['name'][$subscription->snid] =  array('#value' => isset($subscription->uid) ? l($subscription->name, 'user/'. $subscription->uid) : $subscription->name);
     $form['status'][$subscription->snid] = array('#value' => theme('simplenews_status', $subscription->activated, 'activated'));
+    $form['language'][$subscription->snid] = array('#value' => $languages[$subscription->language]->name);
     $form['operations'][$subscription->snid] = array('#value' => l(t('edit'), 'admin/content/simplenews/users/edit/'. $subscription->snid, array(), drupal_get_destination()));
   }
   $form['snids'] = array('#type' => 'checkboxes', '#options' => $snids);
@@ -1255,7 +1258,8 @@ function theme_simplenews_subscription_l
     array('data' => t('Email'), 'field' => 'ss.mail', 'sort' => 'asc'),
     array('data' => t('Username'), 'field' => 'u.name'),
     array('data' => t('Status'), 'field' => 'ss.activated'),
-    t('Operations')
+    array('data' => t('Language'), 'field' => 'ss.language'),
+    t('Operations'),
   );
 
   // Subscription table
@@ -1267,6 +1271,7 @@ function theme_simplenews_subscription_l
       $row[] = drupal_render($form['mail'][$key]);
       $row[] = drupal_render($form['name'][$key]);
       $row[] = drupal_render($form['status'][$key]);
+      $row[] = drupal_render($form['language'][$key]);
       $row[] = drupal_render($form['operations'][$key]);
       $rows[] = $row;
     }
Index: simplenews.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/simplenews.module,v
retrieving revision 1.220.2.13
diff -u -p -r1.220.2.13 simplenews.module
--- simplenews.module	9 Jan 2010 13:17:11 -0000	1.220.2.13
+++ simplenews.module	12 Jan 2010 21:29:52 -0000
@@ -179,7 +179,7 @@ function simplenews_menu() {
     'page arguments' => array('simplenews_admin_users_form', 5),
     'access arguments' => array('administer simplenews subscriptions'),
     'file' => 'simplenews.subscription.inc',
-    );
+  );
   $items['admin/content/simplenews/users/list'] = array(
     'title' => 'List',
     'type' => MENU_DEFAULT_LOCAL_TASK,
@@ -311,6 +311,7 @@ function simplenews_node_type($op, $info
     case 'update':
       $simplenews_types = variable_get('simplenews_content_types', array());
       if (isset($info->old_type) && isset($simplenews_types[$info->old_type]) && $info->old_type != $info->type) {
+        // apply nodetype rename
         unset($simplenews_types[$info->old_type]);
         $simplenews_types[$info->type] = $info->type;
         variable_set('simplenews_content_types', $simplenews_types);
@@ -336,12 +337,12 @@ function simplenews_nodeapi(&$node, $op,
       if (!isset($node->simplenews_mail)) {
         global $language;
         $context['node'] = $node;
-        
-        if (isset($node->body)) {
-          $node->body = token_replace($node->body, 'simplenews', array('node' => $node));
-        }
-        if (isset($node->teaser)) {
-          $node->teaser = token_replace($node->teaser, 'simplenews', array('node' => $node));
+
+          if (isset($node->body)) {
+            $node->body = token_replace($node->body, 'simplenews', array('node' => $node));
+          }
+          if (isset($node->teaser)) {
+            $node->teaser = token_replace($node->teaser, 'simplenews', array('node' => $node));
         }
       }
       break;
@@ -387,7 +388,7 @@ function simplenews_nodeapi(&$node, $op,
         $s_status = $send_with_permission ? SIMPLENEWS_STATUS_SEND_PENDING : SIMPLENEWS_STATUS_SEND_NOT;
         db_query("INSERT INTO {simplenews_newsletters} (nid, vid, tid, s_status, s_format, priority, receipt)
                   VALUES (%d, %d, %d, %d, '%s', %d, %d)", $node->nid, $node->vid, $node->simplenews['tid'], $s_status, $node->simplenews['s_format'], $node->simplenews['priority'], $node->simplenews['receipt']);
-        }
+      }
       else {
         // Update node
         if ($send_with_permission) {
@@ -407,9 +408,9 @@ function simplenews_nodeapi(&$node, $op,
         if ($translations = translation_node_get_translations($node->tnid))  {
           foreach ($translations as $translation) {
             db_query("UPDATE {simplenews_newsletters} SET s_status = %d, s_format = '%s', priority = %d, receipt = %d
-              WHERE nid = %d",
-              SIMPLENEWS_STATUS_SEND_PENDING, $node->simplenews['s_format'], $node->simplenews['priority'],
-              $node->simplenews['receipt'], $translation->nid);
+            WHERE nid = %d",
+            SIMPLENEWS_STATUS_SEND_PENDING, $node->simplenews['s_format'], $node->simplenews['priority'],
+            $node->simplenews['receipt'], $translation->nid);
           }
         }
       }
@@ -493,7 +494,7 @@ function simplenews_form_alter(&$form, $
 
   // Newsletter vocabulary form
   if ($form_id == 'taxonomy_form_vocabulary' && isset($form['vid']) && $form['vid']['#value'] == $vid) {
-    // Hide critical options from newsletter vocabulary.
+    // Enforce and hide critical options from newsletter vocabulary.
     $form['help_simplenews_vocab'] = array(
       '#value' => t('This is the designated simplenews vocabulary.'),
       '#weight' => -1,
@@ -518,7 +519,6 @@ function simplenews_form_alter(&$form, $
   // Simplenews newsletter node form
   elseif (strpos($form_id, '_node_form')) {
     if (in_array($form['type']['#value'], variable_get('simplenews_content_types', array('simplenews')))) {
-
       // Available variables are based on user_mail_tokens().
       // But uses only those which can be used with uid = 0 since simplenews also sends to anonymous users.
       if (isset($form['body_field'])) {
@@ -554,7 +554,7 @@ function simplenews_form_alter(&$form, $
       // Translations of newsletters don't have send and format options. Only the
       // translation source (and non translated) newsletters will get these options.
       if (module_exists('translation') && translation_supported_type($form['#node']->type) &&
-          (isset($form['#node']->translation_source) || ($form['#node']->tnid && $form['#node']->tnid != $form['#node']->nid))) {
+        (isset($form['#node']->translation_source) || ($form['#node']->tnid && $form['#node']->tnid != $form['#node']->nid))) {
         $form['simplenews']['#description'] = t('This newsletter issue is part of a translation set. Sending this set is controlled from the <a href="@link">translation source newsletter</a>.', array('@link' => url('node/'. $form['tnid']['#value'])));
         // Send option of translated newsletters are not used, but a default is
         // required to prevent errors when data is stored in the database.
@@ -567,10 +567,9 @@ function simplenews_form_alter(&$form, $
         // Show newsletter sending options if newsletter has not been send yet.
         // If send a nodification is shown.
         if (!isset($simplenews_values['s_status']) || (isset($simplenews_values['s_status']) && $simplenews_values['s_status'] == SIMPLENEWS_STATUS_SEND_NOT)) {
-  
           // Add dynamic text for send button.
           drupal_add_js(drupal_get_path('module', 'simplenews') .'/simplenews.js', 'module');
-  
+          
           if (user_access('send newsletter')) {
             $options[SIMPLENEWS_COMMAND_SEND_NONE] = t("Don't send now");
             $options[SIMPLENEWS_COMMAND_SEND_TEST] = t('Send one test newsletter to the test address');
@@ -595,7 +594,7 @@ function simplenews_form_alter(&$form, $
               '#attributes' => array('class' => 'simplenews-command-send'),
             );
           }
-  
+          
           $address_default = variable_get('site_mail', ini_get('sendmail_from'));
           if (variable_get('simplenews_test_address_override', 0)) {
             $form['simplenews']['test_address'] = array(
@@ -613,14 +612,14 @@ function simplenews_form_alter(&$form, $
               '#value' => variable_get('simplenews_test_address', $address_default),
             );
           }
-  
+          
           $form['simplenews']['advanced'] = array(
             '#type' => 'fieldset',
             '#title' => t('Email options'),
             '#collapsible' => TRUE,
             '#collapsed' => TRUE,
           );
-             // Hide format selection if there is nothing to choose.
+          // Hide format selection if there is nothing to choose.
           // The default format is plain text.
           $format_options = _simplenews_format_options();
           if (count($format_options) > 1) {
@@ -637,7 +636,7 @@ function simplenews_form_alter(&$form, $
               '#value' => key($format_options),
             );
           }
-  
+          
           $form['simplenews']['advanced']['priority'] = array(
             '#type' => 'select',
             '#title' => t('Email priority'),
@@ -686,7 +685,6 @@ function simplenews_cron() {
   simplenews_clear_spool();
   // Update sent status for newsletter admin panel.
   simplenews_send_status_update();
-
 }
 
 /**
@@ -731,7 +729,7 @@ function simplenews_user($op, &$edit, &$
         }
         else {
           if ($subscribe_new_account == 'silent' || ($subscribe_new_account == 'on' && $opt_inout_method == 'hidden')) {
-            $hidden[] = $newsletter->tid;            
+            $hidden[] = $newsletter->tid;
           }
         }
       }
@@ -759,6 +757,7 @@ function simplenews_user($op, &$edit, &$
       break;
     case 'insert':
       if ($edit['mail']) {
+        // take over previously anonymous subscribed mail.
         $query = "SELECT snid FROM {simplenews_subscriptions} WHERE mail = '%s'";
         if ($result = db_fetch_object(db_query($query, $edit['mail']))) {
           db_query("UPDATE {simplenews_subscriptions} SET uid = %d, language = '%s' WHERE snid = %d", $edit['uid'], $edit['language'], $result->snid);
@@ -802,15 +801,20 @@ function simplenews_user($op, &$edit, &$
       break;
     case 'update':
       if ($category == 'account' && $edit['mail']) {
+        // always keep uid, mail, language in sync
         $query = "SELECT snid FROM {simplenews_subscriptions} WHERE uid = %d";
         if ($result = db_fetch_object(db_query($query, $account->uid))) {
-          db_query("DELETE FROM {simplenews_subscriptions} WHERE mail = '%s' AND uid = %d", $edit['mail'], 0);
+          // user has snid. if user changes mail to previously subscribed anonymous mail, remove subscription.
+          db_query("DELETE FROM {simplenews_subscriptions} WHERE mail = '%s' AND uid = 0", $edit['mail']);
+          // migrate current subscription snid to new mail, language.
           db_query("UPDATE {simplenews_subscriptions} SET mail = '%s', language = '%s' WHERE snid = %d", $edit['mail'], $edit['language'], $result->snid);
         }
         else {
+          // no current snid. try taking over subscription via user mail match.
           $query = "SELECT snid FROM {simplenews_subscriptions} WHERE mail = '%s'";
           if ($result = db_fetch_object(db_query($query, $edit['mail']))) {
-            db_query("UPDATE {simplenews_subscriptions} SET uid = %d, language = '%s' WHERE snid = %d", $account->uid, $account->language, $result->snid);
+            // take over subscription, overwrite edited language.
+            db_query("UPDATE {simplenews_subscriptions} SET uid = %d, language = '%s' WHERE snid = %d", $account->uid, $edit['language'], $result->snid);
           }
         }
       }
@@ -825,7 +829,9 @@ function simplenews_user($op, &$edit, &$
       if ($category == 'newsletter' && user_access('subscribe to newsletters')) {
         foreach ($edit['newsletters'] as $tid => $checked) {
           if ($checked) {
-            simplenews_subscribe_user($account->mail, $tid, FALSE, 'website');
+            $subscriber = simplenews_subscribe_user($account->mail, $tid, FALSE, 'website');
+            // TODO unneeded language selection in newsletter settings. apply account language!
+            //simplenews_subscriber_update($subscriber->snid, array('language' => $edit['language']));
           }
           else {
             simplenews_unsubscribe_user($account->mail, $tid, FALSE, 'website');
@@ -850,7 +856,7 @@ function simplenews_user($op, &$edit, &$
     case 'form':
       if ($category == 'newsletter' && user_access('subscribe to newsletters')) {
         $subscription = simplenews_get_subscription($account);
-        $form = _simplenews_subscription_manager_form($subscription);
+        $form = _simplenews_subscription_manager_form($subscription, 'user');
         $form['subscriptions']['#title'] =  t('Current newsletter subscriptions');
         unset($form['update'], $form['subscriptions']['mail']);
         return $form;
@@ -876,10 +882,11 @@ function simplenews_user($op, &$edit, &$
         // Collect newsletter to which the current user is subscribed.
         // 'hidden' newsletters are not listed.
         foreach (simplenews_get_newsletters(variable_get('simplenews_vid', '')) as $newsletter) {
-          if (db_result(db_query('SELECT COUNT(s.uid) FROM {simplenews_subscriptions} s
-                                 INNER JOIN {simplenews_snid_tid} t ON s.snid = t.snid
-                                 WHERE s.uid = %d AND t.tid = %d AND t.status = %d',
-                                 $account->uid, $newsletter->tid, SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED))) {
+          if (db_result(db_query(
+            'SELECT COUNT(s.uid) FROM {simplenews_subscriptions} s
+            INNER JOIN {simplenews_snid_tid} t ON s.snid = t.snid
+            WHERE s.uid = %d AND t.tid = %d AND t.status = %d',
+            $account->uid, $newsletter->tid, SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED))) {
             $subscriptions[] = l($newsletter->name, 'taxonomy/term/'. $newsletter->tid);
           }
         }
@@ -919,7 +926,7 @@ function simplenews_block($op = 'list', 
       $blocks = array();
       foreach (simplenews_get_newsletters(variable_get('simplenews_vid', '')) as $newsletter) {
         //TODO: 1. without form -> by role; 2. with form -> user caching with refresh on subscribe/unsubscribe (option as setting) or no caching
-        // Only list a block if the newsletter is not Hidden.
+        // Only list a block if the newsletter is not hidden.
         $blocks[$newsletter->tid] = array(
           'info' => t('Newsletter: @title', array('@title' => $newsletter->name)),
           'cache' => variable_get('simplenews_block_f_'. $newsletter->tid, 1) ? BLOCK_NO_CACHE : BLOCK_CACHE_PER_ROLE,
@@ -1028,6 +1035,20 @@ function _simplenews_user_load($mail) {
 }
 
 /**
+ * Update subscriber data.
+ *
+ * @param $snid
+ *   Subscribers ID.
+ * @param $data
+ *   Array of data to be updated
+ *   'language'  Preferred newsletter language (default: '')
+ */
+function simplenews_subscriber_update($snid, $data) {
+  $language = isset($data['language']) ? $data['language'] : '';
+  db_query("UPDATE {simplenews_subscriptions} SET language = '%s' WHERE snid = %d", $language, $snid);
+}
+
+/**
  * Subscribe a user to a newsletter or send a confirmation mail.
  *
  * The $confirm parameter determines the action:
@@ -1035,6 +1056,8 @@ function _simplenews_user_load($mail) {
  *   TRUE  = User receives an email to verify the address and complete the subscription
  * A new subscription account is created when the user is subscribed to the first newsletter
  *
+ * This function does NOT update language information if account already exists.
+ *
  * @param string $mail
  *   The email address to subscribe to the newsletter.
  * @param integer $tid
@@ -1051,6 +1074,9 @@ function _simplenews_user_load($mail) {
  *    mass subscribe: mass admin UI
  *    mass unsubscribe: mass admin UI
  *    action: Drupal actions
+ *
+ * @return $subscription
+ *   Subscription object.
  */
 function simplenews_subscribe_user($mail, $tid, $confirm = TRUE, $source = 'unknown', $preferred_language = NULL) {
   global $language;
@@ -1069,6 +1095,7 @@ function simplenews_subscribe_user($mail
     // Note that step 3 gets subscription data based on mail address because the uid can be 0 (for anonymous users)
     $account = _simplenews_user_load($mail);
 
+    // TODO MIRO
     // If the site is multilingual:
     //  - Anonymous users are subscribed with their preferred language
     //    equal to the language of the current page.
@@ -1099,26 +1126,29 @@ function simplenews_subscribe_user($mail
   }
   elseif (!isset($subscription->tids[$tid])) {
     // Add user to newsletter relationship if not already subscribed.
-    
+
     // Check if user is (un)subscribed to this newsletter.
     // Resubscribe or add new subscription.
     if (isset($subscription->newsletter_subscription[$tid])) {
-      db_query("UPDATE {simplenews_snid_tid}
-               SET status = %d, timestamp = %d, source = '%s'
-               WHERE snid = %d AND tid = %d",
-               SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED, time(), $source,
-               $subscription->snid, $tid);
+      db_query("
+        UPDATE {simplenews_snid_tid}
+        SET status = %d, timestamp = %d, source = '%s'
+        WHERE snid = %d AND tid = %d",
+        SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED, time(), $source,
+        $subscription->snid, $tid);
     }
     else {
-      db_query("INSERT INTO {simplenews_snid_tid} (snid, tid, status, timestamp, source)
-               VALUES (%d, %d, %d, %d, '%s')",
-               $subscription->snid, $tid, SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED, time(), $source);
+      db_query("
+        INSERT INTO {simplenews_snid_tid} (snid, tid, status, timestamp, source)
+        VALUES (%d, %d, %d, %d, '%s')",
+        $subscription->snid, $tid, SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED, time(), $source);
     }
 
     // Execute simplenews subscribe trigger.
     simplenews_call_actions('subscribe', $subscription);
   }
-  return TRUE;
+
+  return $subscription;
 }
 
 /**
@@ -1163,7 +1193,7 @@ function simplenews_unsubscribe_user($ma
     db_query("UPDATE {simplenews_snid_tid}
              SET status = %d, timestamp = %d, source = '%s'
              WHERE snid = %d AND tid = %d",
-             SIMPLENEWS_SUBSCRIPTION_STATUS_UNSUBSCRIBED, time(), $source, $subscription->snid, $tid);
+    SIMPLENEWS_SUBSCRIPTION_STATUS_UNSUBSCRIBED, time(), $source, $subscription->snid, $tid);
 
     // Execute simplenews unsubscribe trigger
     simplenews_call_actions('unsubscribe', $subscription);
@@ -1184,16 +1214,16 @@ function simplenews_unsubscribe_user($ma
 function simplenews_user_is_subscribed($mail, $tid, $reset = FALSE) {
   static $subscribed = array();
 
-    if ($reset) {
-      $subscribed = array();
-    }
+  if ($reset) {
+    $subscribed = array();
+  }
 
-    if (!isset($subscribed[$mail][$tid])) {
-      $subscribed[$mail][$tid] = db_result(db_query("SELECT COUNT(*) FROM {simplenews_subscriptions} s
+  if (!isset($subscribed[$mail][$tid])) {
+    $subscribed[$mail][$tid] = db_result(db_query("SELECT COUNT(*) FROM {simplenews_subscriptions} s
                                                     INNER JOIN {simplenews_snid_tid} t ON s.snid = t.snid
                                                     WHERE s.mail = '%s' AND t.tid = %d AND t.status = %d",
-                                                    $mail, $tid, SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED)) ? TRUE : FALSE;
-    }
+    $mail, $tid, SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED)) ? TRUE : FALSE;
+  }
 
   return $subscribed[$mail][$tid];
 }
@@ -1235,7 +1265,8 @@ function simplenews_get_subscription($ac
   elseif (isset($account->uid) && $account->uid > 0) {
     $subscription = db_fetch_object(db_query("SELECT s.*, u.name FROM {simplenews_subscriptions} s LEFT JOIN {users} u ON u.uid = s.uid WHERE s.uid = %d", $account->uid));
   }
-
+  // TODO what if
+  
   if (!empty($subscription)) {
     $result = db_query("SELECT tid, status, timestamp, source
                         FROM {simplenews_snid_tid} t WHERE t.snid = %d", $subscription->snid);
@@ -1246,6 +1277,7 @@ function simplenews_get_subscription($ac
       }
       $subscription->newsletter_subscription[$newsletter_subscription->tid] = $newsletter_subscription;
     }
+    // simplenews_subscription matches account language if registered.
     $subscription->language = user_preferred_language($subscription);
   }
   else {
@@ -1278,8 +1310,9 @@ function simplenews_delete_subscription(
  * Build subscription manager form.
  *
  * @param object $subscription subscription object
+ * @param string $context 'user' or 'admin' depending form usage
  */
-function _simplenews_subscription_manager_form($subscription) {
+function _simplenews_subscription_manager_form($subscription, $context = 'user') {
   $form = array();
   $options = array();
   $default_value = array();
@@ -1307,6 +1340,46 @@ function _simplenews_subscription_manage
   if ($subscription->mail) {
     $form['subscriptions']['#title'] = t('Subscriptions for %mail', array('%mail' => $subscription->mail));
     $form['subscriptions']['mail'] = array('#type' => 'value', '#value' => $subscription->mail);
+    if ($context =='admin'
+      && (variable_get('language_count', 1) > 1)) {
+      // TODO no default detectable due to user_load and subscription load
+      //$language_options[''] = t('Site default language');
+      $languages = language_list('enabled');
+      foreach ($languages[1] as $langcode => $item) {
+        $name = t($item->name);
+        $language_options[$langcode] = $name . ($item->native != $name ? ' ('. $item->native .')' : '');
+      }
+      // std users have language in profile. disable
+      $disabled = $subscription->uid ? TRUE : FALSE;
+      $form['language'] = array(
+        '#type' => 'fieldset',
+        '#title' => 'Preferred language',
+        '#description' => t('Subscriber language settings.'),
+        '#disabled' => TRUE,
+      );
+      if ($subscription->uid) {
+        // TODO fapi error: disabled not supported for select type
+        // workaround: output markup
+        $form['language']['language'] = array(
+          '#type' => 'markup',
+          '#value' => check_plain($language_options[$subscription->language->language]), // check_plain needed?
+        );
+      }
+      else {
+        $form['language']['language'] = array(
+          '#type' => 'radios',
+          '#default_value' => $subscription->language->language,
+          '#options' => $language_options,
+        );
+      }
+    }
+    else {
+      // TODO should we ignore this case?
+      $form['language']['language'] = array(
+        '#type' => 'value',
+        '#value' => $subscription->language->language
+      );
+    }
     $form['update'] = array(
       '#type' => 'submit',
       '#value' => t('Update'),
@@ -1878,7 +1951,7 @@ function simplenews_mail_spool($nid = NU
     else {
       watchdog('simplenews', '%success emails sent, %fail failed.', array('%success' => $count_success, '%fail' => $count_fail));
     }
-    
+
     variable_set('simplenews_last_cron', time());
     variable_set('simplenews_last_sent', count($mail_sent));
   }
@@ -2019,7 +2092,7 @@ function simplenews_send_status_update()
     foreach ($node_count as $nidvid => $count) {
       // Translated nodes (tnid != 0)
       if ($tnid != '0' && $sum[$tnid] == '0') {
-          $send[] = $nidvid;
+        $send[] = $nidvid;
       }
       // Untranslated nodes (tnid == 0)
       elseif ($tnid == '0' && $count == '0') {
@@ -2118,7 +2191,7 @@ function _simplenews_set_from($node = NU
 
   // Windows based PHP systems don't accept formatted emails.
   $formatted_address = substr(PHP_OS, 0, 3) == 'WIN' ? $address : '"'. mime_header_encode($name) .'" <'. $address .'>';
-  
+
   return array(
     'address' => $address,
     'formatted' => $formatted_address,
@@ -2242,7 +2315,7 @@ function _simplenews_absolute_mail_urls(
  * List of preg* regular expression patterns to search for and replace with
  */
 function _simplenews_html_replace() {
-    return array(
+  return array(
         '/&quot;/i'  => '"',
         '/&gt;/i'    => '>',
         '/&lt;/i'    => '<',
@@ -2263,7 +2336,7 @@ function _simplenews_html_replace() {
         '/&reg;/i'   => '(R)',
         '/&bull;/i'  => '*',
         '/&euro;/i'  => 'Euro ',
-    );
+  );
 }
 
 /**
@@ -2321,7 +2394,7 @@ function simplenews_token_values($type, 
         $hash = _simplenews_generate_hash($account->mail, $account->snid, $newsletter->tid);
       }
 
-      // When simplenews_token_values() is called from simplenews_nodeapi() 
+      // When simplenews_token_values() is called from simplenews_nodeapi()
       // $newsletter->name contains no value. Newsletter name is
       // reconstructed from $node->simplenews['tid'].
       $newsletter_name = isset($newsletter->name) ? $newsletter->name : '';
@@ -2334,7 +2407,7 @@ function simplenews_token_values($type, 
       }
 
       // Build tokens for both 'simplenews_subscription' and 'simplenews'.
-      $values['simplenews-subscribe-url']       = url('newsletter/confirm/add/'. $hash, array('absolute' => TRUE, 'language' => $language));      
+      $values['simplenews-subscribe-url']       = url('newsletter/confirm/add/'. $hash, array('absolute' => TRUE, 'language' => $language));
       $values['simplenews-unsubscribe-url']     = url('newsletter/confirm/remove/'. $hash, array('absolute' => TRUE, 'language' => $language));
       $values['simplenews-receiver-mail']       = $account->mail;
       $values['simplenews-newsletters-name']    = $newsletter_name ? check_plain($newsletter_name) : '';
@@ -2513,7 +2586,7 @@ function _simplenews_measure_usec($start
   if (!function_exists('getrusage')) {
     return 0;
   }
-  
+
   static $start_time;
   $usage = getrusage();
   $now = (float)($dat["ru_stime.tv_sec"] .'.'. $dat["ru_stime.tv_usec"]) + (float)($usage["ru_utime.tv_sec"] .'.'. $usage["ru_utime.tv_usec"]);
@@ -2534,7 +2607,7 @@ function _simplenews_get_node_form_defau
       's_format' => variable_get('simplenews_format', 'plain'),
       'priority' => variable_get('simplenews_priority', SIMPLENEWS_PRIORITY_NONE),
       'receipt' => variable_get('simplenews_receipt', 0),
-    ),
+  ),
     'send' => user_access('send newsletter') ? variable_get('simplenews_send', SIMPLENEWS_COMMAND_SEND_NONE) : SIMPLENEWS_COMMAND_SEND_NONE,
     's_status' => '0',
     'test_address' => variable_get('simplenews_test_address', variable_get('site_mail', ini_get('sendmail_from'))),
@@ -2572,29 +2645,29 @@ function simplenews_theme() {
       'template' => 'simplenews-block',
       'arguments' => array('tid' => NULL),
       'pattern' => 'simplenews_block__',
-    ),
+  ),
     'simplenews_status' => array(
       'template' => 'simplenews-status',
       'file' => 'simplenews.admin.inc',
       'arguments' => array('status' => NULL, 'source' => NULL),
-    ),
+  ),
     'simplenews_newsletter_subject' => array(
       'arguments' => array('name' => NULL, 'title' => NULL, 'language' => NULL),
-    ),
+  ),
     'simplenews_newsletter_body' => array(
       'template' => 'simplenews-newsletter-body',
       'arguments' => array('node' => NULL, 'language' => NULL),
       'pattern' => 'simplenews_newsletter_body__',
-    ),
+  ),
     'simplenews_newsletter_footer' => array(
       'template' => 'simplenews-newsletter-footer',
       'arguments' => array('node' => NULL, 'key' => NULL, 'language' => NULL),
       'pattern' => 'simplenews_newsletter_footer__',
-    ),
+  ),
     'simplenews_subscription_list' => array(
       'file' => 'simplenews.admin.inc',
       'arguments' => array('form' => NULL),
-    ),
+  ),
   );
 }
 
Index: simplenews.subscription.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/simplenews.subscription.inc,v
retrieving revision 1.13
diff -u -p -r1.13 simplenews.subscription.inc
--- simplenews.subscription.inc	30 Jul 2009 19:56:47 -0000	1.13
+++ simplenews.subscription.inc	12 Jan 2010 21:29:52 -0000
@@ -31,7 +31,7 @@ function simplenews_subscription_manager
     drupal_access_denied();
     return;
   }
-  $form = _simplenews_subscription_manager_form($subscription);
+  $form = _simplenews_subscription_manager_form($subscription, 'admin');
   $form['#validate'][] = 'simplenews_subscription_manager_form_validate';
   $form['#submit'][] = 'simplenews_subscription_manager_form_submit';
   $form['#redirect'] = '';  //Return to home page after (un)subscribe
@@ -53,6 +53,10 @@ function simplenews_subscription_manager
 }
 
 function simplenews_subscription_manager_form_submit($form, &$form_state) {
+  // Get current subscriptions if any.
+  $account = (object) array('mail' => $form_state['values']['mail']);
+  $subscription = simplenews_get_subscription($account);
+
   switch ($form_state['values']['op']) {
     case t('Update'):
       // We first subscribe, then unsubscribe. This prevents deletion of subscriptions
@@ -60,11 +64,12 @@ function simplenews_subscription_manager
       arsort($form_state['values']['newsletters'], SORT_NUMERIC);
       foreach ($form_state['values']['newsletters'] as $tid => $checked) {
         if ($checked) {
-          simplenews_subscribe_user($form_state['values']['mail'], $tid, FALSE, 'website');
+          $subscription = simplenews_subscribe_user($form_state['values']['mail'], $tid, FALSE, 'website');
         }
         else {
           simplenews_unsubscribe_user($form_state['values']['mail'], $tid, FALSE, 'website');
         }
+      simplenews_subscriber_update($subscription->snid, array('language' => $form_state['values']['language']));
       }
       drupal_set_message(t('The newsletter subscriptions for %mail have been updated.', array('%mail' => $form_state['values']['mail'])));
       break;
@@ -74,6 +79,7 @@ function simplenews_subscription_manager
           simplenews_subscribe_user($form_state['values']['mail'], $tid, TRUE, 'website');
         }
       }
+      simplenews_subscriber_update($subscription->snid, array('language' => $form_state['values']['language']));
       drupal_set_message(t('You will receive a confirmation email shortly containing further instructions on how to complete your subscription.'));
       break;
     case t('Unsubscribe'):
