Fixes bugs with characters in search strings that require escaping in the URL

(space, =, &, etc.).  Also uses the same set up as the opac search results
templates now.  ie the FORMINPUTS template variable is sent as variable and
value pairs so that the value can be url escaped by HTML::Template
This commit is contained in:
tonnesen 2002-11-08 20:15:39 +00:00
parent 2c0ae077b9
commit bc79ea23e1
3 changed files with 30 additions and 97 deletions

View File

@ -21,7 +21,7 @@
<!-- Row of numbers corresponding to search result pages -->
<TMPL_IF NAME=displayprev>
<a href=search.pl?startfrom=<TMPL_VAR NAME="prevstartfrom">&<TMPL_LOOP NAME=FORMINPUTS><TMPL_VAR NAME=line>&</TMPL_LOOP>><img src=/images/numbers/prev.gif border=0></a>
<a href=search.pl?startfrom=<TMPL_VAR NAME="prevstartfrom"><TMPL_LOOP NAME='FORMINPUTS'>&<TMPL_VAR NAME='field'>=<TMPL_VAR NAME='value' ESCAPE=URL></TMPL_LOOP>><img src=/images/numbers/prev.gif border=0></a>
<TMPL_ELSE>
<img src=/images/numbers/placeholder.gif border=0>
</TMPL_IF>
@ -29,11 +29,11 @@
<TMPL_IF NAME=highlight>
<img src=/images/numbers/<TMPL_VAR NAME=number>-highlight.gif>
<TMPL_ELSE>
<a href=search.pl?startfrom=<TMPL_VAR NAME=startfrom>&<TMPL_LOOP NAME=FORMINPUTS><TMPL_VAR NAME=line>&</TMPL_LOOP>><img src=/images/numbers/<TMPL_VAR NAME=number>.gif border=0></a>
<a href=search.pl?startfrom=<TMPL_VAR NAME=startfrom><TMPL_LOOP NAME='FORMINPUTS'>&<TMPL_VAR NAME='field'>=<TMPL_VAR NAME='value' ESCAPE=URL></TMPL_LOOP>><img src=/images/numbers/<TMPL_VAR NAME=number>.gif border=0></a>
</TMPL_IF>
</TMPL_LOOP>
<TMPL_IF NAME=displaynext>
<a href=search.pl?startfrom=<TMPL_VAR NAME="nextstartfrom">&<TMPL_LOOP NAME=FORMINPUTS><TMPL_VAR NAME=line>&</TMPL_LOOP>><img src=/images/numbers/next.gif border=0></a>
<a href=search.pl?startfrom=<TMPL_VAR NAME="nextstartfrom"><TMPL_LOOP NAME='FORMINPUTS'>&<TMPL_VAR NAME='field'>=<TMPL_VAR NAME='value' ESCAPE=URL></TMPL_LOOP>><img src=/images/numbers/next.gif border=0></a>
<TMPL_ELSE>
<img src=/images/numbers/placeholder.gif border=0>
</TMPL_IF>
@ -73,13 +73,13 @@
<table border=0 cellpadding=0 cellspacing=0 width=100%">
<tr bgcolor=#ccccff background="/images/background-mem.gif"><td align=left>
<TMPL_IF NAME=displayprev>
<a href=search.pl?startfrom=<TMPL_VAR NAME="prevstartfrom">&<TMPL_LOOP NAME=FORMINPUTS><TMPL_VAR NAME=line>&</TMPL_LOOP>>Previous Records</a>
<a href=search.pl?startfrom=<TMPL_VAR NAME="prevstartfrom"><TMPL_LOOP NAME='FORMINPUTS'>&<TMPL_VAR NAME='field'>=<TMPL_VAR NAME='value' ESCAPE=URL></TMPL_LOOP>>Previous Records</a>
<TMPL_ELSE>
&nbsp;
</TMPL_IF>
</td><td align=right>
<TMPL_IF NAME=displaynext>
<a href=search.pl?startfrom=<TMPL_VAR NAME="nextstartfrom">&<TMPL_LOOP NAME=FORMINPUTS><TMPL_VAR NAME=line>&</TMPL_LOOP>>Next Records</a>
<a href=search.pl?startfrom=<TMPL_VAR NAME="nextstartfrom"><TMPL_LOOP NAME='FORMINPUTS'>&<TMPL_VAR NAME='field'>=<TMPL_VAR NAME='value' ESCAPE=URL></TMPL_LOOP>>Next Records</a>
<TMPL_ELSE>
&nbsp;
</TMPL_IF>

