You are here

function administerusersbyrole_form_alter in Administer Users by Role 5

File

./administerusersbyrole.module, line 94
Allows users with 'administer users' permission and a role (specified in 'Access control') to edit/delete other users with a specified role. If the user being edited has multiple roles, the user doing the editing must have…

Code

function administerusersbyrole_form_alter($form_id, &$form) {
  if ($form_id === 'user_multiple_delete_confirm') {
    $anyallowed = FALSE;
    foreach (array_filter($form['accounts']) as $uid => $value) {
      if (!is_numeric($uid)) {
        continue;
      }
      $account = user_load(array(
        'uid' => $uid,
      ));
      if (_administerusersbyrole_can_delete_user($account)) {
        $anyallowed = TRUE;
      }
      else {
        drupal_set_message(t('You do not have permission to delete %user.', array(
          '%user' => $account->name,
        )), 'error');
        unset($form['accounts'][$uid]);
        unset($form['accounts'][$uid]);
      }
    }
    if (!$anyallowed) {
      drupal_goto(substr($form['#action'], 1));
    }
  }
}