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