d13bb825f0d65052910930f1ce2875d9733c2cc2
[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 .'&amp;templatedir='.$templatedir
68 .(!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
69 .(!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '')
70 .(!empty($text_direction) ? '&amp;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 //$js_includes = $oTemplate->get_javascript_includes(TRUE);
195 $sJsBlock = '';
196 foreach ($js_includes as $js_file) {
197 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
198 }
199 if ($sHeaderJs) {
200 $sJsBlock .= "\n<script type=\"text/javascript\">" .
201 "\n<!--\n" .
202 $sHeaderJs . "\n\n// -->\n</script>\n";
203 }
204 displayHtmlHeader ('SquirrelMail', $sJsBlock);
205 } else {
206 /* do not use JavaScript */
207 displayHtmlHeader ('SquirrelMail');
208 $sBodyTagJs = '';
209 }
210 /*
211 * this explains the imap_mailbox.php dependency. We should instead store
212 * the selected mailbox in the session and fallback to the session var.
213 */
214 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
215 readShortMailboxName($mailbox, $delimiter)));
216 if ( $shortBoxName == 'INBOX' ) {
217 $shortBoxName = _("INBOX");
218 }
219
220 $sm_attributes = '';
221 if (!$hide_sm_attributions) {
222 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
223 if (empty($provider_uri)) {
224 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
225 } else {
226 if (empty($provider_name)) $provider_name= 'SquirrelMail';
227 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
228 }
229 $sm_attributes .= " </td>\n";
230 }
231
232 $oTemplate->assign('body_tag_js', $sBodyTagJs);
233 $oTemplate->assign('shortBoxName', $shortBoxName);
234 $oTemplate->assign('sm_attribute_str', $sm_attributes);
235 $oTemplate->assign('frame_top', $frame_top);
236 $oTemplate->assign('urlMailbox', $urlMailbox);
237 $oTemplate->assign('startMessage', $startMessage);
238 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
239 $oTemplate->display('page_header.tpl');
240 }
241
242 /**
243 * Blatantly copied/truncated/modified from displayPageHeader.
244 * Outputs a page header specifically for the compose_in_new popup window
245 *
246 * @param array color the array of theme colors
247 * @param string mailbox the current mailbox name to display
248 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
249 * @param string sBodyTagJs js events to be inserted in the body tag
250 * @return void
251 */
252 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
253
254 global $reply_focus, $javascript_on, $action, $oTemplate;
255
256 if (empty($sBodyTagJs)) {
257 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
258 if ($reply_focus == 'select')
259 $sBodyTagJs = 'onload="checkForm(\'select\');"';
260 else if ($reply_focus == 'focus')
261 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
262 else if ($reply_focus != 'none')
263 $sBodyTagJs = 'onload="checkForm();"';
264 }
265 else
266 $sBodyTagJs = 'onload="checkForm();"';
267 }
268
269
270 /*
271 * Locate the first displayable form element (only when JavaScript on)
272 */
273 if($javascript_on) {
274 if ($sHeaderJs) {
275 $sJsBlock = "\n<script type=\"text/javascript\">" .
276 "\n<!--\n" .
277 $sHeaderJs . "\n\n// -->\n</script>\n";
278 } else {
279 $sJsBlock = '';
280 }
281 $sJsBlock .= "\n";
282
283 $js_includes = $oTemplate->getJavascriptIncludes();
284 //$js_includes = $oTemplate->get_javascript_includes(TRUE);
285 foreach ($js_includes as $js_file) {
286 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
287 }
288
289 displayHtmlHeader (_("Compose"), $sJsBlock);
290 } else {
291 /* javascript off */
292 displayHtmlHeader(_("Compose"));
293 $onload = '';
294 }
295 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
296 }