View File

@ -10,7 +10,7 @@
<!-- Row of numbers corresponding to search result pages -->
<TMPL_IF NAME=displayprev>
<a href=search.pl?startfrom=<TMPL_VAR NAME="prevstartfrom">&<TMPL_LOOP NAME=FORMINPUTS><TMPL_VAR NAME=line>&</TMPL_LOOP>><img src=/images/numbers/prev.gif border=0></a>
<a href=search.pl?startfrom=<TMPL_VAR NAME="prevstartfrom"><TMPL_LOOP NAME='FORMINPUTS'>&<TMPL_VAR NAME='field'>=<TMPL_VAR NAME='value' ESCAPE=URL></TMPL_LOOP>><img src=/images/numbers/prev.gif border=0></a>
<TMPL_ELSE>
<img src=/images/numbers/placeholder.gif border=0>
</TMPL_IF>
@ -18,11 +18,11 @@
<TMPL_IF NAME=highlight>
<img src=/images/numbers/<TMPL_VAR NAME=number>-highlight.gif>
<TMPL_ELSE>
<a href=search.pl?startfrom=<TMPL_VAR NAME=startfrom>&<TMPL_LOOP NAME=FORMINPUTS><TMPL_VAR NAME=line>&</TMPL_LOOP>><img src=/images/numbers/<TMPL_VAR NAME=number>.gif border=0></a>
<a href=search.pl?startfrom=<TMPL_VAR NAME=startfrom><TMPL_LOOP NAME='FORMINPUTS'>&<TMPL_VAR NAME='field'>=<TMPL_VAR NAME='value' ESCAPE=URL></TMPL_LOOP>><img src=/images/numbers/<TMPL_VAR NAME=number>.gif border=0></a>
</TMPL_IF>
</TMPL_LOOP>
<TMPL_IF NAME=displaynext>
<a href=search.pl?startfrom=<TMPL_VAR NAME="nextstartfrom">&<TMPL_LOOP NAME=FORMINPUTS><TMPL_VAR NAME=line>&</TMPL_LOOP>><img src=/images/numbers/next.gif border=0></a>
<a href=search.pl?startfrom=<TMPL_VAR NAME="nextstartfrom"><TMPL_LOOP NAME='FORMINPUTS'>&<TMPL_VAR NAME='field'>=<TMPL_VAR NAME='value' ESCAPE=URL></TMPL_LOOP>><img src=/images/numbers/next.gif border=0></a>
<TMPL_ELSE>
<img src=/images/numbers/placeholder.gif border=0>
</TMPL_IF>
@ -42,7 +42,7 @@
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr><td align=left>
<TMPL_IF NAME=displayprev>
<a href=search.pl?startfrom=<TMPL_VAR NAME="prevstartfrom">&<TMPL_LOOP NAME=FORMINPUTS><TMPL_VAR NAME=line>&</TMPL_LOOP>>Previous Records</a>
<a href=search.pl?startfrom=<TMPL_VAR NAME="prevstartfrom"><TMPL_LOOP NAME='FORMINPUTS'>&<TMPL_VAR NAME='field'>=<TMPL_VAR NAME='value' ESCAPE=URL></TMPL_LOOP>>Previous Records</a>
<TMPL_ELSE>
&nbsp;
</TMPL_IF>
@ -50,7 +50,7 @@
</td><td align=right>
<TMPL_IF NAME=displaynext>
<a href=search.pl?startfrom=<TMPL_VAR NAME="nextstartfrom">&<TMPL_LOOP NAME=FORMINPUTS><TMPL_VAR NAME=line>&</TMPL_LOOP>>Next Records</a>
<a href=search.pl?startfrom=<TMPL_VAR NAME="nextstartfrom"><TMPL_LOOP NAME='FORMINPUTS'>&<TMPL_VAR NAME='field'>=<TMPL_VAR NAME='value' ESCAPE=URL></TMPL_LOOP>>Next Records</a>
<TMPL_ELSE>
&nbsp;
</TMPL_IF>

107
search.pl
View File

