You are here

function subscriptions_user_suspend_form in Subscriptions 2.0.x

Same name and namespace in other branches
  1. 6 subscriptions.admin.inc \subscriptions_user_suspend_form()
  2. 7 subscriptions.admin.inc \subscriptions_user_suspend_form()

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

_state

Parameters

array $form:

object|null $account: Must be a valid user account from user_load().

1 call to subscriptions_user_suspend_form()
subscriptions_page_user_overview in ./subscriptions.admin.old.php
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.old.php, line 438
Subscriptions module (load-on-demand admin functions).

Code

function subscriptions_user_suspend_form(array &$form, array &$form_state, $account) {
  global $user;
  if (!isset($account)) {
    return;
  }
  $uid = $account->uid;
  $suspended = subscriptions_suspended($uid, TRUE);
  if (!user_access('administer user subscriptions') && !($user->uid == $uid && (user_access('suspend own subscriptions') || $suspended))) {
    return;
  }
  $form['suspend'] = array(
    '#type' => 'fieldset',
    '#title' => t('Delivery of notifications'),
    '#weight' => 5,
    '#collapsible' => TRUE,
    '#collapsed' => !$suspended,
  );
  $count = 0;
  if ($suspended) {
    $count = db_query("SELECT COUNT(*) FROM {subscriptions_queue} WHERE uid = :uid AND suspended <> 0", array(
      ':uid' => $uid,
    ))
      ->fetchField();
  }
  $tr = 't';
  $options[] = $tr('Yes');
  if ($count > 0) {
    $form['suspend']['queued'] = array(
      '#markup' => '<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'),
    ));
  }
  $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'),
  ));
  $form['suspend']['state'] = array(
    '#type' => 'radios',
    '#title' => t('Receive notifications'),
    '#description' => filter_xss($description),
    '#default_value' => user_access('administer user subscriptions') ? $suspended : min($suspended, 1),
    '#options' => $options,
  );
  $form['suspend']['uid'] = array(
    '#type' => 'value',
    '#value' => $uid,
  );
  $form['suspend']['save_notifications'] = array(
    '#type' => 'submit',
    '#value' => t('Save notifications'),
  );
  $form['#submit'][] = '_subscriptions_user_suspend_form_submit';
}