3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * Paypal utility script
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
);
41 if ($SESSION->wantsurl
) {
42 $destination = $SESSION->wantsurl
;
43 unset($SESSION->wantsurl
);
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();
57 $a->teacher
= get_string('defaultcourseteacher');
58 $a->fullname
= $fullname;
59 notice(get_string('paymentsorry', '', $a), $destination);