You are here

function masquerade_menu_access in Masquerade 7

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_menu_access()
masquerade_block_1 in ./masquerade.module
Masquerade block form.
masquerade_user_operations_masquerade in ./masquerade.module
Callback for user operation.
1 string reference to 'masquerade_menu_access'
masquerade_menu in ./masquerade.module
Implements hook_menu().

File

./masquerade.module, line 228
The masquerade module allows administrators to masquerade as other user.

Code

function masquerade_menu_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_query("SELECT 1 FROM {masquerade_users} WHERE uid_from = :uid_from", array(
        ':uid_from' => $user->uid,
      ))
        ->fetchField();
      break;
    case 'switch':
      $switch_to_account = FALSE;
      global $user;
      if ($uid) {
        if (!is_numeric($uid)) {
          return FALSE;
        }
        if ($account = user_load($uid)) {
          $switch_to_account = db_query("SELECT 1 FROM {masquerade_users} WHERE uid_from = :uid_from AND uid_to = :uid_to", array(
            ':uid_from' => $user->uid,
            ':uid_to' => $account->uid,
          ))
            ->fetchField();
        }
      }
      return !isset($_SESSION['masquerading']) && (user_access('masquerade as user') || user_access('masquerade as admin') || $switch_to_account);
      break;
  }
}