page_header.php 12 KB

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