page_header.php 13 KB

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