page_header.php 16 KB

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