MDL-21437 data - checkbox and multimenu fields search working + require all too
[moodle.git] / enrol / index.php
CommitLineData
df997f84
PS
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
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.
9//
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.
14//
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/>.
17
18/**
19 * This page shows all course enrolment options for current user.
20 *
21 * @package core
5379726a 22 * @subpackage enrol
df997f84
PS
23 * @copyright 2010 Petr Skoda {@link http://skodak.org}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
27require('../config.php');
28require_once("$CFG->libdir/formslib.php");
29
30$id = required_param('id', PARAM_INT);
31
32if (!isloggedin()) {
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());
36}
37
38$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
39$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
40
41// Everybody is enrolled on the frontpage
42if ($course->id == SITEID) {
43 redirect("$CFG->wwwroot/");
44}
45
b0060fe5
SH
46$PAGE->set_course($course);
47$PAGE->set_pagelayout('course');
df997f84
PS
48$PAGE->set_url('/enrol/index.php', array('id'=>$course->id));
49
50// do not allow enrols when in login-as session
51if (session_is_loggedinas() and $USER->loginascontext->contextlevel == CONTEXT_COURSE) {
52 print_error('loginasnoenrol', '', $CFG->wwwroot.'/course/view.php?id='.$USER->loginascontext->instanceid);
53}
54
55// get all enrol forms available in this course
56$enrols = enrol_get_plugins(true);
57$enrolinstances = enrol_get_instances($course->id, true);
58$forms = array();
59foreach($enrolinstances as $instance) {
60 if (!isset($enrols[$instance->enrol])) {
61 continue;
62 }
63 $form = $enrols[$instance->enrol]->enrol_page_hook($instance);
64 if ($form) {
65 $forms[$instance->id] = $form;
66 }
67}
68
69// Check if user already enrolled
70if (is_enrolled($context, $USER, '', true)) {
71 if (!empty($SESSION->wantsurl)) {
72 $destination = $SESSION->wantsurl;
73 unset($SESSION->wantsurl);
74 } else {
75 $destination = "$CFG->wwwroot/course/view.php?id=$course->id";
76 }
77 redirect($destination); // Bye!
78}
79
80$PAGE->set_title($course->shortname);
81$PAGE->set_heading($course->fullname);
b0060fe5 82$PAGE->navbar->add(get_string('enrolmentoptions','enrol'));
df997f84
PS
83
84echo $OUTPUT->header();
85
86//TODO: find if future enrolments present and display some info
87
88foreach ($forms as $form) {
89 echo $form;
90}
91
92if (!$forms) {
93 if (isguestuser()) {
94 notice(get_string('noguestaccess', 'enrol'), get_login_url());
95 } else {
96 notice(get_string('notenrollable', 'enrol'), "$CFG->wwwroot/index.php");
97 }
98}
99
100echo $OUTPUT->footer();