use C4::SocialData;
use C4::External::OverDrive;
+use Koha::Libraries;
use Koha::ItemTypes;
use Koha::Ratings;
use Koha::Virtualshelves;
use Koha::Library::Groups;
+use Koha::Patrons;
+use Koha::SearchFields;
use POSIX qw(ceil floor strftime);
use URI::Escape;
elsif (@params && $build_grouped_results) {
$template_name = 'opac-results-grouped.tt';
}
-elsif ((@params>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) ) {
+elsif ((@params>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) || @searchCategories ) {
$template_name = 'opac-results.tt';
}
else {
$template_name = 'opac-advsearch.tt';
$template_type = 'advsearch';
}
+
+$format = 'rss' if $format =~ /^rss2?$/;
+
# load the template
($template, $borrowernumber, $cookie) = get_template_and_user({
template_name => $template_name,
authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
}
);
+my $patron = Koha::Patrons->find( $borrowernumber );
my $lang = C4::Languages::getlanguage($cgi);
@cart_list = split(/\//, $cart_list);
}
-if ($format eq 'rss2' or $format eq 'opensearchdescription' or $format eq 'atom') {
+if ($format eq 'rss' or $format eq 'opensearchdescription' or $format eq 'atom') {
$template->param($format => 1);
$template->param(timestamp => strftime("%Y-%m-%dT%H:%M:%S-00:00", gmtime)) if ($format eq 'atom');
# FIXME - the timestamp is a hack - the biblio update timestamp should be used for each
# add translated_description to itemtypes
foreach my $itemtype ( keys %{$itemtypes} ) {
# Itemtypes search categories don't have (yet) translated descriptions, they are auth values (and could still have no descriptions too BZ 18400)
- my $translated_description = Koha::ItemTypes->find( $itemtype )->translated_description;
+ # If 'iscat' (see ITEMTYPECAT) then there is no itemtype and the description is not translated
+ my $translated_description = $itemtypes->{$itemtype}->{iscat}
+ ? $itemtypes->{$itemtype}->{description}
+ : Koha::ItemTypes->find($itemtype)->translated_description;
$itemtypes->{$itemtype}->{translated_description} = $translated_description || $itemtypes->{$itemtype}->{description} || q{};
}
# 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 whith 3 boxes
+ my $search_boxes_count = 3; # begin with 3 boxes
$template->param( search_boxes_count => $search_boxes_count );
if ($cgi->cookie("num_paragraph")){
}
}
- if (C4::Context->preference('OPACNumbersPreferPhrase')) {
- $template->param('numbersphr' => 1);
- }
output_html_with_http_headers $cgi, $cookie, $template->output;
exit;
# if a simple index (only one) display the index used in the top search box
if ($indexes[0] && !$indexes[1]) {
- $template->param("ms_".$indexes[0] => 1);
+ my $idx = "ms_".$indexes[0];
+ $idx =~ s/\,/comma/g; # template toolkit doesn't like variables with a , in it
+ $idx =~ s/-/dash/g; # template toolkit doesn't like variables with a dash in it
+ $template->param($idx => 1);
}
# an operand can be a single term, a phrase, or a complete ccl query
my @operands = $cgi->multi_param('q');
if($params->{'multibranchlimit'}) {
my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} );
my @libraries = $search_group->all_libraries;
- my $multibranch = '('.join( " or ", map { 'branch: ' . $_->id } @libraries ) .')';
+ my $multibranch = '('.join( " or ", map { 'branch: ' . $_->branchcode } @libraries ) .')';
push @limits, $multibranch if ($multibranch ne '()');
}
my $page = $cgi->param('page') || 1;
$offset = ($page-1)*$results_per_page if $page>1;
my $hits;
-my $expanded_facet = $params->{'expand'};
# Define some global variables
my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type);
\@sort_by,
0,
$lang,
- { expanded_facet => $expanded_facet, suppress => $suppress }
- );
+ {
+ suppress => $suppress,
+ is_opac => 1,
+ weighted_fields => !$cgi->param('advsearch')
+ }
+);
sub _input_cgi_parse {
my @elements;
## parse the limit_cgi string and put it into a form suitable for <input>s
my @limit_inputs = $limit_cgi ? _input_cgi_parse($limit_cgi) : ();
+# OpenURL
+my @OpenURL_itypes;
+if (C4::Context->preference('OPACShowOpenURL')) {
+ @OpenURL_itypes = split( /\s/, C4::Context->preference('OPACOpenURLItemTypes') );
+ $template->param(
+ OPACShowOpenURL => 1,
+ OpenURLResolverURL => C4::Context->preference('OpenURLResolverURL'),
+ OpenURLText => C4::Context->preference('OpenURLText'),
+ OpenURLImageLocation => C4::Context->preference('OpenURLImageLocation')
+ );
+}
+
$template->param ( LIMIT_INPUTS => \@limit_inputs );
$template->param ( OPACResultsSidebar => C4::Context->preference('OPACResultsSidebar'));
my @coins;
if ($tag) {
- $query_cgi = "tag=" .$tag . "&" . $query_cgi;
+ $query_cgi = "tag=" . uri_escape_utf8( $tag ) . "&" . $query_cgi;
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
+ # displays search results which should be hidden.
# FIXME: No facets for tags search.
} elsif ($build_grouped_results) {
eval {
- ($error, $results_hashref, $facets) = C4::Search::pazGetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,undef,$query_type,$scan);
+ ($error, $results_hashref, $facets) = C4::Search::pazGetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,undef,$query_type,$scan);
};
} else {
$pasarParams .= '&query=' . uri_escape_utf8($query);
$pasarParams .= '&query_type=' . uri_escape_utf8($query_type) if ($query_type);
my $itemtypes_nocategory = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
eval {
- ($error, $results_hashref, $facets) = $searcher->search_compat($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,undef,$itemtypes_nocategory,$query_type,$scan,1);
+ ($error, $results_hashref, $facets) = $searcher->search_compat($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,undef,$itemtypes_nocategory,$query_type,$scan,1);
};
}
# At this point, each server has given us a result set
# now we build that set for template display
my @sup_results_array;
+my $search_context = {};
+$search_context->{'interface'} = 'opac';
+if (C4::Context->preference('OpacHiddenItemsExceptions')){
+ $search_context->{'category'} = $patron ? $patron->categorycode : q{};
+}
+
for (my $i=0;$i<@servers;$i++) {
my $server = $servers[$i];
if ($server && $server =~/biblioserver/) { # this is the local bibliographic server
# because pazGetRecords handles retieving only the records
# we want as specified by $offset and $results_per_page,
# we need to set the offset parameter of searchResults to 0
- my @group_results = searchResults( 'opac', $query_desc, $group->{'group_count'},$results_per_page, 0, $scan,
+ my @group_results = searchResults( $search_context, $query_desc, $group->{'group_count'},$results_per_page, 0, $scan,
$group->{"RECORDS"});
push @newresults, { group_label => $group->{'group_label'}, GROUP_RESULTS => \@group_results };
}
} else {
- @newresults = searchResults('opac', $query_desc, $hits, $results_per_page, $offset, $scan,
+ @newresults = searchResults( $search_context, $query_desc, $hits, $results_per_page, $offset, $scan,
$results_hashref->{$server}->{"RECORDS"});
}
$hits = 0 unless @newresults;
+ my $art_req_itypes;
+ if( C4::Context->preference('ArticleRequests') ) {
+ $art_req_itypes = Koha::IssuingRules->guess_article_requestable_itemtypes({ $patron ? ( categorycode => $patron->categorycode ) : () });
+ }
+
foreach my $res (@newresults) {
# must define a value for size if not present in DB
}
if (C4::Context->preference('COinSinOPACResults')) {
- my $record = GetMarcBiblio({ biblionumber => $res->{'biblionumber'} });
- $res->{coins} = GetCOinSBiblio($record);
+ my $biblio = Koha::Biblios->find( $res->{'biblionumber'} );
+ $res->{coins} = $biblio->get_coins;
}
if ( C4::Context->preference( "Babeltheque" ) and $res->{normalized_isbn} ) {
if( my $isbn = Business::ISBN->new( $res->{normalized_isbn} ) ) {
$res->{ratings} = $ratings;
$res->{my_rating} = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef;
}
+
+ # BZ17530: 'Intelligent' guess if result can be article requested
+ $res->{artreqpossible} = ( $art_req_itypes->{ $res->{itemtype} // q{} } || $art_req_itypes->{ '*' } ) ? 1 : q{};
}
if ($results_hashref->{$server}->{"hits"}){
}
## If there's just one result, redirect to the detail page
- if ($total == 1 && $format ne 'rss2'
+ if ($total == 1 && $format ne 'rss'
&& $format ne 'opensearchdescription' && $format ne 'atom') {
my $biblionumber=$newresults[0]->{biblionumber};
if (C4::Context->preference('BiblioDefaultView') eq 'isbd') {
}
## Build the page numbers on the bottom of the page
my @page_numbers;
+ my $max_result_window = $searcher->max_result_window;
+ my $hits_to_paginate = ($max_result_window && $max_result_window < $hits) ? $max_result_window : $hits;
+ $template->param( hits_to_paginate => $hits_to_paginate );
# total number of pages there will be
- my $pages = ceil($hits / $results_per_page);
+ my $pages = ceil($hits_to_paginate / $results_per_page);
my $last_page_offset = ( $pages - 1 ) * $results_per_page;
# default page number
my $current_page_number = 1;
$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'));
+if ($offset == 0) {
+ $template->param(firstPage => 1);
}
$template->param( borrowernumber => $borrowernumber);