1 user.admin.inc user_multiple_cancel_confirm($form, &$form_state)

Form builder; Cancel multiple accounts at the same time.

See also

user_cancel_user_action()

Related topics

File

core/modules/user/user.admin.inc, line 13
Admin page callback file for the user module.

Code

function user_multiple_cancel_confirm($form, &$form_state) {
  if (isset($_SESSION['user_cancel_action']['timestamp']) && (REQUEST_TIME - $_SESSION['user_cancel_action']['timestamp'] < 6000)) {
    $uids = $_SESSION['user_cancel_action']['uids'];
  }
  else {
    $uids = array();
  }

  $accounts = user_load_multiple($uids);

  // Output a notice that user 1 cannot be canceled.
  if (isset($accounts[1])) {
    $redirect = (count($accounts) == 1);
    $message = t('The user account %name cannot be cancelled.', array('%name' => $accounts[1]->name));
    backdrop_set_message($message, $redirect ? 'error' : 'warning');
    unset($accounts[1]);
    // If only user 1 was selected, redirect to the overview.
    if ($redirect) {
      backdrop_goto('admin/people');
    }
  }

  if (empty($accounts)) {
    $destination = isset($_GET['destination']) ? $_GET['destination'] : 'admin/people';
    $form['empty']['#markup'] = '<p>' . t('Return to the <a href="!url">content administration page</a>.', array('!url' => url($destination))) . '</p>';
    backdrop_set_message(t('No user accounts have been selected for cancellation.'), 'error');
    return $form;
  }

  $form_state['accounts'] = $accounts;

  $form['user_list'] = array(
    '#theme' => 'item_list',
    '#items' => array(),
  );
  foreach ($accounts as $account) {
    $form['user_list']['#items'][] = check_plain($account->name);
  }

  module_load_include('inc', 'user', 'user.pages');
  $form['user_cancel_method'] = array(
    '#type' => 'item',
    '#title' => t('When cancelling these accounts'),
  );
  $form['user_cancel_method'] += user_cancel_methods();

  // Remove method descriptions.
  foreach (element_children($form['user_cancel_method']) as $element) {
    unset($form['user_cancel_method'][$element]['#description']);
  }

  // Allow to send the account cancellation confirmation mail.
  $form['user_cancel_confirm'] = array(
    '#type' => 'checkbox',
    '#title' => t('Require email confirmation to cancel account.'),
    '#default_value' => FALSE,
    '#description' => t('When enabled, the user must confirm the account cancellation via email.'),
  );
  // Also allow to send account canceled notification mail, if enabled.
  $form['user_cancel_notify'] = array(
    '#type' => 'checkbox',
    '#title' => t('Notify user when account is canceled.'),
    '#default_value' => FALSE,
    '#access' => config_get('system.core', 'user_mail_status_canceled_notify'),
    '#description' => t('When enabled, the user will receive an email notification after the account has been cancelled.'),
  );

  $confirm_question = format_plural(count($accounts), 'Are you sure you want to cancel this user account?', 'Are you sure you want to cancel these user accounts?');
  return confirm_form($form, $confirm_question, 'admin/people', NULL, t('Cancel accounts'), t('Cancel'));
}