Work around the fact that /src/style.php depends on a logged in user, thus breaking...
[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 * @param bool style use style.php CSS, default true (since 1.5.1)
35 * @return void
36 */
37 function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE, $frames = FALSE, $style = TRUE ) {
38 global $squirrelmail_language, $sTplDir;
39
40 if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
41 global $base_uri;
42 }
43 global $theme_css, $custom_css, $pageheader_sent,
44 $chosen_fontset, $chosen_fontsize, $chosen_theme;
45
46 /* add no cache headers here */
47 header('Pragma: no-cache'); // http 1.0 (rfc1945)
48 header('Cache-Control: private, no-cache, no-store'); // http 1.1 (rfc2616)
49
50 if ($frames) {
51 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">';
52 } else {
53 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
54 }
55 echo "\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) .
56 "<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n";
57
58
59 $used_theme = basename($chosen_theme,'.php');
60
61 /*
62 * The $style parameter is needed since style.php breaks the login otherwise.
63 * This can be removed when style.php doesn't depend on a logged in user.
64 */
65 if ($style) {
66 /*
67 * Add closing / to link and meta elements only after switching to xhtml 1.0 Transitional.
68 * It is not compatible with html 4.01 Transitional
69 */
70 echo '<link rel="stylesheet" type="text/css" href="'. $base_uri .'src/style.php'
71 .'?fontset='.$chosen_fontset
72 .'&themeid='.$used_theme
73 .(isset($chosen_fontsize) ? '&fontsize='.$chosen_fontsize : '')."\">\n";
74 }
75
76 // load custom style sheet (deprecated)
77 if ( !isset( $theme_css ) || empty($theme_css) ) {
78 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">";
79 }
80
81 if ($squirrelmail_language == 'ja_JP') {
82 /*
83 * force correct detection of charset, when browser does not follow
84 * http content-type and tries to detect charset from page content.
85 * Shooting of browser's creator can't be implemented in php.
86 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
87 * recommendations and switch to unicode.
88 */
89 echo "<!-- \xfd\xfe -->\n";
90 echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
91 }
92 if ($do_hook) {
93 do_hook('generic_header');
94 }
95
96 echo "<title>$title</title>\n$xtra\n";
97
98 /* work around IE6's scrollbar bug */
99 echo <<<ECHO
100 <style type="text/css">
101 <!--
102 /* avoid stupid IE6 bug with frames and scrollbars */
103 body {
104 voice-family: "\"}\"";
105 voice-family: inherit;
106 width: expression(document.documentElement.clientWidth - 30);
107 }
108 -->
109 </style>
110
111 ECHO;
112
113 echo "\n</head>\n\n";
114
115 /* this is used to check elsewhere whether we should call this function */
116 $pageheader_sent = TRUE;
117 }
118
119 /**
120 * Given a path to a SquirrelMail file, return a HTML link to it
121 *
122 * @param string path the SquirrelMail file to link to
123 * @param string text the link text
124 * @param string target the target frame for this link
125 */
126 function makeInternalLink($path, $text, $target='') {
127 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
128 if ($target != '') {
129 $target = " target=\"$target\"";
130 }
131
132 // This is an inefficient hook and is only used by
133 // one plugin that still needs to patch this code,
134 // plus if we are templat-izing SM, visual hooks
135 // are not needed. However, I am leaving the code
136 // here just in case we find a good (non-visual?)
137 // use for the internal_link hook.
138 //
139 //$hooktext = do_hook_function('internal_link',$text);
140 //if ($hooktext != '')
141 // $text = $hooktext;
142
143 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
144 }
145
146 /**
147 * Same as makeInternalLink, but echoes it too
148 */
149 function displayInternalLink($path, $text, $target='') {
150 echo makeInternalLink($path, $text, $target);
151 }
152
153 /**
154 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
155 * including the default menu bar. Uses displayHtmlHeader and takes
156 * JavaScript and locale settings into account.
157 *
158 * @param array color the array of theme colors
159 * @param string mailbox the current mailbox name to display
160 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
161 * @param string sBodyTagJs js events to be inserted in the body tag
162 * @return void
163 */
164
165 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
166
167 global $reply_focus, $hide_sm_attributions, $frame_top,
168 $provider_name, $provider_uri, $startMessage,
169 $javascript_on, $action, $oTemplate;
170
171 if (empty($sBodyTagJs)) {
172 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
173 if ($reply_focus == 'select')
174 $sBodyTagJs = 'onload="checkForm(\'select\');"';
175 else if ($reply_focus == 'focus')
176 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
177 else if ($reply_focus != 'none')
178 $sBodyTagJs = 'onload="checkForm();"';
179 }
180 else
181 $sBodyTagJs = 'onload="checkForm();"';
182 }
183
184 $urlMailbox = urlencode($mailbox);
185 $startMessage = (int)$startMessage;
186
187 $sTplDir = $oTemplate->template_dir;
188
189 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
190
191 if (!isset($frame_top)) {
192 $frame_top = '_top';
193 }
194
195 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
196 $sJsBlock = '<script src="'. $sTplDir. 'js/default.js" type="text/javascript" language="JavaScript"></script>' ."\n";
197 if ($sHeaderJs) {
198 $sJsBlock .= "\n<script language=\"JavaScript\" type=\"text/javascript\">" .
199 "\n<!--\n" .
200 $sHeaderJs . "\n\n// -->\n</script>\n";
201 }
202 displayHtmlHeader ('SquirrelMail', $sJsBlock);
203 } else {
204 /* do not use JavaScript */
205 displayHtmlHeader ('SquirrelMail');
206 $sBodyTagJs = '';
207 }
208
209 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
210 readShortMailboxName($mailbox, $delimiter)));
211 if ( $shortBoxName == 'INBOX' ) {
212 $shortBoxName = _("INBOX");
213 }
214
215 $sm_attributes = '';
216 if (!$hide_sm_attributions) {
217 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
218 if (empty($provider_uri)) {
219 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
220 } else {
221 if (empty($provider_name)) $provider_name= 'SquirrelMail';
222 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
223 }
224 $sm_attributes .= " </td>\n";
225 }
226
227 $oTemplate->assign('body_tag_js', $sBodyTagJs);
228 $oTemplate->assign('shortBoxName', $shortBoxName);
229 $oTemplate->assign('sm_attribute_str', $sm_attributes);
230 $oTemplate->assign('frame_top', $frame_top);
231 $oTemplate->assign('urlMailbox', $urlMailbox);
232 $oTemplate->assign('startMessage', $startMessage);
233 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
234 $oTemplate->display('page_header.tpl');
235 }
236
237 /**
238 * Blatantly copied/truncated/modified from displayPageHeader.
239 * Outputs a page header specifically for the compose_in_new popup window
240 *
241 * @param array color the array of theme colors
242 * @param string mailbox the current mailbox name to display
243 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
244 * @param string sBodyTagJs js events to be inserted in the body tag
245 * @return void
246 */
247 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
248
249 global $reply_focus, $javascript_on, $action;
250
251 if (empty($sBodyTagJs)) {
252 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
253 if ($reply_focus == 'select')
254 $sBodyTagJs = 'onload="checkForm(\'select\');"';
255 else if ($reply_focus == 'focus')
256 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
257 else if ($reply_focus != 'none')
258 $sBodyTagJs = 'onload="checkForm();"';
259 }
260 else
261 $sBodyTagJs = 'onload="checkForm();"';
262 }
263
264
265 /*
266 * Locate the first displayable form element (only when JavaScript on)
267 */
268 if($javascript_on) {
269 if ($sHeaderJs) {
270 $sJsBlock = "\n<script language=\"JavaScript\" type=\"text/javascript\">" .
271 "\n<!--\n" .
272 $sHeaderJs . "\n\n// -->\n</script>\n";
273 } else {
274 $sJsBlock = '';
275 }
276 $sJsBlock .= "\n" . '<script src="'. SM_PATH .'templates/default/js/default.js" type="text/javascript" language="JavaScript"></script>' ."\n";
277 displayHtmlHeader (_("Compose"), $sJsBlock);
278 } else {
279 /* javascript off */
280 displayHtmlHeader(_("Compose"));
281 $onload = '';
282 }
283 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
284 }
285 ?>