Correct me if I'm wrong (because oddly, this seemed to be working previously for...
[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, $oTemplate;
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 $templatedir=basename($sTplDir);
61 $oTemplate->assign('base_uri',$base_uri);
62 $oTemplate->assign('templatedir',$templatedir);
63 $oTemplate->assign('themeid',$used_theme);
64 $oTemplate->display('stylelink.tpl');
65 echo '<link rel="stylesheet" type="text/css" href="'. $base_uri .'src/style.php'
66 .'?themeid='.$used_theme
67 .'&templatedir='.$templatedir
68 .(!empty($used_fontset) ? '&fontset='.$used_fontset : '')
69 .(!empty($used_fontsize) ? '&fontsize='.$used_fontsize : '')
70 .(!empty($text_direction) ? '&dir='.$text_direction : '')."\">\n";
71 // load custom style sheet (deprecated)
72 if ( ! empty($theme_css) ) {
73 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">\n";
74 }
75
76 if ($squirrelmail_language == 'ja_JP') {
77 /*
78 * force correct detection of charset, when browser does not follow
79 * http content-type and tries to detect charset from page content.
80 * Shooting of browser's creator can't be implemented in php.
81 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
82 * recommendations and switch to unicode.
83 */
84 echo "<!-- \xfd\xfe -->\n";
85 echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
86 }
87 if ($do_hook) {
88 do_hook('generic_header');
89 }
90
91 echo "<title>$title</title>\n$xtra\n";
92
93 /* work around IE6's scrollbar bug */
94 echo <<<ECHO
95 <!--[if IE 6]>
96 <style type="text/css">
97 /* avoid stupid IE6 bug with frames and scrollbars */
98 body {
99 width: expression(document.documentElement.clientWidth - 30);
100 }
101 </style>
102 <![endif]-->
103
104 ECHO;
105
106 echo "\n</head>\n\n";
107
108 /* this is used to check elsewhere whether we should call this function */
109 $pageheader_sent = TRUE;
110 if (isset($oErrorHandler)) {
111 $oErrorHandler->HeaderSent();
112 }
113 }
114
115 /**
116 * Given a path to a SquirrelMail file, return a HTML link to it
117 *
118 * @param string path the SquirrelMail file to link to
119 * @param string text the link text
120 * @param string target the target frame for this link
121 */
122 function makeInternalLink($path, $text, $target='') {
123 global $base_uri;
124 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
125 if ($target != '') {
126 $target = " target=\"$target\"";
127 }
128
129 // This is an inefficient hook and is only used by
130 // one plugin that still needs to patch this code,
131 // plus if we are templat-izing SM, visual hooks
132 // are not needed. However, I am leaving the code
133 // here just in case we find a good (non-visual?)
134 // use for the internal_link hook.
135 //
136 //$hooktext = do_hook_function('internal_link',$text);
137 //if ($hooktext != '')
138 // $text = $hooktext;
139
140 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
141 }
142
143 /**
144 * Same as makeInternalLink, but echoes it too
145 */
146 function displayInternalLink($path, $text, $target='') {
147 echo makeInternalLink($path, $text, $target);
148 }
149
150 /**
151 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
152 * including the default menu bar. Uses displayHtmlHeader and takes
153 * JavaScript and locale settings into account.
154 *
155 * @param array color the array of theme colors
156 * @param string mailbox the current mailbox name to display
157 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
158 * @param string sBodyTagJs js events to be inserted in the body tag
159 * @return void
160 */
161
162 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
163
164 global $reply_focus, $hide_sm_attributions, $frame_top,
165 $provider_name, $provider_uri, $startMessage,
166 $javascript_on, $action, $oTemplate;
167
168 if (empty($sBodyTagJs)) {
169 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
170 if ($reply_focus == 'select')
171 $sBodyTagJs = 'onload="checkForm(\'select\');"';
172 else if ($reply_focus == 'focus')
173 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
174 else if ($reply_focus != 'none')
175 $sBodyTagJs = 'onload="checkForm();"';
176 }
177 else
178 $sBodyTagJs = 'onload="checkForm();"';
179 }
180
181 $urlMailbox = urlencode($mailbox);
182 $startMessage = (int)$startMessage;
183
184 $sTplDir = $oTemplate->template_dir;
185
186 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
187
188 if (!isset($frame_top)) {
189 $frame_top = '_top';
190 }
191
192 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
193 $js_includes = $oTemplate->getJavascriptIncludes();
194 $sJsBlock = '';
195 foreach ($js_includes as $js_file) {
196 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
197 }
198 if ($sHeaderJs) {
199 $sJsBlock .= "\n<script type=\"text/javascript\">" .
200 "\n<!--\n" .
201 $sHeaderJs . "\n\n// -->\n</script>\n";
202 }
203 displayHtmlHeader ('SquirrelMail', $sJsBlock);
204 } else {
205 /* do not use JavaScript */
206 displayHtmlHeader ('SquirrelMail');
207 $sBodyTagJs = '';
208 }
209 /*
210 * this explains the imap_mailbox.php dependency. We should instead store
211 * the selected mailbox in the session and fallback to the session var.
212 */
213 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
214 readShortMailboxName($mailbox, $delimiter)));
215 if ( $shortBoxName == 'INBOX' ) {
216 $shortBoxName = _("INBOX");
217 }
218
219 $sm_attributes = '';
220 if (!$hide_sm_attributions) {
221 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
222 if (empty($provider_uri)) {
223 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
224 } else {
225 if (empty($provider_name)) $provider_name= 'SquirrelMail';
226 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
227 }
228 $sm_attributes .= " </td>\n";
229 }
230
231 $oTemplate->assign('body_tag_js', $sBodyTagJs);
232 $oTemplate->assign('shortBoxName', $shortBoxName);
233 $oTemplate->assign('sm_attribute_str', $sm_attributes);
234 $oTemplate->assign('frame_top', $frame_top);
235 $oTemplate->assign('urlMailbox', $urlMailbox);
236 $oTemplate->assign('startMessage', $startMessage);
237 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
238 $oTemplate->display('page_header.tpl');
239 }
240
241 /**
242 * Blatantly copied/truncated/modified from displayPageHeader.
243 * Outputs a page header specifically for the compose_in_new popup window
244 *
245 * @param array color the array of theme colors
246 * @param string mailbox the current mailbox name to display
247 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
248 * @param string sBodyTagJs js events to be inserted in the body tag
249 * @return void
250 */
251 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
252
253 global $reply_focus, $javascript_on, $action, $oTemplate;
254
255 if (empty($sBodyTagJs)) {
256 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
257 if ($reply_focus == 'select')
258 $sBodyTagJs = 'onload="checkForm(\'select\');"';
259 else if ($reply_focus == 'focus')
260 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
261 else if ($reply_focus != 'none')
262 $sBodyTagJs = 'onload="checkForm();"';
263 }
264 else
265 $sBodyTagJs = 'onload="checkForm();"';
266 }
267
268
269 /*
270 * Locate the first displayable form element (only when JavaScript on)
271 */
272 if($javascript_on) {
273 if ($sHeaderJs) {
274 $sJsBlock = "\n<script type=\"text/javascript\">" .
275 "\n<!--\n" .
276 $sHeaderJs . "\n\n// -->\n</script>\n";
277 } else {
278 $sJsBlock = '';
279 }
280 $sJsBlock .= "\n";
281
282 $js_includes = $oTemplate->getJavascriptIncludes();
283 foreach ($js_includes as $js_file) {
284 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
285 }
286
287 displayHtmlHeader (_("Compose"), $sJsBlock);
288 } else {
289 /* javascript off */
290 displayHtmlHeader(_("Compose"));
291 $onload = '';
292 }
293 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
294 }