Bug 12495 - Include streetnumber in hold alert address
[koha_fer] / opac / opac-search.pl
index 83f16d8..cc6beb7 100755 (executable)
@@ -30,21 +30,19 @@ use Modern::Perl;
 use C4::Context;
 
 my $searchengine = C4::Context->preference("SearchEngine");
-for ( $searchengine ) {
-    when ( /^Solr$/ ) {
-        warn "We use Solr";
-        require 'opac/search.pl';
-        exit;
-    }
-    when ( /^Zebra$/ ) {
+if ( $searchengine =~ /^Solr$/ ) {
+    warn "We use Solr";
+    require 'opac/search.pl';
+    exit;
+} elsif ( $searchengine =~ /^Zebra$/ ) {
 
-    }
 }
 
 use C4::Output;
-use C4::Auth qw(:DEFAULT get_session ParseSearchHistorySession SetSearchHistorySession);
+use C4::Auth qw(:DEFAULT get_session);
 use C4::Languages qw(getLanguages);
 use C4::Search;
+use C4::Search::History;
 use C4::Biblio;  # GetBiblioData
 use C4::Koha;
 use C4::Tags qw(get_tags);
@@ -90,7 +88,6 @@ BEGIN {
 }
 
 my ($template,$borrowernumber,$cookie);
-my $lang = C4::Templates::getlanguage($cgi, 'opac');
 # decide which template to use
 my $template_name;
 my $template_type = 'basic';
@@ -120,6 +117,9 @@ else {
     authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
     }
 );
+
+my $lang = C4::Languages::getlanguage($cgi);
+
 if ($template_name eq 'opac-results.tmpl') {
    $template->param('COinSinOPACResults' => C4::Context->preference('COinSinOPACResults'));
 }
@@ -357,7 +357,7 @@ my @allowed_sortby = qw /acqdate_asc acqdate_dsc author_az author_za call_number
 @sort_by = $cgi->param('sort_by');
 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
 foreach my $sort (@sort_by) {
-    if ( $sort ~~ @allowed_sortby ) {
+    if ( grep { /^$sort$/ } @allowed_sortby ) {
         $template->param($sort => 1);
     }
 }
@@ -400,6 +400,9 @@ if ($operands[0] && !$operands[1]) {
 
 # limits are use to limit to results to a pre-defined category such as branch or language
 my @limits = $cgi->param('limit');
+my @nolimits = $cgi->param('nolimit');
+my %is_nolimit = map { $_ => 1 } @nolimits;
+@limits = grep { not $is_nolimit{$_} } @limits;
 @limits = map { uri_unescape($_) } @limits;
 
 if($params->{'multibranchlimit'}) {
@@ -453,7 +456,7 @@ sub _input_cgi_parse {
     for my $this_cgi ( split('&',shift) ) {
         next unless $this_cgi;
         $this_cgi =~ /(.*?)=(.*)/;
-        push @elements, { input_name => $1, input_value => $2 };
+        push @elements, { input_name => $1, input_value => uri_unescape($2) };
     }
     return @elements;
 }
@@ -501,7 +504,7 @@ if ($tag) {
     my $taglist = get_tags({term=>$tag, approved=>1});
     $results_hashref->{biblioserver}->{hits} = scalar (@$taglist);
     my @biblist  = (map {GetBiblioData($_->{biblionumber})} @$taglist);
-    my @marclist = (map {$_->{marc}} @biblist );
+    my @marclist = (map { (C4::Context->config('zebra_bib_index_mode') eq 'dom')? $_->{marcxml}: $_->{marc}; } @biblist);
     $DEBUG and printf STDERR "taglist (%s biblionumber)\nmarclist (%s records)\n", scalar(@$taglist), scalar(@marclist);
     $results_hashref->{biblioserver}->{RECORDS} = \@marclist;
     # FIXME: tag search and standard search should work together, not exclusively
@@ -616,38 +619,36 @@ for (my $i=0;$i<@servers;$i++) {
 
         # Opac search history
         if (C4::Context->preference('EnableOpacSearchHistory')) {
-            my @recentSearches = ParseSearchHistorySession($cgi);
-
-            # Adding the new search if needed
-            my $path_info = $cgi->url(-path_info=>1);
-            my $query_cgi_history = $cgi->url(-query=>1);
-            $query_cgi_history =~ s/^$path_info\?//;
-            $query_cgi_history =~ s/;/&/g;
-            my $query_desc_history = join ", ", grep { defined $_ } $query_desc, $limit_desc;
-
-            if (!$borrowernumber || $borrowernumber eq '') {
-                # To the session (the user is not logged in)
-                if (!$offset) {
-                    push @recentSearches, {
-                                "query_desc" => Encode::decode_utf8($query_desc_history) || "unknown",
-                                "query_cgi"  => Encode::decode_utf8($query_cgi_history)  || "unknown",
-                                "time"       => time(),
-                                "total"      => $total
-                              };
-                    $template->param(ShowOpacRecentSearchLink => 1);
-                }
-
-                shift @recentSearches if (@recentSearches > 15);
-                SetSearchHistorySession($cgi, \@recentSearches);
-            }
-            else {
-                # To the database (the user is logged in)
-                if (!$offset) {
-                    AddSearchHistory($borrowernumber, $cgi->cookie("CGISESSID"), $query_desc_history, $query_cgi_history, $total);
-                    $template->param(ShowOpacRecentSearchLink => 1);
+            unless ( $offset ) {
+                my $path_info = $cgi->url(-path_info=>1);
+                my $query_cgi_history = $cgi->url(-query=>1);
+                $query_cgi_history =~ s/^$path_info\?//;
+                $query_cgi_history =~ s/;/&/g;
+                my $query_desc_history = join ", ", grep { defined $_ } $query_desc, $limit_desc;
+
+                unless ( $borrowernumber ) {
+                    my $new_searches = C4::Search::History::add_to_session({
+                            cgi => $cgi,
+                            query_desc => $query_desc_history,
+                            query_cgi => $query_cgi_history,
+                            total => $total,
+                            type => "biblio",
+                    });
+                } else {
+                    # To the session (the user is logged in)
+                    C4::Search::History::add({
+                        userid => $borrowernumber,
+                        sessionid => $cgi->cookie("CGISESSID"),
+                        query_desc => $query_desc_history,
+                        query_cgi => $query_cgi_history,
+                        total => $total,
+                        type => "biblio",
+                    });
                 }
             }
+            $template->param( EnableOpacSearchHistory => 1 );
         }
+
         ## If there's just one result, redirect to the detail page
         if ($total == 1 && $format ne 'rss2'
         && $format ne 'opensearchdescription' && $format ne 'atom') {
@@ -841,6 +842,16 @@ 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;
+    }
+}
+
+
 $template->param(
             #classlist => $classlist,
             total => $total,