@ -10,9 +10,8 @@ use C4::Output; # no contains gettemplate
my $query=new CGI;
my $type=$query->param('type');
(-e "opac") && ($type='opac');
my ($loggedinuser, $cookie, $sessionID) = checkauth($query, ($type eq 'opac') ? (1) : (0));
my ($loggedinuser, $cookie, $sessionID) = checkauth($query);
@ -35,54 +34,28 @@ $env->{itemcount}=1;
# get all the search variables
# we assume that C4::Search will validate these values for us
my %search;
my $keyword=$query->param('keyword');
$search{'keyword'}=$keyword;
$search{'subject'}=$subject;
my $author=$query->param('author');
$search{'author'}=$author;
$search{'authoresc'}=$author;
#$search{'authorhtmlescaped'}=~s/ /%20/g;
my $illustrator=$query->param('illustrator');
$search{'illustrator'}=$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');
$search{'ttype'}=$ttype;
my @fields = ('keyword', 'subject', 'author', 'illustrator', 'itemnumber', 'isbn', 'date-before', 'date-after', 'class', 'dewey', 'class', 'branch', 'title', 'abstract', 'publisher');
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"});
my $searchdesc = '';
foreach my $field (@fields) {
$search{$field} = $query->param($field);
if ($search{$field}) {
push @$forminputs, {field => $field, value => $search{$field}};
$searchdesc .= "$field = $search{$field}, ";
}
}
$search{'ttype'} = $query->param('ttype');
push @$forminputs, {field => 'ttype', value => $search{'ttype'}};
if (my $subjectitems=$query->param('subjectitems')){
$search{'subject'} = $subjectitems;
$searchdesc.="subject = $subjectitems, ";
}
($forminputs) || (@$forminputs=());
$template->param(FORMINPUTS => $forminputs);
# whats this for?
# I think it is (or was) a search from the "front" page... [st]
@ -106,43 +79,11 @@ foreach my $result (@results) {
$result->{'authorhtmlescaped'}=$result->{'author'};
$result->{'authorhtmlescaped'}=~s/ /%20/g;
($result->{'copyrightdate'}==0) && ($result->{'copyrightdate'}='');
($type eq 'opac') ? ($result->{'opac'}=1) : ($result->{'opac'}=0);
push (@$resultsarray, $result);
}
($resultsarray) || (@$resultsarray=());
my $search="num=20";
my $searchdesc='';
if ($keyword){
$search=$search."&keyword=$keyword";
$searchdesc.="keyword $keyword, ";
}
if (my $subjectitems=$query->param('subjectitems')){
$search=$search."&subjectitems=$subjectitems";
$searchdesc.="subject $subjectitems, ";
}
if ($subject){
$search=$search."&subject=$subject";
$searchdesc.="subject $subject, ";
}
if ($author){
$search=$search."&author=$author";
$searchdesc.="author $author, ";
}
if ($class){
$search=$search."&class=$class";
$searchdesc.="class $class, ";
}
if ($title){
$search=$search."&title=$title";
$searchdesc.="title $title, ";
}
if ($dewey){
$search=$search."&dewey=$dewey";
$searchdesc.="dewey $dewey, ";
}
$search.="&ttype=$ttype";
$search=~ s/ /%20/g;
$template->param(startfrom => $startfrom+1);
($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num)) : ($template->param(endat => $count));
$template->param(numrecords => $count);
@ -155,7 +96,6 @@ my $displayprev=0;
($prevstartfrom==-1) ? ($displayprev=0) : ($displayprev=1);
$template->param(displaynext => $displaynext);
$template->param(displayprev => $displayprev);
($type eq 'opac') ? ($template->param(opac => 1)) : ($template->param(opac => 0));
$template->param(prevstartfrom => $prevstartfrom);
$template->param(search => $search);
$template->param(searchdesc => $searchdesc);
@ -168,16 +108,9 @@ my $numbers;
if ($count>10) {
for (my $i=1; $i<$count/10+1; $i++) {
if ($i<16) {
($title) && (push @$forminputs, { line => "title=$title"});
my $highlight=0;
($startfrom==($i-1)*10) && ($highlight=1);
my $formelements='';
foreach (@$forminputs) {
my $line=$_->{line};
$formelements.="$line&";
}
$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 , FORMINPUTS => $forminputs, startfrom => ($i-1)*10};
}
}
}