Move squirrelmail.css into default.css. squirrelmail.css should no longer be needed.
[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 /** Include required files from SM */
15 include_once(SM_PATH . 'functions/imap_mailbox.php');
16
17 /**
18 * Output a SquirrelMail page header, from <!doctype> to </head>
19 * Always set up the language before calling these functions.
20 *
21 * Since 1.5.1 function sends http headers. Function should be called
22 * before any output is started.
23 * @param string title the page title, default SquirrelMail.
24 * @param string xtra extra HTML to insert into the header
25 * @param bool do_hook whether to execute hooks, default true
26 * @param bool frames generate html frameset doctype (since 1.5.1)
27 * @return void
28 */
29 function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE, $frames = FALSE ) {
30 global $squirrelmail_language, $sTemplateID, $oErrorHandler, $oTemplate;
31
32 if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
33 global $base_uri;
34 }
35 global $theme_css, $custom_css, $pageheader_sent, $theme, $theme_default, $text_direction,
36 $default_fontset, $chosen_fontset, $default_fontsize, $chosen_fontsize, $chosen_theme;
37
38 /* add no cache headers here */
39 //FIXME: should change all header() calls in SM core to use $oTemplate->header()!!
40 $oTemplate->header('Pragma: no-cache'); // http 1.0 (rfc1945)
41 $oTemplate->header('Cache-Control: private, no-cache, no-store'); // http 1.1 (rfc2616)
42
43 $oTemplate->assign('frames', $frames);
44 $oTemplate->assign('lang', $squirrelmail_language);
45
46 $header_tags = '';
47
48 $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\">\n";
49
50 $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset);
51 $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize);
52 $used_theme = basename((!empty($chosen_theme) ? $chosen_theme : $theme[$theme_default]['PATH']),'.php');
53
54 /**
55 * Stylesheets are loaded in the following order:
56 * 1) All stylesheets provided by the template. Normally, these are
57 * stylsheets in $sTplDir/css/. This is accomplished by calling
58 * $oTemplate->fetch_standard_stylesheet_links().
59 * 2) An optional user-defined stylesheet. This is set in the Display
60 * Preferences.
61 * 3) src/style.php which sets some basic font prefs.
62 * 4) If we are dealing with an RTL language, we load rtl.css from the
63 * template set.
64 **/
65
66 // 1. Stylesheets from the template.
67 $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
68
69 $aUserStyles = array();
70 // 2. Option user-defined stylesheet from preferences.
71 // FIXME: the following user pref ("sUserStyle"; rename as necessary) will have to be populated by the display prefs screen from a widget similar to the color themes widget (which it replaces) where its values should be full relative paths (from SM_PATH) to the selected css "themes" (either in template css/alternates dir or SM_PATH/css/alternates dir)
72 // FIXME: uhhh, getPref() is not available yet here. (at least on login page) Ugh. Nor has load_prefs been included yet -- how do we fix this?
73 // $aUserStyles[] = getPref($data_dir, $username, 'sUserStyle', '');
74
75 // 3. src/style.php
76 $aUserStyles[] = $base_uri .'src/style.php?'
77 . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
78 . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '');
79 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
80
81 // 4. Optional rtl.css stylesheet
82 if ($text_direction == 'rtl') {
83 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
84 }
85
86 if ($squirrelmail_language == 'ja_JP') {
87 /*
88 * force correct detection of charset, when browser does not follow
89 * http content-type and tries to detect charset from page content.
90 * Shooting of browser's creator can't be implemented in php.
91 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
92 * recommendations and switch to unicode.
93 */
94 $header_tags .= "<!-- \xfd\xfe -->\n";
95 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
96 }
97 if ($do_hook) {
98 // NOTE! plugins here must assign output to template
99 // and NOT echo anything directly!!
100 do_hook('generic_header');
101 }
102
103 $header_tags .= $xtra;
104 $oTemplate->assign('page_title', $title);
105
106 /* work around IE6's scrollbar bug */
107 $header_tags .= <<<EOS
108 <!--[if IE 6]>
109 <style type="text/css">
110 /* avoid stupid IE6 bug with frames and scrollbars */
111 body {
112 width: expression(document.documentElement.clientWidth - 30);
113 }
114 </style>
115 <![endif]-->
116
117 EOS;
118
119 $oTemplate->assign('header_tags', $header_tags);
120 $oTemplate->display('protocol_header.tpl');
121
122 /* this is used to check elsewhere whether we should call this function */
123 $pageheader_sent = TRUE;
124 if (isset($oErrorHandler)) {
125 $oErrorHandler->HeaderSent();
126 }
127
128 }
129
130 /**
131 * Given a path to a SquirrelMail file, return a HTML link to it
132 *
133 * @param string path the SquirrelMail file to link to
134 * @param string text the link text
135 * @param string target the target frame for this link
136 */
137 function makeInternalLink($path, $text, $target='') {
138 global $base_uri;
139 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
140 if ($target != '') {
141 $target = " target=\"$target\"";
142 }
143
144 // This is an inefficient hook and is only used by
145 // one plugin that still needs to patch this code,
146 // plus if we are templat-izing SM, visual hooks
147 // are not needed. However, I am leaving the code
148 // here just in case we find a good (non-visual?)
149 // use for the internal_link hook.
150 //
151 //$hooktext = do_hook_function('internal_link',$text);
152 //if ($hooktext != '')
153 // $text = $hooktext;
154
155 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
156 }
157
158 /**
159 * Same as makeInternalLink, but echoes it too
160 */
161 function displayInternalLink($path, $text, $target='') {
162 // FIXME: should let the template echo all these kinds of things
163 echo makeInternalLink($path, $text, $target);
164 }
165
166 /**
167 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
168 * including the default menu bar. Uses displayHtmlHeader and takes
169 * JavaScript and locale settings into account.
170 *
171 * @param array color the array of theme colors
172 * @param string mailbox the current mailbox name to display
173 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
174 * @param string sBodyTagJs js events to be inserted in the body tag
175 * @return void
176 */
177
178 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
179
180 global $reply_focus, $hide_sm_attributions, $frame_top,
181 $provider_name, $provider_uri, $startMessage,
182 $javascript_on, $action, $oTemplate;
183
184 if (empty($sBodyTagJs)) {
185 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
186 if ($reply_focus == 'select')
187 $sBodyTagJs = 'onload="checkForm(\'select\');"';
188 else if ($reply_focus == 'focus')
189 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
190 else if ($reply_focus != 'none')
191 $sBodyTagJs = 'onload="checkForm();"';
192 }
193 else
194 $sBodyTagJs = 'onload="checkForm();"';
195 }
196
197 $urlMailbox = urlencode($mailbox);
198 $startMessage = (int)$startMessage;
199
200 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
201
202 if (!isset($frame_top)) {
203 $frame_top = '_top';
204 }
205
206 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
207 $js_includes = $oTemplate->get_javascript_includes(TRUE);
208 $sJsBlock = '';
209 foreach ($js_includes as $js_file) {
210 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
211 }
212 if ($sHeaderJs) {
213 $sJsBlock .= "\n<script type=\"text/javascript\">" .
214 "\n<!--\n" .
215 $sHeaderJs . "\n\n// -->\n</script>\n";
216 }
217 displayHtmlHeader ('SquirrelMail', $sJsBlock);
218 } else {
219 /* do not use JavaScript */
220 displayHtmlHeader ('SquirrelMail');
221 $sBodyTagJs = '';
222 }
223 /*
224 * this explains the imap_mailbox.php dependency. We should instead store
225 * the selected mailbox in the session and fallback to the session var.
226 */
227 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
228 readShortMailboxName($mailbox, $delimiter)));
229 if ( $shortBoxName == 'INBOX' ) {
230 $shortBoxName = _("INBOX");
231 }
232
233 $sm_attributes = '';
234 if (!$hide_sm_attributions) {
235 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
236 if (empty($provider_uri)) {
237 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
238 } else {
239 if (empty($provider_name)) $provider_name= 'SquirrelMail';
240 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
241 }
242 $sm_attributes .= " </td>\n";
243 }
244
245 $oTemplate->assign('body_tag_js', $sBodyTagJs);
246 $oTemplate->assign('shortBoxName', $shortBoxName);
247 $oTemplate->assign('sm_attribute_str', $sm_attributes);
248 $oTemplate->assign('frame_top', $frame_top);
249 $oTemplate->assign('urlMailbox', $urlMailbox);
250 $oTemplate->assign('startMessage', $startMessage);
251 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
252 $oTemplate->display('page_header.tpl');
253 }
254
255 /**
256 * Blatantly copied/truncated/modified from displayPageHeader.
257 * Outputs a page header specifically for the compose_in_new popup window
258 *
259 * @param array color the array of theme colors
260 * @param string mailbox the current mailbox name to display
261 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
262 * @param string sBodyTagJs js events to be inserted in the body tag
263 * @return void
264 */
265 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
266
267 global $reply_focus, $javascript_on, $action, $oTemplate;
268
269 if (empty($sBodyTagJs)) {
270 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
271 if ($reply_focus == 'select')
272 $sBodyTagJs = 'onload="checkForm(\'select\');"';
273 else if ($reply_focus == 'focus')
274 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
275 else if ($reply_focus != 'none')
276 $sBodyTagJs = 'onload="checkForm();"';
277 }
278 else
279 $sBodyTagJs = 'onload="checkForm();"';
280 }
281
282
283 /*
284 * Locate the first displayable form element (only when JavaScript on)
285 */
286 if($javascript_on) {
287 if ($sHeaderJs) {
288 $sJsBlock = "\n<script type=\"text/javascript\">" .
289 "\n<!--\n" .
290 $sHeaderJs . "\n\n// -->\n</script>\n";
291 } else {
292 $sJsBlock = '';
293 }
294 $sJsBlock .= "\n";
295
296 $js_includes = $oTemplate->get_javascript_includes(TRUE);
297 foreach ($js_includes as $js_file) {
298 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
299 }
300
301 displayHtmlHeader (_("Compose"), $sJsBlock);
302 } else {
303 /* javascript off */
304 displayHtmlHeader(_("Compose"));
305 $onload = '';
306 }
307 // FIXME: should let the template echo all these kinds of things
308 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
309 }