| 1 |
<?php |
<?php |
| 2 |
// $Id: masquerade.module,v 1.5.2.3 2006/03/14 23:05:23 merlinofchaos Exp $ |
// $Id: masquerade.module,v 1.5.2.4 2006/10/31 05:22:51 Gurpartap Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file masquerade.module |
* @file masquerade.module |
| 25 |
function masquerade_menu($may_cache) { |
function masquerade_menu($may_cache) { |
| 26 |
$items = array(); |
$items = array(); |
| 27 |
if ($may_cache) { |
if ($may_cache) { |
| 28 |
$items[] = array('path' => 'masquerade/switch', |
$items[] = array('path' => 'masquerade/switch', |
| 29 |
'title' => t('switch user'), |
'title' => t('switch user'), |
| 30 |
'callback' => 'masquerade_switch_user', |
'callback' => 'masquerade_switch_user', |
| 31 |
'access' => !$user->masquerading && (user_access('masquerade as user') || user_access('masquerade as admin')), |
'access' => !$user->masquerading && (user_access('masquerade as user') || user_access('masquerade as admin')), |
| 32 |
'type' => MENU_CALLBACK); |
'type' => MENU_CALLBACK); |
| 33 |
|
|
| 34 |
global $user; |
global $user; |
| 35 |
$items[] = array('path' => 'masquerade/unswitch', |
$items[] = array('path' => 'masquerade/unswitch', |
| 36 |
'title' => t('switch back'), |
'title' => t('switch back'), |
| 37 |
'callback' => 'masquerade_switch_back', |
'callback' => 'masquerade_switch_back', |
| 38 |
'access' => $user->masquerading, |
'access' => $user->masquerading, |
| 61 |
*/ |
*/ |
| 62 |
function masquerade_user($op, &$edit, &$edit_user, $category = NULL) { |
function masquerade_user($op, &$edit, &$edit_user, $category = NULL) { |
| 63 |
switch ($op) { |
switch ($op) { |
| 64 |
|
|
| 65 |
case 'logout': |
case 'logout': |
| 66 |
if ($edit_user->masquerading) { |
if (!empty($edit_user->masquerading)) { |
| 67 |
global $user; |
global $user; |
| 68 |
$real_user = user_load(array('uid' => $user->masquerading)); |
$real_user = user_load(array('uid' => $user->masquerading)); |
| 69 |
watchdog('masquerade', "User '$real_user->name' no longer masquerading as '$user->name'"); |
watchdog('masquerade', "User '$real_user->name' no longer masquerading as '$user->name'"); |
| 74 |
case 'view': |
case 'view': |
| 75 |
// check if user qualifies as admin |
// check if user qualifies as admin |
| 76 |
$roles = variable_get('masquerade_admin_roles', array()); |
$roles = variable_get('masquerade_admin_roles', array()); |
| 77 |
$perm = $edit_user->uid == 1 || array_intersect(array_keys($edit_user->roles), $roles) ? |
$perm = $edit_user->uid == 1 || array_intersect(array_keys($edit_user->roles), $roles) ? |
| 78 |
'masquerade as admin' : |
'masquerade as admin' : |
| 79 |
'masquerade as user'; |
'masquerade as user'; |
| 80 |
|
|
| 123 |
|
|
| 124 |
$roles = variable_get('masquerade_admin_roles', array()); |
$roles = variable_get('masquerade_admin_roles', array()); |
| 125 |
|
|
| 126 |
$perm = $uid == 1 || array_intersect(array_keys($new_user->roles), $roles) ? |
$perm = $uid == 1 || array_intersect(array_keys($new_user->roles), $roles) ? |
| 127 |
'masquerade as admin' : |
'masquerade as admin' : |
| 128 |
'masquerade as user'; |
'masquerade as user'; |
| 129 |
// check to see if we need admin permission |
// check to see if we need admin permission |