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