Bumped to 1.7.6
[moodle.git] / message / history.php
blobb5cd97ee96c1d045114d6c0d27e91c3de88f310c
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 (isguest()) {
10 redirect($CFG->wwwroot);
13 if (empty($CFG->messaging)) {
14 error("Messaging is disabled on this site");
17 /// Script parameters
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 (has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM, SITEID))) { // 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");
28 } else {
29 $userid2 = $USER->id; // Can only see messages involving yourself
30 $user2 = $USER;
32 $search = optional_param('search', '', PARAM_CLEAN);
34 add_to_log(SITEID, 'message', 'history', 'history.php?user1='.$userid1.'&amp;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);
47 echo '</td>';
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">';
51 echo '</td>';
52 echo '<td align="center">';
53 echo print_user_picture($user2->id, SITEID, $user2->picture, 100, true, true, 'userwindow').'<br />';
54 echo fullname($user2);
55 echo '</td>';
56 echo '</tr></table>';
57 print_simple_box_end();
60 /// Get all the messages and print them
62 if ($messages = message_get_history($user1, $user2)) {
63 $current->mday = '';
64 $current->month = '';
65 $current->year = '';
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');
79 } else {
80 echo message_format_message($message, $user2, $messagedate, $search, 'me');
83 } else {
84 print_heading(get_string('nomessagesfound', 'message'));