Cleaned up enrol and unenrol process a bit
authormartin <martin>
Tue, 4 Jun 2002 06:30:51 +0000 (06:30 +0000)
committermartin <martin>
Tue, 4 Jun 2002 06:30:51 +0000 (06:30 +0000)
course/enrol.html [moved from course/login.html with 92% similarity]
course/enrol.php [moved from course/login.php with 83% similarity]
course/lib.php
course/unenrol.php [new file with mode: 0644]

similarity index 92%
rename from course/login.html
rename to course/enrol.html
index 47d6083..56bea06 100644 (file)
@@ -9,7 +9,7 @@
   </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
similarity index 83%
rename from course/login.php
rename to course/enrol.php
index 4bb5277..f816cc1 100644 (file)
@@ -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)."\")";
         }
     }
 
 
     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;
-       }
-}
-
 ?>
index 3c20221..863ec1b 100644 (file)
@@ -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 (file)
index 0000000..58f3029
--- /dev/null
@@ -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();
+
+
+?>