Gossamer Forum
Home : Products : DBMan : Customization :

Time stamp for new modifications to old record

Quote Reply
Time stamp for new modifications to old record
Hello.

I need to add an automatic timetamp to modifications made to old records.

Example: User A adds record to dbman, saves and it's accepted. Days later user B comes and changes this record. I would need a date and time for this new change added automatically to this record. It doesn't need to be hidden or anything.

If anyone can help me with this, I would appreciate a 'cut and paste' since I'm learning as I go along. I have changed the entire database, record view and such, but I don't know how to add this.

Thanks in advance to everone who will help.

Sincerely,

Richard
Quote Reply
Re: [ryl] Time stamp for new modifications to old record In reply to
Do you only want the latest modification, with date/time and perhaps also user name, recorded in the database, or should there be something like a traceable history of all modifications? Needless to say, the former is much easier to code :-)
kellner
Quote Reply
Re: [kellner] Time stamp for new modifications to old record In reply to
To update the date and userid when a record is modified you could use:

Create a new fields called:

LastModified - date
LastModifiedBy


In html.pl, sub html_modify_form_record, just after the line that starts with

if (!%rec) { &html_modify_failure(

add

$rec{'LastModified'} = &get_date; # Last modified date
$rec{'LastModifiedBy'} = $db_userid;

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

To create just a time stamp with userid you could try something like this:

Create a field called Modified

In DB.CGI, in sub modify_record after:

my ($status, $line, @lines, @data, $output, $found, $restricted);

$date = &get_date;
$time = &get_time;
$timestamp= "$date $time $db_userid";
$in{'Modified} .= "\n\n$timestamp\n\n";

I know someone will clean up this code if needed :)

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [kellner] Time stamp for new modifications to old record In reply to
Hi Kelner, thanks for replying.

Yes I want the latest modification, with date/time and perhaps also user name, recorded in the database as a new entry.

Thanks for the help.

Ryl
Quote Reply
Re: [ryl] Time stamp for new modifications to old record In reply to
In that case, I would recommend LoisC's second suggestion, with a slight modification:

Instead of

$in{'Modified} .= "\n\n$timestamp\n\n";

you can just use:

$in{'Modified'} = "$timestamp";
kellner
Quote Reply
Re: [LoisC] Time stamp for new modifications to old record In reply to
Thanks Lois.

I'll try the second suggestion which is what I needed.

Will this timestamp appear only in the modification form or in the original enty form as well?

Thanks again for the help.

RYL
Quote Reply
Re: [kellner] Time stamp for new modifications to old record In reply to
Grrr get rid of those quotes Cool

$in{'Modified'} = $timestamp;

Last edited by:

Paul: Mar 29, 2002, 4:55 AM
Quote Reply
Re: [Paul] Time stamp for new modifications to old record In reply to
Well, then:

$in{Modified} = $timestamp; Wink



And, while we're at it: it would be a *great* idea to declare variables locally.
kellner
Quote Reply
Re: [kellner] Time stamp for new modifications to old record In reply to
Where I got the this code from was adding user comments mod. The timestamp was added to the response field each time someone added a comment

$in{'Modified} .= "\n$timestamp";

so that is why it had the ".=" and also the line break.
This was used for a textarea field, which would be needed if you are going to allow for extra lines.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Time stamp for new modifications to old record In reply to
Yes, I thought so. That would work if you wanted to trace an entire history of modifications.

But as this does not seem to be desired in the present case, it won't be necessary. (Besides, it would also require adding a hidden "Modify" field to html_record_form, for otherwise the earlier modification timestamps would get lose.)
kellner
Quote Reply
Re: [kellner] Time stamp for new modifications to old record In reply to
O.K. So if I get this right (and I may be stating the obvious and hoping not to frustrate the people who understand this stuff so well):

I Create a field called Modified; this would be in within default.cfg within %db_def = (....................
)

Then in
DB.CGI,

in sub modify_record

after:
my ($status, $line, @lines, @data, $output, $found, $restricted);

I enter the following:

$date = &get_date;
$time = &get_time;
$timestamp= "$date $time $db_userid";
$in{'Modified'} = $timestamp;

All this would mean I would also have to create a new record field in
sub html_record_form (do I make it hidden so as not to see it when entering data in the initial filling of the form?)
And I would also have to create a new field within the sub html_record section to actually see it when modifying the record).

Am I understanding this right??

Thanks again.

RYL
Quote Reply
Re: [ryl] Time stamp for new modifications to old record In reply to
In html_record_form, I don't think you'll need an additional form field. Not if you just want the last timestamp added when modifying. Just make sure the field "Modify" in the %db_def is NOT obligatory (i.e. has "0" for "non_null"). The value of "Modify" will be added *after* the modification form is submitted, and you're not going to edit this field manually anyway.

In html_record, print $rec{'Modify'} wherever you want to see the timestamp.
kellner
Quote Reply
Re: [ryl] Time stamp for new modifications to old record In reply to
Quote:
I have changed the entire database, record view and such, but I don't know how to add this.

To avoid an often made mistake, (once you get your database set up like you want it) - start out with an "empty" db file. Or if you have to add fields (in the .cfg file) to an already existing database, then don't forget to stick in the appropriate additional delimiters in your database.

Example (existing default.db):

Joe|Smith|123 Main|Anytown|TX|77220
Bob|Jones|PO Box 4|Mytown|FL|33200

After adding a field called "Middle Name" you'll have to stick in an additional "|" in the existing records or your data will print out all whacky.

Example (default.db after adding new field):

Joe||Smith|123 Main|Anytown|TX|77220 (existing record)
Bob||Jones|PO Box 4|Mytown|FL|33200 (existing record)
Frank|L.|Doe|456 Maple|Yourtown|NY|10002 (new record)

Hope this makes sense...
Quote Reply
Re: [Watts] Time stamp for new modifications to old record In reply to
If you're not auto-generating your html_record_form and would like fields to be displayed on that form in a set sequence, you actually needn't bother adding the additional field at a particular position in the middle of the line.

You can just add it at the end: in your text-editor, replace all linefeeds with "|" + linefeed, and your field is added.
kellner
Quote Reply
Re: [kellner] Time stamp for new modifications to old record In reply to
Thanks for all the help, I'm closer but not there yet.

I can see the 'modified' field in the database file but it's not displayed anywhere when I go list all or search or even in the 'modified successfully' results page.

How can I view the content of the modified field info when displaying any kind of results?

Thanks again.

When this modification is finally working I'll be moving to another mod. Poor people.... But it's sooo appreciated.

Ryl
Quote Reply
Re: [ryl] Time stamp for new modifications to old record In reply to
If you added an extra field to both your .cfg file and your html add form then it should be storing the timestamp value in the database. If so, you can dispay the field using:

$rec{'modified'}
- changing it to what you called the field.

Any field in your .cfg file MUST have a matching field in your add form.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Time stamp for new modifications to old record In reply to
No, Lois, I don't think it's necessary for all fields to be present in add forms.

If the value of $in{'modified} is automatically generated in sub modify_record, you don't need it. When a new record is added, dbman creates the line in sub join_encode. This takes all values of %in and matches them to the database columns. If there's no value for a field, then the database column will simply be left empty.
kellner
Quote Reply
Re: [LoisC] Time stamp for new modifications to old record In reply to
Thanks for all the help.

It works fine and looks good.

Sincerely,

Ryl
(Now on to the next task.)