Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Modifications to unenrol. Now a teacher can unenrol students from the…

… course.
  • Loading branch information...
commit 7dc1ea300ad6a469680d947d6ec5ff85dd14c9bf 1 parent 2f21e98
martin authored
Showing with 27 additions and 10 deletions.
  1. +26 −10 course/unenrol.php
  2. +1 −0  user/index.php
View
36 course/unenrol.php
@@ -1,6 +1,6 @@
<?PHP // $Id$
-// Allows a student to "unenrol" from a class
+// Removes a student from a class
// This will not delete any of their data from the course,
// but will remove them from the student list and prevent
// any course email being sent to them.
@@ -8,35 +8,51 @@
require("../config.php");
require("lib.php");
- require_variable($id); //course
+ require_variable($id); //course
+ optional_variable($user, $USER->id); //user
if (! $course = get_record("course", "id", $id) ) {
error("That's an invalid course id");
}
+ if (! $user = get_record("user", "id", $user) ) {
+ error("That's an invalid user id");
+ }
require_login($course->id);
+ if ($user->id != $USER->id and !isteacher($course->id)) {
+ error("You must be a teacher to do this");
+ }
+
if (isset($confirm)) {
- if (! unenrol_student_in_course($USER->id, $course->id)) {
+
+ if (! unenrol_student_in_course($user->id, $course->id)) {
error("An error occurred while trying to unenrol you.");
}
// remove some other things
- delete_records("discuss_subscriptions", "user", $USER->id);
+ delete_records("discuss_subscriptions", "user", $user->id);
- add_to_log($course->id, "course", "unenrol", "view.php?id=$course->id", "$USER->id");
+ add_to_log($course->id, "course", "unenrol", "view.php?id=$course->id", "$user->id");
- unset($USER->student["$id"]);
+ if ($user->id == $USER->id) {
+ unset($USER->student["$id"]);
+ redirect("$CFG->wwwroot");
+ }
- redirect("$CFG->wwwroot");
+ redirect("$CFG->wwwroot/user/index.php?id=$course->id");
}
print_header("Unenrol from $course->shortname", "$course->shortname", "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> Unenrol");
- notice_yesno ("Are you sure you want to remove yourself from this course?",
- "unenrol.php?id=$id&confirm=yes",
- "$HTTP_REFERER");
+ if ($user->id == $USER->id) {
+ notice_yesno ("Are you sure you want to remove yourself from this course?",
+ "unenrol.php?id=$id&user=$user->id&confirm=yes", "$HTTP_REFERER");
+ } else {
+ notice_yesno ("Are you sure you want to remove $user->firstname $user->lastname from this course?",
+ "unenrol.php?id=$id&user=$user->id&confirm=yes", "$HTTP_REFERER");
+ }
print_footer();
View
1  user/index.php
@@ -79,6 +79,7 @@ function print_user($user, $course, $teacherlinks) {
echo "<A HREF=\"../course/user.php?id=$course->id&user=$user->id\">Contributions</A><BR>";
echo "<A HREF=\"../course/log.php?id=$course->id&user=$user->id&date=$timemidnight\">Today's logs</A><BR>";
echo "<A HREF=\"../course/log.php?id=$course->id&user=$user->id\">All logs</A><BR>";
+ echo "<A HREF=\"../course/unenrol.php?id=$course->id&user=$user->id\">Unenrol</A><BR>";
if (isstudent($course->id, $user->id)) {
echo "<A HREF=\"../course/loginas.php?id=$course->id&user=$user->id\">Login as</A><BR>";
}
Please sign in to comment.
Something went wrong with that request. Please try again.