Permalink
Browse files

Cleaned up enrol and unenrol process a bit

  • Loading branch information...
martin
martin committed Jun 4, 2002
1 parent c888501 commit e13607280e7d913763a59469f12ee95d92b34f97
Showing with 66 additions and 20 deletions.
  1. +1 −1 course/{login.html → enrol.html}
  2. +2 −19 course/{login.php → enrol.php}
  3. +23 −0 course/lib.php
  4. +40 −0 course/unenrol.php
@@ -9,7 +9,7 @@
</tr>
<tr valign=top>
<td bgcolor="<?=$THEME->cellheading?>"> <CENTER><? formerr($errormsg) ?> </CENTER>
- <form name="form" method="post" action="login.php">
+ <form name="form" method="post" action="enrol.php">
<table>
<tr>
<td width=50% align=right><P>Entry Key:</P></td>
@@ -34,7 +34,7 @@
} 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)."\")";
}
}
@@ -68,26 +68,9 @@
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;
- }
-}
-
?>
View
@@ -280,4 +280,27 @@ function print_recent_activity($course) {
}
+
+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;
+ }
+}
+
?>
View
@@ -0,0 +1,40 @@
+<?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();
+
+
+?>

0 comments on commit e136072

Please sign in to comment.