Don't assume we are the first form on the page
[squirrelmail.git] / src / login.php
index 0ae20dd679eec094c69f79a97960ac3e8469ca9b..ef769f85585b3f3e1c71f58e3e75ff5c0636142d 100644 (file)
@@ -6,21 +6,20 @@
  * This a simple login screen. Some housekeeping is done to clean
  * cookies and find language.
  *
- * @copyright © 1999-2006 The SquirrelMail Project Team
+ * @copyright © 1999-2007 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
  */
 
-// reduces the files included in init.php
-$sInitLocation = 'login';
+/** This is the login page */
+define('PAGE_NAME', 'login');
 
 /**
  * Include the SquirrelMail initialization file.
  */
 require('../include/init.php');
 
-
 /* SquirrelMail required files. */
 require_once(SM_PATH . 'functions/imap_general.php');
 require_once(SM_PATH . 'functions/forms.php');
@@ -31,25 +30,6 @@ require_once(SM_PATH . 'functions/forms.php');
  */
 set_up_language($squirrelmail_language, TRUE, TRUE);
 
-/**
- * In case the last session was not terminated properly, make sure
- * we get a new one, but make sure we preserve session_expired_*
- */
-if ( !empty($_SESSION['session_expired_post']) && !empty($_SESSION['session_expired_location']) ) {
-    $sep = $_SESSION['session_expired_post'];
-    $sel = $_SESSION['session_expired_location'];
-
-    sqsession_destroy();
-    @sqsession_is_active();
-    $_SESSION=array();
-    sqsession_register($sep, 'session_expired_post');
-    sqsession_register($sel, 'session_expired_location');
-} else {
-    sqsession_destroy();
-    @sqsession_is_active();
-    $_SESSION=array();
-}
-
 /**
  * This detects if the IMAP server has logins disabled, and if so,
  * squelches the display of the login form and puts up a message
@@ -87,13 +67,15 @@ $loginname_value = (sqGetGlobalVar('loginname', $loginname) ? htmlspecialchars($
 /* Output the javascript onload function. */
 $header = "<script type=\"text/javascript\">\n" .
           "<!--\n".
+          "  var alreadyFocused = false;\n".
           "  function squirrelmail_loginpage_onload() {\n".
-          "    var textElements = 0;\n".
-          "    for (i = 0; i < document.forms[0].elements.length; i++) {\n".
-          "      if (document.forms[0].elements[i].type == \"text\" || document.forms[0].elements[i].type == \"password\") {\n".
+          "    if (alreadyFocused) return;\n".
+          "    var textElements = 0; var i = 0;\n".
+          "    for (i = 0; i < document.login_form.elements.length; i++) {\n".
+          "      if (document.login_form.elements[i].type == \"text\" || document.login_form.elements[i].type == \"password\") {\n".
           "        textElements++;\n".
           "        if (textElements == " . (isset($loginname) ? 2 : 1) . ") {\n".
-          "          document.forms[0].elements[i].focus();\n".
+          "          document.login_form.elements[i].focus();\n".
           "          break;\n".
           "        }\n".
           "      }\n".
@@ -115,10 +97,6 @@ if (! isset($color) || ! is_array($color)) {
     $color[7]  = '#0000cc';  /* blue          Links                  */
     $color[8]  = '#000000';  /* black         Normal text            */
 }
-/**
- * send out all the cookies
- */
-sqsetcookieflush();
 
 displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );
 
@@ -127,7 +105,7 @@ displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );
 /* If they don't have a logo, don't bother.. */
 $logo_str = '';
 if (isset($org_logo) && $org_logo) {
-    
+
     if (isset($org_logo_width) && is_numeric($org_logo_width) &&
      $org_logo_width>0) {
         $width = $org_logo_width;
@@ -141,16 +119,15 @@ if (isset($org_logo) && $org_logo) {
         $height = '';
     }
 
-    $logo_str = create_image($org_logo, sprintf(_("%s Logo"), $org_name), 
+    $logo_str = create_image($org_logo, sprintf(_("%s Logo"), $org_name),
                              $width, $height, '', 'sqm_loginImage');
 
 }
 
 $sm_attribute_str = '';
 if (isset($hide_sm_attributions) && !$hide_sm_attributions) {
-//FIXME: need to remove *ALL* HTML from this file!
-    $sm_attribute_str = _("SquirrelMail Webmail Application")."<br />\n" .
-                        _("By the SquirrelMail Project Team")."<br />\n";
+    $sm_attribute_str = _("SquirrelMail Webmail")."\n" .
+                        _("By the SquirrelMail Project Team");
 }
 
 if(sqgetGlobalVar('mailtodata', $mailtodata)) {
@@ -166,16 +143,19 @@ $login_extra = addHidden('js_autodetect_results', SMPREF_JS_OFF).
 
 session_write_close();
 
-$oTemplate->assign('logo_str', $logo_str);
+$oTemplate->assign('logo_str', $logo_str, FALSE);
 $oTemplate->assign('logo_path', $org_logo);
 $oTemplate->assign('sm_attribute_str', $sm_attribute_str);
+// i18n: The %s represents the service provider's name
 $oTemplate->assign('org_name_str', sprintf (_("%s Login"), $org_name));
+// i18n: The %s represents the service provider's name
+$oTemplate->assign('org_logo_str', sprintf (_("The %s logo"), $org_name));
 $oTemplate->assign('login_field_value', $loginname_value);
-$oTemplate->assign('login_extra', $login_extra);
+$oTemplate->assign('login_extra', $login_extra, FALSE);
 
 //FIXME: need to remove *ALL* HTML from this file!
-echo '<body onLoad="squirrelmail_loginpage_onload()">'."\n";
-echo '<form action="redirect.php" method="post" onSubmit="document.forms[0].js_autodetect_results.value='. SMPREF_JS_ON .'">'."\n";
+echo '<body onload="squirrelmail_loginpage_onload()">'."\n";
+echo '<form name="login_form" id="login_form" action="redirect.php" method="post" onsubmit="document.login_form.js_autodetect_results.value='. SMPREF_JS_ON .'">'."\n";
 do_hook('login_top', $null);
 
 $oTemplate->display('login.tpl');
@@ -188,4 +168,3 @@ do_hook('login_bottom', $null);
 $oErrorHandler->setDelayedErrors(false);
 
 $oTemplate->display('footer.tpl');
-?>