Merge branch 'w27_MDL-39754_m23_evn26' of https://github.com/skodak/moodle into MOODL...
[moodle.git] / enrol / index.php
blob14e7da2d420bdff8b6d06ee5f016c978cb6bba3c
1 <?php
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.
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/>.
18 /**
19 * This page shows all course enrolment options for current user.
21 * @package core
22 * @subpackage enrol
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);
32 if (!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());
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);
58 $forms = array();
59 foreach($enrolinstances as $instance) {
60 if (!isset($enrols[$instance->enrol])) {
61 continue;
63 $form = $enrols[$instance->enrol]->enrol_page_hook($instance);
64 if ($form) {
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);
74 } else {
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();
85 echo $OUTPUT->heading(get_string('enrolmentoptions','enrol'));
87 echo $OUTPUT->box_start('generalbox info');
89 $summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', null);
90 echo format_text($summary, $course->summaryformat, array('overflowdiv'=>true), $course->id);
91 if (!empty($CFG->coursecontact)) {
92 $coursecontactroles = explode(',', $CFG->coursecontact);
93 foreach ($coursecontactroles as $roleid) {
94 $role = $DB->get_record('role', array('id'=>$roleid));
95 $roleid = (int) $roleid;
96 if ($users = get_role_users($roleid, $context, true)) {
97 foreach ($users as $teacher) {
98 $fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', $context));
99 $namesarray[] = format_string(role_get_name($role, $context)).': <a href="'.$CFG->wwwroot.'/user/view.php?id='.
100 $teacher->id.'&amp;course='.SITEID.'">'.$fullname.'</a>';
105 if (!empty($namesarray)) {
106 echo "<ul class=\"teachers\">\n<li>";
107 echo implode('</li><li>', $namesarray);
108 echo "</li></ul>";
112 echo $OUTPUT->box_end();
115 //TODO: find if future enrolments present and display some info
117 foreach ($forms as $form) {
118 echo $form;
121 if (!$forms) {
122 if (isguestuser()) {
123 notice(get_string('noguestaccess', 'enrol'), get_login_url());
124 } else {
125 notice(get_string('notenrollable', 'enrol'), "$CFG->wwwroot/index.php");
129 echo $OUTPUT->footer();