d62321fa5fd0a5fb1b8333527cdfa2ff23305460
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" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) .
45 "<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n";
48 * Add closing / to link and meta elements only after switching to xhtml 1.0 Transitional.
49 * It is not compatible with html 4.01 Transitional
51 if ( !isset( $custom_css ) ||
$custom_css == 'none' ) {
52 if ($theme_css != '') {
53 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">";
56 echo '<link rel="stylesheet" type="text/css" href="' .
57 $base_uri . 'themes/css/'.$custom_css.'">';
60 if ($squirrelmail_language == 'ja_JP') {
62 * force correct detection of charset, when browser does not follow
63 * http content-type and tries to detect charset from page content.
64 * Shooting of browser's creator can't be implemented in php.
65 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
66 * recommendations and switch to unicode.
68 echo "<!-- \xfd\xfe -->\n";
69 echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
73 do_hook('generic_header');
76 echo "<title>$title</title>\n$xtra\n";
78 /* work around IE6's scrollbar bug */
80 <style type="text/css">
82 /* avoid stupid IE6 bug with frames and scrollbars */
84 voice-family: "\"}\"";
85 voice-family: inherit;
86 width: expression(document.documentElement.clientWidth - 30);
95 /* this is used to check elsewhere whether we should call this function */
96 $pageheader_sent = TRUE;
100 * Given a path to a SquirrelMail file, return a HTML link to it
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
106 function makeInternalLink($path, $text, $target='') {
107 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
109 $target = " target=\"$target\"";
112 // This is an inefficient hook and is only used by
113 // one plugin that still needs to patch this code,
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?)
117 // use for the internal_link hook.
119 //$hooktext = do_hook_function('internal_link',$text);
120 //if ($hooktext != '')
121 // $text = $hooktext;
123 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
127 * Same as makeInternalLink, but echoes it too
129 function displayInternalLink($path, $text, $target='') {
130 echo makeInternalLink($path, $text, $target);
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.
138 * @param array color the array of theme colors
139 * @param string mailbox the current mailbox name to display
140 * @param string xtra extra html code to add
141 * @param bool session
144 function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
146 global $hide_sm_attributions, $PHP_SELF, $frame_top,
147 $compose_new_win, $compose_width, $compose_height,
148 $provider_name, $provider_uri, $startMessage,
149 $javascript_on, $default_use_mdn, $mdn_user_support;
151 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
152 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
153 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
154 if ($qmark = strpos($module, '?')) {
155 $module = substr($module, 0, $qmark);
157 if (!isset($frame_top)) {
162 $compose_uri = $base_uri.'src/compose.php?mailbox='.urlencode($mailbox).'&attachedmessages=true&session='."$session";
164 $compose_uri = $base_uri.'src/compose.php?newmessage=1';
168 if( $javascript_on ||
strpos($xtra, 'new_js_autodetect_results.value') ) {
171 case 'src/read_body.php':
174 // compose in new window code
175 if ($compose_new_win == '1') {
176 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
177 $compose_width = '640';
179 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
180 $compose_height = '550';
182 $js .= "function comp_in_new_form(comp_uri, button, myform) {\n".
183 ' if (!comp_uri) {'."\n".
184 ' comp_uri = "'.$compose_uri."\";\n".
186 ' comp_uri += "&" + button.name + "=1";'."\n".
187 ' for ( var i=0; i < myform.elements.length; i++ ) {'."\n".
188 ' if ( myform.elements[i].type == "checkbox" && myform.elements[i].checked )'."\n".
189 ' comp_uri += "&" + myform.elements[i].name + "=1";'."\n".
191 ' var newwin = window.open(comp_uri' .
193 '"width='.$compose_width. ',height='.$compose_height.
194 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
196 $js .= "function comp_in_new(comp_uri) {\n".
197 " if (!comp_uri) {\n".
198 ' comp_uri = "'.$compose_uri."\";\n".
200 ' var newwin = window.open(comp_uri' .
202 '"width='.$compose_width. ',height='.$compose_height.
203 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
207 // javascript for sending read receipts
208 if($default_use_mdn && $mdn_user_support) {
209 $js .= 'function sendMDN() {'."\n".
210 " mdnuri=window.location+'&sendreceipt=1'; ".
211 "var newwin = window.open(mdnuri,'right');".
215 // if any of the above passes, add the JS tags too.
217 $js = "\n".'<script language="JavaScript" type="text/javascript">' .
218 "\n<!--\n" . $js . "// -->\n</script>\n";
221 displayHtmlHeader ('SquirrelMail', $js);
224 case 'src/compose.php':
225 $js = '<script language="JavaScript" type="text/javascript">' .
227 "function checkForm() {\n";
229 global $action, $reply_focus;
230 if (strpos($action, 'reply') !== FALSE && $reply_focus)
232 if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
233 else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
234 else if ($reply_focus == 'none') $js .= "}\n";
236 // no reply focus also applies to composing new messages
237 else if ($reply_focus == 'none')
242 $js .= "var f = document.forms.length;\n".
245 "while( pos == -1 && i < f ) {\n".
246 "var e = document.forms[i].elements.length;\n".
248 "while( pos == -1 && j < e ) {\n".
249 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
256 "if( pos >= 0 ) {\n".
257 "document.forms[i-1].elements[pos].focus();\n".
263 $onload = 'onload="checkForm();"';
264 displayHtmlHeader ('SquirrelMail', $js);
267 case 'src/right_main.php':
268 global $fancy_index_highlite;
269 if (!$fancy_index_highlite) {
271 } else //{ putting braces around this block creats strange PHP errors
272 // following code graciously borrowed from
273 // phpMyAdmin project at:
274 // http://www.phpmyadmin.net
277 * This array is used to remember mark status of rows in browse mode
279 var marked_row = new Array;
283 * (un)Checks checkbox for the row that the current table cell is in
284 * when it gets clicked.
286 * @param string the name of the checkbox that should be (un)checked
288 function row_click(chkboxName) {
289 chkbox = document.getElementById(chkboxName);
291 chkbox.checked = (chkbox.checked ? false : true);
298 * Sets/unsets the pointer and marker in browse mode
300 * @param object the table row
301 * @param integer the row number
302 * @param string the action calling this script (over, out or click)
303 * @param string the default background color
304 * @param string the color to use for mouseover
305 * @param string the color to use for marking a row
307 * @return boolean whether pointer is set or not
309 function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
313 // 1. Pointer and mark feature are disabled or the browser can't get the
315 if ((thePointerColor == '' && theMarkColor == '')
316 || typeof(theRow.style) == 'undefined') {
320 // 2. Gets the current row and exits if the browser can't get it
321 if (typeof(document.getElementsByTagName) != 'undefined') {
322 theCells = theRow.getElementsByTagName('td');
324 else if (typeof(theRow.cells) != 'undefined') {
325 theCells = theRow.cells;
331 // 3. Gets the current color...
332 var rowCellsCnt = theCells.length;
333 var domDetect = null;
334 var currentColor = null;
336 // 3.1 ... with DOM compatible browsers except Opera that does not return
337 // valid values with "getAttribute"
338 if (typeof(window.opera) == 'undefined'
339 && typeof(theCells[0].getAttribute) != 'undefined') {
340 currentColor = theCells[0].getAttribute('bgcolor');
343 // 3.2 ... with other browsers
345 currentColor = theCells[0].style.backgroundColor;
349 // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
350 if (currentColor.indexOf("rgb") >= 0)
352 var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
353 currentColor.indexOf(')'));
354 var rgbValues = rgbStr.split(",");
356 var hexChars = "0123456789ABCDEF";
357 for (var i = 0; i < 3; i++)
359 var v = rgbValues[i].valueOf();
360 currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
364 // 4. Defines the new color
365 // 4.1 Current color is the default one
366 if (currentColor == ''
367 || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
368 if (theAction == 'over' && thePointerColor != '') {
369 newColor = thePointerColor;
371 else if (theAction == 'click' && theMarkColor != '') {
372 newColor = theMarkColor;
373 marked_row[theRowNum] = true;
374 // deactivated onclick marking of the checkbox because it's also executed
375 // when an action (clicking on the checkbox itself) on a single item is
376 // performed. Then the checkbox would get deactived, even though we need
377 // it activated. Maybe there is a way to detect if the row was clicked,
378 // and not an item therein...
379 //document.getElementById('msg[' + theRowNum + ']').checked = true;
382 // 4.1.2 Current color is the pointer one
383 else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
384 && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
385 if (theAction == 'out') {
386 newColor = theDefaultColor;
388 else if (theAction == 'click' && theMarkColor != '') {
389 newColor = theMarkColor;
390 marked_row[theRowNum] = true;
391 //document.getElementById('msg[' + theRowNum + ']').checked = true;
394 // 4.1.3 Current color is the marker one
395 else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
396 if (theAction == 'click') {
397 newColor = (thePointerColor != '')
400 marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
403 //document.getElementById('msg[' + theRowNum + ']').checked = false;
407 // 5. Sets the new color...
410 // 5.1 ... with DOM compatible browsers except Opera
412 for (c = 0; c < rowCellsCnt; c++) {
413 theCells[c].setAttribute('bgcolor', newColor, 0);
416 // 5.2 ... with other browsers
418 for (c = 0; c < rowCellsCnt; c++) {
419 theCells[c].style.backgroundColor = newColor;
425 } // end of the 'setPointer()' function
427 //} putting braces around this block creats strange PHP errors
428 $js = "\n".'<script language="JavaScript" type="text/javascript">' .
430 if ($compose_new_win == '1') {
431 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
432 $compose_width = '640';
434 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
435 $compose_height = '550';
437 $js .= "\n\nfunction comp_in_new(comp_uri) {\n".
438 " if (!comp_uri) {\n".
439 ' comp_uri = "'.$compose_uri."\";\n".
441 ' var newwin = window.open(comp_uri' .
443 '"width='.$compose_width. ',height='.$compose_height.
444 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
447 $js .= $xtra . "\n\n// -->\n</script>\n";
449 displayHtmlHeader ('SquirrelMail', $js);
453 $js = '<script language="JavaScript" type="text/javascript">' .
455 "function checkForm() {\n".
456 "var f = document.forms.length;\n".
459 "while( pos == -1 && i < f ) {\n".
460 "var e = document.forms[i].elements.length;\n".
462 "while( pos == -1 && j < e ) {\n".
463 "if ( document.forms[i].elements[j].type == 'text' " .
464 "|| document.forms[i].elements[j].type == 'password' ) {\n".
471 "if( pos >= 0 ) {\n".
472 "document.forms[i-1].elements[pos].focus();\n".
477 if ($compose_new_win == '1') {
478 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
479 $compose_width = '640';
481 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
482 $compose_height = '550';
484 $js .= "function comp_in_new(comp_uri) {\n".
485 " if (!comp_uri) {\n".
486 ' comp_uri = "'.$compose_uri."\";\n".
488 ' var newwin = window.open(comp_uri' .
490 '"width='.$compose_width. ',height='.$compose_height.
491 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
495 $js .= "// -->\n". "</script>\n";
497 $onload = 'onload="checkForm();"';
498 displayHtmlHeader ('SquirrelMail', $js);
503 /* do not use JavaScript */
504 displayHtmlHeader ('SquirrelMail');
508 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
509 /** Here is the header and wrapping table **/
510 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
511 readShortMailboxName($mailbox, $delimiter)));
512 if ( $shortBoxName == 'INBOX' ) {
513 $shortBoxName = _("INBOX");
515 echo "<a name=\"pagetop\"></a>\n"
516 . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
517 . html_tag( 'tr', '', '', $color[9] ) ."\n"
518 . html_tag( 'td', '', 'left' ) ."\n";
519 if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
520 echo ' ' . _("Current Folder") . ": <b>$shortBoxName </b>\n";
525 . html_tag( 'td', '', 'right' ) ."<b>\n";
526 displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
529 . html_tag( 'tr', '', '', $color[4] ) ."\n"
530 . ($hide_sm_attributions ?
html_tag( 'td', '', 'left', '', 'colspan="2"' )
531 : html_tag( 'td', '', 'left' ) )
533 $urlMailbox = urlencode($mailbox);
534 echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&startMessage='.$startMessage);
535 echo " \n";
536 displayInternalLink ('src/addressbook.php', _("Addresses"));
537 echo " \n";
538 displayInternalLink ('src/folders.php', _("Folders"));
539 echo " \n";
540 displayInternalLink ('src/options.php', _("Options"));
541 echo " \n";
542 displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"));
543 echo " \n";
544 displayInternalLink ('src/help.php', _("Help"));
545 echo " \n";
551 if (!$hide_sm_attributions)
553 echo html_tag( 'td', '', 'right' ) ."\n";
554 if (empty($provider_uri)) {
555 echo '<a href="about.php">SquirrelMail</a>';
557 if (empty($provider_name)) $provider_name= 'SquirrelMail';
558 echo '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>';
563 "</table><br />\n\n";
567 * Blatantly copied/truncated/modified from displayPageHeader.
568 * Outputs a page header specifically for the compose_in_new popup window
570 * @param array color the array of theme colors
571 * @param string mailbox the current mailbox name to display
574 function compose_Header($color, $mailbox) {
576 global $javascript_on;
579 * Locate the first displayable form element (only when JavaScript on)
582 global $base_uri, $PHP_SELF, $data_dir, $username;
584 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
587 case 'src/search.php':
588 $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1;
589 $onload = "onload=\"document.forms[$pos].elements[2].focus();\"";
590 displayHtmlHeader (_("Compose"));
593 $js = '<script language="JavaScript" type="text/javascript">' .
595 "function checkForm() {\n";
597 global $action, $reply_focus;
598 if (strpos($action, 'reply') !== FALSE && $reply_focus)
600 if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
601 else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
602 else if ($reply_focus == 'none') $js .= "}\n";
604 // no reply focus also applies to composing new messages
605 else if ($reply_focus == 'none')
610 $js .= "var f = document.forms.length;\n".
613 "while( pos == -1 && i < f ) {\n".
614 "var e = document.forms[i].elements.length;\n".
616 "while( pos == -1 && j < e ) {\n".
617 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
624 "if( pos >= 0 ) {\n".
625 "document.forms[i-1].elements[pos].focus();\n".
630 $onload = 'onload="checkForm();"';
631 displayHtmlHeader (_("Compose"), $js);
636 displayHtmlHeader(_("Compose"));
640 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";