You are here

function subscriptions_user_suspend_form in Subscriptions 6

Same name and namespace in other branches
  1. 7 subscriptions.admin.inc \subscriptions_user_suspend_form()
  2. 2.0.x subscriptions.admin.old.php \subscriptions_user_suspend_form()

Returns the form definition for the suspend part of the overview page.

@params $account Must be a valid user account from user_load().

1 string reference to 'subscriptions_user_suspend_form'
subscriptions_page_user_overview in ./subscriptions.admin.inc
Construct the overview page, which displays a summary of subscriptions per type as well as the user settings at user/UID/subscriptions. This form is also used for admin/settings/subscriptions/userdefaults.

File

./subscriptions.admin.inc, line 381
Subscriptions module (load-on-demand admin functions).

Code

function subscriptions_user_suspend_form(&$form_state, $account) {
  global $user;
  if (!isset($account)) {
    return NULL;
  }
  $uid = $account->uid;
  $suspended = subscriptions_suspended($uid, TRUE);
  if (!user_access('administer user subscriptions') && !($user->uid == $uid && (user_access('suspend own subscriptions') || $suspended))) {
    return NULL;
  }
  $tr = 't';
  $form['suspend'] = array(
    '#type' => 'fieldset',
    '#title' => $tr('Delivery of notifications'),
    '#weight' => 5,
    '#collapsible' => TRUE,
    '#collapsed' => !$suspended,
  );
  $count = 0;
  if ($suspended) {
    $count = db_result(db_query("SELECT COUNT(*) FROM {subscriptions_queue} WHERE uid = %d AND suspended <> 0", $uid));
  }
  $options[] = $tr('Yes');
  if ($count > 0) {
    $form['suspend']['queued'] = array(
      '#value' => '<div>' . t('You have %count items queued for delivery. (The number of resulting notifications will typically be much smaller.)', array(
        '%count' => $count,
      )) . '</div>',
    );
    $options[-1] = t('!Yes, but drop the queued items', array(
      '!Yes' => $tr('Yes'),
    ));
  }
  $options[] = $tr('No');
  if (user_access('administer user subscriptions')) {
    $options[2] = t('!No, and alert user to bad email address (administrator option)', array(
      '!No' => $tr('No'),
    ));
  }
  $form['suspend']['state'] = array(
    '#type' => 'radios',
    '#title' => t('Receive notifications'),
    '#description' => user_access('suspend own subscriptions', $account) ? t('You can temporarily suspend notifications from being sent, e.g. during a vacation. They will be retained and sent after you reenable notifications.') : t('Select %Yes to send all queued notifications and resume normal delivery.', array(
      '%Yes' => $tr('Yes'),
    )),
    '#default_value' => user_access('administer user subscriptions') ? $suspended : min($suspended, 1),
    '#options' => $options,
  );
  $form['suspend']['uid'] = array(
    '#type' => 'value',
    '#value' => $uid,
  );
  $form['suspend']['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}