restoring globalization of text alignment vars.
[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 /** @ignore */
15 if (! defined('SM_PATH')) define('SM_PATH','../');
16
17 /** Include required files from SM */
18 require_once(SM_PATH . 'functions/strings.php');
19 require_once(SM_PATH . 'functions/html.php');
20 require_once(SM_PATH . 'functions/imap_mailbox.php');
21 require_once(SM_PATH . 'functions/global.php');
22 include_once(SM_PATH . 'class/template/template.class.php');
23
24 /**
25 * Output a SquirrelMail page header, from <!doctype> to </head>
26 * Always set up the language before calling these functions.
27 *
28 * Since 1.5.1 function sends http headers. Function should be called
29 * before any output is started.
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
33 * @param bool frames generate html frameset doctype (since 1.5.1)
34 * @return void
35 */
36 function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE, $frames = FALSE ) {
37 global $squirrelmail_language, $sTplDir, $oErroHandler;
38
39 if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
40 global $base_uri;
41 }
42 global $theme_css, $custom_css, $pageheader_sent, $theme, $theme_default, $text_direction,
43 $default_fontset, $chosen_fontset, $default_fontsize, $chosen_fontsize, $chosen_theme;
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)
48
49 if ($frames) {
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">';
52 } else {
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">';
55 }
56 echo "\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) .
57 "<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n";
58
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');
62
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 */
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 : '')
71 .(!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '')
72 .(!empty($text_direction) ? '&amp;dir='.$text_direction : '')."\">\n";
73
74
75 // load custom style sheet (deprecated)
76 if ( ! empty($theme_css) ) {
77 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">\n";
78 }
79
80 if ($squirrelmail_language == 'ja_JP') {
81 /*
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 */
88 echo "<!-- \xfd\xfe -->\n";
89 echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
90 }
91 if ($do_hook) {
92 do_hook('generic_header');
93 }
94
95 echo "<title>$title</title>\n$xtra\n";
96
97 /* work around IE6's scrollbar bug */
98 echo <<<ECHO
99 <style type="text/css">
100 <!--
101 /* avoid stupid IE6 bug with frames and scrollbars */
102 body {
103 voice-family: "\"}\"";
104 voice-family: inherit;
105 width: expression(document.documentElement.clientWidth - 30);
106 }
107 -->
108 </style>
109
110 ECHO;
111
112 echo "\n</head>\n\n";
113
114 /* this is used to check elsewhere whether we should call this function */
115 $pageheader_sent = TRUE;
116 if (isset($oErrorHandler)) {
117 $oErrorHander->HeaderSent();
118 }
119 }
120
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 */
128 function makeInternalLink($path, $text, $target='') {
129 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
130 if ($target != '') {
131 $target = " target=\"$target\"";
132 }
133
134 // This is an inefficient hook and is only used by
135 // one plugin that still needs to patch this code,
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?)
139 // use for the internal_link hook.
140 //
141 //$hooktext = do_hook_function('internal_link',$text);
142 //if ($hooktext != '')
143 // $text = $hooktext;
144
145 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
146 }
147
148 /**
149 * Same as makeInternalLink, but echoes it too
150 */
151 function displayInternalLink($path, $text, $target='') {
152 echo makeInternalLink($path, $text, $target);
153 }
154
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
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
164 * @return void
165 */
166
167 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
168
169 global $reply_focus, $hide_sm_attributions, $frame_top,
170 $provider_name, $provider_uri, $startMessage,
171 $javascript_on, $action, $oTemplate;
172
173 if (empty($sBodyTagJs)) {
174 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
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();"';
181 }
182 else
183 $sBodyTagJs = 'onload="checkForm();"';
184 }
185
186 $urlMailbox = urlencode($mailbox);
187 $startMessage = (int)$startMessage;
188
189 $sTplDir = $oTemplate->template_dir;
190
191 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
192
193 if (!isset($frame_top)) {
194 $frame_top = '_top';
195 }
196
197 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
198 $sJsBlock = '<script src="'. $sTplDir. 'js/default.js" type="text/javascript"></script>' ."\n";
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 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
212 readShortMailboxName($mailbox, $delimiter)));
213 if ( $shortBoxName == 'INBOX' ) {
214 $shortBoxName = _("INBOX");
215 }
216
217 $sm_attributes = '';
218 if (!$hide_sm_attributions) {
219 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
220 if (empty($provider_uri)) {
221 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
222 } else {
223 if (empty($provider_name)) $provider_name= 'SquirrelMail';
224 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
225 }
226 $sm_attributes .= " </td>\n";
227 }
228
229 $oTemplate->assign('body_tag_js', $sBodyTagJs);
230 $oTemplate->assign('shortBoxName', $shortBoxName);
231 $oTemplate->assign('sm_attribute_str', $sm_attributes);
232 $oTemplate->assign('frame_top', $frame_top);
233 $oTemplate->assign('urlMailbox', $urlMailbox);
234 $oTemplate->assign('startMessage', $startMessage);
235 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
236 $oTemplate->display('page_header.tpl');
237 }
238
239 /**
240 * Blatantly copied/truncated/modified from displayPageHeader.
241 * Outputs a page header specifically for the compose_in_new popup window
242 *
243 * @param array color the array of theme colors
244 * @param string mailbox the current mailbox name to display
245 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
246 * @param string sBodyTagJs js events to be inserted in the body tag
247 * @return void
248 */
249 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
250
251 global $reply_focus, $javascript_on, $action;
252
253 if (empty($sBodyTagJs)) {
254 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
255 if ($reply_focus == 'select')
256 $sBodyTagJs = 'onload="checkForm(\'select\');"';
257 else if ($reply_focus == 'focus')
258 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
259 else if ($reply_focus != 'none')
260 $sBodyTagJs = 'onload="checkForm();"';
261 }
262 else
263 $sBodyTagJs = 'onload="checkForm();"';
264 }
265
266
267 /*
268 * Locate the first displayable form element (only when JavaScript on)
269 */
270 if($javascript_on) {
271 if ($sHeaderJs) {
272 $sJsBlock = "\n<script type=\"text/javascript\">" .
273 "\n<!--\n" .
274 $sHeaderJs . "\n\n// -->\n</script>\n";
275 } else {
276 $sJsBlock = '';
277 }
278 $sJsBlock .= "\n" . '<script src="'. SM_PATH .'templates/default/js/default.js" type="text/javascript"></script>' ."\n";
279 displayHtmlHeader (_("Compose"), $sJsBlock);
280 } else {
281 /* javascript off */
282 displayHtmlHeader(_("Compose"));
283 $onload = '';
284 }
285 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
286 }
287 ?>