2 // For listing message histories between any two users
4 require('../config.php');
10 redirect($CFG->wwwroot
);
13 if (empty($CFG->messaging
)) {
14 error("Messaging is disabled on this site");
18 $userid1 = required_param('user1', PARAM_INT
);
19 if (! $user1 = get_record("user", "id", $userid1)) { // Check it's correct
20 error("User ID 1 was incorrect");
23 if (isadmin()) { // Able to see any discussion
24 $userid2 = optional_param('user2', $USER->id
, PARAM_INT
);
25 if (! $user2 = get_record("user", "id", $userid2)) { // Check
26 error("User ID 2 was incorrect");
29 $userid2 = $USER->id
; // Can only see messages involving yourself
32 $search = optional_param('search', '', PARAM_CLEAN
);
34 add_to_log(SITEID
, 'message', 'history', 'history.php?user1='.$userid1.'&user2='.$userid2, $userid1);
36 /// Our two users are defined - let's set up the page
38 print_header(get_string('messagehistory', 'message'), '', '', '', '<base target="_blank">');
40 /// Print out a heading including the users we are looking at
42 print_simple_box_start('center');
43 echo '<table align="center" cellpadding="10"><tr>';
44 echo '<td align="center">';
45 echo print_user_picture($user1->id
, SITEID
, $user1->picture
, 100, true, true, 'userwindow').'<br />';
46 echo fullname($user1);
48 echo '<td align="center">';
49 echo '<img src="'.$CFG->wwwroot
.'/pix/t/left.gif">';
50 echo '<img src="'.$CFG->wwwroot
.'/pix/t/right.gif">';
52 echo '<td align="center">';
53 echo print_user_picture($user2->id
, SITEID
, $user2->picture
, 100, true, true, 'userwindow').'<br />';
54 echo fullname($user2);
57 print_simple_box_end();
60 /// Get all the messages and print them
62 if ($messages = message_get_history($user1, $user2)) {
66 $messagedate = get_string('strftimetime');
67 $blockdate = get_string('strftimedaydate');
68 foreach ($messages as $message) {
69 $date = usergetdate($message->timecreated
);
70 if ($current->mday
!= $date['mday'] |
$current->month
!= $date['month'] |
$current->year
!= $date['year']) {
71 $current->mday
= $date['mday'];
72 $current->month
= $date['month'];
73 $current->year
= $date['year'];
74 echo '<a name="'.$date['year'].$date['mon'].$date['mday'].'"></a>';
75 print_heading(userdate($message->timecreated
, $blockdate), 'center', 4);
77 if ($message->useridfrom
== $user1->id
) {
78 echo message_format_message($message, $user1, $messagedate, $search, 'other');
80 echo message_format_message($message, $user2, $messagedate, $search, 'me');
84 print_heading(get_string('nomessagesfound', 'message'));