Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/enrol/unenroluser.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");
00032 
00033 $ueid    = required_param('ue', PARAM_INT); // user enrolment id
00034 $confirm = optional_param('confirm', false, PARAM_BOOL);
00035 $filter  = optional_param('ifilter', 0, PARAM_INT);
00036 
00037 $ue = $DB->get_record('user_enrolments', array('id' => $ueid), '*', MUST_EXIST);
00038 $user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST);
00039 $instance = $DB->get_record('enrol', array('id'=>$ue->enrolid), '*', MUST_EXIST);
00040 $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST);
00041 
00042 $context = context_course::instance($course->id);
00043 
00044 // set up PAGE url first!
00045 $PAGE->set_url('/enrol/unenroluser.php', array('ue'=>$ueid, 'ifilter'=>$filter));
00046 
00047 require_login($course);
00048 
00049 if (!enrol_is_enabled($instance->enrol)) {
00050     print_error('erroreditenrolment', 'enrol');
00051 }
00052 
00053 $plugin = enrol_get_plugin($instance->enrol);
00054 
00055 if (!$plugin->allow_unenrol_user($instance, $ue) or !has_capability("enrol/$instance->enrol:unenrol", $context)) {
00056     print_error('erroreditenrolment', 'enrol');
00057 }
00058 
00059 $manager = new course_enrolment_manager($PAGE, $course, $filter);
00060 $table = new course_enrolment_users_table($manager, $PAGE);
00061 
00062 $returnurl = new moodle_url('/enrol/users.php', array('id' => $course->id)+$manager->get_url_params()+$table->get_url_params());
00063 $usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id));
00064 
00065 $PAGE->set_pagelayout('admin');
00066 navigation_node::override_active_url($usersurl);
00067 
00068 // If the unenrolment has been confirmed and the sesskey is valid unenrol the user.
00069 if ($confirm && confirm_sesskey()) {
00070     $plugin->unenrol_user($instance, $ue->userid);
00071     redirect($returnurl);
00072 }
00073 
00074 $yesurl = new moodle_url($PAGE->url, array('confirm'=>1, 'sesskey'=>sesskey()));
00075 $message = get_string('unenrolconfirm', 'core_enrol', array('user'=>fullname($user, true), 'course'=>format_string($course->fullname)));
00076 $fullname = fullname($user);
00077 $title = get_string('unenrol', 'core_enrol');
00078 
00079 $PAGE->set_title($title);
00080 $PAGE->set_heading($title);
00081 $PAGE->navbar->add($title);
00082 $PAGE->navbar->add($fullname);
00083 
00084 echo $OUTPUT->header();
00085 echo $OUTPUT->heading($fullname);
00086 echo $OUTPUT->confirm($message, $yesurl, $returnurl);
00087 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations