From: moodler Date: Thu, 28 Sep 2006 08:55:04 +0000 (+0000) Subject: Unenrol fixed to support other users too and better workflow X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=8d73640e7f69773a08407b485a4780b28559ccca;p=moodle.git Unenrol fixed to support other users too and better workflow --- diff --git a/course/unenrol.php b/course/unenrol.php index d33fa84f28..ba15e4545f 100644 --- a/course/unenrol.php +++ b/course/unenrol.php @@ -1,14 +1,17 @@ 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, "wwwroot/course/view.php?id=$course->id\">$course->shortname -> $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);