You have decided you wish to log all access to every table in your database. You have tried the method as posted by Ahmad on the main site but it will not work or you just get a blank page each time.
Here is the link on the AppGini site:
http://www.bigprof.com/appgini/help/adv ... obal-hooks
Here is the code from that link:
function login_ok($memberInfo, &$args){
// the log file where we'll save member activity
$logFile='members.log';
// the member details we'll be saving into the file
$username=$memberInfo['username'];
$ip=$memberInfo['IP'];
$date=date('m/d/Y');
$time=date('h:i:s a');
// open the log file and append member login details
if(!$fp=@fopen($logFile, 'a')) return '';
fwrite($fp, "$date,$time,$username,$ip\n");
fclose($fp);
return '';
}
But it will just not work for you. Simple fix. Remove the last return ''; and past it into yourtablename.php in hooks folder in the yourtablename_init function so it looks like this now. (Make sure you have a unique file name for your log file).
Code: Select all
function yourtablename_init(&$options, $memberInfo, &$args){
//the log file where we'll save member activity
//added to create log file
$memberInfo = getMemberInfo();
$logFile=uniquename.log'; //this can also be a .txt file if you wish
// the member details we'll be saving into the file
$username=$memberInfo['username'];
$ip=$memberInfo['IP'];
$date=date('m/d/Y');
$time=date('h:i:s a');
// open the log file and append member login details
if(!$fp=@fopen($logFile, 'a')) return '';
fwrite($fp, "$date,$time,$username,$ip\n");
fclose($fp);
//end of log file capture
return TRUE;
}
One thing I do with this data is I save it to a table in my database where it records username and other info. This way I can check to see who is looking at what to check to see if the table is being used or not. I also write to another table when a entry is changed and by whom to insure I can track who is making changes to data in tables. This gives me an ongoing record of changes, when and by whom. I do not track what change was made.
This is also done by putting code in the hook file in the function yourtablename_after_update($data, $memberInfo, &$args) area of the hook file. I create a table in AppGini with the fields I wish to record and then write my own code to update it. I turn off the ability for anyone to create a new record in that table and access is very limited. It records user name, date, time, table changed and other tidbits. I am also working on writing a routine to record what was changed. This is just a matter of putting into an array the existing record data then running a comparison when the record is updated between what is in the array of existing data and what is different then recording that info into the same table.
Hope this helps someone.
Alan