1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-24 16:31:48 +02:00

Issue #5476 - Emulation mode. (beta)

This commit is contained in:
camer0n
2025-04-21 17:03:52 -07:00
parent 5275acdacd
commit effb433b1d
2 changed files with 58 additions and 0 deletions

View File

@@ -524,6 +524,33 @@ if(!isset($_E107['no_session']) && !isset($_E107['no_lan']))
$dbg->logTime('Set User Language Session');
e107::getLanguage()->set(); // set e_LANGUAGE, USERLAN, Language Session / Cookies etc. requires $pref;
if($id = e107::getSession()->get('emulate'))
{
if(!empty($_POST['stopEmulation']))
{
e107::getSession()->clear('emulate');
e107::getMessage()->addSuccess("User access emulation mode has been stopped.");
}
else
{
$emulatedUser = e107::user($id);
$msg = "You are currently emulating the userclass and admin permissions of <b>".$emulatedUser['user_name']."</b>";
$msg .= "<br />This is a temporary emulation mode and will be cleared when you log out.";
$msg .= "<pre>userclasses: ".$emulatedUser['user_class']."\nadminperms: ".$emulatedUser['user_perms']."</pre>";
e107::getMessage()->setTitle('User Access Emulation Mode', E_MESSAGE_WARNING)->addWarning($msg);
$text = "<form action='".e_REQUEST_URI."' method='post'>\n";
$text .= "<input class='btn btn-dark' type='submit' name='stopEmulation' value='Stop Emulating' />\n";
$text .= "</form>\n";
e107::getMessage()->addWarning($text);
define('USERCLASS_LIST', $emulatedUser['user_class']);
define('ADMINPERMS', $emulatedUser['user_perms']);
}
}
}
else
{
@@ -536,6 +563,8 @@ if(!empty($pref['multilanguage']) && (e_LANGUAGE !== $pref['sitelanguage']))
$sql2->mySQLlanguage = e_LANGUAGE;
}
//do it only once and with the proper function
// e107_include_once(e_LANGUAGEDIR.e_LANGUAGE.'/'.e_LANGUAGE.'.php');
// e107_include_once(e_LANGUAGEDIR.e_LANGUAGE.'/'.e_LANGUAGE.'_custom.php');

View File

@@ -182,6 +182,13 @@ JS;
->setMode('main')
->setAction('logoutas');
break;
case 'emulate':
$this->getRequest()
->setQuery(array())
->setMode('main')
->setAction('emulate');
break;
// redirect to AdminObserver/AdminPage()
case 'admin':
@@ -862,6 +869,26 @@ class users_admin_ui extends e_admin_ui
{
// System Message only on non-successful logout as another user
}
/**
* Allows the emulation of a user ID if the current user has sufficient permissions and a user ID is provided.
* If the conditions are met, a message with the emulated User ID is displayed, and the session is updated to emulate the specified user ID.
*
* @return void
*/
public function emulatePage()
{
if(getperms('0') && !empty($_POST['userid']))
{
e107::getMessage()->addInfo("Emulating User ID".print_a($_POST,true));
e107::getSession()->set('emulate', (int) $_POST['userid']);
}
$this->redirect('list', 'main', true);
}
/**
* Remove admin status trigger
@@ -2723,6 +2750,8 @@ class users_admin_form_ui extends e_admin_form_ui
// login/logout As
if(getperms('0') && !($row['user_admin'] && getperms('0', $row['user_perms'])))
{
$opts['emulate'] = 'Emulate Permissions';
if(e107::getUser()->getSessionDataAs() == $row['user_id'])
{
// $text .= "<option value='logoutas'>".sprintf(USRLAN_AS_2, $row['user_name'])."</option>";