MDL-41369 Set proper context and navigation path for user messages
authorMarina Glancy <marina@moodle.com>
Mon, 26 Aug 2013 07:23:34 +0000 (17:23 +1000)
committerMarina Glancy <marina@moodle.com>
Mon, 26 Aug 2013 07:32:57 +0000 (17:32 +1000)
lib/navigationlib.php
message/index.php
user/view.php

index 3a897d7..6c3cdf0 100644 (file)
@@ -2182,9 +2182,12 @@ class global_navigation extends navigation_node {
         }
 
         if (!empty($CFG->messaging)) {
-            $messageargs = null;
+            $messageargs = array('user1' => $USER->id);
             if ($USER->id != $user->id) {
-                $messageargs = array('user1' => $user->id);
+                $messageargs['user2'] = $user->id;
+            }
+            if ($course->id != $SITE->id) {
+                $messageargs['viewing'] = MESSAGE_VIEW_COURSE. $course->id;
             }
             $url = new moodle_url('/message/index.php',$messageargs);
             $usernode->add(get_string('messages', 'message'), $url, self::TYPE_SETTING, null, 'messages');
index 43e5293..42189b9 100644 (file)
@@ -83,9 +83,6 @@ if ($viewing != MESSAGE_VIEW_UNREAD_MESSAGES) {
 
 $PAGE->set_url($url);
 
-$navigationurl = new moodle_url('/message/index.php', array('user1' => $user1id));
-navigation_node::override_active_url($navigationurl);
-
 // Disable message notification popups while the user is viewing their messages
 $PAGE->set_popup_notification_allowed(false);
 
@@ -125,9 +122,21 @@ if (!message_current_user_is_involved($user1, $user2) && !has_capability('moodle
     print_error('accessdenied','admin');
 }
 
-$PAGE->set_context(context_user::instance($user1->id));
-$PAGE->set_pagelayout('course');
-$PAGE->navigation->extend_for_user($user1);
+if (substr($viewing, 0, 7) == MESSAGE_VIEW_COURSE) {
+    $courseid = intval(substr($viewing, 7));
+    require_login($courseid);
+    require_capability('moodle/course:viewparticipants', context_course::instance($courseid));
+    $PAGE->set_pagelayout('incourse');
+} else {
+    $PAGE->set_pagelayout('course');
+    $PAGE->set_context(context_user::instance($user1->id));
+}
+if (!empty($user1->id) && $user1->id != $USER->id) {
+    $PAGE->navigation->extend_for_user($user1);
+}
+if (!empty($user2->id) && $user2->id != $USER->id) {
+    $PAGE->navigation->extend_for_user($user2);
+}
 
 /// Process any contact maintenance requests there may be
 if ($addcontact and confirm_sesskey()) {
index 27df57e..05095ce 100644 (file)
@@ -342,7 +342,11 @@ echo "</div></div>"; // Closing desriptionbox and userprofilebox.
 if (isloggedin() && has_capability('moodle/site:sendmessage', $usercontext)
     && !empty($CFG->messaging) && !isguestuser() && !isguestuser($user) && ($USER->id != $user->id)) {
     echo '<div class="messagebox">';
-    echo '<a href="'.$CFG->wwwroot.'/message/index.php?id='.$user->id.'">'.get_string('messageselectadd').'</a>';
+    $sendmessageurl = new moodle_url('/message/index.php', array('id' => $user->id));
+    if ($courseid) {
+        $sendmessageurl->param('viewing', MESSAGE_VIEW_COURSE. $courseid);
+    }
+    echo html_writer::link($sendmessageurl, get_string('messageselectadd'));
     echo '</div>';
 }