2009-09-29 03:54:14 +00:00
|
|
|
<?php
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
2010-11-17 06:34:59 +00:00
|
|
|
* A page displaying the user's contacts and messages
|
2009-09-29 03:54:14 +00:00
|
|
|
*
|
2012-01-05 12:05:02 +07:00
|
|
|
* @package core_message
|
|
|
|
* @copyright 2010 Andrew Davis
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2009-09-29 03:54:14 +00:00
|
|
|
*/
|
|
|
|
|
2010-06-29 07:27:24 +00:00
|
|
|
require_once('../config.php');
|
2009-09-29 03:54:14 +00:00
|
|
|
|
2016-09-23 13:28:42 +08:00
|
|
|
require_login(null, false);
|
2009-09-29 03:54:14 +00:00
|
|
|
|
2010-03-31 07:41:31 +00:00
|
|
|
if (isguestuser()) {
|
2009-09-29 03:54:14 +00:00
|
|
|
redirect($CFG->wwwroot);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($CFG->messaging)) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('disabled', 'message');
|
2009-09-29 03:54:14 +00:00
|
|
|
}
|
2005-01-31 07:11:42 +00:00
|
|
|
|
2016-09-23 13:28:42 +08:00
|
|
|
// The id of the user we want to view messages from.
|
|
|
|
$id = optional_param('id', 0, PARAM_INT);
|
2019-07-11 15:27:43 +08:00
|
|
|
$view = optional_param('view', null, PARAM_ALPHANUM);
|
2019-01-18 12:10:05 +08:00
|
|
|
// It's possible a user may come from a link where these parameters are specified.
|
|
|
|
// We no longer support viewing another user's messaging area (that can be achieved
|
|
|
|
// via the 'Log-in as' feature). The 'user2' value takes preference over 'id'.
|
|
|
|
$userid = optional_param('user2', $id, PARAM_INT);
|
2019-04-05 14:48:26 +08:00
|
|
|
$conversationid = optional_param('convid', null, PARAM_INT);
|
2011-01-12 17:15:43 +08:00
|
|
|
|
2019-01-18 12:10:05 +08:00
|
|
|
if (!core_user::is_real_user($userid)) {
|
|
|
|
$userid = null;
|
2009-09-29 03:54:14 +00:00
|
|
|
}
|
2019-04-05 14:48:26 +08:00
|
|
|
// You can specify either a user, or a conversation, not both.
|
|
|
|
if ($userid) {
|
|
|
|
$conversationid = \core_message\api::get_conversation_between_users([$USER->id, $userid]);
|
|
|
|
} else if ($conversationid) {
|
|
|
|
// Check that the user belongs to the conversation.
|
|
|
|
if (!\core_message\api::is_user_in_conversation($USER->id, $conversationid)) {
|
|
|
|
$conversationid = null;
|
|
|
|
}
|
|
|
|
}
|
2004-12-31 02:17:44 +00:00
|
|
|
|
2019-01-18 12:10:05 +08:00
|
|
|
if ($userid) {
|
2019-07-25 14:22:20 +08:00
|
|
|
if (!\core_message\api::can_send_message($userid, $USER->id)) {
|
2019-01-18 12:10:05 +08:00
|
|
|
throw new moodle_exception('Can not contact user');
|
|
|
|
}
|
2010-06-29 07:27:24 +00:00
|
|
|
}
|
2004-12-16 12:40:36 +00:00
|
|
|
|
2019-01-18 12:10:05 +08:00
|
|
|
$url = new moodle_url('/message/index.php');
|
|
|
|
if ($userid) {
|
|
|
|
$url->param('id', $userid);
|
2010-10-08 02:31:57 +00:00
|
|
|
}
|
2019-01-18 12:10:05 +08:00
|
|
|
$PAGE->set_url($url);
|
|
|
|
$PAGE->set_context(context_user::instance($USER->id));
|
2019-03-13 17:24:30 +01:00
|
|
|
$PAGE->set_pagelayout('mydashboard');
|
2019-01-18 12:10:05 +08:00
|
|
|
|
2015-03-24 17:11:15 -07:00
|
|
|
$strmessages = get_string('messages', 'message');
|
|
|
|
|
2019-01-18 12:10:05 +08:00
|
|
|
$PAGE->set_title("$strmessages");
|
|
|
|
$PAGE->set_heading("$strmessages");
|
2015-03-24 17:11:15 -07:00
|
|
|
|
2015-03-19 10:59:27 +08:00
|
|
|
// Remove the user node from the main navigation for this page.
|
|
|
|
$usernode = $PAGE->navigation->find('users', null);
|
|
|
|
$usernode->remove();
|
|
|
|
|
|
|
|
$settings = $PAGE->settingsnav->find('messages', null);
|
2016-05-31 19:34:29 +08:00
|
|
|
$settings->make_active();
|
|
|
|
|
2010-06-29 07:27:24 +00:00
|
|
|
echo $OUTPUT->header();
|
2018-02-20 14:12:20 +08:00
|
|
|
// Display a message if the messages have not been migrated yet.
|
2019-01-18 12:10:05 +08:00
|
|
|
if (!get_user_preferences('core_message_migrate_data', false)) {
|
2018-02-20 14:12:20 +08:00
|
|
|
$notify = new \core\output\notification(get_string('messagingdatahasnotbeenmigrated', 'message'),
|
|
|
|
\core\output\notification::NOTIFY_WARNING);
|
|
|
|
echo $OUTPUT->render($notify);
|
|
|
|
}
|
2019-07-11 15:27:43 +08:00
|
|
|
echo \core_message\helper::render_messaging_widget(false, $userid, $conversationid, $view);
|
2009-09-29 03:54:14 +00:00
|
|
|
echo $OUTPUT->footer();
|