Stupid IE 6 bugs should use stupid IE conditionals that conform to HTML standards...
[squirrelmail.git] / functions / page_header.php
1 <?php
2
3 /**
4 * page_header.php
5 *
6 * Prints the page header (duh)
7 *
8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
13
14 /** Include required files from SM */
15 include_once(SM_PATH . 'functions/imap_mailbox.php');
16
17 /**
18 * Output a SquirrelMail page header, from <!doctype> to </head>
19 * Always set up the language before calling these functions.
20 *
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)
27 * @return void
28 */
29 function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE, $frames = FALSE ) {
30 global $squirrelmail_language, $sTplDir, $oErrorHandler;
31
32 if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
33 global $base_uri;
34 }
35 global $theme_css, $custom_css, $pageheader_sent, $theme, $theme_default, $text_direction,
36 $default_fontset, $chosen_fontset, $default_fontsize, $chosen_fontsize, $chosen_theme;
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)
41
42 if ($frames) {
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">';
45 } else {
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">';
48 }
49 echo "\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) .
50 "<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n";
51
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');
55
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 */
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 : '')
64 .(!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '')
65 .(!empty($text_direction) ? '&amp;dir='.$text_direction : '')."\">\n";
66
67 // load custom style sheet (deprecated)
68 if ( ! empty($theme_css) ) {
69 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">\n";
70 }
71
72 if ($squirrelmail_language == 'ja_JP') {
73 /*
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 */
80 echo "<!-- \xfd\xfe -->\n";
81 echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
82 }
83 if ($do_hook) {
84 do_hook('generic_header');
85 }
86
87 echo "<title>$title</title>\n$xtra\n";
88
89 /* work around IE6's scrollbar bug */
90 echo <<<ECHO
91 <!--[if IE 6]>
92 <style type="text/css">
93 /* avoid stupid IE6 bug with frames and scrollbars */
94 body {
95 width: expression(document.documentElement.clientWidth - 30);
96 }
97 </style>
98 <![endif]-->
99
100 ECHO;
101
102 echo "\n</head>\n\n";
103
104 /* this is used to check elsewhere whether we should call this function */
105 $pageheader_sent = TRUE;
106 if (isset($oErrorHandler)) {
107 $oErrorHandler->HeaderSent();
108 }
109 }
110
111 /**
112 * Given a path to a SquirrelMail file, return a HTML link to it
113 *
114 * @param string path the SquirrelMail file to link to
115 * @param string text the link text
116 * @param string target the target frame for this link
117 */
118 function makeInternalLink($path, $text, $target='') {
119 global $base_uri;
120 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
121 if ($target != '') {
122 $target = " target=\"$target\"";
123 }
124
125 // This is an inefficient hook and is only used by
126 // one plugin that still needs to patch this code,
127 // plus if we are templat-izing SM, visual hooks
128 // are not needed. However, I am leaving the code
129 // here just in case we find a good (non-visual?)
130 // use for the internal_link hook.
131 //
132 //$hooktext = do_hook_function('internal_link',$text);
133 //if ($hooktext != '')
134 // $text = $hooktext;
135
136 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
137 }
138
139 /**
140 * Same as makeInternalLink, but echoes it too
141 */
142 function displayInternalLink($path, $text, $target='') {
143 echo makeInternalLink($path, $text, $target);
144 }
145
146 /**
147 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
148 * including the default menu bar. Uses displayHtmlHeader and takes
149 * JavaScript and locale settings into account.
150 *
151 * @param array color the array of theme colors
152 * @param string mailbox the current mailbox name to display
153 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
154 * @param string sBodyTagJs js events to be inserted in the body tag
155 * @return void
156 */
157
158 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
159
160 global $reply_focus, $hide_sm_attributions, $frame_top,
161 $provider_name, $provider_uri, $startMessage,
162 $javascript_on, $action, $oTemplate;
163
164 if (empty($sBodyTagJs)) {
165 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
166 if ($reply_focus == 'select')
167 $sBodyTagJs = 'onload="checkForm(\'select\');"';
168 else if ($reply_focus == 'focus')
169 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
170 else if ($reply_focus != 'none')
171 $sBodyTagJs = 'onload="checkForm();"';
172 }
173 else
174 $sBodyTagJs = 'onload="checkForm();"';
175 }
176
177 $urlMailbox = urlencode($mailbox);
178 $startMessage = (int)$startMessage;
179
180 $sTplDir = $oTemplate->template_dir;
181
182 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
183
184 if (!isset($frame_top)) {
185 $frame_top = '_top';
186 }
187
188 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
189 $js_includes = $oTemplate->getJavascriptIncludes();
190 $sJsBlock = '';
191 foreach ($js_includes as $js_file) {
192 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
193 }
194 if ($sHeaderJs) {
195 $sJsBlock .= "\n<script type=\"text/javascript\">" .
196 "\n<!--\n" .
197 $sHeaderJs . "\n\n// -->\n</script>\n";
198 }
199 displayHtmlHeader ('SquirrelMail', $sJsBlock);
200 } else {
201 /* do not use JavaScript */
202 displayHtmlHeader ('SquirrelMail');
203 $sBodyTagJs = '';
204 }
205 /*
206 * this explains the imap_mailbox.php dependency. We should instead store
207 * the selected mailbox in the session and fallback to the session var.
208 */
209 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
210 readShortMailboxName($mailbox, $delimiter)));
211 if ( $shortBoxName == 'INBOX' ) {
212 $shortBoxName = _("INBOX");
213 }
214
215 $sm_attributes = '';
216 if (!$hide_sm_attributions) {
217 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
218 if (empty($provider_uri)) {
219 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
220 } else {
221 if (empty($provider_name)) $provider_name= 'SquirrelMail';
222 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
223 }
224 $sm_attributes .= " </td>\n";
225 }
226
227 $oTemplate->assign('body_tag_js', $sBodyTagJs);
228 $oTemplate->assign('shortBoxName', $shortBoxName);
229 $oTemplate->assign('sm_attribute_str', $sm_attributes);
230 $oTemplate->assign('frame_top', $frame_top);
231 $oTemplate->assign('urlMailbox', $urlMailbox);
232 $oTemplate->assign('startMessage', $startMessage);
233 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
234 $oTemplate->display('page_header.tpl');
235 }
236
237 /**
238 * Blatantly copied/truncated/modified from displayPageHeader.
239 * Outputs a page header specifically for the compose_in_new popup window
240 *
241 * @param array color the array of theme colors
242 * @param string mailbox the current mailbox name to display
243 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
244 * @param string sBodyTagJs js events to be inserted in the body tag
245 * @return void
246 */
247 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
248
249 global $reply_focus, $javascript_on, $action, $oTemplate;
250
251 if (empty($sBodyTagJs)) {
252 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
253 if ($reply_focus == 'select')
254 $sBodyTagJs = 'onload="checkForm(\'select\');"';
255 else if ($reply_focus == 'focus')
256 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
257 else if ($reply_focus != 'none')
258 $sBodyTagJs = 'onload="checkForm();"';
259 }
260 else
261 $sBodyTagJs = 'onload="checkForm();"';
262 }
263
264
265 /*
266 * Locate the first displayable form element (only when JavaScript on)
267 */
268 if($javascript_on) {
269 if ($sHeaderJs) {
270 $sJsBlock = "\n<script type=\"text/javascript\">" .
271 "\n<!--\n" .
272 $sHeaderJs . "\n\n// -->\n</script>\n";
273 } else {
274 $sJsBlock = '';
275 }
276 $sJsBlock .= "\n";
277
278 $js_includes = $oTemplate->getJavascriptIncludes();
279 foreach ($js_includes as $js_file) {
280 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
281 }
282
283 displayHtmlHeader (_("Compose"), $sJsBlock);
284 } else {
285 /* javascript off */
286 displayHtmlHeader(_("Compose"));
287 $onload = '';
288 }
289 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
290 }