Gossamer Forum
Home : Products : DBMan : Installation :

making modify change the date in the record

Quote Reply
making modify change the date in the record
OK, more strangeness for my database.
I want to make the Modify function automagically update the Date field in the database whenever someone actually modifies their record.

I think the &get_date function can make that happen, but do I need to create a separate function inside the html.pl or db.cgi to make this work?


Additionally, I then want to use the date to do a structured search from a link.

So, for example, when a user clicks the link to display alumni who have recently signed up, I would like to return results sorted from most recent to least most recent, but only if they have been added in the past 30 days.

Would I be better off creating a separate perl program that would search against the alumni.db and return the data in a table for this?

I would like to keep it all in the same set of dbman programs if possible in order to pass the environment from dbman to the other routines.

Jamie


------------------
James A. (Jamie) Dennis
*Certified AIX Administrator
*Certified Solaris Administrator
*Member - SAGE, USENIX
Quote Reply
Re: making modify change the date in the record In reply to
First updating the date field--

In sub html_modify_form_record, just after

my (%rec) = &get_record($in{'modify'});

add

$rec{'Date'} = &get_date;

The second one is a "what's new" routine, which I have been meaning to change in my DBMan mods. But here's what you can do.

Before you print out the link for new records, add

Code:
$days = 30; # set this to whatever number of days you want to be "new"
$new = &get_date(&date_to_unix(&get_date)-($days * 86400));
print qq|<a href="$db_script_link_url&view_records=1&Date-gt=$new&so=descend&sb=0">
<$font>New Records</font></a>|;

substituting the field number for your date field for the 0 in "sb=0" above.

You might also have to fix what seems to be a bug in db.cgi. In sub query, change the bolded things below:

Code:
if ($in{"$column-gt"} !~ /^\s*$/) {
($db_sort{$column} eq 'date') and (&date_to_unix($in{"$column-gt"})
or return "Invalid date format: '$in{$column}'");
push(@search_gt_fields, $i); }
if ($in{"$column-lt"} !~ /^\s*$/) {
($db_sort{$column} eq 'date') and (&date_to_unix($in{"$column-lt"})
or return "Invalid date format: '$in{$column}'");
push(@search_lt_fields, $i); }

You might try it without changing db.cgi, but it wouldn't work for me until I made the change.

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


[This message has been edited by JPDeni (edited February 10, 1999).]
Quote Reply
Re: making modify change the date in the record In reply to
The date stuff you posted ALMOST works. For some reason, when I click the link, the URL looks like this:

http://nadia.alldata.net/cgi-bin/dbman-test/db.cgi?db=alumni&uid=jdennis.91867541367505&view_records=1&Date-gt=10-Feb-1999&so=descend&sb=15

If I change the URL string in the browser to show Date-gt=10-Jan-1999, it pulls records fine.

Here is how my code looks in alumni.pl

$days = 30;
$new = &get_date(&date_to_unix(&get_date)-($days * 86400 ));
print qq!<TD><a href="$db_script_link_url&view_records=1&Date-gt=$new&so
=descend&sb=15"><$font>New Records (last 30 days)</font></a></TD>!;

This looks like what you posted to me.

I have tried changing some of the code to make it work, but have been unsuccessful thus far.



Thanks


------------------
James A. (Jamie) Dennis
*Certified AIX Administrator
*Certified Solaris Administrator
*Member - SAGE, USENIX
Quote Reply
Re: making modify change the date in the record In reply to
Hmmmmmm. I don't know why it's not working.

I'd try some things to figure out what's going on. (I tend to overdo my debugging, but it helps me to see what's happening.)

First, I'd add a line after the $new variable is defined--

print "new = $new";

and just run it to see what it comes up with. It will probably be today's date, though, from what you said.

If it is today's date, copy the $new variable definition, paste it below the current line and then put a # before one of them. (This will help you to test each part of the $new definition, but you won't have to do so much typing.)

In the uncommented line, take out everything but &get_date. Run that. You should come up with today's date.

Then add in the &date_to_unix part--

&date_to_unix(&get_date)

You should come up with a very large number. Make a note of the number.

Take out everything and just put in

$days * 86400

You should come up with 2592000.

Put the other stuff back in, so that the uncommented line looks like

$new = &date_to_unix(&get_date) - ($days * 86400);

You should come up with a number that is 2592000 less than the large number you wrote down before. Write this number down.

Change your uncommented line to be

$new = &get_date([the number you just wrote down]);

When you run it, you should get the date that's 30 days from today's date.

Let me know where you ran into trouble, if you can't find it.


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