You are here

function simplenews_subscription_list_remove_submit in Simplenews 7

Same name and namespace in other branches
  1. 6.2 includes/simplenews.admin.inc \simplenews_subscription_list_remove_submit()
  2. 6 simplenews.admin.inc \simplenews_subscription_list_remove_submit()
  3. 7.2 includes/simplenews.admin.inc \simplenews_subscription_list_remove_submit()

@todo

File

includes/simplenews.admin.inc, line 1005
Newsletter admin, subscription admin, simplenews settings

Code

function simplenews_subscription_list_remove_submit($form, &$form_state) {
  $removed = array();
  $invalid = array();
  $checked_lists = array_keys(array_filter($form_state['values']['newsletters']));
  $emails = preg_split("/[\\s,]+/", $form_state['values']['emails']);
  foreach ($emails as $email) {
    $email = trim($email);
    if (valid_email_address($email)) {
      foreach ($checked_lists as $tid) {
        simplenews_unsubscribe_user($email, $tid, FALSE, 'mass unsubscribe');
        $removed[] = $email;
      }
    }
    else {
      $invalid[] = $email;
    }
  }
  if ($removed) {
    $removed = implode(", ", $removed);
    drupal_set_message(t('The following addresses were unsubscribed: %removed.', array(
      '%removed' => $removed,
    )));
    $lists = simplenews_categories_load_multiple();
    $list_names = array();
    foreach ($checked_lists as $tid) {
      $list_names[] = _simplenews_newsletter_name($lists[$tid]);
    }
    drupal_set_message(t('The addresses were unsubscribed from the following newsletters: %newsletters.', array(
      '%newsletters' => implode(', ', $list_names),
    )));
  }
  else {
    drupal_set_message(t('No addresses were removed.'));
  }
  if ($invalid) {
    $invalid = implode(", ", $invalid);
    drupal_set_message(t('The following addresses were invalid: %invalid.', array(
      '%invalid' => $invalid,
    )), 'error');
  }

  // Return to the parent page.
  $form_state['redirect'] = 'admin/people/simplenews';
}