2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * A page displaying the user's contacts and messages
20 * @package core_message
21 * @copyright 2010 Andrew Davis
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once('../config.php');
27 require_login(null, false);
30 redirect($CFG->wwwroot
);
33 if (empty($CFG->messaging
)) {
34 print_error('disabled', 'message');
37 // The id of the user we want to view messages from.
38 $id = optional_param('id', 0, PARAM_INT
);
39 // It's possible a user may come from a link where these parameters are specified.
40 // We no longer support viewing another user's messaging area (that can be achieved
41 // via the 'Log-in as' feature). The 'user2' value takes preference over 'id'.
42 $userid = optional_param('user2', $id, PARAM_INT
);
44 if (!core_user
::is_real_user($userid)) {
49 $recipient = new stdClass();
50 $recipient->id
= $userid;
51 if (!\core_message\api
::can_post_message($recipient)) {
52 throw new moodle_exception('Can not contact user');
56 $url = new moodle_url('/message/index.php');
58 $url->param('id', $userid);
61 $PAGE->set_context(context_user
::instance($USER->id
));
62 $PAGE->set_pagelayout('standard');
64 $strmessages = get_string('messages', 'message');
66 $PAGE->set_title("$strmessages");
67 $PAGE->set_heading("$strmessages");
69 // Remove the user node from the main navigation for this page.
70 $usernode = $PAGE->navigation
->find('users', null);
73 $settings = $PAGE->settingsnav
->find('messages', null);
74 $settings->make_active();
76 // Check if there is an existing conversation with the supplied user (if there is one).
77 $conversationid = null;
79 $conversationid = \core_message\api
::get_conversation_between_users([$USER->id
, $userid]);
82 echo $OUTPUT->header();
83 // Display a message if the messages have not been migrated yet.
84 if (!get_user_preferences('core_message_migrate_data', false)) {
85 $notify = new \core\output\notification
(get_string('messagingdatahasnotbeenmigrated', 'message'),
86 \core\output\notification
::NOTIFY_WARNING
);
87 echo $OUTPUT->render($notify);
89 echo $OUTPUT->heading(get_string('messages', 'message'));
90 echo \core_message\helper
::render_messaging_widget(false, $userid, $conversationid);
91 echo $OUTPUT->footer();