You are here

function administerusersbyrole_init in Administer Users by Role 6

Implements hook_init().

File

./administerusersbyrole.module, line 34
Non-displayable characters.

Code

function administerusersbyrole_init() {
  $items = array();
  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("");
    }
  }
  elseif (arg(0) === 'user') {
    $uid = arg(1);
    if (module_exists('me')) {
      $uid = _me_check_arg($uid);
    }
    $account = user_load(array(
      'uid' => $uid,
    ));
    switch (arg(2)) {
      case 'edit':
        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/' . $account->uid);
        }
        break;
      case 'delete':
        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/' . $account->uid);
        }
        break;
    }
  }
  return $items;
}