6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * Prints the page header (duh)
12 * @package squirrelmail
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');
22 * Output a SquirrelMail page header, from <!doctype> to </head>
23 * Always set up the language before calling these functions.
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)
31 function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = true, $frames = false ) {
32 global $squirrelmail_language;
34 if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
) ) {
37 global $theme_css, $custom_css, $pageheader_sent;
40 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">';
42 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
44 echo "\n\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) . "\n<head>\n";
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
50 if ( !isset( $custom_css ) ||
$custom_css == 'none' ) {
51 if ($theme_css != '') {
52 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">";
55 echo '<link rel="stylesheet" type="text/css" href="' .
56 $base_uri . 'themes/css/'.$custom_css.'">';
59 if ($squirrelmail_language == 'ja_JP') {
61 * force correct detection of charset, when browser does not follow
62 * http content-type and tries to detect charset from page content.
63 * Shooting of browser's creator can't be implemented in php.
64 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
65 * recommendations and switch to unicode.
67 echo "<!-- \xfd\xfe -->\n";
68 echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
72 do_hook('generic_header');
75 echo "\n<title>$title</title>$xtra\n";
77 /* work around IE6's scrollbar bug */
79 <style type="text/css">
81 /* avoid stupid IE6 bug with frames and scrollbars */
83 voice-family: "\"}\"";
84 voice-family: inherit;
85 width: expression(document.documentElement.clientWidth - 30);
94 /* this is used to check elsewhere whether we should call this function */
95 $pageheader_sent = TRUE;
99 * Given a path to a SquirrelMail file, return a HTML link to it
101 * @param string path the SquirrelMail file to link to
102 * @param string text the link text
103 * @param string target the target frame for this link
105 function makeInternalLink($path, $text, $target='') {
106 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
108 $target = " target=\"$target\"";
111 // This is an inefficient hook and is only used by
112 // one plugin that still needs to patch this code,
113 // plus if we are templat-izing SM, visual hooks
114 // are not needed. However, I am leaving the code
115 // here just in case we find a good (non-visual?)
116 // use for the internal_link hook.
118 //$hooktext = do_hook_function('internal_link',$text);
119 //if ($hooktext != '')
120 // $text = $hooktext;
122 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
126 * Same as makeInternalLink, but echoes it too
128 function displayInternalLink($path, $text, $target='') {
129 echo makeInternalLink($path, $text, $target);
133 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
134 * including the default menu bar. Uses displayHtmlHeader and takes
135 * JavaScript and locale settings into account.
137 * @param array color the array of theme colors
138 * @param string mailbox the current mailbox name to display
139 * @param string xtra extra html code to add
140 * @param bool session
143 function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
145 global $hide_sm_attributions, $PHP_SELF, $frame_top,
146 $compose_new_win, $compose_width, $compose_height,
147 $provider_name, $provider_uri, $startMessage,
148 $javascript_on, $default_use_mdn, $mdn_user_support;
150 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
151 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
152 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
153 if ($qmark = strpos($module, '?')) {
154 $module = substr($module, 0, $qmark);
156 if (!isset($frame_top)) {
161 $compose_uri = $base_uri.'src/compose.php?mailbox='.urlencode($mailbox).'&attachedmessages=true&session='."$session";
163 $compose_uri = $base_uri.'src/compose.php?newmessage=1';
167 if( $javascript_on ||
strpos($xtra, 'new_js_autodetect_results.value') ) {
170 case 'src/read_body.php':
173 // compose in new window code
174 if ($compose_new_win == '1') {
175 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
176 $compose_width = '640';
178 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
179 $compose_height = '550';
181 $js .= "function comp_in_new_form(comp_uri, button, myform) {\n".
182 ' if (!comp_uri) {'."\n".
183 ' comp_uri = "'.$compose_uri."\";\n".
185 ' comp_uri += "&" + button.name + "=1";'."\n".
186 ' for ( var i=0; i < myform.elements.length; i++ ) {'."\n".
187 ' if ( myform.elements[i].type == "checkbox" && myform.elements[i].checked )'."\n".
188 ' comp_uri += "&" + myform.elements[i].name + "=1";'."\n".
190 ' var newwin = window.open(comp_uri' .
192 '"width='.$compose_width. ',height='.$compose_height.
193 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
195 $js .= "function comp_in_new(comp_uri) {\n".
196 " if (!comp_uri) {\n".
197 ' comp_uri = "'.$compose_uri."\";\n".
199 ' var newwin = window.open(comp_uri' .
201 '"width='.$compose_width. ',height='.$compose_height.
202 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
206 // javascript for sending read receipts
207 if($default_use_mdn && $mdn_user_support) {
208 $js .= 'function sendMDN() {'."\n".
209 " mdnuri=window.location+'&sendreceipt=1'; ".
210 "var newwin = window.open(mdnuri,'right');".
214 // if any of the above passes, add the JS tags too.
216 $js = "\n".'<script language="JavaScript" type="text/javascript">' .
217 "\n<!--\n" . $js . "// -->\n</script>\n";
220 displayHtmlHeader ('SquirrelMail', $js);
223 case 'src/compose.php':
224 $js = '<script language="JavaScript" type="text/javascript">' .
226 "function checkForm() {\n";
228 global $action, $reply_focus;
229 if (strpos($action, 'reply') !== FALSE && $reply_focus)
231 if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
232 else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
233 else if ($reply_focus == 'none') $js .= "}\n";
235 // no reply focus also applies to composing new messages
236 else if ($reply_focus == 'none')
241 $js .= "var f = document.forms.length;\n".
244 "while( pos == -1 && i < f ) {\n".
245 "var e = document.forms[i].elements.length;\n".
247 "while( pos == -1 && j < e ) {\n".
248 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
255 "if( pos >= 0 ) {\n".
256 "document.forms[i-1].elements[pos].focus();\n".
262 $onload = 'onload="checkForm();"';
263 displayHtmlHeader ('SquirrelMail', $js);
266 case 'src/right_main.php':
267 // following code graciously stolen from phpMyAdmin project at:
268 // http://www.phpmyadmin.net
271 * This array is used to remember mark status of rows in browse mode
273 var marked_row = new Array;
277 * Sets/unsets the pointer and marker in browse mode
279 * @param object the table row
280 * @param integer the row number
281 * @param string the action calling this script (over, out or click)
282 * @param string the default background color
283 * @param string the color to use for mouseover
284 * @param string the color to use for marking a row
286 * @return boolean whether pointer is set or not
288 function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
292 // 1. Pointer and mark feature are disabled or the browser can't get the
294 if ((thePointerColor == '' && theMarkColor == '')
295 || typeof(theRow.style) == 'undefined') {
299 // 2. Gets the current row and exits if the browser can't get it
300 if (typeof(document.getElementsByTagName) != 'undefined') {
301 theCells = theRow.getElementsByTagName('td');
303 else if (typeof(theRow.cells) != 'undefined') {
304 theCells = theRow.cells;
310 // 3. Gets the current color...
311 var rowCellsCnt = theCells.length;
312 var domDetect = null;
313 var currentColor = null;
315 // 3.1 ... with DOM compatible browsers except Opera that does not return
316 // valid values with "getAttribute"
317 if (typeof(window.opera) == 'undefined'
318 && typeof(theCells[0].getAttribute) != 'undefined') {
319 currentColor = theCells[0].getAttribute('bgcolor');
322 // 3.2 ... with other browsers
324 currentColor = theCells[0].style.backgroundColor;
328 // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
329 if (currentColor.indexOf("rgb") >= 0)
331 var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
332 currentColor.indexOf(')'));
333 var rgbValues = rgbStr.split(",");
335 var hexChars = "0123456789ABCDEF";
336 for (var i = 0; i < 3; i++)
338 var v = rgbValues[i].valueOf();
339 currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
343 // 4. Defines the new color
344 // 4.1 Current color is the default one
345 if (currentColor == ''
346 || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
347 if (theAction == 'over' && thePointerColor != '') {
348 newColor = thePointerColor;
350 else if (theAction == 'click' && theMarkColor != '') {
351 newColor = theMarkColor;
352 marked_row[theRowNum] = true;
353 // deactivated onclick marking of the checkbox because it's also executed
354 // when an action (clicking on the checkbox itself) on a single item is
355 // performed. Then the checkbox would get deactived, even though we need
356 // it activated. Maybe there is a way to detect if the row was clicked,
357 // and not an item therein...
358 //document.getElementById('msg[' + theRowNum + ']').checked = true;
361 // 4.1.2 Current color is the pointer one
362 else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
363 && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
364 if (theAction == 'out') {
365 newColor = theDefaultColor;
367 else if (theAction == 'click' && theMarkColor != '') {
368 newColor = theMarkColor;
369 marked_row[theRowNum] = true;
370 //document.getElementById('msg[' + theRowNum + ']').checked = true;
373 // 4.1.3 Current color is the marker one
374 else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
375 if (theAction == 'click') {
376 newColor = (thePointerColor != '')
379 marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
382 //document.getElementById('msg[' + theRowNum + ']').checked = false;
386 // 5. Sets the new color...
389 // 5.1 ... with DOM compatible browsers except Opera
391 for (c = 0; c < rowCellsCnt; c++) {
392 theCells[c].setAttribute('bgcolor', newColor, 0);
395 // 5.2 ... with other browsers
397 for (c = 0; c < rowCellsCnt; c++) {
398 theCells[c].style.backgroundColor = newColor;
404 } // end of the 'setPointer()' function
406 $js = "\n".'<script language="JavaScript" type="text/javascript">' .
407 "\n<!--\n" . $js . "// -->\n</script>\n";
409 displayHtmlHeader ('SquirrelMail', $js);
413 $js = '<script language="JavaScript" type="text/javascript">' .
415 "function checkForm() {\n".
416 "var f = document.forms.length;\n".
419 "while( pos == -1 && i < f ) {\n".
420 "var e = document.forms[i].elements.length;\n".
422 "while( pos == -1 && j < e ) {\n".
423 "if ( document.forms[i].elements[j].type == 'text' " .
424 "|| document.forms[i].elements[j].type == 'password' ) {\n".
431 "if( pos >= 0 ) {\n".
432 "document.forms[i-1].elements[pos].focus();\n".
437 if ($compose_new_win == '1') {
438 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
439 $compose_width = '640';
441 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
442 $compose_height = '550';
444 $js .= "function comp_in_new(comp_uri) {\n".
445 " if (!comp_uri) {\n".
446 ' comp_uri = "'.$compose_uri."\";\n".
448 ' var newwin = window.open(comp_uri' .
450 '"width='.$compose_width. ',height='.$compose_height.
451 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
455 $js .= "// -->\n". "</script>\n";
457 $onload = 'onload="checkForm();"';
458 displayHtmlHeader ('SquirrelMail', $js);
463 /* do not use JavaScript */
464 displayHtmlHeader ('SquirrelMail');
468 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
469 /** Here is the header and wrapping table **/
470 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
471 readShortMailboxName($mailbox, $delimiter)));
472 if ( $shortBoxName == 'INBOX' ) {
473 $shortBoxName = _("INBOX");
475 echo "<a name=\"pagetop\"></a>\n"
476 . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
477 . html_tag( 'tr', '', '', $color[9] ) ."\n"
478 . html_tag( 'td', '', 'left' ) ."\n";
479 if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
480 echo ' ' . _("Current Folder") . ": <b>$shortBoxName </b>\n";
485 . html_tag( 'td', '', 'right' ) ."<b>\n";
486 displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
489 . html_tag( 'tr', '', '', $color[4] ) ."\n"
490 . ($hide_sm_attributions ?
html_tag( 'td', '', 'left', '', 'colspan="2"' )
491 : html_tag( 'td', '', 'left' ) )
493 $urlMailbox = urlencode($mailbox);
494 echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&startMessage='.$startMessage);
495 echo " \n";
496 displayInternalLink ('src/addressbook.php', _("Addresses"));
497 echo " \n";
498 displayInternalLink ('src/folders.php', _("Folders"));
499 echo " \n";
500 displayInternalLink ('src/options.php', _("Options"));
501 echo " \n";
502 displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"));
503 echo " \n";
504 displayInternalLink ('src/help.php', _("Help"));
505 echo " \n";
511 if (!$hide_sm_attributions)
513 echo html_tag( 'td', '', 'right' ) ."\n";
514 if (!isset($provider_uri)) $provider_uri= 'http://www.squirrelmail.org/';
515 if (!isset($provider_name)) $provider_name= 'SquirrelMail';
516 echo '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>';
520 "</table><br />\n\n";
524 * Blatantly copied/truncated/modified from displayPageHeader.
525 * Outputs a page header specifically for the compose_in_new popup window
527 * @param array color the array of theme colors
528 * @param string mailbox the current mailbox name to display
531 function compose_Header($color, $mailbox) {
533 global $javascript_on;
536 * Locate the first displayable form element (only when JavaScript on)
539 global $base_uri, $PHP_SELF, $data_dir, $username;
541 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
544 case 'src/search.php':
545 $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1;
546 $onload = "onload=\"document.forms[$pos].elements[2].focus();\"";
547 displayHtmlHeader (_("Compose"));
550 $js = '<script language="JavaScript" type="text/javascript">' .
552 "function checkForm() {\n";
554 global $action, $reply_focus;
555 if (strpos($action, 'reply') !== FALSE && $reply_focus)
557 if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
558 else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
559 else if ($reply_focus == 'none') $js .= "}\n";
561 // no reply focus also applies to composing new messages
562 else if ($reply_focus == 'none')
567 $js .= "var f = document.forms.length;\n".
570 "while( pos == -1 && i < f ) {\n".
571 "var e = document.forms[i].elements.length;\n".
573 "while( pos == -1 && j < e ) {\n".
574 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
581 "if( pos >= 0 ) {\n".
582 "document.forms[i-1].elements[pos].focus();\n".
587 $onload = 'onload="checkForm();"';
588 displayHtmlHeader (_("Compose"), $js);
593 displayHtmlHeader(_("Compose"));
597 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";