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