MDL-31410 paypal: fix problem on notifications
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Thu, 12 Dec 2013 01:03:41 +0000 (02:03 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Thu, 12 Dec 2013 01:27:53 +0000 (02:27 +0100)
This commit fixes a PHP warning about using a
unititialised variable and also the problems when
notifications are enabled and there is not yet a
teacher in the course, defaulting to admin for student
notifications and preventing teacher notifications to happen.

enrol/paypal/ipn.php

index 58b7893..e6d6582 100644 (file)
@@ -243,6 +243,7 @@ if (strlen($result) > 0) {
 
 
         if (!empty($mailstudents)) {
+            $a = new stdClass();
             $a->coursename = format_string($course->fullname, true, array('context' => $coursecontext));
             $a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id";
 
@@ -250,7 +251,7 @@ if (strlen($result) > 0) {
             $eventdata->modulename        = 'moodle';
             $eventdata->component         = 'enrol_paypal';
             $eventdata->name              = 'paypal_enrolment';
-            $eventdata->userfrom          = $teacher;
+            $eventdata->userfrom          = empty($teacher) ? get_admin() : $teacher;
             $eventdata->userto            = $user;
             $eventdata->subject           = get_string("enrolmentnew", 'enrol', $shortname);
             $eventdata->fullmessage       = get_string('welcometocoursetext', '', $a);
@@ -261,7 +262,7 @@ if (strlen($result) > 0) {
 
         }
 
-        if (!empty($mailteachers)) {
+        if (!empty($mailteachers) && !empty($teacher)) {
             $a->course = format_string($course->fullname, true, array('context' => $coursecontext));
             $a->user = fullname($user);