Template object is referenced in load_prefs.php if icons are enabled. Need to includ...
[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 $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
55 $aUserStyles = array();
56 //FIXME: remove this!!
57 // load custom style sheet (deprecated)
58 if ( ! empty($theme_css) ) {
59 $aUserStyles[] = $theme_css;
60 }
61 // 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)
62 // 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?
63 // $aUserStyles[] = getPref($data_dir, $username, 'sUserStyle', '');
64 $aUserStyles[] = $base_uri .'src/style.php'
65 . '?themeid='.$used_theme
66 . '&amp;templateid='.$sTemplateID
67 . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
68 . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '')
69 . (!empty($text_direction) ? '&amp;dir='.$text_direction : '');
70 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
71 //FIXME: only call the next method if language is right-to-left!
72 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
73
74 if ($squirrelmail_language == 'ja_JP') {
75 /*
76 * force correct detection of charset, when browser does not follow
77 * http content-type and tries to detect charset from page content.
78 * Shooting of browser's creator can't be implemented in php.
79 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
80 * recommendations and switch to unicode.
81 */
82 $header_tags .= "<!-- \xfd\xfe -->\n";
83 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
84 }
85 if ($do_hook) {
86 // NOTE! plugins here must assign output to template
87 // and NOT echo anything directly!!
88 do_hook('generic_header');
89 }
90
91 $header_tags .= $xtra;
92 $oTemplate->assign('page_title', $title);
93
94 /* work around IE6's scrollbar bug */
95 $header_tags .= <<<EOS
96 <!--[if IE 6]>
97 <style type="text/css">
98 /* avoid stupid IE6 bug with frames and scrollbars */
99 body {
100 width: expression(document.documentElement.clientWidth - 30);
101 }
102 </style>
103 <![endif]-->
104
105 EOS;
106
107 $oTemplate->assign('header_tags', $header_tags);
108 $oTemplate->display('protocol_header.tpl');
109
110 /* this is used to check elsewhere whether we should call this function */
111 $pageheader_sent = TRUE;
112 if (isset($oErrorHandler)) {
113 $oErrorHandler->HeaderSent();
114 }
115
116 }
117
118 /**
119 * Given a path to a SquirrelMail file, return a HTML link to it
120 *
121 * @param string path the SquirrelMail file to link to
122 * @param string text the link text
123 * @param string target the target frame for this link
124 */
125 function makeInternalLink($path, $text, $target='') {
126 global $base_uri;
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 // FIXME: should let the template echo all these kinds of things
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 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
189
190 if (!isset($frame_top)) {
191 $frame_top = '_top';
192 }
193
194 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
195 $js_includes = $oTemplate->get_javascript_includes(TRUE);
196 $sJsBlock = '';
197 foreach ($js_includes as $js_file) {
198 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
199 }
200 if ($sHeaderJs) {
201 $sJsBlock .= "\n<script type=\"text/javascript\">" .
202 "\n<!--\n" .
203 $sHeaderJs . "\n\n// -->\n</script>\n";
204 }
205 displayHtmlHeader ('SquirrelMail', $sJsBlock);
206 } else {
207 /* do not use JavaScript */
208 displayHtmlHeader ('SquirrelMail');
209 $sBodyTagJs = '';
210 }
211 /*
212 * this explains the imap_mailbox.php dependency. We should instead store
213 * the selected mailbox in the session and fallback to the session var.
214 */
215 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
216 readShortMailboxName($mailbox, $delimiter)));
217 if ( $shortBoxName == 'INBOX' ) {
218 $shortBoxName = _("INBOX");
219 }
220
221 $sm_attributes = '';
222 if (!$hide_sm_attributions) {
223 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
224 if (empty($provider_uri)) {
225 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
226 } else {
227 if (empty($provider_name)) $provider_name= 'SquirrelMail';
228 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
229 }
230 $sm_attributes .= " </td>\n";
231 }
232
233 $oTemplate->assign('body_tag_js', $sBodyTagJs);
234 $oTemplate->assign('shortBoxName', $shortBoxName);
235 $oTemplate->assign('sm_attribute_str', $sm_attributes);
236 $oTemplate->assign('frame_top', $frame_top);
237 $oTemplate->assign('urlMailbox', $urlMailbox);
238 $oTemplate->assign('startMessage', $startMessage);
239 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
240 $oTemplate->display('page_header.tpl');
241 }
242
243 /**
244 * Blatantly copied/truncated/modified from displayPageHeader.
245 * Outputs a page header specifically for the compose_in_new popup window
246 *
247 * @param array color the array of theme colors
248 * @param string mailbox the current mailbox name to display
249 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
250 * @param string sBodyTagJs js events to be inserted in the body tag
251 * @return void
252 */
253 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
254
255 global $reply_focus, $javascript_on, $action, $oTemplate;
256
257 if (empty($sBodyTagJs)) {
258 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
259 if ($reply_focus == 'select')
260 $sBodyTagJs = 'onload="checkForm(\'select\');"';
261 else if ($reply_focus == 'focus')
262 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
263 else if ($reply_focus != 'none')
264 $sBodyTagJs = 'onload="checkForm();"';
265 }
266 else
267 $sBodyTagJs = 'onload="checkForm();"';
268 }
269
270
271 /*
272 * Locate the first displayable form element (only when JavaScript on)
273 */
274 if($javascript_on) {
275 if ($sHeaderJs) {
276 $sJsBlock = "\n<script type=\"text/javascript\">" .
277 "\n<!--\n" .
278 $sHeaderJs . "\n\n// -->\n</script>\n";
279 } else {
280 $sJsBlock = '';
281 }
282 $sJsBlock .= "\n";
283
284 $js_includes = $oTemplate->get_javascript_includes(TRUE);
285 foreach ($js_includes as $js_file) {
286 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
287 }
288
289 displayHtmlHeader (_("Compose"), $sJsBlock);
290 } else {
291 /* javascript off */
292 displayHtmlHeader(_("Compose"));
293 $onload = '';
294 }
295 // FIXME: should let the template echo all these kinds of things
296 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
297 }