page_header.php 12 KB

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