Fixed/restored reply focus functionality
[squirrelmail.git] / functions / page_header.php
CommitLineData
59177427 1<?php
7350889b 2
35586184 3/**
4 * page_header.php
5 *
35586184 6 * Prints the page header (duh)
7 *
4b4abf93 8 * @copyright &copy; 1999-2005 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
31841a9e 10 * @version $Id$
d6c32258 11 * @package squirrelmail
35586184 12 */
13
d6c32258 14/** Include required files from SM */
b68edc75 15require_once(SM_PATH . 'functions/strings.php');
16require_once(SM_PATH . 'functions/html.php');
17require_once(SM_PATH . 'functions/imap_mailbox.php');
0b97a708 18require_once(SM_PATH . 'functions/global.php');
b68edc75 19
d6c32258 20/**
8b096f0a 21 * Output a SquirrelMail page header, from <!doctype> to </head>
22 * Always set up the language before calling these functions.
23 *
24 * @param string title the page title, default SquirrelMail.
25 * @param string xtra extra HTML to insert into the header
26 * @param bool do_hook whether to execute hooks, default true
62b9c984 27 * @param bool frames generate html frameset doctype (since 1.5.1)
8b096f0a 28 * @return void
d6c32258 29 */
62b9c984 30function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = true, $frames = false ) {
e842b215 31 global $squirrelmail_language;
692155b7 32
0365891c 33 if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
0b97a708 34 global $base_uri;
35 }
b6c283c4 36 global $theme_css, $custom_css, $pageheader_sent;
2c21ef20 37
62b9c984 38 if ($frames) {
39 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">';
91e0dccc 40 } else {
62b9c984 41 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
42 }
f9f738dc 43 echo "\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) .
44 "<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n";
2c21ef20 45
fcae5445 46 /*
47 * Add closing / to link and meta elements only after switching to xhtml 1.0 Transitional.
48 * It is not compatible with html 4.01 Transitional
49 */
a714cb95 50 if ( !isset( $custom_css ) || $custom_css == 'none' ) {
692155b7 51 if ($theme_css != '') {
fcae5445 52 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">";
692155b7 53 }
8f1ba72b 54 } else {
d68323ff 55 echo '<link rel="stylesheet" type="text/css" href="' .
fcae5445 56 $base_uri . 'themes/css/'.$custom_css.'">';
8f1ba72b 57 }
62f7daa5 58
6299388d 59 echo '<link rel="stylesheet" type="text/css" href="'. $base_uri .'templates/default/squirrelmail.css">';
e2f43bfa 60
e842b215 61 if ($squirrelmail_language == 'ja_JP') {
683b7853 62 /*
e50f5ac2 63 * force correct detection of charset, when browser does not follow
683b7853 64 * http content-type and tries to detect charset from page content.
65 * Shooting of browser's creator can't be implemented in php.
e50f5ac2 66 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
683b7853 67 * recommendations and switch to unicode.
e50f5ac2 68 */
e842b215 69 echo "<!-- \xfd\xfe -->\n";
fcae5445 70 echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
e842b215 71 }
237470b4 72 if ($do_hook) {
d68323ff 73 do_hook('generic_header');
237470b4 74 }
62f7daa5 75
f9f738dc 76 echo "<title>$title</title>\n$xtra\n";
5ca4b1ee 77
78 /* work around IE6's scrollbar bug */
79 echo <<<ECHO
80<style type="text/css">
81<!--
82 /* avoid stupid IE6 bug with frames and scrollbars */
62f7daa5 83 body {
84 voice-family: "\"}\"";
85 voice-family: inherit;
5ca4b1ee 86 width: expression(document.documentElement.clientWidth - 30);
87 }
88-->
89</style>
90
91ECHO;
92
93 echo "\n</head>\n\n";
b6c283c4 94
95 /* this is used to check elsewhere whether we should call this function */
96 $pageheader_sent = TRUE;
a07cd1a4 97}
98
8b096f0a 99/**
100 * Given a path to a SquirrelMail file, return a HTML link to it
101 *
102 * @param string path the SquirrelMail file to link to
103 * @param string text the link text
104 * @param string target the target frame for this link
105 */
d62c4938 106function makeInternalLink($path, $text, $target='') {
0365891c 107 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
dcc1cc82 108 if ($target != '') {
109 $target = " target=\"$target\"";
110 }
4910106a 111
e50f5ac2 112 // This is an inefficient hook and is only used by
4910106a 113 // one plugin that still needs to patch this code,
e50f5ac2 114 // plus if we are templat-izing SM, visual hooks
115 // are not needed. However, I am leaving the code
116 // here just in case we find a good (non-visual?)
4910106a 117 // use for the internal_link hook.
118 //
119 //$hooktext = do_hook_function('internal_link',$text);
120 //if ($hooktext != '')
121 // $text = $hooktext;
122
d62c4938 123 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
124}
125
8b096f0a 126/**
127 * Same as makeInternalLink, but echoes it too
128 */
d62c4938 129function displayInternalLink($path, $text, $target='') {
b26d81e5 130 echo makeInternalLink($path, $text, $target);
a07cd1a4 131}
132
8b096f0a 133/**
134 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
135 * including the default menu bar. Uses displayHtmlHeader and takes
136 * JavaScript and locale settings into account.
137 *
138 * @param array color the array of theme colors
139 * @param string mailbox the current mailbox name to display
91c27aee 140 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
141 * @param string sBodyTagJs js events to be inserted in the body tag
8b096f0a 142 * @return void
143 */
715225af 144
10bf80c0 145function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
146
147 global $reply_focus, $hide_sm_attributions, $frame_top,
ce68b76b 148 $provider_name, $provider_uri, $startMessage,
10bf80c0 149 $javascript_on, $action;
150
151 if (empty($sBodyTagJs)) {
152 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
153 if ($reply_focus == 'select')
154 $sBodyTagJs = 'onload="checkForm(\'select\');"';
155 else if ($reply_focus == 'focus')
156 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
157 else if ($reply_focus != 'none')
158 $sBodyTagJs = 'onload="checkForm();"';
159 }
160 else
161 $sBodyTagJs = 'onload="checkForm();"';
162 }
163
715225af 164
0365891c 165 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
91c27aee 166
d03f3582 167 if (!isset($frame_top)) {
168 $frame_top = '_top';
169 }
715225af 170
c18f58c5 171 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
a3d59ec3 172 $sJsBlock = '<script src="'. SM_PATH .'templates/default/js/default.js" type="text/javascript" language="JavaScript"></script>' ."\n";
91c27aee 173 if ($sHeaderJs) {
a3d59ec3 174 $sJsBlock .= "\n<script language=\"JavaScript\" type=\"text/javascript\">" .
91c27aee 175 "\n<!--\n" .
a3d59ec3 176 $sHeaderJs . "\n\n// -->\n</script>\n";
d62c4938 177 }
91c27aee 178 displayHtmlHeader ('SquirrelMail', $sJsBlock);
179 } else {
d62c4938 180 /* do not use JavaScript */
181 displayHtmlHeader ('SquirrelMail');
91c27aee 182 $sBodyTagJs = '';
715225af 183 }
184
91c27aee 185 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
186
a07cd1a4 187 /** Here is the header and wrapping table **/
72520f77 188 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
91e0dccc 189 readShortMailboxName($mailbox, $delimiter)));
3b7d68e6 190 if ( $shortBoxName == 'INBOX' ) {
7da23762 191 $shortBoxName = _("INBOX");
192 }
b01b21d0 193 echo "<a name=\"pagetop\"></a>\n"
194 . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
195 . html_tag( 'tr', '', '', $color[9] ) ."\n"
196 . html_tag( 'td', '', 'left' ) ."\n";
5bb2a991 197 if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
b01b21d0 198 echo ' ' . _("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
5bb2a991 199 } else {
200 echo '&nbsp;';
201 }
b01b21d0 202 echo " </td>\n"
203 . html_tag( 'td', '', 'right' ) ."<b>\n";
80e86e94 204 displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
b01b21d0 205 echo "</b></td>\n"
206 . " </tr>\n"
207 . html_tag( 'tr', '', '', $color[4] ) ."\n"
99ea51d3 208 . ($hide_sm_attributions ? html_tag( 'td', '', 'left', '', 'colspan="2"' )
209 : html_tag( 'td', '', 'left' ) )
210 . "\n";
a07cd1a4 211 $urlMailbox = urlencode($mailbox);
0493ed11 212 $startMessage = (int)$startMessage;
213
e233a3ad 214 echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&amp;startMessage='.$startMessage);
a07cd1a4 215 echo "&nbsp;&nbsp;\n";
21a957a9 216 displayInternalLink ('src/addressbook.php', _("Addresses"));
a07cd1a4 217 echo "&nbsp;&nbsp;\n";
21a957a9 218 displayInternalLink ('src/folders.php', _("Folders"));
a07cd1a4 219 echo "&nbsp;&nbsp;\n";
21a957a9 220 displayInternalLink ('src/options.php', _("Options"));
a07cd1a4 221 echo "&nbsp;&nbsp;\n";
21a957a9 222 displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"));
a07cd1a4 223 echo "&nbsp;&nbsp;\n";
21a957a9 224 displayInternalLink ('src/help.php', _("Help"));
a07cd1a4 225 echo "&nbsp;&nbsp;\n";
226
d68323ff 227 do_hook('menuline');
a07cd1a4 228
99ea51d3 229 echo " </td>\n";
230
231 if (!$hide_sm_attributions)
232 {
233 echo html_tag( 'td', '', 'right' ) ."\n";
8b5c49cd 234 if (empty($provider_uri)) {
235 echo '<a href="about.php">SquirrelMail</a>';
236 } else {
237 if (empty($provider_name)) $provider_name= 'SquirrelMail';
238 echo '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>';
239 }
99ea51d3 240 echo "</td>\n";
241 }
242 echo " </tr>\n".
04fa3c41 243 "</table><br />\n\n";
a07cd1a4 244}
2ba13803 245
8b096f0a 246/**
247 * Blatantly copied/truncated/modified from displayPageHeader.
248 * Outputs a page header specifically for the compose_in_new popup window
249 *
250 * @param array color the array of theme colors
251 * @param string mailbox the current mailbox name to display
91c27aee 252 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
253 * @param string sBodyTagJs js events to be inserted in the body tag
8b096f0a 254 * @return void
255 */
10bf80c0 256function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
257
258 global $reply_focus, $javascript_on, $action;
259
260 if (empty($sBodyTagJs)) {
261 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
262 if ($reply_focus == 'select')
263 $sBodyTagJs = 'onload="checkForm(\'select\');"';
264 else if ($reply_focus == 'focus')
265 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
266 else if ($reply_focus != 'none')
267 $sBodyTagJs = 'onload="checkForm();"';
268 }
269 else
270 $sBodyTagJs = 'onload="checkForm();"';
271 }
272
273
9c3e6cd4 274 /*
d62c4938 275 * Locate the first displayable form element (only when JavaScript on)
276 */
277 if($javascript_on) {
91c27aee 278 if ($sHeaderJs) {
279 $sJsBlock = "\n<script language=\"JavaScript\" type=\"text/javascript\">" .
280 "\n<!--\n" .
a3d59ec3 281 $sHeaderJs . "\n\n// -->\n</script>\n";
91c27aee 282 } else {
283 $sJsBlock = '';
d62c4938 284 }
91c27aee 285 $sJsBlock .= "\n" . '<script src="'. SM_PATH .'templates/default/js/default.js" type="text/javascript" language="JavaScript"></script>' ."\n";
286 displayHtmlHeader (_("Compose"), $sJsBlock);
d62c4938 287 } else {
288 /* javascript off */
289 displayHtmlHeader(_("Compose"));
290 $onload = '';
9c3e6cd4 291 }
91c27aee 292 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
9c3e6cd4 293}
10bf80c0 294?>