managing agresive decoding and ja_JP + utf-8.
[squirrelmail.git] / functions / page_header.php
index 53c5d003e4603a30a125b22c3c586989405495ef..b134b141c95818cbc86670ebc7f74adde5ecf0fa 100644 (file)
@@ -9,14 +9,24 @@
  * Prints the page header (duh)
  *
  * $Id$
+ * @package squirrelmail
  */
 
+/** Include required files from SM */
 require_once(SM_PATH . 'functions/strings.php');
 require_once(SM_PATH . 'functions/html.php');
 require_once(SM_PATH . 'functions/imap_mailbox.php');
 require_once(SM_PATH . 'functions/global.php');
 
-/* Always set up the language before calling these functions */
+/**
+ * Output a SquirrelMail page header, from <!doctype> to </head>
+ * Always set up the language before calling these functions.
+ *
+ * @param string title the page title, default SquirrelMail.
+ * @param string xtra extra HTML to insert into the header
+ * @param bool do_hook whether to execute hooks, default true
+ * @return void
+ */
 function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE ) {
     global $squirrelmail_language;
 
@@ -26,7 +36,7 @@ function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE
     global $theme_css, $custom_css, $pageheader_sent;
 
     echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' .
-         "\n\n" . html_tag( 'html' ,'' , '', '', '' ) . "\n<head>\n";
+         "\n\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) . "\n<head>\n";
 
     if ( !isset( $custom_css ) || $custom_css == 'none' ) {
         if ($theme_css != '') {
@@ -39,7 +49,7 @@ function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE
     
     if ($squirrelmail_language == 'ja_JP') {
         echo "<!-- \xfd\xfe -->\n";
-        echo '<meta http-equuiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
+        echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
     }
     
     if ($do_hook) {
@@ -69,24 +79,49 @@ ECHO;
     $pageheader_sent = TRUE;
 }
 
+/**
+ * Given a path to a SquirrelMail file, return a HTML link to it
+ *
+ * @param string path the SquirrelMail file to link to
+ * @param string text the link text
+ * @param string target the target frame for this link
+ */
 function makeInternalLink($path, $text, $target='') {
     sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
     if ($target != '') {
         $target = " target=\"$target\"";
     }
+    $hooktext = do_hook_function('internal_link',$text);
+    if ($hooktext != '')
+        $text = $hooktext;
     return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
 }
 
+/**
+ * Same as makeInternalLink, but echoes it too
+ */
 function displayInternalLink($path, $text, $target='') {
     echo makeInternalLink($path, $text, $target);
 }
 
+/**
+ * Outputs a complete SquirrelMail page header, starting with <!doctype> and
+ * including the default menu bar. Uses displayHtmlHeader and takes
+ * JavaScript and locale settings into account.
+ *
+ * @param array color the array of theme colors
+ * @param string mailbox the current mailbox name to display
+ * @param string xtra extra html code to add
+ * @param bool session
+ * @return void
+ */
 function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
 
     global $hide_sm_attributions, $PHP_SELF, $frame_top,
            $compose_new_win, $compose_width, $compose_height,
            $attachemessages, $provider_name, $provider_uri,
-           $javascript_on, $default_use_mdn, $mdn_user_support;
+           $javascript_on, $default_use_mdn, $mdn_user_support,
+           $startMessage;
 
     sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION );
     sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
@@ -150,8 +185,16 @@ function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
         case 'src/compose.php':
             $js = '<script language="JavaScript" type="text/javascript">' .
                  "\n<!--\n" .
-                 "function checkForm() {\n".
-                    "var f = document.forms.length;\n".
+             "function checkForm() {\n";
+
+            global $action, $reply_focus;
+            if (strpos($action, 'reply') !== FALSE && $reply_focus)
+            {
+                if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
+                else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
+            }
+            else
+                $js .= "var f = document.forms.length;\n".
                     "var i = 0;\n".
                     "var pos = -1;\n".
                     "while( pos == -1 && i < f ) {\n".
@@ -258,7 +301,7 @@ function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
                                  : html_tag( 'td', '', 'left' ) )
         . "\n";
     $urlMailbox = urlencode($mailbox);
-    echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox);
+    echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&startMessage='.$startMessage);
     echo "&nbsp;&nbsp;\n";
     displayInternalLink ('src/addressbook.php', _("Addresses"), 'right');
     echo "&nbsp;&nbsp;\n";
@@ -287,7 +330,14 @@ function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
         "</table><br>\n\n";
 }
 
-/* blatently copied/truncated/modified from the above function */
+/**
+ * Blatantly copied/truncated/modified from displayPageHeader.
+ * Outputs a page header specifically for the compose_in_new popup window
+ *
+ * @param array color the array of theme colors
+ * @param string mailbox the current mailbox name to display
+ * @return void
+ */
 function compose_Header($color, $mailbox) {
 
     global $javascript_on;
@@ -309,8 +359,16 @@ function compose_Header($color, $mailbox) {
         default:
             $js = '<script language="JavaScript" type="text/javascript">' .
                  "\n<!--\n" .
-                 "function checkForm() {\n".
-                    "var f = document.forms.length;\n".
+             "function checkForm() {\n";
+
+            global $action, $reply_focus;
+            if (strpos($action, 'reply') !== FALSE && $reply_focus)
+            {
+                if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
+                else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
+            }
+            else
+                $js .= "var f = document.forms.length;\n".
                     "var i = 0;\n".
                     "var pos = -1;\n".
                     "while( pos == -1 && i < f ) {\n".