#!/usr/bin/perl -w
# ###################################################################
# lit_search1.pl
# Moes G. 2005
# ###################################################################
# The name of the results template
$tplfile="../httpdocs/results1.htm";
# ####################################################################
use CGI;
my $query = new CGI; # neues CGI-Objekt erzeugen
my $SEARCH = $query->param('text');
my @TEXTS = split(/\s+/, $SEARCH);
my @ALLURLS = $query->param('auswahl');
my $BOOL = $query->param('boolean');
my $text;
foreach $text (@TEXTS) {
if ($text eq "")
{
print "Content-type: text/html\n\n";
print "\n";
print "
\n";
print "Literatursuche\n";
print "\n";
print "\n";
print "\n";
print "";
exit;
}
}
# Read the template
if (open(FILE,"$tplfile"))
{
@TEMPLATE = ;
close(FILE);
}
else
{
&error_open;
}
# Locates ##LOOP-START## and ##LOOP-END## in the template
$loopstart = 0;
$loopend = 0;
$tempsize=@TEMPLATE;
for($n=0; $n<$tempsize; $n++) {
$line=$TEMPLATE[$n];
if($line =~ /LOOP-STARTS/i) {
$loopstart=$n; }
if($line =~ /LOOP-ENDS/i) {
$loopend=$n; }
}
# print the top of the page
print "Content-type: text/html\n\n";
for($n=0; $n<$loopstart; $n++) {
$line=$TEMPLATE[$n];
print $line; }
# flags definition
$flag_any = 0;
$flag_page = 0;
$counter = 0;
@ALLURLS = $query->param('auswahl');
# Loops through all urls
for($n=0; $n<@ALLURLS; $n++) {
$flag_page=0;
# split between the URL and the file description
@PARTS = split(/\|/, $ALLURLS[$n]);
if (open(CONTENT_FILE,"$PARTS[0]"))
{
@CONTENT = ;
$all = @CONTENT;
close(CONTENT_FILE);
for($m=0; $m<@CONTENT && $flag_page <10000; $m++) {
$line=$CONTENT[$m];
# Remove html tags from $line
$line =~ s/<(.*?)>/\.\.\./g;
$i=1;
if ($BOOL eq 'oder'){
foreach $text (@TEXTS) {
if($line =~ /$text/){
# Highligt the text found
$line=~ s/$text/$text<\/b>/g;
&result;
}
$i = $i++;
}
}
elsif ($BOOL eq 'und'){
if($line =~ /$TEXTS[0]/) {
if($line =~ /$TEXTS[1]/) {
if($line =~ /$TEXTS[2]/) {
if($line =~ /$TEXTS[3]/) {
if($line =~ /$TEXTS[4]/) {
# Highligt the text found
foreach $text (@TEXTS) {
$line=~ s/$text/$text<\/b>/g;
}
&result;
$i = $i++;
}
}
}
}
}
}
}
}
else
{
&error_open;
}
}
# Prints the rest of the page
if ($flag_any == 0)
{
print "";
print "
";
print "";
print "";
print "Kein passender Eintrag gefunden. | ";
print "<\/tr>";
print "<\/table>";
print "<\/center>";
print "<\/div>";
}
for($n=$loopend; $n<$tempsize; $n++) {
$line=$TEMPLATE[$n];
$line =~ s/##QUERY##/$query/gi;
print $line; }
exit;
sub error_open
{
print "Content-type: text/html\n\n";
print "\n";
print "\n";
print "Fehler!\n";
print "\n";
print "\n";
print "";
print "Die Datei konnte nicht geƶffnet werden oder wurde nicht gefunden.";
print "
";
print "";
exit;
}
sub result
{
$counter = $counter + 1;
# Prints this record looping throug the template
for($tpline=$loopstart; $tpline<$loopend && $flag_page == 0; $tpline++)
{
$linet=$TEMPLATE[$tpline];
$linet =~ s/##DESCRIPTION##/$PARTS[1]/gi;
$linet =~ s/##ALL##/$all /gi;
print $linet;
}
print "";
print "";
print $line;
print" ";
print "<\/font>";
print "<\/td>";
print "<\/tr>";
$flag_page = $flag_page+1;
if ($flag_page == 2) {$counter--;}
$flag_any = 1;
}
|