You are here

function subuser_switch_user_access in Subuser 6

Same name and namespace in other branches
  1. 8 switch/subuser_switch.module \subuser_switch_user_access()
  2. 7.2 switch/subuser_switch.module \subuser_switch_user_access()

Check if the user has permission to switch the specified user.

Pass cases:

  • Super user.
  • Returning to parent account.
  • The user is a parent of the user being switched to.

Parameters

integer $uid User ID being switched to.:

boolean $check_token Boolean flag to check the token (used by router).:

Return value

boolean Access granted.

1 call to subuser_switch_user_access()
subuser_handler_field_user_link_switch::render in ./subuser_handler_field_user_link_switch.inc
1 string reference to 'subuser_switch_user_access'
subuser_menu in ./subuser.module
Implementation of hook_menu().

File

./subuser.module, line 225
Allows users of a particular role to create sub user account in another role.

Code

function subuser_switch_user_access($uid, $check_token = FALSE) {
  global $user;

  // Check for valid token or ignore token if $check_token is FALSE.
  if (!$check_token || isset($_GET['token']) && drupal_valid_token($_GET['token'], 'subuser/switch/' . $uid)) {

    // Check if user is switching back.
    if (isset($_SESSION['subuser_uid']) && $uid == $_SESSION['subuser_uid']) {
      return TRUE;
    }

    // Check if user is #1 or has the 'switch subuser' permission and is the
    // parent of the user to be switched to.
    if ($user->uid == 1 || user_access('switch subuser') && db_result(db_query('SELECT uid FROM {subuser_relationship} WHERE uid = %d AND parent_id = %d', $uid, $user->uid))) {
      return TRUE;
    }
  }
  return FALSE;
}