#!/usr/local/bin/perl #print "Content-type: text/html\n\n; use CGI qw /:standard :html3/; $query = new CGI; $datafile = "./bkdata.txt"; $search = $query->param('search'); $search_for = $query->param(search_field); $exact_match = $query->param(exact_match); $from = $query->param(from); if($search eq ""){$search = ".";} $sspecial=$search; $search =~ s/999/&/; $aaa1=$search; $aaa2=$search_for; &Do_Search; $count=@matches; &No_Matches if($count == 0); &Print_Results; exit; sub Do_Search{ open(DATAFILE,"$datafile"); while(){ #($title,$author,$review,$category,$subcat) = split(/\|/, $_); ($id,$title,$author,$review_1,$review_link1,$review_2,$review_link2,$category1,$subcat1,$isbn_hard,$isbn_paper,$image_source,$image_large,$image_small,$keywords,$age_group,$Notes,$category2,$subcat2,$booktype,$update,$newadd) = split(/\|/, $_); $sline2 = ""; if ($search_for eq "0") { $sline = $title; } elsif ($search_for eq "1") { $sline = $author; } elsif ($search_for eq "2") { $sline = $review_1; $exact_match=0;} elsif ($search_for eq "3") { $sline = $category1; $sline2 = $category2;} elsif ($search_for eq "4") { $sline = $keywords; $search =~ s/,//g; $exact_match=0; } elsif ($search_for eq "5") { $sline = $subcat1; $sline2 = $subcat2; } elsif ($search_for eq "6") { $sline = $newadd; } if ($exact_match eq "1") { ## EXACT MATCH #$search = ":$search:"; #$sline = ":$sline:"; #if ($search eq $sline) { push @matches, $_; } if ($sline =~ /^$search$/i) { push @matches, $_; } #if ($sline =~ /\(/) { if ($sline =~ /$search/oi) { push @matches, $_; } } } else { ##NOT EXACT MATCH @keyword_list = split(/\s+/,$search); @not_found_words = @keyword_list; &FindKeywords($sline, *not_found_words); if (@not_found_words < 1) { push @matches, $_; } elsif ($sline2 ne "") { &FindKeywords($sline2, *not_found_words); if (@not_found_words < 1) {push @matches, $_; } } } } # End of while. close(DATAFILE); return; } # End of Do_Search subroutine. sub Print_Results{ $jscript=<'ChildSake Search Results',-BGCOLOR=>'#FEE7B1', -script=>$jscript); if ($from eq "topic") { print "
"; print "Topic: $search<\/center><\/b><\/font>"; } elsif ($from eq "subtopic") { print "
"; print "SubTopic: $search<\/center><\/b><\/font>"; } elsif ($from eq "alpha") { print "
"; } elsif ($from eq "newadd") { print "
"; print "FEATURED: $search<\/center><\/b><\/font>"; } else { print "
Search Results<\/CENTER><\/FONT>"; } foreach $match (@matches){ #($title,$author,$review,$category,$subcat) = split(/\|/, $match); ($id,$title,$author,$review_1,$review_link1,$review_2,$review_link2,$category1,$subcat1,$isbn_hard,$isbn_paper,$image_source,$image_large,$image_small,$keywords,$age_group,$notes,$category2,$subcat2,$booktype,$update,$newadd) = split(/\|/, $match); ##remove white space $isbn_hard =~ s/\s//g; $isbn_paper =~ s/\s//g; $image_source =~ s/\s//g; $image_large =~ s/\s//g; $image_small =~ s/\s//g; #### Image Caption and No Image if($image_source eq "hardcover"){$image_caption = "HARDCOVER" }; if($image_source eq "paperback"){$image_caption = "PAPERBACK" }; if($image_source eq "no_image"){$image_caption = "" }; if($image_source eq "no_image"){$image_small = "noimage.gif" }; if($image_source eq ""){$image_caption = "" }; if($image_source eq ""){$image_small = "noimage.gif" }; #### SUBCAT if($subcat1 ne "") { $subcat1 =~ s/^/ : /; } if($subcat2 ne "") { $subcat2 =~ s/^/ : /; } if ($age_group eq "") { $age_group = "All"; } #### Orion Quote $orion = " \From Bringing the World Alive: A Bibliography of Nature Stories for Children, published by \The Orion Society\<\/a\>\<\/i\>."; if($review_link1 eq "Orion"){ $review_1 = join(" ",$review_1,$orion); }; if($review_link2 eq "Orion"){ $review_2 = join(" ",$review_2,$orion); }; #### CCEL Quote $ccel = " CCEL<\/a><\/i>."; if($review_link1 eq "CCEL"){ $review_1 =~ s/CCEL\.//; $review_1 = join(" ",$review_1,$ccel); }; if($review_link2 eq "CCEL"){ $review_2 =~ s/CCEL\.//; $review_2 = join(" ",$review_2,$ccel); }; #### ISBN $isbn_hard =~ s/ //g; $isbn_paper =~ s/ //g; $hardbook = ""; $paperbook = ""; if($isbn_hard ne ""){ $hardbook = "  <\/a>"; } if($isbn_paper ne ""){ $paperbook = "  <\/a>"; } print<<"END_OF_TEXT1";

  END_OF_TEXT1 print $title; print<<"END_OF_TEXT2";

by END_OF_TEXT2 print $author; print<<"END_OF_TEXT3";

$image_caption
END_OF_TEXT3 print "$category1"; print "$subcat1"; if($category2 ne "") { print "
$category2"; print " $subcat2"; } print<<"END_OF_TEXT4";

END_OF_TEXT4 print $review_1; if ($review_1 ne "") { print "

"; } print $review_2; print<<"END_OF_TEXT5";

END_OF_TEXT5 print "$hardbook"; print "$paperbook"; #print "    $booktype      Grades: $age_group"; print "    Grades: $age_group"; print "<\/font>"; print<<"END_OF_TEXT5";

END_OF_TEXT5 } # End of foreach. print<<"END_OF_TEXT6";
END_OF_TEXT6 print "<\/body>"; print "<\/html>"; return; } # End of Print_Results subroutine. sub No_Matches{ print header, start_html(-title=>'ChildSake Search Results',-BGCOLOR=>'#FEE7B1'); print "
"; print "

"; print "Sorry, there were no matches for $search,
please use your BACK button and try again."; print "<\/b>"; #print "aaa1=:$aaa1: aaa2=:$aaa2:
"; print end_html; exit; } # End of No_Matches subroutine. ############################################################ # # subroutine: FindKeywords # Usage: # &FindKeywords($line, *not_found_words); # # Parameters: # $line = line to search on # *not_found_words = array of keywords that have not # matched yet # # Output: # *not_found_words will have keywords spliced out of it # as they are found. # ############################################################ sub FindKeywords { local($line, *not_found_words) = @_; local($x, $match_word,$notexact); $notexact = @not_found_words; for ($x = @not_found_words; $x > 0; $x--) { $not_found_words[$x - 1] =~ s/\\//iog; $match_word = $not_found_words[$x - 1]; if ($line =~ /\b$match_word\b/io) { splice(@not_found_words,$x - 1, 1); } # End of If } # End of For Loop if ($not_found_words < notexact) {@not_found_words = 0;} } # End of FindKeywords