#!/usr/local/bin/perl -w # search.cgi # script which is passed a parameter to search in a flatfile and come up with # right links all prettied up. typically used for subjectarea/author/keyword # search (meta tags are parsed to create the flatfile). chdir "/usr/local/httpd/docs/cespubs/pest"; $flatfile = "index.data"; $delim = "\|"; my @months = qw(January February March April May June July August September October November December); print "Content-type: text/html\n\n"; if(&CGIParse) { $CGI = 1; while (($cgi_name,$cgi_value) = each %cgi_vars) { ${$cgi_name}=$cgi_value if ($cgi_value); } } open(FLAT,$flatfile) || die "Can't open $flatfile: $!\n"; if(($method eq "get") && (($subjectarea) || ($keyword) || ($author))) { &print_header; while () { chop; my ($filename,$oauthor,$otitle,$okeywords,$osubjectarea,$odate) = split(/\|/,$_,6); # print "$filename - $osubjectarea
\n"; $match = 1; if($author) { $match = 0 unless ($author =~ /$oauthor/i); } if($title) { $match = 0 unless ($title =~ /$otitle/i); } if($subjectarea) { $obsubjectarea =~ s/\s*$//; # $sub = $subjectarea; # $osub = $osubjectarea; # $sub =~ tr/A-Z/a-z/; # $osub =~ tr/A-Z/a-z/; $match = 0 unless ($osubjectarea =~ /$subjectarea/i); # print "$sub--$osub--$match
\n"; } if ($match) { # print "$filename - $otitle - $odate
\n"; # $hit_title{$filename} = $otitle; push @data,"$otitle|$filename|$odate"; $count++; } } if($subjectarea) { # $subjectarea =~ tr/a-z/A-Z/; print<<"TAG_1";

$subjectarea Related Articles

\n"; } &print_footer; } ############################################################### # CGIParse # # # # Reads in CGI variables to %cgi, and records method. # ############################################################### sub CGIParse { *cgi = @_ if @_; local ($i, $key, $val); # Read in text if ($ENV{'REQUEST_METHOD'} eq "GET") { $cgi = $ENV{'QUERY_STRING'}; $method="get" if $cgi; } elsif ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN,$cgi,$ENV{'CONTENT_LENGTH'}); $method="post"; } @cgi = split(/&/,$cgi); foreach $i (0 .. $#cgi) { # Convert plus's to spaces $cgi[$i] =~ s/\+/ /g; # Split into key and value. ($key, $val) = split(/=/,$cgi[$i],2); # splits on the first =. # Convert %XX from hex numbers to alphanumeric $key =~ s/%(..)/pack("c",hex($1))/ge; $val =~ s/%(..)/pack("c",hex($1))/ge; # Associate key and value $cgi_vars{$key} .= "|" if (defined($cgi_vars{$key})); $cgi_vars{$key} .= $val; } return length($cgi); } ###################################################################### # print_header:: prints the header to our pages. all nice and neat. # # no rocket science. # ###################################################################### sub print_header { if($subjectarea eq "Insect") { $insect = "linsect2.jpg"; } else { $insect = "insect2.jpg"; } if($subjectarea eq "Plant Diseases") { $plant = "lplant2.jpg"; } else { $plant = "plant2.jpg"; } if($subjectarea eq "Crop Development") { $crop = "lcrop2.jpg"; } else { $crop = "crop2.jpg"; } if($subjectarea eq "Weeds") { $weeds = "lweeds2.jpg"; } else { $weeds = "weeds2.jpg"; } print<<"TAG_1"; Pest Management & Crop Development Bulletin







TAG_1 print ""; print<<"TAG_2"; TAG_2 print ""; print<<"TAG_2"; TAG_2 print ""; print<<"TAG_2"; TAG_2 print ""; print<<"HEAD";

HEAD } ###################################################################### # print_footer:: prints the footer to our pages. all nice and neat. # # no rocket science. # ###################################################################### sub print_footer { print<<"FOOT";
FOOT } sub nice_title { # sort records to omit A/An/The and also " and ' out. my ($tmp1, $tmp2); ($tmp1 = $a) =~ s/^(An|A|The) //; ($tmp2 = $b) =~ s/^(An|A|The) //; $tmp1 =~ s/^[\'\"]//; $tmp2 =~ s/^[\'\"]//; return $tmp1 cmp $tmp2; }