#!/usr/bin/perl
###############################################################################
# search.cgi 7/4/2001
# (c)Pam Carey Durstock durp@one.net
# searchable index of Kentucky Biographies
# biographies are located at http://www.rootsweb.com/~kygenweb/kybiog/
# path to the bios: /u1/home0013/home/kygenweb/public_html/kybiog/.....
###############################################################################
use DBI;
use Text::Soundex;
use CGI::Carp qw(fatalsToBrowser);
$db_name="test_kybios";
$dbserver="resources.rootsweb.com";
$alt="Kentucky Biographies";
$searchscript="search.cgi";
$path="/u1/home0013/home/kygenweb/public_html/kybiog";
print "Content-type: text/html\n\n"; # the double '\n' thing is *crucial*
&parse_form;
$surname=$FORM{'surname'};
$fname=$FORM{'fname'};
$county=$FORM{'county'};
$soundex=$FORM{'soundex'};
#
$read=$FORM{'read'};
$vsurname=$FORM{'vsurname'};
$vfname=$FORM{'vfname'};
$vcounty=$FORM{'vcounty'};
$vsoundex=$FORM{'vsoundex'};
$srchterm=$FORM{'srchterm'};
#
$main_id=$FORM{'main_id'};
$next=$FORM{'next'};
$sort=$FORM{'sort'};
#
$database=$FORM{'database'};
$return_to=$FORM{'return_to'};
#
$database="$alt" unless ($database);
$return_to="http://www.rootsweb.com/~kygenweb/kybiog/search.html" unless ($return_to);
&illegal if ($surname=~/^\%/);
&grab if ($exists{'read'});
&missing_info unless ($surname || $fname || $county || $read);
$qstring2=$ENV{'QUERY_STRING'};
&getlist if (($exists{'getlist'}) || ($exists{'getmore'}) || ($surname ne '')); # comes from form
####################################################################
#
# SUBROUTINES
#
####################################################################
sub parse_form {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # for POST methods
$qstring=$ENV{'QUERY_STRING'}; # for GET methods
if ($buffer eq '') {$buffer=$qstring;}
else {$buffer.="&$qstring";}
#
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value=$1 if ($value=~/^(.*)$/); # untaint for writing
if ($FORM{$name}) { # if this var is already defined (multiple checkbox loop)
$FORM{$name}.=", $value"; # append the new one
} else {
$FORM{$name}=$value; # assign it
}
$exists{$name}='y'; # all passed variables will set this
}
}
####################################################################
# SEARCH (getlist)
####################################################################
sub getlist {
&header;
$dbh = DBI->connect("DBI:mysql:$db_name:$dbserver", nobody, undef, undef)
or &dberror;
if ($surname ne '') {
&too_short if (length($surname)<3);
$sndx=soundex($surname);
$surname2=$surname."%";
$quotesurname=$dbh->quote($surname2); # escapes the nasties that lusers enter, which can kill mysql
}
#########################################################################################
# INITIAL RESULTS SCREEN
#########################################################################################
$fields2search=0;
if ($surname ne '') {
$fields2search++;
if ($exists{'soundex'}) {$statement="SELECT surname,fname,maincounty,allplaces,filename,otherbios FROM bios,surnames WHERE sndx='$sndx'";}
else {$statement="SELECT surname,fname,maincounty,allplaces,filename,otherbios FROM bios,surnames WHERE surname like $quotesurname";}
}
if ($fname ne '') {
$fields2search++;
$fname2=$fname."%"; $quotefname=$dbh->quote($fname2);
if ($fields2search==1) {$statement="SELECT surname,fname,maincounty,allplaces,filename,otherbios FROM bios,surnames WHERE fname like $quotefname";}
else {$statement.=" AND fname like $quotefname";}
}
if ($county ne '') {
$fields2search++;
$county4all="%$county%";
if ($fields2search==1) {$statement="SELECT surname,fname,maincounty,allplaces,filename,otherbios FROM bios,surnames WHERE kycounties like '$county4all'";}
else {$statement.=" AND kycounties like '$county4all'";}
}
#
$statement.=" AND lname_id=surnames.id";
#
$sth=$dbh->prepare($statement);
$sth->execute or &dberror;
$findcount=0;
while (@row=$sth->fetchrow_array) {
# main.id,surname,fname,maincounty,kycounties,allplaces,filename,otherbios
$lname=$row[0]; $fname2=$row[1]; $maincounty=$row[2]; $allplaces=$row[3]; $filename=$row[4]; $otherbios=$row[5];
$lname=~s/ \*\*//; $otherbios=~s/
/, /g;
#
$findcount++;
push (@foundstuff, "$lname\t$fname2\t$maincounty\t$allplaces\t$filename\t$otherbios");
}
$sth->finish;
$dbh->disconnect;
#
foreach $gizmo (sort @foundstuff) {push (@foundrecords, "$gizmo");}
print "
Matches $next3 - $last of $findcount | |||||
---|---|---|---|---|---|
Name | Residence/Birthplace | Other Locations Mentioned | Found in Bio for: | ||
 \;$lname, $fname2 | \n"; } else { print " \;$lname | \n"; } print " \;$maincounty | \n"; print " \;$allplaces | \n"; $srchterm="$surname/$fname/$county/$soundex"; if ($otherbios ne '') { print " \;"; @otherbios=split(/, /,$otherbios); $obiocount=0; foreach $obio (@otherbios) { if ($obio=~/(.*)<\/a>/) {$sread=$1; $sname=$2;} $obiocount++; print ", " if ($obiocount>1 && $obio ne ''); print "$sname"; } print " | \n"; } $fname4url=$fname2; $fname4url=~s/([^a-zA-Z0-9])/sprintf("%%%02lx",unpack("C",$1))/ge; print " \;Self | \n" if ($otherbios eq ''); print "
 \;$lname, $fname2 | \n"; } else { print " \;$lname | \n"; } print " \;$maincounty | \n"; print " \;$allplaces | \n"; $srchterm="$surname/$fname/$county/$soundex"; if ($otherbios ne '') { print " \;"; @otherbios=split(/, /,$otherbios); $obiocount=0; foreach $obio (@otherbios) { if ($obio=~/(.*)<\/a>/) {$sread=$1; $sname=$2;} $obiocount++; print ", " if ($obiocount>1 && $obio ne ''); print "$sname"; } print " | \n"; } $fname4url=$fname2; $fname4url=~s/([^a-zA-Z0-9])/sprintf("%%%02lx",unpack("C",$1))/ge; print " \;Self | \n" if ($otherbios eq ''); print "
\n"; } # print "
\n"; } else { print "
\n"; #print "$statement
\n"; print "
\n"; print "
\n"; open (BIO, "$path/$read") || die "Sorry. File Not Available. Please try again later.\n"; print "\n"; while (
) { $line=$1 if ($_=~/^(.*)$/); $vsurname=~s/_/ /g; if ($line!~/^http/) { $line=~s/$vsurname/$vsurname<\/b><\/font>/gi if ($vsurname ne ''); $fname2=$vfname; $fname2=~s/\./\\./g; $line=~s/$fname2/$vfname<\/b><\/font>/gi if ($vfname ne ''); $line=~s/$vcounty/$vcounty<\/b><\/font>/gi if ($vcounty ne ''); } print "$line\n"; } close (BIO); print "