adding option that allows html transitional or frameset doctype
[squirrelmail.git] / functions / page_header.php
CommitLineData
59177427 1<?php
7350889b 2
35586184 3/**
4 * page_header.php
5 *
82d304a0 6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Prints the page header (duh)
10 *
31841a9e 11 * @version $Id$
d6c32258 12 * @package squirrelmail
35586184 13 */
14
d6c32258 15/** Include required files from SM */
b68edc75 16require_once(SM_PATH . 'functions/strings.php');
17require_once(SM_PATH . 'functions/html.php');
18require_once(SM_PATH . 'functions/imap_mailbox.php');
0b97a708 19require_once(SM_PATH . 'functions/global.php');
b68edc75 20
d6c32258 21/**
8b096f0a 22 * Output a SquirrelMail page header, from <!doctype> to </head>
23 * Always set up the language before calling these functions.
24 *
25 * @param string title the page title, default SquirrelMail.
26 * @param string xtra extra HTML to insert into the header
27 * @param bool do_hook whether to execute hooks, default true
62b9c984 28 * @param bool frames generate html frameset doctype (since 1.5.1)
8b096f0a 29 * @return void
d6c32258 30 */
62b9c984 31function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = true, $frames = false ) {
e842b215 32 global $squirrelmail_language;
692155b7 33
0365891c 34 if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
0b97a708 35 global $base_uri;
36 }
b6c283c4 37 global $theme_css, $custom_css, $pageheader_sent;
2c21ef20 38
62b9c984 39 if ($frames) {
40 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">';
41 } else {
42 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
43 }
44 echo "\n\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) . "\n<head>\n";
2c21ef20 45
a714cb95 46 if ( !isset( $custom_css ) || $custom_css == 'none' ) {
692155b7 47 if ($theme_css != '') {
d68323ff 48 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\" />";
692155b7 49 }
8f1ba72b 50 } else {
d68323ff 51 echo '<link rel="stylesheet" type="text/css" href="' .
52 $base_uri . 'themes/css/'.$custom_css.'" />';
8f1ba72b 53 }
62f7daa5 54
e842b215 55 if ($squirrelmail_language == 'ja_JP') {
56 echo "<!-- \xfd\xfe -->\n";
04fa3c41 57 echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp" />' . "\n";
e842b215 58 }
62f7daa5 59
237470b4 60 if ($do_hook) {
d68323ff 61 do_hook('generic_header');
237470b4 62 }
62f7daa5 63
5ca4b1ee 64 echo "\n<title>$title</title>$xtra\n";
65
66 /* work around IE6's scrollbar bug */
67 echo <<<ECHO
68<style type="text/css">
69<!--
70 /* avoid stupid IE6 bug with frames and scrollbars */
62f7daa5 71 body {
72 voice-family: "\"}\"";
73 voice-family: inherit;
5ca4b1ee 74 width: expression(document.documentElement.clientWidth - 30);
75 }
76-->
77</style>
78
79ECHO;
80
81 echo "\n</head>\n\n";
b6c283c4 82
83 /* this is used to check elsewhere whether we should call this function */
84 $pageheader_sent = TRUE;
a07cd1a4 85}
86
8b096f0a 87/**
88 * Given a path to a SquirrelMail file, return a HTML link to it
89 *
90 * @param string path the SquirrelMail file to link to
91 * @param string text the link text
92 * @param string target the target frame for this link
93 */
d62c4938 94function makeInternalLink($path, $text, $target='') {
0365891c 95 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
dcc1cc82 96 if ($target != '') {
97 $target = " target=\"$target\"";
98 }
d3714d3a 99 $hooktext = do_hook_function('internal_link',$text);
100 if ($hooktext != '')
101 $text = $hooktext;
d62c4938 102 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
103}
104
8b096f0a 105/**
106 * Same as makeInternalLink, but echoes it too
107 */
d62c4938 108function displayInternalLink($path, $text, $target='') {
b26d81e5 109 echo makeInternalLink($path, $text, $target);
a07cd1a4 110}
111
8b096f0a 112/**
113 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
114 * including the default menu bar. Uses displayHtmlHeader and takes
115 * JavaScript and locale settings into account.
116 *
117 * @param array color the array of theme colors
118 * @param string mailbox the current mailbox name to display
119 * @param string xtra extra html code to add
120 * @param bool session
121 * @return void
122 */
aca403fa 123function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
715225af 124
0b97a708 125 global $hide_sm_attributions, $PHP_SELF, $frame_top,
1ba8cd6b 126 $compose_new_win, $compose_width, $compose_height,
d62c4938 127 $attachemessages, $provider_name, $provider_uri,
95878c5e 128 $javascript_on, $default_use_mdn, $mdn_user_support,
129 $startMessage;
715225af 130
0365891c 131 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION );
132 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
715225af 133 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
f3e14140 134 if ($qmark = strpos($module, '?')) {
135 $module = substr($module, 0, $qmark);
136 }
d03f3582 137 if (!isset($frame_top)) {
138 $frame_top = '_top';
139 }
715225af 140
735f6b9c 141 if ($session) {
1a531551 142 $compose_uri = $base_uri.'src/compose.php?mailbox='.urlencode($mailbox).'&amp;attachedmessages=true&amp;session='."$session";
aca403fa 143 } else {
087ce5f8 144 $compose_uri = $base_uri.'src/compose.php?newmessage=1';
1a531551 145 $session = 0;
aca403fa 146 }
62f7daa5 147
148 if($javascript_on) {
d62c4938 149
150 switch ( $module ) {
151 case 'src/read_body.php':
152 $js ='';
32485e5e 153
154 // compose in new window code
d62c4938 155 if ($compose_new_win == '1') {
156 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
157 $compose_width = '640';
158 }
159 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
160 $compose_height = '550';
161 }
1a531551 162 $js .= "function comp_in_new_form(comp_uri, button, myform) {\n".
163 ' if (!comp_uri) {'."\n".
164 ' comp_uri = "'.$compose_uri."\";\n".
165 ' }'. "\n".
166 ' comp_uri += "&" + button.name + "=1";'."\n".
167 ' for ( var i=0; i < myform.elements.length; i++ ) {'."\n".
168 ' if ( myform.elements[i].type == "checkbox" && myform.elements[i].checked )'."\n".
169 ' comp_uri += "&" + myform.elements[i].name + "=1";'."\n".
170 ' }'."\n".
171 ' var newwin = window.open(comp_uri' .
172 ', "_blank",'.
173 '"width='.$compose_width. ',height='.$compose_height.
75442b66 174 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
1a531551 175 "}\n\n";
e346043e 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.
75442b66 183 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
e346043e 184 "}\n\n";
32485e5e 185 }
d62c4938 186
32485e5e 187 // javascript for sending read receipts
188 if($default_use_mdn && $mdn_user_support) {
d62c4938 189 $js .= 'function sendMDN() {'."\n".
32485e5e 190 " mdnuri=window.location+'&sendreceipt=1'; ".
d62c4938 191 "var newwin = window.open(mdnuri,'right');".
1a531551 192 "\n}\n\n";
32485e5e 193 }
194
195 // if any of the above passes, add the JS tags too.
196 if($js) {
197 $js = "\n".'<script language="JavaScript" type="text/javascript">' .
198 "\n<!--\n" . $js . "// -->\n</script>\n";
199 }
d62c4938 200
32485e5e 201 displayHtmlHeader ('SquirrelMail', $js);
202 $onload = $xtra;
d62c4938 203 break;
204 case 'src/compose.php':
205 $js = '<script language="JavaScript" type="text/javascript">' .
206 "\n<!--\n" .
9f2f6126 207 "function checkForm() {\n";
208
209 global $action, $reply_focus;
210 if (strpos($action, 'reply') !== FALSE && $reply_focus)
211 {
212 if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
213 else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
192cdcf5 214 else if ($reply_focus == 'none') $js .= "}\n";
215 }
216 // no reply focus also applies to composing new messages
217 else if ($reply_focus == 'none')
218 {
219 $js .= "}\n";
9f2f6126 220 }
221 else
222 $js .= "var f = document.forms.length;\n".
d62c4938 223 "var i = 0;\n".
224 "var pos = -1;\n".
225 "while( pos == -1 && i < f ) {\n".
226 "var e = document.forms[i].elements.length;\n".
227 "var j = 0;\n".
228 "while( pos == -1 && j < e ) {\n".
229 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
230 "pos = j;\n".
231 "}\n".
232 "j++;\n".
d7f8e6e6 233 "}\n".
d62c4938 234 "i++;\n".
d7f8e6e6 235 "}\n".
d62c4938 236 "if( pos >= 0 ) {\n".
237 "document.forms[i-1].elements[pos].focus();\n".
238 "}\n".
239 "}\n";
62f7daa5 240
d62c4938 241 $js .= "// -->\n".
1a531551 242 "</script>\n";
d62c4938 243 $onload = 'onload="checkForm();"';
244 displayHtmlHeader ('SquirrelMail', $js);
62f7daa5 245 break;
d62c4938 246
247 default:
248 $js = '<script language="JavaScript" type="text/javascript">' .
249 "\n<!--\n" .
250 "function checkForm() {\n".
251 "var f = document.forms.length;\n".
252 "var i = 0;\n".
253 "var pos = -1;\n".
254 "while( pos == -1 && i < f ) {\n".
255 "var e = document.forms[i].elements.length;\n".
256 "var j = 0;\n".
257 "while( pos == -1 && j < e ) {\n".
258 "if ( document.forms[i].elements[j].type == 'text' " .
259 "|| document.forms[i].elements[j].type == 'password' ) {\n".
260 "pos = j;\n".
261 "}\n".
262 "j++;\n".
353616c4 263 "}\n".
d62c4938 264 "i++;\n".
265 "}\n".
266 "if( pos >= 0 ) {\n".
267 "document.forms[i-1].elements[pos].focus();\n".
353616c4 268 "}\n".
1a531551 269 "$xtra\n".
d62c4938 270 "}\n";
62f7daa5 271
d62c4938 272 if ($compose_new_win == '1') {
273 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
274 $compose_width = '640';
275 }
276 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
277 $compose_height = '550';
278 }
279 $js .= "function comp_in_new(comp_uri) {\n".
75442b66 280 " if (!comp_uri) {\n".
281 ' comp_uri = "'.$compose_uri."\";\n".
282 ' }'. "\n".
d62c4938 283 ' var newwin = window.open(comp_uri' .
284 ', "_blank",'.
285 '"width='.$compose_width. ',height='.$compose_height.
75442b66 286 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
d62c4938 287 "}\n\n";
288
9c3e6cd4 289 }
d62c4938 290 $js .= "// -->\n". "</script>\n";
62f7daa5 291
d62c4938 292 $onload = 'onload="checkForm();"';
293 displayHtmlHeader ('SquirrelMail', $js);
62f7daa5 294 break;
0cba960a 295
d62c4938 296 }
297 } else {
298 /* do not use JavaScript */
299 displayHtmlHeader ('SquirrelMail');
300 $onload = '';
715225af 301 }
302
b01b21d0 303 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
a07cd1a4 304 /** Here is the header and wrapping table **/
72520f77 305 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
306 readShortMailboxName($mailbox, $delimiter)));
3b7d68e6 307 if ( $shortBoxName == 'INBOX' ) {
7da23762 308 $shortBoxName = _("INBOX");
309 }
b01b21d0 310 echo "<a name=\"pagetop\"></a>\n"
311 . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
312 . html_tag( 'tr', '', '', $color[9] ) ."\n"
313 . html_tag( 'td', '', 'left' ) ."\n";
5bb2a991 314 if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
b01b21d0 315 echo ' ' . _("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
5bb2a991 316 } else {
317 echo '&nbsp;';
318 }
b01b21d0 319 echo " </td>\n"
320 . html_tag( 'td', '', 'right' ) ."<b>\n";
80e86e94 321 displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
b01b21d0 322 echo "</b></td>\n"
323 . " </tr>\n"
324 . html_tag( 'tr', '', '', $color[4] ) ."\n"
99ea51d3 325 . ($hide_sm_attributions ? html_tag( 'td', '', 'left', '', 'colspan="2"' )
326 : html_tag( 'td', '', 'left' ) )
327 . "\n";
a07cd1a4 328 $urlMailbox = urlencode($mailbox);
e233a3ad 329 echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&amp;startMessage='.$startMessage);
a07cd1a4 330 echo "&nbsp;&nbsp;\n";
21a957a9 331 displayInternalLink ('src/addressbook.php', _("Addresses"));
a07cd1a4 332 echo "&nbsp;&nbsp;\n";
21a957a9 333 displayInternalLink ('src/folders.php', _("Folders"));
a07cd1a4 334 echo "&nbsp;&nbsp;\n";
21a957a9 335 displayInternalLink ('src/options.php', _("Options"));
a07cd1a4 336 echo "&nbsp;&nbsp;\n";
21a957a9 337 displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"));
a07cd1a4 338 echo "&nbsp;&nbsp;\n";
21a957a9 339 displayInternalLink ('src/help.php', _("Help"));
a07cd1a4 340 echo "&nbsp;&nbsp;\n";
341
d68323ff 342 do_hook('menuline');
a07cd1a4 343
99ea51d3 344 echo " </td>\n";
345
346 if (!$hide_sm_attributions)
347 {
348 echo html_tag( 'td', '', 'right' ) ."\n";
349 if (!isset($provider_uri)) $provider_uri= 'http://www.squirrelmail.org/';
350 if (!isset($provider_name)) $provider_name= 'SquirrelMail';
351 echo '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>';
352 echo "</td>\n";
353 }
354 echo " </tr>\n".
04fa3c41 355 "</table><br />\n\n";
a07cd1a4 356}
2ba13803 357
8b096f0a 358/**
359 * Blatantly copied/truncated/modified from displayPageHeader.
360 * Outputs a page header specifically for the compose_in_new popup window
361 *
362 * @param array color the array of theme colors
363 * @param string mailbox the current mailbox name to display
364 * @return void
365 */
9c3e6cd4 366function compose_Header($color, $mailbox) {
367
d62c4938 368 global $javascript_on;
9c3e6cd4 369
370 /*
d62c4938 371 * Locate the first displayable form element (only when JavaScript on)
372 */
373 if($javascript_on) {
374 global $delimiter, $base_uri, $PHP_SELF, $data_dir, $username;
375
376 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
377
378 switch ( $module ) {
379 case 'src/search.php':
380 $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1;
381 $onload = "onload=\"document.forms[$pos].elements[2].focus();\"";
382 displayHtmlHeader (_("Compose"));
383 break;
384 default:
385 $js = '<script language="JavaScript" type="text/javascript">' .
386 "\n<!--\n" .
9f2f6126 387 "function checkForm() {\n";
388
389 global $action, $reply_focus;
390 if (strpos($action, 'reply') !== FALSE && $reply_focus)
391 {
392 if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
393 else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
192cdcf5 394 else if ($reply_focus == 'none') $js .= "}\n";
395 }
396 // no reply focus also applies to composing new messages
397 else if ($reply_focus == 'none')
398 {
399 $js .= "}\n";
9f2f6126 400 }
401 else
402 $js .= "var f = document.forms.length;\n".
d62c4938 403 "var i = 0;\n".
404 "var pos = -1;\n".
405 "while( pos == -1 && i < f ) {\n".
406 "var e = document.forms[i].elements.length;\n".
407 "var j = 0;\n".
408 "while( pos == -1 && j < e ) {\n".
409 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
410 "pos = j;\n".
411 "}\n".
412 "j++;\n".
9c3e6cd4 413 "}\n".
d62c4938 414 "i++;\n".
9c3e6cd4 415 "}\n".
d62c4938 416 "if( pos >= 0 ) {\n".
417 "document.forms[i-1].elements[pos].focus();\n".
418 "}\n".
419 "}\n";
420 $js .= "// -->\n".
1a531551 421 "</script>\n";
d62c4938 422 $onload = 'onload="checkForm();"';
423 displayHtmlHeader (_("Compose"), $js);
62f7daa5 424 break;
d62c4938 425 }
426 } else {
427 /* javascript off */
428 displayHtmlHeader(_("Compose"));
429 $onload = '';
9c3e6cd4 430 }
431
b01b21d0 432 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
9c3e6cd4 433}
e842b215 434
62f7daa5 435?>