moodle/course/enrol.php

101 lines
3.0 KiB
PHP
Raw Normal View History

2001-11-22 06:23:56 +00:00
<?PHP // $Id$
// Asks for a course pass key, once only, and enrols that user
2001-11-22 06:23:56 +00:00
require_once("../config.php");
require_once("lib.php");
2001-11-22 06:23:56 +00:00
require_variable($id);
require_login();
if (! $course = get_record("course", "id", $id) ) {
error("That's an invalid course id");
}
2001-11-22 06:23:56 +00:00
if ($form = data_submitted()) {
2001-11-22 06:23:56 +00:00
if ($form->password == $course->password) {
2001-11-22 06:23:56 +00:00
if (isguest()) {
add_to_log($course->id, "course", "guest", "view.php?id=$course->id", "$REMOTE_ADDR, $REMOTE_HOST");
} else if (!record_exists("user_students", "userid", $USER->id, "course", $course->id)) {
if (! enrol_student($USER->id, $course->id)) {
error("An error occurred while trying to enrol you.");
}
2002-07-19 12:01:35 +00:00
$subject = get_string("welcometocourse", "", $course->fullname);
2002-07-19 12:18:12 +00:00
$a->coursename = $course->fullname;
$a->profileurl = "$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id";
$message = get_string("welcometocoursetext", "", $a);
2002-07-19 12:01:35 +00:00
if (! $teacher = get_teacher($course->id)) {
$teacher = get_admin();
}
email_to_user($USER, $teacher, $subject, $message);
2002-07-19 12:01:35 +00:00
add_to_log($course->id, "course", "enrol", "view.php?id=$course->id", "$USER->id");
}
2001-11-22 06:23:56 +00:00
$USER->student["$id"] = true;
if ($SESSION->wantsurl) {
$destination = $SESSION->wantsurl;
unset($SESSION->wantsurl);
} else {
$destination = "$CFG->wwwroot/course/view.php?id=$id";
}
redirect($destination);
} else {
$errormsg = get_string("enrolmentkeyhint", "", substr($course->password,0,1));
2001-11-22 06:23:56 +00:00
}
}
if (! $site = get_site()) {
2001-11-22 06:23:56 +00:00
error("Could not find a site!");
}
if ($course->password == "") { // no password, so enrol
if (isguest()) {
add_to_log($course->id, "course", "guest", "view.php?id=$course->id", "$USER->id");
} else {
if (! enrol_student($USER->id, $course->id)) {
error("An error occurred while trying to enrol you.");
}
add_to_log($course->id, "course", "enrol", "view.php?id=$course->id", "$USER->id");
2001-11-22 06:23:56 +00:00
}
$USER->student["$id"] = true;
if ($SESSION->wantsurl) {
$destination = $SESSION->wantsurl;
unset($SESSION->wantsurl);
} else {
$destination = "$CFG->wwwroot/course/view.php?id=$id";
}
redirect($destination);
}
$teacher = get_teacher($course->id);
2002-08-04 02:10:00 +00:00
$strloginto = get_string("loginto", "", $course->shortname);
$strcourses = get_string("courses");
print_header($strloginto, $strloginto, "<A HREF=\".\">$strcourses</A> -> $strloginto", "form.password");
2001-11-22 06:23:56 +00:00
print_course($course);
include("enrol.html");
2001-11-22 06:23:56 +00:00
print_footer();
?>