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