page_header.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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' ,'' , '', '', '' ) . "\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-equuiv="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. "var f = document.forms.length;\n".
  133. "var i = 0;\n".
  134. "var pos = -1;\n".
  135. "while( pos == -1 && i < f ) {\n".
  136. "var e = document.forms[i].elements.length;\n".
  137. "var j = 0;\n".
  138. "while( pos == -1 && j < e ) {\n".
  139. "if ( document.forms[i].elements[j].type == 'text' ) {\n".
  140. "pos = j;\n".
  141. "}\n".
  142. "j++;\n".
  143. "}\n".
  144. "i++;\n".
  145. "}\n".
  146. "if( pos >= 0 ) {\n".
  147. "document.forms[i-1].elements[pos].focus();\n".
  148. "}\n".
  149. "}\n";
  150. $js .= "// -->\n".
  151. "</script>\n";
  152. $onload = 'onload="checkForm();"';
  153. displayHtmlHeader ('SquirrelMail', $js);
  154. break;
  155. default:
  156. $js = '<script language="JavaScript" type="text/javascript">' .
  157. "\n<!--\n" .
  158. "function checkForm() {\n".
  159. "var f = document.forms.length;\n".
  160. "var i = 0;\n".
  161. "var pos = -1;\n".
  162. "while( pos == -1 && i < f ) {\n".
  163. "var e = document.forms[i].elements.length;\n".
  164. "var j = 0;\n".
  165. "while( pos == -1 && j < e ) {\n".
  166. "if ( document.forms[i].elements[j].type == 'text' " .
  167. "|| document.forms[i].elements[j].type == 'password' ) {\n".
  168. "pos = j;\n".
  169. "}\n".
  170. "j++;\n".
  171. "}\n".
  172. "i++;\n".
  173. "}\n".
  174. "if( pos >= 0 ) {\n".
  175. "document.forms[i-1].elements[pos].focus();\n".
  176. "}\n".
  177. "$xtra\n".
  178. "}\n";
  179. if ($compose_new_win == '1') {
  180. if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
  181. $compose_width = '640';
  182. }
  183. if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
  184. $compose_height = '550';
  185. }
  186. $js .= "function comp_in_new(comp_uri) {\n".
  187. " if (!comp_uri) {\n".
  188. ' comp_uri = "'.$compose_uri."\";\n".
  189. ' }'. "\n".
  190. ' var newwin = window.open(comp_uri' .
  191. ', "_blank",'.
  192. '"width='.$compose_width. ',height='.$compose_height.
  193. ',scrollbars=yes,resizable=yes");'."\n".
  194. "}\n\n";
  195. }
  196. $js .= "// -->\n". "</script>\n";
  197. $onload = 'onload="checkForm();"';
  198. displayHtmlHeader ('SquirrelMail', $js);
  199. break;
  200. }
  201. } else {
  202. /* do not use JavaScript */
  203. displayHtmlHeader ('SquirrelMail');
  204. $onload = '';
  205. }
  206. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  207. /** Here is the header and wrapping table **/
  208. $shortBoxName = imap_utf7_decode_local(
  209. readShortMailboxName($mailbox, $delimiter));
  210. if ( $shortBoxName == 'INBOX' ) {
  211. $shortBoxName = _("INBOX");
  212. }
  213. echo "<a name=\"pagetop\"></a>\n"
  214. . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
  215. . html_tag( 'tr', '', '', $color[9] ) ."\n"
  216. . html_tag( 'td', '', 'left' ) ."\n";
  217. if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
  218. echo ' ' . _("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
  219. } else {
  220. echo '&nbsp;';
  221. }
  222. echo " </td>\n"
  223. . html_tag( 'td', '', 'right' ) ."<b>\n";
  224. displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
  225. echo "</b></td>\n"
  226. . " </tr>\n"
  227. . html_tag( 'tr', '', '', $color[4] ) ."\n"
  228. . ($hide_sm_attributions ? html_tag( 'td', '', 'left', '', 'colspan="2"' )
  229. : html_tag( 'td', '', 'left' ) )
  230. . "\n";
  231. $urlMailbox = urlencode($mailbox);
  232. echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox);
  233. echo "&nbsp;&nbsp;\n";
  234. displayInternalLink ('src/addressbook.php', _("Addresses"), 'right');
  235. echo "&nbsp;&nbsp;\n";
  236. displayInternalLink ('src/folders.php', _("Folders"), 'right');
  237. echo "&nbsp;&nbsp;\n";
  238. displayInternalLink ('src/options.php', _("Options"), 'right');
  239. echo "&nbsp;&nbsp;\n";
  240. displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"), 'right');
  241. echo "&nbsp;&nbsp;\n";
  242. displayInternalLink ('src/help.php', _("Help"), 'right');
  243. echo "&nbsp;&nbsp;\n";
  244. do_hook('menuline');
  245. echo " </td>\n";
  246. if (!$hide_sm_attributions)
  247. {
  248. echo html_tag( 'td', '', 'right' ) ."\n";
  249. if (!isset($provider_uri)) $provider_uri= 'http://www.squirrelmail.org/';
  250. if (!isset($provider_name)) $provider_name= 'SquirrelMail';
  251. echo '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>';
  252. echo "</td>\n";
  253. }
  254. echo " </tr>\n".
  255. "</table><br>\n\n";
  256. }
  257. /* blatently copied/truncated/modified from the above function */
  258. function compose_Header($color, $mailbox) {
  259. global $javascript_on;
  260. /*
  261. * Locate the first displayable form element (only when JavaScript on)
  262. */
  263. if($javascript_on) {
  264. global $delimiter, $base_uri, $PHP_SELF, $data_dir, $username;
  265. $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
  266. switch ( $module ) {
  267. case 'src/search.php':
  268. $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1;
  269. $onload = "onload=\"document.forms[$pos].elements[2].focus();\"";
  270. displayHtmlHeader (_("Compose"));
  271. break;
  272. default:
  273. $js = '<script language="JavaScript" type="text/javascript">' .
  274. "\n<!--\n" .
  275. "function checkForm() {\n".
  276. "var f = document.forms.length;\n".
  277. "var i = 0;\n".
  278. "var pos = -1;\n".
  279. "while( pos == -1 && i < f ) {\n".
  280. "var e = document.forms[i].elements.length;\n".
  281. "var j = 0;\n".
  282. "while( pos == -1 && j < e ) {\n".
  283. "if ( document.forms[i].elements[j].type == 'text' ) {\n".
  284. "pos = j;\n".
  285. "}\n".
  286. "j++;\n".
  287. "}\n".
  288. "i++;\n".
  289. "}\n".
  290. "if( pos >= 0 ) {\n".
  291. "document.forms[i-1].elements[pos].focus();\n".
  292. "}\n".
  293. "}\n";
  294. $js .= "// -->\n".
  295. "</script>\n";
  296. $onload = 'onload="checkForm();"';
  297. displayHtmlHeader (_("Compose"), $js);
  298. break;
  299. }
  300. } else {
  301. /* javascript off */
  302. displayHtmlHeader(_("Compose"));
  303. $onload = '';
  304. }
  305. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  306. }
  307. ?>