2004-09-12 12:21:27 +00:00
|
|
|
<?php // $Id$
|
2007-08-17 19:09:11 +00:00
|
|
|
// Depending on the current enrolment method, this page
|
|
|
|
// presents the user with whatever they need to know when
|
2004-06-25 03:31:20 +00:00
|
|
|
// 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");
|
2006-03-09 02:48:29 +00:00
|
|
|
require_once("$CFG->dirroot/enrol/enrol.class.php");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2006-05-21 20:51:52 +00:00
|
|
|
$id = required_param('id', PARAM_INT);
|
2006-12-18 19:21:10 +00:00
|
|
|
$loginasguest = optional_param('loginasguest', 0, PARAM_BOOL); // hmm, is this still needed?
|
|
|
|
|
|
|
|
if (!isloggedin()) {
|
|
|
|
$wwwroot = $CFG->wwwroot;
|
|
|
|
if (!empty($CFG->loginhttps)) {
|
|
|
|
$wwwroot = str_replace('http:','https:', $wwwroot);
|
|
|
|
}
|
2007-08-17 19:09:11 +00:00
|
|
|
// do not use require_login here because we are usually comming from it
|
2006-12-18 19:21:10 +00:00
|
|
|
redirect($wwwroot.'/login/index.php');
|
2006-10-24 02:13:42 +00:00
|
|
|
}
|
|
|
|
|
2006-09-16 13:59:38 +00:00
|
|
|
if (! $course = get_record('course', 'id', $id) ) {
|
2002-05-31 09:34:50 +00:00
|
|
|
error("That's an invalid course id");
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2006-09-16 13:59:38 +00:00
|
|
|
if (! $context = get_context_instance(CONTEXT_COURSE, $course->id) ) {
|
|
|
|
error("That's an invalid course id");
|
2004-01-23 08:30:15 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 07:42:41 +00:00
|
|
|
/// do not use when in course login as
|
|
|
|
if (!empty($USER->realuser) and $USER->loginascontext->contextlevel == CONTEXT_COURSE) {
|
|
|
|
print_error('loginasnoenrol', '', $CFG->wwwroot.'/course/view.php?id='.$USER->loginascontext->instanceid);
|
|
|
|
}
|
|
|
|
|
2007-08-17 19:09:11 +00:00
|
|
|
$enrol = enrolment_factory::factory($course->enrol); // do not use if (!$enrol... here, it can not work in PHP4 - see MDL-7529
|
2004-06-26 09:51:13 +00:00
|
|
|
|
2006-09-16 13:59:38 +00:00
|
|
|
/// Refreshing all current role assignments for the current user
|
2004-06-26 09:51:13 +00:00
|
|
|
|
2006-10-23 15:17:31 +00:00
|
|
|
load_all_capabilities();
|
2004-06-26 09:51:13 +00:00
|
|
|
|
2007-08-17 19:09:11 +00:00
|
|
|
/// Double check just in case they are actually enrolled already and
|
|
|
|
/// thus got to this script by mistake. This might occur if enrolments
|
2006-09-16 13:59:38 +00:00
|
|
|
/// changed during this session or something
|
2004-06-26 09:51:13 +00:00
|
|
|
|
2006-12-18 19:21:10 +00:00
|
|
|
if (has_capability('moodle/course:view', $context) and !has_capability('moodle/legacy:guest', $context, NULL, false)) {
|
2008-03-03 05:28:56 +00:00
|
|
|
if (!empty($SESSION->wantsurl)) {
|
2004-06-26 09:51:13 +00:00
|
|
|
$destination = $SESSION->wantsurl;
|
|
|
|
unset($SESSION->wantsurl);
|
|
|
|
} else {
|
|
|
|
$destination = "$CFG->wwwroot/course/view.php?id=$course->id";
|
|
|
|
}
|
2006-09-16 13:59:38 +00:00
|
|
|
redirect($destination); // Bye!
|
2004-06-26 09:51:13 +00:00
|
|
|
}
|
2006-06-06 19:01:46 +00:00
|
|
|
|
2006-09-16 13:59:38 +00:00
|
|
|
/// Check if the course is a meta course (bug 5734)
|
2006-06-06 19:01:46 +00:00
|
|
|
if ($course->metacourse) {
|
|
|
|
print_header_simple();
|
2006-08-24 02:08:59 +00:00
|
|
|
notice(get_string('coursenotaccessible'), "$CFG->wwwroot/index.php");
|
2006-06-06 19:01:46 +00:00
|
|
|
}
|
2007-08-17 19:09:11 +00:00
|
|
|
|
2004-08-22 14:38:47 +00:00
|
|
|
/// Users can't enroll to site course
|
2006-09-16 13:59:38 +00:00
|
|
|
if ($course->id == SITEID) {
|
2004-08-22 14:38:47 +00:00
|
|
|
print_header_simple();
|
2006-08-24 02:08:59 +00:00
|
|
|
notice(get_string('enrollfirst'), "$CFG->wwwroot/index.php");
|
2004-08-22 14:38:47 +00:00
|
|
|
}
|
2004-06-26 09:51:13 +00:00
|
|
|
|
2007-08-17 19:09:11 +00:00
|
|
|
/// Double check just in case they are enrolled to start in the future
|
2004-07-29 13:12:35 +00:00
|
|
|
|
2006-09-16 13:59:38 +00:00
|
|
|
if ($course->enrolperiod) { // Only active if the course has an enrolment period in effect
|
|
|
|
if ($roles = get_user_roles($context, $USER->id)) {
|
|
|
|
foreach ($roles as $role) {
|
|
|
|
if ($role->timestart and ($role->timestart >= time())) {
|
|
|
|
$message = get_string('enrolmentnotyet', '', userdate($student->timestart));
|
|
|
|
print_header();
|
|
|
|
notice($message, "$CFG->wwwroot/index.php");
|
|
|
|
}
|
|
|
|
}
|
2004-09-09 09:43:51 +00:00
|
|
|
}
|
2004-07-29 13:12:35 +00:00
|
|
|
}
|
2004-06-26 09:51:13 +00:00
|
|
|
|
2005-10-04 01:59:19 +00:00
|
|
|
/// Check if the course is enrollable
|
2006-03-09 02:48:29 +00:00
|
|
|
if (!method_exists($enrol, 'print_entry')) {
|
|
|
|
print_header_simple();
|
2006-08-24 02:08:59 +00:00
|
|
|
notice(get_string('enrolmentnointernal'), "$CFG->wwwroot/index.php");
|
2006-03-09 02:48:29 +00:00
|
|
|
}
|
|
|
|
|
2005-10-04 01:59:19 +00:00
|
|
|
if (!$course->enrollable ||
|
|
|
|
($course->enrollable == 2 && $course->enrolstartdate > 0 && $course->enrolstartdate > time()) ||
|
|
|
|
($course->enrollable == 2 && $course->enrolenddate > 0 && $course->enrolenddate <= time())
|
|
|
|
) {
|
2007-08-17 19:09:11 +00:00
|
|
|
print_header($course->shortname, $course->fullname, build_navigation(array(array('name'=>$course->shortname,'link'=>'','type'=>'misc'))) );
|
2006-08-24 02:08:59 +00:00
|
|
|
notice(get_string('notenrollable'), "$CFG->wwwroot/index.php");
|
2005-10-04 01:59:19 +00:00
|
|
|
}
|
|
|
|
|
2006-09-16 13:59:38 +00:00
|
|
|
/// Check the submitted enrolment information if there is any (eg could be enrolment key)
|
2004-01-23 08:30:15 +00:00
|
|
|
|
2003-01-02 14:49:23 +00:00
|
|
|
if ($form = data_submitted()) {
|
2006-09-16 13:59:38 +00:00
|
|
|
$enrol->check_entry($form, $course); // Should terminate/redirect in here if it's all OK
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2006-09-16 13:59:38 +00:00
|
|
|
/// Otherwise, we print the entry form.
|
|
|
|
|
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
|
|
|
|
|
|
|
?>
|