Audit Log Installation

Information:

I have tried to make the installation as easy as possible.
However, with the certain knowledge that no matter how idiot proof you make something - nature will provide a better idiot, I feel I must add the following:
Despite the fact that I have used this installation procedure on 11 different applications built with appgini, I in NO way take ANY responsibility for mistakes in the code or that YOU might make - ALWAYS backup you files before attempting a major modification!

Adjustments by Olaf Nöhring, 2019-12 (https://datenbank-projekt.de):
- improved INSERTION: Now, all non-empty fields are written to the auditor table after insert. Until now, only the new primary key was written. - you can easily use a different table name for teh auditor. Simply adjust

$audittablename = "auditor";
in function table_after_change in auditLog_functions.php (and the setup sql or course). - changed auditor table name from Auditor to auditor (script and setup). Note: On Linux systems the tablenames are case sensitive!

Adjustments by Olaf Nöhring, 2019-06 (https://datenbank-projekt.de):
- Trick: Added in docs. Remove access to Auditor from Admin menu, but use regular AppGini table instead, so Auditor stays even when application is regenerated.
- Trick: Remove changes from 'application_root/lib.php', instead place code in config.php which stays in place, even when the application is regenerated.
- Changes to auditLog_functions.php, added , $eo to SQL queries (following vaalonv tip)
- Instead of foreign keys you will see the values the user actually selected (old code to see FKs still in the file). For this to work correct, make sure the order of the fields in your database is exactly like the order of the fields in specific table in AppGini!



ATTENTION!!

Note 1. For the Search/Replace I used 'Notepad++' available here : Notepad++ Home Page

Note 2. I suggest that you wait till your application is ready to go to production before making these changes - although this is NOT essential - (with the proviso that you BACK UP YOUR FILES FIRST!)

Note 3. When it comes to the tedious task of doing the Search/Replace in the Hooks folder. I suggest that you copy the hook files ONLY for the tables you wish to monitor into a separate directory and then BACKUP that directory. I further suggest that you not include 'Lookup' tables.
This way, you can do it speedily using Notepad++'s Search/Replace facility 'Find in Files' and do them all in just six shots.


1. Create the Audit Log Table using the audit_tableSQL.sql file provided.


2. Copy and then Extract the auditlog_files.zip in your application root folder.

The zip file contain only 2 files:
'auditLog_functions.php' -> The functions that allow the audit log to work.
'admin/auditLog.php' -> A table (filterable and pageable) that will be added to the Admin Menu Options.

3. Essential File Modifications.

Trick

If you create a table in AppGini with the name as the Auditor table (i.e. Auditor) and the same fields (case sensitive) as the in the Auditor table, you can build a regular Audit-Table button from AppGini and let user access that with the regular permissions.
Maybe you want to make sure, that noone can change anything in that table.
If you to this, you do not need to make changes in 'admin/incHeader.php' as described now (and thus Auditor will stay in your application even when regenerated.

In 'admin/incHeader.php' - (Adds page to the Admin Menu Options.)

Do find for :


and replace with:


In 'application_root/config.php':

Add the following to the bottom of the file.


-------------------------------------------------------

Trick: The following changes in 'application_root/lib.php' are not needed anymore when you included also

in the /config.php (described directly above), where your changes are not overwritten when updating the files.
Attention: If you modify the admin settings (Admin Area -> Admin settings) the config.php will be overwritten. You can recover your old values from the backup config.bak.php

In 'application_root/lib.php':

Do find for :

and replace with:


-------------------------------------------------------


4. The HOOKs folder. After you've read Note 3, above:

In the temp folder that contains the Hooks for the tables that you wish to monitor:

A. Do 'find in files' for : (Remember to set the correct directory!)

and replace with:

B. Do 'find in files' for :

and replace with:

C. Do 'find in files' for :

and replace with:

D. Do 'find in files' for :

and replace with:

E. Do 'find in files' for :

and replace with:

F. Do 'find in files' for :

and replace with:

Remember to copy the files from the temp directory created in Note 3 back to the original Hooks Folder!

Your Audit Log should now be working! and using this technique will allow you to keep other modifications made to the Hooks folder.
Yours, primitive_man
Discussions about this: Here