Merge branch 'MDL-30175' of git://github.com/stronk7/moodle
[moodle.git] / enrol / paypal / return.php
bloba8a65570c4c86157c9d23c0535052d330e3e7bc9
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 utility script
21 * @package enrol
22 * @subpackage paypal
23 * @subpackage file
24 * @copyright 2004 onwards Martin Dougiamas (http://dougiamas.com)
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 require("../../config.php");
29 require_once("$CFG->dirroot/enrol/paypal/lib.php");
31 $id = required_param('id', PARAM_INT);
33 if (!$course = $DB->get_record("course", array("id"=>$id))) {
34 redirect($CFG->wwwroot);
37 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
39 require_login();
41 if ($SESSION->wantsurl) {
42 $destination = $SESSION->wantsurl;
43 unset($SESSION->wantsurl);
44 } else {
45 $destination = "$CFG->wwwroot/course/view.php?id=$course->id";
48 $fullname = format_string($course->fullname, true, array('context' => $context));
50 if (is_enrolled($context, NULL, '', true)) { // TODO: use real paypal check
51 redirect($destination, get_string('paymentthanks', '', $fullname));
53 } else { /// Somehow they aren't enrolled yet! :-(
54 $PAGE->set_url($destination);
55 echo $OUTPUT->header();
56 $a = new stdClass();
57 $a->teacher = get_string('defaultcourseteacher');
58 $a->fullname = $fullname;
59 notice(get_string('paymentsorry', '', $a), $destination);