59177427 |
1 | <?php |
7350889b |
2 | |
35586184 |
3 | /** |
4 | * page_header.php |
5 | * |
6c84ba1e |
6 | * Copyright (c) 1999-2005 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 |
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'); |
0b97a708 |
19 | require_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 |
31 | function 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') { |
683b7853 |
56 | /* |
e50f5ac2 |
57 | * force correct detection of charset, when browser does not follow |
683b7853 |
58 | * http content-type and tries to detect charset from page content. |
59 | * Shooting of browser's creator can't be implemented in php. |
e50f5ac2 |
60 | * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/ |
683b7853 |
61 | * recommendations and switch to unicode. |
e50f5ac2 |
62 | */ |
e842b215 |
63 | echo "<!-- \xfd\xfe -->\n"; |
04fa3c41 |
64 | echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp" />' . "\n"; |
e842b215 |
65 | } |
62f7daa5 |
66 | |
237470b4 |
67 | if ($do_hook) { |
d68323ff |
68 | do_hook('generic_header'); |
237470b4 |
69 | } |
62f7daa5 |
70 | |
5ca4b1ee |
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 */ |
62f7daa5 |
78 | body { |
79 | voice-family: "\"}\""; |
80 | voice-family: inherit; |
5ca4b1ee |
81 | width: expression(document.documentElement.clientWidth - 30); |
82 | } |
83 | --> |
84 | </style> |
85 | |
86 | ECHO; |
87 | |
88 | echo "\n</head>\n\n"; |
b6c283c4 |
89 | |
90 | /* this is used to check elsewhere whether we should call this function */ |
91 | $pageheader_sent = TRUE; |
a07cd1a4 |
92 | } |
93 | |
8b096f0a |
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 | */ |
d62c4938 |
101 | function makeInternalLink($path, $text, $target='') { |
0365891c |
102 | sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION); |
dcc1cc82 |
103 | if ($target != '') { |
104 | $target = " target=\"$target\""; |
105 | } |
4910106a |
106 | |
e50f5ac2 |
107 | // This is an inefficient hook and is only used by |
4910106a |
108 | // one plugin that still needs to patch this code, |
e50f5ac2 |
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?) |
4910106a |
112 | // use for the internal_link hook. |
113 | // |
114 | //$hooktext = do_hook_function('internal_link',$text); |
115 | //if ($hooktext != '') |
116 | // $text = $hooktext; |
117 | |
d62c4938 |
118 | return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>'; |
119 | } |
120 | |
8b096f0a |
121 | /** |
122 | * Same as makeInternalLink, but echoes it too |
123 | */ |
d62c4938 |
124 | function displayInternalLink($path, $text, $target='') { |
b26d81e5 |
125 | echo makeInternalLink($path, $text, $target); |
a07cd1a4 |
126 | } |
127 | |
8b096f0a |
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 | */ |
aca403fa |
139 | function displayPageHeader($color, $mailbox, $xtra='', $session=false) { |
715225af |
140 | |
0b97a708 |
141 | global $hide_sm_attributions, $PHP_SELF, $frame_top, |
1ba8cd6b |
142 | $compose_new_win, $compose_width, $compose_height, |
ce68b76b |
143 | $provider_name, $provider_uri, $startMessage, |
144 | $javascript_on, $default_use_mdn, $mdn_user_support; |
715225af |
145 | |
0365891c |
146 | sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION ); |
147 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION ); |
715225af |
148 | $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 ); |
f3e14140 |
149 | if ($qmark = strpos($module, '?')) { |
150 | $module = substr($module, 0, $qmark); |
151 | } |
d03f3582 |
152 | if (!isset($frame_top)) { |
153 | $frame_top = '_top'; |
154 | } |
715225af |
155 | |
735f6b9c |
156 | if ($session) { |
1a531551 |
157 | $compose_uri = $base_uri.'src/compose.php?mailbox='.urlencode($mailbox).'&attachedmessages=true&session='."$session"; |
aca403fa |
158 | } else { |
087ce5f8 |
159 | $compose_uri = $base_uri.'src/compose.php?newmessage=1'; |
1a531551 |
160 | $session = 0; |
aca403fa |
161 | } |
62f7daa5 |
162 | |
04f8889b |
163 | if( $javascript_on || strpos($xtra, 'new_js_autodetect_results.value') ) { |
d62c4938 |
164 | |
165 | switch ( $module ) { |
166 | case 'src/read_body.php': |
167 | $js =''; |
32485e5e |
168 | |
169 | // compose in new window code |
d62c4938 |
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 | } |
1a531551 |
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. |
75442b66 |
189 | ',scrollbars=yes,resizable=yes,status=yes");'."\n". |
1a531551 |
190 | "}\n\n"; |
e346043e |
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. |
75442b66 |
198 | ',scrollbars=yes,resizable=yes,status=yes");'."\n". |
e346043e |
199 | "}\n\n"; |
32485e5e |
200 | } |
d62c4938 |
201 | |
32485e5e |
202 | // javascript for sending read receipts |
203 | if($default_use_mdn && $mdn_user_support) { |
d62c4938 |
204 | $js .= 'function sendMDN() {'."\n". |
32485e5e |
205 | " mdnuri=window.location+'&sendreceipt=1'; ". |
d62c4938 |
206 | "var newwin = window.open(mdnuri,'right');". |
1a531551 |
207 | "\n}\n\n"; |
32485e5e |
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 | } |
d62c4938 |
215 | |
32485e5e |
216 | displayHtmlHeader ('SquirrelMail', $js); |
217 | $onload = $xtra; |
d62c4938 |
218 | break; |
219 | case 'src/compose.php': |
220 | $js = '<script language="JavaScript" type="text/javascript">' . |
221 | "\n<!--\n" . |
9f2f6126 |
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"; |
192cdcf5 |
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"; |
9f2f6126 |
235 | } |
236 | else |
237 | $js .= "var f = document.forms.length;\n". |
d62c4938 |
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". |
d7f8e6e6 |
248 | "}\n". |
d62c4938 |
249 | "i++;\n". |
d7f8e6e6 |
250 | "}\n". |
d62c4938 |
251 | "if( pos >= 0 ) {\n". |
252 | "document.forms[i-1].elements[pos].focus();\n". |
253 | "}\n". |
254 | "}\n"; |
62f7daa5 |
255 | |
d62c4938 |
256 | $js .= "// -->\n". |
1a531551 |
257 | "</script>\n"; |
d62c4938 |
258 | $onload = 'onload="checkForm();"'; |
259 | displayHtmlHeader ('SquirrelMail', $js); |
62f7daa5 |
260 | break; |
d62c4938 |
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". |
353616c4 |
278 | "}\n". |
d62c4938 |
279 | "i++;\n". |
280 | "}\n". |
281 | "if( pos >= 0 ) {\n". |
282 | "document.forms[i-1].elements[pos].focus();\n". |
353616c4 |
283 | "}\n". |
1a531551 |
284 | "$xtra\n". |
d62c4938 |
285 | "}\n"; |
62f7daa5 |
286 | |
d62c4938 |
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". |
75442b66 |
295 | " if (!comp_uri) {\n". |
296 | ' comp_uri = "'.$compose_uri."\";\n". |
297 | ' }'. "\n". |
d62c4938 |
298 | ' var newwin = window.open(comp_uri' . |
299 | ', "_blank",'. |
300 | '"width='.$compose_width. ',height='.$compose_height. |
75442b66 |
301 | ',scrollbars=yes,resizable=yes,status=yes");'."\n". |
d62c4938 |
302 | "}\n\n"; |
303 | |
9c3e6cd4 |
304 | } |
d62c4938 |
305 | $js .= "// -->\n". "</script>\n"; |
62f7daa5 |
306 | |
d62c4938 |
307 | $onload = 'onload="checkForm();"'; |
308 | displayHtmlHeader ('SquirrelMail', $js); |
62f7daa5 |
309 | break; |
0cba960a |
310 | |
d62c4938 |
311 | } |
312 | } else { |
313 | /* do not use JavaScript */ |
314 | displayHtmlHeader ('SquirrelMail'); |
315 | $onload = ''; |
715225af |
316 | } |
317 | |
b01b21d0 |
318 | echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n"; |
a07cd1a4 |
319 | /** Here is the header and wrapping table **/ |
72520f77 |
320 | $shortBoxName = htmlspecialchars(imap_utf7_decode_local( |
91e0dccc |
321 | readShortMailboxName($mailbox, $delimiter))); |
3b7d68e6 |
322 | if ( $shortBoxName == 'INBOX' ) { |
7da23762 |
323 | $shortBoxName = _("INBOX"); |
324 | } |
b01b21d0 |
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"; |
5bb2a991 |
329 | if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) { |
b01b21d0 |
330 | echo ' ' . _("Current Folder") . ": <b>$shortBoxName </b>\n"; |
5bb2a991 |
331 | } else { |
332 | echo ' '; |
333 | } |
b01b21d0 |
334 | echo " </td>\n" |
335 | . html_tag( 'td', '', 'right' ) ."<b>\n"; |
80e86e94 |
336 | displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top); |
b01b21d0 |
337 | echo "</b></td>\n" |
338 | . " </tr>\n" |
339 | . html_tag( 'tr', '', '', $color[4] ) ."\n" |
99ea51d3 |
340 | . ($hide_sm_attributions ? html_tag( 'td', '', 'left', '', 'colspan="2"' ) |
341 | : html_tag( 'td', '', 'left' ) ) |
342 | . "\n"; |
a07cd1a4 |
343 | $urlMailbox = urlencode($mailbox); |
e233a3ad |
344 | echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&startMessage='.$startMessage); |
a07cd1a4 |
345 | echo " \n"; |
21a957a9 |
346 | displayInternalLink ('src/addressbook.php', _("Addresses")); |
a07cd1a4 |
347 | echo " \n"; |
21a957a9 |
348 | displayInternalLink ('src/folders.php', _("Folders")); |
a07cd1a4 |
349 | echo " \n"; |
21a957a9 |
350 | displayInternalLink ('src/options.php', _("Options")); |
a07cd1a4 |
351 | echo " \n"; |
21a957a9 |
352 | displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search")); |
a07cd1a4 |
353 | echo " \n"; |
21a957a9 |
354 | displayInternalLink ('src/help.php', _("Help")); |
a07cd1a4 |
355 | echo " \n"; |
356 | |
d68323ff |
357 | do_hook('menuline'); |
a07cd1a4 |
358 | |
99ea51d3 |
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". |
04fa3c41 |
370 | "</table><br />\n\n"; |
a07cd1a4 |
371 | } |
2ba13803 |
372 | |
8b096f0a |
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 | */ |
9c3e6cd4 |
381 | function compose_Header($color, $mailbox) { |
382 | |
d62c4938 |
383 | global $javascript_on; |
9c3e6cd4 |
384 | |
385 | /* |
d62c4938 |
386 | * Locate the first displayable form element (only when JavaScript on) |
387 | */ |
388 | if($javascript_on) { |
ce68b76b |
389 | global $base_uri, $PHP_SELF, $data_dir, $username; |
d62c4938 |
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" . |
9f2f6126 |
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"; |
192cdcf5 |
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"; |
9f2f6126 |
415 | } |
416 | else |
417 | $js .= "var f = document.forms.length;\n". |
d62c4938 |
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". |
9c3e6cd4 |
428 | "}\n". |
d62c4938 |
429 | "i++;\n". |
9c3e6cd4 |
430 | "}\n". |
d62c4938 |
431 | "if( pos >= 0 ) {\n". |
432 | "document.forms[i-1].elements[pos].focus();\n". |
433 | "}\n". |
434 | "}\n"; |
435 | $js .= "// -->\n". |
1a531551 |
436 | "</script>\n"; |
d62c4938 |
437 | $onload = 'onload="checkForm();"'; |
438 | displayHtmlHeader (_("Compose"), $js); |
62f7daa5 |
439 | break; |
d62c4938 |
440 | } |
441 | } else { |
442 | /* javascript off */ |
443 | displayHtmlHeader(_("Compose")); |
444 | $onload = ''; |
9c3e6cd4 |
445 | } |
446 | |
b01b21d0 |
447 | echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n"; |
9c3e6cd4 |
448 | } |
e842b215 |
449 | |
e50f5ac2 |
450 | ?> |