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