2004-09-12 12:21:27 +00:00
|
|
|
<?php // $Id$
|
2004-06-25 03:31:20 +00:00
|
|
|
// Depending on the current enrolment method, this page
|
|
|
|
// presents the user with whatever they need to know when
|
|
|
|
// they try to enrol in a course.
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-01-05 14:19:20 +00:00
|
|
|
require_once("../config.php");
|
|
|
|
require_once("lib.php");
|
2004-06-25 03:31:20 +00:00
|
|
|
require_once("$CFG->dirroot/enrol/$CFG->enrol/enrol.php");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
require_variable($id);
|
|
|
|
|
2003-05-24 07:29:17 +00:00
|
|
|
require_login();
|
|
|
|
|
2002-05-31 09:34:50 +00:00
|
|
|
if (! $course = get_record("course", "id", $id) ) {
|
|
|
|
error("That's an invalid course id");
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-01-23 08:30:15 +00:00
|
|
|
if (! $site = get_site()) {
|
|
|
|
error("Could not find a site!");
|
|
|
|
}
|
|
|
|
|
2004-02-04 12:52:31 +00:00
|
|
|
check_for_restricted_user($USER->username);
|
2004-01-23 08:30:15 +00:00
|
|
|
|
2004-06-25 03:31:20 +00:00
|
|
|
$enrol = new enrolment_plugin();
|
|
|
|
|
2004-06-26 09:51:13 +00:00
|
|
|
/// Refreshing enrolment data in the USER session
|
|
|
|
$enrol->get_student_courses($USER);
|
|
|
|
$enrol->get_teacher_courses($USER);
|
|
|
|
|
|
|
|
|
|
|
|
/// Double check just in case they are actually enrolled already
|
|
|
|
/// This might occur if they were enrolled during this session
|
|
|
|
|
2004-07-29 13:12:35 +00:00
|
|
|
if ( !empty($USER->student[$course->id]) or !empty($USER->teacher[$course->id]) ) {
|
2004-06-26 09:51:13 +00:00
|
|
|
|
|
|
|
if ($SESSION->wantsurl) {
|
|
|
|
$destination = $SESSION->wantsurl;
|
|
|
|
unset($SESSION->wantsurl);
|
|
|
|
} else {
|
|
|
|
$destination = "$CFG->wwwroot/course/view.php?id=$course->id";
|
|
|
|
}
|
|
|
|
|
|
|
|
redirect($destination);
|
|
|
|
}
|
2004-08-22 14:38:47 +00:00
|
|
|
|
|
|
|
/// Users can't enroll to site course
|
|
|
|
if (!$course->category) {
|
|
|
|
print_header_simple();
|
|
|
|
notice(get_string('enrollfirst'), $CFG->wwwroot);
|
|
|
|
}
|
2004-06-26 09:51:13 +00:00
|
|
|
|
2004-07-29 13:12:35 +00:00
|
|
|
/// Double check just in case they are enrolled to start in the future
|
|
|
|
|
|
|
|
if ($student = get_record('user_students', 'userid', $USER->id, 'course', $course->id)) {
|
2004-09-09 09:43:51 +00:00
|
|
|
if ($course->enrolperiod and $student->timestart and ($student->timestart >= time())) {
|
|
|
|
$message = get_string('enrolmentnotyet', '', userdate($student->timestart));
|
|
|
|
print_header();
|
|
|
|
notice($message, $CFG->wwwroot);
|
|
|
|
}
|
2004-07-29 13:12:35 +00:00
|
|
|
}
|
2004-06-26 09:51:13 +00:00
|
|
|
|
2004-01-23 08:30:15 +00:00
|
|
|
/// Check the submitted enrollment key if there is one
|
|
|
|
|
2003-01-02 14:49:23 +00:00
|
|
|
if ($form = data_submitted()) {
|
2005-02-05 16:46:26 +00:00
|
|
|
//User is not enrolled in the course, wants to access course content
|
|
|
|
//as a guest, and course setting allow unlimited guest access
|
|
|
|
//Code cribbed from course/loginas.php
|
|
|
|
if (isset($loginasguest) && ($course->guest==1)) {
|
|
|
|
$realuser = $USER->id;
|
|
|
|
$realname = fullname($USER, true);
|
|
|
|
$USER = guest_user();
|
|
|
|
$USER->loggedin = true;
|
|
|
|
$USER->site = $CFG->wwwroot;
|
|
|
|
$USER->realuser = $realuser;
|
2005-02-19 21:02:33 +00:00
|
|
|
$USER->sessionIP = md5(getremoteaddr()); // Store the current IP in the session
|
|
|
|
if (isset($SESSION->currentgroup)) { // Remember current cache setting for later
|
|
|
|
$SESSION->oldcurrentgroup = $SESSION->currentgroup;
|
|
|
|
unset($SESSION->currentgroup);
|
|
|
|
}
|
2005-02-05 16:46:26 +00:00
|
|
|
$guest_name = fullname($USER, true);
|
|
|
|
add_to_log($course->id, "course", "loginas", "../user/view.php?id=$course->id&$USER->id$", "$realname -> $guest_name");
|
|
|
|
if ($SESSION->wantsurl) {
|
|
|
|
$destination = $SESSION->wantsurl;
|
|
|
|
unset($SESSION->wantsurl);
|
|
|
|
} else {
|
|
|
|
$destination = "$CFG->wwwroot/course/view.php?id=$course->id";
|
|
|
|
}
|
|
|
|
redirect($destination);
|
|
|
|
}
|
|
|
|
$enrol->check_entry($form, $course);
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2004-06-25 03:31:20 +00:00
|
|
|
$enrol->print_entry($course);
|
2004-01-23 08:30:15 +00:00
|
|
|
|
2004-06-25 03:31:20 +00:00
|
|
|
/// Easy!
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
?>
|