|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00029 require('../../config.php'); 00030 require_once("$CFG->dirroot/enrol/locallib.php"); // Required for the course enrolment manager 00031 require_once("$CFG->dirroot/enrol/renderer.php"); // Required for the course enrolment users table 00032 require_once("$CFG->dirroot/enrol/self/editenrolment_form.php"); // Forms for this page 00033 00034 $ueid = required_param('ue', PARAM_INT); // user enrolment id 00035 $filter = optional_param('ifilter', 0, PARAM_INT); // table filter for return url 00036 00037 // Get the user enrolment object 00038 $ue = $DB->get_record('user_enrolments', array('id' => $ueid), '*', MUST_EXIST); 00039 // Get the user for whom the enrolment is 00040 $user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST); 00041 // Get the course the enrolment is to 00042 list($ctxsql, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); 00043 $sql = "SELECT c.* $ctxsql 00044 FROM {course} c 00045 LEFT JOIN {enrol} e ON e.courseid = c.id 00046 $ctxjoin 00047 WHERE e.id = :enrolid"; 00048 $params = array('enrolid' => $ue->enrolid); 00049 $course = $DB->get_record_sql($sql, $params, MUST_EXIST); 00050 context_instance_preload($course); 00051 00052 // Make sure the course isn't the front page 00053 if ($course->id == SITEID) { 00054 redirect(new moodle_url('/')); 00055 } 00056 00057 // Obvioulsy 00058 require_login($course); 00059 // The user must be able to manage self enrolments within the course 00060 require_capability("enrol/self:manage", get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST)); 00061 00062 // Get the enrolment manager for this course 00063 $manager = new course_enrolment_manager($PAGE, $course, $filter); 00064 // Get an enrolment users table object. Doign this will automatically retrieve the the URL params 00065 // relating to table the user was viewing before coming here, and allows us to return the user to the 00066 // exact page of the users screen they can from. 00067 $table = new course_enrolment_users_table($manager, $PAGE); 00068 00069 // The URL of the enrolled users page for the course. 00070 $usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id)); 00071 // The URl to return the user too after this screen. 00072 $returnurl = new moodle_url($usersurl, $manager->get_url_params()+$table->get_url_params()); 00073 // The URL of this page 00074 $url = new moodle_url('/enrol/self/editenrolment.php', $returnurl->params()); 00075 00076 $PAGE->set_url($url); 00077 $PAGE->set_pagelayout('admin'); 00078 navigation_node::override_active_url($usersurl); 00079 00080 // Gets the compontents of the user enrolment 00081 list($instance, $plugin) = $manager->get_user_enrolment_components($ue); 00082 // Check that the user can manage this instance, and that the instance is of the correct type 00083 if (!$plugin->allow_manage($instance) || $instance->enrol != 'self' || !($plugin instanceof enrol_self_plugin)) { 00084 print_error('erroreditenrolment', 'enrol'); 00085 } 00086 00087 // Get the self enrolment edit form 00088 $mform = new enrol_self_user_enrolment_form($url, array('user'=>$user, 'course'=>$course, 'ue'=>$ue)); 00089 $mform->set_data($PAGE->url->params()); 00090 00091 // Check the form hasn't been cancelled 00092 if ($mform->is_cancelled()) { 00093 redirect($returnurl); 00094 } else if ($mform->is_submitted() && $mform->is_validated() && confirm_sesskey()) { 00095 // The forms been submit, validated and the sesskey has been checked ... edit the enrolment. 00096 $data = $mform->get_data(); 00097 if ($manager->edit_enrolment($ue, $data)) { 00098 redirect($returnurl); 00099 } 00100 } 00101 00102 $fullname = fullname($user); 00103 $title = get_string('editenrolment', 'enrol_self'); 00104 00105 $PAGE->set_title($title); 00106 $PAGE->set_heading($title); 00107 $PAGE->navbar->add($title); 00108 $PAGE->navbar->add($fullname); 00109 00110 echo $OUTPUT->header(); 00111 echo $OUTPUT->heading($fullname); 00112 $mform->display(); 00113 echo $OUTPUT->footer();