You are here

function simplenews_subscription_manager_form in Simplenews 5

Same name and namespace in other branches
  1. 6 simplenews.subscription.inc \simplenews_subscription_manager_form()

Generates the subscription form for users.

1 call to simplenews_subscription_manager_form()
simplenews_admin_users_form in ./simplenews.module
Menu callback; handles the edit/delete subscription page and a subscription page for anonymous users.
2 string references to 'simplenews_subscription_manager_form'
simplenews_menu in ./simplenews.module
Implementation of hook_menu().
_simplenews_subscription_manager_form in ./simplenews.module
Helper function to build subscription manager form, also used in user edit.

File

./simplenews.module, line 931

Code

function simplenews_subscription_manager_form($snid = NULL) {
  global $user;
  if (isset($snid)) {
    $subscription = simplenews_get_subscription($snid);

    // If we couldn't load subscription set defaults.
    if (!$subscription) {
      $subscription = new stdClass();
      $subscription->tids = array();
    }
  }
  else {
    $subscription = simplenews_get_user_subscription($user->mail);

    // If current user is not subscribed to any newsletter set current user data.
    if ($user->uid && !$subscription) {
      $subscription = new stdClass();
      $subscription->tids = array();
      $subscription->uid = $user->uid;
      $subscription->mail = $user->mail;
    }
  }

  // If non-admin is trying to edit someone else's subscription, access denied.
  if ($user->uid && $user->uid != $subscription->uid && !user_access('subscribe to newsletters')) {
    drupal_access_denied();
    return;
  }
  $form = _simplenews_subscription_manager_form($subscription);
  return $form;
}