page_header.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?php
  2. /**
  3. * page_header.php
  4. *
  5. * Prints the page header (duh)
  6. *
  7. * @copyright &copy; 1999-2005 The SquirrelMail Project Team
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @version $Id$
  10. * @package squirrelmail
  11. */
  12. /** Include required files from SM */
  13. require_once(SM_PATH . 'functions/strings.php');
  14. require_once(SM_PATH . 'functions/html.php');
  15. require_once(SM_PATH . 'functions/imap_mailbox.php');
  16. require_once(SM_PATH . 'functions/global.php');
  17. /**
  18. * Output a SquirrelMail page header, from <!doctype> to </head>
  19. * Always set up the language before calling these functions.
  20. *
  21. * @param string title the page title, default SquirrelMail.
  22. * @param string xtra extra HTML to insert into the header
  23. * @param bool do_hook whether to execute hooks, default true
  24. * @param bool frames generate html frameset doctype (since 1.5.1)
  25. * @return void
  26. */
  27. function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = true, $frames = false ) {
  28. global $squirrelmail_language;
  29. if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
  30. global $base_uri;
  31. }
  32. global $theme_css, $custom_css, $pageheader_sent;
  33. if ($frames) {
  34. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">';
  35. } else {
  36. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
  37. }
  38. echo "\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) .
  39. "<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n";
  40. /*
  41. * Add closing / to link and meta elements only after switching to xhtml 1.0 Transitional.
  42. * It is not compatible with html 4.01 Transitional
  43. */
  44. if ( !isset( $custom_css ) || $custom_css == 'none' ) {
  45. if ($theme_css != '') {
  46. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">";
  47. }
  48. } else {
  49. echo '<link rel="stylesheet" type="text/css" href="' .
  50. $base_uri . 'themes/css/'.$custom_css.'">';
  51. }
  52. echo '<link rel="stylesheet" type="text/css" href="'. $base_uri .'templates/default/squirrelmail.css">';
  53. if ($squirrelmail_language == 'ja_JP') {
  54. /*
  55. * force correct detection of charset, when browser does not follow
  56. * http content-type and tries to detect charset from page content.
  57. * Shooting of browser's creator can't be implemented in php.
  58. * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
  59. * recommendations and switch to unicode.
  60. */
  61. echo "<!-- \xfd\xfe -->\n";
  62. echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
  63. }
  64. if ($do_hook) {
  65. do_hook('generic_header');
  66. }
  67. echo "<title>$title</title>\n$xtra\n";
  68. /* work around IE6's scrollbar bug */
  69. echo <<<ECHO
  70. <style type="text/css">
  71. <!--
  72. /* avoid stupid IE6 bug with frames and scrollbars */
  73. body {
  74. voice-family: "\"}\"";
  75. voice-family: inherit;
  76. width: expression(document.documentElement.clientWidth - 30);
  77. }
  78. -->
  79. </style>
  80. ECHO;
  81. echo "\n</head>\n\n";
  82. /* this is used to check elsewhere whether we should call this function */
  83. $pageheader_sent = TRUE;
  84. }
  85. /**
  86. * Given a path to a SquirrelMail file, return a HTML link to it
  87. *
  88. * @param string path the SquirrelMail file to link to
  89. * @param string text the link text
  90. * @param string target the target frame for this link
  91. */
  92. function makeInternalLink($path, $text, $target='') {
  93. sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
  94. if ($target != '') {
  95. $target = " target=\"$target\"";
  96. }
  97. // This is an inefficient hook and is only used by
  98. // one plugin that still needs to patch this code,
  99. // plus if we are templat-izing SM, visual hooks
  100. // are not needed. However, I am leaving the code
  101. // here just in case we find a good (non-visual?)
  102. // use for the internal_link hook.
  103. //
  104. //$hooktext = do_hook_function('internal_link',$text);
  105. //if ($hooktext != '')
  106. // $text = $hooktext;
  107. return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
  108. }
  109. /**
  110. * Same as makeInternalLink, but echoes it too
  111. */
  112. function displayInternalLink($path, $text, $target='') {
  113. echo makeInternalLink($path, $text, $target);
  114. }
  115. /**
  116. * Outputs a complete SquirrelMail page header, starting with <!doctype> and
  117. * including the default menu bar. Uses displayHtmlHeader and takes
  118. * JavaScript and locale settings into account.
  119. *
  120. * @param array color the array of theme colors
  121. * @param string mailbox the current mailbox name to display
  122. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  123. * @param string sBodyTagJs js events to be inserted in the body tag
  124. * @return void
  125. */
  126. function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
  127. global $reply_focus, $hide_sm_attributions, $frame_top,
  128. $provider_name, $provider_uri, $startMessage,
  129. $javascript_on, $action;
  130. if (empty($sBodyTagJs)) {
  131. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  132. if ($reply_focus == 'select')
  133. $sBodyTagJs = 'onload="checkForm(\'select\');"';
  134. else if ($reply_focus == 'focus')
  135. $sBodyTagJs = 'onload="checkForm(\'focus\');"';
  136. else if ($reply_focus != 'none')
  137. $sBodyTagJs = 'onload="checkForm();"';
  138. }
  139. else
  140. $sBodyTagJs = 'onload="checkForm();"';
  141. }
  142. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
  143. if (!isset($frame_top)) {
  144. $frame_top = '_top';
  145. }
  146. if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
  147. $sJsBlock = '<script src="'. SM_PATH .'templates/default/js/default.js" type="text/javascript" language="JavaScript"></script>' ."\n";
  148. if ($sHeaderJs) {
  149. $sJsBlock .= "\n<script language=\"JavaScript\" type=\"text/javascript\">" .
  150. "\n<!--\n" .
  151. $sHeaderJs . "\n\n// -->\n</script>\n";
  152. }
  153. displayHtmlHeader ('SquirrelMail', $sJsBlock);
  154. } else {
  155. /* do not use JavaScript */
  156. displayHtmlHeader ('SquirrelMail');
  157. $sBodyTagJs = '';
  158. }
  159. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
  160. /** Here is the header and wrapping table **/
  161. $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
  162. readShortMailboxName($mailbox, $delimiter)));
  163. if ( $shortBoxName == 'INBOX' ) {
  164. $shortBoxName = _("INBOX");
  165. }
  166. echo "<a name=\"pagetop\"></a>\n"
  167. . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
  168. . html_tag( 'tr', '', '', $color[9] ) ."\n"
  169. . html_tag( 'td', '', 'left' ) ."\n";
  170. if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
  171. echo ' ' . _("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
  172. } else {
  173. echo '&nbsp;';
  174. }
  175. echo " </td>\n"
  176. . html_tag( 'td', '', 'right' ) ."<b>\n";
  177. displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
  178. echo "</b></td>\n"
  179. . " </tr>\n"
  180. . html_tag( 'tr', '', '', $color[4] ) ."\n"
  181. . ($hide_sm_attributions ? html_tag( 'td', '', 'left', '', 'colspan="2"' )
  182. : html_tag( 'td', '', 'left' ) )
  183. . "\n";
  184. $urlMailbox = urlencode($mailbox);
  185. $startMessage = (int)$startMessage;
  186. echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&amp;startMessage='.$startMessage);
  187. echo "&nbsp;&nbsp;\n";
  188. displayInternalLink ('src/addressbook.php', _("Addresses"));
  189. echo "&nbsp;&nbsp;\n";
  190. displayInternalLink ('src/folders.php', _("Folders"));
  191. echo "&nbsp;&nbsp;\n";
  192. displayInternalLink ('src/options.php', _("Options"));
  193. echo "&nbsp;&nbsp;\n";
  194. displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"));
  195. echo "&nbsp;&nbsp;\n";
  196. displayInternalLink ('src/help.php', _("Help"));
  197. echo "&nbsp;&nbsp;\n";
  198. do_hook('menuline');
  199. echo " </td>\n";
  200. if (!$hide_sm_attributions)
  201. {
  202. echo html_tag( 'td', '', 'right' ) ."\n";
  203. if (empty($provider_uri)) {
  204. echo '<a href="about.php">SquirrelMail</a>';
  205. } else {
  206. if (empty($provider_name)) $provider_name= 'SquirrelMail';
  207. echo '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>';
  208. }
  209. echo "</td>\n";
  210. }
  211. echo " </tr>\n".
  212. "</table><br />\n\n";
  213. }
  214. /**
  215. * Blatantly copied/truncated/modified from displayPageHeader.
  216. * Outputs a page header specifically for the compose_in_new popup window
  217. *
  218. * @param array color the array of theme colors
  219. * @param string mailbox the current mailbox name to display
  220. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  221. * @param string sBodyTagJs js events to be inserted in the body tag
  222. * @return void
  223. */
  224. function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
  225. global $reply_focus, $javascript_on, $action;
  226. if (empty($sBodyTagJs)) {
  227. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  228. if ($reply_focus == 'select')
  229. $sBodyTagJs = 'onload="checkForm(\'select\');"';
  230. else if ($reply_focus == 'focus')
  231. $sBodyTagJs = 'onload="checkForm(\'focus\');"';
  232. else if ($reply_focus != 'none')
  233. $sBodyTagJs = 'onload="checkForm();"';
  234. }
  235. else
  236. $sBodyTagJs = 'onload="checkForm();"';
  237. }
  238. /*
  239. * Locate the first displayable form element (only when JavaScript on)
  240. */
  241. if($javascript_on) {
  242. if ($sHeaderJs) {
  243. $sJsBlock = "\n<script language=\"JavaScript\" type=\"text/javascript\">" .
  244. "\n<!--\n" .
  245. $sHeaderJs . "\n\n// -->\n</script>\n";
  246. } else {
  247. $sJsBlock = '';
  248. }
  249. $sJsBlock .= "\n" . '<script src="'. SM_PATH .'templates/default/js/default.js" type="text/javascript" language="JavaScript"></script>' ."\n";
  250. displayHtmlHeader (_("Compose"), $sJsBlock);
  251. } else {
  252. /* javascript off */
  253. displayHtmlHeader(_("Compose"));
  254. $onload = '';
  255. }
  256. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
  257. }
  258. ?>