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