You are here

function masquerade_switch_back in Masquerade 5

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

Page callback that allows a user who is currently masquerading to become a new user.

1 string reference to 'masquerade_switch_back'
masquerade_menu in ./masquerade.module
Implementation of hook_menu().

File

./masquerade.module, line 367
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 uid_from FROM {masquerade} WHERE sid = '%s' AND 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->name;
  $user = user_load(array(
    'uid' => $uid,
  ));
  watchdog('masquerade', t('User %user no longer masquerading as %masq_as.', array(
    '%user' => $user->name,
    '%masq_as' => $oldname,
  )));
  drupal_set_message(t('No longer masquerading as %masq_as.', array(
    '%masq_as' => $oldname,
  )));
  drupal_goto(referer_uri());
}