You are here

function administerusersbyrole_menu in Administer Users by Role 5

File

./administerusersbyrole.module, line 19
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_menu($may_cache) {
  $items = array();
  if (!$may_cache) {
    if (arg(0) === 'admin' && arg(1) === 'user' && arg(2) === 'user' && arg(3) === 'create') {
      if (!user_access('create users')) {
        drupal_set_message(t('You do not have permission to create users.'), 'error');
        drupal_goto("");
      }
    }
    else {
      if (arg(0) === 'user') {
        switch (arg(2)) {
          case 'edit':
            $uid = arg(1);
            $account = user_load(array(
              'uid' => $uid,
            ));
            if (!_administerusersbyrole_can_edit_user($account)) {
              drupal_set_message(t('You do not have permission to edit %user.', array(
                '%user' => $account->name,
              )), 'error');
              drupal_goto("user/{$uid}");
            }
            break;
          case 'delete':
            $uid = arg(1);
            $account = user_load(array(
              'uid' => $uid,
            ));
            if (!_administerusersbyrole_can_delete_user($account)) {
              drupal_set_message(t('You do not have permission to delete %user.', array(
                '%user' => $account->name,
              )), 'error');
              drupal_goto("user/{$uid}");
            }
            break;
        }
      }
    }
  }
  return $items;
}