PHPMaker has the ability to generate Audit Trail in order to log users activities in your web applications, either using log file or database. I recently using database instead of log file for implementing Audit Trail in most web applications I created. Unfortunately, PHPMaker does not log both CurrentUserID and CurrentUserName values in User column in the audittrail table. For Login/Logout activities, PHPMaker will log only CurrentUserName in User column, meanwhile, for Add/Edit/Delete activities, PHPMaker will log only CurrentUserID in User column of audittrail table.
This following customization will solve the problem by combining the CurrentUserID and CurrentUserName and save them in the User column of your audittrail table. For example, one of your users has UserName as John Doe and this user belongs to the office with value of 40005 as his/her CurrentUserID. So, after implementing this customization, then the value of User column in your auditrail table will become as 40005 - John Doe. This will make your audittrail more informative and more consistent compared to the previous condition.
I have successfully customized PHPMaker template files in order to implement it. In other words, we will not customize any generated web files at all.
Updated on May 30, 2012: This customization has been implemented in PHPMaker version 9.0.2, it matches to each other, and as a result, it works properly.
Updated on July 22, 2012: This customization has been implemented in PHPMaker version 9.0.3, it matches to each other, and as a result, it works properly.
Updated on September 5, 2012: This customization has been implemented in PHPMaker version 9.0.4, it matches to each other, and as a result, it works properly.
Updated on November 29, 2012: This customization has been implemented in PHPMaker version 9.1.0, it matches to each other, and as a result, it works properly.
Updated on February 9, 2013: This customization has been implemented in PHPMaker version 9.2.0, it matches to each other, and as a result, it works properly.
Updated on June 17, 2013: The customization has been handled by using MasinoLogin and MasinoFixedWidthSite extensions. You donβt need to implement the customization below if you use my extensions together with the original PHPMaker Template and Extension files.
[hidepost]
-
Open your \Script\audittrail.php file, and find this code:
<!--## if (bUserID) { ##--> $usr = CurrentUserID(); <!--## } else { ##--> $usr = CurrentUserName(); <!--## } ##-->
then replace it with the following code:
<!--## if (bUserID) { ##--> $usr = CurrentUserID() ." - ".CurrentUserName(); <!--## } else { ##--> $usr = CurrentUserID() ." - ".CurrentUserName(); <!--## } ##-->
-
Still in that \Script\audittrail.php file, find again this code:
<!--## if (bUserID) { ##--> $usr = CurrentUserID(); <!--## } else { ##--> $usr = CurrentUserName(); <!--## } ##-->
then replace it with the following code:
<!--## if (bUserID) { ##--> $usr = CurrentUserID() ." - ".CurrentUserName(); <!--## } else { ##--> $usr = CurrentUserID() ." - ".CurrentUserName(); <!--## } ##-->
-
Still in that \Script\audittrail.php file, find again this code:
<!--## if (bUserID) { ##--> $usr = CurrentUserID(); <!--## } else { ##--> $usr = CurrentUserName(); <!--## } ##-->
then replace it with the following code:
<!--## if (bUserID) { ##--> $usr = CurrentUserID() ." - ".CurrentUserName(); <!--## } else { ##--> $usr = CurrentUserID() ." - ".CurrentUserName(); <!--## } ##-->
-
Still in that \Script\audittrail.php file, find again this code:
<!--## if (bUserID) { ##--> $curUser = CurrentUserID(); <!--## } else { ##--> $curUser = CurrentUserName(); <!--## } ##-->
then replace it with the following code:
<!--## if (bUserID) { ##--> $curUser = CurrentUserID() ." - ".CurrentUserName(); <!--## } else { ##--> $curUser = CurrentUserID() ." - ".CurrentUserName(); <!--## } ##-->
-
Open your \Script\login.php file, and find this code:
ew_WriteAuditTrail("log", ew_StdCurrentDateTime(), ew_ScriptName(), $usr, $Language->Phrase("AuditTrailLogin"), ew_CurrentUserIP(), "", "", "", "");
then replace it with the following code:
ew_WriteAuditTrail("log", ew_StdCurrentDateTime(), ew_ScriptName(), CurrentUserID()." - ".$usr, $Language->Phrase("AuditTrailLogin"), ew_CurrentUserIP(), "", "", "", "");
-
Open your \Script\logout.php file, and find this code:
ew_WriteAuditTrail("log", ew_StdCurrentDateTime(), ew_ScriptName(), $usr, $Language->Phrase("AuditTrailLogout"), ew_CurrentUserIP(), "", "", "", "");
then replace it with the following code:
ew_WriteAuditTrail("log", ew_StdCurrentDateTime(), ew_ScriptName(), CurrentUserID()." - ".$usr, $Language->Phrase("AuditTrailLogout"), ew_CurrentUserIP(), "", "", "", "");
-
Open your \Script\phpfn.php file, and find this code:
ew_WriteAuditTrail("log", ew_StdCurrentDateTime(), ew_ScriptName(), $usr, $GLOBALS["Language"]->Phrase("AuditTrailAutoLogin"), ew_CurrentUserIP(), "", "", "", "");
then replace it with the following code:
ew_WriteAuditTrail("log", ew_StdCurrentDateTime(), ew_ScriptName(), ms_GetCurrentUserID($usr)." - ".$usr, $GLOBALS["Language"]->Phrase("AuditTrailAutoLogin"), ew_CurrentUserIP(), "", "", "", "");
-
Still in that \Script\phpfn.php file, find again this code:
ew_WriteAuditTrail("log", ew_StdCurrentDateTime(), ew_ScriptName(), $usr, str_replace("%n", $retrycount, $Language->Phrase("AuditTrailFailedAttempt")), ew_CurrentUserIP(), "", "", "", "");
then replace it with the following code:
ew_WriteAuditTrail("log", ew_StdCurrentDateTime(), ew_ScriptName(), ms_GetCurrentUserID($usr)." - ".$usr, str_replace("%n", $retrycount, $Language->Phrase("AuditTrailFailedAttempt")), ew_CurrentUserIP(), "", "", "", "");
-
Still in that \Script\phpfn.php file, find again this code:
ew_WriteAuditTrail("log", ew_StdCurrentDateTime(), ew_ScriptName(), $usr, $Language->Phrase("AuditTrailUserLoggedIn"), ew_CurrentUserIP(), "", "", "", "");
then replace it with the following code:
ew_WriteAuditTrail("log", ew_StdCurrentDateTime(), ew_ScriptName(), ms_GetCurrentUserID($usr)." - ".$usr, $Language->Phrase("AuditTrailUserLoggedIn"), ew_CurrentUserIP(), "", "", "", "");
-
Still in that \Script\phpfn.php file, find again this code:
ew_WriteAuditTrail("log", ew_StdCurrentDateTime(), ew_ScriptName(), $usr, $Language->Phrase("AuditTrailPasswordExpired"), ew_CurrentUserIP(), "", "", "", "");
then replace it with the following code:
ew_WriteAuditTrail("log", ew_StdCurrentDateTime(), ew_ScriptName(), ms_GetCurrentUserID($usr)." - ".$usr, $Language->Phrase("AuditTrailPasswordExpired"), ew_CurrentUserIP(), "", "", "", "");
-
Still in that \Script\phpfn.php file, find again this code:
// include shared code
before that line, please insert the following code:
function ms_GetCurrentUserID($usr) { global $conn; <!--## if (bUserID) { FIELD = SECTABLE.Fields(DB.SecuUserIDFld); sFld = SQuote(DB.SecuUserIDFld); } ##--> $secUserID = "<!--##=GetFldVal(sFld, FIELD.FldType)##-->"; // Load User ID $sFilter = str_replace("%u", ew_AdjustSql($usr), EW_USER_NAME_FILTER); if (($rsUI = $conn->Execute("SELECT ".$secUserID." FROM ".EW_USER_TABLE." WHERE ".$sFilter."")) && !$rsUI->EOF) { $rsUserID = $rsUI->fields("".$secUserID.""); $rsUI->Close(); } else { $rsUserID = ""; } return $rsUserID; }
- Finally, re-generate your script files using PHPMaker as always. π
[/hidepost]
[…] note that you have to implement the customization that I wrote it in this article before doing customization […]