You are here

function advuser_admin_account_submit in Advanced User 6.3

Same name and namespace in other branches
  1. 5.2 advuser.module \advuser_admin_account_submit()
  2. 6.2 advuser.module \advuser_admin_account_submit()
  3. 7.3 forms/advuser_admin_account.inc \advuser_admin_account_submit()

Submit the user administration update form.

File

forms/advuser_admin_account.inc, line 137
This is the part of the form that provides the actions and the list based on the selected filters.

Code

function advuser_admin_account_submit($form, &$form_state) {
  $operations = module_invoke_all('advuser_operations', $form_state);
  $operation = $operations[$form_state['values']['operation']];
  $destination = $form_state['values']['destination'];

  // Filter out unchecked accounts.
  $accounts_selected = array_filter($form_state['values']['accounts']);
  $form_accounts = $form['accounts']['#options'];
  $advuser =& $_SESSION['advuser'];
  $accounts =& $advuser['accounts'];
  $selectall =& $advuser['selectall'];
  $deselected =& $advuser['deselected'];
  switch ($form_state['values']['operation']) {
    case 'saveselect':
      foreach ($form_accounts as $form_user_id => $value) {
        if (isset($accounts_selected[$form_user_id])) {
          $accounts[$form_user_id] = $form_user_id;
          unset($deselected[$form_user_id]);
        }
        else {
          $deselected[$form_user_id] = $form_user_id;
          unset($accounts[$form_user_id]);
        }
      }
      break;
    case 'deselectall':
      $selectall = FALSE;
      $accounts = array();
      $deselected = array();
      drupal_set_message(t('All selections have been reset.'));
      break;
    case 'selectall':
      $selectall = TRUE;
      $accounts = array();
      $deselected = array();
      drupal_set_message(t('All filtered users have been selected.'));
      break;
    case 'block':
      foreach ($accounts as $user_id) {
        $account = user_load(array(
          'uid' => $user_id,
        ));
        if ($account !== FALSE && $account->status == 1) {
          user_save($account, array(
            'status' => 0,
          ));
        }
        unset($accounts[$user_id]);
      }
      drupal_set_message(t('The selected users have been blocked.'));
      break;
    case 'unblock':
      foreach ($accounts as $user_id) {
        $account = user_load(array(
          'uid' => $user_id,
        ));
        if ($account !== FALSE && $account->status == 0) {
          user_save($account, array(
            'status' => 1,
          ));
        }
        unset($accounts[$user_id]);
      }
      drupal_set_message(t('The selected users have been unblocked.'));
      break;
    case 'email':

      // Menu callback is provided for mass emailing.
      drupal_goto('admin/user/user/advuser/confirm/email');
      break;
    case 'delete':

      // Menu callback is provided for mass deleting.
      drupal_goto('admin/user/user/advuser/confirm/delete');
      break;
  }

  // The add_role and remove_role actions have a callback that is called from
  // here.
  if ($function = $operation['callback']) {

    // Add in callback arguments if present.
    if (isset($operation['callback arguments'])) {
      $args = array_merge(array(
        $accounts_selected,
      ), $operation['callback arguments']);
    }
    else {
      $args = array(
        $accounts_selected,
      );
    }
    call_user_func_array($function, $args);
    $act = str_replace('_', ' ', $operation['callback arguments'][0]);
    drupal_set_message(t('The !action action has been applied.', array(
      '!action' => t($act),
    )));
  }

  // Where to from here?
  extract(parse_url($destination));
  drupal_goto($path, $query);
}