Use checkForJavascript() instead of $javascript_on. Except I did not change mailbox_...
[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 ) {
b8292491 30 global $squirrelmail_language, $sTemplateID, $oErrorHandler, $oTemplate;
692155b7 31
0365891c 32 if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
0b97a708 33 global $base_uri;
34 }
ab034e59 35 global $custom_css, $pageheader_sent, $theme, $theme_default, $text_direction,
acd7fdf2 36 $default_fontset, $chosen_fontset, $default_fontsize, $chosen_fontsize,
37 $chosen_theme, $chosen_theme_path, $user_themes, $user_theme_default;
81132de8 38
39 /* add no cache headers here */
b8292491 40//FIXME: should change all header() calls in SM core to use $oTemplate->header()!!
41 $oTemplate->header('Pragma: no-cache'); // http 1.0 (rfc1945)
42 $oTemplate->header('Cache-Control: private, no-cache, no-store'); // http 1.1 (rfc2616)
2c21ef20 43
b8292491 44 $oTemplate->assign('frames', $frames);
45 $oTemplate->assign('lang', $squirrelmail_language);
46
47 $header_tags = '';
48
49 $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\">\n";
2c21ef20 50
d88941c7 51 $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset);
52 $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize);
8757c848 53 $used_theme = !isset($chosen_theme) && $user_theme_default != 'none' && is_dir($chosen_theme) && is_readable($chosen_theme)? $user_themes[$user_theme_default]['PATH'].'/default.css' : $chosen_theme_path;
acd7fdf2 54
d6a6f46b 55 /**
56 * Stylesheets are loaded in the following order:
57 * 1) All stylesheets provided by the template. Normally, these are
e2048f8e 58 * stylsheets in templates/<template>/css/. This is accomplished by calling
d6a6f46b 59 * $oTemplate->fetch_standard_stylesheet_links().
60 * 2) An optional user-defined stylesheet. This is set in the Display
61 * Preferences.
62 * 3) src/style.php which sets some basic font prefs.
63 * 4) If we are dealing with an RTL language, we load rtl.css from the
64 * template set.
e2048f8e 65 */
66
d6a6f46b 67 // 1. Stylesheets from the template.
b8292491 68 $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
d6a6f46b 69
b8292491 70 $aUserStyles = array();
e2048f8e 71
d6a6f46b 72 // 2. Option user-defined stylesheet from preferences.
f9376f0b 73 if (!empty($used_theme)) {
83fc5c5e 74 /**
8757c848 75 * All styles just point to a directory, so we need to include all .css
76 * files in that directory.
83fc5c5e 77 */
8757c848 78 $styles = list_files($used_theme, '.css');
79 foreach ($styles as $sheet) {
80 $aUserStyles[] = $used_theme .'/'.$sheet;
f9376f0b 81 }
deb25c8f 82 }
d6a6f46b 83
84 // 3. src/style.php
85 $aUserStyles[] = $base_uri .'src/style.php?'
b8292491 86 . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
d6a6f46b 87 . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '');
f9376f0b 88
89 // 3.1. Load the stylesheets we have already
b8292491 90 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
6182ab4d 91
d6a6f46b 92 // 4. Optional rtl.css stylesheet
6182ab4d 93 if ($text_direction == 'rtl') {
94 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
95 }
62f7daa5 96
e842b215 97 if ($squirrelmail_language == 'ja_JP') {
683b7853 98 /*
cbd8c251 99 * force correct detection of charset, when browser does not follow
100 * http content-type and tries to detect charset from page content.
101 * Shooting of browser's creator can't be implemented in php.
102 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
103 * recommendations and switch to unicode.
104 */
b8292491 105 $header_tags .= "<!-- \xfd\xfe -->\n";
106 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
e842b215 107 }
237470b4 108 if ($do_hook) {
b8292491 109 // NOTE! plugins here must assign output to template
110 // and NOT echo anything directly!!
d849b570 111 global $null;
112 do_hook('generic_header', $null);
237470b4 113 }
62f7daa5 114
b8292491 115 $header_tags .= $xtra;
116 $oTemplate->assign('page_title', $title);
5ca4b1ee 117
118 /* work around IE6's scrollbar bug */
b8292491 119 $header_tags .= <<<EOS
292a9c32 120<!--[if IE 6]>
5ca4b1ee 121<style type="text/css">
5fe8257d 122/* avoid stupid IE6 bug with frames and scrollbars */
123body {
5fe8257d 124 width: expression(document.documentElement.clientWidth - 30);
125}
5ca4b1ee 126</style>
292a9c32 127<![endif]-->
5ca4b1ee 128
b8292491 129EOS;
5ca4b1ee 130
b8292491 131 $oTemplate->assign('header_tags', $header_tags);
132 $oTemplate->display('protocol_header.tpl');
b6c283c4 133
134 /* this is used to check elsewhere whether we should call this function */
135 $pageheader_sent = TRUE;
81de00c0 136 if (isset($oErrorHandler)) {
e6c4caae 137 $oErrorHandler->HeaderSent();
81de00c0 138 }
b8292491 139
a07cd1a4 140}
141
8b096f0a 142/**
143 * Given a path to a SquirrelMail file, return a HTML link to it
144 *
145 * @param string path the SquirrelMail file to link to
146 * @param string text the link text
147 * @param string target the target frame for this link
148 */
d62c4938 149function makeInternalLink($path, $text, $target='') {
f7b996c3 150 global $base_uri, $oTemplate;
202bcbcc 151// sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
4910106a 152
e50f5ac2 153 // This is an inefficient hook and is only used by
4910106a 154 // one plugin that still needs to patch this code,
e50f5ac2 155 // plus if we are templat-izing SM, visual hooks
156 // are not needed. However, I am leaving the code
157 // here just in case we find a good (non-visual?)
4910106a 158 // use for the internal_link hook.
159 //
d849b570 160 //do_hook('internal_link', $text);
4910106a 161
769a819d 162 return create_hyperlink($base_uri . $path, $text, $target);
d62c4938 163}
164
8b096f0a 165/**
166 * Same as makeInternalLink, but echoes it too
167 */
d62c4938 168function displayInternalLink($path, $text, $target='') {
b8292491 169// FIXME: should let the template echo all these kinds of things
b26d81e5 170 echo makeInternalLink($path, $text, $target);
a07cd1a4 171}
172
8b096f0a 173/**
174 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
175 * including the default menu bar. Uses displayHtmlHeader and takes
176 * JavaScript and locale settings into account.
177 *
178 * @param array color the array of theme colors
179 * @param string mailbox the current mailbox name to display
91c27aee 180 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
181 * @param string sBodyTagJs js events to be inserted in the body tag
8b096f0a 182 * @return void
183 */
715225af 184
10bf80c0 185function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
186
187 global $reply_focus, $hide_sm_attributions, $frame_top,
5fe8257d 188 $provider_name, $provider_uri, $startMessage,
83aff890 189 $action, $oTemplate;
10bf80c0 190
191 if (empty($sBodyTagJs)) {
192 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5fe8257d 193 if ($reply_focus == 'select')
194 $sBodyTagJs = 'onload="checkForm(\'select\');"';
195 else if ($reply_focus == 'focus')
196 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
197 else if ($reply_focus != 'none')
198 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 199 }
200 else
5fe8257d 201 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 202 }
203
5fe8257d 204 $urlMailbox = urlencode($mailbox);
205 $startMessage = (int)$startMessage;
206
0365891c 207 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
91c27aee 208
d03f3582 209 if (!isset($frame_top)) {
210 $frame_top = '_top';
211 }
715225af 212
83aff890 213//FIXME: does checkForJavascript() make the 2nd part of the if() below unneccessary??
214 if( checkForJavascript() || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
b8292491 215 $js_includes = $oTemplate->get_javascript_includes(TRUE);
6373ad12 216 $sJsBlock = '';
217 foreach ($js_includes as $js_file) {
218 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
219 }
91c27aee 220 if ($sHeaderJs) {
2c92ea9d 221 $sJsBlock .= "\n<script type=\"text/javascript\">" .
91c27aee 222 "\n<!--\n" .
a3d59ec3 223 $sHeaderJs . "\n\n// -->\n</script>\n";
d62c4938 224 }
91c27aee 225 displayHtmlHeader ('SquirrelMail', $sJsBlock);
5fe8257d 226 } else {
d62c4938 227 /* do not use JavaScript */
228 displayHtmlHeader ('SquirrelMail');
91c27aee 229 $sBodyTagJs = '';
715225af 230 }
202bcbcc 231 /*
232 * this explains the imap_mailbox.php dependency. We should instead store
233 * the selected mailbox in the session and fallback to the session var.
234 */
72520f77 235 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
91e0dccc 236 readShortMailboxName($mailbox, $delimiter)));
3b7d68e6 237 if ( $shortBoxName == 'INBOX' ) {
7da23762 238 $shortBoxName = _("INBOX");
239 }
0493ed11 240
5fe8257d 241 $sm_attributes = '';
242 if (!$hide_sm_attributions) {
243 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
8b5c49cd 244 if (empty($provider_uri)) {
5fe8257d 245 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
8b5c49cd 246 } else {
247 if (empty($provider_name)) $provider_name= 'SquirrelMail';
5fe8257d 248 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
8b5c49cd 249 }
5fe8257d 250 $sm_attributes .= " </td>\n";
99ea51d3 251 }
5fe8257d 252
253 $oTemplate->assign('body_tag_js', $sBodyTagJs);
254 $oTemplate->assign('shortBoxName', $shortBoxName);
255 $oTemplate->assign('sm_attribute_str', $sm_attributes);
256 $oTemplate->assign('frame_top', $frame_top);
257 $oTemplate->assign('urlMailbox', $urlMailbox);
258 $oTemplate->assign('startMessage', $startMessage);
259 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
260 $oTemplate->display('page_header.tpl');
a07cd1a4 261}
2ba13803 262
8b096f0a 263/**
264 * Blatantly copied/truncated/modified from displayPageHeader.
265 * Outputs a page header specifically for the compose_in_new popup window
266 *
267 * @param array color the array of theme colors
268 * @param string mailbox the current mailbox name to display
91c27aee 269 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
270 * @param string sBodyTagJs js events to be inserted in the body tag
8b096f0a 271 * @return void
272 */
10bf80c0 273function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
274
83aff890 275 global $reply_focus, $action, $oTemplate;
10bf80c0 276
277 if (empty($sBodyTagJs)) {
278 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5fe8257d 279 if ($reply_focus == 'select')
280 $sBodyTagJs = 'onload="checkForm(\'select\');"';
281 else if ($reply_focus == 'focus')
282 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
283 else if ($reply_focus != 'none')
284 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 285 }
286 else
5fe8257d 287 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 288 }
289
290
9c3e6cd4 291 /*
d62c4938 292 * Locate the first displayable form element (only when JavaScript on)
293 */
83aff890 294 if(checkForJavascript()) {
91c27aee 295 if ($sHeaderJs) {
2c92ea9d 296 $sJsBlock = "\n<script type=\"text/javascript\">" .
91c27aee 297 "\n<!--\n" .
a3d59ec3 298 $sHeaderJs . "\n\n// -->\n</script>\n";
91c27aee 299 } else {
5fe8257d 300 $sJsBlock = '';
d62c4938 301 }
6373ad12 302 $sJsBlock .= "\n";
303
b8292491 304 $js_includes = $oTemplate->get_javascript_includes(TRUE);
6373ad12 305 foreach ($js_includes as $js_file) {
306 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
307 }
308
91c27aee 309 displayHtmlHeader (_("Compose"), $sJsBlock);
d62c4938 310 } else {
311 /* javascript off */
312 displayHtmlHeader(_("Compose"));
313 $onload = '';
9c3e6cd4 314 }
b8292491 315// FIXME: should let the template echo all these kinds of things
91c27aee 316 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
9c3e6cd4 317}