page_header.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <?php
  2. /**
  3. * page_header.php
  4. *
  5. * Copyright (c) 1999-2004 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. * @version $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. $startMessage;
  108. sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION );
  109. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
  110. $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
  111. if ($qmark = strpos($module, '?')) {
  112. $module = substr($module, 0, $qmark);
  113. }
  114. if (!isset($frame_top)) {
  115. $frame_top = '_top';
  116. }
  117. if ($session) {
  118. $compose_uri = $base_uri.'src/compose.php?mailbox='.urlencode($mailbox).'&amp;attachedmessages=true&amp;session='."$session";
  119. } else {
  120. $compose_uri = $base_uri.'src/compose.php?newmessage=1';
  121. $session = 0;
  122. }
  123. if($javascript_on) {
  124. switch ( $module ) {
  125. case 'src/read_body.php':
  126. $js ='';
  127. // compose in new window code
  128. if ($compose_new_win == '1') {
  129. if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
  130. $compose_width = '640';
  131. }
  132. if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
  133. $compose_height = '550';
  134. }
  135. $js .= "function comp_in_new_form(comp_uri, button, myform) {\n".
  136. ' if (!comp_uri) {'."\n".
  137. ' comp_uri = "'.$compose_uri."\";\n".
  138. ' }'. "\n".
  139. ' comp_uri += "&" + button.name + "=1";'."\n".
  140. ' for ( var i=0; i < myform.elements.length; i++ ) {'."\n".
  141. ' if ( myform.elements[i].type == "checkbox" && myform.elements[i].checked )'."\n".
  142. ' comp_uri += "&" + myform.elements[i].name + "=1";'."\n".
  143. ' }'."\n".
  144. ' var newwin = window.open(comp_uri' .
  145. ', "_blank",'.
  146. '"width='.$compose_width. ',height='.$compose_height.
  147. ',scrollbars=yes,resizable=yes");'."\n".
  148. "}\n\n";
  149. $js .= "function comp_in_new(comp_uri) {\n".
  150. " if (!comp_uri) {\n".
  151. ' comp_uri = "'.$compose_uri."\";\n".
  152. ' }'. "\n".
  153. ' var newwin = window.open(comp_uri' .
  154. ', "_blank",'.
  155. '"width='.$compose_width. ',height='.$compose_height.
  156. ',scrollbars=yes,resizable=yes");'."\n".
  157. "}\n\n";
  158. }
  159. // javascript for sending read receipts
  160. if($default_use_mdn && $mdn_user_support) {
  161. $js .= 'function sendMDN() {'."\n".
  162. " mdnuri=window.location+'&sendreceipt=1'; ".
  163. "var newwin = window.open(mdnuri,'right');".
  164. "\n}\n\n";
  165. }
  166. // if any of the above passes, add the JS tags too.
  167. if($js) {
  168. $js = "\n".'<script language="JavaScript" type="text/javascript">' .
  169. "\n<!--\n" . $js . "// -->\n</script>\n";
  170. }
  171. displayHtmlHeader ('SquirrelMail', $js);
  172. $onload = $xtra;
  173. break;
  174. case 'src/compose.php':
  175. $js = '<script language="JavaScript" type="text/javascript">' .
  176. "\n<!--\n" .
  177. "function checkForm() {\n";
  178. global $action, $reply_focus;
  179. if (strpos($action, 'reply') !== FALSE && $reply_focus)
  180. {
  181. if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
  182. else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
  183. else if ($reply_focus == 'none') $js .= "}\n";
  184. }
  185. // no reply focus also applies to composing new messages
  186. else if ($reply_focus == 'none')
  187. {
  188. $js .= "}\n";
  189. }
  190. else
  191. $js .= "var f = document.forms.length;\n".
  192. "var i = 0;\n".
  193. "var pos = -1;\n".
  194. "while( pos == -1 && i < f ) {\n".
  195. "var e = document.forms[i].elements.length;\n".
  196. "var j = 0;\n".
  197. "while( pos == -1 && j < e ) {\n".
  198. "if ( document.forms[i].elements[j].type == 'text' ) {\n".
  199. "pos = j;\n".
  200. "}\n".
  201. "j++;\n".
  202. "}\n".
  203. "i++;\n".
  204. "}\n".
  205. "if( pos >= 0 ) {\n".
  206. "document.forms[i-1].elements[pos].focus();\n".
  207. "}\n".
  208. "}\n";
  209. $js .= "// -->\n".
  210. "</script>\n";
  211. $onload = 'onload="checkForm();"';
  212. displayHtmlHeader ('SquirrelMail', $js);
  213. break;
  214. default:
  215. $js = '<script language="JavaScript" type="text/javascript">' .
  216. "\n<!--\n" .
  217. "function checkForm() {\n".
  218. "var f = document.forms.length;\n".
  219. "var i = 0;\n".
  220. "var pos = -1;\n".
  221. "while( pos == -1 && i < f ) {\n".
  222. "var e = document.forms[i].elements.length;\n".
  223. "var j = 0;\n".
  224. "while( pos == -1 && j < e ) {\n".
  225. "if ( document.forms[i].elements[j].type == 'text' " .
  226. "|| document.forms[i].elements[j].type == 'password' ) {\n".
  227. "pos = j;\n".
  228. "}\n".
  229. "j++;\n".
  230. "}\n".
  231. "i++;\n".
  232. "}\n".
  233. "if( pos >= 0 ) {\n".
  234. "document.forms[i-1].elements[pos].focus();\n".
  235. "}\n".
  236. "$xtra\n".
  237. "}\n";
  238. if ($compose_new_win == '1') {
  239. if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
  240. $compose_width = '640';
  241. }
  242. if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
  243. $compose_height = '550';
  244. }
  245. $js .= "function comp_in_new(comp_uri) {\n".
  246. " if (!comp_uri) {\n".
  247. ' comp_uri = "'.$compose_uri."\";\n".
  248. ' }'. "\n".
  249. ' var newwin = window.open(comp_uri' .
  250. ', "_blank",'.
  251. '"width='.$compose_width. ',height='.$compose_height.
  252. ',scrollbars=yes,resizable=yes");'."\n".
  253. "}\n\n";
  254. }
  255. $js .= "// -->\n". "</script>\n";
  256. $onload = 'onload="checkForm();"';
  257. displayHtmlHeader ('SquirrelMail', $js);
  258. break;
  259. }
  260. } else {
  261. /* do not use JavaScript */
  262. displayHtmlHeader ('SquirrelMail');
  263. $onload = '';
  264. }
  265. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  266. /** Here is the header and wrapping table **/
  267. $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
  268. readShortMailboxName($mailbox, $delimiter)));
  269. if ( $shortBoxName == 'INBOX' ) {
  270. $shortBoxName = _("INBOX");
  271. }
  272. echo "<a name=\"pagetop\"></a>\n"
  273. . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
  274. . html_tag( 'tr', '', '', $color[9] ) ."\n"
  275. . html_tag( 'td', '', 'left' ) ."\n";
  276. if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
  277. echo ' ' . _("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
  278. } else {
  279. echo '&nbsp;';
  280. }
  281. echo " </td>\n"
  282. . html_tag( 'td', '', 'right' ) ."<b>\n";
  283. displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
  284. echo "</b></td>\n"
  285. . " </tr>\n"
  286. . html_tag( 'tr', '', '', $color[4] ) ."\n"
  287. . ($hide_sm_attributions ? html_tag( 'td', '', 'left', '', 'colspan="2"' )
  288. : html_tag( 'td', '', 'left' ) )
  289. . "\n";
  290. $urlMailbox = urlencode($mailbox);
  291. echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&amp;startMessage='.$startMessage);
  292. echo "&nbsp;&nbsp;\n";
  293. displayInternalLink ('src/addressbook.php', _("Addresses"));
  294. echo "&nbsp;&nbsp;\n";
  295. displayInternalLink ('src/folders.php', _("Folders"));
  296. echo "&nbsp;&nbsp;\n";
  297. displayInternalLink ('src/options.php', _("Options"));
  298. echo "&nbsp;&nbsp;\n";
  299. displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"));
  300. echo "&nbsp;&nbsp;\n";
  301. displayInternalLink ('src/help.php', _("Help"));
  302. echo "&nbsp;&nbsp;\n";
  303. do_hook('menuline');
  304. echo " </td>\n";
  305. if (!$hide_sm_attributions)
  306. {
  307. echo html_tag( 'td', '', 'right' ) ."\n";
  308. if (!isset($provider_uri)) $provider_uri= 'http://www.squirrelmail.org/';
  309. if (!isset($provider_name)) $provider_name= 'SquirrelMail';
  310. echo '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>';
  311. echo "</td>\n";
  312. }
  313. echo " </tr>\n".
  314. "</table><br>\n\n";
  315. }
  316. /**
  317. * Blatantly copied/truncated/modified from displayPageHeader.
  318. * Outputs a page header specifically for the compose_in_new popup window
  319. *
  320. * @param array color the array of theme colors
  321. * @param string mailbox the current mailbox name to display
  322. * @return void
  323. */
  324. function compose_Header($color, $mailbox) {
  325. global $javascript_on;
  326. /*
  327. * Locate the first displayable form element (only when JavaScript on)
  328. */
  329. if($javascript_on) {
  330. global $delimiter, $base_uri, $PHP_SELF, $data_dir, $username;
  331. $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
  332. switch ( $module ) {
  333. case 'src/search.php':
  334. $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1;
  335. $onload = "onload=\"document.forms[$pos].elements[2].focus();\"";
  336. displayHtmlHeader (_("Compose"));
  337. break;
  338. default:
  339. $js = '<script language="JavaScript" type="text/javascript">' .
  340. "\n<!--\n" .
  341. "function checkForm() {\n";
  342. global $action, $reply_focus;
  343. if (strpos($action, 'reply') !== FALSE && $reply_focus)
  344. {
  345. if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
  346. else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
  347. else if ($reply_focus == 'none') $js .= "}\n";
  348. }
  349. // no reply focus also applies to composing new messages
  350. else if ($reply_focus == 'none')
  351. {
  352. $js .= "}\n";
  353. }
  354. else
  355. $js .= "var f = document.forms.length;\n".
  356. "var i = 0;\n".
  357. "var pos = -1;\n".
  358. "while( pos == -1 && i < f ) {\n".
  359. "var e = document.forms[i].elements.length;\n".
  360. "var j = 0;\n".
  361. "while( pos == -1 && j < e ) {\n".
  362. "if ( document.forms[i].elements[j].type == 'text' ) {\n".
  363. "pos = j;\n".
  364. "}\n".
  365. "j++;\n".
  366. "}\n".
  367. "i++;\n".
  368. "}\n".
  369. "if( pos >= 0 ) {\n".
  370. "document.forms[i-1].elements[pos].focus();\n".
  371. "}\n".
  372. "}\n";
  373. $js .= "// -->\n".
  374. "</script>\n";
  375. $onload = 'onload="checkForm();"';
  376. displayHtmlHeader (_("Compose"), $js);
  377. break;
  378. }
  379. } else {
  380. /* javascript off */
  381. displayHtmlHeader(_("Compose"));
  382. $onload = '';
  383. }
  384. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  385. }
  386. ?>