]> git.mjollnir.org Git - moodle.git/commitdiff
Emailing is now working well, and more GUI cleanups
authormoodler <moodler>
Sat, 1 Jan 2005 16:00:35 +0000 (16:00 +0000)
committermoodler <moodler>
Sat, 1 Jan 2005 16:00:35 +0000 (16:00 +0000)
lang/en/message.php
message/index.php
message/lib.php
message/user.php

index ec1a770cf1df0f7e48096bf3ef87a0e536433cc3..f766d9d279ca716062c92319a0b2382243914dc7 100644 (file)
@@ -11,6 +11,7 @@ $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['emailtagline'] = 'This email is a copy of a message sent to you at \"$a\"';
 $string['emptysearchstring'] = 'You must search for something';
 $string['includeblockedusers'] = 'Include blocked users';
 $string['incomingcontacts'] = 'Incoming Contacts ($a)';
index fd3983f36932ae816a72441213137097b0056dc2..2fecc812434933ede4b4fe2006d20b0917f3780e 100644 (file)
@@ -12,6 +12,14 @@ $addcontact     = optional_param('addcontact',     0, PARAM_INT); // adding a co
 $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
+$popup          = optional_param('popup', false, PARAM_ALPHA);    // If set then starts a new popup window
+
+if ($popup) {
+    print_header();
+    echo '<script language="JavaScript" type="text/javascript">'."\n openpopup('/message/index.php', 'message', 'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500', 0);\n</script>";
+    redirect("$CFG->wwwroot/");
+    exit;
+}
 
 if ($addcontact and confirm_sesskey()) {
     add_to_log(SITEID, 'message', 'add contact', 'history.php?user1='.$addcontact.'&amp;user2='.$USER->id, $addcontact);
index 46006a2f4e51fb7aef21e6ab868565eb8338a2a1..1ace85cf68df5b2593e3ea6f2af449fc2b774c0f 100644 (file)
@@ -64,7 +64,9 @@ function message_print_contacts() {
             print_user_picture($contact->id, SITEID, $contact->picture, 20, false, true, 'userwindow');
             echo '</td>';
             echo '<td class="message_contact">';
-            link_to_popup_window("/message/user.php?id=$contact->id", "message_$contact->id", $fullnamelink, 400, 400, get_string('sendmessageto', 'message', $fullname));
+            link_to_popup_window("/message/user.php?id=$contact->id", "message_$contact->id", 
+                                 $fullnamelink, 500, 500, get_string('sendmessageto', 'message', $fullname),
+                                 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500');
             echo '</td>';
             echo '<td class="message_link">'.$strcontact.'</td>';
             echo '</tr>';
@@ -97,7 +99,9 @@ function message_print_contacts() {
             print_user_picture($contact->id, SITEID, $contact->picture, 20, false, true, 'userwindow');
             echo '</td>';
             echo '<td class="message_contact">';
-            link_to_popup_window("/message/user.php?id=$contact->id", "message_$contact->id", $fullnamelink, 400, 400, get_string('sendmessageto', 'message', $fullname));
+            link_to_popup_window("/message/user.php?id=$contact->id", "message_$contact->id", 
+                                 $fullnamelink, 500, 500, get_string('sendmessageto', 'message', $fullname),
+                                 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500');
             echo '</td>';
             echo '<td class="message_link">'.$strcontact.'</td>';
             echo '</tr>';
@@ -154,7 +158,9 @@ function message_print_contacts() {
             print_user_picture($messageuser->useridfrom, SITEID, $messageuser->picture, 20, false, true, 'userwindow');
             echo '</td>';
             echo '<td class="message_contact">';
-            link_to_popup_window("/message/user.php?id=$messageuser->useridfrom", "message_$messageuser->useridfrom", $fullnamelink, 400, 400, get_string('sendmessageto', 'message', $fullname));
+            link_to_popup_window("/message/user.php?id=$messageuser->useridfrom", "message_$messageuser->useridfrom", 
+                                 $fullnamelink, 500, 500, get_string('sendmessageto', 'message', $fullname),
+                                 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500');
             echo '</td>';
             echo '<td class="message_link">'.$strcontact.'&nbsp;'.$strblock.'</td>';
             echo '</tr>';
@@ -224,7 +230,7 @@ function message_print_settings() {
 
         set_user_preferences($pref);
         
-        redirect($ME, get_string('settingssaved', 'message'), 3);
+        redirect($ME, get_string('settingssaved', 'message'), 1);
     }
 
     $cbshowmessagewindow = (get_user_preferences('message_showmessagewindow', 1) == '1') ? 'checked="checked"' : '';
@@ -337,7 +343,9 @@ function message_print_search_results($frm) {
                 print_user_picture($user->id, SITEID, $user->picture, 20, false, true, 'userwindow');
                 echo '</td>';
                 echo '<td class="message_contact">';
-                link_to_popup_window("/message/user.php?id=$user->id", "message_$user->id", fullname($user), 400, 400, get_string('sendmessageto', 'message', fullname($user)));
+                link_to_popup_window("/message/user.php?id=$user->id", "message_$user->id", fullname($user), 
+                                     500, 500, get_string('sendmessageto', 'message', fullname($user)),
+                                     'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500');
                 echo '</td>';
                 
                 echo '<td class="message_link">'.$strcontact.'</td>';
@@ -500,7 +508,9 @@ function message_print_user ($user=false, $iscontact=false, $isblocked=false) {
             message_contact_link($user->id, 'block');
         }
         echo '<br />';
-        link_to_popup_window("/message/user.php?id=$user->id", "message_$user->id", fullname($user), 400, 400, get_string('sendmessageto', 'message', fullname($user)));
+        link_to_popup_window("/message/user.php?id=$user->id", "message_$user->id", 
+                             fullname($user), 400, 400, get_string('sendmessageto', 'message', fullname($user)),
+                             'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500');
     }
 }
 
@@ -819,11 +829,64 @@ function message_get_history($user1, $user2) {
 
 function message_format_message(&$message, &$user, $format='') {
     if (empty($format)) {
-        $format = get_string('strftimemessage', 'chat');
+        $format = get_string('strftimedaytime');
     }
     $time = userdate($message->timecreated, $format);
-    return '<p><font size="-1"><b>'.addslashes($user->firstname).'</b> ['.$time.']: '.format_text($message->message, $message->format).'</font></p>';
+    return '<p><font size="-1"><strong>'.s($user->firstname).'</strong> ['.$time.']: '.
+            format_text($message->message, $message->format).'</font></p>';
 }
 
+/*
+ * Inserts a message into the database, but also forwards it
+ * via other means if appropriate.
+ */
+function message_post_message($userfrom, $userto, $message, $format, $messagetype) {
+
+    global $CFG, $SITE;
+
+/// Save the new message in the database
+
+    $savemessage = NULL;
+    $savemessage->useridfrom    = $userfrom->id;
+    $savemessage->useridto      = $userto->id;
+    $savemessage->message       = $message;
+    $savemessage->format        = $format;
+    $savemessage->timecreated   = time();
+    $savemessage->messagetype   = 'direct';
+
+    if (!insert_record('message', $savemessage)) {
+        return false;
+    }
+
+
+/// Check to see if anything else needs to be done with it
+
+    $preference = (object)get_user_preferences(NULL, NULL, $userto->id);
+
+    if (!empty($preference->message_emailmessages)) {  // Receiver wants mail forwarding
+        if ((time() - $userto->lastaccess) > ((int)$preference->message_emailtimenosee * 60)) { // Long enough
+
+            $message = stripslashes_safe($message);
+            $tagline = get_string('emailtagline', 'message', $SITE->shortname);
+            
+            $messagesubject = message_shorten_message(strip_tags($message), 30).'...';
+
+            $messagetext = format_text_email($message, $format).
+                           "\n\n--\n".$tagline."\n"."$CFG->wwwroot/message/index.php?popup=1";
+
+            if ($preference->message_emailformat == FORMAT_HTML) {
+                $messagehtml  = format_text($message, $format);
+                $messagehtml .= '<hr /><p><a href="'.$CFG->wwwroot.'/message/index.php?popup=1">'.$tagline.'</a></p>';
+            } else {
+                $messagehtml = NULL;
+            }
+
+            $userto->email = $preference->message_emailaddress;   // Use custom messaging address
+            email_to_user($userto, $userfrom, $messagesubject, $messagetext, $messagehtml);
+        }
+    }
+
+    return true;
+}
 
 ?>
index 37db3d8f25840d9a1cd7f139ce760275e24b9acf..645c32d0cc2cca279adb6f8c78ce7119c2f76b22 100644 (file)
@@ -80,7 +80,7 @@
             if ($messages = get_records_select('message', "useridto = '$USER->id' AND useridfrom = '$user->id'", 
                                                'timecreated')) {
                 foreach ($messages as $message) {
-                    $time = userdate($message->timecreated, get_string('strftimemessage', 'chat'));
+                    $time = userdate($message->timecreated, get_string('strftimedaytime'));
 
                     $options = NULL;
                     $options->para = false;
             if ($message and confirm_sesskey()) {   /// Current user has just sent a message
 
             /// Save it to the database...
-                $savemessage = NULL;
-                $savemessage->useridfrom    = $USER->id;
-                $savemessage->useridto      = $user->id;
-                $savemessage->message       = $message;
-                $savemessage->format        = $format;
-                $savemessage->timecreated   = time();
-                $savemessage->messagetype   = 'direct';
-
-                if (!insert_record('message', $savemessage)) {
-                    notify('Error: Message was not sent!!');
-                }
+                message_post_message($USER, $user, $message, $format, 'direct');
 
             /// Format the message as HTML
                 $options = NULL;