Fix for #1093360.
[squirrelmail.git] / functions / page_header.php
CommitLineData
59177427 1<?php
7350889b 2
35586184 3/**
4 * page_header.php
5 *
35586184 6 * Prints the page header (duh)
7 *
47ccfad4 8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
4b4abf93 9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
31841a9e 10 * @version $Id$
d6c32258 11 * @package squirrelmail
35586184 12 */
13
81132de8 14/** @ignore */
15if (! defined('SM_PATH')) define('SM_PATH','../');
16
d6c32258 17/** Include required files from SM */
b68edc75 18require_once(SM_PATH . 'functions/strings.php');
19require_once(SM_PATH . 'functions/html.php');
20require_once(SM_PATH . 'functions/imap_mailbox.php');
0b97a708 21require_once(SM_PATH . 'functions/global.php');
5fe8257d 22include_once(SM_PATH . 'class/template/template.class.php');
b68edc75 23
d6c32258 24/**
8b096f0a 25 * Output a SquirrelMail page header, from <!doctype> to </head>
26 * Always set up the language before calling these functions.
27 *
81132de8 28 * Since 1.5.1 function sends http headers. Function should be called
29 * before any output is started.
8b096f0a 30 * @param string title the page title, default SquirrelMail.
31 * @param string xtra extra HTML to insert into the header
32 * @param bool do_hook whether to execute hooks, default true
62b9c984 33 * @param bool frames generate html frameset doctype (since 1.5.1)
8b096f0a 34 * @return void
d6c32258 35 */
d88941c7 36function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE, $frames = FALSE ) {
81de00c0 37 global $squirrelmail_language, $sTplDir, $oErroHandler;
692155b7 38
0365891c 39 if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
0b97a708 40 global $base_uri;
41 }
d88941c7 42 global $theme_css, $custom_css, $pageheader_sent, $theme, $theme_default,
43 $default_fontset, $chosen_fontset, $default_fontsize, $chosen_fontsize, $chosen_theme;
81132de8 44
45 /* add no cache headers here */
46 header('Pragma: no-cache'); // http 1.0 (rfc1945)
47 header('Cache-Control: private, no-cache, no-store'); // http 1.1 (rfc2616)
2c21ef20 48
62b9c984 49 if ($frames) {
d88941c7 50 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"'."\n"
51 .' "http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd">';
91e0dccc 52 } else {
d88941c7 53 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"'."\n"
54 .' "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">';
62b9c984 55 }
f9f738dc 56 echo "\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) .
57 "<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n";
2c21ef20 58
d88941c7 59 $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset);
60 $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize);
61 $used_theme = basename((!empty($chosen_theme) ? $chosen_theme : $theme[$theme_default]['PATH']),'.php');
5fe8257d 62
cbd8c251 63 /*
64 * Add closing / to link and meta elements only after switching to xhtml 1.0 Transitional.
65 * It is not compatible with html 4.01 Transitional
66 */
d88941c7 67 echo '<link rel="stylesheet" type="text/css" href="'. $base_uri .'src/style.php'
68 .'?themeid='.$used_theme
69 .'&amp;templateid='.basename($sTplDir)
70 .(!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
71 .(!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '')."\">\n";
72
81132de8 73
74 // load custom style sheet (deprecated)
d88941c7 75 if ( ! empty($theme_css) ) {
76 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">\n";
8f1ba72b 77 }
62f7daa5 78
e842b215 79 if ($squirrelmail_language == 'ja_JP') {
683b7853 80 /*
cbd8c251 81 * force correct detection of charset, when browser does not follow
82 * http content-type and tries to detect charset from page content.
83 * Shooting of browser's creator can't be implemented in php.
84 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
85 * recommendations and switch to unicode.
86 */
e842b215 87 echo "<!-- \xfd\xfe -->\n";
fcae5445 88 echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
e842b215 89 }
237470b4 90 if ($do_hook) {
d68323ff 91 do_hook('generic_header');
237470b4 92 }
62f7daa5 93
f9f738dc 94 echo "<title>$title</title>\n$xtra\n";
5ca4b1ee 95
96 /* work around IE6's scrollbar bug */
97 echo <<<ECHO
98<style type="text/css">
99<!--
5fe8257d 100/* avoid stupid IE6 bug with frames and scrollbars */
101body {
102 voice-family: "\"}\"";
103 voice-family: inherit;
104 width: expression(document.documentElement.clientWidth - 30);
105}
5ca4b1ee 106-->
107</style>
108
109ECHO;
110
111 echo "\n</head>\n\n";
b6c283c4 112
113 /* this is used to check elsewhere whether we should call this function */
114 $pageheader_sent = TRUE;
81de00c0 115 if (isset($oErrorHandler)) {
116 $oErrorHander->HeaderSent();
117 }
a07cd1a4 118}
119
8b096f0a 120/**
121 * Given a path to a SquirrelMail file, return a HTML link to it
122 *
123 * @param string path the SquirrelMail file to link to
124 * @param string text the link text
125 * @param string target the target frame for this link
126 */
d62c4938 127function makeInternalLink($path, $text, $target='') {
0365891c 128 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
dcc1cc82 129 if ($target != '') {
130 $target = " target=\"$target\"";
131 }
4910106a 132
e50f5ac2 133 // This is an inefficient hook and is only used by
4910106a 134 // one plugin that still needs to patch this code,
e50f5ac2 135 // plus if we are templat-izing SM, visual hooks
136 // are not needed. However, I am leaving the code
137 // here just in case we find a good (non-visual?)
4910106a 138 // use for the internal_link hook.
139 //
140 //$hooktext = do_hook_function('internal_link',$text);
141 //if ($hooktext != '')
142 // $text = $hooktext;
143
d62c4938 144 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
145}
146
8b096f0a 147/**
148 * Same as makeInternalLink, but echoes it too
149 */
d62c4938 150function displayInternalLink($path, $text, $target='') {
b26d81e5 151 echo makeInternalLink($path, $text, $target);
a07cd1a4 152}
153
8b096f0a 154/**
155 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
156 * including the default menu bar. Uses displayHtmlHeader and takes
157 * JavaScript and locale settings into account.
158 *
159 * @param array color the array of theme colors
160 * @param string mailbox the current mailbox name to display
91c27aee 161 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
162 * @param string sBodyTagJs js events to be inserted in the body tag
8b096f0a 163 * @return void
164 */
715225af 165
10bf80c0 166function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
167
168 global $reply_focus, $hide_sm_attributions, $frame_top,
5fe8257d 169 $provider_name, $provider_uri, $startMessage,
170 $javascript_on, $action, $oTemplate;
10bf80c0 171
172 if (empty($sBodyTagJs)) {
173 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5fe8257d 174 if ($reply_focus == 'select')
175 $sBodyTagJs = 'onload="checkForm(\'select\');"';
176 else if ($reply_focus == 'focus')
177 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
178 else if ($reply_focus != 'none')
179 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 180 }
181 else
5fe8257d 182 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 183 }
184
5fe8257d 185 $urlMailbox = urlencode($mailbox);
186 $startMessage = (int)$startMessage;
187
188 $sTplDir = $oTemplate->template_dir;
715225af 189
0365891c 190 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
91c27aee 191
d03f3582 192 if (!isset($frame_top)) {
193 $frame_top = '_top';
194 }
715225af 195
c18f58c5 196 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
2c92ea9d 197 $sJsBlock = '<script src="'. $sTplDir. 'js/default.js" type="text/javascript"></script>' ."\n";
91c27aee 198 if ($sHeaderJs) {
2c92ea9d 199 $sJsBlock .= "\n<script type=\"text/javascript\">" .
91c27aee 200 "\n<!--\n" .
a3d59ec3 201 $sHeaderJs . "\n\n// -->\n</script>\n";
d62c4938 202 }
91c27aee 203 displayHtmlHeader ('SquirrelMail', $sJsBlock);
5fe8257d 204 } else {
d62c4938 205 /* do not use JavaScript */
206 displayHtmlHeader ('SquirrelMail');
91c27aee 207 $sBodyTagJs = '';
715225af 208 }
209
72520f77 210 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
91e0dccc 211 readShortMailboxName($mailbox, $delimiter)));
3b7d68e6 212 if ( $shortBoxName == 'INBOX' ) {
7da23762 213 $shortBoxName = _("INBOX");
214 }
0493ed11 215
5fe8257d 216 $sm_attributes = '';
217 if (!$hide_sm_attributions) {
218 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
8b5c49cd 219 if (empty($provider_uri)) {
5fe8257d 220 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
8b5c49cd 221 } else {
222 if (empty($provider_name)) $provider_name= 'SquirrelMail';
5fe8257d 223 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
8b5c49cd 224 }
5fe8257d 225 $sm_attributes .= " </td>\n";
99ea51d3 226 }
5fe8257d 227
228 $oTemplate->assign('body_tag_js', $sBodyTagJs);
229 $oTemplate->assign('shortBoxName', $shortBoxName);
230 $oTemplate->assign('sm_attribute_str', $sm_attributes);
231 $oTemplate->assign('frame_top', $frame_top);
232 $oTemplate->assign('urlMailbox', $urlMailbox);
233 $oTemplate->assign('startMessage', $startMessage);
234 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
235 $oTemplate->display('page_header.tpl');
a07cd1a4 236}
2ba13803 237
8b096f0a 238/**
239 * Blatantly copied/truncated/modified from displayPageHeader.
240 * Outputs a page header specifically for the compose_in_new popup window
241 *
242 * @param array color the array of theme colors
243 * @param string mailbox the current mailbox name to display
91c27aee 244 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
245 * @param string sBodyTagJs js events to be inserted in the body tag
8b096f0a 246 * @return void
247 */
10bf80c0 248function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
249
250 global $reply_focus, $javascript_on, $action;
251
252 if (empty($sBodyTagJs)) {
253 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5fe8257d 254 if ($reply_focus == 'select')
255 $sBodyTagJs = 'onload="checkForm(\'select\');"';
256 else if ($reply_focus == 'focus')
257 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
258 else if ($reply_focus != 'none')
259 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 260 }
261 else
5fe8257d 262 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 263 }
264
265
9c3e6cd4 266 /*
d62c4938 267 * Locate the first displayable form element (only when JavaScript on)
268 */
269 if($javascript_on) {
91c27aee 270 if ($sHeaderJs) {
2c92ea9d 271 $sJsBlock = "\n<script type=\"text/javascript\">" .
91c27aee 272 "\n<!--\n" .
a3d59ec3 273 $sHeaderJs . "\n\n// -->\n</script>\n";
91c27aee 274 } else {
5fe8257d 275 $sJsBlock = '';
d62c4938 276 }
2c92ea9d 277 $sJsBlock .= "\n" . '<script src="'. SM_PATH .'templates/default/js/default.js" type="text/javascript"></script>' ."\n";
91c27aee 278 displayHtmlHeader (_("Compose"), $sJsBlock);
d62c4938 279 } else {
280 /* javascript off */
281 displayHtmlHeader(_("Compose"));
282 $onload = '';
9c3e6cd4 283 }
91c27aee 284 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
9c3e6cd4 285}
cbd8c251 286?>