You are here

function masquerade_switch_back in Masquerade 6

Same name and namespace in other branches
  1. 5 masquerade.module \masquerade_switch_back()
  2. 7 masquerade.module \masquerade_switch_back()

Function for a masquerading user to switch back to the previous user.

1 call to masquerade_switch_back()
masquerade_switch_back_page in ./masquerade.module
Page callback that allows a user who is currently masquerading to become a new user.

File

./masquerade.module, line 730
masquerade.module

Code

function masquerade_switch_back() {

  // switch user
  global $user;
  cache_clear_all($user->uid, 'cache_menu', true);
  $uid = db_result(db_query("SELECT m.uid_from FROM {masquerade} m WHERE m.sid = '%s' AND m.uid_as = %d ", session_id(), $user->uid));

  // erase record
  db_query("DELETE FROM {masquerade} WHERE sid = '%s' AND uid_as = %d ", session_id(), $user->uid);
  $oldname = $user->uid == 0 ? variable_get('anonymous', t('Anonymous')) : $user->name;
  $user = user_load(array(
    'uid' => $uid,
  ));
  watchdog('masquerade', 'User %user no longer masquerading as %masq_as.', array(
    '%user' => $user->name,
    '%masq_as' => $oldname,
  ), WATCHDOG_INFO);
}