X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=opac%2Fopac-search.pl;h=2854da62030909fe16fbac7b915b891ee0c2529d;hb=08382876306cfda839637c5f72a107b304458a8e;hp=a0ba2964ec4d78cd8eb2440d0c99487f48e4bd46;hpb=fb8aa63f9d9f56bf80ffab7b6e45b8cadb66ddf4;p=koha.git diff --git a/opac/opac-search.pl b/opac/opac-search.pl index a0ba2964ec..2854da6203 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -42,7 +42,7 @@ for ( $searchengine ) { } use C4::Output; -use C4::Auth qw(:DEFAULT get_session); +use C4::Auth qw(:DEFAULT get_session ParseSearchHistoryCookie); use C4::Languages qw(getAllLanguages); use C4::Search; use C4::Biblio; # GetBiblioData @@ -51,10 +51,11 @@ use C4::Tags qw(get_tags); use C4::Branch; # GetBranches use C4::SocialData; use C4::Ratings; +use C4::External::OverDrive; use POSIX qw(ceil floor strftime); use URI::Escape; -use Storable qw(thaw freeze); +use JSON qw/decode_json encode_json/; use Business::ISBN; my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold"); @@ -63,6 +64,24 @@ 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-/ ) { + # For search groups we are going to convert this branch_group_limit CGI + # parameter into a multibranchlimit CGI parameter for the purposes of + # actually performing the query + $cgi->param( + -name => 'multibranchlimit', + -values => substr($branch_group_limit, 17) + ); + } else { + $cgi->append( + -name => 'limit', + -values => [ $branch_group_limit ] + ); + } +} + BEGIN { if (C4::Context->preference('BakerTaylorEnabled')) { require C4::External::BakerTaylor; @@ -77,6 +96,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)/) { @@ -174,7 +194,7 @@ if (C4::Context->preference('TagsEnabled')) { 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(undef,'searchdomain'), + searchdomainloop => GetBranchCategories('searchdomain'), ); # load the language limits (for search) @@ -227,10 +247,6 @@ foreach my $advanced_srch_type (@advanced_search_types) { } $template->param(advancedsearchesloop => \@advancedsearchesloop); -# # load the itypes (Called item types in the template -- just authorized values for searching) -# my ($itypecount,@itype_loop) = GetCcodes(); -# $template->param(itypeloop=>\@itype_loop,); - # The following should only be loaded if we're bringing up the advanced search template if ( $template_type && $template_type eq 'advsearch' ) { # load the servers (used for searching -- to do federated searching, etc.) @@ -387,7 +403,8 @@ my @limits = $cgi->param('limit'); @limits = map { uri_unescape($_) } @limits; if($params->{'multibranchlimit'}) { - push @limits, '('.join( " or ", map { "branch: $_ " } @{ GetBranchesInCategory( $params->{'multibranchlimit'} ) } ).')'; + my $multibranch = '('.join( " or ", map { "branch: $_ " } @{ GetBranchesInCategory( $params->{'multibranchlimit'} ) } ).')'; + push @limits, $multibranch if ($multibranch ne '()'); } my $available; @@ -540,52 +557,50 @@ for (my $i=0;$i<@servers;$i++) { $results_hashref->{$server}->{"RECORDS"}); } - # must define a value for size if not present in DB - # in order to avoid problems generated by the default size value in TT - foreach my $line (@newresults) { - if ( not exists $line->{'size'} ) { $line->{'size'} = "" } + foreach my $res (@newresults) { + + # must define a value for size if not present in DB + # in order to avoid problems generated by the default size value in TT + if ( not exists $res->{'size'} ) { $res->{'size'} = "" } # while we're checking each line, see if item is in the cart - if ( grep {$_ eq $line->{'biblionumber'}} @cart_list) { - $line->{'incart'} = 1; + if ( grep {$_ eq $res->{'biblionumber'}} @cart_list) { + $res->{'incart'} = 1; } - } - - my $tag_quantity; - if (C4::Context->preference('TagsEnabled') and - $tag_quantity = C4::Context->preference('TagsShowOnList')) { - foreach (@newresults) { - my $bibnum = $_->{biblionumber} or next; - $_->{itemsissued} = CountItemsIssued( $bibnum ); - $_ ->{'TagLoop'} = get_tags({biblionumber=>$bibnum, approved=>1, 'sort'=>'-weight', - limit=>$tag_quantity }); + if (C4::Context->preference('COinSinOPACResults')) { + my $record = GetMarcBiblio($res->{'biblionumber'}); + $res->{coins} = GetCOinSBiblio($record); } - } - - if (C4::Context->preference('COinSinOPACResults')) { - foreach (@newresults) { - my $record = GetMarcBiblio($_->{'biblionumber'}); - $_->{coins} = GetCOinSBiblio($record); - if ( C4::Context->preference( "Babeltheque" ) and $_->{normalized_isbn} ) { - my $isbn = Business::ISBN->new( $_->{normalized_isbn} ); - next if not $isbn; + if ( C4::Context->preference( "Babeltheque" ) and $res->{normalized_isbn} ) { + if( my $isbn = Business::ISBN->new( $res->{normalized_isbn} ) ) { $isbn = $isbn->as_isbn13->as_string; $isbn =~ s/-//g; my $social_datas = C4::SocialData::get_data( $isbn ); - next if not $social_datas; - for my $key ( keys %$social_datas ) { - $_->{$key} = $$social_datas{$key}; - if ( $key eq 'score_avg' ){ - $_->{score_int} = sprintf("%.0f", $$social_datas{score_avg} ); + if ( $social_datas ) { + for my $key ( keys %$social_datas ) { + $res->{$key} = $$social_datas{$key}; + if ( $key eq 'score_avg' ){ + $res->{score_int} = sprintf("%.0f", $$social_datas{score_avg} ); + } } } } } - } + if (C4::Context->preference('TagsEnabled') and + C4::Context->preference('TagsShowOnList')) { + if ( my $bibnum = $res->{biblionumber} ) { + $res->{itemsissued} = CountItemsIssued( $bibnum ); + $res->{'TagLoop'} = get_tags({ + biblionumber => $bibnum, + approved => 1, + sort => '-weight', + limit => C4::Context->preference('TagsShowOnList') + }); + } + } - if ( C4::Context->preference('OpacStarRatings') eq 'all' ) { - foreach my $res (@newresults) { + if ( C4::Context->preference('OpacStarRatings') eq 'all' ) { my $rating = GetRating( $res->{'biblionumber'}, $borrowernumber ); $res->{'rating_value'} = $rating->{'rating_value'}; $res->{'rating_total'} = $rating->{'rating_total'}; @@ -601,16 +616,7 @@ for (my $i=0;$i<@servers;$i++) { # Opac search history my $newsearchcookie; if (C4::Context->preference('EnableOpacSearchHistory')) { - my @recentSearches; - - # Getting the (maybe) already sent cookie - my $searchcookie = $cgi->cookie('KohaOpacRecentSearches'); - if ($searchcookie){ - $searchcookie = uri_unescape($searchcookie); - if (thaw($searchcookie)) { - @recentSearches = @{thaw($searchcookie)}; - } - } + my @recentSearches = ParseSearchHistoryCookie($cgi); # Adding the new search if needed my $path_info = $cgi->url(-path_info=>1); @@ -623,8 +629,8 @@ for (my $i=0;$i<@servers;$i++) { # To a cookie (the user is not logged in) if (!$offset) { push @recentSearches, { - "query_desc" => $query_desc_history || "unknown", - "query_cgi" => $query_cgi_history || "unknown", + "query_desc" => Encode::decode_utf8($query_desc_history) || "unknown", + "query_cgi" => Encode::decode_utf8($query_cgi_history) || "unknown", "time" => time(), "total" => $total }; @@ -635,8 +641,8 @@ for (my $i=0;$i<@servers;$i++) { # Pushing the cookie back $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)), + # We uri_escape the whole serialized structure so we're sure we won't have any encoding problems + -value => uri_escape( encode_json(\@recentSearches) ), -expires => '' ); $cookie = [$cookie, $newsearchcookie]; @@ -699,6 +705,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")), @@ -845,5 +887,10 @@ $template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksRe $template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer'); $template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults'); +if ($offset == 0 && IsOverDriveEnabled()) { + $template->param(OverDriveEnabled => 1); + $template->param(OverDriveLibraryID => C4::Context->preference('OverDriveLibraryID')); +} + $template->param( borrowernumber => $borrowernumber); output_with_http_headers $cgi, $cookie, $template->output, $content_type;