page_header.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
  64. }
  65. function displayInternalLink($path, $text, $target='') {
  66. echo makeInternalLink($path, $text, $target);
  67. }
  68. function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
  69. global $hide_sm_attributions, $PHP_SELF, $frame_top,
  70. $compose_new_win, $compose_width, $compose_height,
  71. $attachemessages, $provider_name, $provider_uri,
  72. $javascript_on, $default_use_mdn, $mdn_user_support;
  73. sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION );
  74. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
  75. $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
  76. if ($qmark = strpos($module, '?')) {
  77. $module = substr($module, 0, $qmark);
  78. }
  79. if (!isset($frame_top)) {
  80. $frame_top = '_top';
  81. }
  82. if ($session) {
  83. $compose_uri = $base_uri.'src/compose.php?mailbox='.urlencode($mailbox).'&amp;attachedmessages=true&amp;session='."$session";
  84. } else {
  85. $compose_uri = $base_uri.'src/compose.php?newmessage=1';
  86. $session = 0;
  87. }
  88. if($javascript_on) {
  89. switch ( $module ) {
  90. case 'src/read_body.php':
  91. $js ='';
  92. // compose in new window code
  93. if ($compose_new_win == '1') {
  94. if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
  95. $compose_width = '640';
  96. }
  97. if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
  98. $compose_height = '550';
  99. }
  100. $js .= "function comp_in_new(comp_uri) {\n".
  101. " if (!comp_uri) {\n".
  102. ' comp_uri = "'.$compose_uri."\";\n".
  103. ' }'. "\n".
  104. ' var newwin = window.open(comp_uri' .
  105. ', "_blank",'.
  106. '"width='.$compose_width. ',height='.$compose_height.
  107. ',scrollbars=yes,resizable=yes");'."\n".
  108. "}\n\n";
  109. }
  110. // javascript for sending read receipts
  111. if($default_use_mdn && $mdn_user_support) {
  112. $js .= 'function sendMDN() {'."\n".
  113. " mdnuri=window.location+'&sendreceipt=1'; ".
  114. "var newwin = window.open(mdnuri,'right');".
  115. "\n}\n\n";
  116. }
  117. // if any of the above passes, add the JS tags too.
  118. if($js) {
  119. $js = "\n".'<script language="JavaScript" type="text/javascript">' .
  120. "\n<!--\n" . $js . "// -->\n</script>\n";
  121. }
  122. displayHtmlHeader ('SquirrelMail', $js);
  123. $onload = $xtra;
  124. break;
  125. case 'src/compose.php':
  126. $js = '<script language="JavaScript" type="text/javascript">' .
  127. "\n<!--\n" .
  128. "function checkForm() {\n".
  129. "var f = document.forms.length;\n".
  130. "var i = 0;\n".
  131. "var pos = -1;\n".
  132. "while( pos == -1 && i < f ) {\n".
  133. "var e = document.forms[i].elements.length;\n".
  134. "var j = 0;\n".
  135. "while( pos == -1 && j < e ) {\n".
  136. "if ( document.forms[i].elements[j].type == 'text' ) {\n".
  137. "pos = j;\n".
  138. "}\n".
  139. "j++;\n".
  140. "}\n".
  141. "i++;\n".
  142. "}\n".
  143. "if( pos >= 0 ) {\n".
  144. "document.forms[i-1].elements[pos].focus();\n".
  145. "}\n".
  146. "}\n";
  147. $js .= "// -->\n".
  148. "</script>\n";
  149. $onload = 'onload="checkForm();"';
  150. displayHtmlHeader ('SquirrelMail', $js);
  151. break;
  152. default:
  153. $js = '<script language="JavaScript" type="text/javascript">' .
  154. "\n<!--\n" .
  155. "function checkForm() {\n".
  156. "var f = document.forms.length;\n".
  157. "var i = 0;\n".
  158. "var pos = -1;\n".
  159. "while( pos == -1 && i < f ) {\n".
  160. "var e = document.forms[i].elements.length;\n".
  161. "var j = 0;\n".
  162. "while( pos == -1 && j < e ) {\n".
  163. "if ( document.forms[i].elements[j].type == 'text' " .
  164. "|| document.forms[i].elements[j].type == 'password' ) {\n".
  165. "pos = j;\n".
  166. "}\n".
  167. "j++;\n".
  168. "}\n".
  169. "i++;\n".
  170. "}\n".
  171. "if( pos >= 0 ) {\n".
  172. "document.forms[i-1].elements[pos].focus();\n".
  173. "}\n".
  174. "$xtra\n".
  175. "}\n";
  176. if ($compose_new_win == '1') {
  177. if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
  178. $compose_width = '640';
  179. }
  180. if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
  181. $compose_height = '550';
  182. }
  183. $js .= "function comp_in_new(comp_uri) {\n".
  184. " if (!comp_uri) {\n".
  185. ' comp_uri = "'.$compose_uri."\";\n".
  186. ' }'. "\n".
  187. ' var newwin = window.open(comp_uri' .
  188. ', "_blank",'.
  189. '"width='.$compose_width. ',height='.$compose_height.
  190. ',scrollbars=yes,resizable=yes");'."\n".
  191. "}\n\n";
  192. }
  193. $js .= "// -->\n". "</script>\n";
  194. $onload = 'onload="checkForm();"';
  195. displayHtmlHeader ('SquirrelMail', $js);
  196. break;
  197. }
  198. } else {
  199. /* do not use JavaScript */
  200. displayHtmlHeader ('SquirrelMail');
  201. $onload = '';
  202. }
  203. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  204. /** Here is the header and wrapping table **/
  205. $shortBoxName = imap_utf7_decode_local(
  206. readShortMailboxName($mailbox, $delimiter));
  207. if ( $shortBoxName == 'INBOX' ) {
  208. $shortBoxName = _("INBOX");
  209. }
  210. echo "<a name=\"pagetop\"></a>\n"
  211. . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
  212. . html_tag( 'tr', '', '', $color[9] ) ."\n"
  213. . html_tag( 'td', '', 'left' ) ."\n";
  214. if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
  215. echo ' ' . _("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
  216. } else {
  217. echo '&nbsp;';
  218. }
  219. echo " </td>\n"
  220. . html_tag( 'td', '', 'right' ) ."<b>\n";
  221. displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
  222. echo "</b></td>\n"
  223. . " </tr>\n"
  224. . html_tag( 'tr', '', '', $color[4] ) ."\n"
  225. . html_tag( 'td', '', 'left' ) ."\n";
  226. $urlMailbox = urlencode($mailbox);
  227. echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox);
  228. echo "&nbsp;&nbsp;\n";
  229. displayInternalLink ('src/addressbook.php', _("Addresses"), 'right');
  230. echo "&nbsp;&nbsp;\n";
  231. displayInternalLink ('src/folders.php', _("Folders"), 'right');
  232. echo "&nbsp;&nbsp;\n";
  233. displayInternalLink ('src/options.php', _("Options"), 'right');
  234. echo "&nbsp;&nbsp;\n";
  235. displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"), 'right');
  236. echo "&nbsp;&nbsp;\n";
  237. displayInternalLink ('src/help.php', _("Help"), 'right');
  238. echo "&nbsp;&nbsp;\n";
  239. do_hook('menuline');
  240. echo " </td>\n"
  241. . html_tag( 'td', '', 'right' ) ."\n";
  242. if (!isset($provider_uri)) $provider_uri= 'http://www.squirrelmail.org/';
  243. if (!isset($provider_name)) $provider_name= 'SquirrelMail';
  244. echo ($hide_sm_attributions ? '&nbsp;' :
  245. '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>');
  246. echo "</td>\n".
  247. " </tr>\n".
  248. "</table><br>\n\n";
  249. }
  250. /* blatently copied/truncated/modified from the above function */
  251. function compose_Header($color, $mailbox) {
  252. global $javascript_on;
  253. /*
  254. * Locate the first displayable form element (only when JavaScript on)
  255. */
  256. if($javascript_on) {
  257. global $delimiter, $base_uri, $PHP_SELF, $data_dir, $username;
  258. $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
  259. switch ( $module ) {
  260. case 'src/search.php':
  261. $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1;
  262. $onload = "onload=\"document.forms[$pos].elements[2].focus();\"";
  263. displayHtmlHeader (_("Compose"));
  264. break;
  265. default:
  266. $js = '<script language="JavaScript" type="text/javascript">' .
  267. "\n<!--\n" .
  268. "function checkForm() {\n".
  269. "var f = document.forms.length;\n".
  270. "var i = 0;\n".
  271. "var pos = -1;\n".
  272. "while( pos == -1 && i < f ) {\n".
  273. "var e = document.forms[i].elements.length;\n".
  274. "var j = 0;\n".
  275. "while( pos == -1 && j < e ) {\n".
  276. "if ( document.forms[i].elements[j].type == 'text' ) {\n".
  277. "pos = j;\n".
  278. "}\n".
  279. "j++;\n".
  280. "}\n".
  281. "i++;\n".
  282. "}\n".
  283. "if( pos >= 0 ) {\n".
  284. "document.forms[i-1].elements[pos].focus();\n".
  285. "}\n".
  286. "}\n";
  287. $js .= "// -->\n".
  288. "</script>\n";
  289. $onload = 'onload="checkForm();"';
  290. displayHtmlHeader (_("Compose"), $js);
  291. break;
  292. }
  293. } else {
  294. /* javascript off */
  295. displayHtmlHeader(_("Compose"));
  296. $onload = '';
  297. }
  298. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  299. }
  300. ?>