You are here

function masquerade_access in Masquerade 6

Determine if the current user has permission to switch users.

Parameters

string $type: Either 'switch', 'unswitch', 'user', or 'autocomplete'.

object $uid: An optional parameter indicating a specific uid to switch to. Otherwise, return if the user can switch to any user account.

Return value

TRUE, if the user can perform the requested action, FALSE otherwise.

2 calls to masquerade_access()
masquerade_block in ./masquerade.module
Implementation of hook_block().
masquerade_block_1 in ./masquerade.module
Masquerade block form.
1 string reference to 'masquerade_access'
masquerade_menu in ./masquerade.module
Implementation of hook_menu().

File

./masquerade.module, line 178
masquerade.module

Code

function masquerade_access($type, $uid = NULL) {
  switch ($type) {
    case 'unswitch':
      return isset($_SESSION['masquerading']) || arg(2) == 'menu-customize' || arg(2) == 'menu';
    case 'autocomplete':
      return isset($_SESSION['masquerading']) || (user_access('masquerade as user') || user_access('masquerade as admin'));
      break;
    case 'user':
      global $user;
      return db_result(db_query("SELECT TRUE FROM {masquerade_users} WHERE uid_from = %d", $user->uid));
      break;
    case 'switch':
      global $user;
      $switch_to_account = FALSE;
      if ($uid) {
        if (!is_numeric($uid)) {
          return FALSE;
        }
        if ($account = user_load(array(
          'uid' => $uid,
        ))) {
          $switch_to_account = db_result(db_query("SELECT TRUE FROM {masquerade_users} WHERE uid_from = %d AND uid_to = %d", $user->uid, $account->uid));
        }
      }
      return !isset($_SESSION['masquerading']) && (user_access('masquerade as user') || user_access('masquerade as admin') || $switch_to_account);
      break;
  }
}