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