MDL-22788 upgrade enrol/paypal plugin to use enrolments
[moodle.git] / enrol / paypal / return.php
1 <?php
3     require("../../config.php");
4     require_once("$CFG->dirroot/enrol/paypal/lib.php");
6     $id = required_param('id', PARAM_INT);
8     if (!$course = $DB->get_record("course", array("id"=>$id))) {
9         redirect($CFG->wwwroot);
10     }
12     if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) {
13         redirect($CFG->wwwroot);
14     }
16     require_login();
18 /// Refreshing enrolment data in the USER session
19     load_all_capabilities();
21     if ($SESSION->wantsurl) {
22         $destination = $SESSION->wantsurl;
23         unset($SESSION->wantsurl);
24     } else {
25         $destination = "$CFG->wwwroot/course/view.php?id=$course->id";
26     }
28     if (is_enrolled($context, NULL, '', true)) { // TODO: use real paypal check
29         redirect($destination, get_string('paymentthanks', '', $course->fullname));
31     } else {   /// Somehow they aren't enrolled yet!  :-(
32         $PAGE->set_url($destination);
33         echo $OUTPUT->header();
34         $a = new stdClass();
35         $a->teacher = get_string('defaultcourseteacher');
36         $a->fullname = format_string($course->fullname);
37         notice(get_string('paymentsorry', '', $a), $destination);
38     }