| 1 |
<?php |
<?php |
| 2 |
// $Id: masquerade.module,v 1.13 2006/07/09 16:55:17 steved Exp $ |
// $Id: masquerade.module,v 1.13.2.1 2007/05/02 08:15:21 Gurpartap Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file masquerade.module |
* @file masquerade.module |
| 27 |
if ($may_cache) { |
if ($may_cache) { |
| 28 |
$default_test_user = user_load(array('name' => variable_get('masquerade_test_user', 0))); |
$default_test_user = user_load(array('name' => variable_get('masquerade_test_user', 0))); |
| 29 |
|
|
| 30 |
$items[] = array('path' => 'masquerade/switch', |
$items[] = array('path' => 'masquerade/switch', |
| 31 |
'title' => t('switch user'), |
'title' => t('switch user'), |
| 32 |
'callback' => 'masquerade_switch_user', |
'callback' => 'masquerade_switch_user', |
| 33 |
'access' => !$GLOBALS['masquerading'] && (user_access('masquerade as user') || user_access('masquerade as admin')), |
'access' => !$GLOBALS['masquerading'] && (user_access('masquerade as user') || user_access('masquerade as admin')), |
| 34 |
'type' => MENU_CALLBACK); |
'type' => MENU_CALLBACK); |
| 35 |
|
|
| 36 |
$items[] = array('path' => 'masquerade/quickswitch', |
$items[] = array('path' => 'masquerade/quickswitch', |
| 37 |
'title' => t('switch to test user'), |
'title' => t('switch to test user'), |
| 38 |
'callback' => 'masquerade_switch_user', |
'callback' => 'masquerade_switch_user', |
| 39 |
'callback arguments' => array($default_test_user->uid), |
'callback arguments' => array($default_test_user->uid), |
| 40 |
'access' => !$GLOBALS['masquerading'] && (user_access('masquerade as user') || user_access('masquerade as admin')), |
'access' => !$GLOBALS['masquerading'] && (user_access('masquerade as user') || user_access('masquerade as admin')), |
| 41 |
'type' => MENU_NORMAL_ITEM); |
'type' => MENU_NORMAL_ITEM); |
| 42 |
|
|
| 43 |
$items[] = array('path' => 'masquerade/unswitch', |
$items[] = array('path' => 'masquerade/unswitch', |
| 44 |
'title' => t('switch back'), |
'title' => t('switch back'), |
| 45 |
'callback' => 'masquerade_switch_back', |
'callback' => 'masquerade_switch_back', |
| 46 |
'access' => $GLOBALS['masquerading'], |
'access' => $GLOBALS['masquerading'], |
| 72 |
*/ |
*/ |
| 73 |
function masquerade_user($op, &$edit, &$edit_user, $category = NULL) { |
function masquerade_user($op, &$edit, &$edit_user, $category = NULL) { |
| 74 |
switch ($op) { |
switch ($op) { |
| 75 |
|
|
| 76 |
case 'logout': |
case 'logout': |
| 77 |
if ($edit_user->masquerading) { |
if (!empty($edit_user->masquerading)) { |
| 78 |
global $user; |
global $user; |
| 79 |
cache_clear_all("menu:".$user->uid.":", true); |
cache_clear_all("menu:".$user->uid.":", true); |
| 80 |
$real_user = user_load(array('uid' => $user->masquerading)); |
$real_user = user_load(array('uid' => $user->masquerading)); |
| 86 |
case 'view': |
case 'view': |
| 87 |
// check if user qualifies as admin |
// check if user qualifies as admin |
| 88 |
$roles = array_keys(array_filter(variable_get('masquerade_admin_roles', array()))); |
$roles = array_keys(array_filter(variable_get('masquerade_admin_roles', array()))); |
| 89 |
$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) ? |
| 90 |
'masquerade as admin' : |
'masquerade as admin' : |
| 91 |
'masquerade as user'; |
'masquerade as user'; |
| 92 |
|
|
| 142 |
'#default_value' => check_plain($test_user->name), |
'#default_value' => check_plain($test_user->name), |
| 143 |
'#description' => 'Enter the username of an account you wish to switch easily between. The name must be an exisiting user.', |
'#description' => 'Enter the username of an account you wish to switch easily between. The name must be an exisiting user.', |
| 144 |
); |
); |
| 145 |
|
|
| 146 |
$form['#validate'] = array( |
$form['#validate'] = array( |
| 147 |
'masquerade_settings_validate' => array() |
'masquerade_settings_validate' => array() |
| 148 |
); |
); |
| 168 |
} |
} |
| 169 |
|
|
| 170 |
$roles = array_keys(array_filter(variable_get('masquerade_admin_roles', array()))); |
$roles = array_keys(array_filter(variable_get('masquerade_admin_roles', array()))); |
| 171 |
$perm = $uid == 1 || array_intersect(array_keys($new_user->roles), $roles) ? |
$perm = $uid == 1 || array_intersect(array_keys($new_user->roles), $roles) ? |
| 172 |
'masquerade as admin' : |
'masquerade as admin' : |
| 173 |
'masquerade as user'; |
'masquerade as user'; |
| 174 |
// check to see if we need admin permission |
// check to see if we need admin permission |