Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/enrol/manual/unenrolself.php
Go to the documentation of this file.
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 
00029 $enrolid = required_param('enrolid', PARAM_INT);
00030 $confirm = optional_param('confirm', 0, PARAM_BOOL);
00031 
00032 $instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'manual'), '*', MUST_EXIST);
00033 $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST);
00034 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
00035 
00036 require_login();
00037 if (!is_enrolled($context)) {
00038     redirect(new moodle_url('/'));
00039 }
00040 require_login($course);
00041 
00042 $plugin = enrol_get_plugin('manual');
00043 
00044 // security defined inside following function
00045 if (!$plugin->get_unenrolself_link($instance)) {
00046     redirect(new moodle_url('/course/view.php', array('id'=>$course->id)));
00047 }
00048 
00049 $PAGE->set_url('/enrol/manual/unenrolself.php', array('enrolid'=>$instance->id));
00050 $PAGE->set_title($plugin->get_instance_name($instance));
00051 
00052 if ($confirm and confirm_sesskey()) {
00053     $plugin->unenrol_user($instance, $USER->id);
00054     add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere!
00055     redirect(new moodle_url('/index.php'));
00056 }
00057 
00058 echo $OUTPUT->header();
00059 $yesurl = new moodle_url($PAGE->url, array('confirm'=>1, 'sesskey'=>sesskey()));
00060 $nourl = new moodle_url('/course/view.php', array('id'=>$course->id));
00061 $message = get_string('unenrolselfconfirm', 'enrol_manual', format_string($course->fullname));
00062 echo $OUTPUT->confirm($message, $yesurl, $nourl);
00063 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations