]> git.mjollnir.org Git - moodle.git/commitdiff
Some tidy up of some code and the information display in a discussion window.
authormoodler <moodler>
Mon, 3 Jan 2005 15:20:56 +0000 (15:20 +0000)
committermoodler <moodler>
Mon, 3 Jan 2005 15:20:56 +0000 (15:20 +0000)
The online status of the other user is now more accurate, and will not
keep updating once the user has gone offline.

lang/en/message.php
message/lib.php
message/user.php

index c8bb495d85fb1913e2185f2cc53461901dbf3712..0ffd16566832debb002a0373712e9a90dfefb9da 100644 (file)
@@ -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';
index 31d5b4bce69faab093f0013ec74dc9111fcf2b6f..7745c55f1d68d172d580b2d1a3b8623349f80fc2 100644 (file)
@@ -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 '<tr><td class="message_pix">';
             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 '<tr><td class="message_pix">';
             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 '<tr><td class="message_pix">';
             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 '<tr><td class="message_pix">';
                 print_user_picture($user->id, SITEID, $user->picture, 20, false, true, 'userwindow');
@@ -359,6 +363,7 @@ function message_print_search_results($frm) {
                 
                 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>';
@@ -471,7 +476,9 @@ function message_print_search_results($frm) {
                 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";
@@ -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 = '<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&amp;blockcontact='.$userid.
+            $output = '<a target="message" href="'.$script.'&amp;blockcontact='.$userid.
                    '&amp;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&amp;unblockcontact='.$userid.
+            $output = '<a target="message" href="'.$script.'&amp;unblockcontact='.$userid.
                    '&amp;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&amp;removecontact='.$userid.
+            $output = '<a target="message" href="'.$script.'&amp;removecontact='.$userid.
                    '&amp;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&amp;addcontact='.$userid.
+            $output = '<a target="message" href="'.$script.'&amp;addcontact='.$userid.
                    '&amp;sesskey='.$USER->sesskey.'" title="'.$str->addcontact.'">'.
                    '<img src="'.$CFG->pixpath.'/t/usernot.gif" height="11" width="11" border="0"></a>';
 
index 781a449b50a120f28166bf5a2fd8fc3b202d2f5f..8b91c24699b11b12483ebc3f66083a29206e4440 100644 (file)
     $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.'&amp;user2='.$USER->id, $addcontact);
+        message_add_contact($addcontact);
+    }
+    if ($removecontact and confirm_sesskey()) {
+        add_to_log(SITEID, 'message', 'remove contact', 'history.php?user1='.$removecontact.'&amp;user2='.$USER->id, $removecontact);
+        message_remove_contact($removecontact);
+    }
+    if ($blockcontact and confirm_sesskey()) {
+        add_to_log(SITEID, 'message', 'block contact', 'history.php?user1='.$blockcontact.'&amp;user2='.$USER->id, $blockcontact);
+        message_block_contact($blockcontact);
+    }
+    if ($unblockcontact and confirm_sesskey()) {
+        add_to_log(SITEID, 'message', 'unblock contact', 'history.php?user1='.$unblockcontact.'&amp;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 "&nbsp;";
+                     message_contact_link($user->id, 'unblock', false, 'user.php?frame=info'); echo "&nbsp;";
+                 } else {
+                     message_contact_link($user->id, 'remove', false, 'user.php?frame=info'); echo "&nbsp;";
+                     message_contact_link($user->id, 'block', false, 'user.php?frame=info'); echo "&nbsp;";
+                 }
+            } else {
+                 message_contact_link($user->id, 'add', false, 'user.php?frame=info'); echo "&nbsp;";
+                 message_contact_link($user->id, 'block', false, 'user.php?frame=info'); echo "&nbsp;";
+            }
+            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";