Add base url to output of configtest.php.
[squirrelmail.git] / functions / page_header.php
... / ...
CommitLineData
1<?php
2
3/**
4 * page_header.php
5 *
6 * Copyright (c) 1999-2005 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 */
16require_once(SM_PATH . 'functions/strings.php');
17require_once(SM_PATH . 'functions/html.php');
18require_once(SM_PATH . 'functions/imap_mailbox.php');
19require_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 */
31function 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 /*
57 * force correct detection of charset, when browser does not follow
58 * http content-type and tries to detect charset from page content.
59 * Shooting of browser's creator can't be implemented in php.
60 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
61 * recommendations and switch to unicode.
62 */
63 echo "<!-- \xfd\xfe -->\n";
64 echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp" />' . "\n";
65 }
66
67 if ($do_hook) {
68 do_hook('generic_header');
69 }
70
71 echo "\n<title>$title</title>$xtra\n";
72
73 /* work around IE6's scrollbar bug */
74 echo <<<ECHO
75<style type="text/css">
76<!--
77 /* avoid stupid IE6 bug with frames and scrollbars */
78 body {
79 voice-family: "\"}\"";
80 voice-family: inherit;
81 width: expression(document.documentElement.clientWidth - 30);
82 }
83-->
84</style>
85
86ECHO;
87
88 echo "\n</head>\n\n";
89
90 /* this is used to check elsewhere whether we should call this function */
91 $pageheader_sent = TRUE;
92}
93
94/**
95 * Given a path to a SquirrelMail file, return a HTML link to it
96 *
97 * @param string path the SquirrelMail file to link to
98 * @param string text the link text
99 * @param string target the target frame for this link
100 */
101function makeInternalLink($path, $text, $target='') {
102 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
103 if ($target != '') {
104 $target = " target=\"$target\"";
105 }
106
107 // This is an inefficient hook and is only used by
108 // one plugin that still needs to patch this code,
109 // plus if we are templat-izing SM, visual hooks
110 // are not needed. However, I am leaving the code
111 // here just in case we find a good (non-visual?)
112 // use for the internal_link hook.
113 //
114 //$hooktext = do_hook_function('internal_link',$text);
115 //if ($hooktext != '')
116 // $text = $hooktext;
117
118 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
119}
120
121/**
122 * Same as makeInternalLink, but echoes it too
123 */
124function displayInternalLink($path, $text, $target='') {
125 echo makeInternalLink($path, $text, $target);
126}
127
128/**
129 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
130 * including the default menu bar. Uses displayHtmlHeader and takes
131 * JavaScript and locale settings into account.
132 *
133 * @param array color the array of theme colors
134 * @param string mailbox the current mailbox name to display
135 * @param string xtra extra html code to add
136 * @param bool session
137 * @return void
138 */
139function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
140
141 global $hide_sm_attributions, $PHP_SELF, $frame_top,
142 $compose_new_win, $compose_width, $compose_height,
143 $provider_name, $provider_uri, $startMessage,
144 $javascript_on, $default_use_mdn, $mdn_user_support;
145
146 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION );
147 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
148 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
149 if ($qmark = strpos($module, '?')) {
150 $module = substr($module, 0, $qmark);
151 }
152 if (!isset($frame_top)) {
153 $frame_top = '_top';
154 }
155
156 if ($session) {
157 $compose_uri = $base_uri.'src/compose.php?mailbox='.urlencode($mailbox).'&amp;attachedmessages=true&amp;session='."$session";
158 } else {
159 $compose_uri = $base_uri.'src/compose.php?newmessage=1';
160 $session = 0;
161 }
162
163 if( $javascript_on || strpos($xtra, 'new_js_autodetect_results.value') ) {
164
165 switch ( $module ) {
166 case 'src/read_body.php':
167 $js ='';
168
169 // compose in new window code
170 if ($compose_new_win == '1') {
171 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
172 $compose_width = '640';
173 }
174 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
175 $compose_height = '550';
176 }
177 $js .= "function comp_in_new_form(comp_uri, button, myform) {\n".
178 ' if (!comp_uri) {'."\n".
179 ' comp_uri = "'.$compose_uri."\";\n".
180 ' }'. "\n".
181 ' comp_uri += "&" + button.name + "=1";'."\n".
182 ' for ( var i=0; i < myform.elements.length; i++ ) {'."\n".
183 ' if ( myform.elements[i].type == "checkbox" && myform.elements[i].checked )'."\n".
184 ' comp_uri += "&" + myform.elements[i].name + "=1";'."\n".
185 ' }'."\n".
186 ' var newwin = window.open(comp_uri' .
187 ', "_blank",'.
188 '"width='.$compose_width. ',height='.$compose_height.
189 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
190 "}\n\n";
191 $js .= "function comp_in_new(comp_uri) {\n".
192 " if (!comp_uri) {\n".
193 ' comp_uri = "'.$compose_uri."\";\n".
194 ' }'. "\n".
195 ' var newwin = window.open(comp_uri' .
196 ', "_blank",'.
197 '"width='.$compose_width. ',height='.$compose_height.
198 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
199 "}\n\n";
200 }
201
202 // javascript for sending read receipts
203 if($default_use_mdn && $mdn_user_support) {
204 $js .= 'function sendMDN() {'."\n".
205 " mdnuri=window.location+'&sendreceipt=1'; ".
206 "var newwin = window.open(mdnuri,'right');".
207 "\n}\n\n";
208 }
209
210 // if any of the above passes, add the JS tags too.
211 if($js) {
212 $js = "\n".'<script language="JavaScript" type="text/javascript">' .
213 "\n<!--\n" . $js . "// -->\n</script>\n";
214 }
215
216 displayHtmlHeader ('SquirrelMail', $js);
217 $onload = $xtra;
218 break;
219 case 'src/compose.php':
220 $js = '<script language="JavaScript" type="text/javascript">' .
221 "\n<!--\n" .
222 "function checkForm() {\n";
223
224 global $action, $reply_focus;
225 if (strpos($action, 'reply') !== FALSE && $reply_focus)
226 {
227 if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
228 else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
229 else if ($reply_focus == 'none') $js .= "}\n";
230 }
231 // no reply focus also applies to composing new messages
232 else if ($reply_focus == 'none')
233 {
234 $js .= "}\n";
235 }
236 else
237 $js .= "var f = document.forms.length;\n".
238 "var i = 0;\n".
239 "var pos = -1;\n".
240 "while( pos == -1 && i < f ) {\n".
241 "var e = document.forms[i].elements.length;\n".
242 "var j = 0;\n".
243 "while( pos == -1 && j < e ) {\n".
244 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
245 "pos = j;\n".
246 "}\n".
247 "j++;\n".
248 "}\n".
249 "i++;\n".
250 "}\n".
251 "if( pos >= 0 ) {\n".
252 "document.forms[i-1].elements[pos].focus();\n".
253 "}\n".
254 "}\n";
255
256 $js .= "// -->\n".
257 "</script>\n";
258 $onload = 'onload="checkForm();"';
259 displayHtmlHeader ('SquirrelMail', $js);
260 break;
261
262 default:
263 $js = '<script language="JavaScript" type="text/javascript">' .
264 "\n<!--\n" .
265 "function checkForm() {\n".
266 "var f = document.forms.length;\n".
267 "var i = 0;\n".
268 "var pos = -1;\n".
269 "while( pos == -1 && i < f ) {\n".
270 "var e = document.forms[i].elements.length;\n".
271 "var j = 0;\n".
272 "while( pos == -1 && j < e ) {\n".
273 "if ( document.forms[i].elements[j].type == 'text' " .
274 "|| document.forms[i].elements[j].type == 'password' ) {\n".
275 "pos = j;\n".
276 "}\n".
277 "j++;\n".
278 "}\n".
279 "i++;\n".
280 "}\n".
281 "if( pos >= 0 ) {\n".
282 "document.forms[i-1].elements[pos].focus();\n".
283 "}\n".
284 "$xtra\n".
285 "}\n";
286
287 if ($compose_new_win == '1') {
288 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
289 $compose_width = '640';
290 }
291 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
292 $compose_height = '550';
293 }
294 $js .= "function comp_in_new(comp_uri) {\n".
295 " if (!comp_uri) {\n".
296 ' comp_uri = "'.$compose_uri."\";\n".
297 ' }'. "\n".
298 ' var newwin = window.open(comp_uri' .
299 ', "_blank",'.
300 '"width='.$compose_width. ',height='.$compose_height.
301 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
302 "}\n\n";
303
304 }
305 $js .= "// -->\n". "</script>\n";
306
307 $onload = 'onload="checkForm();"';
308 displayHtmlHeader ('SquirrelMail', $js);
309 break;
310
311 }
312 } else {
313 /* do not use JavaScript */
314 displayHtmlHeader ('SquirrelMail');
315 $onload = '';
316 }
317
318 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
319 /** Here is the header and wrapping table **/
320 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
321 readShortMailboxName($mailbox, $delimiter)));
322 if ( $shortBoxName == 'INBOX' ) {
323 $shortBoxName = _("INBOX");
324 }
325 echo "<a name=\"pagetop\"></a>\n"
326 . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
327 . html_tag( 'tr', '', '', $color[9] ) ."\n"
328 . html_tag( 'td', '', 'left' ) ."\n";
329 if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
330 echo ' ' . _("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
331 } else {
332 echo '&nbsp;';
333 }
334 echo " </td>\n"
335 . html_tag( 'td', '', 'right' ) ."<b>\n";
336 displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
337 echo "</b></td>\n"
338 . " </tr>\n"
339 . html_tag( 'tr', '', '', $color[4] ) ."\n"
340 . ($hide_sm_attributions ? html_tag( 'td', '', 'left', '', 'colspan="2"' )
341 : html_tag( 'td', '', 'left' ) )
342 . "\n";
343 $urlMailbox = urlencode($mailbox);
344 echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&amp;startMessage='.$startMessage);
345 echo "&nbsp;&nbsp;\n";
346 displayInternalLink ('src/addressbook.php', _("Addresses"));
347 echo "&nbsp;&nbsp;\n";
348 displayInternalLink ('src/folders.php', _("Folders"));
349 echo "&nbsp;&nbsp;\n";
350 displayInternalLink ('src/options.php', _("Options"));
351 echo "&nbsp;&nbsp;\n";
352 displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"));
353 echo "&nbsp;&nbsp;\n";
354 displayInternalLink ('src/help.php', _("Help"));
355 echo "&nbsp;&nbsp;\n";
356
357 do_hook('menuline');
358
359 echo " </td>\n";
360
361 if (!$hide_sm_attributions)
362 {
363 echo html_tag( 'td', '', 'right' ) ."\n";
364 if (!isset($provider_uri)) $provider_uri= 'http://www.squirrelmail.org/';
365 if (!isset($provider_name)) $provider_name= 'SquirrelMail';
366 echo '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>';
367 echo "</td>\n";
368 }
369 echo " </tr>\n".
370 "</table><br />\n\n";
371}
372
373/**
374 * Blatantly copied/truncated/modified from displayPageHeader.
375 * Outputs a page header specifically for the compose_in_new popup window
376 *
377 * @param array color the array of theme colors
378 * @param string mailbox the current mailbox name to display
379 * @return void
380 */
381function compose_Header($color, $mailbox) {
382
383 global $javascript_on;
384
385 /*
386 * Locate the first displayable form element (only when JavaScript on)
387 */
388 if($javascript_on) {
389 global $base_uri, $PHP_SELF, $data_dir, $username;
390
391 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
392
393 switch ( $module ) {
394 case 'src/search.php':
395 $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1;
396 $onload = "onload=\"document.forms[$pos].elements[2].focus();\"";
397 displayHtmlHeader (_("Compose"));
398 break;
399 default:
400 $js = '<script language="JavaScript" type="text/javascript">' .
401 "\n<!--\n" .
402 "function checkForm() {\n";
403
404 global $action, $reply_focus;
405 if (strpos($action, 'reply') !== FALSE && $reply_focus)
406 {
407 if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
408 else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
409 else if ($reply_focus == 'none') $js .= "}\n";
410 }
411 // no reply focus also applies to composing new messages
412 else if ($reply_focus == 'none')
413 {
414 $js .= "}\n";
415 }
416 else
417 $js .= "var f = document.forms.length;\n".
418 "var i = 0;\n".
419 "var pos = -1;\n".
420 "while( pos == -1 && i < f ) {\n".
421 "var e = document.forms[i].elements.length;\n".
422 "var j = 0;\n".
423 "while( pos == -1 && j < e ) {\n".
424 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
425 "pos = j;\n".
426 "}\n".
427 "j++;\n".
428 "}\n".
429 "i++;\n".
430 "}\n".
431 "if( pos >= 0 ) {\n".
432 "document.forms[i-1].elements[pos].focus();\n".
433 "}\n".
434 "}\n";
435 $js .= "// -->\n".
436 "</script>\n";
437 $onload = 'onload="checkForm();"';
438 displayHtmlHeader (_("Compose"), $js);
439 break;
440 }
441 } else {
442 /* javascript off */
443 displayHtmlHeader(_("Compose"));
444 $onload = '';
445 }
446
447 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
448}
449
450?>