3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * This page shows all course enrolment options for current user.
23 * @copyright 2010 Petr Skoda {@link http://skodak.org}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require('../config.php');
28 require_once("$CFG->libdir/formslib.php");
30 $id = required_param('id', PARAM_INT
);
33 // do not use require_login here because we are usually coming from it,
34 // it would also mess up the SESSION->wantsurl
35 redirect(get_login_url());
38 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST
);
39 $context = get_context_instance(CONTEXT_COURSE
, $course->id
, MUST_EXIST
);
41 // Everybody is enrolled on the frontpage
42 if ($course->id
== SITEID
) {
43 redirect("$CFG->wwwroot/");
46 $PAGE->set_course($course);
47 $PAGE->set_pagelayout('course');
48 $PAGE->set_url('/enrol/index.php', array('id'=>$course->id
));
50 // do not allow enrols when in login-as session
51 if (session_is_loggedinas() and $USER->loginascontext
->contextlevel
== CONTEXT_COURSE
) {
52 print_error('loginasnoenrol', '', $CFG->wwwroot
.'/course/view.php?id='.$USER->loginascontext
->instanceid
);
55 // get all enrol forms available in this course
56 $enrols = enrol_get_plugins(true);
57 $enrolinstances = enrol_get_instances($course->id
, true);
59 foreach($enrolinstances as $instance) {
60 if (!isset($enrols[$instance->enrol
])) {
63 $form = $enrols[$instance->enrol
]->enrol_page_hook($instance);
65 $forms[$instance->id
] = $form;
69 // Check if user already enrolled
70 if (is_enrolled($context, $USER, '', true)) {
71 if (!empty($SESSION->wantsurl
)) {
72 $destination = $SESSION->wantsurl
;
73 unset($SESSION->wantsurl
);
75 $destination = "$CFG->wwwroot/course/view.php?id=$course->id";
77 redirect($destination); // Bye!
80 $PAGE->set_title($course->shortname
);
81 $PAGE->set_heading($course->fullname
);
82 $PAGE->navbar
->add(get_string('enrolmentoptions','enrol'));
84 echo $OUTPUT->header();
86 //TODO: find if future enrolments present and display some info
88 foreach ($forms as $form) {
94 notice(get_string('noguestaccess', 'enrol'), get_login_url());
96 notice(get_string('notenrollable', 'enrol'), "$CFG->wwwroot/index.php");
100 echo $OUTPUT->footer();