weekly release 1.9.12+
[moodle.git] / message / history.php
blobd5dde7c99ddac6f92a679de69d40634bf6dfefb5
1 <?php // $Id$
2 // For listing message histories between any two users
4 require('../config.php');
5 require('lib.php');
7 require_login();
9 if (isguestuser()) {
10 redirect($CFG->wwwroot);
13 if (empty($CFG->messaging)) {
14 error("Messaging is disabled on this site");
17 // We expect 2 users and by default user2 is the current user
18 $userid1 = required_param('user1', PARAM_INT);
19 $userid2 = optional_param('user2', $USER->id, PARAM_INT);
20 $search = optional_param('search', '', PARAM_CLEAN);
22 // Check if user1 is the current user, this should not occur but just incase
23 if ($userid1 == $USER->id) {
24 // user1 is the current user :(
25 $user1 = $USER;
26 } else if ($userid2 == $USER->id) {
27 // user2 is the current user
28 $user2 = $USER;
29 } else {
30 // Neither user is the current user, so check the user has the readallmessages
31 // capability
32 require_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM));
34 // Load user1 if it wasn't set above (only set if user1 is the current user)
35 if (!isset($user1) && !($user1 = get_record("user", "id", $userid1))) {
36 error("User ID 1 was incorrect");
38 // Load user2 if it wasn't set above (only set if user2 is the current user)
39 if (!isset($user2) && !($user2 = get_record("user", "id", $userid2))) {
40 error("User ID 2 was incorrect");
43 // If either user has been deleted then print a page that details that information
44 // we can't use print_error because this is in a popup and the continue button
45 // would cause mayhem
46 if ($user1->deleted || $user2->deleted) {
47 print_header();
48 print_heading(get_string('userdeleted', 'moodle'));
49 print_footer();
52 add_to_log(SITEID, 'message', 'history', 'history.php?user1='.$userid1.'&amp;user2='.$userid2, $userid1);
54 /// Our two users are defined - let's set up the page
56 print_header(get_string('messagehistory', 'message'), '', '', '', '<base target="_blank" />');
58 /// Print out a heading including the users we are looking at
60 print_simple_box_start('center');
61 echo '<table align="center" cellpadding="10"><tr>';
62 echo '<td align="center">';
63 echo print_user_picture($user1, SITEID, $user1->picture, 100, true, true, 'userwindow').'<br />';
64 echo fullname($user1);
65 echo '</td>';
66 echo '<td align="center">';
67 echo '<img src="'.$CFG->wwwroot.'/pix/t/left.gif" alt="'.get_string('from').'" />';
68 echo '<img src="'.$CFG->wwwroot.'/pix/t/right.gif" alt="'.get_string('to').'" />';
69 echo '</td>';
70 echo '<td align="center">';
71 echo print_user_picture($user2, SITEID, $user2->picture, 100, true, true, 'userwindow').'<br />';
72 echo fullname($user2);
73 echo '</td>';
74 echo '</tr></table>';
75 print_simple_box_end();
78 /// Get all the messages and print them
80 if ($messages = message_get_history($user1, $user2)) {
81 $current->mday = '';
82 $current->month = '';
83 $current->year = '';
84 $messagedate = get_string('strftimetime');
85 $blockdate = get_string('strftimedaydate');
86 foreach ($messages as $message) {
87 $date = usergetdate($message->timecreated);
88 if ($current->mday != $date['mday'] | $current->month != $date['month'] | $current->year != $date['year']) {
89 $current->mday = $date['mday'];
90 $current->month = $date['month'];
91 $current->year = $date['year'];
92 echo '<a name="'.$date['year'].$date['mon'].$date['mday'].'"></a>';
93 print_heading(userdate($message->timecreated, $blockdate), 'center', 4);
95 if ($message->useridfrom == $user1->id) {
96 echo message_format_message($message, $user1, $messagedate, $search, 'other');
97 } else {
98 echo message_format_message($message, $user2, $messagedate, $search, 'me');
101 } else {
102 print_heading(get_string('nomessagesfound', 'message'));
105 print_footer('none');