added functions to support the html class
[squirrelmail.git] / functions / page_header.php
CommitLineData
59177427 1<?php
7350889b 2
35586184 3/**
4 * page_header.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
35586184 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
46d38f78 14require_once('../functions/strings.php');
f3e14140 15require_once('../functions/imap_utf7_decode_local.php');
b01b21d0 16require_once('../functions/html.php');
ec291321 17require_once('../class/html.class');
43fdb2a4 18
34c90574 19/* Always set up the language before calling these functions */
a07cd1a4 20function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE ) {
692155b7 21
2c21ef20 22 global $theme_css, $custom_css, $base_uri;
23
8f1ba72b 24 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">' .
25 "\n\n<HTML>\n<HEAD>\n";
2c21ef20 26
a714cb95 27 if ( !isset( $custom_css ) || $custom_css == 'none' ) {
692155b7 28 if ($theme_css != '') {
34c90574 29 echo "<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"$theme_css\">";
692155b7 30 }
8f1ba72b 31 } else {
2c21ef20 32 echo '<LINK REL="stylesheet" TYPE="text/css" HREF="' .
67dfe419 33 $base_uri . 'themes/css/'.$custom_css.'">';
8f1ba72b 34 }
cdaf8338 35
36 if ($do_hook) {
37 do_hook ("generic_header");
38 }
8f1ba72b 39
34c90574 40 echo "\n<title>$title</title>$xtra</head>\n\n";
a07cd1a4 41}
42
43function displayInternalLink($path, $text, $target='') {
44 global $base_uri;
45
46 if ($target != '') {
47 $target = " target=\"$target\"";
48 }
49
50 echo '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
51}
52
aca403fa 53function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
715225af 54
07687736 55 global $delimiter, $hide_sm_attributions, $base_uri, $PHP_SELF, $frame_top,
aca403fa 56 $compose_new_win, $username, $datadir, $compose_width, $compose_height,
57 $attachemessages, $session;
715225af 58
715225af 59 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
f3e14140 60 if ($qmark = strpos($module, '?')) {
61 $module = substr($module, 0, $qmark);
62 }
d03f3582 63 if (!isset($frame_top)) {
64 $frame_top = '_top';
65 }
715225af 66
67 /*
68 Locate the first displayable form element
69 */
aca403fa 70
cb6b53c6 71 if ($session != false) {
aca403fa 72 $compose_uri = 'src/compose.php?mailbox='. urlencode($mailbox).'&attachedmessages=true&session='."$session";
73 } else {
d7f8e6e6 74 $compose_uri = 'src/compose.php?newmessage=1';
75 $session = 0;
aca403fa 76 }
cb6b53c6 77
715225af 78 switch ( $module ) {
f3e14140 79 case 'src/read_body.php':
80 if ($compose_new_win == '1') {
81 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
82 $compose_width = '640';
83 }
84 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
85 $compose_height = '550';
86 }
87 $js = "\n".'<script language="JavaScript" type="text/javascript">' .
88 "\n<!--\n";
d7f8e6e6 89 $js .= "function comp_in_new(new_mes, comp_uri) {\n".
90 ' if (new_mes) { '."\n".
43ee2b5c 91 " comp_uri = \"".$base_uri."src/compose.php?newmessage=1\";\n".
d7f8e6e6 92 ' } else { '."\n".
93 " if (comp_uri =='') {\n".
94 ' comp_uri = "'.$base_uri.$compose_uri."\";\n".
95 ' }'. "\n".
96 ' }'. "\n".
97 ' var newwin = window.open(comp_uri' .
98 ', "_blank",
99 "width='.$compose_width.",height=$compose_height".
f3e14140 100 ",scrollbars=yes,resizable=yes\");\n".
101 "}\n";
d7f8e6e6 102
f3e14140 103 $js .= "// -->\n".
104 "</script>\n";
105 displayHtmlHeader ('Squirrelmail', $js);
106 }
107 displayHtmlHeader();
aca403fa 108 $onload = $xtra;
f3e14140 109 break;
d7f8e6e6 110 case 'src/compose.php':
111 $js = '<script language="JavaScript" type="text/javascript">' .
112 "\n<!--\n" .
113 "function checkForm() {\n".
114 "var f = document.forms.length;\n".
115 "var i = 0;\n".
116 "var pos = -1;\n".
117 "while( pos == -1 && i < f ) {\n".
118 "var e = document.forms[i].elements.length;\n".
119 "var j = 0;\n".
120 "while( pos == -1 && j < e ) {\n".
121 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
122 "pos = j;\n".
123 "}\n".
124 "j++;\n".
125 "}\n".
126 "i++;\n".
127 "}\n".
128 "if( pos >= 0 ) {\n".
129 "document.forms[i-1].elements[pos].focus();\n".
130 "}\n".
131 "}\n";
132
133 $js .= "// -->\n".
134 "</script>\n";
135 $onload = "onLoad=\"checkForm();\"";
136 displayHtmlHeader ('Squirrelmail', $js);
137 break;
138
715225af 139 default:
aaf16822 140 $js = '<script language="JavaScript" type="text/javascript">' .
353616c4 141 "\n<!--\n" .
142 "function checkForm() {\n".
143 "var f = document.forms.length;\n".
144 "var i = 0;\n".
145 "var pos = -1;\n".
146 "while( pos == -1 && i < f ) {\n".
147 "var e = document.forms[i].elements.length;\n".
148 "var j = 0;\n".
149 "while( pos == -1 && j < e ) {\n".
150 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
151 "pos = j;\n".
152 "}\n".
153 "j++;\n".
154 "}\n".
155 "i++;\n".
156 "}\n".
157 "if( pos >= 0 ) {\n".
158 "document.forms[i-1].elements[pos].focus();\n".
159 "}\n".
de19cd73 160 "$xtra\n".
9c3e6cd4 161 "}\n";
f3e14140 162
9c3e6cd4 163 if ($compose_new_win == '1') {
07687736 164 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
165 $compose_width = '640';
9c3e6cd4 166 }
07687736 167 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
168 $compose_height = '550';
9c3e6cd4 169 }
d7f8e6e6 170 $js .= "function comp_in_new(new_mes, comp_uri) {\n".
171 ' if (new_mes) { '."\n".
cb6b53c6 172 " comp_uri = \"".$base_uri."src/compose.php?newmessage=1\";\n".
d7f8e6e6 173 ' } else { '."\n".
174 " if (comp_uri =='') {\n".
175 ' comp_uri = "'.$base_uri.$compose_uri."\";\n".
176 ' }'. "\n".
177 ' }'. "\n".
d7f8e6e6 178 ' var newwin = window.open(comp_uri' .
179 ', "_blank",
f3e14140 180 "width='.$compose_width.",height=$compose_height".
9c3e6cd4 181 ",scrollbars=yes,resizable=yes\");\n".
182 "}\n";
183 }
aaf16822 184 $js .= "// -->\n".
de19cd73 185 "</script>\n";
715225af 186 $onload = "onLoad=\"checkForm();\"";
aaf16822 187 displayHtmlHeader ('Squirrelmail', $js);
715225af 188 break;
189
190 }
191
b01b21d0 192 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
a07cd1a4 193 /** Here is the header and wrapping table **/
f3e14140 194 $shortBoxName = imap_utf7_decode_local(
195 readShortMailboxName($mailbox, $delimiter));
3b7d68e6 196 if ( $shortBoxName == 'INBOX' ) {
7da23762 197 $shortBoxName = _("INBOX");
198 }
b01b21d0 199 echo "<a name=\"pagetop\"></a>\n"
200 . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
201 . html_tag( 'tr', '', '', $color[9] ) ."\n"
202 . html_tag( 'td', '', 'left' ) ."\n";
5bb2a991 203 if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
b01b21d0 204 echo ' ' . _("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
5bb2a991 205 } else {
206 echo '&nbsp;';
207 }
b01b21d0 208 echo " </td>\n"
209 . html_tag( 'td', '', 'right' ) ."<b>\n";
80e86e94 210 displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
b01b21d0 211 echo "</b></td>\n"
212 . " </tr>\n"
213 . html_tag( 'tr', '', '', $color[4] ) ."\n"
214 . html_tag( 'td', '', 'left' ) ."\n";
a07cd1a4 215 $urlMailbox = urlencode($mailbox);
9c3e6cd4 216 if ($compose_new_win == '1') {
d7f8e6e6 217 echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(true,'')\">". _("Compose"). '</a>';
9c3e6cd4 218 }
219 else {
220 displayInternalLink ("src/compose.php?mailbox=$urlMailbox", _("Compose"), 'right');
221 }
a07cd1a4 222 echo "&nbsp;&nbsp;\n";
223 displayInternalLink ("src/addressbook.php", _("Addresses"), 'right');
224 echo "&nbsp;&nbsp;\n";
225 displayInternalLink ("src/folders.php", _("Folders"), 'right');
226 echo "&nbsp;&nbsp;\n";
227 displayInternalLink ("src/options.php", _("Options"), 'right');
228 echo "&nbsp;&nbsp;\n";
229 displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"), 'right');
230 echo "&nbsp;&nbsp;\n";
231 displayInternalLink ("src/help.php", _("Help"), 'right');
232 echo "&nbsp;&nbsp;\n";
233
234 do_hook("menuline");
235
b01b21d0 236 echo " </td>\n"
237 . html_tag( 'td', '', 'right' ) ."\n";
a07cd1a4 238 echo ($hide_sm_attributions ? '&nbsp;' :
b01b21d0 239 '<a href="http://www.squirrelmail.org/" target="_blank">SquirrelMail</a>');
240 echo "</td>\n".
241 " </tr>\n".
242 "</table>\n\n";
a07cd1a4 243}
2ba13803 244
9c3e6cd4 245/* blatently copied/truncated/modified from the above function */
246function compose_Header($color, $mailbox) {
247
248 global $delimiter, $hide_sm_attributions, $base_uri, $PHP_SELF, $frame_top, $compose_new_win;
249
9c3e6cd4 250
251 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
252 if (!isset($frame_top)) {
253 $frame_top = '_top';
254 }
255
256 /*
257 Locate the first displayable form element
258 */
259 switch ( $module ) {
260 case 'src/search.php':
261 $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1;
262 $onload = "onLoad=\"document.forms[$pos].elements[2].focus();\"";
aaf16822 263 displayHtmlHeader (_("Compose"));
9c3e6cd4 264 break;
265 default:
aaf16822 266 $js = '<script language="JavaScript" type="text/javascript">' .
9c3e6cd4 267 "\n<!--\n" .
268 "function checkForm() {\n".
269 "var f = document.forms.length;\n".
270 "var i = 0;\n".
271 "var pos = -1;\n".
272 "while( pos == -1 && i < f ) {\n".
273 "var e = document.forms[i].elements.length;\n".
274 "var j = 0;\n".
275 "while( pos == -1 && j < e ) {\n".
276 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
277 "pos = j;\n".
278 "}\n".
279 "j++;\n".
280 "}\n".
281 "i++;\n".
282 "}\n".
283 "if( pos >= 0 ) {\n".
284 "document.forms[i-1].elements[pos].focus();\n".
285 "}\n".
286 "}\n";
aaf16822 287 $js .= "// -->\n".
de19cd73 288 "</script>\n";
9c3e6cd4 289 $onload = "onLoad=\"checkForm();\"";
aaf16822 290 displayHtmlHeader (_("Compose"), $js);
9c3e6cd4 291 break;
292
293 }
294
b01b21d0 295 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
9c3e6cd4 296}
ec291321 297
298function initPage () {
299
300 global $theme_css, $custom_css, $base_uri;
301 $page = new html();
302 $page->addChild('!DOCTYPE','','','','',
303 array('HTML','PUBLIC', '"-//W3C//DTD HTML 4.0 Transitional//EN"'));
304 $html = new html('html');
305 $html->addChild('HTML');
306 return $page;
307}
308
309function initHead ($title = 'SquirrelMail') {
310 global $use_css, $compose_new_win, $compose_width, $compose_height,
311 $base_uri;
312
313 $head = new html('head');
314 $head->addChild('title', $title);
315 if ($use_css) {
316 $head->addChild('link','','','','',
317 array('REL' => 'stylesheet', 'TYPE' => 'text/css',
318 'HREF' => $base_uri .'/css/read_body.css'));
319 }
320 if ($compose_new_win == '1') {
321 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
322 $compose_width = '640';
323 }
324 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
325 $compose_height = '550';
326 }
327 $js = "function comp_in_new(new_mes, comp_uri) {\n".
328 ' if (new_mes) { '."\n".
329 " comp_uri = \"".$base_uri."src/compose.php?newmessage=1\";\n".
330 ' } else { '."\n".
331 " if (comp_uri =='') {\n".
332 ' comp_uri = "'.$base_uri.$compose_uri."\";\n".
333 ' }'. "\n".
334 ' }'. "\n".
335 ' var newwin = window.open(comp_uri' .
336 ', "_blank",
337 "width='.$compose_width.",height=$compose_height".
338 ",scrollbars=yes,resizable=yes\");\n".
339 "}\n";
340 $head->scriptAdd($js);
341 }
342 return $head;
343}
344
345function initBody($color, $javascript='') {
346 global $use_css;
347
348 if (!$use_css) {
349 $body = new html('body','','','','',
350 array('bgcolor' => $color[4], 'text' => $color[8], 'link' => $color[7],
351 'vlink' => $color[7], 'alink' => $color[7]), $javascript);
352 } else {
353 $body = new html('body','','','','','',$javascript);
354 }
355 return $body;
356}
357
358
359function getTop($color, $mailbox) {
360
361 global $use_css, $languages, $squirrelmail_language, $frame_top,
362 $delimiter, $base_uri;
363
364 if ( isset( $languages[$squirrelmail_language]['DIR']) ) {
365 $dir = $languages[$squirrelmail_language]['DIR'];
366 } else {
367 $dir = 'ltr';
368 }
369
370 if ( $dir == 'ltr' ) {
371 $rgt = 'right';
372 $lft = 'left';
373 } else {
374 $rgt = 'left';
375 $lft = 'right';
376 }
377
378
379
380 if (!$use_css) {
381 $tbl_ar = array('bgcolor' => $color[4], 'border' => 0, 'width' => '100%',
382 'cellspacing' => 0, 'cellpadding' => 2);
383 $row_ar = array('bgcolor' => $color[9]);
384 $col_ar = array('align' => $lft);
385 } else {
386 $tbl_ar = array('border' => 0,
387 'cellspacing' => 0, 'cellpadding' => 2);
388 $row_ar = '';
389 $col_ar = array('align' => $lft);
390 }
391
392 $shortBoxName = imap_utf7_decode_local(
393 readShortMailboxName($mailbox, $delimiter));
394 if ( $shortBoxName == 'INBOX' ) {
395 $shortBoxName = _("INBOX");
396 }
397
398 $top = new html('table','','','tp','tp',$tbl_ar);
399 $row = new html('tr','','','tp_r','tp_r',$row_ar);
400
401 if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
402 $row->addChild('td',_("Current Folder") .':','','tp_c','tp_mbx_k',
403 array('align' => $lft));
404 $row->addChild('td',$shortBoxName .'&nbsp',array('b'=>true),'tp_c',
405 'tp_mbx_v',array('align' => $lft));
406 }
407 $col = new html('td','','','tp_c','tp_so',array('align' => $rgt));
408 if ($frame_top) {
409 $lnk_ar = array('href' => $base_uri.'src/signout.php', 'target' => $frame_top);
410 } else {
411 $lnk_ar = array('href' => $base_uri.'src/signout.php');
412 }
413 $col->addChild('a', _("Sign Out"),array('b'=>true),'','',$lnk_ar);
414 $row->htmlAdd($col);
415 $top->htmlAdd($row);
416
417 return $top;
418}
419
420function getMenu($color,$mailbox) {
421 global $use_css, $languages, $squirrelmail_language, $frame_top, $base_uri,
422 $compose_new_win,$hide_sm_attributions;
423
424 $urlMailbox = urlencode($mailbox);
425
426 if ( isset( $languages[$squirrelmail_language]['DIR']) ) {
427 $dir = $languages[$squirrelmail_language]['DIR'];
428 } else {
429 $dir = 'ltr';
430 }
431
432 if ( $dir == 'ltr' ) {
433 $rgt = 'right';
434 $lft = 'left';
435 } else {
436 $rgt = 'left';
437 $lft = 'right';
438 }
439
440 if (!$use_css) {
441 $tbl_ar = array('bgcolor' => $color[4], 'border' => 0, 'width' => '100%',
442 'cellspacing' => 0, 'cellpadding' => 2);
443 $row_ar = array('bgcolor' => $color[4]);
444 $col_ar = array('align' => $lft);
445 } else {
446 $tbl_ar = array('border' => 0,
447 'cellspacing' => 0, 'cellpadding' => 2);
448 $row_ar = '';
449 $col_ar = array('align' => $lft);
450 }
451
452 $menu = new html('table','','','mn','mn',$tbl_ar);
453 $row = new html('tr','','','mn','mn_r',$row_ar);
454 $col = new html('td','','','mn','mn_c',$col_ar);
455 $delimiter = new html('','&nbsp;&nbsp;');
456 if ($compose_new_win == '1') {
457 $col->addChild('a',_("Compose"),'','mn_c','mn_co',
458 array('href' => 'javascript:void(0)'),
459 array('onclick'=>'comp_in_new(true,"")'));
460 } else {
461 $col->addChild('a',_("Compose"),'','mn_c','mn_co',
462 array('href' => $base_uri.'src/compose.php?mailbox='.$urlMailbox,
463 'target' => 'right'));
464 }
465 $col->htmlAdd($delimiter);
466 $col->addChild('a',_("Addresses"),'','mn_c','mn_ad',
467 array('href' => $base_uri.'src/addressbook.php',
468 'target' => 'right'));
469 $col->htmlAdd($delimiter);
470 $col->addChild('a',_("Folders"),'','mn_c','mn_fo',
471 array('href' => $base_uri.'src/folders.php',
472 'target' => 'right'));
473 $col->htmlAdd($delimiter);
474
475 $col->addChild('a',_("Options"),'','mn_c','mn_op',
476 array('href' => $base_uri.'src/options.php',
477 'target' => 'right'));
478 $col->htmlAdd($delimiter);
479 $col->addChild('a',_("Search"),'','mn_c','mn_se',
480 array('href' => $base_uri.'src/search.php?mailbox='.$urlMailbox,
481 'target' => 'right'));
482 $col->htmlAdd($delimiter);
483 $col->addChild('a',_("Help"),'','mn_c','mn_he',
484 array('href' => $base_uri.'src/help.php',
485 'target' => 'right'));
486
487 do_hook("menuline");
488 $row->htmlAdd($col);
489 if (!$hide_sm_attributions) {
490 $col = new html('td','','','mn','mn_sm',array('align'=>$rgt));
491 $col->addChild('a','SquirrelMail','','','',
492 array('href'=>'http://www.squirrelmail.org','target'=>'_blank'));
493 $row->htmlAdd($col);
494 }
495 $menu->htmlAdd($row);
496 return $menu;
497}
498
43fdb2a4 499?>