8fed43b9dc722fa41f3c0c8e4aaaf8eb8c7a4bb1
[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
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
111 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
112 }
113
114 /**
115 * Same as makeInternalLink, but echoes it too
116 */
117 function displayInternalLink($path, $text, $target='') {
118 echo makeInternalLink($path, $text, $target);
119 }
120
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 */
132 function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
133
134 global $hide_sm_attributions, $PHP_SELF, $frame_top,
135 $compose_new_win, $compose_width, $compose_height,
136 $provider_name, $provider_uri, $startMessage,
137 $javascript_on, $default_use_mdn, $mdn_user_support;
138
139 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION );
140 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
141 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
142 if ($qmark = strpos($module, '?')) {
143 $module = substr($module, 0, $qmark);
144 }
145 if (!isset($frame_top)) {
146 $frame_top = '_top';
147 }
148
149 if ($session) {
150 $compose_uri = $base_uri.'src/compose.php?mailbox='.urlencode($mailbox).'&amp;attachedmessages=true&amp;session='."$session";
151 } else {
152 $compose_uri = $base_uri.'src/compose.php?newmessage=1';
153 $session = 0;
154 }
155
156 if($javascript_on) {
157
158 switch ( $module ) {
159 case 'src/read_body.php':
160 $js ='';
161
162 // compose in new window code
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 }
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.
182 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
183 "}\n\n";
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.
191 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
192 "}\n\n";
193 }
194
195 // javascript for sending read receipts
196 if($default_use_mdn && $mdn_user_support) {
197 $js .= 'function sendMDN() {'."\n".
198 " mdnuri=window.location+'&sendreceipt=1'; ".
199 "var newwin = window.open(mdnuri,'right');".
200 "\n}\n\n";
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 }
208
209 displayHtmlHeader ('SquirrelMail', $js);
210 $onload = $xtra;
211 break;
212 case 'src/compose.php':
213 $js = '<script language="JavaScript" type="text/javascript">' .
214 "\n<!--\n" .
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";
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";
228 }
229 else
230 $js .= "var f = document.forms.length;\n".
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".
241 "}\n".
242 "i++;\n".
243 "}\n".
244 "if( pos >= 0 ) {\n".
245 "document.forms[i-1].elements[pos].focus();\n".
246 "}\n".
247 "}\n";
248
249 $js .= "// -->\n".
250 "</script>\n";
251 $onload = 'onload="checkForm();"';
252 displayHtmlHeader ('SquirrelMail', $js);
253 break;
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".
271 "}\n".
272 "i++;\n".
273 "}\n".
274 "if( pos >= 0 ) {\n".
275 "document.forms[i-1].elements[pos].focus();\n".
276 "}\n".
277 "$xtra\n".
278 "}\n";
279
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".
288 " if (!comp_uri) {\n".
289 ' comp_uri = "'.$compose_uri."\";\n".
290 ' }'. "\n".
291 ' var newwin = window.open(comp_uri' .
292 ', "_blank",'.
293 '"width='.$compose_width. ',height='.$compose_height.
294 ',scrollbars=yes,resizable=yes,status=yes");'."\n".
295 "}\n\n";
296
297 }
298 $js .= "// -->\n". "</script>\n";
299
300 $onload = 'onload="checkForm();"';
301 displayHtmlHeader ('SquirrelMail', $js);
302 break;
303
304 }
305 } else {
306 /* do not use JavaScript */
307 displayHtmlHeader ('SquirrelMail');
308 $onload = '';
309 }
310
311 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
312 /** Here is the header and wrapping table **/
313 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
314 readShortMailboxName($mailbox, $delimiter)));
315 if ( $shortBoxName == 'INBOX' ) {
316 $shortBoxName = _("INBOX");
317 }
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";
322 if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
323 echo ' ' . _("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
324 } else {
325 echo '&nbsp;';
326 }
327 echo " </td>\n"
328 . html_tag( 'td', '', 'right' ) ."<b>\n";
329 displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
330 echo "</b></td>\n"
331 . " </tr>\n"
332 . html_tag( 'tr', '', '', $color[4] ) ."\n"
333 . ($hide_sm_attributions ? html_tag( 'td', '', 'left', '', 'colspan="2"' )
334 : html_tag( 'td', '', 'left' ) )
335 . "\n";
336 $urlMailbox = urlencode($mailbox);
337 echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&amp;startMessage='.$startMessage);
338 echo "&nbsp;&nbsp;\n";
339 displayInternalLink ('src/addressbook.php', _("Addresses"));
340 echo "&nbsp;&nbsp;\n";
341 displayInternalLink ('src/folders.php', _("Folders"));
342 echo "&nbsp;&nbsp;\n";
343 displayInternalLink ('src/options.php', _("Options"));
344 echo "&nbsp;&nbsp;\n";
345 displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"));
346 echo "&nbsp;&nbsp;\n";
347 displayInternalLink ('src/help.php', _("Help"));
348 echo "&nbsp;&nbsp;\n";
349
350 do_hook('menuline');
351
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".
363 "</table><br />\n\n";
364 }
365
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 */
374 function compose_Header($color, $mailbox) {
375
376 global $javascript_on;
377
378 /*
379 * Locate the first displayable form element (only when JavaScript on)
380 */
381 if($javascript_on) {
382 global $base_uri, $PHP_SELF, $data_dir, $username;
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" .
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";
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";
408 }
409 else
410 $js .= "var f = document.forms.length;\n".
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".
421 "}\n".
422 "i++;\n".
423 "}\n".
424 "if( pos >= 0 ) {\n".
425 "document.forms[i-1].elements[pos].focus();\n".
426 "}\n".
427 "}\n";
428 $js .= "// -->\n".
429 "</script>\n";
430 $onload = 'onload="checkForm();"';
431 displayHtmlHeader (_("Compose"), $js);
432 break;
433 }
434 } else {
435 /* javascript off */
436 displayHtmlHeader(_("Compose"));
437 $onload = '';
438 }
439
440 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
441 }
442
443 ?>