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