### Eclipse Workspace Patch 1.0
#P moodle
Index: message/settings.html
===================================================================
RCS file: /cvsroot/moodle/moodle/message/settings.html,v
retrieving revision 1.7
diff -u -r1.7 settings.html
--- message/settings.html	18 Dec 2006 17:10:36 -0000	1.7
+++ message/settings.html	18 Dec 2006 21:54:30 -0000
@@ -20,6 +20,10 @@
         <td align="right"><input type="checkbox" name="usehtmleditor" id="usehtmleditor" <?php echo $cbusehtmleditor ?>  /></td>
         <td colspan="2"><label for="usehtmleditor"><?php print_string('htmleditor') ?></label></td>
     </tr>
+    <tr valign="top">
+        <td align="right"><input type="checkbox" name="noframes" id="noframes" <?php echo $cbnoframes ?>  /></td>
+        <td colspan="2"><label for="noframes"><?php print_string('noframes', 'message') ?></label></td>
+    </tr>
 
     
     <tr valign="top">
Index: message/send.php
===================================================================
RCS file: /cvsroot/moodle/moodle/message/send.php,v
retrieving revision 1.15
diff -u -r1.15 send.php
--- message/send.php	18 Dec 2006 09:04:34 -0000	1.15
+++ message/send.php	18 Dec 2006 21:54:30 -0000
@@ -56,7 +56,7 @@
         }
     }
 
