Gossamer Forum
Home : Products : DBMan : Customization :

Time and Date Stamp

Quote Reply
Time and Date Stamp
On my database I have a notes/comments Field, What I want to do is be able to put a time stamp on when some one adds data to that field e.g

10/05/99 SimonT
DBman run's well under NT
10/06/99 JohnD
Dbman run's well under Unix

But the thing is that I dont want John to be
able to change what SimonT has written, Also it would be nice if the time stamp could come from the server rather than from the client.

Any one got any ideas ??


Quote Reply
Re: Time and Date Stamp In reply to
There was a long discussion about how to let users add to a field without being able to change the contents of the field a while back. I just can't remember enough about it to be able to find it in the search. So I guess I'll try to recreate it from memory. Smile

You'll need to make another subroutine to create your "user comments" form. (You could use html_record_form, but it would get really messy with a lot of "if" statements.)

Change anything in bold print to fit your database.

Code:
sub html_user_comment_form {
my (%rec) = @_;

foreach $column (@db_cols) {
print qq|<input type="hidden" name="$column" value="$rec{$column}">|;
}

&html_record(%rec); # prints out the current contents of the record

print qq|<textarea name="new_comment" rows=5 columns="40 wrap="virtual"></textarea>|;
}

In html_modify_form_record change

&html_record_form (%rec);

to

Code:
if ($per_admin) {
&html_record_form (%rec);
}
else {
&html_user_comment_form (%rec);
}

The above assumes that you only want the admin to be able to modify the other information in the database. If users will be adding records, and will "own" the records (and be allowed to modify them), use the following instead:

Code:
if (($per_admin) &#0124; &#0124; $rec{'Userid'} eq $db_userid)) {
&html_record_form (%rec);
}
else {
&html_user_comment_form (%rec);
}

Take out the space between the two | characters above.

In db.cgi, in modify_record

after

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

add

Code:
if ($in{'new_comment'}) {
$date = &get_date;
$time = &get_time;

$timestamp= "$date $time $db_userid";
$in{'Comments'} .= "\n$timestamp\n$in{'new_comment'}";
}

This will add a linefeed to the end of the comment field and add the new comment to the end of it.

This does assume that the user is logged in. Otherwise the $db_userid will equal "default."

This is very different from the previous discussion, but I'm pretty sure it will work. I haven't tried it, though.

There is a potential for security problems with this. A user could save the form to his own computer, edit the hidden fields, load the form back into his browser and click the submit button. If that's a concern for you, I'll try to remember the other way we did it.

------------------
JPD





Quote Reply
Re: Time and Date Stamp In reply to
Thats fine I will try this out tonight on my server. Security problems/issues not to worry
not a problem in this case.
Quote Reply
Re: Time and Date Stamp In reply to
How do you post a time and date stamp for the whole database on the Main Menu?? I would like to put a "Last Updated" message at least the Main Menu.

Any thoughts or ideas?

TIA.

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Time and Date Stamp In reply to
You would need to put a time and date stamp on each record when it is added or modified. Then do a search through all the records and sort (descending) by the time and date stamp field.

I suppose if you wanted to you could add another file to your directory that would write the time and date whenever a record is added or modified. It would work similar to the .count file. Then you'd just have to open the file from the home page.


------------------
JPD





Quote Reply
Re: Time and Date Stamp In reply to
I just ran across another way to find out the last time a record was modified, which is a little easier.

(I'm pretty sure this will work.)

Add a subroutine to db.cgi:
Code:
sub get_date_and_time {

my ($time) = @_;
($time) &#0124; &#0124; ($time = time());
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");

# if you want the time returned in "am/pm"
# format, uncomment the lines below

# ($hour > 11) ? ($am_pm = "pm") : ($am_pm = "am");
# if ($hour > 12) { $hour -= 12; }
# elsif ($hour < 1) {$hour = 12; }

return "$months[$mon]-$day-$year $hour:$min:$sec $am_pm";
}

(Be sure to remove the space between the two | characters above.)

Then, at the beginning of the html subroutine where you want to print out the date and time, use

Code:
$last_mod = &get_date_and_time(time() - ((-M $db_file_name) * 86400));

Wherever you want to print out the last modified date and time, use the variable $last_mod.


------------------
JPD





Quote Reply
Re: Time and Date Stamp In reply to
Works like a charm! Thanks, JPDeni!