Fix reply indentation. It was an ordinary typo ;)
[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);
71//FIXME: only call the next method if language is right-to-left!
72 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
62f7daa5 73
e842b215 74 if ($squirrelmail_language == 'ja_JP') {
683b7853 75 /*
cbd8c251 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.
81 */
b8292491 82 $header_tags .= "<!-- \xfd\xfe -->\n";
83 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
e842b215 84 }
237470b4 85 if ($do_hook) {
b8292491 86 // NOTE! plugins here must assign output to template
87 // and NOT echo anything directly!!
d68323ff 88 do_hook('generic_header');
237470b4 89 }
62f7daa5 90
b8292491 91 $header_tags .= $xtra;
92 $oTemplate->assign('page_title', $title);
5ca4b1ee 93
94 /* work around IE6's scrollbar bug */
b8292491 95 $header_tags .= <<<EOS
292a9c32 96<!--[if IE 6]>
5ca4b1ee 97<style type="text/css">
5fe8257d 98/* avoid stupid IE6 bug with frames and scrollbars */
99body {
5fe8257d 100 width: expression(document.documentElement.clientWidth - 30);
101}
5ca4b1ee 102</style>
292a9c32 103<![endif]-->
5ca4b1ee 104
b8292491 105EOS;
5ca4b1ee 106
b8292491 107 $oTemplate->assign('header_tags', $header_tags);
108 $oTemplate->display('protocol_header.tpl');
b6c283c4 109
110 /* this is used to check elsewhere whether we should call this function */
111 $pageheader_sent = TRUE;
81de00c0 112 if (isset($oErrorHandler)) {
e6c4caae 113 $oErrorHandler->HeaderSent();
81de00c0 114 }
b8292491 115
a07cd1a4 116}
117
8b096f0a 118/**
119 * Given a path to a SquirrelMail file, return a HTML link to it
120 *
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
124 */
d62c4938 125function makeInternalLink($path, $text, $target='') {
202bcbcc 126 global $base_uri;
127// sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
dcc1cc82 128 if ($target != '') {
129 $target = " target=\"$target\"";
130 }
4910106a 131
e50f5ac2 132 // This is an inefficient hook and is only used by
4910106a 133 // one plugin that still needs to patch this code,
e50f5ac2 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?)
4910106a 137 // use for the internal_link hook.
138 //
139 //$hooktext = do_hook_function('internal_link',$text);
140 //if ($hooktext != '')
141 // $text = $hooktext;
142
d62c4938 143 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
144}
145
8b096f0a 146/**
147 * Same as makeInternalLink, but echoes it too
148 */
d62c4938 149function displayInternalLink($path, $text, $target='') {
b8292491 150// FIXME: should let the template echo all these kinds of things
b26d81e5 151 echo makeInternalLink($path, $text, $target);
a07cd1a4 152}
153
8b096f0a 154/**
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.
158 *
159 * @param array color the array of theme colors
160 * @param string mailbox the current mailbox name to display
91c27aee 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
8b096f0a 163 * @return void
164 */
715225af 165
10bf80c0 166function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
167
168 global $reply_focus, $hide_sm_attributions, $frame_top,
5fe8257d 169 $provider_name, $provider_uri, $startMessage,
170 $javascript_on, $action, $oTemplate;
10bf80c0 171
172 if (empty($sBodyTagJs)) {
173 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5fe8257d 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();"';
10bf80c0 180 }
181 else
5fe8257d 182 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 183 }
184
5fe8257d 185 $urlMailbox = urlencode($mailbox);
186 $startMessage = (int)$startMessage;
187
0365891c 188 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
91c27aee 189
d03f3582 190 if (!isset($frame_top)) {
191 $frame_top = '_top';
192 }
715225af 193
c18f58c5 194 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
b8292491 195 $js_includes = $oTemplate->get_javascript_includes(TRUE);
6373ad12 196 $sJsBlock = '';
197 foreach ($js_includes as $js_file) {
198 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
199 }
91c27aee 200 if ($sHeaderJs) {
2c92ea9d 201 $sJsBlock .= "\n<script type=\"text/javascript\">" .
91c27aee 202 "\n<!--\n" .
a3d59ec3 203 $sHeaderJs . "\n\n// -->\n</script>\n";
d62c4938 204 }
91c27aee 205 displayHtmlHeader ('SquirrelMail', $sJsBlock);
5fe8257d 206 } else {
d62c4938 207 /* do not use JavaScript */
208 displayHtmlHeader ('SquirrelMail');
91c27aee 209 $sBodyTagJs = '';
715225af 210 }
202bcbcc 211 /*
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.
214 */
72520f77 215 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
91e0dccc 216 readShortMailboxName($mailbox, $delimiter)));
3b7d68e6 217 if ( $shortBoxName == 'INBOX' ) {
7da23762 218 $shortBoxName = _("INBOX");
219 }
0493ed11 220
5fe8257d 221 $sm_attributes = '';
222 if (!$hide_sm_attributions) {
223 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
8b5c49cd 224 if (empty($provider_uri)) {
5fe8257d 225 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
8b5c49cd 226 } else {
227 if (empty($provider_name)) $provider_name= 'SquirrelMail';
5fe8257d 228 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
8b5c49cd 229 }
5fe8257d 230 $sm_attributes .= " </td>\n";
99ea51d3 231 }
5fe8257d 232
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');
a07cd1a4 241}
2ba13803 242
8b096f0a 243/**
244 * Blatantly copied/truncated/modified from displayPageHeader.
245 * Outputs a page header specifically for the compose_in_new popup window
246 *
247 * @param array color the array of theme colors
248 * @param string mailbox the current mailbox name to display
91c27aee 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
8b096f0a 251 * @return void
252 */
10bf80c0 253function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
254
6373ad12 255 global $reply_focus, $javascript_on, $action, $oTemplate;
10bf80c0 256
257 if (empty($sBodyTagJs)) {
258 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5fe8257d 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();"';
10bf80c0 265 }
266 else
5fe8257d 267 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 268 }
269
270
9c3e6cd4 271 /*
d62c4938 272 * Locate the first displayable form element (only when JavaScript on)
273 */
274 if($javascript_on) {
91c27aee 275 if ($sHeaderJs) {
2c92ea9d 276 $sJsBlock = "\n<script type=\"text/javascript\">" .
91c27aee 277 "\n<!--\n" .
a3d59ec3 278 $sHeaderJs . "\n\n// -->\n</script>\n";
91c27aee 279 } else {
5fe8257d 280 $sJsBlock = '';
d62c4938 281 }
6373ad12 282 $sJsBlock .= "\n";
283
b8292491 284 $js_includes = $oTemplate->get_javascript_includes(TRUE);
6373ad12 285 foreach ($js_includes as $js_file) {
286 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
287 }
288
91c27aee 289 displayHtmlHeader (_("Compose"), $sJsBlock);
d62c4938 290 } else {
291 /* javascript off */
292 displayHtmlHeader(_("Compose"));
293 $onload = '';
9c3e6cd4 294 }
b8292491 295// FIXME: should let the template echo all these kinds of things
91c27aee 296 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
9c3e6cd4 297}