forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory.php
133 lines (113 loc) · 4.45 KB
/
history.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?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/>.
/**
* For listing message histories between any two users
*
* @author Luis Rodrigues and Martin Dougiamas
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package message
*/
require('../config.php');
require('lib.php');
require_login();
if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
redirect($CFG->wwwroot);
}
if (empty($CFG->messaging)) {
print_error('disabled', 'message');
}
$PAGE->set_title(get_string('messagehistory', 'message'));
/// Script parameters
$userid1 = required_param('user1', PARAM_INT);
$PAGE->set_url(new moodle_url($CFG->wwwroot.'/message/history.php', array('user1'=>$userid1)));
if (! $user1 = $DB->get_record("user", array("id"=>$userid1))) { // Check it's correct
print_error('invaliduserid');
}
if ($user1->deleted) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('userdeleted').': '.$userid1, 1);
echo $OUTPUT->footer();
die;
}
if (has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM))) { // Able to see any discussion
$userid2 = optional_param('user2', $USER->id, PARAM_INT);
$PAGE->url->param('user2', $userid2);
if (! $user2 = $DB->get_record("user", array("id"=>$userid2))) { // Check
print_error('invaliduserid');
}
if ($user2->deleted) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('userdeleted').': '.$userid2, 1);
echo $OUTPUT->footer();
die;
}
} else {
$userid2 = $USER->id; // Can only see messages involving yourself
$user2 = $USER;
}
$search = optional_param('search', '', PARAM_CLEAN);
add_to_log(SITEID, 'message', 'history', 'history.php?user1='.$userid1.'&user2='.$userid2, $userid1);
/// Our two users are defined - let's set up the page
echo $OUTPUT->header();
/// Print out a heading including the users we are looking at
echo $OUTPUT->box_start('center');
echo '<table align="center" cellpadding="10"><tr>';
echo '<td align="center">';
$userpic = moodle_user_picture::make($user1, SITEID);
$userpic->size = 100;
$userpic->link = true;
echo $OUTPUT->user_picture($userpic).'<br />';
echo fullname($user1);
echo '</td>';
echo '<td align="center">';
echo '<img src="'.$CFG->wwwroot.'/pix/t/left.gif" alt="'.get_string('from').'" />';
echo '<img src="'.$CFG->wwwroot.'/pix/t/right.gif" alt="'.get_string('to').'" />';
echo '</td>';
echo '<td align="center">';
$userpic = moodle_user_picture::make($user2, SITEID);
$userpic->size = 100;
$userpic->link = true;
echo $OUTPUT->user_picture($userpic).'<br />';
echo fullname($user2);
echo '</td>';
echo '</tr></table>';
echo $OUTPUT->box_end();
/// Get all the messages and print them
if ($messages = message_get_history($user1, $user2)) {
$current->mday = '';
$current->month = '';
$current->year = '';
$messagedate = get_string('strftimetime');
$blockdate = get_string('strftimedaydate');
foreach ($messages as $message) {
$date = usergetdate($message->timecreated);
if ($current->mday != $date['mday'] | $current->month != $date['month'] | $current->year != $date['year']) {
$current->mday = $date['mday'];
$current->month = $date['month'];
$current->year = $date['year'];
echo '<a name="'.$date['year'].$date['mon'].$date['mday'].'"></a>';
echo $OUTPUT->heading(userdate($message->timecreated, $blockdate), 4, 'center');
}
if ($message->useridfrom == $user1->id) {
echo message_format_message($message, $user1, $messagedate, $search, 'other');
} else {
echo message_format_message($message, $user2, $messagedate, $search, 'me');
}
}
} else {
echo $OUTPUT->heading(get_string('nomessagesfound', 'message'), 1);
}
echo $OUTPUT->footer();