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