Add preliminary printerfriendly-through-css feature. This adds a new print.css
[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 *
4b5049de 8 * @copyright &copy; 1999-2007 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
b116fd78 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.
cd81f956 73 if (!empty($used_theme) && $used_theme != 'none') {
83fc5c5e 74 /**
2d2acf5e 75 * All styles (except "none" - ugh) just point to a directory,
76 * so we need to include all .css files in that directory.
83fc5c5e 77 */
2d2acf5e 78//FIXME: rid ourselves of "none" strings! I didn't do it here because I think the problem is that the theme itself should never be "none" (? well, what else would it be? if "none" theme is actually OK, then is there a constant to use below in stead of a hard-coded string?)
79 $styles = $used_theme == 'none' ? array()
80 : list_files($used_theme, '.css');
8757c848 81 foreach ($styles as $sheet) {
82 $aUserStyles[] = $used_theme .'/'.$sheet;
f9376f0b 83 }
deb25c8f 84 }
d6a6f46b 85
86 // 3. src/style.php
87 $aUserStyles[] = $base_uri .'src/style.php?'
b8292491 88 . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
d6a6f46b 89 . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '');
f9376f0b 90
91 // 3.1. Load the stylesheets we have already
b8292491 92 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
6182ab4d 93
d6a6f46b 94 // 4. Optional rtl.css stylesheet
6182ab4d 95 if ($text_direction == 'rtl') {
96 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
97 }
62f7daa5 98
2ad37738 99 // 5. Printer friendly stylesheet
100 $header_tags .= create_css_link($base_uri . 'css/print.css', 'printerfriendly', false, 'print');
101
e842b215 102 if ($squirrelmail_language == 'ja_JP') {
683b7853 103 /*
cbd8c251 104 * force correct detection of charset, when browser does not follow
105 * http content-type and tries to detect charset from page content.
106 * Shooting of browser's creator can't be implemented in php.
107 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
108 * recommendations and switch to unicode.
109 */
b8292491 110 $header_tags .= "<!-- \xfd\xfe -->\n";
b116fd78 111 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp" />' . "\n";
e842b215 112 }
237470b4 113 if ($do_hook) {
ed1c151d 114 // NOTE! plugins here MUST assign output to template
115 // and NOT echo anything directly!! A common
116 // approach is if a plugin decides it needs to
117 // put something at page-top after the standard
118 // SM page header, to dynamically add itself to
119 // the page_header_bottom and/or compose_header_bottom
120 // hooks for the current page request. See
121 // the Sent Confirmation v1.7 or Restrict Senders v1.2
122 // plugins for examples of this approach.
ed1c151d 123 ob_start();
c0071a26 124 $temp = array(&$header_tags);
125 do_hook('generic_header', $temp);
ed1c151d 126 $output = ob_get_contents();
127 ob_end_clean();
128 // plugin authors can debug their errors with one of the following:
129 //sm_print_r($output);
130 //echo $output;
131 if (!empty($output)) trigger_error('A plugin on the "generic_header" hook has attempted to output directly to the browser', E_USER_ERROR);
237470b4 132 }
62f7daa5 133
b8292491 134 $header_tags .= $xtra;
135 $oTemplate->assign('page_title', $title);
5ca4b1ee 136
137 /* work around IE6's scrollbar bug */
b8292491 138 $header_tags .= <<<EOS
292a9c32 139<!--[if IE 6]>
5ca4b1ee 140<style type="text/css">
5fe8257d 141/* avoid stupid IE6 bug with frames and scrollbars */
142body {
5fe8257d 143 width: expression(document.documentElement.clientWidth - 30);
144}
5ca4b1ee 145</style>
292a9c32 146<![endif]-->
5ca4b1ee 147
b8292491 148EOS;
5ca4b1ee 149
4bf6fc19 150 $oTemplate->assign('header_tags', $header_tags);
b8292491 151 $oTemplate->display('protocol_header.tpl');
b6c283c4 152
153 /* this is used to check elsewhere whether we should call this function */
154 $pageheader_sent = TRUE;
81de00c0 155 if (isset($oErrorHandler)) {
e6c4caae 156 $oErrorHandler->HeaderSent();
81de00c0 157 }
b8292491 158
a07cd1a4 159}
160
8b096f0a 161/**
162 * Given a path to a SquirrelMail file, return a HTML link to it
163 *
164 * @param string path the SquirrelMail file to link to
165 * @param string text the link text
166 * @param string target the target frame for this link
167 */
d62c4938 168function makeInternalLink($path, $text, $target='') {
f7b996c3 169 global $base_uri, $oTemplate;
202bcbcc 170// sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
4910106a 171
e50f5ac2 172 // This is an inefficient hook and is only used by
4910106a 173 // one plugin that still needs to patch this code,
e50f5ac2 174 // plus if we are templat-izing SM, visual hooks
175 // are not needed. However, I am leaving the code
176 // here just in case we find a good (non-visual?)
4910106a 177 // use for the internal_link hook.
178 //
d849b570 179 //do_hook('internal_link', $text);
4910106a 180
769a819d 181 return create_hyperlink($base_uri . $path, $text, $target);
d62c4938 182}
183
8b096f0a 184/**
8b096f0a 185 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
186 * including the default menu bar. Uses displayHtmlHeader and takes
187 * JavaScript and locale settings into account.
188 *
189 * @param array color the array of theme colors
190 * @param string mailbox the current mailbox name to display
91c27aee 191 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
192 * @param string sBodyTagJs js events to be inserted in the body tag
8b096f0a 193 * @return void
194 */
715225af 195
876fdb60 196function displayPageHeader($color, $mailbox='', $sHeaderJs='', $sBodyTagJs = '') {
10bf80c0 197
198 global $reply_focus, $hide_sm_attributions, $frame_top,
5fe8257d 199 $provider_name, $provider_uri, $startMessage,
d8ca5ea3 200 $action, $oTemplate, $org_title, $base_uri,
201 $data_dir, $username;
10bf80c0 202
5bcce050 203//FIXME: $sBodyTag should be turned into $sOnload and should only contain the contents of the onload attribute (not the attribute name nor any quotes).... only question is if anyone was using $sBodyTag for anything but onload event handlers? (see function compose_Header() below for how to fix it once we confirm it can be changed)
10bf80c0 204 if (empty($sBodyTagJs)) {
205 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5fe8257d 206 if ($reply_focus == 'select')
207 $sBodyTagJs = 'onload="checkForm(\'select\');"';
208 else if ($reply_focus == 'focus')
209 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
210 else if ($reply_focus != 'none')
211 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 212 }
213 else
5fe8257d 214 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 215 }
216
5fe8257d 217 $startMessage = (int)$startMessage;
218
0365891c 219 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
91c27aee 220
d03f3582 221 if (!isset($frame_top)) {
222 $frame_top = '_top';
223 }
715225af 224
83aff890 225//FIXME: does checkForJavascript() make the 2nd part of the if() below unneccessary??
226 if( checkForJavascript() || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
b8292491 227 $js_includes = $oTemplate->get_javascript_includes(TRUE);
6373ad12 228 $sJsBlock = '';
229 foreach ($js_includes as $js_file) {
230 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
231 }
91c27aee 232 if ($sHeaderJs) {
2c92ea9d 233 $sJsBlock .= "\n<script type=\"text/javascript\">" .
91c27aee 234 "\n<!--\n" .
a3d59ec3 235 $sHeaderJs . "\n\n// -->\n</script>\n";
d62c4938 236 }
e9e5a322 237 displayHtmlHeader ($org_title, $sJsBlock);
5fe8257d 238 } else {
d62c4938 239 /* do not use JavaScript */
e9e5a322 240 displayHtmlHeader ($org_title);
91c27aee 241 $sBodyTagJs = '';
715225af 242 }
d8ca5ea3 243 if ($mailbox) {
244 /*
245 * this explains the imap_mailbox.php dependency. We should instead store
246 * the selected mailbox in the session and fallback to the session var.
247 */
248 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
249 readShortMailboxName($mailbox, $delimiter)));
250 if (getPref($data_dir, $username, 'translate_special_folders')) {
251 $shortBoxName = _($shortBoxName);
252 }
253 $urlMailbox = urlencode($mailbox);
254 } else {
255 $shortBoxName = '';
256 $urlMailbox = '';
7da23762 257 }
0493ed11 258
5810acfa 259 $provider_link = '';
260 if (!empty($provider_uri) && !empty($provider_name) && $provider_name != 'SquirrelMail') {
261 $provider_link = create_hyperlink($provider_uri, $provider_name, '_blank');
99ea51d3 262 }
5fe8257d 263
264 $oTemplate->assign('body_tag_js', $sBodyTagJs);
265 $oTemplate->assign('shortBoxName', $shortBoxName);
4bf6fc19 266 $oTemplate->assign('provider_link', $provider_link);
5fe8257d 267 $oTemplate->assign('frame_top', $frame_top);
268 $oTemplate->assign('urlMailbox', $urlMailbox);
269 $oTemplate->assign('startMessage', $startMessage);
270 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
271 $oTemplate->display('page_header.tpl');
c5634692 272
273 global $null;
274 do_hook('page_header_bottom', $null);
a07cd1a4 275}
2ba13803 276
8b096f0a 277/**
278 * Blatantly copied/truncated/modified from displayPageHeader.
279 * Outputs a page header specifically for the compose_in_new popup window
280 *
281 * @param array color the array of theme colors
282 * @param string mailbox the current mailbox name to display
91c27aee 283 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
5bcce050 284 * @param string sOnload JavaScript code to be added inside the body's onload handler
285 * as of 1.5.2, this replaces $sBodyTagJs argument
8b096f0a 286 * @return void
287 */
5bcce050 288function compose_Header($color, $mailbox, $sHeaderJs='', $sOnload = '') {
10bf80c0 289
83aff890 290 global $reply_focus, $action, $oTemplate;
10bf80c0 291
5bcce050 292 if (empty($sOnload)) {
10bf80c0 293 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5bcce050 294 if ($reply_focus == 'select')
295 $sOnload = 'checkForm(\'select\');';
296 else if ($reply_focus == 'focus')
297 $sOnload = 'checkForm(\'focus\');';
298 else if ($reply_focus != 'none')
299 $sOnload = 'checkForm();';
10bf80c0 300 }
301 else
5bcce050 302 $sOnload = 'checkForm();';
10bf80c0 303 }
304
305
9c3e6cd4 306 /*
d62c4938 307 * Locate the first displayable form element (only when JavaScript on)
308 */
83aff890 309 if(checkForJavascript()) {
91c27aee 310 if ($sHeaderJs) {
2c92ea9d 311 $sJsBlock = "\n<script type=\"text/javascript\">" .
91c27aee 312 "\n<!--\n" .
a3d59ec3 313 $sHeaderJs . "\n\n// -->\n</script>\n";
91c27aee 314 } else {
5fe8257d 315 $sJsBlock = '';
d62c4938 316 }
6373ad12 317 $sJsBlock .= "\n";
318
b8292491 319 $js_includes = $oTemplate->get_javascript_includes(TRUE);
6373ad12 320 foreach ($js_includes as $js_file) {
321 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
322 }
323
91c27aee 324 displayHtmlHeader (_("Compose"), $sJsBlock);
d62c4938 325 } else {
326 /* javascript off */
327 displayHtmlHeader(_("Compose"));
328 $onload = '';
9c3e6cd4 329 }
5bcce050 330
331// FIXME: change the colorization attributes below to a CSS class!
332 $class = '';
333 $aAttribs = array('text' => $color[8], 'bgcolor' => $color[4],
334 'link' => $color[7], 'vlink' => $color[7],
335 'alink' => $color[7]);
ed1c151d 336
337 // this is template-safe (see create_body() function)
5bcce050 338 echo create_body($sOnload, $class, $aAttribs);
339
6f4b6b68 340 global $null;
341 do_hook('compose_header_bottom', $null);
9c3e6cd4 342}