Bug 10204 - Patron image no longer appears in the OPAC
[koha.git] / opac / opac-search.pl
index d2ba9fc..363a11e 100755 (executable)
@@ -63,6 +63,21 @@ my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
 use CGI qw('-no_undef_params');
 my $cgi = new CGI;
 
+my $branch_group_limit = $cgi->param("branch_group_limit");
+if ( $branch_group_limit ) {
+    if ( $branch_group_limit =~ /^multibranchlimit/ ) {
+        $cgi->param(
+            -name => 'multibranchlimit',
+            -values => [ ( split( 'multibranchlimit-', $branch_group_limit ) )[1] ]
+        );
+    } else {
+        $cgi->append(
+            -name => 'limit',
+            -values => [ $branch_group_limit ]
+        );
+    }
+}
+
 BEGIN {
     if (C4::Context->preference('BakerTaylorEnabled')) {
         require C4::External::BakerTaylor;
@@ -77,6 +92,7 @@ my $template_name;
 my $template_type = 'basic';
 my @params = $cgi->param("limit");
 
+
 my $format = $cgi->param("format") || '';
 my $build_grouped_results = C4::Context->preference('OPACGroupResults');
 if ($format =~ /(rss|atom|opensearchdescription)/) {
@@ -489,11 +505,6 @@ if ($tag) {
     $results_hashref->{biblioserver}->{RECORDS} = \@marclist;
     # FIXME: tag search and standard search should work together, not exclusively
     # FIXME: No facets for tags search.
-}
-elsif (C4::Context->preference('NoZebra')) {
-    eval {
-        ($error, $results_hashref, $facets) = NZgetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan);
-    };
 } elsif ($build_grouped_results) {
     eval {
         ($error, $results_hashref, $facets) = C4::Search::pazGetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan);
@@ -641,7 +652,7 @@ for (my $i=0;$i<@servers;$i++) {
                 $newsearchcookie = $cgi->cookie(
                             -name => 'KohaOpacRecentSearches',
                             # We uri_escape the whole freezed structure so we're sure we won't have any encoding problems
-                            -value => uri_escape(freeze(\@recentSearches)),
+                            -value =>freeze(\@recentSearches),
                             -expires => ''
                 );
                 $cookie = [$cookie, $newsearchcookie];
@@ -668,7 +679,7 @@ for (my $i=0;$i<@servers;$i++) {
             exit;
         }
         if ($hits) {
-            if (!C4::Context->preference('NoZebra') && !$build_grouped_results) {
+            if ( !$build_grouped_results ) {
                 # We build the encrypted list of first OPACnumSearchResults biblios to pass with the search criteria for paging on opac-detail
                 $pasarParams .= '&amp;listBiblios=';
                 my $j = 0;
@@ -704,6 +715,42 @@ for (my $i=0;$i<@servers;$i++) {
             $template->param(results_per_page =>  $results_per_page);
             my $hide = C4::Context->preference('OpacHiddenItems');
             $hide = ($hide =~ m/\S/) if $hide; # Just in case it has some spaces/new lines
+            my $branch = '';
+            if (C4::Context->userenv){
+                $branch = C4::Context->userenv->{branch};
+            }
+            if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) {
+                if (
+                    ( ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
+                    ||
+                    C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
+                ) {
+                    my $branchname;
+                    if ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
+                        $branchname = $branches->{$branch}->{'branchname'};
+                    }
+                    elsif (  C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
+                        $branchname = $branches->{ $ENV{'BRANCHCODE'} }->{'branchname'};
+                    }
+
+                    foreach my $res ( @newresults ) {
+                        my @new_loop;
+                        my @top_loop;
+                        my @old_loop = @{$res->{'available_items_loop'}};
+                        foreach my $item ( @old_loop ) {
+                            if ( $item->{'branchname'} eq $branchname ) {
+                                $item->{'this_branch'} = 1;
+                                push( @top_loop, $item );
+                            } else {
+                                push( @new_loop, $item );
+                            }
+                        }
+                        my @complete_loop = ( @top_loop, @new_loop );
+                        $res->{'available_items_loop'} = \@complete_loop;
+                    }
+                }
+            }
+
             $template->param(
                 SEARCH_RESULTS => \@newresults,
                 OPACItemsResultsDisplay => (C4::Context->preference("OPACItemsResultsDisplay")),