doctype switched from quirks to standards compliance mode
[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;
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,
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 : '')."\">\n";
72
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 }
116
117 /**
118 * Given a path to a SquirrelMail file, return a HTML link to it
119 *
120 * @param string path the SquirrelMail file to link to
121 * @param string text the link text
122 * @param string target the target frame for this link
123 */
124 function makeInternalLink($path, $text, $target='') {
125 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
126 if ($target != '') {
127 $target = " target=\"$target\"";
128 }
129
130 // This is an inefficient hook and is only used by
131 // one plugin that still needs to patch this code,
132 // plus if we are templat-izing SM, visual hooks
133 // are not needed. However, I am leaving the code
134 // here just in case we find a good (non-visual?)
135 // use for the internal_link hook.
136 //
137 //$hooktext = do_hook_function('internal_link',$text);
138 //if ($hooktext != '')
139 // $text = $hooktext;
140
141 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
142 }
143
144 /**
145 * Same as makeInternalLink, but echoes it too
146 */
147 function displayInternalLink($path, $text, $target='') {
148 echo makeInternalLink($path, $text, $target);
149 }
150
151 /**
152 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
153 * including the default menu bar. Uses displayHtmlHeader and takes
154 * JavaScript and locale settings into account.
155 *
156 * @param array color the array of theme colors
157 * @param string mailbox the current mailbox name to display
158 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
159 * @param string sBodyTagJs js events to be inserted in the body tag
160 * @return void
161 */
162
163 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
164
165 global $reply_focus, $hide_sm_attributions, $frame_top,
166 $provider_name, $provider_uri, $startMessage,
167 $javascript_on, $action, $oTemplate;
168
169 if (empty($sBodyTagJs)) {
170 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
171 if ($reply_focus == 'select')
172 $sBodyTagJs = 'onload="checkForm(\'select\');"';
173 else if ($reply_focus == 'focus')
174 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
175 else if ($reply_focus != 'none')
176 $sBodyTagJs = 'onload="checkForm();"';
177 }
178 else
179 $sBodyTagJs = 'onload="checkForm();"';
180 }
181
182 $urlMailbox = urlencode($mailbox);
183 $startMessage = (int)$startMessage;
184
185 $sTplDir = $oTemplate->template_dir;
186
187 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
188
189 if (!isset($frame_top)) {
190 $frame_top = '_top';
191 }
192
193 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
194 $sJsBlock = '<script src="'. $sTplDir. 'js/default.js" type="text/javascript" language="JavaScript"></script>' ."\n";
195 if ($sHeaderJs) {
196 $sJsBlock .= "\n<script language=\"JavaScript\" type=\"text/javascript\">" .
197 "\n<!--\n" .
198 $sHeaderJs . "\n\n// -->\n</script>\n";
199 }
200 displayHtmlHeader ('SquirrelMail', $sJsBlock);
201 } else {
202 /* do not use JavaScript */
203 displayHtmlHeader ('SquirrelMail');
204 $sBodyTagJs = '';
205 }
206
207 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
208 readShortMailboxName($mailbox, $delimiter)));
209 if ( $shortBoxName == 'INBOX' ) {
210 $shortBoxName = _("INBOX");
211 }
212
213 $sm_attributes = '';
214 if (!$hide_sm_attributions) {
215 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
216 if (empty($provider_uri)) {
217 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
218 } else {
219 if (empty($provider_name)) $provider_name= 'SquirrelMail';
220 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
221 }
222 $sm_attributes .= " </td>\n";
223 }
224
225 $oTemplate->assign('body_tag_js', $sBodyTagJs);
226 $oTemplate->assign('shortBoxName', $shortBoxName);
227 $oTemplate->assign('sm_attribute_str', $sm_attributes);
228 $oTemplate->assign('frame_top', $frame_top);
229 $oTemplate->assign('urlMailbox', $urlMailbox);
230 $oTemplate->assign('startMessage', $startMessage);
231 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
232 $oTemplate->display('page_header.tpl');
233 }
234
235 /**
236 * Blatantly copied/truncated/modified from displayPageHeader.
237 * Outputs a page header specifically for the compose_in_new popup window
238 *
239 * @param array color the array of theme colors
240 * @param string mailbox the current mailbox name to display
241 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
242 * @param string sBodyTagJs js events to be inserted in the body tag
243 * @return void
244 */
245 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
246
247 global $reply_focus, $javascript_on, $action;
248
249 if (empty($sBodyTagJs)) {
250 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
251 if ($reply_focus == 'select')
252 $sBodyTagJs = 'onload="checkForm(\'select\');"';
253 else if ($reply_focus == 'focus')
254 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
255 else if ($reply_focus != 'none')
256 $sBodyTagJs = 'onload="checkForm();"';
257 }
258 else
259 $sBodyTagJs = 'onload="checkForm();"';
260 }
261
262
263 /*
264 * Locate the first displayable form element (only when JavaScript on)
265 */
266 if($javascript_on) {
267 if ($sHeaderJs) {
268 $sJsBlock = "\n<script language=\"JavaScript\" type=\"text/javascript\">" .
269 "\n<!--\n" .
270 $sHeaderJs . "\n\n// -->\n</script>\n";
271 } else {
272 $sJsBlock = '';
273 }
274 $sJsBlock .= "\n" . '<script src="'. SM_PATH .'templates/default/js/default.js" type="text/javascript" language="JavaScript"></script>' ."\n";
275 displayHtmlHeader (_("Compose"), $sJsBlock);
276 } else {
277 /* javascript off */
278 displayHtmlHeader(_("Compose"));
279 $onload = '';
280 }
281 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
282 }
283 ?>