diff --git a/masquerade.module b/masquerade.module index c50c2cf..324e1c2 100644 --- a/masquerade.module +++ b/masquerade.module @@ -453,20 +453,20 @@ function masquerade_block_1($record) { // Add in user-specific switches. $result = db_query("SELECT uid_to FROM {masquerade_users} WHERE uid_from = %d", $user->uid); while ($uid_to = db_result($result)) { - $masquerade_switches[] = $uid_to; + if (!isset($_SESSION['user']->uid) || $uid_to != $_SESSION['user']->uid) { + $masquerade_switches[] = $uid_to; + } } - foreach ($masquerade_switches as $switch_user) { - if (!isset($_SESSION['user']->uid) || $switch_user != $_SESSION['user']->uid) { - $user_name = user_load(array('uid' => $switch_user)); - $switch_link = 'masquerade/switch/'. $user_name->uid; - if ($user_name->uid) { - $quick_switch_link[] = l($user_name->name, $switch_link, array('query' => array('token' => drupal_get_token($switch_link)))); - } - if ($switch_user == 0) { - $user_name->name = variable_get('anonymous', t('Anonymous')); - $quick_switch_link[] = l($user_name->name, $switch_link, array('query' => array('token' => drupal_get_token($switch_link)))); - } + $result = db_query("SELECT uid, name FROM {users} WHERE uid IN (". db_placeholders($masquerade_switches) .")", $masquerade_switches); + while ($user_name = db_fetch_object($result)) { + $switch_link = 'masquerade/switch/'. $user_name->uid; + if ($user_name->uid) { + $quick_switch_link[] = l($user_name->name, $switch_link, array('query' => array('token' => drupal_get_token($switch_link)))); + } + else { + $user_name->name = variable_get('anonymous', t('Anonymous')); + $quick_switch_link[] = l($user_name->name, $switch_link, array('query' => array('token' => drupal_get_token($switch_link)))); } }