6d2f4ce6db3f3b18bb01f90ce6b85c5ab92ce589
[moodle.git] / enrol / paypal / return.php
1 <?php
3     require("../../config.php");
4     require_once("$CFG->dirroot/enrol/paypal/enrol.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         notice(get_string('paymentsorry', '', get_string('defaultcourseteacher')), $destination);
35     }