Skip to content

Commit

Permalink
Cleaned up enrol and unenrol process a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
martin committed Jun 4, 2002
1 parent c888501 commit e136072
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 20 deletions.
2 changes: 1 addition & 1 deletion course/login.html → course/enrol.html
Expand Up @@ -9,7 +9,7 @@
</tr> </tr>
<tr valign=top> <tr valign=top>
<td bgcolor="<?=$THEME->cellheading?>"> <CENTER><? formerr($errormsg) ?> </CENTER> <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> <table>
<tr> <tr>
<td width=50% align=right><P>Entry Key:</P></td> <td width=50% align=right><P>Entry Key:</P></td>
Expand Down
21 changes: 2 additions & 19 deletions course/login.php → course/enrol.php
Expand Up @@ -34,7 +34,7 @@


} else { } else {
$errormsg = "That entry key was incorrect, please try again". $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)."\")";
} }
} }


Expand Down Expand Up @@ -68,26 +68,9 @@


print_course($course); print_course($course);


include("login.html"); include("enrol.html");


print_footer(); 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;
}
}

?> ?>
23 changes: 23 additions & 0 deletions course/lib.php
Expand Up @@ -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;
}
}

?> ?>
40 changes: 40 additions & 0 deletions course/unenrol.php
@@ -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.