Skip to content

Course: Add "login as" and reporting actions in user tool - refs #BT22573 #6250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 39 additions & 53 deletions public/main/user/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -1025,91 +1025,77 @@ function active_filter($active, $urlParams, $row)
*/
function modify_filter($user_id, $row, $data)
{
$canEditUsers = 'true' == api_get_setting('allow_user_course_subscription_by_course_admin') || api_is_platform_admin();

$canEditUsers = 'true' === api_get_setting('allow_user_course_subscription_by_course_admin') || api_is_platform_admin();
$is_allowed_to_track = api_is_allowed_to_edit(true, true);
$user_id = $data[0];
$userInfo = api_get_user_info($user_id);
$isInvitee = INVITEE == $userInfo['status'] ? true : false;
$isInvitee = INVITEE == $userInfo['status'];
$course_info = $_course = api_get_course_info();
$current_user_id = api_get_user_id();
$sessionId = api_get_session_id();
$courseId = $_course['id'];
$type = isset($_REQUEST['type']) ? intval($_REQUEST['type']) : STUDENT;

$result = '';
$result = '<div class="flex items-center justify-center gap-2 text-sm">';

// Reporting
if ($is_allowed_to_track) {
$result .= '<a href="../my_space/myStudents.php?'.api_get_cidreq().'&student='.$user_id.'&details=true&course='.$courseId.'&origin=user_course&id_session='.api_get_session_id().'"
title="'.get_lang('Reporting').'">
'.Display::getMdiIcon('statistics', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Reporting')).'
</a>';
$result .= Display::url(
Display::getMdiIcon(ActionIcon::VIEW_DETAILS, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Reporting')),
'../my_space/myStudents.php?'.api_get_cidreq().'&student='.$user_id.'&details=true&course='.$courseId.'&origin=user_course&id_session='.api_get_session_id()
);
}

// If platform admin, show the login_as icon (this drastically shortens
// time taken by support to test things out)
// Login as
if (api_is_platform_admin()) {
$result .= ' <a
href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php?action=login_as&user_id='.$user_id.'&sec_token='.Security::getTokenFromSession().'">'.
Display::getMdiIcon('login_as', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Login as')).'</a>&nbsp;&nbsp;';
$result .= Display::url(
Display::getMdiIcon(ActionIcon::LOGIN_AS, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Login as')),
api_get_path(WEB_PATH).'?_switch_user='.$userInfo['username']
);
}

if (api_is_allowed_to_edit(null, true)) {
if (empty($sessionId)) {
$isTutor = isset($data['is_tutor']) ? (int) $data['is_tutor'] : 0;
$isTutor = empty($isTutor) ? 1 : 0;
$text = $isTutor ? get_lang('Convert to assistant') : get_lang('Remove assistant role');
$disabled = $isInvitee ? 'disabled' : '';

$text = get_lang('Remove assistant role');
if ($isTutor) {
$text = get_lang('Convert to assistant');
}

if ($isInvitee) {
$disabled = 'disabled';
} else {
$disabled = '';
}

$allow = api_get_configuration_value('extra');
if ($allow) {
$result .= '<a href="'.
api_get_path(WEB_CODE_PATH).'extra/userInfo.php?'.api_get_cidreq().'&editMainUserInfo='.$user_id.'"
title="'.get_lang('Edit').'" >'.
Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')).
'</a>&nbsp;';
// Edit
if (api_get_configuration_value('extra')) {
$result .= Display::url(
Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Edit')),
api_get_path(WEB_CODE_PATH).'extra/userInfo.php?'.api_get_cidreq().'&editMainUserInfo='.$user_id
);
}

// Convert to assistant / Remove
if (STUDENT == $data['user_status_in_course']) {
$result .= Display::url(
$text,
Display::getMdiIcon($isTutor ? ActionIcon::ACCEPT : ActionIcon::REJECT, 'ch-tool-icon text-xl', ICON_SIZE_MEDIUM, null, $text),
'user.php?'.api_get_cidreq().'&action=set_tutor&is_tutor='.$isTutor.'&user_id='.$user_id.'&type='.$type,
['class' => 'btn btn--plain '.$disabled]
).'&nbsp;';
['class' => $disabled]
);
}
}

// edit
if ($canEditUsers) {
// unregister
if ($user_id != $current_user_id || api_is_platform_admin()) {
$result .= '<a
class="btn btn-sm btn--danger delete-swal"
href="'.api_get_self().'?'.api_get_cidreq().'&type='.$type.'&unregister=yes&user_id='.$user_id.'"
title="'.addslashes(api_htmlentities(get_lang('Unsubscribe'))).' " >'.
get_lang('Unsubscribe').'</a>&nbsp;';
}
// Unsubscribe
if ($canEditUsers && ($user_id != $current_user_id || api_is_platform_admin())) {
$result .= Display::url(
Display::getMdiIcon(ActionIcon::EXIT, 'ch-tool-icon text-xl delete-swal', null, ICON_SIZE_MEDIUM, get_lang('Unsubscribe')),
api_get_self().'?'.api_get_cidreq().'&type='.$type.'&unregister=yes&user_id='.$user_id
);
}
} else {
// Show buttons for unsubscribe
if (1 == $course_info['unsubscribe']) {
if ($user_id == $current_user_id) {
$result .= '<a
class="btn btn-sm btn--danger delete-swal"
href="'.api_get_self().'?'.api_get_cidreq().'&type='.$type.'&unregister=yes&user_id='.$user_id.'"
title="'.addslashes(api_htmlentities(get_lang('Unsubscribe'))).' >'.
get_lang('Unsubscribe').'</a>&nbsp;';
}
if (1 == $course_info['unsubscribe'] && $user_id == $current_user_id) {
$result .= Display::url(
Display::getMdiIcon(ActionIcon::EXIT, 'ch-tool-icon text-xl delete-swal', null, ICON_SIZE_MEDIUM, get_lang('Unsubscribe')),
api_get_self().'?'.api_get_cidreq().'&type='.$type.'&unregister=yes&user_id='.$user_id
);
}
}

$result .= '</div>';

return $result;
}
Loading