|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 require('../config.php'); 00028 require_once("$CFG->libdir/formslib.php"); 00029 00030 $id = required_param('id', PARAM_INT); 00031 00032 if (!isloggedin()) { 00033 // do not use require_login here because we are usually coming from it, 00034 // it would also mess up the SESSION->wantsurl 00035 redirect(get_login_url()); 00036 } 00037 00038 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); 00039 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); 00040 00041 // Everybody is enrolled on the frontpage 00042 if ($course->id == SITEID) { 00043 redirect("$CFG->wwwroot/"); 00044 } 00045 00046 $PAGE->set_course($course); 00047 $PAGE->set_pagelayout('course'); 00048 $PAGE->set_url('/enrol/index.php', array('id'=>$course->id)); 00049 00050 // do not allow enrols when in login-as session 00051 if (session_is_loggedinas() and $USER->loginascontext->contextlevel == CONTEXT_COURSE) { 00052 print_error('loginasnoenrol', '', $CFG->wwwroot.'/course/view.php?id='.$USER->loginascontext->instanceid); 00053 } 00054 00055 // get all enrol forms available in this course 00056 $enrols = enrol_get_plugins(true); 00057 $enrolinstances = enrol_get_instances($course->id, true); 00058 $forms = array(); 00059 foreach($enrolinstances as $instance) { 00060 if (!isset($enrols[$instance->enrol])) { 00061 continue; 00062 } 00063 $form = $enrols[$instance->enrol]->enrol_page_hook($instance); 00064 if ($form) { 00065 $forms[$instance->id] = $form; 00066 } 00067 } 00068 00069 // Check if user already enrolled 00070 if (is_enrolled($context, $USER, '', true)) { 00071 if (!empty($SESSION->wantsurl)) { 00072 $destination = $SESSION->wantsurl; 00073 unset($SESSION->wantsurl); 00074 } else { 00075 $destination = "$CFG->wwwroot/course/view.php?id=$course->id"; 00076 } 00077 redirect($destination); // Bye! 00078 } 00079 00080 $PAGE->set_title($course->shortname); 00081 $PAGE->set_heading($course->fullname); 00082 $PAGE->navbar->add(get_string('enrolmentoptions','enrol')); 00083 00084 echo $OUTPUT->header(); 00085 echo $OUTPUT->heading(get_string('enrolmentoptions','enrol')); 00086 00087 //TODO: find if future enrolments present and display some info 00088 00089 foreach ($forms as $form) { 00090 echo $form; 00091 } 00092 00093 if (!$forms) { 00094 if (isguestuser()) { 00095 notice(get_string('noguestaccess', 'enrol'), get_login_url()); 00096 } else { 00097 notice(get_string('notenrollable', 'enrol'), "$CFG->wwwroot/index.php"); 00098 } 00099 } 00100 00101 echo $OUTPUT->footer();