Apply correct stylesheets for RTL languages
[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 }
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 */
b8292491 39//FIXME: should change all header() calls in SM core to use $oTemplate->header()!!
40 $oTemplate->header('Pragma: no-cache'); // http 1.0 (rfc1945)
41 $oTemplate->header('Cache-Control: private, no-cache, no-store'); // http 1.1 (rfc2616)
2c21ef20 42
b8292491 43 $oTemplate->assign('frames', $frames);
44 $oTemplate->assign('lang', $squirrelmail_language);
45
46 $header_tags = '';
47
48 $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\">\n";
2c21ef20 49
d88941c7 50 $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset);
51 $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize);
52 $used_theme = basename((!empty($chosen_theme) ? $chosen_theme : $theme[$theme_default]['PATH']),'.php');
5fe8257d 53
b8292491 54 $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
55 $aUserStyles = array();
56//FIXME: remove this!!
81132de8 57 // load custom style sheet (deprecated)
d88941c7 58 if ( ! empty($theme_css) ) {
b8292491 59 $aUserStyles[] = $theme_css;
8f1ba72b 60 }
b8292491 61// FIXME: the following user pref ("sUserStyle"; rename as necessary) will have to be populated by the display prefs screen from a widget similar to the color themes widget (which it replaces) where its values should be full relative paths (from SM_PATH) to the selected css "themes" (either in template css/alternates dir or SM_PATH/css/alternates dir)
62// FIXME: uhhh, getPref() is not available yet here. (at least on login page) Ugh. Nor has load_prefs been included yet -- how do we fix this?
63// $aUserStyles[] = getPref($data_dir, $username, 'sUserStyle', '');
64 $aUserStyles[] = $base_uri .'src/style.php'
65 . '?themeid='.$used_theme
66 . '&amp;templateid='.$sTemplateID
67 . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
68 . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '')
69 . (!empty($text_direction) ? '&amp;dir='.$text_direction : '');
70 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
6182ab4d 71
72 if ($text_direction == 'rtl') {
73 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
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 */
b8292491 84 $header_tags .= "<!-- \xfd\xfe -->\n";
85 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
e842b215 86 }
237470b4 87 if ($do_hook) {
b8292491 88 // NOTE! plugins here must assign output to template
89 // and NOT echo anything directly!!
d68323ff 90 do_hook('generic_header');
237470b4 91 }
62f7daa5 92
b8292491 93 $header_tags .= $xtra;
94 $oTemplate->assign('page_title', $title);
5ca4b1ee 95
96 /* work around IE6's scrollbar bug */
b8292491 97 $header_tags .= <<<EOS
292a9c32 98<!--[if IE 6]>
5ca4b1ee 99<style type="text/css">
5fe8257d 100/* avoid stupid IE6 bug with frames and scrollbars */
101body {
5fe8257d 102 width: expression(document.documentElement.clientWidth - 30);
103}
5ca4b1ee 104</style>
292a9c32 105<![endif]-->
5ca4b1ee 106
b8292491 107EOS;
5ca4b1ee 108
b8292491 109 $oTemplate->assign('header_tags', $header_tags);
110 $oTemplate->display('protocol_header.tpl');
b6c283c4 111
112 /* this is used to check elsewhere whether we should call this function */
113 $pageheader_sent = TRUE;
81de00c0 114 if (isset($oErrorHandler)) {
e6c4caae 115 $oErrorHandler->HeaderSent();
81de00c0 116 }
b8292491 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='') {
202bcbcc 128 global $base_uri;
129// sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
dcc1cc82 130 if ($target != '') {
131 $target = " target=\"$target\"";
132 }
4910106a 133
e50f5ac2 134 // This is an inefficient hook and is only used by
4910106a 135 // one plugin that still needs to patch this code,
e50f5ac2 136 // plus if we are templat-izing SM, visual hooks
137 // are not needed. However, I am leaving the code
138 // here just in case we find a good (non-visual?)
4910106a 139 // use for the internal_link hook.
140 //
141 //$hooktext = do_hook_function('internal_link',$text);
142 //if ($hooktext != '')
143 // $text = $hooktext;
144
d62c4938 145 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
146}
147
8b096f0a 148/**
149 * Same as makeInternalLink, but echoes it too
150 */
d62c4938 151function displayInternalLink($path, $text, $target='') {
b8292491 152// FIXME: should let the template echo all these kinds of things
b26d81e5 153 echo makeInternalLink($path, $text, $target);
a07cd1a4 154}
155
8b096f0a 156/**
157 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
158 * including the default menu bar. Uses displayHtmlHeader and takes
159 * JavaScript and locale settings into account.
160 *
161 * @param array color the array of theme colors
162 * @param string mailbox the current mailbox name to display
91c27aee 163 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
164 * @param string sBodyTagJs js events to be inserted in the body tag
8b096f0a 165 * @return void
166 */
715225af 167
10bf80c0 168function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
169
170 global $reply_focus, $hide_sm_attributions, $frame_top,
5fe8257d 171 $provider_name, $provider_uri, $startMessage,
172 $javascript_on, $action, $oTemplate;
10bf80c0 173
174 if (empty($sBodyTagJs)) {
175 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5fe8257d 176 if ($reply_focus == 'select')
177 $sBodyTagJs = 'onload="checkForm(\'select\');"';
178 else if ($reply_focus == 'focus')
179 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
180 else if ($reply_focus != 'none')
181 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 182 }
183 else
5fe8257d 184 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 185 }
186
5fe8257d 187 $urlMailbox = urlencode($mailbox);
188 $startMessage = (int)$startMessage;
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') ) {
b8292491 197 $js_includes = $oTemplate->get_javascript_includes(TRUE);
6373ad12 198 $sJsBlock = '';
199 foreach ($js_includes as $js_file) {
200 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
201 }
91c27aee 202 if ($sHeaderJs) {
2c92ea9d 203 $sJsBlock .= "\n<script type=\"text/javascript\">" .
91c27aee 204 "\n<!--\n" .
a3d59ec3 205 $sHeaderJs . "\n\n// -->\n</script>\n";
d62c4938 206 }
91c27aee 207 displayHtmlHeader ('SquirrelMail', $sJsBlock);
5fe8257d 208 } else {
d62c4938 209 /* do not use JavaScript */
210 displayHtmlHeader ('SquirrelMail');
91c27aee 211 $sBodyTagJs = '';
715225af 212 }
202bcbcc 213 /*
214 * this explains the imap_mailbox.php dependency. We should instead store
215 * the selected mailbox in the session and fallback to the session var.
216 */
72520f77 217 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
91e0dccc 218 readShortMailboxName($mailbox, $delimiter)));
3b7d68e6 219 if ( $shortBoxName == 'INBOX' ) {
7da23762 220 $shortBoxName = _("INBOX");
221 }
0493ed11 222
5fe8257d 223 $sm_attributes = '';
224 if (!$hide_sm_attributions) {
225 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
8b5c49cd 226 if (empty($provider_uri)) {
5fe8257d 227 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
8b5c49cd 228 } else {
229 if (empty($provider_name)) $provider_name= 'SquirrelMail';
5fe8257d 230 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
8b5c49cd 231 }
5fe8257d 232 $sm_attributes .= " </td>\n";
99ea51d3 233 }
5fe8257d 234
235 $oTemplate->assign('body_tag_js', $sBodyTagJs);
236 $oTemplate->assign('shortBoxName', $shortBoxName);
237 $oTemplate->assign('sm_attribute_str', $sm_attributes);
238 $oTemplate->assign('frame_top', $frame_top);
239 $oTemplate->assign('urlMailbox', $urlMailbox);
240 $oTemplate->assign('startMessage', $startMessage);
241 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
242 $oTemplate->display('page_header.tpl');
a07cd1a4 243}
2ba13803 244
8b096f0a 245/**
246 * Blatantly copied/truncated/modified from displayPageHeader.
247 * Outputs a page header specifically for the compose_in_new popup window
248 *
249 * @param array color the array of theme colors
250 * @param string mailbox the current mailbox name to display
91c27aee 251 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
252 * @param string sBodyTagJs js events to be inserted in the body tag
8b096f0a 253 * @return void
254 */
10bf80c0 255function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
256
6373ad12 257 global $reply_focus, $javascript_on, $action, $oTemplate;
10bf80c0 258
259 if (empty($sBodyTagJs)) {
260 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5fe8257d 261 if ($reply_focus == 'select')
262 $sBodyTagJs = 'onload="checkForm(\'select\');"';
263 else if ($reply_focus == 'focus')
264 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
265 else if ($reply_focus != 'none')
266 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 267 }
268 else
5fe8257d 269 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 270 }
271
272
9c3e6cd4 273 /*
d62c4938 274 * Locate the first displayable form element (only when JavaScript on)
275 */
276 if($javascript_on) {
91c27aee 277 if ($sHeaderJs) {
2c92ea9d 278 $sJsBlock = "\n<script type=\"text/javascript\">" .
91c27aee 279 "\n<!--\n" .
a3d59ec3 280 $sHeaderJs . "\n\n// -->\n</script>\n";
91c27aee 281 } else {
5fe8257d 282 $sJsBlock = '';
d62c4938 283 }
6373ad12 284 $sJsBlock .= "\n";
285
b8292491 286 $js_includes = $oTemplate->get_javascript_includes(TRUE);
6373ad12 287 foreach ($js_includes as $js_file) {
288 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
289 }
290
91c27aee 291 displayHtmlHeader (_("Compose"), $sJsBlock);
d62c4938 292 } else {
293 /* javascript off */
294 displayHtmlHeader(_("Compose"));
295 $onload = '';
9c3e6cd4 296 }
b8292491 297// FIXME: should let the template echo all these kinds of things
91c27aee 298 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
9c3e6cd4 299}