Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/enrol/manual/editenrolment.php
Go to the documentation of this file.
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");
00031 require_once("$CFG->dirroot/enrol/renderer.php"); // Required for the course enrolment manager table
00032 require_once("$CFG->dirroot/enrol/manual/editenrolment_form.php");
00033 
00034 $ueid   = required_param('ue', PARAM_INT); // user enrolment id
00035 $filter = optional_param('ifilter', 0, PARAM_INT);
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 its not the front page course
00053 if ($course->id == SITEID) {
00054     redirect(new moodle_url('/'));
00055 }
00056 
00057 // Obviously
00058 require_login($course);
00059 // Make sure the user can manage manual enrolments for this course
00060 require_capability("enrol/manual: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/manual/editenrolment.php', $returnurl->params());
00075 
00076 $PAGE->set_url($url);
00077 $PAGE->set_pagelayout('admin');
00078 navigation_node::override_active_url($usersurl);
00079 
00080 list($instance, $plugin) = $manager->get_user_enrolment_components($ue);
00081 if (!$plugin->allow_manage($instance) || $instance->enrol != 'manual' || !($plugin instanceof enrol_manual_plugin)) {
00082     print_error('erroreditenrolment', 'enrol');
00083 }
00084 
00085 $mform = new enrol_manual_user_enrolment_form($url, array('user'=>$user, 'course'=>$course, 'ue'=>$ue));
00086 $mform->set_data($PAGE->url->params());
00087 
00088 // Check the form hasn't been cancelled
00089 if ($mform->is_cancelled()) {
00090     redirect($returnurl);
00091 } else if ($mform->is_submitted() && $mform->is_validated() && confirm_sesskey()) {
00092     // The forms been submit, validated and the sesskey has been checked ... edit the enrolment.
00093     $data = $mform->get_data();
00094     if ($manager->edit_enrolment($ue, $data)) {
00095         redirect($returnurl);
00096     }
00097 }
00098 
00099 $fullname = fullname($user);
00100 $title = get_string('editenrolment', 'enrol_manual');
00101 
00102 $PAGE->set_title($title);
00103 $PAGE->set_heading($title);
00104 $PAGE->navbar->add($title);
00105 $PAGE->navbar->add($fullname);
00106 
00107 echo $OUTPUT->header();
00108 echo $OUTPUT->heading($fullname);
00109 $mform->display();
00110 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations