Gossamer Forum
Home : Products : DBMan : Customization :

Assistance with expiration date field

Quote Reply
Assistance with expiration date field
Hi - I found a record on the FAQ board (#468) about having an expiration date field (admin only) in my database that would take the date field and add any number of days to it (most likely 365 days) and input that new date into the expiration date field. Well when I go to add a record, it keeps showing the current date in the expiration date field as well as the current date field. Same thing when I view the record after I add it. I tried to figure it out per the FAQ record, but it isnt working for me, so im hoping that someone can possibly tell me where I have gone wrong.

I've only made changes to 3 subs in the db.cgi record...which are the add_record, get_date and added the new calc_date subs, but it must be set up wrong. Here is the text file of those 3 subs if someone could please take a look and let me know if they see anything wrong. Thanks and Happy Holidays!! Smile

http://www.wdu.net/dbtext.txt
Quote Reply
Re: [wdu2002] Assistance with expiration date field In reply to
Just checking but you do have all the fields within the sub defined in your .cfg file and they are exactly the same field names?

sub calc_date {
#------------------------------------------------------------
my ($temp_date);
$temp_date = &date_to_unix($in{'Date'});
$temp_date = $temp_date + ($in{'Days'}*86400);
$in{'Expdate'} = &get_date($temp_date);
}

You have the following fields?

Date - start date
Days - define number of days
Expdate

Are you calling the sub within:

sub add_record and sub modify_record

using:

&calc_expire_date; # added to increment expired field



Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Assistance with expiration date field In reply to
Lois,

I double checked and I do have all the field names correct in the cfg file, but maybe I have something confused in the subs. Per the instructions on the FAQ that I am using as a guide, I have this:
Code:
$status = &validate_record;
&calc_date;

That is in 3 places after all of the validate record lines in the add_record sub. Im not exactly sure where to put the calc_expire_date. Wouldn't I also need to have a seperate sub for the calc_expire_date just like the calc_date and get_date ones? The FAQ didnt say anything about that either. I also do have the right fields, but Im only using the date and expdate fields. The days field is named in the cfg file, but I dont have it on the add form or records because I want it to do this automatically, so I dont want to have to input the number of days I want it to increment with each record. Maybe you can explain a little more to me? Thanks for your help! Wink
Quote Reply
Re: [wdu2002] Assistance with expiration date field In reply to
You do only need the one sub for what you are trying to do.

quote:
The days field is named in the cfg file, but I dont have it on the add form or records because I want it to do this automatically, so I dont want to have to input the number of days I want it to increment with each record.

When you list fields in the .cfg file you MUST have them in the add form. Either as regular or hidden fields, if not, you will have problems.

How are you going to determine the number of days if you don't define it within either the add form or as the default value within the .cfg file field definition?




Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Assistance with expiration date field In reply to
Lois,

Thanks for the info on the add form. I will add the days field in as a hidden field.

But in answer to your question about defining the days field. I want it to be setup so when a new user (one that hasnt paid) goes to submit a new record, the expiration date is automatically set for 90 days. (They wont see this, I have it set for admin only). But if they login before the 90 days are up and pay for their membership, the expiration date needs to be "renewed" til 365 days later. So my problem is, I dont want the user to be able to see or change the expiration date or the "days" field, but the expiration dates will vary according to the user (whether they have paid or not), so assigning a default value in the field name in my cfg file wont work since there will be 2 different expiration dates. Does this make sense? I'm just trying to figure out how to have the expiration date default to 90 days, but that I am able to go back in as an admin when someone pays and change just that record (not the default) to 365 days.
Quote Reply
Re: [wdu2002] Assistance with expiration date field In reply to
If you set a default for the number of days, you can then afterwards enter a different value in that field.

Defaults just set what is initially shown.

There are various threads in the FAQ noted below regarding dealing with dates and I know there is an example of automatically setting dates for 90 days ahead.



Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/