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