diff --git a/lang/en/message.php b/lang/en/message.php
index c8bb495d85f..0ffd1656683 100644
--- a/lang/en/message.php
+++ b/lang/en/message.php
@@ -29,7 +29,9 @@ $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['offline'] = 'Offline';
$string['offlinecontacts'] = 'Offline Contacts ($a)';
+$string['online'] = 'Online';
$string['onlinecontacts'] = 'Online Contacts ($a)';
$string['onlyfromme'] = 'Only messages from me';
$string['onlymycourses'] = 'Only in my courses';
diff --git a/message/lib.php b/message/lib.php
index 31d5b4bce69..7745c55f1d6 100644
--- a/message/lib.php
+++ b/message/lib.php
@@ -11,6 +11,9 @@ if (!isset($CFG->message_contacts_refresh)) { // Refresh the contacts list ever
if (!isset($CFG->message_chat_refresh)) { // Look for new comments every 5 seconds
$CFG->message_chat_refresh = 5;
}
+if (!isset($CFG->message_offline_time)) {
+ $CFG->message_offline_time = 300;
+}
function message_print_contacts() {
@@ -65,7 +68,7 @@ function message_print_contacts() {
}
/// link to remove from contact list
$strcontact = message_contact_link($contact->id, 'remove', true);
- $strhistory = message_contact_link($contact->id, 'history', true);
+ $strhistory = message_history_link($contact->id, 0, true, '', '', 'icon');
echo '
| ';
print_user_picture($contact->id, SITEID, $contact->picture, 20, false, true, 'userwindow');
@@ -101,7 +104,7 @@ function message_print_contacts() {
}
/// link to remove from contact list
$strcontact = message_contact_link($contact->id, 'remove', true);
- $strhistory = message_contact_link($contact->id, 'history', true);
+ $strhistory = message_history_link($contact->id, 0, true, '', '', 'icon');
echo ' |
| ';
print_user_picture($contact->id, SITEID, $contact->picture, 20, false, true, 'userwindow');
@@ -161,7 +164,7 @@ function message_print_contacts() {
$strcontact = message_contact_link($messageuser->useridfrom, 'add', true);
$strblock = message_contact_link($messageuser->useridfrom, 'block', true);
- $strhistory = message_contact_link($messageuser->useridfrom, 'history', true);
+ $strhistory = message_history_link($messageuser->useridfrom, 0, true, '', '', 'icon');
echo ' |
| ';
print_user_picture($messageuser->useridfrom, SITEID, $messageuser->picture, 20, false, true, 'userwindow');
@@ -347,6 +350,7 @@ function message_print_search_results($frm) {
$strcontact = message_contact_link($user->id, 'add', true);
$strblock = message_contact_link($user->id, 'block', true);
}
+ $strhistory = message_history_link($user->id, 0, true, '', '', 'icon');
echo ' |
| ';
print_user_picture($user->id, SITEID, $user->picture, 20, false, true, 'userwindow');
@@ -359,6 +363,7 @@ function message_print_search_results($frm) {
echo ' | '.$strcontact.' | ';
echo ''.$strblock.' | ';
+ echo ''.$strhistory.' | ';
echo '
';
}
echo '';
@@ -471,7 +476,9 @@ function message_print_search_results($frm) {
message_print_user($userto, $tocontact, $toblocked);
echo '';
echo ''.message_get_fragment($message->message, $keywords);
- echo '
'.message_history_link($message->useridto, $message->useridfrom, true, $keywordstring, $datestring, $strcontext).' ';
+ echo '
';
+ message_history_link($message->useridto, $message->useridfrom, true, $keywordstring, $datestring, $strcontext);
+ echo ' ';
echo ' | ';
echo ''.userdate($message->timecreated, $dateformat).' | ';
echo "\n";
@@ -527,7 +534,7 @@ function message_print_user ($user=false, $iscontact=false, $isblocked=false) {
/// linktype can be: add, remove, block, unblock
-function message_contact_link($userid, $linktype='add', $return=false) {
+function message_contact_link($userid, $linktype='add', $return=false, $script="index.php?tab=contacts") {
global $USER, $CFG;
static $str;
@@ -537,31 +544,27 @@ function message_contact_link($userid, $linktype='add', $return=false) {
$str->unblockcontact = get_string('unblockcontact', 'message');
$str->removecontact = get_string('removecontact', 'message');
$str->addcontact = get_string('addcontact', 'message');
- $str->messagehistory = get_string('messagehistory', 'message');
}
switch ($linktype) {
- case 'history':
- $output = '
';
- break;
case 'block':
- $output = ''.
'
';
break;
case 'unblock':
- $output = ''.
'
';
break;
case 'remove':
- $output = ''.
'
';
break;
case 'add':
default:
- $output = ''.
'
';
diff --git a/message/user.php b/message/user.php
index 781a449b50a..8b91c24699b 100644
--- a/message/user.php
+++ b/message/user.php
@@ -12,11 +12,35 @@
$message = optional_param('message', '', PARAM_CLEAN);
$format = optional_param('format', FORMAT_MOODLE, PARAM_INT);
+ $addcontact = optional_param('addcontact', 0, PARAM_INT); // adding a contact
+ $removecontact = optional_param('removecontact', 0, PARAM_INT); // removing a contact
+ $blockcontact = optional_param('blockcontact', 0, PARAM_INT); // blocking a contact
+ $unblockcontact = optional_param('unblockcontact', 0, PARAM_INT); // unblocking a contact
+
/// Check the user we are talking to is valid
if (! $user = get_record("user", "id", $userid)) {
error("User ID was incorrect");
}
+/// Possibly change some contacts if requested
+
+ if ($addcontact and confirm_sesskey()) {
+ add_to_log(SITEID, 'message', 'add contact', 'history.php?user1='.$addcontact.'&user2='.$USER->id, $addcontact);
+ message_add_contact($addcontact);
+ }
+ if ($removecontact and confirm_sesskey()) {
+ add_to_log(SITEID, 'message', 'remove contact', 'history.php?user1='.$removecontact.'&user2='.$USER->id, $removecontact);
+ message_remove_contact($removecontact);
+ }
+ if ($blockcontact and confirm_sesskey()) {
+ add_to_log(SITEID, 'message', 'block contact', 'history.php?user1='.$blockcontact.'&user2='.$USER->id, $blockcontact);
+ message_block_contact($blockcontact);
+ }
+ if ($unblockcontact and confirm_sesskey()) {
+ add_to_log(SITEID, 'message', 'unblock contact', 'history.php?user1='.$unblockcontact.'&user2='.$USER->id, $unblockcontact);
+ message_unblock_contact($unblockcontact);
+ }
+
/// By default, print frameset to contain all the various panes
if (!$frame) {
$USER->message_user_refresh[$user->id] = time();
@@ -41,26 +65,47 @@
switch ($frame) { /// Put data into all the frames
case 'info': /// Print the top frame with information and links
- print_header();
+ $THEME->body = $THEME->cellcontent2;
+ print_header('','','','','',false,'','',false,'leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"');
echo '';
- echo '| '.print_user_picture($user->id, SITEID, $user->picture, true, true, true, 'userwindow').' | ';
- echo '';
+ echo ' | ';
+ echo print_user_picture($user->id, SITEID, $user->picture, true, true, true, 'userwindow').' | ';
+ echo '';
+
echo fullname($user);
- echo ' ';
+ echo ' '; /// Print login status of this user
if ($user->lastaccess) {
- $datestring = get_string('ago', 'message', format_time(time() - $user->lastaccess));
+ if (time() - $user->lastaccess > $CFG->message_offline_time) {
+ echo get_string('offline', 'message');
+ } else {
+ echo get_string("lastaccess").":".get_string('ago', 'message', format_time(time() - $user->lastaccess));
+ }
} else {
- $datestring = get_string("never");
+ echo get_string("lastaccess").":". get_string("never");
}
- echo get_string("lastaccess").":", $datestring;
echo '';
echo ' ';
- message_history_link($user->id);
- echo ' | ';
- echo '
';
+ echo '';
+ if ($contact = get_record('message_contacts', 'userid', $USER->id, 'contactid', $user->id)) {
+ if ($contact->blocked) {
+ message_contact_link($user->id, 'add', false, 'user.php?frame=info'); echo " ";
+ message_contact_link($user->id, 'unblock', false, 'user.php?frame=info'); echo " ";
+ } else {
+ message_contact_link($user->id, 'remove', false, 'user.php?frame=info'); echo " ";
+ message_contact_link($user->id, 'block', false, 'user.php?frame=info'); echo " ";
+ }
+ } else {
+ message_contact_link($user->id, 'add', false, 'user.php?frame=info'); echo " ";
+ message_contact_link($user->id, 'block', false, 'user.php?frame=info'); echo " ";
+ }
+ message_history_link($user->id, 0, false, '', '', 'icon');
+ echo '
';
+
+ echo '';
+
echo '