page_header.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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. }
  184. else
  185. $js .= "var f = document.forms.length;\n".
  186. "var i = 0;\n".
  187. "var pos = -1;\n".
  188. "while( pos == -1 && i < f ) {\n".
  189. "var e = document.forms[i].elements.length;\n".
  190. "var j = 0;\n".
  191. "while( pos == -1 && j < e ) {\n".
  192. "if ( document.forms[i].elements[j].type == 'text' ) {\n".
  193. "pos = j;\n".
  194. "}\n".
  195. "j++;\n".
  196. "}\n".
  197. "i++;\n".
  198. "}\n".
  199. "if( pos >= 0 ) {\n".
  200. "document.forms[i-1].elements[pos].focus();\n".
  201. "}\n".
  202. "}\n";
  203. $js .= "// -->\n".
  204. "</script>\n";
  205. $onload = 'onload="checkForm();"';
  206. displayHtmlHeader ('SquirrelMail', $js);
  207. break;
  208. default:
  209. $js = '<script language="JavaScript" type="text/javascript">' .
  210. "\n<!--\n" .
  211. "function checkForm() {\n".
  212. "var f = document.forms.length;\n".
  213. "var i = 0;\n".
  214. "var pos = -1;\n".
  215. "while( pos == -1 && i < f ) {\n".
  216. "var e = document.forms[i].elements.length;\n".
  217. "var j = 0;\n".
  218. "while( pos == -1 && j < e ) {\n".
  219. "if ( document.forms[i].elements[j].type == 'text' " .
  220. "|| document.forms[i].elements[j].type == 'password' ) {\n".
  221. "pos = j;\n".
  222. "}\n".
  223. "j++;\n".
  224. "}\n".
  225. "i++;\n".
  226. "}\n".
  227. "if( pos >= 0 ) {\n".
  228. "document.forms[i-1].elements[pos].focus();\n".
  229. "}\n".
  230. "$xtra\n".
  231. "}\n";
  232. if ($compose_new_win == '1') {
  233. if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
  234. $compose_width = '640';
  235. }
  236. if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
  237. $compose_height = '550';
  238. }
  239. $js .= "function comp_in_new(comp_uri) {\n".
  240. " if (!comp_uri) {\n".
  241. ' comp_uri = "'.$compose_uri."\";\n".
  242. ' }'. "\n".
  243. ' var newwin = window.open(comp_uri' .
  244. ', "_blank",'.
  245. '"width='.$compose_width. ',height='.$compose_height.
  246. ',scrollbars=yes,resizable=yes");'."\n".
  247. "}\n\n";
  248. }
  249. $js .= "// -->\n". "</script>\n";
  250. $onload = 'onload="checkForm();"';
  251. displayHtmlHeader ('SquirrelMail', $js);
  252. break;
  253. }
  254. } else {
  255. /* do not use JavaScript */
  256. displayHtmlHeader ('SquirrelMail');
  257. $onload = '';
  258. }
  259. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  260. /** Here is the header and wrapping table **/
  261. $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
  262. readShortMailboxName($mailbox, $delimiter)));
  263. if ( $shortBoxName == 'INBOX' ) {
  264. $shortBoxName = _("INBOX");
  265. }
  266. echo "<a name=\"pagetop\"></a>\n"
  267. . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
  268. . html_tag( 'tr', '', '', $color[9] ) ."\n"
  269. . html_tag( 'td', '', 'left' ) ."\n";
  270. if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
  271. echo ' ' . _("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
  272. } else {
  273. echo '&nbsp;';
  274. }
  275. echo " </td>\n"
  276. . html_tag( 'td', '', 'right' ) ."<b>\n";
  277. displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
  278. echo "</b></td>\n"
  279. . " </tr>\n"
  280. . html_tag( 'tr', '', '', $color[4] ) ."\n"
  281. . ($hide_sm_attributions ? html_tag( 'td', '', 'left', '', 'colspan="2"' )
  282. : html_tag( 'td', '', 'left' ) )
  283. . "\n";
  284. $urlMailbox = urlencode($mailbox);
  285. echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&amp;startMessage='.$startMessage);
  286. echo "&nbsp;&nbsp;\n";
  287. displayInternalLink ('src/addressbook.php', _("Addresses"));
  288. echo "&nbsp;&nbsp;\n";
  289. displayInternalLink ('src/folders.php', _("Folders"));
  290. echo "&nbsp;&nbsp;\n";
  291. displayInternalLink ('src/options.php', _("Options"));
  292. echo "&nbsp;&nbsp;\n";
  293. displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"));
  294. echo "&nbsp;&nbsp;\n";
  295. displayInternalLink ('src/help.php', _("Help"));
  296. echo "&nbsp;&nbsp;\n";
  297. do_hook('menuline');
  298. echo " </td>\n";
  299. if (!$hide_sm_attributions)
  300. {
  301. echo html_tag( 'td', '', 'right' ) ."\n";
  302. if (!isset($provider_uri)) $provider_uri= 'http://www.squirrelmail.org/';
  303. if (!isset($provider_name)) $provider_name= 'SquirrelMail';
  304. echo '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>';
  305. echo "</td>\n";
  306. }
  307. echo " </tr>\n".
  308. "</table><br>\n\n";
  309. }
  310. /**
  311. * Blatantly copied/truncated/modified from displayPageHeader.
  312. * Outputs a page header specifically for the compose_in_new popup window
  313. *
  314. * @param array color the array of theme colors
  315. * @param string mailbox the current mailbox name to display
  316. * @return void
  317. */
  318. function compose_Header($color, $mailbox) {
  319. global $javascript_on;
  320. /*
  321. * Locate the first displayable form element (only when JavaScript on)
  322. */
  323. if($javascript_on) {
  324. global $delimiter, $base_uri, $PHP_SELF, $data_dir, $username;
  325. $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
  326. switch ( $module ) {
  327. case 'src/search.php':
  328. $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1;
  329. $onload = "onload=\"document.forms[$pos].elements[2].focus();\"";
  330. displayHtmlHeader (_("Compose"));
  331. break;
  332. default:
  333. $js = '<script language="JavaScript" type="text/javascript">' .
  334. "\n<!--\n" .
  335. "function checkForm() {\n";
  336. global $action, $reply_focus;
  337. if (strpos($action, 'reply') !== FALSE && $reply_focus)
  338. {
  339. if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
  340. else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
  341. }
  342. else
  343. $js .= "var f = document.forms.length;\n".
  344. "var i = 0;\n".
  345. "var pos = -1;\n".
  346. "while( pos == -1 && i < f ) {\n".
  347. "var e = document.forms[i].elements.length;\n".
  348. "var j = 0;\n".
  349. "while( pos == -1 && j < e ) {\n".
  350. "if ( document.forms[i].elements[j].type == 'text' ) {\n".
  351. "pos = j;\n".
  352. "}\n".
  353. "j++;\n".
  354. "}\n".
  355. "i++;\n".
  356. "}\n".
  357. "if( pos >= 0 ) {\n".
  358. "document.forms[i-1].elements[pos].focus();\n".
  359. "}\n".
  360. "}\n";
  361. $js .= "// -->\n".
  362. "</script>\n";
  363. $onload = 'onload="checkForm();"';
  364. displayHtmlHeader (_("Compose"), $js);
  365. break;
  366. }
  367. } else {
  368. /* javascript off */
  369. displayHtmlHeader(_("Compose"));
  370. $onload = '';
  371. }
  372. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  373. }
  374. ?>