Merge branch 'MDL-36754-master' of git://github.com/andrewnicols/moodle
[moodle.git] / enrol / paypal / return.php
blob6ee4f5e3166c4495b5062fec4d174aaeba76dd6b
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Paypal utility script
20 * @package enrol_paypal
21 * @copyright 2004 onwards Martin Dougiamas (http://dougiamas.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require("../../config.php");
26 require_once("$CFG->dirroot/enrol/paypal/lib.php");
28 $id = required_param('id', PARAM_INT);
30 if (!$course = $DB->get_record("course", array("id"=>$id))) {
31 redirect($CFG->wwwroot);
34 $context = context_course::instance($course->id, MUST_EXIST);
35 $PAGE->set_context($context);
37 require_login();
39 if (!empty($SESSION->wantsurl)) {
40 $destination = $SESSION->wantsurl;
41 unset($SESSION->wantsurl);
42 } else {
43 $destination = "$CFG->wwwroot/course/view.php?id=$course->id";
46 $fullname = format_string($course->fullname, true, array('context' => $context));
48 if (is_enrolled($context, NULL, '', true)) { // TODO: use real paypal check
49 redirect($destination, get_string('paymentthanks', '', $fullname));
51 } else { /// Somehow they aren't enrolled yet! :-(
52 $PAGE->set_url($destination);
53 echo $OUTPUT->header();
54 $a = new stdClass();
55 $a->teacher = get_string('defaultcourseteacher');
56 $a->fullname = $fullname;
57 notice(get_string('paymentsorry', '', $a), $destination);