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

Issue #5476 Use a navigation icon instead of an alert.

This commit is contained in:
camer0n
2025-04-26 06:43:06 -07:00
parent 0dc24de938
commit 9455504dda
4 changed files with 154 additions and 31 deletions

View File

@@ -525,33 +525,23 @@ 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(deftrue('e_ADMIN_AREA') && getperms('0') && ($id = e107::getSession()->get('emulate')))
{
if(!empty($_POST['stopEmulation']))
{
e107::getSession()->clear('emulate');
e107::getMessage()->addSuccess("User access emulation mode has been stopped.");
e107::getMessage()->addSuccess("Admin 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']);
// define('USERID', $emulatedUser['user_id']); Don't emulate user id. It will mess with logs.
// define('USERID', $emulatedUser['user_id']); // Don't emulate user id. It will mess with logs.
define('USERNAME', $emulatedUser['user_name']);
}
unset($id);
}
}
else

View File

@@ -882,7 +882,10 @@ class users_admin_ui extends e_admin_ui
if(getperms('0') && !empty($_POST['userid']))
{
e107::getSession()->set('emulate', (int) $_POST['userid']);
$uid = (int) $_POST['userid'];
e107::getSession()->set('emulate',$uid);
$user = e107::user($uid);
e107::getMessage()->addSuccess("Emulation of <strong>".$user['user_name']."</strong> activated.", 'default', true);;
}
$this->redirect('list', 'main', true);
@@ -2749,7 +2752,7 @@ 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'])
{
@@ -2814,6 +2817,11 @@ class users_admin_form_ui extends e_admin_form_ui
// $text .= "<option value='adminperms'>".USRLAN_221."</option>\n";
// $text .= "<option value='unadmin'>".USRLAN_34."</option>\n";
if(getperms('0'))
{
$opts['emulate'] = 'Emulate permissions';
}
$opts['adminperms'] = USRLAN_221;
$opts['unadmin'] = USRLAN_34;
}

View File

