Fixed/restored reply focus functionality
[squirrelmail.git] / functions / page_header.php
index 6ece0a393a05f0658628c5368bdaea847ad0daa9..a7812b526b77302c2998cbe4c26fbbcf0bd5ad6d 100644 (file)
@@ -3,11 +3,10 @@
 /**
  * page_header.php
  *
- * Copyright (c) 1999-2005 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
  * Prints the page header (duh)
  *
+ * @copyright © 1999-2005 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
  */
@@ -57,6 +56,8 @@ function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = true
              $base_uri . 'themes/css/'.$custom_css.'">';
     }
 
+    echo '<link rel="stylesheet" type="text/css" href="'. $base_uri .'templates/default/squirrelmail.css">';
+
     if ($squirrelmail_language == 'ja_JP') {
         /*
          * force correct detection of charset, when browser does not follow
@@ -141,10 +142,25 @@ function displayInternalLink($path, $text, $target='') {
  * @return void
  */
 
-function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = 'onload="checkForm();"') {
-    global $hide_sm_attributions, $frame_top,
+function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
+
+    global $reply_focus, $hide_sm_attributions, $frame_top,
            $provider_name, $provider_uri, $startMessage,
-           $javascript_on;
+           $javascript_on, $action;
+
+    if (empty($sBodyTagJs)) {
+        if (strpos($action, 'reply') !== FALSE && $reply_focus) {
+          if ($reply_focus == 'select')
+              $sBodyTagJs = 'onload="checkForm(\'select\');"';
+          else if ($reply_focus == 'focus')
+              $sBodyTagJs = 'onload="checkForm(\'focus\');"';
+          else if ($reply_focus != 'none')
+              $sBodyTagJs = 'onload="checkForm();"';
+        }
+        else
+          $sBodyTagJs = 'onload="checkForm();"';
+    }
+
 
     sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
 
@@ -152,15 +168,13 @@ function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = 'onloa
         $frame_top = '_top';
     }
 
-    if( $javascript_on || strpos($xtra, 'new_js_autodetect_results.value') ) {
+    if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
+        $sJsBlock = '<script src="'. SM_PATH .'templates/default/js/default.js" type="text/javascript" language="JavaScript"></script>' ."\n";
         if ($sHeaderJs) {
-            $sJsBlock = "\n<script language=\"JavaScript\" type=\"text/javascript\">" .
+            $sJsBlock .= "\n<script language=\"JavaScript\" type=\"text/javascript\">" .
                         "\n<!--\n" .
-                        $sJsHeader . "\n\n// -->\n</script>\n";
-        } else {
-           $sJsBlock = '';
+                        $sHeaderJs . "\n\n// -->\n</script>\n";
         }
-        $sJsBlock .= "\n" . '<script src="'. SM_PATH .'templates/default/js/default.js" type="text/javascript" language="JavaScript"></script>' ."\n";
         displayHtmlHeader ('SquirrelMail', $sJsBlock);
    } else {
         /* do not use JavaScript */
@@ -195,6 +209,8 @@ function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = 'onloa
                                  : html_tag( 'td', '', 'left' ) )
         . "\n";
     $urlMailbox = urlencode($mailbox);
+    $startMessage = (int)$startMessage;
+
     echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&amp;startMessage='.$startMessage);
     echo "&nbsp;&nbsp;\n";
     displayInternalLink ('src/addressbook.php', _("Addresses"));
@@ -237,8 +253,24 @@ function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = 'onloa
  * @param string sBodyTagJs js events to be inserted in the body tag
  * @return void
  */
-function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = 'onload="checkForm();"') {
-    global $javascript_on;
+function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
+
+    global $reply_focus, $javascript_on, $action;
+
+    if (empty($sBodyTagJs)) {
+        if (strpos($action, 'reply') !== FALSE && $reply_focus) {
+          if ($reply_focus == 'select')
+              $sBodyTagJs = 'onload="checkForm(\'select\');"';
+          else if ($reply_focus == 'focus')
+              $sBodyTagJs = 'onload="checkForm(\'focus\');"';
+          else if ($reply_focus != 'none')
+              $sBodyTagJs = 'onload="checkForm();"';
+        }
+        else
+          $sBodyTagJs = 'onload="checkForm();"';
+    }
+
+
     /*
      * Locate the first displayable form element (only when JavaScript on)
      */
@@ -246,7 +278,7 @@ function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = 'onload="
         if ($sHeaderJs) {
             $sJsBlock = "\n<script language=\"JavaScript\" type=\"text/javascript\">" .
                         "\n<!--\n" .
-                        $sJsHeader . "\n\n// -->\n</script>\n";
+                        $sHeaderJs . "\n\n// -->\n</script>\n";
         } else {
            $sJsBlock = '';
         }