Only 0 is allowed to not have a type
[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 ) {
e6c4caae 30 global $squirrelmail_language, $sTplDir, $oErrorHandler;
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 */
39 header('Pragma: no-cache'); // http 1.0 (rfc1945)
40 header('Cache-Control: private, no-cache, no-store'); // http 1.1 (rfc2616)
2c21ef20 41
62b9c984 42 if ($frames) {
d88941c7 43 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"'."\n"
44 .' "http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd">';
91e0dccc 45 } else {
d88941c7 46 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"'."\n"
47 .' "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">';
62b9c984 48 }
f9f738dc 49 echo "\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) .
50 "<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n";
2c21ef20 51
d88941c7 52 $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset);
53 $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize);
54 $used_theme = basename((!empty($chosen_theme) ? $chosen_theme : $theme[$theme_default]['PATH']),'.php');
5fe8257d 55
cbd8c251 56 /*
57 * Add closing / to link and meta elements only after switching to xhtml 1.0 Transitional.
58 * It is not compatible with html 4.01 Transitional
59 */
d88941c7 60 echo '<link rel="stylesheet" type="text/css" href="'. $base_uri .'src/style.php'
61 .'?themeid='.$used_theme
62 .'&amp;templateid='.basename($sTplDir)
63 .(!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
f549a706 64 .(!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '')
65 .(!empty($text_direction) ? '&amp;dir='.$text_direction : '')."\">\n";
d88941c7 66
81132de8 67 // load custom style sheet (deprecated)
d88941c7 68 if ( ! empty($theme_css) ) {
69 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">\n";
8f1ba72b 70 }
62f7daa5 71
e842b215 72 if ($squirrelmail_language == 'ja_JP') {
683b7853 73 /*
cbd8c251 74 * force correct detection of charset, when browser does not follow
75 * http content-type and tries to detect charset from page content.
76 * Shooting of browser's creator can't be implemented in php.
77 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
78 * recommendations and switch to unicode.
79 */
e842b215 80 echo "<!-- \xfd\xfe -->\n";
fcae5445 81 echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
e842b215 82 }
237470b4 83 if ($do_hook) {
d68323ff 84 do_hook('generic_header');
237470b4 85 }
62f7daa5 86
f9f738dc 87 echo "<title>$title</title>\n$xtra\n";
5ca4b1ee 88
89 /* work around IE6's scrollbar bug */
90 echo <<<ECHO
91<style type="text/css">
92<!--
5fe8257d 93/* avoid stupid IE6 bug with frames and scrollbars */
94body {
95 voice-family: "\"}\"";
96 voice-family: inherit;
97 width: expression(document.documentElement.clientWidth - 30);
98}
5ca4b1ee 99-->
100</style>
101
102ECHO;
103
104 echo "\n</head>\n\n";
b6c283c4 105
106 /* this is used to check elsewhere whether we should call this function */
107 $pageheader_sent = TRUE;
81de00c0 108 if (isset($oErrorHandler)) {
e6c4caae 109 $oErrorHandler->HeaderSent();
81de00c0 110 }
a07cd1a4 111}
112
8b096f0a 113/**
114 * Given a path to a SquirrelMail file, return a HTML link to it
115 *
116 * @param string path the SquirrelMail file to link to
117 * @param string text the link text
118 * @param string target the target frame for this link
119 */
d62c4938 120function makeInternalLink($path, $text, $target='') {
202bcbcc 121 global $base_uri;
122// sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
dcc1cc82 123 if ($target != '') {
124 $target = " target=\"$target\"";
125 }
4910106a 126
e50f5ac2 127 // This is an inefficient hook and is only used by
4910106a 128 // one plugin that still needs to patch this code,
e50f5ac2 129 // plus if we are templat-izing SM, visual hooks
130 // are not needed. However, I am leaving the code
131 // here just in case we find a good (non-visual?)
4910106a 132 // use for the internal_link hook.
133 //
134 //$hooktext = do_hook_function('internal_link',$text);
135 //if ($hooktext != '')
136 // $text = $hooktext;
137
d62c4938 138 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
139}
140
8b096f0a 141/**
142 * Same as makeInternalLink, but echoes it too
143 */
d62c4938 144function displayInternalLink($path, $text, $target='') {
b26d81e5 145 echo makeInternalLink($path, $text, $target);
a07cd1a4 146}
147
8b096f0a 148/**
149 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
150 * including the default menu bar. Uses displayHtmlHeader and takes
151 * JavaScript and locale settings into account.
152 *
153 * @param array color the array of theme colors
154 * @param string mailbox the current mailbox name to display
91c27aee 155 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
156 * @param string sBodyTagJs js events to be inserted in the body tag
8b096f0a 157 * @return void
158 */
715225af 159
10bf80c0 160function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
161
162 global $reply_focus, $hide_sm_attributions, $frame_top,
5fe8257d 163 $provider_name, $provider_uri, $startMessage,
164 $javascript_on, $action, $oTemplate;
10bf80c0 165
166 if (empty($sBodyTagJs)) {
167 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5fe8257d 168 if ($reply_focus == 'select')
169 $sBodyTagJs = 'onload="checkForm(\'select\');"';
170 else if ($reply_focus == 'focus')
171 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
172 else if ($reply_focus != 'none')
173 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 174 }
175 else
5fe8257d 176 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 177 }
178
5fe8257d 179 $urlMailbox = urlencode($mailbox);
180 $startMessage = (int)$startMessage;
181
182 $sTplDir = $oTemplate->template_dir;
715225af 183
0365891c 184 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
91c27aee 185
d03f3582 186 if (!isset($frame_top)) {
187 $frame_top = '_top';
188 }
715225af 189
c18f58c5 190 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
6373ad12 191 $js_includes = $oTemplate->getJavascriptIncludes();
192 $sJsBlock = '';
193 foreach ($js_includes as $js_file) {
194 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
195 }
91c27aee 196 if ($sHeaderJs) {
2c92ea9d 197 $sJsBlock .= "\n<script type=\"text/javascript\">" .
91c27aee 198 "\n<!--\n" .
a3d59ec3 199 $sHeaderJs . "\n\n// -->\n</script>\n";
d62c4938 200 }
91c27aee 201 displayHtmlHeader ('SquirrelMail', $sJsBlock);
5fe8257d 202 } else {
d62c4938 203 /* do not use JavaScript */
204 displayHtmlHeader ('SquirrelMail');
91c27aee 205 $sBodyTagJs = '';
715225af 206 }
202bcbcc 207 /*
208 * this explains the imap_mailbox.php dependency. We should instead store
209 * the selected mailbox in the session and fallback to the session var.
210 */
72520f77 211 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
91e0dccc 212 readShortMailboxName($mailbox, $delimiter)));
3b7d68e6 213 if ( $shortBoxName == 'INBOX' ) {
7da23762 214 $shortBoxName = _("INBOX");
215 }
0493ed11 216
5fe8257d 217 $sm_attributes = '';
218 if (!$hide_sm_attributions) {
219 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
8b5c49cd 220 if (empty($provider_uri)) {
5fe8257d 221 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
8b5c49cd 222 } else {
223 if (empty($provider_name)) $provider_name= 'SquirrelMail';
5fe8257d 224 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
8b5c49cd 225 }
5fe8257d 226 $sm_attributes .= " </td>\n";
99ea51d3 227 }
5fe8257d 228
229 $oTemplate->assign('body_tag_js', $sBodyTagJs);
230 $oTemplate->assign('shortBoxName', $shortBoxName);
231 $oTemplate->assign('sm_attribute_str', $sm_attributes);
232 $oTemplate->assign('frame_top', $frame_top);
233 $oTemplate->assign('urlMailbox', $urlMailbox);
234 $oTemplate->assign('startMessage', $startMessage);
235 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
236 $oTemplate->display('page_header.tpl');
a07cd1a4 237}
2ba13803 238
8b096f0a 239/**
240 * Blatantly copied/truncated/modified from displayPageHeader.
241 * Outputs a page header specifically for the compose_in_new popup window
242 *
243 * @param array color the array of theme colors
244 * @param string mailbox the current mailbox name to display
91c27aee 245 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
246 * @param string sBodyTagJs js events to be inserted in the body tag
8b096f0a 247 * @return void
248 */
10bf80c0 249function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
250
6373ad12 251 global $reply_focus, $javascript_on, $action, $oTemplate;
10bf80c0 252
253 if (empty($sBodyTagJs)) {
254 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5fe8257d 255 if ($reply_focus == 'select')
256 $sBodyTagJs = 'onload="checkForm(\'select\');"';
257 else if ($reply_focus == 'focus')
258 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
259 else if ($reply_focus != 'none')
260 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 261 }
262 else
5fe8257d 263 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 264 }
265
266
9c3e6cd4 267 /*
d62c4938 268 * Locate the first displayable form element (only when JavaScript on)
269 */
270 if($javascript_on) {
91c27aee 271 if ($sHeaderJs) {
2c92ea9d 272 $sJsBlock = "\n<script type=\"text/javascript\">" .
91c27aee 273 "\n<!--\n" .
a3d59ec3 274 $sHeaderJs . "\n\n// -->\n</script>\n";
91c27aee 275 } else {
5fe8257d 276 $sJsBlock = '';
d62c4938 277 }
6373ad12 278 $sJsBlock .= "\n";
279
280 $js_includes = $oTemplate->getJavascriptIncludes();
6373ad12 281 foreach ($js_includes as $js_file) {
282 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
283 }
284
91c27aee 285 displayHtmlHeader (_("Compose"), $sJsBlock);
d62c4938 286 } else {
287 /* javascript off */
288 displayHtmlHeader(_("Compose"));
289 $onload = '';
9c3e6cd4 290 }
91c27aee 291 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
9c3e6cd4 292}