Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Auto Change of Mod_Date via Admin

Quote Reply
Auto Change of Mod_Date via Admin
Hmmm,

If a record gets updated or changed via a user modification, the modification date for the record will also get updated, (assuming the change has been validated).

Is there a way to change the Mod_Date for a record when the admin makes changes to a record. Currently, One has to manually change the mod_date in order for the change to be reflected when building.

What I'm trying to do is recording the last date the record was actually changed whether by admin or by user or whatever.

I had hoped I could say something like
$form = $db->build_html_record_form ($hits, {...
Mod_Date => \&get_date,
...
});

Doesn't work. Just get an error saying can't find the subroutine get_date.

Anybody have any ideas on this?

Peace.

Kyle
Quote Reply
Re: Auto Change of Mod_Date via Admin In reply to
Try $db->get_date() instead.

Cheers,

Alex
Quote Reply
Re: Auto Change of Mod_Date via Admin In reply to
Thanks Alex, but ... Doesn't work,

But - I discovered this work around which probably needs some help, but it works, the only downside I can think of is that I can not see when the last Mod_Date was if I'm Modifying (I can however, If I'm viewing or deleting.)

I did this:

IN Admin_HTML.pm

TO sub html_modify_mult_form {
AND
TO sub html_modify_form_record {


CHANGED:

print $db->build_html_record_form ($hit, { multiple => 1, show_attach => 1, base_url => "$SCRIPT_URL?do=show_attach&db=$DATABASE&config=$CONFIG&ID=", CategoryID => \&build_category_row...

TO:
... \&build_category_row,
Mod_Date => \&get_mod_date....

(add , after &get_mod_date if necessary)



NOW BECAUSE I'VE ALLREADY CHANGED:
sub build_html_record_form {
...
if (ref $opt->{$field} eq 'CODE') { $output .= &{$opt->{$field}}($name, $value, $rec); }
...
TO:

...if (ref $opt->{$field} eq 'CODE') { $output .= &{$opt->{$field}}($name, $value, $rec, $self); }...


I WAS THEN ABLE TO ADD to DB_Utils based on DBSQL.pm:

sub get_mod_date {
# ---------------------------------------------------------------
# Return todays date (self may or may not be an object).
#

my $name =shift;
my $value =shift;
my $rec =shift;
my $self = shift;
#Clean up the visible name for the Mod_Date field when modifying multiple
my $last = rindex ($name,"-");
my $new_name = substr($name,0,$last);
ref $self ? return "<tr><td align=right valign=top width=20%><font face='verdana,arial' size=2> $new_name </font></td><td width=80%><input type=text name=$name value=" . &_unix_mod_to_date (@_) . "></td></tr>\n" : return &_unix_mod_to_date($self);
}

AND COPIED FROM DBSQL.pm ALL OF:

sub _unix_mod_to_date {

}

FINALLY, in DB_Utils.pm

Added to the @EXPORT list at the the top:

&get_mod_date &_unix_mod_to_dat

And it works, and nph-build.cgi acknowledges the update (It works like a car odometer!).

Please Please let me know if I've done something wrong OR if there's an easier way to do it!

Peace.

Kyle
Quote Reply
Re: Auto Change of Mod_Date via Admin In reply to
I think there is an easier way. The first argument to build_html_record_form is a hash ref of name => value. So what you want to do is update that. Try adding:

$hit->{Mod_Date} = $db->get_date();

just before the call to $db->build_html_record_form ...

This will overwrite the default mod_date with todays date.

Cheers,

Alex
Quote Reply
Re: Auto Change of Mod_Date via Admin In reply to
I made the change you suggested, I did make this change though:
$hit->{Mod_Date} = $db->get_date();
TO
$hits->{Mod_Date} = $db->get_date();

and placed it above

$form = $db->build_html_record_form ($hits, { show_attach => 1,....

This is the result:

Not a HASH reference at Links/Admin_HTML.pm line 1014. (that's the added line)

This error message always confuses me and I'm never really sure what makes it go away.

Peace.

Kyle
Quote Reply
Re: Auto Change of Mod_Date via Admin In reply to
Oops, that error means $hits is _not_ a hash reference. It is an array reference. So what you need to do is add:

$hits->[16] = $db->get_date();

where 16 is the position of your Mod_Date in your .def file.

Cheers,

Alex
Quote Reply
Re: Auto Change of Mod_Date via Admin In reply to
Ah yes, That took care of it, but there's a couple of notes to make on this for anyone else whose listening.

Quote:
$hits->[16] = $db->get_date();

where 16 is the position of your Mod_Date in your .def file.
Counting begins at 0. The .def file starts at counting at 1. So for example, my Mod_Date says it's 5 but for this code, I had to put in 4.

Also, when doing this for modify_multiple you have to change $hits to $hit.

Thanks for following through on this Alex,

Peace.

Kyle
Quote Reply
Re: Auto Change of Mod_Date via Admin In reply to
Found another problem with this. This mod also effects my Category database which fortunately is just my keyword field. Is there a good way to prevent it from automatically writing to that database.

I thought perhaps of saying something like
$hits->[4] = $db->get_date() if ($DATABASE eq "Links");

Which works, but I always dislike hardcoding anything. Any ideas?

Peace.

Kyle