Turned 'env' into a hash instead of a reference-to-hash, for

readability. Likewise, @$numbers -> @numbers, @$forminputs ->
@forminputs
Added a foreach loop to set up the search terms and output form, for
readability and easy extensibility.
This commit is contained in:
arensb 2002-10-14 01:13:18 +00:00
parent a21ba22b26
commit dff0b77740

129
search.pl
View file

@ -45,65 +45,37 @@ if ($subject) {
$template = gettemplate("catalogue/searchresults.tmpl", 0); $template = gettemplate("catalogue/searchresults.tmpl", 0);
} }
my $env; # %env
$env->{itemcount}=1; # Additional parameters for &catalogsearch
my %env = (
itemcount => 1, # If set to 1, &catalogsearch enumerates
# the results found and returns the number
# of items found, where they're located,
# etc.
);
# get all the search variables # get all the search variables
# we assume that C4::Search will validate these values for us # we assume that C4::Search will validate these values for us
# FIXME - This whole section, up to the &catalogsearch call, is crying my %search; # Search terms. If the key is "author",
# out for # then $search{author} is the author the
# foreach $search_term (qw(keyword subject author ...)) # user is looking for.
# { ... }
my %search;
my $keyword=$query->param('keyword');
$search{'keyword'}=$keyword;
$search{'subject'}=$subject; my @forminputs; # This is used in the form template.
my $author=$query->param('author');
$search{'author'}=$author;
$search{'authoresc'}=$author;
#$search{'authorhtmlescaped'}=~s/ /%20/g;
my $illustrator=$query->param('illustrator');
$search{'param'}=$illustrator;
my $itemnumber=$query->param('itemnumber');
$search{'itemnumber'}=$itemnumber;
my $isbn=$query->param('isbn');
$search{'isbn'}=$isbn;
my $datebefore=$query->param('date-before');
$search{'date-before'}=$datebefore;
my $class=$query->param('class');
$search{'class'}=$class;
my $dewey=$query->param('dewey');
$search{'dewey'}=$dewey;
my $branch=$query->param('branch');
$search{'branch'}=$branch;
my $title=$query->param('title');
$search{'title'}=$title;
my $abstract=$query->param('abstract');
$search{'abstract'}=$abstract;
my $publisher=$query->param('publisher');
$search{'publisher'}=$publisher;
my $ttype=$query->param('ttype'); foreach my $term (qw(keyword subject author illustrator itemnumber
$search{'ttype'}=$ttype; isbn date-before class dewey branch title abstract
publisher ttype))
{
my $value = $query->param($term);
next unless defined $value && $value ne "";
# Skip blank search terms
$search{$term} = $value;
push @forminputs, { line => "$term=$value" };
}
$template->param(FORMINPUTS => \@forminputs);
my $forminputs;
($keyword) && (push @$forminputs, { line => "keyword=$keyword"});
($subject) && (push @$forminputs, { line => "subject=$subject"});
($author) && (push @$forminputs, { line => "author=$author"});
($illustrator) && (push @$forminputs, { line => "illustrator=$illustrator"});
($itemnumber) && (push @$forminputs, { line => "itemnumber=$itemnumber"});
($isbn) && (push @$forminputs, { line => "isbn=$isbn"});
($datebefore) && (push @$forminputs, { line => "date-before=$datebefore"});
($class) && (push @$forminputs, { line => "class=$class"});
($dewey) && (push @$forminputs, { line => "dewey=$dewey"});
($branch) && (push @$forminputs, { line => "branch=$branch"});
($title) && (push @$forminputs, { line => "title=$title"});
($ttype) && (push @$forminputs, { line => "ttype=$ttype"});
($abstract) && (push @$forminputs, { line => "abstract=$abstract"});
($publisher) && (push @$forminputs, { line => "publisher=$publisher"});
($forminputs) || (@$forminputs=());
$template->param(FORMINPUTS => $forminputs);
# whats this for? # whats this for?
# I think it is (or was) a search from the "front" page... [st] # I think it is (or was) a search from the "front" page... [st]
$search{'front'}=$query->param('front'); $search{'front'}=$query->param('front');
@ -116,7 +88,7 @@ if (my $subject=$query->param('subjectitems')) {
@results=subsearch(\$blah,$subject); @results=subsearch(\$blah,$subject);
$count=$#results+1; $count=$#results+1;
} else { } else {
($count,@results)=catalogsearch($env,'',\%search,$num,$startfrom); ($count,@results)=catalogsearch(\%env,'',\%search,$num,$startfrom);
} }
#my $resultsarray=\@results; #my $resultsarray=\@results;
@ -132,9 +104,9 @@ foreach my $result (@results) {
($resultsarray) || (@$resultsarray=()); ($resultsarray) || (@$resultsarray=());
my $search="num=20"; my $search="num=20";
my $searchdesc=''; my $searchdesc='';
if ($keyword){ if ($search{"keyword"}) {
$search .= "&keyword=$keyword"; $search .= "&keyword=$search{keyword}";
$searchdesc.="keyword $keyword, "; $searchdesc.="keyword $search{keyword}, ";
} }
if (my $subjectitems=$query->param('subjectitems')){ if (my $subjectitems=$query->param('subjectitems')){
$search .= "&subjectitems=$subjectitems"; $search .= "&subjectitems=$subjectitems";
@ -144,23 +116,23 @@ if ($subject){
$search .= "&subject=$subject"; $search .= "&subject=$subject";
$searchdesc.="subject $subject, "; $searchdesc.="subject $subject, ";
} }
if ($author){ if ($search{"author"}){
$search .= "&author=$author"; $search .= "&author=$search{author}";
$searchdesc.="author $author, "; $searchdesc.="author $search{author}, ";
} }
if ($class){ if ($search{"class"}){
$search .= "&class=$class"; $search .= "&class=$search{class}";
$searchdesc.="class $class, "; $searchdesc.="class $search{class}, ";
} }
if ($title){ if ($search{"title"}){
$search .= "&title=$title"; $search .= "&title=$search{title}";
$searchdesc.="title $title, "; $searchdesc.="title $search{title}, ";
} }
if ($dewey){ if ($search{"dewey"}){
$search .= "&dewey=$dewey"; $search .= "&dewey=$search{dewey}";
$searchdesc.="dewey $dewey, "; $searchdesc.="dewey $search{dewey}, ";
} }
$search.="&ttype=$ttype"; $search.="&ttype=$search{ttype}";
$search=~ s/ /%20/g; $search=~ s/ /%20/g;
$template->param(startfrom => $startfrom+1); $template->param(startfrom => $startfrom+1);
@ -183,28 +155,29 @@ $template->param(SEARCH_RESULTS => $resultsarray);
#$template->param(includesdir => $includes); #$template->param(includesdir => $includes);
$template->param(loggedinuser => $loggedinuser); $template->param(loggedinuser => $loggedinuser);
my $numbers; my @numbers = ();
@$numbers=();
if ($count>10) { if ($count>10) {
for (my $i=1; $i<$count/10+1; $i++) { for (my $i=1; $i<$count/10+1; $i++) {
if ($i<16) { if ($i<16) {
($title) && (push @$forminputs, { line => "title=$title"}); if ($search{"title"})
{
push @forminputs, { line => "title=$search{title}"};
}
my $highlight=0; my $highlight=0;
($startfrom==($i-1)*10) && ($highlight=1); ($startfrom==($i-1)*10) && ($highlight=1);
my $formelements=''; my $formelements='';
foreach (@$forminputs) { foreach (@forminputs) {
my $line=$_->{line}; my $line=$_->{line};
$formelements.="$line&"; $formelements.="$line&";
} }
$formelements=~s/ /+/g; $formelements=~s/ /+/g;
push @$numbers, { number => $i, highlight => $highlight , FORMELEMENTS => $formelements, FORMINPUTS => $forminputs, startfrom => ($i-1)*10, opac => (($type eq 'opac') ? (1) : (0))}; push @numbers, { number => $i, highlight => $highlight , FORMELEMENTS => $formelements, FORMINPUTS => \@forminputs, startfrom => ($i-1)*10, opac => (($type eq 'opac') ? (1) : (0))};
} }
} }
} }
$template->param(numbers => $numbers); $template->param(numbers => \@numbers);
# Print the page
print $query->header(-cookie => $cookie), $template->output; print $query->header(-cookie => $cookie), $template->output;