Unenrol fixed to support other users too and better workflow
This commit is contained in:
+31
-9
@@ -1,14 +1,17 @@
|
||||
<?php // $Id$
|
||||
|
||||
// Remove oneself from a course, unassigning all roles one might have
|
||||
// Remove oneself or someone else from a course, unassigning all
|
||||
// roles one might have
|
||||
//
|
||||
// This will not delete any of their data from the course,
|
||||
// but will remove them from the student list and prevent
|
||||
// but will remove them from the participant list and prevent
|
||||
// any course email being sent to them.
|
||||
|
||||
require_once("../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
$id = required_param('id', PARAM_INT); //course
|
||||
$userid = optional_param('user', 0, PARAM_INT); //course
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
|
||||
if (! $course = get_record('course', 'id', $id) ) {
|
||||
@@ -23,7 +26,11 @@
|
||||
|
||||
if ($course->metacourse) {
|
||||
print_error('cantunenrollfrommetacourse', '', $CFG->wwwroot.'/course/view.php?id='.$course->id);
|
||||
} else {
|
||||
}
|
||||
|
||||
if ($userid) { // Unenrolling someone else
|
||||
require_capability('moodle/role:assign', $context, NULL, false);
|
||||
} else { // Unenrol yourself
|
||||
require_capability('moodle/role:unassignself', $context, NULL, false);
|
||||
}
|
||||
|
||||
@@ -33,13 +40,19 @@
|
||||
|
||||
if ($confirm and confirm_sesskey()) {
|
||||
|
||||
if (! role_unassign(0, $USER->id, 0, $context->id)) {
|
||||
error("An error occurred while trying to unenrol you.");
|
||||
if ($userid) {
|
||||
if (! role_unassign(0, $userid, 0, $context->id)) {
|
||||
error("An error occurred while trying to unenrol that person.");
|
||||
}
|
||||
} else {
|
||||
if (! role_unassign(0, $USER->id, 0, $context->id)) {
|
||||
error("An error occurred while trying to unenrol you.");
|
||||
}
|
||||
}
|
||||
|
||||
add_to_log($course->id, 'course', 'unenrol', "view.php?id=$course->id", $USER->id);
|
||||
|
||||
redirect($CFG->wwwroot.'/');
|
||||
redirect($CFG->wwwroot.'/user/index.php?id='.$course->id);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,9 +61,18 @@
|
||||
print_header("$course->shortname: $strunenrol", $course->fullname,
|
||||
"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> -> $strunenrol");
|
||||
|
||||
$strunenrolsure = get_string('unenrolsure', '', get_string("yourself"));
|
||||
|
||||
notice_yesno($strunenrolsure, "unenrol.php?id=$id&confirm=yes&sesskey=$USER->sesskey", $_SERVER['HTTP_REFERER']);
|
||||
if ($userid) {
|
||||
if (!$user = get_record('user', 'id', $userid)) {
|
||||
error('That user does not exist!');
|
||||
}
|
||||
$strunenrolsure = get_string('unenrolsure', '', fullname($user, true));
|
||||
notice_yesno($strunenrolsure, "unenrol.php?id=$id&user=$user->id&confirm=yes&sesskey=".sesskey(),
|
||||
$_SERVER['HTTP_REFERER']);
|
||||
} else {
|
||||
$strunenrolsure = get_string('unenrolsure', '', get_string("yourself"));
|
||||
notice_yesno($strunenrolsure, "unenrol.php?id=$id&confirm=yes&sesskey=".sesskey(),
|
||||
$_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
print_footer($course);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user