Bug 14059: Deleting 'issues' table before processing the tests
[koha.git] / opac / opac-search.pl
index b0feaeb..0ff2507 100755 (executable)
@@ -6,18 +6,18 @@
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 # Script to perform searching
 # Mostly copied from search.pl, see POD there
@@ -136,7 +136,7 @@ if (C4::Context->preference("marcflavour") eq "UNIMARC" ) {
 elsif (C4::Context->preference("marcflavour") eq "MARC21" ) {
     $template->param('usmarc' => 1);
 }
-$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
+
 $template->param( 'OPACNoResultsFound' => C4::Context->preference('OPACNoResultsFound') );
 
 $template->param(
@@ -184,6 +184,21 @@ if (C4::Context->preference('TagsEnabled')) {
 
 # load the branches
 
+if ($cgi->param("returntosearch")) {
+    $template->param('ReturnToSearch' => 1);
+}
+if ($cgi->cookie("search_path_code")) {
+    my $pathcode = $cgi->cookie("search_path_code");
+    given ($pathcode)
+    {
+        when ('"ads"') { $template->param('ReturnPath' => '/cgi-bin/koha/opac-search.pl?returntosearch=1'); }
+        when ('"exs"') {
+            $template->param('ReturnPath' => '/cgi-bin/koha/opac-search.pl?expanded_options=1&returntosearch=1');
+        }
+        default {warn "ReturnPath swith error";}
+    }
+}
+
 my $branches = GetBranches();   # used later in *getRecords, probably should be internalized by those functions after caching in C4::Branch is established
 $template->param(
     searchdomainloop => GetBranchCategories('searchdomain'),
@@ -281,6 +296,12 @@ if ( $template_type && $template_type eq 'advsearch' ) {
     # box should only appear on the last, etc.
     my @search_boxes_array;
     my $search_boxes_count = 3; # begin whith 3 boxes
+    $template->param( search_boxes_count => $search_boxes_count );
+
+    if ($cgi->cookie("num_paragraph")){
+        $search_boxes_count = $cgi->cookie("num_paragraph");
+    }
+
     for (my $i=1;$i<=$search_boxes_count;$i++) {
         # if it's the first one, don't display boolean option, but show scan indexes
         if ($i==1) {
@@ -345,8 +366,10 @@ if ( $template_type && $template_type eq 'advsearch' ) {
 #  * multivalued CGI paramaters are returned as a packaged string separated by "\0" (null)
 my $params = $cgi->Vars;
 my $tag;
-$tag = $params->{tag} if $params->{tag};
-
+if ( $params->{tag} ) {
+    $tag = $params->{tag};
+    $template->param( tag => $tag );
+}
 
 # String with params with the search criteria for the paging in opac-detail
 # param value is URI encoded and params separator is HTML encode (&amp;)
@@ -872,12 +895,11 @@ for (my $i=0;$i<@servers;$i++) {
 } #/end of the for loop
 #$template->param(FEDERATED_RESULTS => \@results_array);
 
-my @input_values = map { Encode::decode_utf8($_->{input_value}) } @limit_inputs;
 for my $facet ( @$facets ) {
     for my $entry ( @{ $facet->{facets} } ) {
         my $index = $entry->{type_link_value};
         my $value = $entry->{facet_link_value};
-        $entry->{active} = grep { $_ eq qq{$index:$value} } @input_values;
+        $entry->{active} = grep { $_->{input_value} eq qq{$index:$value} } @limit_inputs;
     }
 }