Gossamer Forum
Home : Products : DBMan : Customization :

Age mod installed, something wrong!

Quote Reply
Age mod installed, something wrong!
Hey,

I have a database at:
http://thor.prohosting.com/~eoinc/cgi-bin/dbman/db.cgi
guest/guest

Then click List All and you'll see that it's a pen pal database. I was helped here before with a mod. The users' birthdates are stored, then their age is calculated when the record is viewed. The problem: their age is now shown as 2000, no matter what their birth date.
I have the files at:
http://thor.prohosting.com/~eoinc/cgi-bin/dbman/

default.cfg.txt
html.pl.txt
default.db.txt

Anyone sees what's going wrong?

Thanks, Eoin
i.am/eoin


[This message has been edited by eoin (edited April 21, 2000).]
Quote Reply
Re: Age mod installed, something wrong! In reply to
Can you give me some idea of where the code is that you installed? It's been a really long time since I wrote that and I don't remember what I did.

I wasn't able to access your database. (I got an error message -- Maybe you didn't strip carriage returns.)

The only one of the files I could read was the .cfg file and the code isn't there.

You will need to copy the files to a directory where you would place .html files and don't just tack .txt onto the names of the files. You need to change the . to a _ --

html_pl.txt

The file I think I need to see is db.cgi, so you'll need to copy it to the other directory and rename it to

db_cgi.txt



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






Quote Reply
Re: Age mod installed, something wrong! In reply to
Ok, i hope this post is more usefull.

I have put the txt files at the following URL:

http://thor.prohosting.com/~eoinc/dbman/

default_cfg.txt
db_cgi.txt
default_db.txt
html_pl.txt
date_translator.txt (the mod, but the age calculation is in html_pl.txt)

What I've noticed is that the test records that I added just recently are showing the correct age. The other older records are all showing 2000 as age for some reason. I imported the database into Excel, and I saw no differences between the different records that would cause the problem with age.

Also, a possibly unconnected problem is when I search with name as * wildcard and sorting date, descending, my recent test records are shown on top, but the rest seem to be unordered. The date is the date the record was added, and there are some records from March 2000 which do not show just after my April 2000 added records. The rest of the records were added August 1999 (the majority of records).

Thanks for this.
Eoin
i.am/eoin
Quote Reply
Re: Age mod installed, something wrong! In reply to
That helps a lot.

I'm going to have to look over the mod again and see what's going on. I may have made a mistake with it.


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






Quote Reply
Re: Age mod installed, something wrong! In reply to
I took a look at your .db file and I saw that, indeed, the date is different. The older records (before your test records) have a format of

18-Sep-51

while your test records have the format of

10-Apr-1963

The mod was set up to translate dates that include a 4-digit year. However, I have made some changes to the mod so that it will translate some 2-digit years. Specifically, it assumes that a 2-digit year is within the past 100 years.

You need to replace your sub date_to_unix with the one at http://www.jpdeni.com/.../date_translator.txt . I have tested the code and it will return a correct age for either 4-digit or 2-digit years (as long as the two-digit year is within the last 100 years).





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






Quote Reply
Re: Age mod installed, something wrong! In reply to
Hey,

Thanks for your time. I replaced the sub date_to_unix and no success because the records still show 2000 as age. I installed the whole mod again just in case but no success. How does the script decide that the date is in the 1900s or 2000s in the year is only two digit? By the way, in html.pl the working out of the age is done by:

$birth = int((&date_to_unix(&get_date()) - &date_to_unix($rec{'birth'}))/10000);

and then just put in the page with $birth.

I think the thing for me to do is convert the format in my database to a 4 digit year.

I know I'm going off the point a bit, but I'd like to force users to add a 4-digit year (the records accept a 2-digit year when adding the record). The very ideal thing would be a drop down menu for the days 1-31, a drop down menu for the months January-December and then a text box where the two digits after 19.. have to be typed in by the user for the year. Am I asking for two much? Smile

Eoin
i.am/eoin
Quote Reply
Re: Age mod installed, something wrong! In reply to
I've been doing a little research. Check out the default.db as it is now:

http://thor.prohosting.com/~eoinc/dbman/default_db.txt

The last two records are my tests today, and the year is added in 4-digits. They are being shown as age 2000. The the next 4 records before that up to Karen Toole show the proper age. Then William Cooke the record above them shows age 2000, along with the rest of the records. If you want to check out the search, the log-in info is in my post above.

So i don't understand why some of the 2-digit years show the right age, most of the 2-digit years show age 2000 and the 4-digit years (my tests) show age 2000. I'm confused.

