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