X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=opac%2Fopac-search.pl;h=0ea238da3db3d8793154e27f7fbb4c441121bf1d;hb=1c115fcff70271246c500d5b5f9290c47b715693;hp=d57cabd321361fbd1b1cf494a6c3fd5a0b67c1d9;hpb=832aa322a822ed3be5d2a2f0b8e3f4f65f4bc32a;p=koha-ffzg.git diff --git a/opac/opac-search.pl b/opac/opac-search.pl index d57cabd321..0ea238da3d 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -30,6 +30,7 @@ use Modern::Perl; use C4::Context; use List::MoreUtils q/any/; use Try::Tiny; +use Encode; use Data::Dumper; # TODO remove @@ -42,14 +43,14 @@ my ($builder, $searcher); $builder = Koha::SearchEngine::QueryBuilder->new({index => 'biblios'}); $searcher = Koha::SearchEngine::Search->new({index => 'biblios'}); -use C4::Output; -use C4::Auth qw(:DEFAULT get_session); -use C4::Languages qw(getLanguages); -use C4::Search; +use C4::Output qw( output_html_with_http_headers pagination_bar output_with_http_headers ); +use C4::Auth qw( get_template_and_user get_session ); +use C4::Languages qw( getlanguage getLanguages ); +use C4::Search qw( searchResults ); use C4::Search::History; -use C4::Biblio; # Unused here? -use C4::Koha; -use C4::Tags qw(get_tags); +use C4::Biblio qw( GetXmlBiblio CountItemsIssued ); +use C4::Koha qw( GetItemTypesCategorized getitemtypeimagelocation GetAuthorisedValues ); +use C4::Tags qw( get_tags get_tag ); use C4::SocialData; use C4::External::OverDrive; use C4::External::BakerTaylor qw( image_url link_url ); @@ -104,7 +105,7 @@ my $format = $cgi->param("format") || ''; if ($format =~ /(rss|atom|opensearchdescription)/) { $template_name = 'opac-opensearch.tt'; } -elsif ((@params>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) || @searchCategories ) { +elsif ((@params>=1) || (defined $cgi->param("q") && $cgi->param("q") ne "") || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) || @searchCategories ) { $template_name = 'opac-results.tt'; } else { @@ -240,17 +241,7 @@ my $cnt; my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes") || "itemtypes"; my @advanced_search_types = split(/\|/, $advanced_search_types); -my $hidingrules = {}; -my $yaml = C4::Context->preference('OpacHiddenItems'); -if ( $yaml =~ /\S/ ) { - $yaml = "$yaml\n\n"; # YAML expects trailing newline. Surplus does not hurt. - eval { - $hidingrules = YAML::Load($yaml); - }; - if ($@) { - warn "Unable to parse OpacHiddenItems syspref : $@"; - } -} +my $hidingrules = C4::Context->yaml_preference('OpacHiddenItems') // {}; my @sorted_itemtypes = sort { $itemtypes->{$a}->{translated_description} cmp $itemtypes->{$b}->{translated_description} } keys %$itemtypes; foreach my $advanced_srch_type (@advanced_search_types) { @@ -321,50 +312,12 @@ if ( $template_type && $template_type eq 'advsearch' ) { $template->param( sort_by => $default_sort_by ); } - # determine what to display next to the search boxes (ie, boolean option - # shouldn't appear on the first one, scan indexes should, adding a new - # box should only appear on the last, etc. - my @search_boxes_array; - my $search_boxes_count = 3; # begin with 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) { - push @search_boxes_array, - { - scan_index => 1, - }; - - } - # if it's the last one, show the 'add field' box - elsif ($i==$search_boxes_count) { - push @search_boxes_array, - { - boolean => 1, - add_field => 1, - }; - } - else { - push @search_boxes_array, - { - boolean => 1, - }; - } - - } - my @advsearch_limits = split /,/, C4::Context->preference('OpacAdvSearchOptions'); my @advsearch_more_limits = split /,/, C4::Context->preference('OpacAdvSearchMoreOptions'); $template->param( uc( C4::Context->preference("marcflavour") ) => 1, # we already did this for UNIMARC advsearch => 1, - search_boxes_loop => \@search_boxes_array, OpacAdvSearchOptions => \@advsearch_limits, OpacAdvSearchMoreOptions => \@advsearch_more_limits, ); @@ -493,11 +446,44 @@ if (@searchCategories > 0) { @limits = map { uri_unescape($_) } @limits; -if($params->{'multibranchlimit'}) { +if ( $params->{'multibranchlimit'} || ( $branch_group_limit && $branch_group_limit =~ /^multibranchlimit-/ ) ) { + my $branchfield = C4::Context->preference('SearchLimitLibrary'); my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} ); - my @libraries = $search_group->all_libraries; - my $multibranch = '('.join( " OR ", map { 'homebranch: ' . $_->branchcode } @libraries ) .')'; - push @limits, $multibranch if ($multibranch ne '()'); + + my @branchcodes = map { $_->branchcode } $search_group->all_libraries; + + if (@branchcodes) { + if ( $branchfield eq "homebranch" ) { + push @limits, sprintf "(%s)", join " or ", map { 'homebranch: ' . $_ } @branchcodes; + } + elsif ( $branchfield eq "holdingbranch" ) { + push @limits, sprintf "(%s)", join " or ", map { 'holdingbranch: ' . $_ } @branchcodes; + } + else { + push @limits, sprintf "(%s or %s)", + join( " or ", map { 'homebranch: ' . $_ } @branchcodes ), + join( " or ", map { 'holdingbranch: ' . $_ } @branchcodes ); + } + } +} + +for ( my $i=0; $i<@limits; $i++ ) { + if ( $limits[$i] =~ /^branch:/ ) { + my $branchfield = C4::Context->preference('SearchLimitLibrary'); + if ( $branchfield eq "homebranch" ) { + $limits[$i] =~ s/branch/homebranch/; + } + elsif ( $branchfield eq "holdingbranch" ) { + $limits[$i] =~ s/branch/holdingbranch/; + } + else { + my $homebranchlimit = $limits[$i]; + my $holdingbranchlimit = $limits[$i]; + $homebranchlimit =~ s/branch/homebranch/; + $holdingbranchlimit =~ s/branch/holdingbranch/; + $limits[$i] = "($homebranchlimit or $holdingbranchlimit)"; + } + } } my $available; @@ -608,7 +594,6 @@ if ($tag) { my $taglist = get_tags({term=>$tag, approved=>1}); $results_hashref->{biblioserver}->{hits} = scalar (@$taglist); my @marclist = map { C4::Biblio::GetXmlBiblio( $_->{biblionumber} ) } @$taglist; - $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 # FIXME: Because search and standard search don't work together OpacHiddenItems @@ -809,43 +794,7 @@ for (my $i=0;$i<@servers;$i++) { $template->param(searchdesc => 1); } $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 $branchcode; - if ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) { - $branchcode = $branch; - } - elsif ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) { - $branchcode = $ENV{'BRANCHCODE'}; - } - - foreach my $res ( @newresults ) { - my @new_loop; - my @top_loop; - my @old_loop = @{$res->{'available_items_loop'}}; - foreach my $item ( @old_loop ) { - if ( $item->{'branchcode'} eq $branchcode ) { - $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; - } - } - } + my $hide = ($hidingrules) ? 1 : 0; $template->param( SEARCH_RESULTS => \@newresults, @@ -879,7 +828,7 @@ for (my $i=0;$i<@servers;$i++) { if ($nohits and $nohits=~/{QUERY_KW}/){ # extracting keywords in case of relaunching search (my $query_kw=$query_desc)=~s/ and|or / /g; - my @query_kw=($query_kw=~ /([-\w]+\b)(?:[^,:]|$)/g); + my @query_kw=($query_kw=~ /([-\w]+\b)(?:[^:]|$)/g); $query_kw=join('+',@query_kw); $nohits=~s/{QUERY_KW}/$query_kw/g; $template->param('OPACNoResultsFound' =>$nohits);