From e13607280e7d913763a59469f12ee95d92b34f97 Mon Sep 17 00:00:00 2001 From: martin Date: Tue, 4 Jun 2002 06:30:51 +0000 Subject: [PATCH] Cleaned up enrol and unenrol process a bit --- course/{login.html => enrol.html} | 2 +- course/{login.php => enrol.php} | 21 ++-------------- course/lib.php | 23 ++++++++++++++++++ course/unenrol.php | 40 +++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 20 deletions(-) rename course/{login.html => enrol.html} (92%) rename course/{login.php => enrol.php} (83%) create mode 100644 course/unenrol.php diff --git a/course/login.html b/course/enrol.html similarity index 92% rename from course/login.html rename to course/enrol.html index 47d6083d35a1a..56bea0685e513 100644 --- a/course/login.html +++ b/course/enrol.html @@ -9,7 +9,7 @@
-
+ diff --git a/course/login.php b/course/enrol.php similarity index 83% rename from course/login.php rename to course/enrol.php index 4bb527755dd74..f816cc1d230f7 100644 --- a/course/login.php +++ b/course/enrol.php @@ -34,7 +34,7 @@ } else { $errormsg = "That entry key was incorrect, please try again". - "
(Here's a hint - it starts with \"".substr($actual_password,0,1)."\")"; + "
(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; - } -} - ?> diff --git a/course/lib.php b/course/lib.php index 3c20221f986fa..863ec1b9029c6 100644 --- a/course/lib.php +++ b/course/lib.php @@ -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; + } +} + ?> diff --git a/course/unenrol.php b/course/unenrol.php new file mode 100644 index 0000000000000..58f3029ff24e9 --- /dev/null +++ b/course/unenrol.php @@ -0,0 +1,40 @@ +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", "wwwroot/course/view.php?id=$course->id\">$course->shortname -> Unenrol"); + + notice_yesno ("Are you sure you want to remove yourself from this course?", + "unenrol.php?id=$id&confirm=yes", + "$HTTP_REFERER"); + + print_footer(); + + +?>

Entry Key: