Fix unknown variable notice
[squirrelmail.git] / src / login.php
1 <?php
2
3 /**
4 * login.php -- simple login screen
5 *
6 * This a simple login screen. Some housekeeping is done to clean
7 * cookies and find language.
8 *
9 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 */
14
15 /** This is the login page */
16 define('PAGE_NAME', 'login');
17
18 /**
19 * Include the SquirrelMail initialization file.
20 */
21 require('../include/init.php');
22
23 /* SquirrelMail required files. */
24 require_once(SM_PATH . 'functions/imap_general.php');
25 require_once(SM_PATH . 'functions/forms.php');
26
27 /**
28 * $squirrelmail_language is set by a cookie when the user selects
29 * language and logs out
30 */
31 set_up_language($squirrelmail_language, TRUE, TRUE);
32
33 /**
34 * This detects if the IMAP server has logins disabled, and if so,
35 * squelches the display of the login form and puts up a message
36 * explaining the situation.
37 */
38 if($imap_auth_mech == 'login') {
39 /**
40 * detect disabled login, only when imapServerAddress contains
41 * server address and not mapping. See sqimap_get_user_server()
42 */
43 if (substr($imapServerAddress, 0, 4) != "map:") {
44 $imap = sqimap_create_stream($imapServerAddress, $imapPort, $use_imap_tls);
45 $logindisabled = sqimap_capability($imap,'LOGINDISABLED');
46 sqimap_logout($imap);
47 if ($logindisabled) {
48 $string = _("The IMAP server is reporting that plain text logins are disabled.").'<br />'.
49 _("Using CRAM-MD5 or DIGEST-MD5 authentication instead may work.").'<br />';
50 if (!$use_imap_tls) {
51 $string .= _("Also, the use of TLS may allow SquirrelMail to login.").'<br />';
52 }
53 $string .= _("Please contact your system administrator and report this error.");
54 error_box($string);
55 // display footer (closes html tags) and stop script execution
56 $oTemplate->display('footer.tpl');
57 exit;
58 }
59 }
60 }
61
62 do_hook('login_cookie', $null);
63
64 $loginname_value = (sqGetGlobalVar('loginname', $loginname) ? htmlspecialchars($loginname) : '');
65
66 //FIXME: should be part of the template, not the core!
67 /* Output the javascript onload function. */
68 $header = "<script type=\"text/javascript\">\n" .
69 "<!--\n".
70 " function squirrelmail_loginpage_onload() {\n".
71 " var textElements = 0;\n".
72 " for (i = 0; i < document.forms[0].elements.length; i++) {\n".
73 " if (document.forms[0].elements[i].type == \"text\" || document.forms[0].elements[i].type == \"password\") {\n".
74 " textElements++;\n".
75 " if (textElements == " . (isset($loginname) ? 2 : 1) . ") {\n".
76 " document.forms[0].elements[i].focus();\n".
77 " break;\n".
78 " }\n".
79 " }\n".
80 " }\n".
81 " }\n".
82 "// -->\n".
83 "</script>\n";
84
85 if (@file_exists($theme[$theme_default]['PATH']))
86 @include ($theme[$theme_default]['PATH']);
87
88 if (! isset($color) || ! is_array($color)) {
89 // Add default color theme, if theme loading fails
90 $color = array();
91 $color[0] = '#dcdcdc'; /* light gray TitleBar */
92 $color[1] = '#800000'; /* red */
93 $color[2] = '#cc0000'; /* light red Warning/Error Messages */
94 $color[4] = '#ffffff'; /* white Normal Background */
95 $color[7] = '#0000cc'; /* blue Links */
96 $color[8] = '#000000'; /* black Normal text */
97 }
98
99 displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );
100
101
102
103 /* If they don't have a logo, don't bother.. */
104 $logo_str = '';
105 if (isset($org_logo) && $org_logo) {
106
107 if (isset($org_logo_width) && is_numeric($org_logo_width) &&
108 $org_logo_width>0) {
109 $width = $org_logo_width;
110 } else {
111 $width = '';
112 }
113 if (isset($org_logo_height) && is_numeric($org_logo_height) &&
114 $org_logo_height>0) {
115 $height = $org_logo_height;
116 } else {
117 $height = '';
118 }
119
120 $logo_str = create_image($org_logo, sprintf(_("%s Logo"), $org_name),
121 $width, $height, '', 'sqm_loginImage');
122
123 }
124
125 $sm_attribute_str = '';
126 if (isset($hide_sm_attributions) && !$hide_sm_attributions) {
127 $sm_attribute_str = _("SquirrelMail Webmail")."\n" .
128 _("By the SquirrelMail Project Team");
129 }
130
131 if(sqgetGlobalVar('mailtodata', $mailtodata)) {
132 $mailtofield = addHidden('mailtodata', $mailtodata);
133 } else {
134 $mailtofield = '';
135 }
136
137 $password_field = addPwField('secretkey');
138 $login_extra = addHidden('js_autodetect_results', SMPREF_JS_OFF).
139 $mailtofield .
140 addHidden('just_logged_in', '1');
141
142 session_write_close();
143
144 $oTemplate->assign('logo_str', $logo_str, FALSE);
145 $oTemplate->assign('logo_path', $org_logo);
146 $oTemplate->assign('sm_attribute_str', $sm_attribute_str);
147 // i18n: The %s represents the service provider's name
148 $oTemplate->assign('org_name_str', sprintf (_("%s Login"), $org_name));
149 // i18n: The %s represents the service provider's name
150 $oTemplate->assign('org_logo_str', sprintf (_("The %s logo"), $org_name));
151 $oTemplate->assign('login_field_value', $loginname_value);
152 $oTemplate->assign('login_extra', $login_extra, FALSE);
153
154 //FIXME: need to remove *ALL* HTML from this file!
155 echo '<body onload="squirrelmail_loginpage_onload()">'."\n";
156 echo '<form action="redirect.php" method="post" onsubmit="document.forms[0].js_autodetect_results.value='. SMPREF_JS_ON .'">'."\n";
157 do_hook('login_top', $null);
158
159 $oTemplate->display('login.tpl');
160
161 //FIXME: need to remove *ALL* HTML from this file!
162 echo "</form>\n";
163 do_hook('login_bottom', $null);
164
165 // Turn off delayed error handling to make sure all errors are dumped.
166 $oErrorHandler->setDelayedErrors(false);
167
168 $oTemplate->display('footer.tpl');