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