6 * Prints the page header (duh)
8 * @copyright © 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @package squirrelmail
14 /** Include required files from SM */
15 include_once(SM_PATH
. 'functions/imap_mailbox.php');
18 * Output a SquirrelMail page header, from <!doctype> to </head>
19 * Always set up the language before calling these functions.
21 * Since 1.5.1 function sends http headers. Function should be called
22 * before any output is started.
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
26 * @param bool frames generate html frameset doctype (since 1.5.1)
29 function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE, $frames = FALSE ) {
30 global $squirrelmail_language, $sTemplateID, $oErrorHandler, $oTemplate;
32 if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
) ) {
35 global $theme_css, $custom_css, $pageheader_sent, $theme, $theme_default, $text_direction,
36 $default_fontset, $chosen_fontset, $default_fontsize, $chosen_fontsize, $chosen_theme;
38 /* add no cache headers here */
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)
43 $oTemplate->assign('frames', $frames);
44 $oTemplate->assign('lang', $squirrelmail_language);
48 $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\">\n";
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');
54 $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
55 $aUserStyles = array();
56 //FIXME: remove this!!
57 // load custom style sheet (deprecated)
58 if ( ! empty($theme_css) ) {
59 $aUserStyles[] = $theme_css;
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 . '&templateid='.$sTemplateID
67 . (!empty($used_fontset) ?
'&fontset='.$used_fontset : '')
68 . (!empty($used_fontsize) ?
'&fontsize='.$used_fontsize : '')
69 . (!empty($text_direction) ?
'&dir='.$text_direction : '');
70 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
71 //FIXME: only call the next method if language is right-to-left!
72 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
74 if ($squirrelmail_language == 'ja_JP') {
76 * force correct detection of charset, when browser does not follow
77 * http content-type and tries to detect charset from page content.
78 * Shooting of browser's creator can't be implemented in php.
79 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
80 * recommendations and switch to unicode.
82 $header_tags .= "<!-- \xfd\xfe -->\n";
83 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
86 // NOTE! plugins here must assign output to template
87 // and NOT echo anything directly!!
88 do_hook('generic_header');
91 $header_tags .= $xtra;
92 $oTemplate->assign('page_title', $title);
94 /* work around IE6's scrollbar bug */
95 $header_tags .= <<<EOS
97 <style type="text/css">
98 /* avoid stupid IE6 bug with frames and scrollbars */
100 width: expression(document.documentElement.clientWidth - 30);
107 $oTemplate->assign('header_tags', $header_tags);
108 $oTemplate->display('protocol_header.tpl');
110 /* this is used to check elsewhere whether we should call this function */
111 $pageheader_sent = TRUE;
112 if (isset($oErrorHandler)) {
113 $oErrorHandler->HeaderSent();
119 * Given a path to a SquirrelMail file, return a HTML link to it
121 * @param string path the SquirrelMail file to link to
122 * @param string text the link text
123 * @param string target the target frame for this link
125 function makeInternalLink($path, $text, $target='') {
127 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
129 $target = " target=\"$target\"";
132 // This is an inefficient hook and is only used by
133 // one plugin that still needs to patch this code,
134 // plus if we are templat-izing SM, visual hooks
135 // are not needed. However, I am leaving the code
136 // here just in case we find a good (non-visual?)
137 // use for the internal_link hook.
139 //$hooktext = do_hook_function('internal_link',$text);
140 //if ($hooktext != '')
141 // $text = $hooktext;
143 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
147 * Same as makeInternalLink, but echoes it too
149 function displayInternalLink($path, $text, $target='') {
150 // FIXME: should let the template echo all these kinds of things
151 echo makeInternalLink($path, $text, $target);
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.
159 * @param array color the array of theme colors
160 * @param string mailbox the current mailbox name to display
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
166 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
168 global $reply_focus, $hide_sm_attributions, $frame_top,
169 $provider_name, $provider_uri, $startMessage,
170 $javascript_on, $action, $oTemplate;
172 if (empty($sBodyTagJs)) {
173 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
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();"';
182 $sBodyTagJs = 'onload="checkForm();"';
185 $urlMailbox = urlencode($mailbox);
186 $startMessage = (int)$startMessage;
188 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
190 if (!isset($frame_top)) {
194 if( $javascript_on ||
strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
195 $js_includes = $oTemplate->get_javascript_includes(TRUE);
197 foreach ($js_includes as $js_file) {
198 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
201 $sJsBlock .= "\n<script type=\"text/javascript\">" .
203 $sHeaderJs . "\n\n// -->\n</script>\n";
205 displayHtmlHeader ('SquirrelMail', $sJsBlock);
207 /* do not use JavaScript */
208 displayHtmlHeader ('SquirrelMail');
212 * this explains the imap_mailbox.php dependency. We should instead store
213 * the selected mailbox in the session and fallback to the session var.
215 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
216 readShortMailboxName($mailbox, $delimiter)));
217 if ( $shortBoxName == 'INBOX' ) {
218 $shortBoxName = _("INBOX");
222 if (!$hide_sm_attributions) {
223 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
224 if (empty($provider_uri)) {
225 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
227 if (empty($provider_name)) $provider_name= 'SquirrelMail';
228 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
230 $sm_attributes .= " </td>\n";
233 $oTemplate->assign('body_tag_js', $sBodyTagJs);
234 $oTemplate->assign('shortBoxName', $shortBoxName);
235 $oTemplate->assign('sm_attribute_str', $sm_attributes);
236 $oTemplate->assign('frame_top', $frame_top);
237 $oTemplate->assign('urlMailbox', $urlMailbox);
238 $oTemplate->assign('startMessage', $startMessage);
239 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
240 $oTemplate->display('page_header.tpl');
244 * Blatantly copied/truncated/modified from displayPageHeader.
245 * Outputs a page header specifically for the compose_in_new popup window
247 * @param array color the array of theme colors
248 * @param string mailbox the current mailbox name to display
249 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
250 * @param string sBodyTagJs js events to be inserted in the body tag
253 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
255 global $reply_focus, $javascript_on, $action, $oTemplate;
257 if (empty($sBodyTagJs)) {
258 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
259 if ($reply_focus == 'select')
260 $sBodyTagJs = 'onload="checkForm(\'select\');"';
261 else if ($reply_focus == 'focus')
262 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
263 else if ($reply_focus != 'none')
264 $sBodyTagJs = 'onload="checkForm();"';
267 $sBodyTagJs = 'onload="checkForm();"';
272 * Locate the first displayable form element (only when JavaScript on)
276 $sJsBlock = "\n<script type=\"text/javascript\">" .
278 $sHeaderJs . "\n\n// -->\n</script>\n";
284 $js_includes = $oTemplate->get_javascript_includes(TRUE);
285 foreach ($js_includes as $js_file) {
286 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
289 displayHtmlHeader (_("Compose"), $sJsBlock);
292 displayHtmlHeader(_("Compose"));
295 // FIXME: should let the template echo all these kinds of things
296 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";