$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';
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() {
}
/// 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 '<tr><td class="message_pix">';
print_user_picture($contact->id, SITEID, $contact->picture, 20, false, true, 'userwindow');
}
/// 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 '<tr><td class="message_pix">';
print_user_picture($contact->id, SITEID, $contact->picture, 20, false, true, 'userwindow');
$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 '<tr><td class="message_pix">';
print_user_picture($messageuser->useridfrom, SITEID, $messageuser->picture, 20, false, true, 'userwindow');
$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 '<tr><td class="message_pix">';
print_user_picture($user->id, SITEID, $user->picture, 20, false, true, 'userwindow');
echo '<td class="message_link">'.$strcontact.'</td>';
echo '<td class="message_link">'.$strblock.'</td>';
+ echo '<td class="message_link">'.$strhistory.'</td>';
echo '</tr>';
}
echo '</table>';
message_print_user($userto, $tocontact, $toblocked);
echo '</td>';
echo '<td class="message_summary">'.message_get_fragment($message->message, $keywords);
- echo '<br /><div class="message_summary_link">'.message_history_link($message->useridto, $message->useridfrom, true, $keywordstring, $datestring, $strcontext).'</div>';
+ echo '<br /><div class="message_summary_link">';
+ message_history_link($message->useridto, $message->useridfrom, true, $keywordstring, $datestring, $strcontext);
+ echo '</div>';
echo '</td>';
echo '<td class="message_date">'.userdate($message->timecreated, $dateformat).'</td>';
echo "</tr>\n";
/// 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;
$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 = '<a target="message_history_'.$userid.'" title="'.$str->messagehistory.'" href="'.$CFG->wwwroot.'/message/history.php?user1='.$userid.'" onclick="return openpopup(\'/message/history.php?user1='.$userid.'\', \'message_history_'.$userid.'\', \'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500\', 0);"><img src="'.$CFG->pixpath.'/t/log.gif" height="11" width="11" border="0"></a>';
- break;
case 'block':
- $output = '<a href="index.php?tab=contacts&blockcontact='.$userid.
+ $output = '<a target="message" href="'.$script.'&blockcontact='.$userid.
'&sesskey='.$USER->sesskey.'" title="'.$str->blockcontact.'">'.
'<img src="'.$CFG->pixpath.'/t/go.gif" height="11" width="11" border="0"></a>';
break;
case 'unblock':
- $output = '<a href="index.php?tab=contacts&unblockcontact='.$userid.
+ $output = '<a target="message" href="'.$script.'&unblockcontact='.$userid.
'&sesskey='.$USER->sesskey.'" title="'.$str->unblockcontact.'">'.
'<img src="'.$CFG->pixpath.'/t/stop.gif" height="11" width="11" border="0"></a>';
break;
case 'remove':
- $output = '<a href="index.php?tab=contacts&removecontact='.$userid.
+ $output = '<a target="message" href="'.$script.'&removecontact='.$userid.
'&sesskey='.$USER->sesskey.'" title="'.$str->removecontact.'">'.
'<img src="'.$CFG->pixpath.'/t/user.gif" height="11" width="11" border="0"></a>';
break;
case 'add':
default:
- $output = '<a href="index.php?tab=contacts&addcontact='.$userid.
+ $output = '<a target="message" href="'.$script.'&addcontact='.$userid.
'&sesskey='.$USER->sesskey.'" title="'.$str->addcontact.'">'.
'<img src="'.$CFG->pixpath.'/t/usernot.gif" height="11" width="11" border="0"></a>';
$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();
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 '<table width="100%" cellpadding="0" cellspacing="0"><tr>';
- echo '<td>'.print_user_picture($user->id, SITEID, $user->picture, true, true, true, 'userwindow').'</td>';
- echo '<td>';
+ echo '<td width="100">';
+ echo print_user_picture($user->id, SITEID, $user->picture, true, true, true, 'userwindow').'</td>';
+ echo '<td valign="middle" align="center">';
+
echo fullname($user);
- echo '<br /><font size="1">';
+ echo '<br /><font size="1">'; /// 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 '</font>';
echo '<br />';
- message_history_link($user->id);
- echo '</td>';
- echo '</tr></table>';
+ echo '<div class="message_users">';
+ 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 '</div>';
+
+ echo '</td></tr></table>';
+
echo '</table></table></body>'; // Close possible theme tables off
- $USER->message_user_refresh[$user->id] = time();
+ $USER->message_user_refresh[$user->id] = time(); // Remember this update
break;
case 'messages': /// Print the main frame containing the current chat
echo "parent.messages.scroll(1,5000000);\n";
echo "</script>\n\n";
}
- if ($user->lastaccess > $USER->message_user_refresh[$user->id]) {
+
+ // Update the info pane, but only if the data there is getting too old
+ $timenow = time();
+ if ($timenow - $user->lastaccess > $CFG->message_offline_time) { // Offline
+ if ($timenow - $USER->message_user_refresh[$user->id] < 30) { // It's just happened so refresh
+ $refreshinfo = true;
+ }
+
+ } else { // Online
+ if ($timenow - $USER->message_user_refresh[$user->id] > 30) { // Been a while
+ $refreshinfo = true;
+ }
+ }
+ if (!empty($refreshinfo)) {
echo '<script language="Javascript">';
echo "parent.info.document.location.replace('$CFG->wwwroot/message/user.php?id=$user->id&frame=info');\n";
echo "</script>\n\n";