</tr>\r
<tr valign=top> \r
<td bgcolor="<?=$THEME->cellheading?>"> <CENTER><? formerr($errormsg) ?> </CENTER>\r
- <form name="form" method="post" action="login.php">\r
+ <form name="form" method="post" action="enrol.php">\r
<table>\r
<tr> \r
<td width=50% align=right><P>Entry Key:</P></td>\r
} else {
$errormsg = "That entry key was incorrect, please try again".
- "<BR>(Here's a hint - it starts with \"".substr($actual_password,0,1)."\")";
+ "<BR>(Here's a hint - it starts with \"".substr($course->password,0,1)."\")";
}
}
print_course($course);
- include("login.html");
+ include("enrol.html");
print_footer();
-//// FUNCTIONS /////////////////////////////////////////////
-
-function enrol_student_in_course($user, $course) {
-
- global $db;
-
- $timenow = time();
-
- $rs = $db->Execute("INSERT INTO user_students (user, course, start, end, time)
- VALUES ($user, $course, 0, 0, $timenow)");
- if ($rs) {
- return true;
- } else {
- return false;
- }
-}
-
?>
}
+
+function unenrol_student_in_course($user, $course) {
+ global $db;
+
+ return $db->Execute("DELETE FROM user_students WHERE user = '$user' AND course = '$course'");
+}
+
+
+
+function enrol_student_in_course($user, $course) {
+ global $db;
+
+ $timenow = time();
+
+ $rs = $db->Execute("INSERT INTO user_students (user, course, start, end, time)
+ VALUES ($user, $course, 0, 0, $timenow)");
+ if ($rs) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
?>
--- /dev/null
+<?PHP // $Id$
+
+// Allows a student to "unenrol" 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.
+
+ require("../config.php");
+ require("lib.php");
+
+ require_variable($id); //course
+
+ if (! $course = get_record("course", "id", $id) ) {
+ error("That's an invalid course id");
+ }
+
+ require_login($course->id);
+
+ if (isset($confirm)) {
+ if (! unenrol_student_in_course($USER->id, $course->id)) {
+ error("An error occurred while trying to unenrol you.");
+ }
+ add_to_log($course->id, "course", "unenrol", "view.php?id=$course->id", "$USER->id");
+
+ unset($USER->student["$id"]);
+
+ redirect("$CFG->wwwroot");
+ }
+
+
+ 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");
+
+ print_footer();
+
+
+?>