use default http port for intertran in order to be able to used it through
[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">';
91e0dccc 41 } else {
62b9c984 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 }
4910106a 99
100 // This is an inefficient hook and is only used by
101 // one plugin that still needs to patch this code,
102 // plus if we are templat-izing SM, visual hooks
103 // are not needed. However, I am leaving the code
104 // here just in case we find a good (non-visual?)
105 // use for the internal_link hook.
106 //
107 //$hooktext = do_hook_function('internal_link',$text);
108 //if ($hooktext != '')
109 // $text = $hooktext;
110
d62c4938 111 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
112}
113
8b096f0a 114/**
115 * Same as makeInternalLink, but echoes it too
116 */
d62c4938 117function displayInternalLink($path, $text, $target='') {
b26d81e5 118 echo makeInternalLink($path, $text, $target);
a07cd1a4 119}
120
8b096f0a 121/**
122 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
123 * including the default menu bar. Uses displayHtmlHeader and takes
124 * JavaScript and locale settings into account.
125 *
126 * @param array color the array of theme colors
127 * @param string mailbox the current mailbox name to display
128 * @param string xtra extra html code to add
129 * @param bool session
130 * @return void
131 */
aca403fa 132function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
715225af 133
0b97a708 134 global $hide_sm_attributions, $PHP_SELF, $frame_top,
1ba8cd6b 135 $compose_new_win, $compose_width, $compose_height,
ce68b76b 136 $provider_name, $provider_uri, $startMessage,
137 $javascript_on, $default_use_mdn, $mdn_user_support;
715225af 138
0365891c 139 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION );
140 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
715225af 141 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
f3e14140 142 if ($qmark = strpos($module, '?')) {
143 $module = substr($module, 0, $qmark);
144 }
d03f3582 145 if (!isset($frame_top)) {
146 $frame_top = '_top';
147 }
715225af 148
735f6b9c 149 if ($session) {
1a531551 150 $compose_uri = $base_uri.'src/compose.php?mailbox='.urlencode($mailbox).'&amp;attachedmessages=true&amp;session='."$session";
aca403fa 151 } else {
087ce5f8 152 $compose_uri = $base_uri.'src/compose.php?newmessage=1';
1a531551 153 $session = 0;
aca403fa 154 }
62f7daa5 155
156 if($javascript_on) {
d62c4938 157
158 switch ( $module ) {
159 case 'src/read_body.php':
160 $js ='';
32485e5e 161
162 // compose in new window code
d62c4938 163 if ($compose_new_win == '1') {
164 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
165 $compose_width = '640';
166 }
167 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
168 $compose_height = '550';
169 }
1a531551 170 $js .= "function comp_in_new_form(comp_uri, button, myform) {\n".
171 ' if (!comp_uri) {'."\n".
172 ' comp_uri = "'.$compose_uri."\";\n".
173 ' }'. "\n".
174 ' comp_uri += "&" + button.name + "=1";'."\n".
175 ' for ( var i=0; i < myform.elements.length; i++ ) {'."\n".
176 ' if ( myform.elements[i].type == "checkbox" && myform.elements[i].checked )'."\n".
177 ' comp_uri += "&" + myform.elements[i].name + "=1";'."\n".
178 ' }'."\n".
179 ' var newwin = window.open(comp_uri' .
180 ', "_blank",'.
181 '"width='.$compose_width. ',height='.$compose_height.
75442b66 182 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
1a531551 183 "}\n\n";
e346043e 184 $js .= "function comp_in_new(comp_uri) {\n".
185 " if (!comp_uri) {\n".
186 ' comp_uri = "'.$compose_uri."\";\n".
187 ' }'. "\n".
188 ' var newwin = window.open(comp_uri' .
189 ', "_blank",'.
190 '"width='.$compose_width. ',height='.$compose_height.
75442b66 191 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
e346043e 192 "}\n\n";
32485e5e 193 }
d62c4938 194
32485e5e 195 // javascript for sending read receipts
196 if($default_use_mdn && $mdn_user_support) {
d62c4938 197 $js .= 'function sendMDN() {'."\n".
32485e5e 198 " mdnuri=window.location+'&sendreceipt=1'; ".
d62c4938 199 "var newwin = window.open(mdnuri,'right');".
1a531551 200 "\n}\n\n";
32485e5e 201 }
202
203 // if any of the above passes, add the JS tags too.
204 if($js) {
205 $js = "\n".'<script language="JavaScript" type="text/javascript">' .
206 "\n<!--\n" . $js . "// -->\n</script>\n";
207 }
d62c4938 208
32485e5e 209 displayHtmlHeader ('SquirrelMail', $js);
210 $onload = $xtra;
d62c4938 211 break;
212 case 'src/compose.php':
213 $js = '<script language="JavaScript" type="text/javascript">' .
214 "\n<!--\n" .
9f2f6126 215 "function checkForm() {\n";
216
217 global $action, $reply_focus;
218 if (strpos($action, 'reply') !== FALSE && $reply_focus)
219 {
220 if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
221 else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
192cdcf5 222 else if ($reply_focus == 'none') $js .= "}\n";
223 }
224 // no reply focus also applies to composing new messages
225 else if ($reply_focus == 'none')
226 {
227 $js .= "}\n";
9f2f6126 228 }
229 else
230 $js .= "var f = document.forms.length;\n".
d62c4938 231 "var i = 0;\n".
232 "var pos = -1;\n".
233 "while( pos == -1 && i < f ) {\n".
234 "var e = document.forms[i].elements.length;\n".
235 "var j = 0;\n".
236 "while( pos == -1 && j < e ) {\n".
237 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
238 "pos = j;\n".
239 "}\n".
240 "j++;\n".
d7f8e6e6 241 "}\n".
d62c4938 242 "i++;\n".
d7f8e6e6 243 "}\n".
d62c4938 244 "if( pos >= 0 ) {\n".
245 "document.forms[i-1].elements[pos].focus();\n".
246 "}\n".
247 "}\n";
62f7daa5 248
d62c4938 249 $js .= "// -->\n".
1a531551 250 "</script>\n";
d62c4938 251 $onload = 'onload="checkForm();"';
252 displayHtmlHeader ('SquirrelMail', $js);
62f7daa5 253 break;
d62c4938 254
255 default:
256 $js = '<script language="JavaScript" type="text/javascript">' .
257 "\n<!--\n" .
258 "function checkForm() {\n".
259 "var f = document.forms.length;\n".
260 "var i = 0;\n".
261 "var pos = -1;\n".
262 "while( pos == -1 && i < f ) {\n".
263 "var e = document.forms[i].elements.length;\n".
264 "var j = 0;\n".
265 "while( pos == -1 && j < e ) {\n".
266 "if ( document.forms[i].elements[j].type == 'text' " .
267 "|| document.forms[i].elements[j].type == 'password' ) {\n".
268 "pos = j;\n".
269 "}\n".
270 "j++;\n".
353616c4 271 "}\n".
d62c4938 272 "i++;\n".
273 "}\n".
274 "if( pos >= 0 ) {\n".
275 "document.forms[i-1].elements[pos].focus();\n".
353616c4 276 "}\n".
1a531551 277 "$xtra\n".
d62c4938 278 "}\n";
62f7daa5 279
d62c4938 280 if ($compose_new_win == '1') {
281 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
282 $compose_width = '640';
283 }
284 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
285 $compose_height = '550';
286 }
287 $js .= "function comp_in_new(comp_uri) {\n".
75442b66 288 " if (!comp_uri) {\n".
289 ' comp_uri = "'.$compose_uri."\";\n".
290 ' }'. "\n".
d62c4938 291 ' var newwin = window.open(comp_uri' .
292 ', "_blank",'.
293 '"width='.$compose_width. ',height='.$compose_height.
75442b66 294 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
d62c4938 295 "}\n\n";
296
9c3e6cd4 297 }
d62c4938 298 $js .= "// -->\n". "</script>\n";
62f7daa5 299
d62c4938 300 $onload = 'onload="checkForm();"';
301 displayHtmlHeader ('SquirrelMail', $js);
62f7daa5 302 break;
0cba960a 303
d62c4938 304 }
305 } else {
306 /* do not use JavaScript */
307 displayHtmlHeader ('SquirrelMail');
308 $onload = '';
715225af 309 }
310
b01b21d0 311 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
a07cd1a4 312 /** Here is the header and wrapping table **/
72520f77 313 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
91e0dccc 314 readShortMailboxName($mailbox, $delimiter)));
3b7d68e6 315 if ( $shortBoxName == 'INBOX' ) {
7da23762 316 $shortBoxName = _("INBOX");
317 }
b01b21d0 318 echo "<a name=\"pagetop\"></a>\n"
319 . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
320 . html_tag( 'tr', '', '', $color[9] ) ."\n"
321 . html_tag( 'td', '', 'left' ) ."\n";
5bb2a991 322 if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
b01b21d0 323 echo ' ' . _("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
5bb2a991 324 } else {
325 echo '&nbsp;';
326 }
b01b21d0 327 echo " </td>\n"
328 . html_tag( 'td', '', 'right' ) ."<b>\n";
80e86e94 329 displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
b01b21d0 330 echo "</b></td>\n"
331 . " </tr>\n"
332 . html_tag( 'tr', '', '', $color[4] ) ."\n"
99ea51d3 333 . ($hide_sm_attributions ? html_tag( 'td', '', 'left', '', 'colspan="2"' )
334 : html_tag( 'td', '', 'left' ) )
335 . "\n";
a07cd1a4 336 $urlMailbox = urlencode($mailbox);
e233a3ad 337 echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&amp;startMessage='.$startMessage);
a07cd1a4 338 echo "&nbsp;&nbsp;\n";
21a957a9 339 displayInternalLink ('src/addressbook.php', _("Addresses"));
a07cd1a4 340 echo "&nbsp;&nbsp;\n";
21a957a9 341 displayInternalLink ('src/folders.php', _("Folders"));
a07cd1a4 342 echo "&nbsp;&nbsp;\n";
21a957a9 343 displayInternalLink ('src/options.php', _("Options"));
a07cd1a4 344 echo "&nbsp;&nbsp;\n";
21a957a9 345 displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"));
a07cd1a4 346 echo "&nbsp;&nbsp;\n";
21a957a9 347 displayInternalLink ('src/help.php', _("Help"));
a07cd1a4 348 echo "&nbsp;&nbsp;\n";
349
d68323ff 350 do_hook('menuline');
a07cd1a4 351
99ea51d3 352 echo " </td>\n";
353
354 if (!$hide_sm_attributions)
355 {
356 echo html_tag( 'td', '', 'right' ) ."\n";
357 if (!isset($provider_uri)) $provider_uri= 'http://www.squirrelmail.org/';
358 if (!isset($provider_name)) $provider_name= 'SquirrelMail';
359 echo '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>';
360 echo "</td>\n";
361 }
362 echo " </tr>\n".
04fa3c41 363 "</table><br />\n\n";
a07cd1a4 364}
2ba13803 365
8b096f0a 366/**
367 * Blatantly copied/truncated/modified from displayPageHeader.
368 * Outputs a page header specifically for the compose_in_new popup window
369 *
370 * @param array color the array of theme colors
371 * @param string mailbox the current mailbox name to display
372 * @return void
373 */
9c3e6cd4 374function compose_Header($color, $mailbox) {
375
d62c4938 376 global $javascript_on;
9c3e6cd4 377
378 /*
d62c4938 379 * Locate the first displayable form element (only when JavaScript on)
380 */
381 if($javascript_on) {
ce68b76b 382 global $base_uri, $PHP_SELF, $data_dir, $username;
d62c4938 383
384 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
385
386 switch ( $module ) {
387 case 'src/search.php':
388 $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1;
389 $onload = "onload=\"document.forms[$pos].elements[2].focus();\"";
390 displayHtmlHeader (_("Compose"));
391 break;
392 default:
393 $js = '<script language="JavaScript" type="text/javascript">' .
394 "\n<!--\n" .
9f2f6126 395 "function checkForm() {\n";
396
397 global $action, $reply_focus;
398 if (strpos($action, 'reply') !== FALSE && $reply_focus)
399 {
400 if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
401 else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
192cdcf5 402 else if ($reply_focus == 'none') $js .= "}\n";
403 }
404 // no reply focus also applies to composing new messages
405 else if ($reply_focus == 'none')
406 {
407 $js .= "}\n";
9f2f6126 408 }
409 else
410 $js .= "var f = document.forms.length;\n".
d62c4938 411 "var i = 0;\n".
412 "var pos = -1;\n".
413 "while( pos == -1 && i < f ) {\n".
414 "var e = document.forms[i].elements.length;\n".
415 "var j = 0;\n".
416 "while( pos == -1 && j < e ) {\n".
417 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
418 "pos = j;\n".
419 "}\n".
420 "j++;\n".
9c3e6cd4 421 "}\n".
d62c4938 422 "i++;\n".
9c3e6cd4 423 "}\n".
d62c4938 424 "if( pos >= 0 ) {\n".
425 "document.forms[i-1].elements[pos].focus();\n".
426 "}\n".
427 "}\n";
428 $js .= "// -->\n".
1a531551 429 "</script>\n";
d62c4938 430 $onload = 'onload="checkForm();"';
431 displayHtmlHeader (_("Compose"), $js);
62f7daa5 432 break;
d62c4938 433 }
434 } else {
435 /* javascript off */
436 displayHtmlHeader(_("Compose"));
437 $onload = '';
9c3e6cd4 438 }
439
b01b21d0 440 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
9c3e6cd4 441}
e842b215 442
4910106a 443?>