dscalcione
Posts: 5
|
| Posted: 01/27/2009, 9:59 AM |
|
Is it possible to determine what a fields orignal value was in the BeforeUpdate event?
Thanks,
_________________
David Scalcione |
 |
 |
jsherk
Posts: 34
|
| Posted: 01/27/2009, 3:19 PM |
|
Can you be a little more specific about what you are trying to do... are you talking about the value that is currently in the database that is about to be overwritten by a new value that is being supplied when you click Update?
|
 |
 |
dscalcione
Posts: 5
|
| Posted: 01/27/2009, 5:21 PM |
|
I am implementing an audit feature that will log a record in another table that contains the original values of a changed record and the new values submitted by the form. It's important that I am able to get the old values in the table prior to the form submission so I can log that information.
Thanks,
_________________
David Scalcione |
 |
 |
Waspman
Posts: 948
|
| Posted: 01/28/2009, 4:05 AM |
|
I do this with a hidden "holder " field populated with original value...
T
_________________
http://www.waspmedia.co.uk |
 |
 |
dscalcione
Posts: 5
|
| Posted: 01/28/2009, 6:26 AM |
|
I thought about doing that, but anyone could override the values of the hidden fields and defeat my auditing system. Software such as the Web Developer toolbar for Firefox lets you convert hidden fields to fillable fields so that the values can be changed before submission.
_________________
David Scalcione |
 |
 |
datadoit
|
| Posted: 01/28/2009, 7:11 AM |
|
In your record form's BeforeShow, capture the field values and place
them into sessions:
CCSetSession("orig_Field1", $Container->ds->f("Field1"));
CCSetSession("orig_Field2", $Container->ds->f("Field2"));
etc.
Then in the form's AfterUpdate event:
if (CCGetFromPost("Field1") != CCGetSession("orig_Field1")) {
insert_log("Field1", CCGetSession("orig_Field1"),
CCGetFromPost("Field1"));
}
Finally, anywhere in your events code put the function (could even be
more generalized and reside in your own functions file):
function insert_log($field, $orig, $new)
{
$db = new clsDBConnection();
$SQL = "INSERT INTO log_changes SET "
. "user_id=" . $db->ToSQL(CCGetUserID(), ccsInteger) . ", "
. "module='applications', "
. "screen='detail', "
. "db_table='tbl_applications', "
. "primary_key=" . CCGetFromPost("YourPrimaryKeyField") . ", "
. "db_field=" . $db->ToSQL($field, ccsText) . ", "
. "original_value=" . $db->ToSQL($orig, ccsText) . ", "
. "new_value=" . $db->ToSQL($new, ccsText);
$db->query($SQL);
$db->close();
} //end of function insert_log().
|
|
|
 |
maxhugen
Posts: 272
|
| Posted: 02/02/2009, 7:14 PM |
|
The other option is to query the database in the BeforeUpdate event, and compare the existing values to the posted ones.
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com |
 |
 |
|