From d77f39b26248196a1810f5adf7f831b3b4739cf8 Mon Sep 17 00:00:00 2001
From: fs959857 <fs959857@ITC18143.win.rz.rwth-aachen.de>
Date: Wed, 8 Apr 2020 10:26:34 +0200
Subject: [PATCH] bugfix notifications: correct userid in link to settings

---
 controller.php          | 4 ++--
 locallib.php            | 6 +++---
 model/comment.class.php | 4 ++--
 version.php             | 2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/controller.php b/controller.php
index e39c140..9f76319 100644
--- a/controller.php
+++ b/controller.php
@@ -498,11 +498,11 @@ if ($action === 'report') {
         $report->reportinguser = fullname($USER);
         $report->url = $CFG->wwwroot . '/mod/pdfannotator/view.php?id=' . $cm->id . '&action=overviewreports';
         $messagetext = new stdClass();
-        $messagetext->text = pdfannotator_format_notification_message_text($course, $cm, $context, get_string('modulename', 'pdfannotator'), $cm->name, $report, 'reportadded');
-        $messagetext->html = pdfannotator_format_notification_message_html($course, $cm, $context, get_string('modulename', 'pdfannotator'), $cm->name, $report, 'reportadded');
+        $messagetext->text = pdfannotator_format_notification_message_text($course, $cm, $context, get_string('modulename', 'pdfannotator'), $cm->name, $report, 'reportadded');      
         $messagetext->url = $report->url;
         try {
             foreach ($recipients as $recipient) {
+                $messagetext->html = pdfannotator_format_notification_message_html($course, $cm, $context, get_string('modulename', 'pdfannotator'), $cm->name, $report, 'reportadded', $recipient->id);
                 $messageid = pdfannotator_notify_manager($recipient, $course, $cm, $name, $messagetext);
             }
             // 2. Notify the reporting user that their report has been sent off (display blue toast box at top of page).
diff --git a/locallib.php b/locallib.php
index 3a2e921..b1d8635 100644
--- a/locallib.php
+++ b/locallib.php
@@ -260,10 +260,10 @@ function pdfannotator_send_forward_message($recipients, $messageparams, $course,
     $text = new stdClass();
     $module = get_string('modulename', 'pdfannotator');
     $text->text = pdfannotator_format_notification_message_text($course, $cm, $context, $module, $cm->name, $messageparams, $name);
-    $text->html = pdfannotator_format_notification_message_html($course, $cm, $context, $module, $cm->name, $messageparams, $name);
     $text->url = $messageparams->urltoquestion;
 
     foreach ($recipients as $recipient) {
+        $text->html = pdfannotator_format_notification_message_html($course, $cm, $context, $module, $cm->name, $messageparams, $name, $recipient);
         pdfannotator_notify_manager($recipient, $course, $cm, $name, $text);
     }
 }
@@ -323,7 +323,7 @@ function pdfannotator_format_notification_message_text($course, $cm, $context, $
  * @param stdClass $coursemodule
  * @param string $assignmentname
  */
-function pdfannotator_format_notification_message_html($course, $cm, $context, $modulename, $pdfannotatorname, $report, $messagetype) {
+function pdfannotator_format_notification_message_html($course, $cm, $context, $modulename, $pdfannotatorname, $report, $messagetype, $recipientid) {
     global $CFG, $USER;
     $formatparams = array('context' => $context->get_course_context());
     $posthtml = '<p><font face="sans-serif">' .
@@ -339,7 +339,7 @@ function pdfannotator_format_notification_message_html($course, $cm, $context, $
     $posthtml .= '<hr /><font face="sans-serif">';
     $report->urltoreport = $CFG->wwwroot . '/mod/pdfannotator/view.php?id=' . $cm->id . '&action=overviewreports';
     $posthtml .= '<p>' . get_string($messagetype . 'html', 'pdfannotator', $report) . '</p>';
-    $linktonotificationsettingspage = new moodle_url('/message/notificationpreferences.php', array('userid' => $USER->id));
+    $linktonotificationsettingspage = new moodle_url('/message/notificationpreferences.php', array('userid' => $recipientid));
     $linktonotificationsettingspage = $linktonotificationsettingspage->__toString();
     $posthtml .= '</font><hr />';
     $posthtml .= '<font face="sans-serif"><p>' . get_string('unsubscribe_notification', 'pdfannotator', $linktonotificationsettingspage) . '</p></font>';
diff --git a/model/comment.class.php b/model/comment.class.php
index e856ac6..ac4e407 100644
--- a/model/comment.class.php
+++ b/model/comment.class.php
@@ -89,11 +89,11 @@ class pdfannotator_comment {
                 $messagetext = new stdClass();
                 $module = get_string('modulename', 'pdfannotator');
                 $messagetext->text = pdfannotator_format_notification_message_text($course, $cm, $context, $module, $cm->name, $comment, 'newanswer');
-                $messagetext->html = pdfannotator_format_notification_message_html($course, $cm, $context, $module, $cm->name, $comment, 'newanswer');
                 $messagetext->url = $comment->urltoanswer;
                 $recipients = self::get_subscribed_users($annotationid);
                 foreach ($recipients as $recipient) {
                     if ($recipient != $USER->id) {
+                        $messagetext->html = pdfannotator_format_notification_message_html($course, $cm, $context, $module, $cm->name, $comment, 'newanswer', $recipient);
                         $messageid = pdfannotator_notify_manager($recipient, $course, $cm, 'newanswer', $messagetext, $anonymous);
                     }
                 }
@@ -112,12 +112,12 @@ class pdfannotator_comment {
 
                 $messagetext = new stdClass();
                 $messagetext->text = pdfannotator_format_notification_message_text($course, $cm, $context, get_string('modulename', 'pdfannotator'), $cm->name, $question, 'newquestion');
-                $messagetext->html = pdfannotator_format_notification_message_html($course, $cm, $context, get_string('modulename', 'pdfannotator'), $cm->name, $question, 'newquestion');
                 $messagetext->url = $question->urltoanswer;
                 foreach ($recipients as $recipient) {
                     if ($recipient->id == $USER->id) {
                         continue;
                     }
+                    $messagetext->html = pdfannotator_format_notification_message_html($course, $cm, $context, get_string('modulename', 'pdfannotator'), $cm->name, $question, 'newquestion', $recipient->id);
                     $messageid = pdfannotator_notify_manager($recipient, $course, $cm, 'newquestion', $messagetext, $anonymous);
                 }
 
diff --git a/version.php b/version.php
index 077b349..1a96ab9 100644
--- a/version.php
+++ b/version.php
@@ -25,6 +25,6 @@
 defined('MOODLE_INTERNAL') || die();
 
 $plugin->component = 'mod_pdfannotator'; // Full name of the plugin (used for diagnostics).
-$plugin->version   = 2020032600; // The current module version (Date: YYYYMMDDXX).
+$plugin->version   = 2020040800; // The current module version (Date: YYYYMMDDXX).
 $plugin->release  = 'PDF Annotator v1.3 release 2';
 $plugin->requires  = 2016112900; // Requires this Moodle version.
-- 
GitLab