squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

page_header.php
Go to the documentation of this file.
1 <?php
2 
15 require_once(SM_PATH . 'functions/strings.php');
16 require_once(SM_PATH . 'functions/html.php');
17 require_once(SM_PATH . 'functions/imap_mailbox.php');
18 require_once(SM_PATH . 'functions/global.php');
19 
20 /* Always set up the language before calling these functions */
21 function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE ) {
23 
24  if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
25  global $base_uri;
26  }
27  global $theme_css, $custom_css, $pageheader_sent;
28 
29  // prevent clickjack attempts
30 // FIXME: should we use DENY instead? We can also make this a configurable value, including giving the admin the option of removing this entirely in case they WANT to be framed by an external domain
31  header('X-Frame-Options: SAMEORIGIN');
32 
33  echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' .
34  "\n\n" . html_tag( 'html' ,'' , '', '', '' ) . "\n<head>\n" .
35  "<meta name=\"robots\" content=\"noindex,nofollow\">\n" .
36  "<meta http-equiv=\"x-dns-prefetch-control\" content=\"off\">\n";
37 
38  // prevent clickjack attempts using JavaScript for browsers that
39  // don't support the X-Frame-Options header...
40  // we check to see if we are *not* the top page, and if not, check
41  // whether or not the top page is in the same domain as we are...
42  // if not, log out immediately -- this is an attempt to do the same
43  // thing that the X-Frame-Options does using JavaScript (never a good
44  // idea to rely on JavaScript-based solutions, though)
45  echo '<script type="text/javascript" language="JavaScript">'
46  . "\n<!--\n"
47  . 'if (self != top) { try { if (document.domain != top.document.domain) {'
48  . ' throw "Clickjacking security violation! Please log out immediately!"; /* this code should never execute - exception should already have been thrown since it\'s a security violation in this case to even try to access top.document.domain (but it\'s left here just to be extra safe) */ } } catch (e) { self.location = "'
49  . sqm_baseuri() . 'src/signout.php"; top.location = "'
50  . sqm_baseuri() . 'src/signout.php" } }'
51  . "\n// -->\n</script>\n";
52 
53  if ( !isset( $custom_css ) || $custom_css == 'none' ) {
54  if ($theme_css != '') {
55  echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">";
56  }
57  } else {
58  echo '<link rel="stylesheet" type="text/css" href="' .
59  $base_uri . 'themes/css/'.$custom_css.'">';
60  }
61 
62  if ($squirrelmail_language == 'ja_JP') {
63  // Why is it added here? Header ('Content-Type:..) is used in i18n.php
64  echo "<!-- \xfd\xfe -->\n";
65  echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
66  }
67 
68  if ($do_hook) {
69  do_hook('generic_header');
70  }
71 
72  echo "\n<title>$title</title>$xtra\n";
73 
74  /* work around IE6's scrollbar bug */
75  echo <<<ECHO
76 <!--[if IE 6]>
77 <style type="text/css">
78 /* avoid stupid IE6 bug with frames and scrollbars */
79 body {
80  width: expression(document.documentElement.clientWidth - 30);
81 }
82 </style>
83 <![endif]-->
84 
85 ECHO;
86 
87  echo "\n</head>\n\n";
88 
89  /* this is used to check elsewhere whether we should call this function */
90  $pageheader_sent = TRUE;
91 }
92 
93 function makeInternalLink($path, $text, $target='') {
94  sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
95  if ($target != '') {
96  $target = " target=\"$target\"";
97  }
98  return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
99 }
100 
101 function displayInternalLink($path, $text, $target='') {
102  echo makeInternalLink($path, $text, $target);
103 }
104 
105 function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
106 
109  $attachemessages, $provider_name, $provider_uri,
111  $startMessage, $org_title;
112 
113  sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION );
114  sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
115  if (!isset($frame_top)) {
116  $frame_top = '_top';
117  }
118 
119  if ($session) {
120  $compose_uri = $base_uri.'src/compose.php?mailbox='.urlencode($mailbox).'&amp;session='."$session";
121  } else {
122  $compose_uri = $base_uri.'src/compose.php?newmessage=1';
123  $session = 0;
124  }
125 
126  // only output JavaScript if actually turned on
127  if($javascript_on || strpos($xtra, 'new_js_autodetect_results.value') ) {
128  if ( !defined('PAGE_NAME') ) define('PAGE_NAME', NULL);
129  switch ( PAGE_NAME ) {
130  case 'read_body':
131  $js ='';
132 
133  // compose in new window code
134  if ($compose_new_win == '1') {
135  if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
136  $compose_width = '640';
137  }
138  if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
139  $compose_height = '550';
140  }
141  $js .= "function comp_in_new(comp_uri) {\n".
142  " if (!comp_uri) {\n".
143  ' comp_uri = "'.$compose_uri."\";\n".
144  ' }'. "\n".
145  ' var newwin = window.open(comp_uri' .
146  ', "_blank",'.
147  '"width='.$compose_width. ',height='.$compose_height.
148  ',scrollbars=yes,resizable=yes,status=yes");'."\n".
149  "}\n\n";
150  }
151 
152  // javascript for sending read receipts
154  $js .= "function sendMDN() {\n".
155  " mdnuri=window.location+'&sendreceipt=1';\n" .
156  " window.location = mdnuri;\n" .
157  "\n}\n\n";
158  }
159 
160  // if any of the above passes, add the JS tags too.
161  if($js) {
162  $js = "\n".'<script language="JavaScript" type="text/javascript">' .
163  "\n<!--\n" . $js . "// -->\n</script>\n";
164  }
165 
167  $onload = $xtra;
168  break;
169  case 'compose':
170  $js = '<script language="JavaScript" type="text/javascript">' .
171  "\n<!--\n" .
172  "var alreadyFocused = false;\n" .
173  "function checkForm() {\n" .
174  "\n if (alreadyFocused) return;\n";
175 
176  global $action, $reply_focus;
177  if (strpos($action, 'reply') !== FALSE && $reply_focus)
178  {
179  if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
180  else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
181  else if ($reply_focus == 'none') $js .= "}\n";
182  }
183  // no reply focus also applies to composing new messages
184  else if ($reply_focus == 'none')
185  {
186  $js .= "}\n";
187  }
188  else
189  $js .= " var f = document.forms.length;\n".
190  " var i = 0;\n".
191  " var pos = -1;\n".
192  " while( pos == -1 && i < f ) {\n".
193  " var e = document.forms[i].elements.length;\n".
194  " var j = 0;\n".
195  " while( pos == -1 && j < e ) {\n".
196  " if ( document.forms[i].elements[j].type == 'text' ) {\n".
197  " pos = j;\n".
198  " }\n".
199  " j++;\n".
200  " }\n".
201  " i++;\n".
202  " }\n".
203  " if( pos >= 0 ) {\n".
204  " document.forms[i-1].elements[pos].focus();\n".
205  " }\n".
206  "}\n";
207 
208  $js .= "// -->\n".
209  "</script>\n";
210  $onload = 'onload="checkForm();"';
212  break;
213 
214  default:
215  $js = '<script language="JavaScript" type="text/javascript">' .
216  "\n<!--\n" .
217  "function checkForm() {\n".
218  " var f = document.forms.length;\n".
219  " var i = 0;\n".
220  " var pos = -1;\n".
221  " while( pos == -1 && i < f ) {\n".
222  " var e = document.forms[i].elements.length;\n".
223  " var j = 0;\n".
224  " while( pos == -1 && j < e ) {\n".
225  " if ( document.forms[i].elements[j].type == 'text' " .
226  " || document.forms[i].elements[j].type == 'password' ) {\n".
227  " pos = j;\n".
228  " }\n".
229  " j++;\n".
230  " }\n".
231  " i++;\n".
232  " }\n".
233  " if( pos >= 0 ) {\n".
234  " document.forms[i-1].elements[pos].focus();\n".
235  " }\n".
236  " $xtra\n".
237  "}\n";
238 
239  if ($compose_new_win == '1') {
240  if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
241  $compose_width = '640';
242  }
243  if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
244  $compose_height = '550';
245  }
246  $js .= "function comp_in_new(comp_uri) {\n".
247  " if (!comp_uri) {\n".
248  ' comp_uri = "'.$compose_uri."\";\n".
249  ' }'. "\n".
250  ' var newwin = window.open(comp_uri' .
251  ', "_blank",'.
252  '"width='.$compose_width. ',height='.$compose_height.
253  ',scrollbars=yes,resizable=yes,status=yes");'."\n".
254  "}\n\n";
255 
256  }
257  $js .= "// -->\n". "</script>\n";
258 
259 
260  $onload = 'onload="checkForm();"';
262  } // end switch module
263  } else {
264  // JavaScript off
266  $onload = '';
267  }
268 
269  echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
271  $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
272  readShortMailboxName($mailbox, $delimiter)));
273  if ( $shortBoxName == 'INBOX' ) {
274  $shortBoxName = _("INBOX");
275  }
276  echo "<a name=\"pagetop\"></a>\n"
277  . html_tag( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
278  . html_tag( 'tr', '', '', $color[9] ) ."\n"
279  . html_tag( 'td', '', 'left' ) ."\n";
280  if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
281  echo ' ' . _("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
282  } else {
283  echo '&nbsp;';
284  }
285  echo " </td>\n"
286  . html_tag( 'td', '', 'right' ) ."<b>\n";
287  displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
288  echo "</b></td>\n"
289  . " </tr>\n"
290  . html_tag( 'tr', '', '', $color[4] ) ."\n"
291  . ($hide_sm_attributions ? html_tag( 'td', '', 'left', '', 'colspan="2"' )
292  : html_tag( 'td', '', 'left' ) )
293  . "\n";
294  $urlMailbox = urlencode($mailbox);
295  $startMessage = (int)$startMessage;
296  echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&amp;startMessage='.$startMessage);
297  echo "&nbsp;&nbsp;\n";
298  displayInternalLink ('src/addressbook.php', _("Addresses"));
299  echo "&nbsp;&nbsp;\n";
300  displayInternalLink ('src/folders.php', _("Folders"));
301  echo "&nbsp;&nbsp;\n";
302  displayInternalLink ('src/options.php', _("Options"));
303  echo "&nbsp;&nbsp;\n";
304  displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"));
305  echo "&nbsp;&nbsp;\n";
306  displayInternalLink ('src/help.php', _("Help"));
307  echo "&nbsp;&nbsp;\n";
308 
309  do_hook('menuline');
310 
311  echo " </td>\n";
312 
314  {
315  echo html_tag( 'td', '', 'right' ) ."\n";
316  if (!isset($provider_uri)) $provider_uri= 'http://squirrelmail.org/';
317  if (!isset($provider_name)) $provider_name= 'SquirrelMail';
318  echo '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>';
319  echo "</td>\n";
320  }
321  echo " </tr>\n".
322  "</table><br>\n\n";
323 }
324 
325 /* blatently copied/truncated/modified from the above function */
327 
328  global $delimiter, $hide_sm_attributions, $base_uri,
330 
331 
332  if (!isset($frame_top)) {
333  $frame_top = '_top';
334  }
335 
336  /*
337  Locate the first displayable form element
338  */
339  if ( !defined('PAGE_NAME') ) define('PAGE_NAME', NULL);
340  switch ( PAGE_NAME ) {
341  case 'search':
342  $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1;
343  $onload = "onload=\"document.forms[$pos].elements[2].focus();\"";
344  displayHtmlHeader (_("Compose"));
345  break;
346  default:
347  $js = '<script language="JavaScript" type="text/javascript">' .
348  "\n<!--\n" .
349  "var alreadyFocused = false;\n" .
350  "function checkForm() {\n" .
351  "\n if (alreadyFocused) return;\n";
352 
353  global $action, $reply_focus;
354  if (strpos($action, 'reply') !== FALSE && $reply_focus)
355  {
356  if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
357  else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
358  else if ($reply_focus == 'none') $js .= "}\n";
359  }
360  // no reply focus also applies to composing new messages
361  else if ($reply_focus == 'none')
362  {
363  $js .= "}\n";
364  }
365  else
366  $js .= "var f = document.forms.length;\n".
367  "var i = 0;\n".
368  "var pos = -1;\n".
369  "while( pos == -1 && i < f ) {\n".
370  "var e = document.forms[i].elements.length;\n".
371  "var j = 0;\n".
372  "while( pos == -1 && j < e ) {\n".
373  "if ( document.forms[i].elements[j].type == 'text' ) {\n".
374  "pos = j;\n".
375  "}\n".
376  "j++;\n".
377  "}\n".
378  "i++;\n".
379  "}\n".
380  "if( pos >= 0 ) {\n".
381  "document.forms[i-1].elements[pos].focus();\n".
382  "}\n".
383  "}\n";
384  $js .= "// -->\n".
385  "</script>\n";
386  $onload = 'onload="checkForm();"';
387  displayHtmlHeader (_("Compose"), $js);
388  break;
389 
390  }
391 
392  echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
393 }
394 
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
PAGE_NAME
const PAGE_NAME
Definition: options.php:17
getPref
getPref($data_dir, $username, $string, $default='')
Definition: db_prefs.php:316
$default_use_mdn
$default_use_mdn
Definition: config_default.php:575
html_tag
html_tag( $tag, $val='', $align='', $bgcolor='', $xtra='')
Definition: html.php:27
$frame_top
$frame_top
Definition: config_default.php:84
$theme_css
$theme_css
Definition: config_default.php:696
$data_dir
$data_dir
Definition: config_default.php:499
SQ_SESSION
const SQ_SESSION
Definition: global.php:18
displayPageHeader
displayPageHeader($color, $mailbox, $xtra='', $session=false)
Definition: page_header.php:105
$mailbox
$mailbox
Definition: options.php:28
sqm_baseuri
sqm_baseuri()
Definition: strings.php:315
$username
global $username
Definition: validate.php:55
do_hook
do_hook($name)
Definition: plugin.php:42
$provider_name
$provider_name
Definition: config_default.php:95
$mdn_user_support
$mdn_user_support
Definition: load_prefs.php:237
$org_title
$org_title
Definition: config_default.php:61
compose_Header
compose_Header($color, $mailbox)
Definition: page_header.php:326
$compose_height
$compose_height
Definition: load_prefs.php:252
makeInternalLink
makeInternalLink($path, $text, $target='')
Definition: page_header.php:93
$custom_css
if(! sqgetGlobalVar('username', $username, SQ_SESSION)) $custom_css
Definition: load_prefs.php:25
makeComposeLink
makeComposeLink($url, $text=null, $target='')
Definition: strings.php:704
$compose_width
$compose_width
Definition: load_prefs.php:253
$provider_uri
$provider_uri
Definition: config_default.php:106
$reply_focus
$reply_focus
Definition: load_prefs.php:164
readShortMailboxName
readShortMailboxName($haystack, $needle)
Definition: strings.php:240
displayHtmlHeader
displayHtmlHeader( $title='SquirrelMail', $xtra='', $do_hook=TRUE)
Definition: page_header.php:21
SM_PATH
const SM_PATH
Definition: decrypt_headers.php:16
imap_utf7_decode_local
imap_utf7_decode_local($s)
Definition: imap_utf7_local.php:88
$action
$action
Definition: options.php:34
_
_($str)
Definition: gettext.php:160
$base_uri
if(!(bool) ini_get('session.use_cookies')||ini_get('session.use_cookies')=='off') $base_uri
Definition: global.php:173
$xtra
for($i=1; $i< $count; $i++) $xtra
Definition: message_details_bottom.php:253
$color
$color
Definition: load_prefs.php:28
$squirrelmail_language
global $squirrelmail_language
Definition: i18n.php:774
NULL
if(!defined('PAGE_NAME')) define('PAGE_NAME' NULL
Definition: validate.php:16
$hide_sm_attributions
$hide_sm_attributions
Definition: config_default.php:567
$compose_new_win
$compose_new_win
Definition: load_prefs.php:251
displayInternalLink
displayInternalLink($path, $text, $target='')
Definition: page_header.php:101
$javascript_on
$javascript_on
Definition: load_prefs.php:270