Skip to content

Commit 63952b8

Browse files
Merge pull request #6250 from christianbeeznest/fide-22573
Course: Add "login as" and reporting actions in user tool - refs #BT22573
2 parents 6445e4b + cb0c03d commit 63952b8

File tree

1 file changed

+39
-53
lines changed

1 file changed

+39
-53
lines changed

public/main/user/user.php

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,91 +1025,77 @@ function active_filter($active, $urlParams, $row)
10251025
*/
10261026
function modify_filter($user_id, $row, $data)
10271027
{
1028-
$canEditUsers = 'true' == api_get_setting('allow_user_course_subscription_by_course_admin') || api_is_platform_admin();
1029-
1028+
$canEditUsers = 'true' === api_get_setting('allow_user_course_subscription_by_course_admin') || api_is_platform_admin();
10301029
$is_allowed_to_track = api_is_allowed_to_edit(true, true);
10311030
$user_id = $data[0];
10321031
$userInfo = api_get_user_info($user_id);
1033-
$isInvitee = INVITEE == $userInfo['status'] ? true : false;
1032+
$isInvitee = INVITEE == $userInfo['status'];
10341033
$course_info = $_course = api_get_course_info();
10351034
$current_user_id = api_get_user_id();
10361035
$sessionId = api_get_session_id();
10371036
$courseId = $_course['id'];
10381037
$type = isset($_REQUEST['type']) ? intval($_REQUEST['type']) : STUDENT;
10391038

1040-
$result = '';
1039+
$result = '<div class="flex items-center justify-center gap-2 text-sm">';
1040+
1041+
// Reporting
10411042
if ($is_allowed_to_track) {
1042-
$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().'"
1043-
title="'.get_lang('Reporting').'">
1044-
'.Display::getMdiIcon('statistics', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Reporting')).'
1045-
</a>';
1043+
$result .= Display::url(
1044+
Display::getMdiIcon(ActionIcon::VIEW_DETAILS, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Reporting')),
1045+
'../my_space/myStudents.php?'.api_get_cidreq().'&student='.$user_id.'&details=true&course='.$courseId.'&origin=user_course&id_session='.api_get_session_id()
1046+
);
10461047
}
10471048

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

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

1061-
$text = get_lang('Remove assistant role');
1062-
if ($isTutor) {
1063-
$text = get_lang('Convert to assistant');
1064-
}
1065-
1066-
if ($isInvitee) {
1067-
$disabled = 'disabled';
1068-
} else {
1069-
$disabled = '';
1070-
}
1071-
1072-
$allow = api_get_configuration_value('extra');
1073-
if ($allow) {
1074-
$result .= '<a href="'.
1075-
api_get_path(WEB_CODE_PATH).'extra/userInfo.php?'.api_get_cidreq().'&editMainUserInfo='.$user_id.'"
1076-
title="'.get_lang('Edit').'" >'.
1077-
Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')).
1078-
'</a>&nbsp;';
1064+
// Edit
1065+
if (api_get_configuration_value('extra')) {
1066+
$result .= Display::url(
1067+
Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Edit')),
1068+
api_get_path(WEB_CODE_PATH).'extra/userInfo.php?'.api_get_cidreq().'&editMainUserInfo='.$user_id
1069+
);
10791070
}
10801071

1072+
// Convert to assistant / Remove
10811073
if (STUDENT == $data['user_status_in_course']) {
10821074
$result .= Display::url(
1083-
$text,
1075+
Display::getMdiIcon($isTutor ? ActionIcon::ACCEPT : ActionIcon::REJECT, 'ch-tool-icon text-xl', ICON_SIZE_MEDIUM, null, $text),
10841076
'user.php?'.api_get_cidreq().'&action=set_tutor&is_tutor='.$isTutor.'&user_id='.$user_id.'&type='.$type,
1085-
['class' => 'btn btn--plain '.$disabled]
1086-
).'&nbsp;';
1077+
['class' => $disabled]
1078+
);
10871079
}
10881080
}
10891081

1090-
// edit
1091-
if ($canEditUsers) {
1092-
// unregister
1093-
if ($user_id != $current_user_id || api_is_platform_admin()) {
1094-
$result .= '<a
1095-
class="btn btn-sm btn--danger delete-swal"
1096-
href="'.api_get_self().'?'.api_get_cidreq().'&type='.$type.'&unregister=yes&user_id='.$user_id.'"
1097-
title="'.addslashes(api_htmlentities(get_lang('Unsubscribe'))).' " >'.
1098-
get_lang('Unsubscribe').'</a>&nbsp;';
1099-
}
1082+
// Unsubscribe
1083+
if ($canEditUsers && ($user_id != $current_user_id || api_is_platform_admin())) {
1084+
$result .= Display::url(
1085+
Display::getMdiIcon(ActionIcon::EXIT, 'ch-tool-icon text-xl delete-swal', null, ICON_SIZE_MEDIUM, get_lang('Unsubscribe')),
1086+
api_get_self().'?'.api_get_cidreq().'&type='.$type.'&unregister=yes&user_id='.$user_id
1087+
);
11001088
}
11011089
} else {
1102-
// Show buttons for unsubscribe
1103-
if (1 == $course_info['unsubscribe']) {
1104-
if ($user_id == $current_user_id) {
1105-
$result .= '<a
1106-
class="btn btn-sm btn--danger delete-swal"
1107-
href="'.api_get_self().'?'.api_get_cidreq().'&type='.$type.'&unregister=yes&user_id='.$user_id.'"
1108-
title="'.addslashes(api_htmlentities(get_lang('Unsubscribe'))).' >'.
1109-
get_lang('Unsubscribe').'</a>&nbsp;';
1110-
}
1090+
if (1 == $course_info['unsubscribe'] && $user_id == $current_user_id) {
1091+
$result .= Display::url(
1092+
Display::getMdiIcon(ActionIcon::EXIT, 'ch-tool-icon text-xl delete-swal', null, ICON_SIZE_MEDIUM, get_lang('Unsubscribe')),
1093+
api_get_self().'?'.api_get_cidreq().'&type='.$type.'&unregister=yes&user_id='.$user_id
1094+
);
11111095
}
11121096
}
11131097

1098+
$result .= '</div>';
1099+
11141100
return $result;
11151101
}

0 commit comments

Comments
 (0)