Eoin
i.am/eoin
Quote Reply
Re: Age mod installed, something wrong! In reply to
I'm not sure what your problem can be. I tested the subroutine before I posted and it works on my computer. Are you sure you uploaded the db.cgi script after you changed it?

Code:
@date_part = split '-',$date;
$year = $date_part[2];
$year = int($year);
if ($year<100) {
my ($lsec, $lmin, $lhour, $lday, $lmon, $lyear, $ldweek, $ldyear, $ldaylight) = localtime(time());
$lyear +=1900;
$year +=2000;
if ($year > $lyear) {
$year -= 100;
}
}

I tested it on my computer, artifically changing the year to 2017 and 2050, and it worked just fine.

Quote:
By the way, in html.pl the working out of the age is done by:

$birth = int((&date_to_unix(&get_date()) - &date_to_unix($rec{'birth'}))/10000);

and then just put in the page with $birth.

Yep. That's the code I tested.

Quote:
I think the thing for me to do is convert the format in my database to a 4 digit year.

That would probably be a good idea.

Quote:
The very ideal thing would be a drop down menu for the days 1-31, a drop down menu for the months January-December and then a text box where the two digits after 19.. have to be typed in by the user for the year. Am I asking for two much?

Not at all. That could be done. You would need to create separate fields for each part of the date in sub html_record_form and then put the parts together within sub add_form. You would also have to break apart the date to fit into the fields when the user modified a record and then put it together again in sub modify_record.

You would also have to go into your .db file and change all of the dates to four-digit years.


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






Quote Reply
Re: Age mod installed, something wrong! In reply to
New discovery! I'll tell you the background. When I started organising this database, I knew the age of the people, but not their birthdates. Because of that, I just made the calculations to see what year they were born, and then put 01-Jan before the year. For example, one of the records could be 01-Jan-56. This would show 2000 as the age.

The very same thing was happening to my test records, which were something like 10-Nov-1982. Then I noticed the newer records added by normal users were showing the proper age. Coincidently, the date was after 12.

Example:
11-Nov-1982 will show age as 2000
11-Nov-82 will show age as 2000
12-Nov-1982 will show age as 2000
13-Nov-1982 will show age as 17.

Do you see that? When the dd is more that 12, the proper age is shown. Do you see why???

Eoin
i.am/eoin
Quote Reply
Re: Age mod installed, something wrong! In reply to
Thank you for testing it out. My apologies for having doubted you. Smile

Before

@date_part = split '-',$date;

add

$date = lc($date);

I really thought I had tested it with a day that was under 12, but I guess I hadn't.

Anyway, I have tested it now (with the added line) and it comes out correctly.


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






Quote Reply
Re: Age mod installed, something wrong! In reply to
Thanks Smile It's all working now and I hope it continues to do so.

I'm going to be cheeky and ask for a favor. I really really don't know how to go about setting up the database for drop down menus for day, month and year. Any chance you could show me how to set that up?

Eoin
i.am/eoin
Quote Reply
Re: Age mod installed, something wrong! In reply to
In sub html_record_form, after

Code:
my (%rec) = @_;

add

Code:
@months = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
($rec{'day'},$rec{'month'},$rec{'year'}) = split "-", $rec{'birth'};
unless ($rec{'year'}) {
$rec{'year'} = 19;
}

Instead of

Code:
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Birthdate:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475">&nbsp;
<INPUT TYPE="TEXT" NAME="birth" SIZE="20" VALUE="$rec{'birth'}" MAXLENGTH="255"><br>
<b>example: 10 November 1982</b>
</TD></TR>

use

Code:
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Birthdate:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475">&nbsp;
<SELECT NAME="day">|;
for ($i=1; $i<32; $i++) {
if ($rec{'day'} == $i) {
print qq|<OPTION SELECTED>$i\n|;
}
else {
print qq|<OPTION>$i\n|;
}
}
print qq|</SELECT>&nbsp;
<SELECT NAME="month">|;
for ($i=0; $i<12;$i++) {
if ($rec{'month'} eq $months[$i]) {
print qq|<OPTION SELECTED>$months[$i]\n|;
}
else {
print qq|<OPTION>$months[$i]\n|;
}
}
print qq|</SELECT>&nbsp;
<INPUT TYPE="TEXT" NAME="year" SIZE="4" VALUE="$rec{'year'}" MAXLENGTH="255">
</TD></TR>

In sub add_record, after

Code:
my ($output, $status, $counter);

add

Code:
$in{'birth'} = "$in{'day'}-$in{'month'}-$in{'year'}";

In sub modify_record, after

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

add

Code:
$in{'birth'} = "$in{'day'}-$in{'month'}-$in{'year'}";


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






Quote Reply
Re: Age mod installed, something wrong! In reply to
Great! Sincere thanks.

Eoin
i.am/eoin