page_header.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <?php
  2. /**
  3. * page_header.php
  4. *
  5. * Copyright (c) 1999-2005 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. * @version $Id$
  11. * @package squirrelmail
  12. */
  13. /** Include required files from SM */
  14. require_once(SM_PATH . 'functions/strings.php');
  15. require_once(SM_PATH . 'functions/html.php');
  16. require_once(SM_PATH . 'functions/imap_mailbox.php');
  17. require_once(SM_PATH . 'functions/global.php');
  18. /**
  19. * Output a SquirrelMail page header, from <!doctype> to </head>
  20. * Always set up the language before calling these functions.
  21. *
  22. * @param string title the page title, default SquirrelMail.
  23. * @param string xtra extra HTML to insert into the header
  24. * @param bool do_hook whether to execute hooks, default true
  25. * @param bool frames generate html frameset doctype (since 1.5.1)
  26. * @return void
  27. */
  28. function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = true, $frames = false ) {
  29. global $squirrelmail_language;
  30. if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
  31. global $base_uri;
  32. }
  33. global $theme_css, $custom_css, $pageheader_sent;
  34. if ($frames) {
  35. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">';
  36. } else {
  37. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
  38. }
  39. echo "\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) .
  40. "<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n";
  41. /*
  42. * Add closing / to link and meta elements only after switching to xhtml 1.0 Transitional.
  43. * It is not compatible with html 4.01 Transitional
  44. */
  45. if ( !isset( $custom_css ) || $custom_css == 'none' ) {
  46. if ($theme_css != '') {
  47. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">";
  48. }
  49. } else {
  50. echo '<link rel="stylesheet" type="text/css" href="' .
  51. $base_uri . 'themes/css/'.$custom_css.'">';
  52. }
  53. if ($squirrelmail_language == 'ja_JP') {
  54. /*
  55. * force correct detection of charset, when browser does not follow
  56. * http content-type and tries to detect charset from page content.
  57. * Shooting of browser's creator can't be implemented in php.
  58. * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
  59. * recommendations and switch to unicode.
  60. */
  61. echo "<!-- \xfd\xfe -->\n";
  62. echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
  63. }
  64. if ($do_hook) {
  65. do_hook('generic_header');
  66. }
  67. echo "<title>$title</title>\n$xtra\n";
  68. /* work around IE6's scrollbar bug */
  69. echo <<<ECHO
  70. <style type="text/css">
  71. <!--
  72. /* avoid stupid IE6 bug with frames and scrollbars */
  73. body {
  74. voice-family: "\"}\"";
  75. voice-family: inherit;
  76. width: expression(document.documentElement.clientWidth - 30);
  77. }
  78. -->
  79. </style>
  80. ECHO;
  81. echo "\n</head>\n\n";
  82. /* this is used to check elsewhere whether we should call this function */
  83. $pageheader_sent = TRUE;
  84. }
  85. /**
  86. * Given a path to a SquirrelMail file, return a HTML link to it
  87. *
  88. * @param string path the SquirrelMail file to link to
  89. * @param string text the link text
  90. * @param string target the target frame for this link
  91. */
  92. function makeInternalLink($path, $text, $target='') {
  93. sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
  94. if ($target != '') {
  95. $target = " target=\"$target\"";
  96. }
  97. // This is an inefficient hook and is only used by
  98. // one plugin that still needs to patch this code,
  99. // plus if we are templat-izing SM, visual hooks
  100. // are not needed. However, I am leaving the code
  101. // here just in case we find a good (non-visual?)
  102. // use for the internal_link hook.
  103. //
  104. //$hooktext = do_hook_function('internal_link',$text);
  105. //if ($hooktext != '')
  106. // $text = $hooktext;
  107. return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
  108. }
  109. /**
  110. * Same as makeInternalLink, but echoes it too
  111. */
  112. function displayInternalLink($path, $text, $target='') {
  113. echo makeInternalLink($path, $text, $target);
  114. }
  115. /**
  116. * Outputs a complete SquirrelMail page header, starting with <!doctype> and
  117. * including the default menu bar. Uses displayHtmlHeader and takes
  118. * JavaScript and locale settings into account.
  119. *
  120. * @param array color the array of theme colors
  121. * @param string mailbox the current mailbox name to display
  122. * @param string xtra extra html code to add
  123. * @param bool session
  124. * @return void
  125. */
  126. function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
  127. global $hide_sm_attributions, $PHP_SELF, $frame_top,
  128. $compose_new_win, $compose_width, $compose_height,
  129. $provider_name, $provider_uri, $startMessage,
  130. $javascript_on, $default_use_mdn, $mdn_user_support;
  131. sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION );
  132. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
  133. $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
  134. if ($qmark = strpos($module, '?')) {
  135. $module = substr($module, 0, $qmark);
  136. }
  137. if (!isset($frame_top)) {
  138. $frame_top = '_top';
  139. }
  140. if ($session) {
  141. $compose_uri = $base_uri.'src/compose.php?mailbox='.urlencode($mailbox).'&amp;attachedmessages=true&amp;session='."$session";
  142. } else {
  143. $compose_uri = $base_uri.'src/compose.php?newmessage=1';
  144. $session = 0;
  145. }
  146. if( $javascript_on || strpos($xtra, 'new_js_autodetect_results.value') ) {
  147. switch ( $module ) {
  148. case 'src/read_body.php':
  149. $js ='';
  150. // compose in new window code
  151. if ($compose_new_win == '1') {
  152. if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
  153. $compose_width = '640';
  154. }
  155. if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
  156. $compose_height = '550';
  157. }
  158. $js .= "function comp_in_new_form(comp_uri, button, myform) {\n".
  159. ' if (!comp_uri) {'."\n".
  160. ' comp_uri = "'.$compose_uri."\";\n".
  161. ' }'. "\n".
  162. ' comp_uri += "&" + button.name + "=1";'."\n".
  163. ' for ( var i=0; i < myform.elements.length; i++ ) {'."\n".
  164. ' if ( myform.elements[i].type == "checkbox" && myform.elements[i].checked )'."\n".
  165. ' comp_uri += "&" + myform.elements[i].name + "=1";'."\n".
  166. ' }'."\n".
  167. ' var newwin = window.open(comp_uri' .
  168. ', "_blank",'.
  169. '"width='.$compose_width. ',height='.$compose_height.
  170. ',scrollbars=yes,resizable=yes,status=yes");'."\n".
  171. "}\n\n";
  172. $js .= "function comp_in_new(comp_uri) {\n".
  173. " if (!comp_uri) {\n".
  174. ' comp_uri = "'.$compose_uri."\";\n".
  175. ' }'. "\n".
  176. ' var newwin = window.open(comp_uri' .
  177. ', "_blank",'.
  178. '"width='.$compose_width. ',height='.$compose_height.
  179. ',scrollbars=yes,resizable=yes,status=yes");'."\n".
  180. "}\n\n";
  181. }
  182. // javascript for sending read receipts
  183. if($default_use_mdn && $mdn_user_support) {
  184. $js .= 'function sendMDN() {'."\n".
  185. " mdnuri=window.location+'&sendreceipt=1'; ".
  186. "var newwin = window.open(mdnuri,'right');".
  187. "\n}\n\n";
  188. }
  189. // if any of the above passes, add the JS tags too.
  190. if($js) {
  191. $js = "\n".'<script language="JavaScript" type="text/javascript">' .
  192. "\n<!--\n" . $js . "// -->\n</script>\n";
  193. }
  194. displayHtmlHeader ('SquirrelMail', $js);
  195. $onload = $xtra;
  196. break;
  197. case 'src/compose.php':
  198. $js = '<script language="JavaScript" type="text/javascript">' .
  199. "\n<!--\n" .
  200. "function checkForm() {\n";
  201. global $action, $reply_focus;
  202. if (strpos($action, 'reply') !== FALSE && $reply_focus)
  203. {
  204. if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
  205. else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
  206. else if ($reply_focus == 'none') $js .= "}\n";
  207. }
  208. // no reply focus also applies to composing new messages
  209. else if ($reply_focus == 'none')
  210. {
  211. $js .= "}\n";
  212. }
  213. else
  214. $js .= "var f = document.forms.length;\n".
  215. "var i = 0;\n".
  216. "var pos = -1;\n".
  217. "while( pos == -1 && i < f ) {\n".
  218. "var e = document.forms[i].elements.length;\n".
  219. "var j = 0;\n".
  220. "while( pos == -1 && j < e ) {\n".
  221. "if ( document.forms[i].elements[j].type == 'text' ) {\n".
  222. "pos = j;\n".
  223. "}\n".
  224. "j++;\n".
  225. "}\n".
  226. "i++;\n".
  227. "}\n".
  228. "if( pos >= 0 ) {\n".
  229. "document.forms[i-1].elements[pos].focus();\n".
  230. "}\n".
  231. "}\n";
  232. $js .= "// -->\n".
  233. "</script>\n";
  234. $onload = 'onload="checkForm();"';
  235. displayHtmlHeader ('SquirrelMail', $js);
  236. break;
  237. case 'src/right_main.php':
  238. global $fancy_index_highlite;
  239. if (!$fancy_index_highlite) {
  240. $js = '';
  241. } else //{ putting braces around this block creats strange PHP errors
  242. // following code graciously borrowed from
  243. // phpMyAdmin project at:
  244. // http://www.phpmyadmin.net
  245. $js = <<<EOS
  246. /**
  247. * This array is used to remember mark status of rows in browse mode
  248. */
  249. var marked_row = new Array;
  250. /*
  251. * (un)Checks checkbox for the row that the current table cell is in
  252. * when it gets clicked.
  253. *
  254. * @param string the name of the checkbox that should be (un)checked
  255. */
  256. function row_click(chkboxName) {
  257. chkbox = document.getElementById(chkboxName);
  258. if (chkbox) {
  259. chkbox.checked = (chkbox.checked ? false : true);
  260. }
  261. }
  262. /*
  263. * Sets/unsets the pointer and marker in browse mode
  264. *
  265. * @param object the table row
  266. * @param integer the row number
  267. * @param string the action calling this script (over, out or click)
  268. * @param string the default background color
  269. * @param string the color to use for mouseover
  270. * @param string the color to use for marking a row
  271. *
  272. * @return boolean whether pointer is set or not
  273. */
  274. function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
  275. {
  276. var theCells = null;
  277. // 1. Pointer and mark feature are disabled or the browser can't get the
  278. // row -> exits
  279. if ((thePointerColor == '' && theMarkColor == '')
  280. || typeof(theRow.style) == 'undefined') {
  281. return false;
  282. }
  283. // 2. Gets the current row and exits if the browser can't get it
  284. if (typeof(document.getElementsByTagName) != 'undefined') {
  285. theCells = theRow.getElementsByTagName('td');
  286. }
  287. else if (typeof(theRow.cells) != 'undefined') {
  288. theCells = theRow.cells;
  289. }
  290. else {
  291. return false;
  292. }
  293. // 3. Gets the current color...
  294. var rowCellsCnt = theCells.length;
  295. var domDetect = null;
  296. var currentColor = null;
  297. var newColor = null;
  298. // 3.1 ... with DOM compatible browsers except Opera that does not return
  299. // valid values with "getAttribute"
  300. if (typeof(window.opera) == 'undefined'
  301. && typeof(theCells[0].getAttribute) != 'undefined') {
  302. currentColor = theCells[0].getAttribute('bgcolor');
  303. domDetect = true;
  304. }
  305. // 3.2 ... with other browsers
  306. else {
  307. currentColor = theCells[0].style.backgroundColor;
  308. domDetect = false;
  309. } // end 3
  310. // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
  311. if (currentColor.indexOf("rgb") >= 0)
  312. {
  313. var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
  314. currentColor.indexOf(')'));
  315. var rgbValues = rgbStr.split(",");
  316. currentColor = "#";
  317. var hexChars = "0123456789ABCDEF";
  318. for (var i = 0; i < 3; i++)
  319. {
  320. var v = rgbValues[i].valueOf();
  321. currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
  322. }
  323. }
  324. // 4. Defines the new color
  325. // 4.1 Current color is the default one
  326. if (currentColor == ''
  327. || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
  328. if (theAction == 'over' && thePointerColor != '') {
  329. newColor = thePointerColor;
  330. }
  331. else if (theAction == 'click' && theMarkColor != '') {
  332. newColor = theMarkColor;
  333. marked_row[theRowNum] = true;
  334. // deactivated onclick marking of the checkbox because it's also executed
  335. // when an action (clicking on the checkbox itself) on a single item is
  336. // performed. Then the checkbox would get deactived, even though we need
  337. // it activated. Maybe there is a way to detect if the row was clicked,
  338. // and not an item therein...
  339. //document.getElementById('msg[' + theRowNum + ']').checked = true;
  340. }
  341. }
  342. // 4.1.2 Current color is the pointer one
  343. else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
  344. && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
  345. if (theAction == 'out') {
  346. newColor = theDefaultColor;
  347. }
  348. else if (theAction == 'click' && theMarkColor != '') {
  349. newColor = theMarkColor;
  350. marked_row[theRowNum] = true;
  351. //document.getElementById('msg[' + theRowNum + ']').checked = true;
  352. }
  353. }
  354. // 4.1.3 Current color is the marker one
  355. else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
  356. if (theAction == 'click') {
  357. newColor = (thePointerColor != '')
  358. ? thePointerColor
  359. : theDefaultColor;
  360. marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
  361. ? true
  362. : null;
  363. //document.getElementById('msg[' + theRowNum + ']').checked = false;
  364. }
  365. } // end 4
  366. // 5. Sets the new color...
  367. if (newColor) {
  368. var c = null;
  369. // 5.1 ... with DOM compatible browsers except Opera
  370. if (domDetect) {
  371. for (c = 0; c < rowCellsCnt; c++) {
  372. theCells[c].setAttribute('bgcolor', newColor, 0);
  373. } // end for
  374. }
  375. // 5.2 ... with other browsers
  376. else {
  377. for (c = 0; c < rowCellsCnt; c++) {
  378. theCells[c].style.backgroundColor = newColor;
  379. }
  380. }
  381. } // end 5
  382. return true;
  383. } // end of the 'setPointer()' function
  384. EOS;
  385. //} putting braces around this block creats strange PHP errors
  386. $js = "\n".'<script language="JavaScript" type="text/javascript">' .
  387. "\n<!--\n" . $js;
  388. if ($compose_new_win == '1') {
  389. if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
  390. $compose_width = '640';
  391. }
  392. if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
  393. $compose_height = '550';
  394. }
  395. $js .= "\n\nfunction comp_in_new(comp_uri) {\n".
  396. " if (!comp_uri) {\n".
  397. ' comp_uri = "'.$compose_uri."\";\n".
  398. ' }'. "\n".
  399. ' var newwin = window.open(comp_uri' .
  400. ', "_blank",'.
  401. '"width='.$compose_width. ',height='.$compose_height.
  402. ',scrollbars=yes,resizable=yes,status=yes");'."\n".
  403. "}\n\n";
  404. }
  405. $js .= $xtra . "\n\n// -->\n</script>\n";
  406. $onload = '';
  407. displayHtmlHeader ('SquirrelMail', $js);
  408. break;
  409. default:
  410. $js = '<script language="JavaScript" type="text/javascript">' .
  411. "\n<!--\n" .
  412. "function checkForm() {\n".
  413. "var f = document.forms.length;\n".
  414. "var i = 0;\n".
  415. "var pos = -1;\n".
  416. "while( pos == -1 && i < f ) {\n".
  417. "var e = document.forms[i].elements.length;\n".
  418. "var j = 0;\n".
  419. "while( pos == -1 && j < e ) {\n".
  420. "if ( document.forms[i].elements[j].type == 'text' " .
  421. "|| document.forms[i].elements[j].type == 'password' ) {\n".
  422. "pos = j;\n".
  423. "}\n".
  424. "j++;\n".
  425. "}\n".
  426. "i++;\n".
  427. "}\n".
  428. "if( pos >= 0 ) {\n".
  429. "document.forms[i-1].elements[pos].focus();\n".
  430. "}\n".
  431. "$xtra\n".
  432. "}\n";
  433. if ($compose_new_win == '1') {
  434. if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
  435. $compose_width = '640';
  436. }
  437. if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
  438. $compose_height = '550';
  439. }
  440. $js .= "function comp_in_new(comp_uri) {\n".
  441. " if (!comp_uri) {\n".
  442. ' comp_uri = "'.$compose_uri."\";\n".
  443. ' }'. "\n".
  444. ' var newwin = window.open(comp_uri' .
  445. ', "_blank",'.
  446. '"width='.$compose_width. ',height='.$compose_height.
  447. ',scrollbars=yes,resizable=yes,status=yes");'."\n".
  448. "}\n\n";
  449. }
  450. $js .= "// -->\n". "</script>\n";
  451. $onload = 'onload="checkForm();"';
  452. displayHtmlHeader ('SquirrelMail', $js);
  453. break;
  454. }
  455. } else {
  456. /* do not use JavaScript */
  457. displayHtmlHeader ('SquirrelMail');
  458. $onload = '';
  459. }
  460. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  461. /** Here is the header and wrapping table **/
  462. $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
  463. readShortMailboxName($mailbox, $delimiter)));
  464. if ( $shortBoxName == 'INBOX' ) {
  465. $shortBoxName = _("INBOX");
  466. }
  467. echo "<a name=\"pagetop\"></a>\n"
  468. . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
  469. . html_tag( 'tr', '', '', $color[9] ) ."\n"
  470. . html_tag( 'td', '', 'left' ) ."\n";
  471. if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
  472. echo ' ' . _("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
  473. } else {
  474. echo '&nbsp;';
  475. }
  476. echo " </td>\n"
  477. . html_tag( 'td', '', 'right' ) ."<b>\n";
  478. displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
  479. echo "</b></td>\n"
  480. . " </tr>\n"
  481. . html_tag( 'tr', '', '', $color[4] ) ."\n"
  482. . ($hide_sm_attributions ? html_tag( 'td', '', 'left', '', 'colspan="2"' )
  483. : html_tag( 'td', '', 'left' ) )
  484. . "\n";
  485. $urlMailbox = urlencode($mailbox);
  486. echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&amp;startMessage='.$startMessage);
  487. echo "&nbsp;&nbsp;\n";
  488. displayInternalLink ('src/addressbook.php', _("Addresses"));
  489. echo "&nbsp;&nbsp;\n";
  490. displayInternalLink ('src/folders.php', _("Folders"));
  491. echo "&nbsp;&nbsp;\n";
  492. displayInternalLink ('src/options.php', _("Options"));
  493. echo "&nbsp;&nbsp;\n";
  494. displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"));
  495. echo "&nbsp;&nbsp;\n";
  496. displayInternalLink ('src/help.php', _("Help"));
  497. echo "&nbsp;&nbsp;\n";
  498. do_hook('menuline');
  499. echo " </td>\n";
  500. if (!$hide_sm_attributions)
  501. {
  502. echo html_tag( 'td', '', 'right' ) ."\n";
  503. if (empty($provider_uri)) {
  504. echo '<a href="about.php">SquirrelMail</a>';
  505. } else {
  506. if (empty($provider_name)) $provider_name= 'SquirrelMail';
  507. echo '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>';
  508. }
  509. echo "</td>\n";
  510. }
  511. echo " </tr>\n".
  512. "</table><br />\n\n";
  513. }
  514. /**
  515. * Blatantly copied/truncated/modified from displayPageHeader.
  516. * Outputs a page header specifically for the compose_in_new popup window
  517. *
  518. * @param array color the array of theme colors
  519. * @param string mailbox the current mailbox name to display
  520. * @return void
  521. */
  522. function compose_Header($color, $mailbox) {
  523. global $javascript_on;
  524. /*
  525. * Locate the first displayable form element (only when JavaScript on)
  526. */
  527. if($javascript_on) {
  528. global $base_uri, $PHP_SELF, $data_dir, $username;
  529. $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
  530. switch ( $module ) {
  531. case 'src/search.php':
  532. $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1;
  533. $onload = "onload=\"document.forms[$pos].elements[2].focus();\"";
  534. displayHtmlHeader (_("Compose"));
  535. break;
  536. default:
  537. $js = '<script language="JavaScript" type="text/javascript">' .
  538. "\n<!--\n" .
  539. "function checkForm() {\n";
  540. global $action, $reply_focus;
  541. if (strpos($action, 'reply') !== FALSE && $reply_focus)
  542. {
  543. if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
  544. else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
  545. else if ($reply_focus == 'none') $js .= "}\n";
  546. }
  547. // no reply focus also applies to composing new messages
  548. else if ($reply_focus == 'none')
  549. {
  550. $js .= "}\n";
  551. }
  552. else
  553. $js .= "var f = document.forms.length;\n".
  554. "var i = 0;\n".
  555. "var pos = -1;\n".
  556. "while( pos == -1 && i < f ) {\n".
  557. "var e = document.forms[i].elements.length;\n".
  558. "var j = 0;\n".
  559. "while( pos == -1 && j < e ) {\n".
  560. "if ( document.forms[i].elements[j].type == 'text' ) {\n".
  561. "pos = j;\n".
  562. "}\n".
  563. "j++;\n".
  564. "}\n".
  565. "i++;\n".
  566. "}\n".
  567. "if( pos >= 0 ) {\n".
  568. "document.forms[i-1].elements[pos].focus();\n".
  569. "}\n".
  570. "}\n";
  571. $js .= "// -->\n".
  572. "</script>\n";
  573. $onload = 'onload="checkForm();"';
  574. displayHtmlHeader (_("Compose"), $js);
  575. break;
  576. }
  577. } else {
  578. /* javascript off */
  579. displayHtmlHeader(_("Compose"));
  580. $onload = '';
  581. }
  582. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  583. }
  584. ?>