fixed comp_in_new handling
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 24 May 2002 15:37:47 +0000 (15:37 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 24 May 2002 15:37:47 +0000 (15:37 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2857 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/page_header.php
src/compose.php
src/read_body.php
src/right_main.php
src/search.php

index 940cefe..dc892c6 100644 (file)
@@ -65,7 +65,8 @@ function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
     if ($session !== false) {
        $compose_uri = 'src/compose.php?mailbox='. urlencode($mailbox).'&attachedmessages=true&session='."$session";
     } else {
-        $compose_uri = 'src/compose.php';
+        $compose_uri = 'src/compose.php?newmessage=1';
+       $session = 0;
     }
 
     switch ( $module ) {
@@ -79,12 +80,20 @@ function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
                 }
                 $js = "\n".'<script language="JavaScript" type="text/javascript">' .
                     "\n<!--\n";
-                $js .= "function comp_in_new() {\n".
-                     "    var newwin = window.open(\"".$base_uri.$compose_uri. '"'.
-                     ", \"compose_window\",
-                \"width=".$compose_width.",height=$compose_height".
+                $js .= "function comp_in_new(new_mes, comp_uri) {\n".
+                    '    if (new_mes) { '."\n".
+                    "       comp_uri = \"../src/compose.php?newmessage=1\";\n".
+                    '    } else { '."\n".
+                    "       if (comp_uri =='') {\n".
+                    '           comp_uri = "'.$base_uri.$compose_uri."\";\n".
+                    '       }'. "\n".
+                    '    }'. "\n".
+                     '    var newwin = window.open(comp_uri' .
+                     ', "_blank",
+                "width='.$compose_width.",height=$compose_height".
                      ",scrollbars=yes,resizable=yes\");\n".
                      "}\n";
+
         $js .= "// -->\n".
                 "</script>\n";
         displayHtmlHeader ('Squirrelmail', $js);
@@ -92,6 +101,35 @@ function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
         displayHtmlHeader();
         $onload = $xtra;
         break;
+    case 'src/compose.php':
+        $js = '<script language="JavaScript" type="text/javascript">' .
+             "\n<!--\n" .
+             "function checkForm() {\n".
+                "var f = document.forms.length;\n".
+                "var i = 0;\n".
+                "var pos = -1;\n".
+                "while( pos == -1 && i < f ) {\n".
+                    "var e = document.forms[i].elements.length;\n".
+                    "var j = 0;\n".
+                    "while( pos == -1 && j < e ) {\n".
+                        "if ( document.forms[i].elements[j].type == 'text' ) {\n".
+                            "pos = j;\n".
+                        "}\n".
+                        "j++;\n".
+                    "}\n".
+                "i++;\n".
+                "}\n".
+                "if( pos >= 0 ) {\n".
+                    "document.forms[i-1].elements[pos].focus();\n".
+                "}\n".
+            "}\n";
+           
+        $js .= "// -->\n".
+                "</script>\n";
+        $onload = "onLoad=\"checkForm();\"";
+        displayHtmlHeader ('Squirrelmail', $js);
+        break;   
+
     default:
         $js = '<script language="JavaScript" type="text/javascript">' .
              "\n<!--\n" .
@@ -123,9 +161,17 @@ function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
                 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
                     $compose_height = '550';
                 }
-                $js .= "function comp_in_new() {\n".
-                     '    var newwin = window.open("'.$base_uri.$compose_uri . '"' .
-                     ', "compose_window",
+                $js .= "function comp_in_new(new_mes, comp_uri) {\n".
+                    '    if (new_mes) { '."\n".
+                    "       comp_uri = \"../src/compose.php?newmessage=1\";\n".
+                    '    } else { '."\n".
+                    "       if (comp_uri =='') {\n".
+                    '           comp_uri = "'.$base_uri.$compose_uri."\";\n".
+                    '       }'. "\n".
+                    '    }'. "\n".
+                    '    window.alert(comp_uri);'.
+                     '    var newwin = window.open(comp_uri' .
+                     ', "_blank",
                 "width='.$compose_width.",height=$compose_height".
                      ",scrollbars=yes,resizable=yes\");\n".
                      "}\n";
@@ -163,8 +209,7 @@ function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
         . "      <TD ALIGN=left>\n";
     $urlMailbox = urlencode($mailbox);
     if ($compose_new_win == '1') {
-        echo "<a href=$base_uri". "src/compose.php?mailbox=$urlMailbox target=".
-             '"compose_window" onClick="comp_in_new()">'. _("Compose"). '</a>';
+        echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(true,'')\">". _("Compose"). '</a>';
     }
     else {
         displayInternalLink ("src/compose.php?mailbox=$urlMailbox", _("Compose"), 'right');
index 90d6ff3..4bebdeb 100644 (file)
@@ -70,10 +70,10 @@ if (!isset($composesession)) {
     session_register('composesession');
 }
 
-if (!isset($session)) {
+if (!isset($session) || (isset($newmessage) && $newmessage)) {
     $session = "$composesession" +1; 
     $composesession = $session;        
-}    
+}     
 
 if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) {
     $mailbox = 'INBOX';
@@ -179,7 +179,7 @@ if (isset($send)) {
             exit();
         }
         if ($compose_new_win == '1') {
-            Header("Location: compose.php?mail_sent=yes&session=$composesession");
+            Header("Location: compose.php?mail_sent=yes");
         }
         else {
             Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
@@ -344,6 +344,10 @@ elseif (isset($sigappend)) {
         getAttachments(0, $session);
     }
 
+    if (isset($passed_id) && $passed_id && isset($ent_num) && $ent_num) {
+        getAttachments(0, $session);
+    }
+
     newMail($session);
     showInputForm($session);
     sqimap_logout($imapConnection);
@@ -510,12 +514,14 @@ function newMail () {
 
 function getAttachments($message, $session) {
     global $mailbox, $attachments, $attachment_dir, $imapConnection,
-           $ent_num, $forward_id, $draft_id, $username;
+           $ent_num, $forward_id, $draft_id, $username, $passed_id;
 
     if (isset($draft_id)) {
         $id = $draft_id;
-    } else {
+    } else if (isset($forward_id)) {
         $id = $forward_id;
+    } else {
+        $id = $passed_id;
     }
 
     if (!$message) {
index a784ab4..be7f05a 100644 (file)
@@ -690,19 +690,31 @@ if ($where && $what) {
 }
 echo _("Delete") . '</A>&nbsp;';
 if (($mailbox == $draft_folder) && ($save_as_draft)) {
-    echo '|&nbsp;<A HREF="' . $base_uri .
-         "src/compose.php?mailbox=$mailbox&amp;identity=$identity&amp;send_to=$url_to_string&amp;send_to_cc=$url_cc_string&amp;send_to_bcc=$url_bcc_string&amp;subject=$url_subj&amp;mailprio=$priority_level&amp;draft_id=$passed_id&amp;ent_num=$ent_num" . '"';
+    $comp_uri = $base_uri . "src/compose.php?mailbox=$mailbox&amp;".
+                "identity=$identity&amp;send_to=$url_to_string&amp;".
+               "send_to_cc=$url_cc_string&amp;send_to_bcc=$url_bcc_string&amp;".
+               "subject=$url_subj&amp;mailprio=$priority_level&amp;".
+               "draft_id=$passed_id&amp;ent_num=$ent_num&amp;passed_id=$passed_id";
+    
     if ($compose_new_win == '1') {
-        echo ' TARGET="compose_window" onClick="comp_in_new()"';
+        echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
+    } else {
+        echo '|&nbsp;<A HREF="' . $comp_uri .'"';
     }
     echo '>'.
          _("Resume Draft") . '</a>';
 }
 if ($mailbox == $sent_folder) {
-    echo '|&nbsp;<A HREF="' . $base_uri .
-         "src/compose.php?mailbox=$mailbox&amp;identity=$identity&amp;send_to=$url_to_string&amp;send_to_cc=$url_cc_string&amp;send_to_bcc=$url_bcc_string&amp;subject=$url_subj&amp;mailprio=$priority_level&amp;draft_id=$passed_id&amp;edit_as_new=1&amp;ent_num=$ent_num" . '"';
+    $comp_uri = $base_uri . "src/compose.php?mailbox=$mailbox&amp;".
+                "identity=$identity&amp;send_to=$url_to_string&amp;".
+               "send_to_cc=$url_cc_string&amp;send_to_bcc=$url_bcc_string&amp;".
+               "subject=$url_subj&amp;mailprio=$priority_level&amp;".
+               "ent_num=$ent_num&amp;passed_id=$passed_id&amp;edit_as_new=1";
+
     if ($compose_new_win == '1') {
-        echo ' TARGET="compose_window" onClick="comp_in_new()"';
+        echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
+    } else {
+        echo '|&nbsp;<A HREF="' . $comp_uri .'"';
     }
     echo '>'.
           _("Edit Message as New") . '</a>';
@@ -737,31 +749,49 @@ if ( !($where && $what) ) {
 
 echo                '</SMALL>' .
                 '</TD><TD WIDTH="33%" ALIGN="RIGHT">' .
-                   '<SMALL>' .
-                   '<A HREF="' . $base_uri . "src/compose.php?forward_id=$passed_id&amp;forward_subj=$url_subj&amp;".
-                    ($default_use_priority?"mailprio=$priority_level&amp;":'')
-                    ."mailbox=$urlMailbox&amp;ent_num=$ent_num\"";
-    if ($compose_new_win == '1') {
-        echo 'TARGET="compose_window" onClick="comp_in_new()"';
-    }
+                   '<SMALL>' ;
+
+$comp_uri = $base_uri . "src/compose.php?forward_id=$passed_id&amp;".
+            "forward_subj=$url_subj&amp;".
+           ($default_use_priority?"mailprio=$priority_level&amp;":'').
+            "mailbox=$urlMailbox&amp;ent_num=$ent_num";
+                          
+if ($compose_new_win == '1') {
+    echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
+} else {
+    echo '|&nbsp;<A HREF="' . $comp_uri .'"';
+}
+
     echo '>'.
     _("Forward") .
-    '</A>&nbsp;|&nbsp;' .
-                   '<A HREF="' . $base_uri . "src/compose.php?send_to=$url_replyto&amp;reply_subj=$url_subj&amp;".
-                    ($default_use_priority?"mailprio=$priority_level&amp;":'').
-                    "reply_id=$passed_id&amp;mailbox=$urlMailbox&amp;ent_num=$ent_num\"";
-    if ($compose_new_win == '1') {
-        echo 'TARGET="compose_window" onClick="comp_in_new()"';
-    }
+    '</A>&nbsp;|&nbsp;';
+
+$comp_uri = $base_uri . "src/compose.php?send_to=$url_replyto&amp;".
+            "reply_subj=$url_subj&amp;".
+            ($default_use_priority?"mailprio=$priority_level&amp;":'').
+            "reply_id=$passed_id&amp;mailbox=$urlMailbox&amp;ent_num=$ent_num";
+               
+if ($compose_new_win == '1') {
+    echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
+} else {
+    echo '|&nbsp;<A HREF="' . $comp_uri .'"';
+}
+
     echo '>'.
     _("Reply") .
-    '</A>&nbsp;|&nbsp;' .
-                   '<A HREF="' . $base_uri . "src/compose.php?send_to=$url_replytoall&amp;send_to_cc=$url_replytoallcc&amp;reply_subj=$url_subj&amp;".
-                    ($default_use_priority?"mailprio=$priority_level&amp;":'').
-                    "reply_id=$passed_id&amp;mailbox=$urlMailbox&amp;ent_num=$ent_num\"";
-    if ($compose_new_win == '1') {
-        echo 'TARGET="compose_window" onClick="comp_in_new()"';
-    }
+    '</A>&nbsp;|&nbsp;';
+
+$comp_uri = $base_uri . "src/compose.php?send_to=$url_replytoall&amp;".
+            "send_to_cc=$url_replytoallcc&amp;reply_subj=$url_subj&amp;".
+            ($default_use_priority?"mailprio=$priority_level&amp;":'').
+            "reply_id=$passed_id&amp;mailbox=$urlMailbox&amp;ent_num=$ent_num";
+
+if ($compose_new_win == '1') {
+    echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
+} else {
+    echo '|&nbsp;<A HREF="' . $comp_uri .'"';
+}
+
     echo '>'.
     _("Reply All") .
     '</A>&nbsp;&nbsp;' .
index 59d84f3..d858149 100644 (file)
@@ -108,7 +108,10 @@ if( isset($do_hook) && $do_hook ) {
 sqimap_mailbox_select($imapConnection, $mailbox);
 
 if (isset($composenew) && $composenew) {
-    displayPageHeader($color, $mailbox, 'comp_in_new();', $session);
+    $comp_uri = "../src/compose.php?mailbox=". urlencode($mailbox).
+               "&amp;session=$composesession&amp;attachedmessages=true&amp";
+
+    displayPageHeader($color, $mailbox, "comp_in_new(false,'$comp_uri');", false);
 } else {
     displayPageHeader($color, $mailbox);
 }
index a3580a7..1c29fe0 100644 (file)
@@ -182,7 +182,9 @@ if ($mailbox == 'All Folders') {
 }
 
 if (isset($composenew) && $composenew) {
-    displayPageHeader($color, $mailbox, 'comp_in_new('.$session.',true);');
+    $comp_uri = "../src/compose.php?mailbox=". urlencode($mailbox).
+               "&amp;session=$composesession&amp;attachedmessages=true&amp";
+    displayPageHeader($color, $mailbox, "comp_in_new(false,'$comp_uri');", false);
 } else {
     displayPageHeader($color, $mailbox);
 }