page_header.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <?php
  2. /**
  3. * page_header.php
  4. *
  5. * Copyright (c) 1999-2003 The SquirrelMail Project Team
  6. * Licensed under the GNU GPL. For full terms see the file COPYING.
  7. *
  8. * Prints the page header (duh)
  9. *
  10. * $Id$
  11. * @package squirrelmail
  12. */
  13. /** Include required files from SM */
  14. require_once(SM_PATH . 'functions/strings.php');
  15. require_once(SM_PATH . 'functions/html.php');
  16. require_once(SM_PATH . 'functions/imap_mailbox.php');
  17. require_once(SM_PATH . 'functions/global.php');
  18. /**
  19. * Output a SquirrelMail page header, from <!doctype> to </head>
  20. * Always set up the language before calling these functions.
  21. *
  22. * @param string title the page title, default SquirrelMail.
  23. * @param string xtra extra HTML to insert into the header
  24. * @param bool do_hook whether to execute hooks, default true
  25. * @return void
  26. */
  27. function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE ) {
  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. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' .
  34. "\n\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) . "\n<head>\n";
  35. if ( !isset( $custom_css ) || $custom_css == 'none' ) {
  36. if ($theme_css != '') {
  37. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\" />";
  38. }
  39. } else {
  40. echo '<link rel="stylesheet" type="text/css" href="' .
  41. $base_uri . 'themes/css/'.$custom_css.'" />';
  42. }
  43. if ($squirrelmail_language == 'ja_JP') {
  44. echo "<!-- \xfd\xfe -->\n";
  45. echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
  46. }
  47. if ($do_hook) {
  48. do_hook('generic_header');
  49. }
  50. echo "\n<title>$title</title>$xtra\n";
  51. /* work around IE6's scrollbar bug */
  52. echo <<<ECHO
  53. <style type="text/css">
  54. <!--
  55. /* avoid stupid IE6 bug with frames and scrollbars */
  56. body {
  57. voice-family: "\"}\"";
  58. voice-family: inherit;
  59. width: expression(document.documentElement.clientWidth - 30);
  60. }
  61. -->
  62. </style>
  63. ECHO;
  64. echo "\n</head>\n\n";
  65. /* this is used to check elsewhere whether we should call this function */
  66. $pageheader_sent = TRUE;
  67. }
  68. /**
  69. * Given a path to a SquirrelMail file, return a HTML link to it
  70. *
  71. * @param string path the SquirrelMail file to link to
  72. * @param string text the link text
  73. * @param string target the target frame for this link
  74. */
  75. function makeInternalLink($path, $text, $target='') {
  76. sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
  77. if ($target != '') {
  78. $target = " target=\"$target\"";
  79. }
  80. $hooktext = do_hook_function('internal_link',$text);
  81. if ($hooktext != '')
  82. $text = $hooktext;
  83. return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
  84. }
  85. /**
  86. * Same as makeInternalLink, but echoes it too
  87. */
  88. function displayInternalLink($path, $text, $target='') {
  89. echo makeInternalLink($path, $text, $target);
  90. }
  91. /**
  92. * Outputs a complete SquirrelMail page header, starting with <!doctype> and
  93. * including the default menu bar. Uses displayHtmlHeader and takes
  94. * JavaScript and locale settings into account.
  95. *
  96. * @param array color the array of theme colors
  97. * @param string mailbox the current mailbox name to display
  98. * @param string xtra extra html code to add
  99. * @param bool session
  100. * @return void
  101. */
  102. function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
  103. global $hide_sm_attributions, $PHP_SELF, $frame_top,
  104. $compose_new_win, $compose_width, $compose_height,
  105. $attachemessages, $provider_name, $provider_uri,
  106. $javascript_on, $default_use_mdn, $mdn_user_support;
  107. sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION );
  108. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
  109. $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
  110. if ($qmark = strpos($module, '?')) {
  111. $module = substr($module, 0, $qmark);
  112. }
  113. if (!isset($frame_top)) {
  114. $frame_top = '_top';
  115. }
  116. if ($session) {
  117. $compose_uri = $base_uri.'src/compose.php?mailbox='.urlencode($mailbox).'&amp;attachedmessages=true&amp;session='."$session";
  118. } else {
  119. $compose_uri = $base_uri.'src/compose.php?newmessage=1';
  120. $session = 0;
  121. }
  122. if($javascript_on) {
  123. switch ( $module ) {
  124. case 'src/read_body.php':
  125. $js ='';
  126. // compose in new window code
  127. if ($compose_new_win == '1') {
  128. if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
  129. $compose_width = '640';
  130. }
  131. if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
  132. $compose_height = '550';
  133. }
  134. $js .= "function comp_in_new(comp_uri) {\n".
  135. " if (!comp_uri) {\n".
  136. ' comp_uri = "'.$compose_uri."\";\n".
  137. ' }'. "\n".
  138. ' var newwin = window.open(comp_uri' .
  139. ', "_blank",'.
  140. '"width='.$compose_width. ',height='.$compose_height.
  141. ',scrollbars=yes,resizable=yes");'."\n".
  142. "}\n\n";
  143. }
  144. // javascript for sending read receipts
  145. if($default_use_mdn && $mdn_user_support) {
  146. $js .= 'function sendMDN() {'."\n".
  147. " mdnuri=window.location+'&sendreceipt=1'; ".
  148. "var newwin = window.open(mdnuri,'right');".
  149. "\n}\n\n";
  150. }
  151. // if any of the above passes, add the JS tags too.
  152. if($js) {
  153. $js = "\n".'<script language="JavaScript" type="text/javascript">' .
  154. "\n<!--\n" . $js . "// -->\n</script>\n";
  155. }
  156. displayHtmlHeader ('SquirrelMail', $js);
  157. $onload = $xtra;
  158. break;
  159. case 'src/compose.php':
  160. $js = '<script language="JavaScript" type="text/javascript">' .
  161. "\n<!--\n" .
  162. "function checkForm() {\n";
  163. global $action, $reply_focus;
  164. if (strpos($action, 'reply') !== FALSE && $reply_focus)
  165. {
  166. if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
  167. else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
  168. }
  169. else
  170. $js .= "var f = document.forms.length;\n".
  171. "var i = 0;\n".
  172. "var pos = -1;\n".
  173. "while( pos == -1 && i < f ) {\n".
  174. "var e = document.forms[i].elements.length;\n".
  175. "var j = 0;\n".
  176. "while( pos == -1 && j < e ) {\n".
  177. "if ( document.forms[i].elements[j].type == 'text' ) {\n".
  178. "pos = j;\n".
  179. "}\n".
  180. "j++;\n".
  181. "}\n".
  182. "i++;\n".
  183. "}\n".
  184. "if( pos >= 0 ) {\n".
  185. "document.forms[i-1].elements[pos].focus();\n".
  186. "}\n".
  187. "}\n";
  188. $js .= "// -->\n".
  189. "</script>\n";
  190. $onload = 'onload="checkForm();"';
  191. displayHtmlHeader ('SquirrelMail', $js);
  192. break;
  193. default:
  194. $js = '<script language="JavaScript" type="text/javascript">' .
  195. "\n<!--\n" .
  196. "function checkForm() {\n".
  197. "var f = document.forms.length;\n".
  198. "var i = 0;\n".
  199. "var pos = -1;\n".
  200. "while( pos == -1 && i < f ) {\n".
  201. "var e = document.forms[i].elements.length;\n".
  202. "var j = 0;\n".
  203. "while( pos == -1 && j < e ) {\n".
  204. "if ( document.forms[i].elements[j].type == 'text' " .
  205. "|| document.forms[i].elements[j].type == 'password' ) {\n".
  206. "pos = j;\n".
  207. "}\n".
  208. "j++;\n".
  209. "}\n".
  210. "i++;\n".
  211. "}\n".
  212. "if( pos >= 0 ) {\n".
  213. "document.forms[i-1].elements[pos].focus();\n".
  214. "}\n".
  215. "$xtra\n".
  216. "}\n";
  217. if ($compose_new_win == '1') {
  218. if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
  219. $compose_width = '640';
  220. }
  221. if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
  222. $compose_height = '550';
  223. }
  224. $js .= "function comp_in_new(comp_uri) {\n".
  225. " if (!comp_uri) {\n".
  226. ' comp_uri = "'.$compose_uri."\";\n".
  227. ' }'. "\n".
  228. ' var newwin = window.open(comp_uri' .
  229. ', "_blank",'.
  230. '"width='.$compose_width. ',height='.$compose_height.
  231. ',scrollbars=yes,resizable=yes");'."\n".
  232. "}\n\n";
  233. }
  234. $js .= "// -->\n". "</script>\n";
  235. $onload = 'onload="checkForm();"';
  236. displayHtmlHeader ('SquirrelMail', $js);
  237. break;
  238. }
  239. } else {
  240. /* do not use JavaScript */
  241. displayHtmlHeader ('SquirrelMail');
  242. $onload = '';
  243. }
  244. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  245. /** Here is the header and wrapping table **/
  246. $shortBoxName = imap_utf7_decode_local(
  247. readShortMailboxName($mailbox, $delimiter));
  248. if ( $shortBoxName == 'INBOX' ) {
  249. $shortBoxName = _("INBOX");
  250. }
  251. echo "<a name=\"pagetop\"></a>\n"
  252. . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
  253. . html_tag( 'tr', '', '', $color[9] ) ."\n"
  254. . html_tag( 'td', '', 'left' ) ."\n";
  255. if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
  256. echo ' ' . _("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
  257. } else {
  258. echo '&nbsp;';
  259. }
  260. echo " </td>\n"
  261. . html_tag( 'td', '', 'right' ) ."<b>\n";
  262. displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
  263. echo "</b></td>\n"
  264. . " </tr>\n"
  265. . html_tag( 'tr', '', '', $color[4] ) ."\n"
  266. . ($hide_sm_attributions ? html_tag( 'td', '', 'left', '', 'colspan="2"' )
  267. : html_tag( 'td', '', 'left' ) )
  268. . "\n";
  269. $urlMailbox = urlencode($mailbox);
  270. echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox);
  271. echo "&nbsp;&nbsp;\n";
  272. displayInternalLink ('src/addressbook.php', _("Addresses"), 'right');
  273. echo "&nbsp;&nbsp;\n";
  274. displayInternalLink ('src/folders.php', _("Folders"), 'right');
  275. echo "&nbsp;&nbsp;\n";
  276. displayInternalLink ('src/options.php', _("Options"), 'right');
  277. echo "&nbsp;&nbsp;\n";
  278. displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"), 'right');
  279. echo "&nbsp;&nbsp;\n";
  280. displayInternalLink ('src/help.php', _("Help"), 'right');
  281. echo "&nbsp;&nbsp;\n";
  282. do_hook('menuline');
  283. echo " </td>\n";
  284. if (!$hide_sm_attributions)
  285. {
  286. echo html_tag( 'td', '', 'right' ) ."\n";
  287. if (!isset($provider_uri)) $provider_uri= 'http://www.squirrelmail.org/';
  288. if (!isset($provider_name)) $provider_name= 'SquirrelMail';
  289. echo '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>';
  290. echo "</td>\n";
  291. }
  292. echo " </tr>\n".
  293. "</table><br>\n\n";
  294. }
  295. /**
  296. * Blatantly copied/truncated/modified from displayPageHeader.
  297. * Outputs a page header specifically for the compose_in_new popup window
  298. *
  299. * @param array color the array of theme colors
  300. * @param string mailbox the current mailbox name to display
  301. * @return void
  302. */
  303. function compose_Header($color, $mailbox) {
  304. global $javascript_on;
  305. /*
  306. * Locate the first displayable form element (only when JavaScript on)
  307. */
  308. if($javascript_on) {
  309. global $delimiter, $base_uri, $PHP_SELF, $data_dir, $username;
  310. $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
  311. switch ( $module ) {
  312. case 'src/search.php':
  313. $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1;
  314. $onload = "onload=\"document.forms[$pos].elements[2].focus();\"";
  315. displayHtmlHeader (_("Compose"));
  316. break;
  317. default:
  318. $js = '<script language="JavaScript" type="text/javascript">' .
  319. "\n<!--\n" .
  320. "function checkForm() {\n";
  321. global $action, $reply_focus;
  322. if (strpos($action, 'reply') !== FALSE && $reply_focus)
  323. {
  324. if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
  325. else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
  326. }
  327. else
  328. $js .= "var f = document.forms.length;\n".
  329. "var i = 0;\n".
  330. "var pos = -1;\n".
  331. "while( pos == -1 && i < f ) {\n".
  332. "var e = document.forms[i].elements.length;\n".
  333. "var j = 0;\n".
  334. "while( pos == -1 && j < e ) {\n".
  335. "if ( document.forms[i].elements[j].type == 'text' ) {\n".
  336. "pos = j;\n".
  337. "}\n".
  338. "j++;\n".
  339. "}\n".
  340. "i++;\n".
  341. "}\n".
  342. "if( pos >= 0 ) {\n".
  343. "document.forms[i-1].elements[pos].focus();\n".
  344. "}\n".
  345. "}\n";
  346. $js .= "// -->\n".
  347. "</script>\n";
  348. $onload = 'onload="checkForm();"';
  349. displayHtmlHeader (_("Compose"), $js);
  350. break;
  351. }
  352. } else {
  353. /* javascript off */
  354. displayHtmlHeader(_("Compose"));
  355. $onload = '';
  356. }
  357. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  358. }
  359. ?>