use C4::Output;
use C4::Auth qw(:DEFAULT get_session);
-use C4::Languages qw(getAllLanguages);
+use C4::Languages qw(getLanguages);
use C4::Search;
+use C4::Search::History;
use C4::Biblio; # GetBiblioData
use C4::Koha;
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");
# create a new CGI object
# FIXME: no_undef_params needs to be tested
-use CGI qw( -no_undef_params -utf8 );
+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/ ) {
+ 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 => [ ( split( 'multibranchlimit-', $branch_group_limit ) )[1] ]
+ -values => substr($branch_group_limit, 17)
);
} else {
$cgi->append(
}
my ($template,$borrowernumber,$cookie);
-my $lang = C4::Templates::getlanguage($cgi, 'opac');
# decide which template to use
my $template_name;
my $template_type = 'basic';
authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
}
);
+
+my $lang = C4::Languages::getlanguage($cgi);
+
if ($template_name eq 'opac-results.tmpl') {
$template->param('COinSinOPACResults' => C4::Context->preference('COinSinOPACResults'));
}
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)
-my $languages_limit_loop = getAllLanguages($lang);
+my $languages_limit_loop = getLanguages($lang, 1);
$template->param(search_languages_loop => $languages_limit_loop,);
# load the Type stuff
}
$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.)
# limits are use to limit to results to a pre-defined category such as branch or language
my @limits = $cgi->param('limit');
+my @nolimits = $cgi->param('nolimit');
+my %is_nolimit = map { $_ => 1 } @nolimits;
+@limits = grep { not $is_nolimit{$_} } @limits;
@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;
for my $this_cgi ( split('&',shift) ) {
next unless $this_cgi;
$this_cgi =~ /(.*?)=(.*)/;
- push @elements, { input_name => $1, input_value => $2 };
+ push @elements, { input_name => $1, input_value => uri_unescape($2) };
}
return @elements;
}
my $taglist = get_tags({term=>$tag, approved=>1});
$results_hashref->{biblioserver}->{hits} = scalar (@$taglist);
my @biblist = (map {GetBiblioData($_->{biblionumber})} @$taglist);
- my @marclist = (map {$_->{marc}} @biblist );
+ my @marclist = (map { (C4::Context->config('zebra_bib_index_mode') eq 'dom')? $_->{marcxml}: $_->{marc}; } @biblist);
$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
@newresults = searchResults('opac', $query_desc, $hits, $results_per_page, $offset, $scan,
$results_hashref->{$server}->{"RECORDS"});
}
+ $hits = 0 unless @newresults;
+
+ 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
- foreach my $line (@newresults) {
- if ( not exists $line->{'size'} ) { $line->{'size'} = "" }
+ # 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'};
}
if ($results_hashref->{$server}->{"hits"}){
- $total = $total + $results_hashref->{$server}->{"hits"};
+ $total = $total + $hits;
}
# 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)};
- }
- }
-
- # Adding the new search if needed
- my $path_info = $cgi->url(-path_info=>1);
- my $query_cgi_history = $cgi->url(-query=>1);
- $query_cgi_history =~ s/^$path_info\?//;
- $query_cgi_history =~ s/;/&/g;
- my $query_desc_history = "$query_desc, $limit_desc";
-
- if (!$borrowernumber || $borrowernumber eq '') {
- # 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",
- "time" => time(),
- "total" => $total
- };
- $template->param(ShowOpacRecentSearchLink => 1);
- }
-
- shift @recentSearches if (@recentSearches > 15);
- # 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_utf8(freeze(\@recentSearches)),
- -expires => ''
- );
- $cookie = [$cookie, $newsearchcookie];
- }
- else {
- # To the session (the user is logged in)
- if (!$offset) {
- AddSearchHistory($borrowernumber, $cgi->cookie("CGISESSID"), $query_desc_history, $query_cgi_history, $total);
- $template->param(ShowOpacRecentSearchLink => 1);
+ unless ( $offset ) {
+ my $path_info = $cgi->url(-path_info=>1);
+ my $query_cgi_history = $cgi->url(-query=>1);
+ $query_cgi_history =~ s/^$path_info\?//;
+ $query_cgi_history =~ s/;/&/g;
+ my $query_desc_history = join ", ", grep { defined $_ } $query_desc, $limit_desc;
+
+ unless ( $borrowernumber ) {
+ my $new_searches = C4::Search::History::add_to_session({
+ cgi => $cgi,
+ query_desc => $query_desc_history,
+ query_cgi => $query_cgi_history,
+ total => $total,
+ type => "biblio",
+ });
+ } else {
+ # To the session (the user is logged in)
+ C4::Search::History::add({
+ userid => $borrowernumber,
+ sessionid => $cgi->cookie("CGISESSID"),
+ query_desc => $query_desc_history,
+ query_cgi => $query_cgi_history,
+ total => $total,
+ type => "biblio",
+ });
}
}
+ $template->param( EnableOpacSearchHistory => 1 );
}
+
## If there's just one result, redirect to the detail page
if ($total == 1 && $format ne 'rss2'
&& $format ne 'opensearchdescription' && $format ne 'atom') {
} #/end of the for loop
#$template->param(FEDERATED_RESULTS => \@results_array);
+my @input_values = map { Encode::decode_utf8($_->{input_value}) } @limit_inputs;
+for my $facet ( @$facets ) {
+ for my $entry ( @{ $facet->{facets} } ) {
+ my $index = $entry->{type_link_value};
+ my $value = $entry->{facet_link_value};
+ $entry->{active} = grep { $_ eq qq{$index:$value} } @input_values;
+ }
+}
+
+
$template->param(
#classlist => $classlist,
total => $total,
$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;