page_header.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. <?php
  2. /**
  3. * page_header.php
  4. *
  5. * Copyright (c) 1999-2005 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. * @param bool frames generate html frameset doctype (since 1.5.1)
  26. * @return void
  27. */
  28. function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = true, $frames = false ) {
  29. global $squirrelmail_language;
  30. if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
  31. global $base_uri;
  32. }
  33. global $theme_css, $custom_css, $pageheader_sent;
  34. if ($frames) {
  35. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">';
  36. } else {
  37. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
  38. }
  39. echo "\n\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) . "\n<head>\n";
  40. if ( !isset( $custom_css ) || $custom_css == 'none' ) {
  41. if ($theme_css != '') {
  42. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\" />";
  43. }
  44. } else {
  45. echo '<link rel="stylesheet" type="text/css" href="' .
  46. $base_uri . 'themes/css/'.$custom_css.'" />';
  47. }
  48. if ($squirrelmail_language == 'ja_JP') {
  49. /*
  50. * force correct detection of charset, when browser does not follow
  51. * http content-type and tries to detect charset from page content.
  52. * Shooting of browser's creator can't be implemented in php.
  53. * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
  54. * recommendations and switch to unicode.
  55. */
  56. echo "<!-- \xfd\xfe -->\n";
  57. echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp" />' . "\n";
  58. }
  59. if ($do_hook) {
  60. do_hook('generic_header');
  61. }
  62. echo "\n<title>$title</title>$xtra\n";
  63. /* work around IE6's scrollbar bug */
  64. echo <<<ECHO
  65. <style type="text/css">
  66. <!--
  67. /* avoid stupid IE6 bug with frames and scrollbars */
  68. body {
  69. voice-family: "\"}\"";
  70. voice-family: inherit;
  71. width: expression(document.documentElement.clientWidth - 30);
  72. }
  73. -->
  74. </style>
  75. ECHO;
  76. echo "\n</head>\n\n";
  77. /* this is used to check elsewhere whether we should call this function */
  78. $pageheader_sent = TRUE;
  79. }
  80. /**
  81. * Given a path to a SquirrelMail file, return a HTML link to it
  82. *
  83. * @param string path the SquirrelMail file to link to
  84. * @param string text the link text
  85. * @param string target the target frame for this link
  86. */
  87. function makeInternalLink($path, $text, $target='') {
  88. sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
  89. if ($target != '') {
  90. $target = " target=\"$target\"";
  91. }
  92. // This is an inefficient hook and is only used by
  93. // one plugin that still needs to patch this code,
  94. // plus if we are templat-izing SM, visual hooks
  95. // are not needed. However, I am leaving the code
  96. // here just in case we find a good (non-visual?)
  97. // use for the internal_link hook.
  98. //
  99. //$hooktext = do_hook_function('internal_link',$text);
  100. //if ($hooktext != '')
  101. // $text = $hooktext;
  102. return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
  103. }
  104. /**
  105. * Same as makeInternalLink, but echoes it too
  106. */
  107. function displayInternalLink($path, $text, $target='') {
  108. echo makeInternalLink($path, $text, $target);
  109. }
  110. /**
  111. * Outputs a complete SquirrelMail page header, starting with <!doctype> and
  112. * including the default menu bar. Uses displayHtmlHeader and takes
  113. * JavaScript and locale settings into account.
  114. *
  115. * @param array color the array of theme colors
  116. * @param string mailbox the current mailbox name to display
  117. * @param string xtra extra html code to add
  118. * @param bool session
  119. * @return void
  120. */
  121. function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
  122. global $hide_sm_attributions, $PHP_SELF, $frame_top,
  123. $compose_new_win, $compose_width, $compose_height,
  124. $provider_name, $provider_uri, $startMessage,
  125. $javascript_on, $default_use_mdn, $mdn_user_support;
  126. sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION );
  127. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
  128. $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
  129. if ($qmark = strpos($module, '?')) {
  130. $module = substr($module, 0, $qmark);
  131. }
  132. if (!isset($frame_top)) {
  133. $frame_top = '_top';
  134. }
  135. if ($session) {
  136. $compose_uri = $base_uri.'src/compose.php?mailbox='.urlencode($mailbox).'&amp;attachedmessages=true&amp;session='."$session";
  137. } else {
  138. $compose_uri = $base_uri.'src/compose.php?newmessage=1';
  139. $session = 0;
  140. }
  141. if( $javascript_on || strpos($xtra, 'new_js_autodetect_results.value') ) {
  142. switch ( $module ) {
  143. case 'src/read_body.php':
  144. $js ='';
  145. // compose in new window code
  146. if ($compose_new_win == '1') {
  147. if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
  148. $compose_width = '640';
  149. }
  150. if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
  151. $compose_height = '550';
  152. }
  153. $js .= "function comp_in_new_form(comp_uri, button, myform) {\n".
  154. ' if (!comp_uri) {'."\n".
  155. ' comp_uri = "'.$compose_uri."\";\n".
  156. ' }'. "\n".
  157. ' comp_uri += "&" + button.name + "=1";'."\n".
  158. ' for ( var i=0; i < myform.elements.length; i++ ) {'."\n".
  159. ' if ( myform.elements[i].type == "checkbox" && myform.elements[i].checked )'."\n".
  160. ' comp_uri += "&" + myform.elements[i].name + "=1";'."\n".
  161. ' }'."\n".
  162. ' var newwin = window.open(comp_uri' .
  163. ', "_blank",'.
  164. '"width='.$compose_width. ',height='.$compose_height.
  165. ',scrollbars=yes,resizable=yes,status=yes");'."\n".
  166. "}\n\n";
  167. $js .= "function comp_in_new(comp_uri) {\n".
  168. " if (!comp_uri) {\n".
  169. ' comp_uri = "'.$compose_uri."\";\n".
  170. ' }'. "\n".
  171. ' var newwin = window.open(comp_uri' .
  172. ', "_blank",'.
  173. '"width='.$compose_width. ',height='.$compose_height.
  174. ',scrollbars=yes,resizable=yes,status=yes");'."\n".
  175. "}\n\n";
  176. }
  177. // javascript for sending read receipts
  178. if($default_use_mdn && $mdn_user_support) {
  179. $js .= 'function sendMDN() {'."\n".
  180. " mdnuri=window.location+'&sendreceipt=1'; ".
  181. "var newwin = window.open(mdnuri,'right');".
  182. "\n}\n\n";
  183. }
  184. // if any of the above passes, add the JS tags too.
  185. if($js) {
  186. $js = "\n".'<script language="JavaScript" type="text/javascript">' .
  187. "\n<!--\n" . $js . "// -->\n</script>\n";
  188. }
  189. displayHtmlHeader ('SquirrelMail', $js);
  190. $onload = $xtra;
  191. break;
  192. case 'src/compose.php':
  193. $js = '<script language="JavaScript" type="text/javascript">' .
  194. "\n<!--\n" .
  195. "function checkForm() {\n";
  196. global $action, $reply_focus;
  197. if (strpos($action, 'reply') !== FALSE && $reply_focus)
  198. {
  199. if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
  200. else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
  201. else if ($reply_focus == 'none') $js .= "}\n";
  202. }
  203. // no reply focus also applies to composing new messages
  204. else if ($reply_focus == 'none')
  205. {
  206. $js .= "}\n";
  207. }
  208. else
  209. $js .= "var f = document.forms.length;\n".
  210. "var i = 0;\n".
  211. "var pos = -1;\n".
  212. "while( pos == -1 && i < f ) {\n".
  213. "var e = document.forms[i].elements.length;\n".
  214. "var j = 0;\n".
  215. "while( pos == -1 && j < e ) {\n".
  216. "if ( document.forms[i].elements[j].type == 'text' ) {\n".
  217. "pos = j;\n".
  218. "}\n".
  219. "j++;\n".
  220. "}\n".
  221. "i++;\n".
  222. "}\n".
  223. "if( pos >= 0 ) {\n".
  224. "document.forms[i-1].elements[pos].focus();\n".
  225. "}\n".
  226. "}\n";
  227. $js .= "// -->\n".
  228. "</script>\n";
  229. $onload = 'onload="checkForm();"';
  230. displayHtmlHeader ('SquirrelMail', $js);
  231. break;
  232. default:
  233. $js = '<script language="JavaScript" type="text/javascript">' .
  234. "\n<!--\n" .
  235. "function checkForm() {\n".
  236. "var f = document.forms.length;\n".
  237. "var i = 0;\n".
  238. "var pos = -1;\n".
  239. "while( pos == -1 && i < f ) {\n".
  240. "var e = document.forms[i].elements.length;\n".
  241. "var j = 0;\n".
  242. "while( pos == -1 && j < e ) {\n".
  243. "if ( document.forms[i].elements[j].type == 'text' " .
  244. "|| document.forms[i].elements[j].type == 'password' ) {\n".
  245. "pos = j;\n".
  246. "}\n".
  247. "j++;\n".
  248. "}\n".
  249. "i++;\n".
  250. "}\n".
  251. "if( pos >= 0 ) {\n".
  252. "document.forms[i-1].elements[pos].focus();\n".
  253. "}\n".
  254. "$xtra\n".
  255. "}\n";
  256. if ($compose_new_win == '1') {
  257. if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
  258. $compose_width = '640';
  259. }
  260. if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
  261. $compose_height = '550';
  262. }
  263. $js .= "function comp_in_new(comp_uri) {\n".
  264. " if (!comp_uri) {\n".
  265. ' comp_uri = "'.$compose_uri."\";\n".
  266. ' }'. "\n".
  267. ' var newwin = window.open(comp_uri' .
  268. ', "_blank",'.
  269. '"width='.$compose_width. ',height='.$compose_height.
  270. ',scrollbars=yes,resizable=yes,status=yes");'."\n".
  271. "}\n\n";
  272. }
  273. $js .= "// -->\n". "</script>\n";
  274. $onload = 'onload="checkForm();"';
  275. displayHtmlHeader ('SquirrelMail', $js);
  276. break;
  277. }
  278. } else {
  279. /* do not use JavaScript */
  280. displayHtmlHeader ('SquirrelMail');
  281. $onload = '';
  282. }
  283. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  284. /** Here is the header and wrapping table **/
  285. $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
  286. readShortMailboxName($mailbox, $delimiter)));
  287. if ( $shortBoxName == 'INBOX' ) {
  288. $shortBoxName = _("INBOX");
  289. }
  290. echo "<a name=\"pagetop\"></a>\n"
  291. . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
  292. . html_tag( 'tr', '', '', $color[9] ) ."\n"
  293. . html_tag( 'td', '', 'left' ) ."\n";
  294. if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
  295. echo ' ' . _("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
  296. } else {
  297. echo '&nbsp;';
  298. }
  299. echo " </td>\n"
  300. . html_tag( 'td', '', 'right' ) ."<b>\n";
  301. displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
  302. echo "</b></td>\n"
  303. . " </tr>\n"
  304. . html_tag( 'tr', '', '', $color[4] ) ."\n"
  305. . ($hide_sm_attributions ? html_tag( 'td', '', 'left', '', 'colspan="2"' )
  306. : html_tag( 'td', '', 'left' ) )
  307. . "\n";
  308. $urlMailbox = urlencode($mailbox);
  309. echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&amp;startMessage='.$startMessage);
  310. echo "&nbsp;&nbsp;\n";
  311. displayInternalLink ('src/addressbook.php', _("Addresses"));
  312. echo "&nbsp;&nbsp;\n";
  313. displayInternalLink ('src/folders.php', _("Folders"));
  314. echo "&nbsp;&nbsp;\n";
  315. displayInternalLink ('src/options.php', _("Options"));
  316. echo "&nbsp;&nbsp;\n";
  317. displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"));
  318. echo "&nbsp;&nbsp;\n";
  319. displayInternalLink ('src/help.php', _("Help"));
  320. echo "&nbsp;&nbsp;\n";
  321. do_hook('menuline');
  322. echo " </td>\n";
  323. if (!$hide_sm_attributions)
  324. {
  325. echo html_tag( 'td', '', 'right' ) ."\n";
  326. if (!isset($provider_uri)) $provider_uri= 'http://www.squirrelmail.org/';
  327. if (!isset($provider_name)) $provider_name= 'SquirrelMail';
  328. echo '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>';
  329. echo "</td>\n";
  330. }
  331. echo " </tr>\n".
  332. "</table><br />\n\n";
  333. }
  334. /**
  335. * Blatantly copied/truncated/modified from displayPageHeader.
  336. * Outputs a page header specifically for the compose_in_new popup window
  337. *
  338. * @param array color the array of theme colors
  339. * @param string mailbox the current mailbox name to display
  340. * @return void
  341. */
  342. function compose_Header($color, $mailbox) {
  343. global $javascript_on;
  344. /*
  345. * Locate the first displayable form element (only when JavaScript on)
  346. */
  347. if($javascript_on) {
  348. global $base_uri, $PHP_SELF, $data_dir, $username;
  349. $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
  350. switch ( $module ) {
  351. case 'src/search.php':
  352. $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1;
  353. $onload = "onload=\"document.forms[$pos].elements[2].focus();\"";
  354. displayHtmlHeader (_("Compose"));
  355. break;
  356. default:
  357. $js = '<script language="JavaScript" type="text/javascript">' .
  358. "\n<!--\n" .
  359. "function checkForm() {\n";
  360. global $action, $reply_focus;
  361. if (strpos($action, 'reply') !== FALSE && $reply_focus)
  362. {
  363. if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
  364. else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
  365. else if ($reply_focus == 'none') $js .= "}\n";
  366. }
  367. // no reply focus also applies to composing new messages
  368. else if ($reply_focus == 'none')
  369. {
  370. $js .= "}\n";
  371. }
  372. else
  373. $js .= "var f = document.forms.length;\n".
  374. "var i = 0;\n".
  375. "var pos = -1;\n".
  376. "while( pos == -1 && i < f ) {\n".
  377. "var e = document.forms[i].elements.length;\n".
  378. "var j = 0;\n".
  379. "while( pos == -1 && j < e ) {\n".
  380. "if ( document.forms[i].elements[j].type == 'text' ) {\n".
  381. "pos = j;\n".
  382. "}\n".
  383. "j++;\n".
  384. "}\n".
  385. "i++;\n".
  386. "}\n".
  387. "if( pos >= 0 ) {\n".
  388. "document.forms[i-1].elements[pos].focus();\n".
  389. "}\n".
  390. "}\n";
  391. $js .= "// -->\n".
  392. "</script>\n";
  393. $onload = 'onload="checkForm();"';
  394. displayHtmlHeader (_("Compose"), $js);
  395. break;
  396. }
  397. } else {
  398. /* javascript off */
  399. displayHtmlHeader(_("Compose"));
  400. $onload = '';
  401. }
  402. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  403. }
  404. ?>