| 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 | require_once('../class/html.class'); |
| 18 | |
| 19 | /* Always set up the language before calling these functions */ |
| 20 | function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE ) { |
| 21 | |
| 22 | global $theme_css, $custom_css, $base_uri; |
| 23 | |
| 24 | echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">' . |
| 25 | "\n\n<HTML>\n<HEAD>\n"; |
| 26 | |
| 27 | if ( !isset( $custom_css ) || $custom_css == 'none' ) { |
| 28 | if ($theme_css != '') { |
| 29 | echo "<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"$theme_css\">"; |
| 30 | } |
| 31 | } else { |
| 32 | echo '<LINK REL="stylesheet" TYPE="text/css" HREF="' . |
| 33 | $base_uri . 'themes/css/'.$custom_css.'">'; |
| 34 | } |
| 35 | |
| 36 | if ($do_hook) { |
| 37 | do_hook ("generic_header"); |
| 38 | } |
| 39 | |
| 40 | echo "\n<title>$title</title>$xtra</head>\n\n"; |
| 41 | } |
| 42 | |
| 43 | function 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 | |
| 53 | function displayPageHeader($color, $mailbox, $xtra='', $session=false) { |
| 54 | |
| 55 | global $delimiter, $hide_sm_attributions, $base_uri, $PHP_SELF, $frame_top, |
| 56 | $compose_new_win, $username, $datadir, $compose_width, $compose_height, |
| 57 | $attachemessages, $session; |
| 58 | |
| 59 | $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 ); |
| 60 | if ($qmark = strpos($module, '?')) { |
| 61 | $module = substr($module, 0, $qmark); |
| 62 | } |
| 63 | if (!isset($frame_top)) { |
| 64 | $frame_top = '_top'; |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | Locate the first displayable form element |
| 69 | */ |
| 70 | |
| 71 | if ($session != false) { |
| 72 | $compose_uri = 'src/compose.php?mailbox='. urlencode($mailbox).'&attachedmessages=true&session='."$session"; |
| 73 | } else { |
| 74 | $compose_uri = 'src/compose.php?newmessage=1'; |
| 75 | $session = 0; |
| 76 | } |
| 77 | |
| 78 | switch ( $module ) { |
| 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"; |
| 89 | $js .= "function comp_in_new(new_mes, comp_uri) {\n". |
| 90 | ' if (new_mes) { '."\n". |
| 91 | " comp_uri = \"".$base_uri."src/compose.php?newmessage=1\";\n". |
| 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". |
| 100 | ",scrollbars=yes,resizable=yes\");\n". |
| 101 | "}\n"; |
| 102 | |
| 103 | $js .= "// -->\n". |
| 104 | "</script>\n"; |
| 105 | displayHtmlHeader ('Squirrelmail', $js); |
| 106 | } |
| 107 | displayHtmlHeader(); |
| 108 | $onload = $xtra; |
| 109 | break; |
| 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 | |
| 139 | default: |
| 140 | $js = '<script language="JavaScript" type="text/javascript">' . |
| 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". |
| 160 | "$xtra\n". |
| 161 | "}\n"; |
| 162 | |
| 163 | if ($compose_new_win == '1') { |
| 164 | if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) { |
| 165 | $compose_width = '640'; |
| 166 | } |
| 167 | if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) { |
| 168 | $compose_height = '550'; |
| 169 | } |
| 170 | $js .= "function comp_in_new(new_mes, comp_uri) {\n". |
| 171 | ' if (new_mes) { '."\n". |
| 172 | " comp_uri = \"".$base_uri."src/compose.php?newmessage=1\";\n". |
| 173 | ' } else { '."\n". |
| 174 | " if (comp_uri =='') {\n". |
| 175 | ' comp_uri = "'.$base_uri.$compose_uri."\";\n". |
| 176 | ' }'. "\n". |
| 177 | ' }'. "\n". |
| 178 | ' var newwin = window.open(comp_uri' . |
| 179 | ', "_blank", |
| 180 | "width='.$compose_width.",height=$compose_height". |
| 181 | ",scrollbars=yes,resizable=yes\");\n". |
| 182 | "}\n"; |
| 183 | } |
| 184 | $js .= "// -->\n". |
| 185 | "</script>\n"; |
| 186 | $onload = "onLoad=\"checkForm();\""; |
| 187 | displayHtmlHeader ('Squirrelmail', $js); |
| 188 | break; |
| 189 | |
| 190 | } |
| 191 | |
| 192 | echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n"; |
| 193 | /** Here is the header and wrapping table **/ |
| 194 | $shortBoxName = imap_utf7_decode_local( |
| 195 | readShortMailboxName($mailbox, $delimiter)); |
| 196 | if ( $shortBoxName == 'INBOX' ) { |
| 197 | $shortBoxName = _("INBOX"); |
| 198 | } |
| 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"; |
| 203 | if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) { |
| 204 | echo ' ' . _("Current Folder") . ": <b>$shortBoxName </b>\n"; |
| 205 | } else { |
| 206 | echo ' '; |
| 207 | } |
| 208 | echo " </td>\n" |
| 209 | . html_tag( 'td', '', 'right' ) ."<b>\n"; |
| 210 | displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top); |
| 211 | echo "</b></td>\n" |
| 212 | . " </tr>\n" |
| 213 | . html_tag( 'tr', '', '', $color[4] ) ."\n" |
| 214 | . html_tag( 'td', '', 'left' ) ."\n"; |
| 215 | $urlMailbox = urlencode($mailbox); |
| 216 | if ($compose_new_win == '1') { |
| 217 | echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(true,'')\">". _("Compose"). '</a>'; |
| 218 | } |
| 219 | else { |
| 220 | displayInternalLink ("src/compose.php?mailbox=$urlMailbox", _("Compose"), 'right'); |
| 221 | } |
| 222 | echo " \n"; |
| 223 | displayInternalLink ("src/addressbook.php", _("Addresses"), 'right'); |
| 224 | echo " \n"; |
| 225 | displayInternalLink ("src/folders.php", _("Folders"), 'right'); |
| 226 | echo " \n"; |
| 227 | displayInternalLink ("src/options.php", _("Options"), 'right'); |
| 228 | echo " \n"; |
| 229 | displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"), 'right'); |
| 230 | echo " \n"; |
| 231 | displayInternalLink ("src/help.php", _("Help"), 'right'); |
| 232 | echo " \n"; |
| 233 | |
| 234 | do_hook("menuline"); |
| 235 | |
| 236 | echo " </td>\n" |
| 237 | . html_tag( 'td', '', 'right' ) ."\n"; |
| 238 | echo ($hide_sm_attributions ? ' ' : |
| 239 | '<a href="http://www.squirrelmail.org/" target="_blank">SquirrelMail</a>'); |
| 240 | echo "</td>\n". |
| 241 | " </tr>\n". |
| 242 | "</table>\n\n"; |
| 243 | } |
| 244 | |
| 245 | /* blatently copied/truncated/modified from the above function */ |
| 246 | function compose_Header($color, $mailbox) { |
| 247 | |
| 248 | global $delimiter, $hide_sm_attributions, $base_uri, $PHP_SELF, $frame_top, $compose_new_win; |
| 249 | |
| 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();\""; |
| 263 | displayHtmlHeader (_("Compose")); |
| 264 | break; |
| 265 | default: |
| 266 | $js = '<script language="JavaScript" type="text/javascript">' . |
| 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"; |
| 287 | $js .= "// -->\n". |
| 288 | "</script>\n"; |
| 289 | $onload = "onLoad=\"checkForm();\""; |
| 290 | displayHtmlHeader (_("Compose"), $js); |
| 291 | break; |
| 292 | |
| 293 | } |
| 294 | |
| 295 | echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n"; |
| 296 | } |
| 297 | |
| 298 | function 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 | |
| 309 | function 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 | |
| 345 | function 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 | |
| 359 | function 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 .' ',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 | |
| 420 | function 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('',' '); |
| 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 | |
| 499 | ?> |