@@ -426,7 +426,7 @@ class admin_shortcodes extends e_shortcode
{
$text .= $sql->mySQLlanguage;
$text .= ' (' .$slng->convert($sql->mySQLlanguage).")
: <span class='btn btn-default btn-secondary button' style='cursor: pointer;' onclick='expandit(\"lan_tables\");'><a style='text-decoration:none' title='' href=\"javascript:void(0);\" >&nbsp;&nbsp;".count($aff). ' ' .UTHEME_MENU_L3."&nbsp;&nbsp;</a></span><br />
: <span class='btn btn-default btn-secondary button' style='cursor: pointer;' onclick='expandit(\"lan_tables\");'><a style='text-decoration:none' title='' href=\"javascript:void(0);\" >&nbsp;&nbsp;".count($aff). ' ' .defset('UTHEME_MENU_L3')."&nbsp;&nbsp;</a></span><br />
<span style='display:none' id='lan_tables'>
";
$text .= implode('<br />', $aff);
@@ -494,7 +494,7 @@ class admin_shortcodes extends e_shortcode
$select .= "<option value='".$lng."' {$selected}>$lng</option>\n";
}
$select .= '</select> ' .(!isset($params['nobutton']) ? "<button class='update e-hide-if-js' type='submit' name='setlanguage' value='no-value'><span>".UTHEME_MENU_L1. '</span></button>' : ''). '
$select .= '</select> ' .(!isset($params['nobutton']) ? "<button class='update e-hide-if-js' type='submit' name='setlanguage' value='no-value'><span>".defset('UTHEME_MENU_L1'). '</span></button>' : ''). '
' .e107::getForm()->hidden('setlanguage', '1'). '
</div>
</form>
@@ -504,7 +504,7 @@ class admin_shortcodes extends e_shortcode
if(isset($params['nomenu'])) { return $select; }
if($select) { $text .= "<div class='center'>{$select}</div>"; }
return $ns->tablerender(UTHEME_MENU_L2, $text, 'core-menu-lang', true);
return $ns->tablerender(defset('UTHEME_MENU_L2'), $text, 'core-menu-lang', true);
}
@@ -805,6 +805,126 @@ class admin_shortcodes extends e_shortcode
return $ret;
}
public function sc_admin_perm_emulation()
{
if(!$id = e107::getSession()->get('emulate'))
{
return null; // Return nothing if not in emulation mode
}
$emulatedUser = e107::user($id);
if(empty($emulatedUser))
{
return null; // Return nothing if user data is invalid
}
// Initialize e107 parser and form helper
$tp = e107::getParser();
$frm = e107::getForm();
// Prepare the navbar dropdown
$text = "<ul class='nav nav-admin navbar-nav navbar-right admin-icon-emulation'>
<li class='dropdown'>
<a class='dropdown-toggle' title='User Access Emulation Mode' role='button' data-toggle='dropdown' href='#'>";
// Add warning glyph and emulated username (with fa-beat modification)
$text .= $tp->toGlyph('fa-user-secret', ['class' => 'fa-beat text-warning']) .
"<span class='text-warning hidden-xs hidden-sm hidden-md' style='margin-left: 5px'>" . $tp->toHTML($emulatedUser['user_name']) . "</span>" .
"<b class='caret text-warning'></b></a>";
// Start dropdown menu with padding and width
$text .= '<ul class="dropdown-menu" role="menu" style="padding: 10px; width: 350px">';
// Emulated user details with fixed height and scrollbar
$text .= '<li role="menuitem" class="text-left"><div style="padding: 10px; max-height: 300px; overflow-y: auto;">';
$text .= "<p><strong>Emulated Admin:</strong><br />";
$text .= '<ul class="list-unstyled" style="margin-left: 20px"><li>' . $tp->toHTML($emulatedUser['user_name']) . '</li></ul></p>';
// User Classes as bullets, sorted alphabetically, excluding PUBLIC (0), MAINADMIN (250), READONLY (251), GUEST (252), MEMBER (253), ADMIN (254), NOBODY (255)
$text .= "<p><strong>User Classes:</strong><br />";
$classIds = array_filter(explode(',', $emulatedUser['user_class']));
$excludedClasses = ['0', '250', '251', '252', '253', '254', '255']; // PUBLIC, MAINADMIN, READONLY, GUEST, MEMBER, ADMIN, NOBODY
$classIds = array_diff($classIds, $excludedClasses);
if(!empty($classIds))
{
$classNames = [];
foreach($classIds as $classId)
{
$className = e107::getUserClass()->getName($classId) ?: "Unknown Class ($classId)";
$classNames[] = $className;
}
natcasesort($classNames);
$text .= '<ul class="list-unstyled" style="margin-left: 20px">';
foreach($classNames as $className)
{
$text .= '<li>' . $tp->toHTML($className) . '</li>';
}
$text .= '</ul>';
}
else
{
$text .= 'None';
}
$text .= "</p>";
// Admin Permissions as bullets, sorted alphabetically
$text .= "<p><strong>Admin Permissions:</strong><br />";
if(!empty($emulatedUser['user_perms']) && $emulatedUser['user_perms'] !== '.')
{
$permKeys = array_filter(explode('.', $emulatedUser['user_perms']));
$permdiz = e107::getUserPerms()->getPermList('all');
$permNames = [];
foreach($permKeys as $p)
{
$val = isset($permdiz[$p]) ? (is_array($permdiz[$p]) ? $permdiz[$p][0] : $permdiz[$p]) : "Unknown Permission ($p)";
$permNames[] = $val;
}
natcasesort($permNames);
if(!empty($permNames))
{
$text .= '<ul class="list-unstyled" style="margin-left: 20px">';
foreach($permNames as $permName)
{
$text .= '<li>' . $tp->toHTML($permName) . '</li>';
}
$text .= '</ul>';
}
else
{
$text .= 'None';
}
}
else
{
$text .= 'None';
}
$text .= "</p>";
$text .= '</div></li>';
// Divider
$text .= '<li class="divider"></li>';
// Stop Emulation button using form helper with correct implementation
$text .= '<li role="menuitem" class="text-right">';
$text .= "<p style='padding:15px'><small class='text-muted'>This is a temporary emulation mode and will be cleared when you log out.</small></p>";
$text .= $frm->open('emulation-form', 'post', e_REQUEST_URI, array('class' => 'no-margin'));
$icon = '<i class="fa fa-right-from-bracket fa-fw"></i>';
$text .= $frm->button('stopEmulation', $icon . ' Stop Emulating');
$text .= $frm->close();
$text .= '</li>';
$text .= '</ul></li></ul>';
return $text;
}
/**
* Admin area debug dropdown menu.
* @return string|null
@@ -2757,7 +2877,7 @@ Inverse 10 <span class="badge badge-inverse">10</span>
/**
* @param string $text
* @return string
* @return string|null
*/
private function renderHelpIcon()
{

View File

@@ -198,10 +198,13 @@ $ADMIN_TEMPLATE['header'] = '
{ADMIN_NAVIGATION=enav_logout}
{ADMIN_NAVIGATION=enav_language}
{ADMIN_NAVIGATION=enav_home}
{ADMIN_MULTISITE}
{ADMIN_PM}
{ADMIN_DEBUG}
{ADMIN_PERM_EMULATION}
{ADMIN_NOTIFICATIONS}
{ADMIN_UPDATE}
</div>
</div>
@@ -212,10 +215,12 @@ $ADMIN_TEMPLATE['header'] = '
{ADMIN_NAVIGATION=enav_logout}
{ADMIN_NAVIGATION=enav_language}
{ADMIN_NAVIGATION=enav_home}
{ADMIN_MULTISITE}
{ADMIN_PM}
{ADMIN_DEBUG}
{ADMIN_NOTIFICATIONS}
{ADMIN_PERM_EMULATION}
{ADMIN_UPDATE}
</div>
</div>