05915145ca98806abb4ed5b01c6702292839cfc6
[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 function makeInternalLink($path, $text, $target='') {
70 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
71 if ($target != '') {
72 $target = " target=\"$target\"";
73 }
74 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
75 }
76
77 function displayInternalLink($path, $text, $target='') {
78 echo makeInternalLink($path, $text, $target);
79 }
80
81 function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
82
83 global $hide_sm_attributions, $PHP_SELF, $frame_top,
84 $compose_new_win, $compose_width, $compose_height,
85 $attachemessages, $provider_name, $provider_uri,
86 $javascript_on;
87
88 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION );
89 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
90 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
91 if ($qmark = strpos($module, '?')) {
92 $module = substr($module, 0, $qmark);
93 }
94 if (!isset($frame_top)) {
95 $frame_top = '_top';
96 }
97
98 if ($session) {
99 $compose_uri = $base_uri.'src/compose.php?mailbox='.urlencode($mailbox).'&amp;attachedmessages=true&amp;session='."$session";
100 } else {
101 $compose_uri = $base_uri.'src/compose.php?newmessage=1';
102 $session = 0;
103 }
104
105 if($javascript_on) {
106
107 switch ( $module ) {
108 case 'src/read_body.php':
109 $js ='';
110 if ($compose_new_win == '1') {
111 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
112 $compose_width = '640';
113 }
114 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
115 $compose_height = '550';
116 }
117 $js .= "\n".'<script language="JavaScript" type="text/javascript">' .
118 "\n<!--\n";
119 $js .= "function comp_in_new(comp_uri) {\n".
120 " if (!comp_uri) {\n".
121 ' comp_uri = "'.$compose_uri."\";\n".
122 ' }'. "\n".
123 ' var newwin = window.open(comp_uri' .
124 ', "_blank",'.
125 '"width='.$compose_width. ',height='.$compose_height.
126 ',scrollbars=yes,resizable=yes");'."\n".
127 "}\n\n";
128
129
130 $js .= 'function sendMDN() {'."\n".
131 "mdnuri=window.location+'&sendreceipt=1';".
132 "var newwin = window.open(mdnuri,'right');".
133 "\n}\n\n";
134
135 $js .= "// -->\n".
136 "</script>\n";
137
138 }
139 displayHtmlHeader ('SquirrelMail', $js);
140 $onload = $xtra;
141 break;
142 case 'src/compose.php':
143 $js = '<script language="JavaScript" type="text/javascript">' .
144 "\n<!--\n" .
145 "function checkForm() {\n".
146 "var f = document.forms.length;\n".
147 "var i = 0;\n".
148 "var pos = -1;\n".
149 "while( pos == -1 && i < f ) {\n".
150 "var e = document.forms[i].elements.length;\n".
151 "var j = 0;\n".
152 "while( pos == -1 && j < e ) {\n".
153 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
154 "pos = j;\n".
155 "}\n".
156 "j++;\n".
157 "}\n".
158 "i++;\n".
159 "}\n".
160 "if( pos >= 0 ) {\n".
161 "document.forms[i-1].elements[pos].focus();\n".
162 "}\n".
163 "}\n";
164
165 $js .= "// -->\n".
166 "</script>\n";
167 $onload = 'onload="checkForm();"';
168 displayHtmlHeader ('SquirrelMail', $js);
169 break;
170
171 default:
172 $js = '<script language="JavaScript" type="text/javascript">' .
173 "\n<!--\n" .
174 "function checkForm() {\n".
175 "var f = document.forms.length;\n".
176 "var i = 0;\n".
177 "var pos = -1;\n".
178 "while( pos == -1 && i < f ) {\n".
179 "var e = document.forms[i].elements.length;\n".
180 "var j = 0;\n".
181 "while( pos == -1 && j < e ) {\n".
182 "if ( document.forms[i].elements[j].type == 'text' " .
183 "|| document.forms[i].elements[j].type == 'password' ) {\n".
184 "pos = j;\n".
185 "}\n".
186 "j++;\n".
187 "}\n".
188 "i++;\n".
189 "}\n".
190 "if( pos >= 0 ) {\n".
191 "document.forms[i-1].elements[pos].focus();\n".
192 "}\n".
193 "$xtra\n".
194 "}\n";
195
196 if ($compose_new_win == '1') {
197 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
198 $compose_width = '640';
199 }
200 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
201 $compose_height = '550';
202 }
203 $js .= "function comp_in_new(comp_uri) {\n".
204 " if (!comp_uri) {\n".
205 ' comp_uri = "'.$compose_uri."\";\n".
206 ' }'. "\n".
207 ' var newwin = window.open(comp_uri' .
208 ', "_blank",'.
209 '"width='.$compose_width. ',height='.$compose_height.
210 ',scrollbars=yes,resizable=yes");'."\n".
211 "}\n\n";
212
213 }
214 $js .= "// -->\n". "</script>\n";
215
216 $onload = 'onload="checkForm();"';
217 displayHtmlHeader ('SquirrelMail', $js);
218 break;
219
220 }
221 } else {
222 /* do not use JavaScript */
223 displayHtmlHeader ('SquirrelMail');
224 $onload = '';
225 }
226
227 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
228 /** Here is the header and wrapping table **/
229 $shortBoxName = imap_utf7_decode_local(
230 readShortMailboxName($mailbox, $delimiter));
231 if ( $shortBoxName == 'INBOX' ) {
232 $shortBoxName = _("INBOX");
233 }
234 echo "<a name=\"pagetop\"></a>\n"
235 . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
236 . html_tag( 'tr', '', '', $color[9] ) ."\n"
237 . html_tag( 'td', '', 'left' ) ."\n";
238 if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
239 echo ' ' . _("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
240 } else {
241 echo '&nbsp;';
242 }
243 echo " </td>\n"
244 . html_tag( 'td', '', 'right' ) ."<b>\n";
245 displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
246 echo "</b></td>\n"
247 . " </tr>\n"
248 . html_tag( 'tr', '', '', $color[4] ) ."\n"
249 . html_tag( 'td', '', 'left' ) ."\n";
250 $urlMailbox = urlencode($mailbox);
251 echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox);
252 echo "&nbsp;&nbsp;\n";
253 displayInternalLink ('src/addressbook.php', _("Addresses"), 'right');
254 echo "&nbsp;&nbsp;\n";
255 displayInternalLink ('src/folders.php', _("Folders"), 'right');
256 echo "&nbsp;&nbsp;\n";
257 displayInternalLink ('src/options.php', _("Options"), 'right');
258 echo "&nbsp;&nbsp;\n";
259 displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"), 'right');
260 echo "&nbsp;&nbsp;\n";
261 displayInternalLink ('src/help.php', _("Help"), 'right');
262 echo "&nbsp;&nbsp;\n";
263
264 do_hook('menuline');
265
266 echo " </td>\n"
267 . html_tag( 'td', '', 'right' ) ."\n";
268 if (!isset($provider_uri)) $provider_uri= 'http://www.squirrelmail.org/';
269 if (!isset($provider_name)) $provider_name= 'SquirrelMail';
270 echo ($hide_sm_attributions ? '&nbsp;' :
271 '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>');
272 echo "</td>\n".
273 " </tr>\n".
274 "</table><br>\n\n";
275 }
276
277 /* blatently copied/truncated/modified from the above function */
278 function compose_Header($color, $mailbox) {
279
280 global $javascript_on;
281
282 /*
283 * Locate the first displayable form element (only when JavaScript on)
284 */
285 if($javascript_on) {
286 global $delimiter, $base_uri, $PHP_SELF, $data_dir, $username;
287
288 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
289
290 switch ( $module ) {
291 case 'src/search.php':
292 $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1;
293 $onload = "onload=\"document.forms[$pos].elements[2].focus();\"";
294 displayHtmlHeader (_("Compose"));
295 break;
296 default:
297 $js = '<script language="JavaScript" type="text/javascript">' .
298 "\n<!--\n" .
299 "function checkForm() {\n".
300 "var f = document.forms.length;\n".
301 "var i = 0;\n".
302 "var pos = -1;\n".
303 "while( pos == -1 && i < f ) {\n".
304 "var e = document.forms[i].elements.length;\n".
305 "var j = 0;\n".
306 "while( pos == -1 && j < e ) {\n".
307 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
308 "pos = j;\n".
309 "}\n".
310 "j++;\n".
311 "}\n".
312 "i++;\n".
313 "}\n".
314 "if( pos >= 0 ) {\n".
315 "document.forms[i-1].elements[pos].focus();\n".
316 "}\n".
317 "}\n";
318 $js .= "// -->\n".
319 "</script>\n";
320 $onload = 'onload="checkForm();"';
321 displayHtmlHeader (_("Compose"), $js);
322 break;
323 }
324 } else {
325 /* javascript off */
326 displayHtmlHeader(_("Compose"));
327 $onload = '';
328 }
329
330 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
331 }
332
333 ?>