You are here

function simplenews_subscriptions_admin_form_submit in Simplenews 6.2

Same name and namespace in other branches
  1. 7.2 includes/simplenews.subscription.inc \simplenews_subscriptions_admin_form_submit()
  2. 7 includes/simplenews.subscription.inc \simplenews_subscriptions_admin_form_submit()

FAPI ADMIN subscription form_submit.

1 string reference to 'simplenews_subscriptions_admin_form_submit'
simplenews_subscriptions_admin_form in includes/simplenews.subscription.inc
FAPI ADMIN subscription form.

File

includes/simplenews.subscription.inc, line 739
(Un)subscription and (un)subscription confirmation

Code

function simplenews_subscriptions_admin_form_submit($form, &$form_state) {
  global $user;
  if (isset($user->mail) && $user->mail == $form_state['values']['mail']) {
    $account = $user;
  }
  else {
    $account = (object) array(
      'mail' => $form_state['values']['mail'],
    );
  }
  $subscription = simplenews_get_subscription($account);
  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');
    }
    else {
      simplenews_unsubscribe_user($form_state['values']['mail'], $tid, FALSE, 'website');
    }
  }
  $data = array();
  $data['activated'] = $form_state['values']['activated'];
  if (!$subscription->uid) {
    if (isset($form_state['values']['language'])) {
      $data['language'] = $form_state['values']['language'];
    }
  }
  simplenews_subscriber_update($subscription, $data);
  drupal_set_message(t('The newsletter subscriptions for %mail have been updated.', array(
    '%mail' => $form_state['values']['mail'],
  )));
}