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