place login form elements before login button. #1245070.
[squirrelmail.git] / src / login.php
1 <?php
2
3 /**
4 * login.php -- simple login screen
5 *
6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This a simple login screen. Some housekeeping is done to clean
10 * cookies and find language.
11 *
12 * @version $Id$
13 * @package squirrelmail
14 */
15
16 /**
17 * Path for SquirrelMail required files.
18 * @ignore
19 */
20 define('SM_PATH','../');
21
22 /* SquirrelMail required files. */
23 require_once(SM_PATH . 'functions/strings.php');
24 require_once(SM_PATH . 'config/config.php');
25 require_once(SM_PATH . 'functions/i18n.php');
26 require_once(SM_PATH . 'functions/plugin.php');
27 require_once(SM_PATH . 'functions/constants.php');
28 require_once(SM_PATH . 'functions/page_header.php');
29 require_once(SM_PATH . 'functions/html.php');
30 require_once(SM_PATH . 'functions/global.php');
31 require_once(SM_PATH . 'functions/imap_general.php');
32 require_once(SM_PATH . 'functions/forms.php');
33
34 /**
35 * $squirrelmail_language is set by a cookie when the user selects
36 * language and logs out
37 */
38 set_up_language($squirrelmail_language, TRUE, TRUE);
39
40 /**
41 * Find out the base URI to set cookies.
42 */
43 if (!function_exists('sqm_baseuri')){
44 require_once(SM_PATH . 'functions/display_messages.php');
45 }
46 $base_uri = sqm_baseuri();
47
48 /*
49 * In case the last session was not terminated properly, make sure
50 * we get a new one.
51 */
52
53 sqsession_destroy();
54
55 header('Pragma: no-cache');
56
57 /**
58 * This detects if the IMAP server has logins disabled, and if so,
59 * squelches the display of the login form and puts up a message
60 * explaining the situation.
61 */
62 if($imap_auth_mech == 'login') {
63 /**
64 * detect disabled login, only when imapServerAddress contains
65 * server address and not mapping. See sqimap_get_user_server()
66 */
67 if (substr($imapServerAddress, 0, 4) != "map:") {
68 $imap = sqimap_create_stream($imapServerAddress, $imapPort, $use_imap_tls);
69 $logindisabled = sqimap_capability($imap,'LOGINDISABLED');
70 sqimap_logout($imap);
71 if ($logindisabled) {
72 $string = _("The IMAP server is reporting that plain text logins are disabled.").'<br />'.
73 _("Using CRAM-MD5 or DIGEST-MD5 authentication instead may work.").'<br />';
74 if (!$use_imap_tls) {
75 $string .= _("Also, the use of TLS may allow SquirrelMail to login.").'<br />';
76 }
77 $string .= _("Please contact your system administrator and report this error.");
78 error_box($string,$color);
79 exit;
80 }
81 }
82 }
83
84 do_hook('login_cookie');
85
86 $loginname_value = (sqGetGlobalVar('loginname', $loginname) ? htmlspecialchars($loginname) : '');
87
88 /* Output the javascript onload function. */
89
90 $header = "<script language=\"JavaScript\" type=\"text/javascript\">\n" .
91 "<!--\n".
92 " function squirrelmail_loginpage_onload() {\n".
93 " var textElements = 0;\n".
94 " for (i = 0; i < document.forms[0].elements.length; i++) {\n".
95 " if (document.forms[0].elements[i].type == \"text\" || document.forms[0].elements[i].type == \"password\") {\n".
96 " textElements++;\n".
97 " if (textElements == " . (isset($loginname) ? 2 : 1) . ") {\n".
98 " document.forms[0].elements[i].focus();\n".
99 " break;\n".
100 " }\n".
101 " }\n".
102 " }\n".
103 " }\n".
104 "// -->\n".
105 "</script>\n";
106
107 if (@file_exists($theme[$theme_default]['PATH']))
108 @include ($theme[$theme_default]['PATH']);
109
110 if (! isset($color) || ! is_array($color)) {
111 // Add default color theme, if theme loading fails
112 $color = array();
113 $color[0] = '#dcdcdc'; /* light gray TitleBar */
114 $color[1] = '#800000'; /* red */
115 $color[2] = '#cc0000'; /* light red Warning/Error Messages */
116 $color[4] = '#ffffff'; /* white Normal Background */
117 $color[7] = '#0000cc'; /* blue Links */
118 $color[8] = '#000000'; /* black Normal text */
119 }
120
121 displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );
122
123 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" onLoad=\"squirrelmail_loginpage_onload()\">" .
124 "\n" . '<form action="redirect.php" method="post" onSubmit="document.forms[0].js_autodetect_results.value=\'' . SMPREF_JS_ON .'\';">' . "\n";
125
126 $username_form_name = 'login_username';
127 $password_form_name = 'secretkey';
128 do_hook('login_top');
129
130 /* If they don't have a logo, don't bother.. */
131 if (isset($org_logo) && $org_logo) {
132 /* Display width and height like good little people */
133 $width_and_height = '';
134 if (isset($org_logo_width) && is_numeric($org_logo_width) &&
135 $org_logo_width>0) {
136 $width_and_height = " width=\"$org_logo_width\"";
137 }
138 if (isset($org_logo_height) && is_numeric($org_logo_height) &&
139 $org_logo_height>0) {
140 $width_and_height .= " height=\"$org_logo_height\"";
141 }
142 }
143
144 if(sqgetGlobalVar('mailto', $mailto)) {
145 $rcptaddress = addHidden('mailto', $mailto);
146 } else {
147 $rcptaddress = '';
148 }
149 echo html_tag( 'table',
150 html_tag( 'tr',
151 html_tag( 'td',
152 '<center>'.
153 ( isset($org_logo) && $org_logo
154 ? '<img src="' . $org_logo . '" alt="' .
155 sprintf(_("%s Logo"), $org_name) .'"' . $width_and_height .
156 ' /><br />' . "\n"
157 : '' ).
158 ( (isset($hide_sm_attributions) && $hide_sm_attributions) ? '' :
159 '<small>' . _("SquirrelMail Webmail Application") . '<br />' ."\n".
160 ' ' . _("By the SquirrelMail Project Team") . '<br /></small>' . "\n" ) .
161 html_tag( 'table',
162 html_tag( 'tr',
163 html_tag( 'td',
164 '<b>' . sprintf (_("%s Login"), $org_name) . "</b>\n",
165 'center', $color[0] )
166 ) .
167 html_tag( 'tr',
168 html_tag( 'td', "\n" .
169 html_tag( 'table',
170 html_tag( 'tr',
171 html_tag( 'td',
172 _("Name:") ,
173 'right', '', 'width="30%"' ) .
174 html_tag( 'td',
175 addInput($username_form_name, $loginname_value),
176 'left', '', 'width="*"' )
177 ) . "\n" .
178 html_tag( 'tr',
179 html_tag( 'td',
180 _("Password:") ,
181 'right', '', 'width="30%"' ) .
182 html_tag( 'td',
183 addPwField($password_form_name).
184 addHidden('js_autodetect_results', SMPREF_JS_OFF).
185 $rcptaddress .
186 addHidden('just_logged_in', '1'),
187 'left', '', 'width="*"' )
188 ) .
189 concat_hook_function('login_form') ,
190 'center', $color[4], 'border="0" width="100%"' ) ,
191 'left', $color[4] )
192 ) .
193 html_tag( 'tr',
194 html_tag( 'td',
195 '<center>'. addSubmit(_("Login")) .'</center>',
196 'left' )
197 ),
198 '', $color[4], 'border="0" width="350"' ) . '</center>',
199 'center' )
200 ) ,
201 '', $color[4], 'border="0" cellspacing="0" cellpadding="0" width="100%"' );
202 echo '</form>' . "\n";
203
204 do_hook('login_bottom');
205
206 ?>
207 </body></html>