Adding template for error box.
[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 // load custom style sheet (deprecated)
75 if ( ! empty($theme_css) ) {
76 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">\n";
77 }
78
79 if ($squirrelmail_language == 'ja_JP') {
80 /*
81 * force correct detection of charset, when browser does not follow
82 * http content-type and tries to detect charset from page content.
83 * Shooting of browser's creator can't be implemented in php.
84 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
85 * recommendations and switch to unicode.
86 */
87 echo "<!-- \xfd\xfe -->\n";
88 echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
89 }
90 if ($do_hook) {
91 do_hook('generic_header');
92 }
93
94 echo "<title>$title</title>\n$xtra\n";
95
96 /* work around IE6's scrollbar bug */
97 echo <<<ECHO
98 <style type="text/css">
99 <!--
100 /* avoid stupid IE6 bug with frames and scrollbars */
101 body {
102 voice-family: "\"}\"";
103 voice-family: inherit;
104 width: expression(document.documentElement.clientWidth - 30);
105 }
106 -->
107 </style>
108
109 ECHO;
110
111 echo "\n</head>\n\n";
112
113 /* this is used to check elsewhere whether we should call this function */
114 $pageheader_sent = TRUE;
115 if (isset($oErrorHandler)) {
116 $oErrorHander->HeaderSent();
117 }
118 }
119
120 /**
121 * Given a path to a SquirrelMail file, return a HTML link to it
122 *
123 * @param string path the SquirrelMail file to link to
124 * @param string text the link text
125 * @param string target the target frame for this link
126 */
127 function makeInternalLink($path, $text, $target='') {
128 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
129 if ($target != '') {
130 $target = " target=\"$target\"";
131 }
132
133 // This is an inefficient hook and is only used by
134 // one plugin that still needs to patch this code,
135 // plus if we are templat-izing SM, visual hooks
136 // are not needed. However, I am leaving the code
137 // here just in case we find a good (non-visual?)
138 // use for the internal_link hook.
139 //
140 //$hooktext = do_hook_function('internal_link',$text);
141 //if ($hooktext != '')
142 // $text = $hooktext;
143
144 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
145 }
146
147 /**
148 * Same as makeInternalLink, but echoes it too
149 */
150 function displayInternalLink($path, $text, $target='') {
151 echo makeInternalLink($path, $text, $target);
152 }
153
154 /**
155 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
156 * including the default menu bar. Uses displayHtmlHeader and takes
157 * JavaScript and locale settings into account.
158 *
159 * @param array color the array of theme colors
160 * @param string mailbox the current mailbox name to display
161 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
162 * @param string sBodyTagJs js events to be inserted in the body tag
163 * @return void
164 */
165
166 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
167
168 global $reply_focus, $hide_sm_attributions, $frame_top,
169 $provider_name, $provider_uri, $startMessage,
170 $javascript_on, $action, $oTemplate;
171
172 if (empty($sBodyTagJs)) {
173 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
174 if ($reply_focus == 'select')
175 $sBodyTagJs = 'onload="checkForm(\'select\');"';
176 else if ($reply_focus == 'focus')
177 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
178 else if ($reply_focus != 'none')
179 $sBodyTagJs = 'onload="checkForm();"';
180 }
181 else
182 $sBodyTagJs = 'onload="checkForm();"';
183 }
184
185 $urlMailbox = urlencode($mailbox);
186 $startMessage = (int)$startMessage;
187
188 $sTplDir = $oTemplate->template_dir;
189
190 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
191
192 if (!isset($frame_top)) {
193 $frame_top = '_top';
194 }
195
196 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
197 $js_includes = $oTemplate->getJavascriptIncludes();
198 $sJsBlock = '';
199 foreach ($js_includes as $js_file) {
200 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
201 }
202 if ($sHeaderJs) {
203 $sJsBlock .= "\n<script type=\"text/javascript\">" .
204 "\n<!--\n" .
205 $sHeaderJs . "\n\n// -->\n</script>\n";
206 }
207 displayHtmlHeader ('SquirrelMail', $sJsBlock);
208 } else {
209 /* do not use JavaScript */
210 displayHtmlHeader ('SquirrelMail');
211 $sBodyTagJs = '';
212 }
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 foreach ($js_includes as $js_file) {
285 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
286 }
287
288 displayHtmlHeader (_("Compose"), $sJsBlock);
289 } else {
290 /* javascript off */
291 displayHtmlHeader(_("Compose"));
292 $onload = '';
293 }
294 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
295 }
296 ?>