#!/usr/bin/perl
#
# Main procedure
# Read through database formatted with ":" separators as:
# DRS = first,middle,last,spec,title,addr1,addr2,city,zip,phone,lang,site
# then generate HTML doctor list based on CGI search criteria
#
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
chomp $buffer;
@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;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$form{$name} = $value;
}
#change directory from cgi-bin
chdir("../dbs");
&genheader;
$doccount = 0;
open(DRS,"doc.dat") || &safedie;
while () {
chomp;
@doc = split(/:/);
$found = 0;
if (defined($form{"lastname"}) && $form{"lastname"}) {
$found = ($doc[2] =~ /$form{"lastname"}/i);
}
if (defined($form{"specialty"}) && $form{"specialty"}) {
$found = ($doc[3] =~ /$form{"specialty"}/i);
}
if (defined($form{"city"}) && $form{"city"}) {
$found = ($doc[7] =~ /$form{"city"}/i);
}
if (defined($form{"zip"}) && $form{"zip"}) {
$found = ($doc[8] =~ /$form{"zip"}/i);
}
if (defined($form{"language"}) && $form{"language"}) {
$found = ($doc[10] =~ /$form{"language"}/i);
}
if ($found) {
$doccount++;
&genhtml;
}
}
unless ($doccount) {
print "No doctors found matching your request, please try
again";
}
print "
ENDPRINT
}
#subroutine to generate doctor list
sub genhtml {
($first,$middle,$last,$spec,$title,$addr1,$addr2,$city,$zip,$phone,$lang,$site)
= @doc;
$basedir="http://www.californiado.org/";
print "- ";
if ($site) { print "" } else { print
""}
print $first," ",$middle," ",$last;
if ($site) { print "" } else { print ""}
print "
\n";
if ($spec) { print $spec,"
"}
if ($title) { print $title,"
"}
print $addr1,"
";
if ($addr2) { print $addr2,"
"}
print $city," ",$zip,"
";
print "",$phone,"
";
if ($lang) { print $lang,"
"}
print "
\n";
}
#subroutine to die safely
sub safedie {
print "Sorry, could not open doctor list!
($!)
";
# opendir(DIR,".");
# while ($filename = readdir(DIR)) {
# print "$filename
";
# }
# closedir(DIR);
}
\n";
# end of main procedure
# subroute to generate HTML header
sub genheader {
print "Content-type: text/html\n\n";
print <<'ENDPRINT';