Bug 30952: Change color of btn-primary and use that for Check out button
[koha-ffzg.git] / opac / opac-search.pl
index b2d7be1..c0f7ca5 100755 (executable)
@@ -205,10 +205,10 @@ if ($cgi->param("returntosearch")) {
 }
 if ($cgi->cookie("search_path_code")) {
     my $pathcode = $cgi->cookie("search_path_code");
-    if ($pathcode eq '"ads"') {
+    if ($pathcode eq 'ads') {
         $template->param('ReturnPath' => '/cgi-bin/koha/opac-search.pl?returntosearch=1');
     }
-    elsif ($pathcode eq '"exs"') {
+    elsif ($pathcode eq 'exs') {
          $template->param('ReturnPath' => '/cgi-bin/koha/opac-search.pl?expanded_options=1&returntosearch=1');
     }
     else {
@@ -216,7 +216,7 @@ if ($cgi->cookie("search_path_code")) {
     }
 }
 
-my @search_groups = Koha::Library::Groups->get_search_groups();
+my @search_groups = Koha::Library::Groups->get_search_groups( { interface => 'opac' } )->as_list;
 $template->param( search_groups => \@search_groups );
 
 # load the language limits (for search)
@@ -239,7 +239,7 @@ foreach my $itemtype ( keys %{$itemtypes} ) {
 my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype';
 my @advancedsearchesloop;
 my $cnt;
-my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes") || "itemtypes";
+my $advanced_search_types = C4::Context->preference("OpacAdvancedSearchTypes") || "itemtypes";
 my @advanced_search_types = split(/\|/, $advanced_search_types);
 
 my $hidingrules = C4::Context->yaml_preference('OpacHiddenItems') // {};
@@ -419,10 +419,12 @@ my @operands = $cgi->multi_param('q');
 $template->{VARS}->{querystring} = join(' ', @operands);
 
 # if a simple search, display the value in the search box
+my $basic_search = 0;
 if ($operands[0] && !$operands[1]) {
     my $ms_query = $operands[0];
     $ms_query =~ s/ #\S+//;
     $template->param(ms_value => $ms_query);
+    $basic_search=1;
 }
 
 # limits are use to limit to results to a pre-defined category such as branch or language
@@ -561,7 +563,8 @@ if ($tag) {
     #        displays search results which should be hidden.
     # FIXME: No facets for tags search.
 } else {
-    $pasarParams .= '&query=' . uri_escape_utf8($query);
+    my $json = JSON->new->utf8->allow_nonref(1);
+    $pasarParams .= '&query=' . uri_escape_utf8($json->encode($query));
     $pasarParams .= '&count=' . uri_escape_utf8($results_per_page);
     $pasarParams .= '&simple_query=' . uri_escape_utf8($simple_query);
     $pasarParams .= '&query_type=' . uri_escape_utf8($query_type) if ($query_type);
@@ -587,7 +590,7 @@ my @sup_results_array;
 my $search_context = {};
 $search_context->{'interface'} = 'opac';
 if (C4::Context->preference('OpacHiddenItemsExceptions')){
-    $search_context->{'category'} = $patron ? $patron->categorycode : q{};
+    $search_context->{patron} = $patron;
 }
 
 my $variables = { anonymous_session => ($borrowernumber) ? 0 : 1 };
@@ -607,6 +610,35 @@ for (my $i=0;$i<@servers;$i++) {
     my $server = $servers[$i];
     if ($server && $server =~/biblioserver/) { # this is the local bibliographic server
         $hits = $results_hashref->{$server}->{"hits"};
+        if ( $hits == 0 && $basic_search ){
+            $operands[0] = '"'.$operands[0].'"'; #quote it
+            ## I. BUILD THE QUERY
+            ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type)
+              = $builder->build_query_compat(
+                \@operators,
+                \@operands,
+                \@indexes,
+                \@limits,
+                \@sort_by,
+                0,
+                $lang,
+                {
+                    suppress => $suppress,
+                    is_opac => 1,
+                    weighted_fields => $weight_search
+                }
+            );
+            my $quoted_results_hashref;
+            my $itemtypes_nocategory = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
+            eval {
+                ($error, $quoted_results_hashref, $facets) = $searcher->search_compat($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,undef,$itemtypes_nocategory,$query_type,$scan,1);
+            };
+            my $quoted_hits = $quoted_results_hashref->{$server}->{"hits"} // 0;
+            if ( $quoted_hits ){
+                $results_hashref->{'biblioserver'} = $quoted_results_hashref->{'biblioserver'};
+                $hits = $quoted_hits;
+            }
+        }
         my $page = $cgi->param('page') || 0;
         my @newresults = searchResults( $search_context, $query_desc, $hits, $results_per_page, $offset, $scan,
                                         $results_hashref->{$server}->{"RECORDS"}, $variables);
@@ -758,7 +790,7 @@ for (my $i=0;$i<@servers;$i++) {
                 $template->param(searchdesc => 1);
             }
             $template->param(results_per_page =>  $results_per_page);
-            my $hide = ($hidingrules) ? 1 : 0;
+            my $hide = keys %$hidingrules ? 1 : 0;
 
             $template->param(
                 SEARCH_RESULTS => \@newresults,