-    if ($message and confirm_sesskey()) {   /// Current user has just sent a message
+    if ($message!='' and confirm_sesskey()) {   /// Current user has just sent a message
 
     /// Save it to the database...
         $messageid = message_post_message($USER, $user, addslashes($message), $format, 'direct');
Index: message/discussion.php
===================================================================
RCS file: /cvsroot/moodle/moodle/message/discussion.php,v
retrieving revision 1.6
diff -u -r1.6 discussion.php
--- message/discussion.php	18 Dec 2006 09:04:38 -0000	1.6
+++ message/discussion.php	18 Dec 2006 21:54:30 -0000
@@ -21,8 +21,11 @@
         error("User ID was incorrect");
     }
 
-/// Print frameset to contain all the various panes
-    @header('Content-Type: text/html; charset=utf-8');
+/// Check if frame&jsless mode selected
+    if (!get_user_preferences('message_noframes', 0)) {
+
+    /// Print frameset to contain all the various panes
+        @header('Content-Type: text/html; charset=utf-8');
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
     <html>
@@ -43,3 +46,162 @@
               scrolling="no"  marginwidth="2" marginheight="2" frameborder="0" />
      </frameset>
     </html>
+
+<?php
+        die;
+    }
+
+/// user wants frame less mode
+
+    $start    = optional_param('start', time(), PARAM_INT);
+    $message  = optional_param('message', '', PARAM_CLEAN);
+    $format   = optional_param('format', FORMAT_MOODLE, PARAM_INT);
+    $refresh  = optional_param('refresh', '', PARAM_RAW);
+    
+/// Check that the user is not blocking us!!
+    if ($contact = get_record('message_contacts', 'userid', $user->id, 'contactid', $USER->id)) {
+        if ($contact->blocked and !has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
+            print_heading(get_string('userisblockingyou', 'message'));
+            exit;
+        }
+    }
+    if (get_user_preferences('message_blocknoncontacts', 0, $user->id)) {  // User is blocking non-contacts
+        if (empty($contact)) {   // We are not a contact!
+            print_heading(get_string('userisblockingyounoncontact', 'message'));
+            exit;
+        }
+    }
+
+    if (empty($refresh) and data_submitted() and $message!='' and confirm_sesskey()) {
+        message_post_message($USER, $user, $message, $format, 'direct');
+    }
+
+
+    $userfullname = fullname($user);
+    $mefullname   = fullname($USER);
+
+    print_header();
+    echo '<div class="user">';
+    echo print_user_picture($user->id, SITEID, $user->picture, true, true, true, 'userwindow');
+    echo '<div class="name">'.$userfullname.'</div>';
+    echo '<div class="commands">';
+    if ($contact = get_record('message_contacts', 'userid', $USER->id, 'contactid', $user->id)) {
+         if ($contact->blocked) {
+             message_contact_link($user->id, 'add', false, 'discussion.php?id='.$user->id, true); 
+             message_contact_link($user->id, 'unblock', false, 'discussion.php?id='.$user->id, true); 
+         } else {
+             message_contact_link($user->id, 'remove', false, 'discussion.php?id='.$user->id, true); 
+             message_contact_link($user->id, 'block', false, 'discussion.php?id='.$user->id, true); 
+         }
+    } else {
+         message_contact_link($user->id, 'add', false, 'discussion.php?id='.$user->id, true);
+         message_contact_link($user->id, 'block', false, 'discussion.php?id='.$user->id, true);
+    }
+    message_history_link($user->id, 0, false, '', '', 'both');
+    echo '</div>';
+    echo '</div>'; // class="suser"
+    
+    echo '<div class="send">';
+    echo '<form name="editing" method="post" action="discussion.php">';
+    echo '<input type="hidden" name="id" value="'.$user->id.'" />';
+    echo '<input type="hidden" name="start" value="'.$start.'" />';
+    echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
+
+    $usehtmleditor = (can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0));
+    if ($usehtmleditor) {
+        echo '<table align="center"><tr><td align="center">';
+        print_textarea($usehtmleditor, 8, 34, 0, 0, 'message', '');
+        echo '</td></tr></table>';
+        use_html_editor('message', 'formatblock subscript superscript copy cut paste clean undo redo justifyleft justifycenter justifyright justifyfull lefttoright righttoleft insertorderedlist insertunorderedlist outdent indent inserthorizontalrule createanchor nolink inserttable');
+        echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
+    } else {
+        print_textarea(false, 5, 34, 0, 0, 'message', '');
+        echo '<input type="hidden" name="format" value="'.FORMAT_MOODLE.'" />';
+    }
+    echo '<br /><input type="submit" value="'.get_string('sendmessage', 'message').'" />';
+    echo '<input type="submit" value="'.get_string('refresh', 'message').'" />';
+    echo '</form>';
+    echo '</div>';
+    
+    echo '<div class="messages">';
+
+    $allmessages = array();
+    $playbeep = true;
+    $options = new object();
+    $options->para = false;
+    $options->newlines = true;
+
+    if ($messages = get_records_select('message_read', "(useridto = '$USER->id' AND useridfrom = '$userid' AND timeread > '$start') OR (useridto = '$userid' AND useridfrom = '$USER->id' AND timeread > '$start')")) {
+        foreach ($messages as $message) {
+            $time = userdate($message->timecreated, get_string('strftimedaytime'));
+            
+            if ($message->useridfrom == $USER->id) {
+                $fullname = $mefullname;  
+            } else {
+                $fullname = $userfullname;  
+            }
+
+            $printmessage = format_text($message->message, $message->format, $options, 0);
+            $printmessage = str_replace("\r", ' ', $printmessage);
+            $printmessage = str_replace("\n", ' ', $printmessage);
+            $printmessage = '<div class="message other"><span class="author">'.$fullname.'</span> '.
+                '<span class="time">['.$time.']</span>: '.
+                '<span class="content">'.$printmessage.'</span></div>';
+            $allmessages[$message->timecreated] = $printmessage;
+        }
+    }                                       
+
+    if ($messages = get_records_select('message', "useridto = '$userid' AND useridfrom = '$USER->id'")) {
+        foreach ($messages as $message) {
+            $time = userdate($message->timecreated, get_string('strftimedaytime'));
+
+            $printmessage = format_text($message->message, $message->format, $options, 0);
+            $printmessage = str_replace("\r", ' ', $printmessage);
+            $printmessage = str_replace("\n", ' ', $printmessage);
+            $printmessage = '<div class="message other"><span class="author">'.$mefullname.'</span> '.
+                '<span class="time">['.$time.']</span>: '.
+                '<span class="content">'.$printmessage.'</span></div>';
+            $allmessages[$message->timecreated] = $printmessage; // hack alert - let's hope users will not post exactly at the same time
+        }
+    }
+
+    if ($messages = get_records_select('message', "useridto = '$USER->id' AND useridfrom = '$userid'")) {
+        foreach ($messages as $message) {
+            $time = userdate($message->timecreated, get_string('strftimedaytime'));
+
+            $printmessage = format_text($message->message, $message->format, $options, 0);
+            $printmessage = str_replace("\r", ' ', $printmessage);
+            $printmessage = str_replace("\n", ' ', $printmessage);
+            $printmessage = '<div class="message other"><span class="author">'.$userfullname.'</span> '.
+                '<span class="time">['.$time.']</span>: '.
+                '<span class="content">'.$printmessage.'</span></div>';
+            $allmessages[$message->timecreated] = $printmessage;
+
+            /// Move the entry to the other table
+
+            $messageid = $message->id;
+            unset($message->id);
+            $message->timeread = time();
+            $message = addslashes_object($message);
+            if (insert_record('message_read', $message)) {
+                delete_records('message', 'id', $messageid);
+            }
+            if ($message->timecreated < $start) {
+                $start = $message->timecreated; // move start back so that we see all current history 
+            } 
+        }
+        if (get_user_preferences('message_beepnewmessage', 0)) {
+            $playbeep = true;
+        }
+    }
+
+    krsort($allmessages);
+
+    foreach ($allmessages as $message) {
+        echo $message;
+    }
+    echo '</div>';
+
+    
+    print_footer('none');
+?>
\ No newline at end of file
Index: message/refresh.php
===================================================================
RCS file: /cvsroot/moodle/moodle/message/refresh.php,v
retrieving revision 1.8
diff -u -r1.8 refresh.php
--- message/refresh.php	11 Nov 2006 17:23:28 -0000	1.8
+++ message/refresh.php	18 Dec 2006 21:54:30 -0000
@@ -52,7 +52,7 @@
         foreach ($messages as $message) {
             $time = userdate($message->timecreated, get_string('strftimedaytime'));
 
-            $options = NULL;
+            $options = new object();
             $options->para = false;
             $options->newlines = true;
             $printmessage = format_text($message->message, $message->format, $options, 0);
@@ -67,7 +67,7 @@
 
             /// Move the entry to the other table
             $message->timeread = time();
-            $message->message = addslashes($message->message);
+            $message = addslashes_object($message);
             $messageid = $message->id;
             unset($message->id);
             if (insert_record('message_read', $message)) {
Index: message/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/message/lib.php,v
retrieving revision 1.53
diff -u -r1.53 lib.php
--- message/lib.php	18 Dec 2006 17:10:36 -0000	1.53
+++ message/lib.php	18 Dec 2006 21:54:30 -0000
@@ -258,6 +258,7 @@
         $pref['message_beepnewmessage'] = (isset($frm->beepnewmessage)) ? '1' : '0';
         $pref['message_blocknoncontacts'] = (isset($frm->blocknoncontacts)) ? '1' : '0';
         $pref['message_usehtmleditor'] = (isset($frm->usehtmleditor)) ? '1' : '0';
+        $pref['message_noframes'] = (isset($frm->noframes)) ? '1' : '0';
         $pref['message_emailmessages'] = (isset($frm->emailmessages)) ? '1' : '0';
         $pref['message_emailtimenosee'] = ((int)$frm->emailtimenosee > 0) ? (int)$frm->emailtimenosee : '10';
         $pref['message_emailaddress'] = (!empty($frm->emailaddress)) ? $frm->emailaddress : $USER->email;
@@ -272,6 +273,7 @@
     $cbbeepnewmessage = (get_user_preferences('message_beepnewmessage', 0) == '1') ? 'checked="checked"' : '';
     $cbblocknoncontacts = (get_user_preferences('message_blocknoncontacts', 0) == '1') ? 'checked="checked"' : '';
     $cbusehtmleditor = (get_user_preferences('message_usehtmleditor', 0) == '1') ? 'checked="checked"' : '';
+    $cbnoframes = (get_user_preferences('message_noframes', 0) == '1') ? 'checked="checked"' : '';
     $cbemailmessages = (get_user_preferences('message_emailmessages', 1) == '1') ? 'checked="checked"' : '';
     $txemailaddress = get_user_preferences('message_emailaddress', $USER->email);
     $txemailtimenosee = get_user_preferences('message_emailtimenosee', 10);
