Audit Trail

QuestionsAudit Trail
Benjamin asked 10 years ago

Hi,

I'm running the Premium versionand have questions about an additional audit trail table I'd like to write each time a record is update in the grid.

I need to log the column name, the value before … I use the on_update function … it works fine but I don't know how to get the column name and the value before.

Does someone can help ?

Thanks a lot
Benjamin

7 Answers
Abu Ghufran answered 10 years ago

I guess you already know, it's doable with on_insert / on_update event callbacks.
In those events handler functions, you get $data array that has key names as columns
in this way: $data["params"]["field"]

For before value, you will need to run an additional sql, that will fetch data in on_update.
e.g. select * from table where id = $data["id"]

Benjamin answered 10 years ago

Yes, I use the on_update function in which I insert a line in Audit table.
That work but I don't know how to get the column header that has changed.

I tried print_r($data) and/or phpgrid_error("blabla") but then I have an error 500 … difficult to see what is happening.

Thanks

Abu Ghufran answered 10 years ago

in event handler try this …

function my_insert($data)
{
ob_start();
print_r($data);
$str = ob_get_clean();
phpgrid_error($str);
}

This would print the $data as error message so you can debug.

Benjamin answered 10 years ago

Nothing is printed … or maybe it is printed behind of <iframe> …
I tried a "brutal" solution by added an "exit;" … nothing more 🙁

I get the value before with an additional "select …" but always do not hva the column label (header) ..

Abu Ghufran answered 10 years ago

You get $data array of this format:

/*
These comments are just to show the input param format

$data => Array
(
[client_id] => 2
[params] => Array
(
[client_id] => 2
[name] => Client 2
[gender] => male
[company] => Client 2 Company
)

)
*/

The params key contains column name with new posted value.
You can run foreach loop to get both in event handler.

kim answered 10 years ago

i need to create an audit trail table to keep track of add and edit transactions along with user, date and time of transactions.
is there an example in the package i can review to help me get started?

thank you.

Abu Ghufran answered 10 years ago

Hello Kim

Sample is not currently available. However i can help in some code snippets.

http://pastebin.com/GvV8bXN9

Your Answer

12 + 2 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?