The following customization will modify your Login page in web applications that generated by PHP Report Maker 6. We are not going to customize the generated Login page for this purpose. We are going to customize PHP Report Maker template files, so this can be re-used for your other future projects.
Just like the customization that I created in PHPMaker version 9, this modification will add the ability to set focus on the Username textbox when your user visits or loads this page. We are also still using the same image to beautify the Login form in PHPMaker version 9. In addition, we will modify the Captcha extension template in order to display the Captcha properly in Login page.
[hidepost]
-
Open your \Script\rpt-config.php file, and find this code:
// General
before that line, please insert the following code:
// Begin of modification Customizing Login Page, by Masino Sinaga, December 4, 2012 define("MSR_SHOW_CAPTCHA_ON_LOGIN_PAGE", FALSE, TRUE); // <-- Switch FALSE to TRUE if you want to display Captcha on the Login page <!--## if (PROJ.SecRegisterPage) { ##--> define("MSR_USER_REGISTRATION", TRUE, TRUE); <!--## } ##--> // End of modification Customizing Login Page, by Masino Sinaga, December 4, 2012
-
Open your \Script\rpt-login.php file, and replace (Yes, Replace!) all the content of the file with the following code (Warning: Backup your rpt-login.php file before doing this step!):
<!--##session currenttable##--> <!--## // Set security table current if (ew_IsNotEmpty(PROJ.SecTbl)) { TABLE = DB.Tables(PROJ.SecTbl); goFlds = goTblFlds.Fields; gsTblVar = TABLE.TblVar; } sLoginOption = PROJ.LoginOption; if (sLoginOption == "") sLoginOption = "AUTO,USER,ASK"; arLoginOption = sLoginOption.split(","); dLoginOption = {}; lLoginOptionCount = 0; for (var i = 0; i < arLoginOption.length; i++) { sOption = arLoginOption[i].trim(); if (sOption == "AUTO" || sOption == "USER" || sOption == "ASK") { if (!(sOption in dLoginOption)) { dLoginOption[sOption] = sOption; lLoginOptionCount += 1; } } } ##--> <!--##/session##--> <?php <!--##session phpmain##--> <!--##include rpt-captcha.php/phpcaptcha_var##--> var $Username; var $LoginType; // // Page main // function Page_Main() { global $Security, $ReportLanguage, $gsFormError; $sPassword = ""; $sLastUrl = $Security->LastUrl(); // Get last URL if ($sLastUrl == "") $sLastUrl = "<!--##=sFnDefault##-->"; if (!$Security->IsLoggedIn()) $Security->AutoLogin(); <!--## if (bUserLevel) { ##--> $Security->LoadUserLevel(); // Load user level <!--## } ##--> $this->Username = ""; // Initialize if (@$_POST["username"] <> "") { // Setup variables $this->Username = ewr_RemoveXSS(ewr_StripSlashes(@$_POST["username"])); $sPassword = ewr_RemoveXSS(ewr_StripSlashes(@$_POST["password"])); $this->LoginType = strtolower(ewr_RemoveXSS(@$_POST["type"])); <!--## if (PROJ.GetV("AllowLoginByUrl")) { ##--> } else if (@$_GET["username"] <> "") { // Setup variables $this->Username = ewr_RemoveXSS(ewr_StripSlashes(@$_GET["username"])); $sPassword = ewr_RemoveXSS(ewr_StripSlashes(@$_GET["password"])); $this->LoginType = strtolower(ewr_RemoveXSS(@$_GET["type"])); <!--## } ##--> } if ($this->Username <> "") { $bValidate = $this->ValidateForm($this->Username, $sPassword); if (!$bValidate) $this->setFailureMessage($gsFormError); } else { if ($Security->IsLoggedIn()) { if ($this->getFailureMessage() == "") $this->Page_Terminate($sLastUrl); // Return to last accessed page } $bValidate = FALSE; // Restore settings if (@$_COOKIE[EWR_PROJECT_NAME]['Checksum'] == strval(crc32(md5(EWR_RANDOM_KEY)))) $this->Username = TEAdecrypt(@$_COOKIE[EWR_PROJECT_NAME]['Username'], EWR_RANDOM_KEY); if (@$_COOKIE[EWR_PROJECT_NAME]['AutoLogin'] == "autologin") { $this->LoginType = "a"; } elseif (@$_COOKIE[EWR_PROJECT_NAME]['AutoLogin'] == "rememberusername") { $this->LoginType = "u"; } else { $this->LoginType = ""; } } $bValidPwd = FALSE; <!--##include rpt-captcha.php/phpcaptcha_php##--> if ($bValidate) { <!--## if (SYSTEMFUNCTIONS.ServerScriptExist("Other","User_LoggingIn")) { ##--> // Call Logging In event $bValidate = $this->User_LoggingIn($this->Username, $sPassword); <!--## } else { ##--> $bValidate = TRUE; <!--## } ##--> if ($bValidate) { $bValidPwd = $Security->ValidateUser($this->Username, $sPassword, FALSE); // Manual login if (!$bValidPwd) { if ($this->getFailureMessage() == "") $this->setFailureMessage($ReportLanguage->Phrase("InvalidUidPwd")); // Invalid user id/password } } else { if ($this->getFailureMessage() == "") $this->setFailureMessage($ReportLanguage->Phrase("LoginCancelled")); // Login cancelled } } if ($bValidPwd) { // Write cookies if ($this->LoginType == "a") { // Auto login setcookie(EWR_PROJECT_VAR . '[AutoLogin]', "autologin", EWR_COOKIE_EXPIRY_TIME); // Set autologin cookie setcookie(EWR_PROJECT_VAR . '[Username]', TEAencrypt($this->Username, EWR_RANDOM_KEY), EWR_COOKIE_EXPIRY_TIME); // Set user name cookie setcookie(EWR_PROJECT_VAR . '[Password]', TEAencrypt($sPassword, EWR_RANDOM_KEY), EWR_COOKIE_EXPIRY_TIME); // Set password cookie setcookie(EWR_PROJECT_VAR . '[Checksum]', crc32(md5(EWR_RANDOM_KEY)), EWR_COOKIE_EXPIRY_TIME); } elseif ($this->LoginType == "u") { // Remember user name setcookie(EWR_PROJECT_VAR . '[AutoLogin]', "rememberusername", EWR_COOKIE_EXPIRY_TIME); // Set remember user name cookie setcookie(EWR_PROJECT_VAR . '[Username]', TEAencrypt($this->Username, EWR_RANDOM_KEY), EWR_COOKIE_EXPIRY_TIME); // Set user name cookie setcookie(EWR_PROJECT_VAR . '[Checksum]', crc32(md5(EWR_RANDOM_KEY)), EWR_COOKIE_EXPIRY_TIME); } else { setcookie(EWR_PROJECT_VAR . '[AutoLogin]', "", EWR_COOKIE_EXPIRY_TIME); // Clear auto login cookie } <!--## if (SYSTEMFUNCTIONS.ServerScriptExist("Other","User_LoggedIn")) { ##--> // Call loggedin event $this->User_LoggedIn($this->Username); <!--## } ##--> $this->Page_Terminate($sLastUrl); // Return to last accessed URL } elseif ($this->Username <> "" && $sPassword <> "") { <!--## if (SYSTEMFUNCTIONS.ServerScriptExist("Other","User_LoginError")) { ##--> // Call user login error event $this->User_LoginError($this->Username, $sPassword); <!--## } ##--> } } <!--##/session##--> ?> <!--##session login_htm##--> <script type="text/javascript"> var <!--##=sFormName##--> = new ewr_Form("<!--##=sFormName##-->"); // Validate method <!--##=sFormName##-->.Validate = function(fobj) { if (!this.ValidateRequired) return true; // Ignore validation if (!ewr_HasValue(fobj.username)) return ewr_OnError(fobj.username, ewLanguage.Phrase("EnterUid")); if (!ewr_HasValue(fobj.password)) return ewr_OnError(fobj.password, ewLanguage.Phrase("EnterPwd")); <!--##include rpt-captcha.php/phpcaptcha_js##--> <!--## if (SYSTEMFUNCTIONS.ClientScriptExist("Other","Form_CustomValidate")) { ##--> // Call Form Custom Validate event if (!this.Form_CustomValidate(fobj)) return false; <!--## } ##--> return true; } <!--## if (SYSTEMFUNCTIONS.ClientScriptExist("Other","Form_CustomValidate")) { ##--> // Form_CustomValidate method <!--##=sFormName##-->.Form_CustomValidate = <!--##~SYSTEMFUNCTIONS.GetClientScript("Other","Form_CustomValidate")##--> <!--## } ##--> // requires js validation <?php if (EWR_CLIENT_VALIDATE) { ?> <!--##=sFormName##-->.ValidateRequired = true; <?php } else { ?> <!--##=sFormName##-->.ValidateRequired = false; <?php } ?> </script> <!--##include rpt-phpcommon.php/header-message##--> <!--##include rpt-phpcommon.php/common-message##--> <?php // Begin of modification Login, by Masino Sinaga, December 4, 2012 ?> <body onload="document.<!--##=sFormName##-->.username.focus()"> <?php // End of modification Login, by Masino Sinaga, December 4, 2012 ?> <form name="<!--##=sFormName##-->" id="<!--##=sFormName##-->" class="ewForm" action="<?php echo ewr_CurrentPage() ?>" method="post" onsubmit="return ewrForms[this.id].Submit();"> <?php // Begin of modification Login, by Masino Sinaga, December 4, 2012 ?> <br /><br /><br /><br /> <?php // End of modification Login, by Masino Sinaga, December 4, 2012 ?> <table border="0" cellpadding="0" cellspacing="0" width="400" align="center"> <tr> <td> <table border="0" cellpadding="0" cellspacing="0" width="420" align="center"> <tr> <td align="left" valign="top" width="4" height="30"><img src="phprptimages/sidebox-title-left.gif"></td> <td align="left" valign="middle" background="phprptimages/sidebox-title-bg.gif" width="390" height="30"> <font class="phpreportmaker"> <strong><!--##@LoginPage##--></strong></font> <?php // Begin of modification Add Help Feature, by Masino Sinaga, June 6, 2012 ?> <a href="#" id="helponline" onclick="MGJS.goTop();return false;"><img src="phprptimages/question.ico" title="<?php echo ewr_HtmlEncode($ReportLanguage->Phrase("help")) ?>" width="16" height="16" border="0"></a> <?php // End of modification Add Help Feature, by Masino Sinaga, June 6, 2012 ?> </td> <td align="left" valign="top" width="4" height="30"><img src="phprptimages/sidebox-title-right.gif"></td> </tr> </table> </td> </tr> </table> <table border="0" cellpadding="0" cellspacing="0" align="center"> <tr valign="top"> <td width="4" align="left" valign="top" background="phprptimages/sidebox-bar-left.gif"><img src="phprptimages/sidebox-bar-px.gif"></td> <td bgcolor="#FFFFFF" width="" align="left" valign="top"> <table bgcolor="#F0F1F5" border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td> <table width="412" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <tr/> <tr> <td width="125"> <span class="phpreportmaker"><!--##@Username##--></span></td> <td width="5"></td> <td width="50"><span class="phpreportmaker"><input type="text" name="username" id="username" size="37" value="<?php echo $<!--##=gsPageObj##-->->Username ?>"></span></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td height="22"> <span class="phpreportmaker"><!--##@Password##--></span></td> <td></td> <td><span class="phpreportmaker"><input type="password" name="password" id="password" size="37" /></span></td> </tr> <tr> <td> </td> <td> </td> </tr> <!--## if (lLoginOptionCount > 1) { ##--> <tr> <td colspan="3"><span class="phpreportmaker"> <!--## if (String("AUTO") in dLoginOption) { ##--> <div class="ewSpacer"><label> <input type="radio" name="type" id="type" value="a"<?php if ($<!--##=gsPageObj##-->->LoginType == "a") { ?> checked="checked"<?php } ?> /><!--##@AutoLogin##--></label></div> <!--## } ##--> <!--## if (String("USER") in dLoginOption) { ##--> <div class="ewSpacer"><label> <input type="radio" name="type" id="type" value="u"<?php if ($<!--##=gsPageObj##-->->LoginType == "u") { ?> checked="checked"<?php } ?> /><!--##@SaveUserName##--></label></div> <!--## } ##--> <!--## if (String("ASK") in dLoginOption) { ##--> <div class="ewSpacer"><label> <input type="radio" name="type" id="type" value=""<?php if ($<!--##=gsPageObj##-->->LoginType == "") { ?> checked="checked"<?php } ?> /><!--##@AlwaysAsk##--></label></div> <!--## } ##--> </span></td> </tr> <!--## } ##--> <?php if (MSR_SHOW_CAPTCHA_ON_LOGIN_PAGE == TRUE) { ?> <!--##include rpt-captcha.php/phpcaptcha_htm##--> <?php } ?> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td><span class="phpreportmaker"><input type="submit" class="msButton" name="btnsubmit" id="btnsubmit" value="<?php echo ewr_BtnCaption($ReportLanguage->Phrase("Login")) ?>" onclick="this.className='msButton:disabled'" /></span> <input name="reset" type="reset" class="msButton" id="Reset" value="<?php echo ewr_BtnCaption($ReportLanguage->Phrase("CancelBtn")) ?>"> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> </table> </td> </tr> </table> </td> <td width="4" align="left" valign="top" background="phprptimages/sidebox-bar-right.gif"><img src="phprptimages/sidebox-bar-px.gif"> </td> </tr> </table> <table border="0" cellpadding="0" cellspacing="0" width="420" align="center"> <tr> <td width="2" height="29" align="left" valign="top"><img src="phprptimages/storybox-bottom-left.gif"></td> <td width="394" height="29" background="phprptimages/storybox-bottom-bg.gif"> <!--## if (bUserTable) { ##--> <span class="phpreportmaker"> <!--## if (PROJ.SecForgetPwdPage) { ##--> <a href="<!--##=sFnForgotPwd##-->"><!--##@ForgotPwd##--></a> <!--## } ##--> <!--## if (PROJ.SecRegisterPage) { ##--> <?php if (MSR_USER_REGISTRATION) { ?> <a href="<!--##=sFnRegister##-->"><!--##@Register##--></a> <?php } ?> <!--## } ##--> </span> <!--## } ##--></td> <td width="8" height="29" align="left" valign="top"><img src="phprptimages/storybox-bottom-right.gif"></td> </tr> </table> <!--## if (lLoginOptionCount == 1) { ##--> <!--## if (String("AUTO") in dLoginOption) { ##--> <input type="hidden" name="type" id="type" value="a" /> <!--## } else if (String("USER") in dLoginOption) { ##--> <input type="hidden" name="type" id="type" value="u" /> <!--## } else if (String("ASK") in dLoginOption) { ##--> <input type="hidden" name="type" id="type" value="" /> <!--## } ##--> <!--## } ##--> <p /> </form> </body> <br /> <script type="text/javascript"> $('form').submit(function(){ $('input[type=submit]', this).attr('disabled', 'disabled'); }); </script> <script type="text/javascript"> <!--##=sFormName##-->.Init(); </script> <!--##include rpt-phpcommon.php/footer-message##--> <!--##/session##--> <?php <!--##session phpfunction##--> // // Validate form // function ValidateForm($usr, $pwd) { global $ReportLanguage, $gsFormError; // Initialize form error message $gsFormError = ""; // Check if validation required if (!EWR_SERVER_VALIDATE) return TRUE; if (trim($usr) == "") { $gsFormError .= ($gsFormError <> "") ? "<div class=\"ewSpacer\"> </div>" : ""; $gsFormError .= $ReportLanguage->Phrase("EnterUid"); } if (trim($pwd) == "") { $gsFormError .= ($gsFormError <> "") ? "<div class=\"ewSpacer\"> </div>" : ""; $gsFormError .= $ReportLanguage->Phrase("EnterPwd"); } // Return validate result $ValidateForm = ($gsFormError == ""); <!--## if (SYSTEMFUNCTIONS.ServerScriptExist("Other","Form_CustomValidate")) { ##--> // Call Form Custom Validate event $sFormCustomError = ""; $ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError); if ($sFormCustomError <> "") { $gsFormError .= ($gsFormError <> "") ? "<div class=\"ewSpacer\"> </div>" : ""; $gsFormError .= $sFormCustomError; } <!--## } ##--> return $ValidateForm; } <!--##/session##--> ?> <?php <!--##session phpevents##--> <!--##~SYSTEMFUNCTIONS.GetServerScript("Other","User_LoggingIn")##--> <!--##~SYSTEMFUNCTIONS.GetServerScript("Other","User_LoggedIn")##--> <!--##~SYSTEMFUNCTIONS.GetServerScript("Other","User_LoginError")##--> <!--##~SYSTEMFUNCTIONS.GetServerScript("Other","Form_CustomValidate")##--> <!--##/session##--> ?>
-
Open your \extensions\CAPTCHA\rpt-captcha.php file, and then replace (Yes, Replace!) all the content of the file with the following code (Warning: Backup your captcha extension file before doing this step!):
<!--##session phpcaptcha_config##--> <!--## // Check if Use Captcha var bUseCaptcha = false; var EXT = EXTS("CAPTCHA"); if (EXT.Enabled) { if (CTRL.CtrlID == "rptlogin") { if (PROJ.SecLoginCaptcha) { bUseCaptcha = true; } } } // Get table variable sTblVar = gsTblVar; ##--> <!--##/session##--> <!--##session phpcaptcha_var##--> <!--## if (bUseCaptcha) { ##--> // CAPTCHA var $captcha; <!--## } ##--> <!--##/session##--> <!--##session phpcaptcha_php##--> <!--## if (bUseCaptcha) { if (CTRL.CtrlID == "rptlogin") { ##--> // Begin of modification Captcha on Login Page, by Masino Sinaga, December 4, 2012 if (MSR_SHOW_CAPTCHA_ON_LOGIN_PAGE == TRUE) { // CAPTCHA checking if (ewr_IsHttpPost()) { $this->captcha = @$_POST["captcha"]; if ($this->captcha <> @$_SESSION["EWR_CAPTCHA_CODE"]) { // CAPTCHA unmatched $this->setFailureMessage($ReportLanguage->Phrase("EnterValidateCode")); // Set message $bValidate = FALSE; } } if (!$bValidate) { $_SESSION["EWR_CAPTCHA_CODE"] = ewr_Random(); } } // End of modification Captcha on Login Page, by Masino Sinaga, December 4, 2012 <!--## } } ##--> <!--##/session##--> <!--##session phpcaptcha_htm##--> <!--## if (bUseCaptcha) { ##--> <!-- captcha html (begin) --> <?php // Begin of modification Captcha on Login Page, by Masino Sinaga, December 4, 2012 ?> <tr> <td > </td> <td > </td> <tr/> <tr> <td colspan="3" align="center"> <?php // End of modification Captcha on Login Page, by Masino Sinaga, December 4, 2012 ?> <?php if (phpversion() < "4.3.2") { echo "<p class=\"ewmsg\">Warning: CAPTCHA extension is enabled but PHP version on this server is " . phpversion() . " only. The extension requires PHP >= 4.3.2.</p>"; } ?> <div><img src="ewcaptcha.php" alt="Security Image" width="200" height="50" /></div><br> <span class="phpreportmaker"><!--##@EnterValidateCode##--><!--##@FieldRequiredIndicator##--></span><br> <input type="text" name="captcha" id="captcha" size="30" /> </td> </tr> <?php // Begin of modification Captcha on Login Page, by Masino Sinaga, December 4, 2012 ?> <!-- </table> --> <!-- <br> --> <?php // End of modification Captcha on Login Page, by Masino Sinaga, December 4, 2012 ?> <!-- captcha html (end) --> <!--## } ##--> <!--##/session##--> <!--##session phpcaptcha_js##--> <!--## if (bUseCaptcha) { ##--> if (fobj.captcha && !ewr_HasValue(fobj.captcha)) return ewr_OnError(fobj.captcha, ewLanguage.Phrase("EnterValidateCode")); <!--## } ##--> <!--##/session##-->
Please note that this step is important, since we have to adjust the layout of captcha to the Login layout page that we have just changed become three columns.
- Finally, re-generate your script files using PHP Report Maker as always.
[/hidepost]
[…] PHP Report Maker Home » PHP Report Maker » Customizing Submit Buttons in Websites that Generated by PHP Report Maker 6.0.0 Customizing Login Page in Websites that Generated by PHP Report Maker 6.0.0 […]