fix for text box focus on read_body.php. Ryan, adding a simple case block causes...
[squirrelmail.git] / functions / page_header.php
1 <?php
2
3 /**
4 * page_header.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Prints the page header (duh)
10 *
11 * $Id$
12 */
13
14 require_once('../functions/strings.php');
15
16 /* Always set up the language before calling these functions */
17 function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE ) {
18
19 global $theme_css, $custom_css, $base_uri;
20
21 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">' .
22 "\n\n<HTML>\n<HEAD>\n";
23
24 if ( !isset( $custom_css ) || $custom_css == 'none' ) {
25 if ($theme_css != '') {
26 echo "<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"$theme_css\">";
27 }
28 } else {
29 echo '<LINK REL="stylesheet" TYPE="text/css" HREF="' .
30 $base_uri . 'themes/css/'.$custom_css.'">';
31 }
32
33 echo "\n<title>$title</title>$xtra</head>\n\n";
34 }
35
36 function displayInternalLink($path, $text, $target='') {
37 global $base_uri;
38
39 if ($target != '') {
40 $target = " target=\"$target\"";
41 }
42
43 echo '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
44 }
45
46 function displayPageHeader($color, $mailbox, $xtra='') {
47
48 global $delimiter, $hide_sm_attributions, $base_uri, $PHP_SELF, $frame_top,
49 $compose_new_win, $username, $datadir, $compose_width, $compose_height;
50
51 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
52 if ($qmark = strpos($module, '?')) {
53 $module = substr($module, 0, $qmark);
54 }
55 if (!isset($frame_top)) {
56 $frame_top = '_top';
57 }
58
59 /*
60 Locate the first displayable form element
61 */
62 switch ( $module ) {
63 case 'src/read_body.php':
64 if ($compose_new_win == '1') {
65 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
66 $compose_width = '640';
67 }
68 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
69 $compose_height = '550';
70 }
71 $js = "\n".'<script language="JavaScript" type="text/javascript">' .
72 "\n<!--\n";
73 $js .= "function comp_in_new() {\n".
74 " var newwin = window.open(\"".$base_uri."src/compose.php\"".
75 ", \"compose_window\",
76 \"width=".$compose_width.",height=$compose_height".
77 ",scrollbars=yes,resizable=yes\");\n".
78 "}\n";
79 $js .= "// -->\n".
80 "</script>\n";
81 displayHtmlHeader ('Squirrelmail', $js);
82 }
83 displayHtmlHeader();
84 $onload = '';
85 break;
86 default:
87 $js = '<script language="JavaScript" type="text/javascript">' .
88 "\n<!--\n" .
89 "function checkForm() {\n".
90 "var f = document.forms.length;\n".
91 "var i = 0;\n".
92 "var pos = -1;\n".
93 "while( pos == -1 && i < f ) {\n".
94 "var e = document.forms[i].elements.length;\n".
95 "var j = 0;\n".
96 "while( pos == -1 && j < e ) {\n".
97 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
98 "pos = j;\n".
99 "}\n".
100 "j++;\n".
101 "}\n".
102 "i++;\n".
103 "}\n".
104 "if( pos >= 0 ) {\n".
105 "document.forms[i-1].elements[pos].focus();\n".
106 "}\n".
107 "$xtra\n".
108 "}\n";
109 if ($compose_new_win == '1') {
110 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
111 $compose_width = '640';
112 }
113 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
114 $compose_height = '550';
115 }
116 $js .= "function comp_in_new() {\n".
117 " var newwin = window.open(\"".$base_uri."src/compose.php\"".
118 ", \"compose_window\",
119 \"width=".$compose_width.",height=$compose_height".
120 ",scrollbars=yes,resizable=yes\");\n".
121 "}\n";
122 }
123 $js .= "// -->\n".
124 "</script>\n";
125 $onload = "onLoad=\"checkForm();\"";
126 displayHtmlHeader ('Squirrelmail', $js);
127 break;
128
129 }
130
131 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\" $onload>\n\n";
132 /** Here is the header and wrapping table **/
133 $shortBoxName = readShortMailboxName($mailbox, $delimiter);
134 if ( $shortBoxName == 'INBOX' ) {
135 $shortBoxName = _("INBOX");
136 }
137 echo "<A NAME=pagetop></A>\n"
138 . "<TABLE BGCOLOR=\"$color[4]\" BORDER=0 WIDTH=\"100%\" CELLSPACING=0 CELLPADDING=2>\n"
139 . " <TR BGCOLOR=\"$color[9]\" >\n"
140 . " <TD ALIGN=left>\n";
141 if ( $shortBoxName <> '' && strtolower( $shortBoxName ) <> 'none' ) {
142 echo ' ' . _("Current Folder") . ": <B>$shortBoxName&nbsp;</B>\n";
143 } else {
144 echo '&nbsp;';
145 }
146 echo " </TD>\n"
147 . ' <TD ALIGN=right><b>';
148 displayInternalLink ('src/signout.php', _("Sign Out"), $frame_top);
149 echo "</b></TD>\n"
150 . " </TR>\n"
151 . " <TR BGCOLOR=\"$color[4]\">\n"
152 . " <TD ALIGN=left>\n";
153 $urlMailbox = urlencode($mailbox);
154 if ($compose_new_win == '1') {
155 echo "<a href=$base_uri". "src/compose.php?mailbox=$urlMailbox target=".
156 '"compose_window" onClick="comp_in_new()">'. _("Compose"). '</a>';
157 }
158 else {
159 displayInternalLink ("src/compose.php?mailbox=$urlMailbox", _("Compose"), 'right');
160 }
161 echo "&nbsp;&nbsp;\n";
162 displayInternalLink ("src/addressbook.php", _("Addresses"), 'right');
163 echo "&nbsp;&nbsp;\n";
164 displayInternalLink ("src/folders.php", _("Folders"), 'right');
165 echo "&nbsp;&nbsp;\n";
166 displayInternalLink ("src/options.php", _("Options"), 'right');
167 echo "&nbsp;&nbsp;\n";
168 displayInternalLink ("src/search.php?mailbox=$urlMailbox", _("Search"), 'right');
169 echo "&nbsp;&nbsp;\n";
170 displayInternalLink ("src/help.php", _("Help"), 'right');
171 echo "&nbsp;&nbsp;\n";
172
173 do_hook("menuline");
174
175 echo " </TD>\n <TD ALIGN=\"right\">";
176 echo ($hide_sm_attributions ? '&nbsp;' :
177 '<A HREF="http://www.squirrelmail.org/" TARGET="_blank">SquirrelMail</A>');
178 echo "</TD>\n".
179 " </TR>\n".
180 "</TABLE>\n\n";
181 }
182
183 /* blatently copied/truncated/modified from the above function */
184 function compose_Header($color, $mailbox) {
185
186 global $delimiter, $hide_sm_attributions, $base_uri, $PHP_SELF, $frame_top, $compose_new_win;
187
188
189 $module = substr( $PHP_SELF, ( strlen( $PHP_SELF ) - strlen( $base_uri ) ) * -1 );
190 if (!isset($frame_top)) {
191 $frame_top = '_top';
192 }
193
194 /*
195 Locate the first displayable form element
196 */
197 switch ( $module ) {
198 case 'src/search.php':
199 $pos = getPref($data_dir, $username, 'search_pos', 0 ) - 1;
200 $onload = "onLoad=\"document.forms[$pos].elements[2].focus();\"";
201 displayHtmlHeader (_("Compose"));
202 break;
203 default:
204 $js = '<script language="JavaScript" type="text/javascript">' .
205 "\n<!--\n" .
206 "function checkForm() {\n".
207 "var f = document.forms.length;\n".
208 "var i = 0;\n".
209 "var pos = -1;\n".
210 "while( pos == -1 && i < f ) {\n".
211 "var e = document.forms[i].elements.length;\n".
212 "var j = 0;\n".
213 "while( pos == -1 && j < e ) {\n".
214 "if ( document.forms[i].elements[j].type == 'text' ) {\n".
215 "pos = j;\n".
216 "}\n".
217 "j++;\n".
218 "}\n".
219 "i++;\n".
220 "}\n".
221 "if( pos >= 0 ) {\n".
222 "document.forms[i-1].elements[pos].focus();\n".
223 "}\n".
224 "}\n";
225 $js .= "// -->\n".
226 "</script>\n";
227 $onload = "onLoad=\"checkForm();\"";
228 displayHtmlHeader (_("Compose"), $js);
229 break;
230
231 }
232
233 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\" $onload>\n\n";
234 }
235 ?>