diff --git a/lang/en/message.php b/lang/en/message.php
index 705806fd6da..ec1a770cf1d 100644
--- a/lang/en/message.php
+++ b/lang/en/message.php
@@ -5,43 +5,48 @@ $string['ago'] = '$a ago';
$string['allmine'] = 'All messages to me or from me';
$string['allstudents'] = 'All messages between students in course';
$string['allusers'] = 'All messages from all users';
+$string['beepnewmessage'] = 'Beep when a new message comes in';
$string['blockcontact'] = 'Block contact';
$string['blockedmessages'] = '$a message(s) to/from blocked users';
+$string['deletemessagesdays'] = 'Number of days before old messages are automatically deleted';
$string['discussion'] = 'Discussion';
+$string['emailmessages'] = 'Email messages when I am offline';
$string['emptysearchstring'] = 'You must search for something';
$string['includeblockedusers'] = 'Include blocked users';
$string['incomingcontacts'] = 'Incoming Contacts ($a)';
$string['keywords'] = 'Keywords';
$string['keywordssearchresults'] = 'Search results: $a messages found';
+$string['maxmessages'] = 'Maximum number of messages to show in the discussion history';
$string['message'] = 'Message';
+$string['messagehistory'] = 'Message History';
$string['messages'] = 'Messages';
$string['messaging'] = 'Messaging';
$string['mycontacts'] = 'My Contacts';
$string['newsearch'] = 'New search';
$string['nosearchresults'] = 'There were no results from your search';
$string['nomessages'] = 'No messages waiting';
+$string['nomessagesfound'] = 'No messages were found';
$string['offlinecontacts'] = 'Offline Contacts ($a)';
$string['onlinecontacts'] = 'Online Contacts ($a)';
$string['onlyfromme'] = 'Only messages from me';
$string['onlymycourses'] = 'Only in my courses';
$string['onlytome'] = 'Only messages to me';
+$string['pagerefreshes'] = 'This page refreshes automatically every $a seconds';
$string['removecontact'] = 'Remove contact';
+$string['savemysettings'] = 'Save my settings';
$string['searchforperson'] = 'Search for a person';
$string['searchmessages'] = 'Search messages';
$string['sendmessage'] = 'Send message';
$string['sendmessageto'] = 'Send message to $a';
+$string['settingssaved'] = 'Your settings have been saved';
+$string['showmessagewindow'] = 'Automatically show Message window when I get new messages (your browser needs to be set so that it doesn\'t block popups on this site)';
+$string['strftimedaydatetime'] = '%%A, %%d %%B %%Y, %%I:%%M %%p';
+$string['timenosee'] = 'Minutes since I was last seen online';
$string['timesent'] = 'Time Sent';
$string['unblockcontact'] = 'Unblock contact';
$string['unreadmessages'] = '$a unread messages';
+$string['userisblockingyou'] = 'This user has blocked you from sending messages to them';
$string['userssearchresults'] = 'Search results: $a users found';
-$string['savemysettings'] = 'Save my settings';
-$string['settingssaved'] = 'Your settings have been saved';
-$string['showmessagewindow'] = 'Automatically show Message window when I get new messages (your browser needs to be set so that it doesn\'t block popups on this site)';
-$string['beepnewmessage'] = 'Beep when a new message comes in';
-$string['maxmessages'] = 'Maximum number of messages to show in the discussion history';
-$string['deletemessagesdays'] = 'Number of days before old messages are automatically deleted';
-$string['emailmessages'] = 'Email messages when I am offline';
-$string['timenosee'] = 'Minutes since I was last seen online';
?>
diff --git a/message/history.php b/message/history.php
index 43ef2bbefcb..55050fd30b1 100644
--- a/message/history.php
+++ b/message/history.php
@@ -1,17 +1,78 @@
id, PARAM_INT);
+ if (! $user2 = get_record("user", "id", $userid2)) { // Check
+ error("User ID 2 was incorrect");
+ }
+ } else {
+ $userid2 = $USER->id; // Can only see messages involving yourself
+ $user2 = $USER;
+ }
+
+/// Our two users are defined - let's set up the page
+
+ $THEME->body = $THEME->cellcontent;
+
+ print_header(get_string('messagehistory', 'message'));
+
+/// Print out a heading including the users we are looking at
+
+ print_simple_box_start('center');
+ echo '
';
+ echo '';
+ echo print_user_picture($user1->id, SITEID, $user1->picture, 100, true, true, 'userwindow').' ';
+ echo fullname($user1);
+ echo ' | ';
+ echo '';
+ echo ' ';
+ echo ' ';
+ echo ' | ';
+ echo '';
+ echo print_user_picture($user2->id, SITEID, $user2->picture, 100, true, true, 'userwindow').' ';
+ echo fullname($user2);
+ echo ' | ';
+ echo '
';
+ print_simple_box_end();
+
+
+/// Get all the messages and print them
+
+ if ($messages = message_get_history($user1, $user2)) {
+ $current->day = '';
+ $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'];
+ print_heading(userdate($message->timecreated, $blockdate), 'center', 4);
+ }
+ if ($message->useridfrom == $user1->id) {
+ echo message_format_message($message, $user1, $messagedate);
+ } else {
+ echo message_format_message($message, $user2, $messagedate);
+ }
+ }
+ } else {
+ print_heading(get_string('nomessagesfound', 'message'));
+ }
+
+
?>
diff --git a/message/index.php b/message/index.php
index 7ccde85af5d..20330da6c31 100644
--- a/message/index.php
+++ b/message/index.php
@@ -31,7 +31,12 @@ if ($unblockcontact and confirm_sesskey()) {
$tabprintfunction = 'message_print_'.$tab;
-print_header(get_string('messages', 'message').' - '.$SITE->fullname);
+if ($tab == 'contacts') {
+ print_header(get_string('messages', 'message').' - '.$SITE->fullname, '', '', '',
+ '');
+} else {
+ print_header(get_string('messages', 'message').' - '.$SITE->fullname);
+}
?>
diff --git a/message/lib.php b/message/lib.php
index cbb051f6b37..3478d48afc8 100644
--- a/message/lib.php
+++ b/message/lib.php
@@ -4,6 +4,7 @@
define ('MESSAGE_SHORTLENGTH', 300);
define ('MESSAGE_WINDOW', true);
+define ('MESSAGE_CONTACTS_REFRESH', 30);
function message_print_contacts() {
@@ -62,7 +63,7 @@ function message_print_contacts() {
/// link to remove from contact list
$strcontact .= message_contact_link($contact->id, 'remove', true);
- echo '| ';
+ echo ' |
| ';
print_user_picture($contact->id, SITEID, $contact->picture, 20, false, false);
echo ' | ';
echo '';
@@ -100,7 +101,7 @@ function message_print_contacts() {
/// link to remove from contact list
$strcontact .= message_contact_link($contact->id, 'remove', true);
- echo ' |
| ';
+ echo ' |
| ';
print_user_picture($contact->id, SITEID, $contact->picture, 20, false, false);
echo ' | ';
echo '';
@@ -159,7 +160,7 @@ function message_print_contacts() {
$strcontact .= message_contact_link($messageuser->useridfrom, 'add', true);
$strblock = message_contact_link($messageuser->useridfrom, 'block', true);
- echo ' |
| ';
+ echo ' |
| ';
print_user_picture($messageuser->useridfrom, SITEID, $messageuser->picture, 20, false, false);
echo ' | ';
echo '';
@@ -174,6 +175,8 @@ function message_print_contacts() {
}
echo '';
+
+ echo ' '.get_string('pagerefreshes', 'message', MESSAGE_CONTACTS_REFRESH).' ';
}
@@ -344,7 +347,7 @@ function message_print_search_results($frm) {
$strblock = message_contact_link($user->id, 'block', true);
}
- echo ' |
| ';
+ echo ' |
| ';
print_user_picture($user->id, SITEID, $user->picture, 20, false, false);
echo ' | ';
echo '';
@@ -404,8 +407,8 @@ function message_print_search_results($frm) {
/// print table headings
echo '';
echo '';
- echo '| '.get_string('to').' | ';
echo ''.get_string('from').' | ';
+ echo ''.get_string('to').' | ';
echo ''.get_string('message', 'message').' | ';
echo ''.get_string('timesent', 'message').' | ';
echo " \n";
@@ -452,13 +455,13 @@ function message_print_search_results($frm) {
/// print out message row
echo '';
echo '| ';
- message_print_user($userto, $tocontact, $toblocked);
- echo ' | ';
- echo '';
message_print_user($userfrom, $fromcontact, $fromblocked);
echo ' | ';
- echo ''.message_shorten_message($message->message, 20).' | ';
- echo ''.userdate($message->timecreated, get_string('strftimedatetime')).' | ';
+ echo '';
+ message_print_user($userto, $tocontact, $toblocked);
+ echo ' | ';
+ echo ''.message_shorten_message($message->message, 20).' | ';
+ echo ''.userdate($message->timecreated, get_string('strftimedatetime')).' | ';
echo " \n";
}
@@ -777,6 +780,27 @@ function message_shorten_message($message, $minlength=0) {
return substr($message, 0, $truncate);
}
+function message_get_history($user1, $user2) {
+ $messages = get_records_select('message_read', "(useridto = '$user1->id' AND useridfrom = '$user2->id') OR
+ (useridto = '$user2->id' AND useridfrom = '$user1->id')",
+ 'timecreated');
+ if ($messages_new = get_records_select('message', "(useridto = '$user1->id' AND useridfrom = '$user2->id') OR
+ (useridto = '$user2->id' AND useridfrom = '$user1->id')",
+ 'timecreated')) {
+ foreach ($messages_new as $message) {
+ $messages[] = $message;
+ }
+ }
+ return $messages;
+}
+
+function message_format_message(&$message, &$user, $format='') {
+ if (empty($format)) {
+ $format = get_string('strftimemessage', 'chat');
+ }
+ $time = userdate($message->timecreated, $format);
+ return ''.addslashes($user->firstname).' ['.$time.']: '.$message->message.' ';
+}
?>
diff --git a/message/user.php b/message/user.php
index a20f85a6a37..7de2486533d 100644
--- a/message/user.php
+++ b/message/user.php
@@ -41,7 +41,7 @@
case 'info': /// Print the top frame with information and links
print_header();
echo '';
- echo '| '.print_user_picture($user->id, SITEID, $user->picture, true, true, false).' | ';
+ echo ''.print_user_picture($user->id, SITEID, $user->picture, true, true, true, 'userwindow').' | ';
echo '';
echo fullname($user);
echo ' ';
@@ -52,6 +52,10 @@
}
echo get_string("lastaccess").":", $datestring;
echo '';
+ echo ' ';
+ echo 'id", "message_history_$user->id",
+ get_string('messagehistory', 'message'), 500, 500, '');
echo ' | ';
echo ' ';
echo ' |