Merge branch 'w24_MDL-33635_m23_sort' of git://github.com/skodak/moodle
[moodle.git] / enrol / paypal / unenrolself.php
blob9984d586306babf30ceabc494bb49f78e9a4342c
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * PayPal enrolment plugin - support for user self unenrolment.
21 * @package enrol
22 * @subpackage paypal
23 * @copyright 2010 Petr Skoda {@link http://skodak.org}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require('../../config.php');
29 $enrolid = required_param('enrolid', PARAM_INT);
30 $confirm = optional_param('confirm', 0, PARAM_BOOL);
32 $instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'paypal'), '*', MUST_EXIST);
33 $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST);
34 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
36 require_login();
37 if (!is_enrolled($context)) {
38 redirect(new moodle_url('/'));
40 require_login($course);
42 $plugin = enrol_get_plugin('paypal');
44 // security defined inside following function
45 if (!$plugin->get_unenrolself_link($instance)) {
46 redirect(new moodle_url('/course/view.php', array('id'=>$course->id)));
49 $PAGE->set_url('/enrol/paypal/unenrolself.php', array('enrolid'=>$instance->id));
50 $PAGE->set_title($plugin->get_instance_name($instance));
52 if ($confirm and confirm_sesskey()) {
53 $plugin->unenrol_user($instance, $USER->id);
54 add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere!
55 redirect(new moodle_url('/index.php'));
58 echo $OUTPUT->header();
59 $yesurl = new moodle_url($PAGE->url, array('confirm'=>1, 'sesskey'=>sesskey()));
60 $nourl = new moodle_url('/course/view.php', array('id'=>$course->id));
61 $message = get_string('unenrolselfconfirm', 'enrol_paypal', format_string($course->fullname));
62 echo $OUTPUT->confirm($message, $yesurl, $nourl);
63 echo $OUTPUT->footer();