3 # Copyright 2008 Garry Collum and the Koha Koha Development team
4 # Copyright 2010 BibLibre
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 # Script to perform searching
22 # Mostly copied from search.pl, see POD there
23 use strict; # always use
26 ## STEP 1. Load things that are used in both search page and
27 # results page and decide which template to load, operations
32 use C4::Auth qw(:DEFAULT get_session);
33 use C4::Languages qw(getAllLanguages);
35 use C4::Biblio; # GetBiblioData
37 use C4::Tags qw(get_tags);
38 use C4::Branch; # GetBranches
39 use POSIX qw(ceil floor strftime);
41 use Storable qw(thaw freeze);
44 my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
45 # create a new CGI object
46 # FIXME: no_undef_params needs to be tested
47 use CGI qw('-no_undef_params');
51 if (C4::Context->preference('BakerTaylorEnabled')) {
52 require C4::External::BakerTaylor;
53 import C4::External::BakerTaylor qw(&image_url &link_url);
57 my ($template,$borrowernumber,$cookie);
59 # decide which template to use
61 my $template_type = 'basic';
62 my @params = $cgi->param("limit");
64 my $format = $cgi->param("format") || '';
65 my $build_grouped_results = C4::Context->preference('OPACGroupResults');
66 if ($format =~ /(rss|atom|opensearchdescription)/) {
67 $template_name = 'opac-opensearch.tmpl';
69 elsif (@params && $build_grouped_results) {
70 $template_name = 'opac-results-grouped.tmpl';
72 elsif ((@params>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) ) {
73 $template_name = 'opac-results.tmpl';
76 $template_name = 'opac-advsearch.tmpl';
77 $template_type = 'advsearch';
80 ($template, $borrowernumber, $cookie) = get_template_and_user({
81 template_name => $template_name,
84 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
87 if ($template_name eq 'opac-results.tmpl') {
88 $template->param('COinSinOPACResults' => C4::Context->preference('COinSinOPACResults'));
91 # get biblionumbers stored in the cart
94 if($cgi->cookie("bib_list")){
95 my $cart_list = $cgi->cookie("bib_list");
96 @cart_list = split(/\//, $cart_list);
99 if ($format eq 'rss2' or $format eq 'opensearchdescription' or $format eq 'atom') {
100 $template->param($format => 1);
101 $template->param(timestamp => strftime("%Y-%m-%dT%H:%M:%S-00:00", gmtime)) if ($format eq 'atom');
102 # FIXME - the timestamp is a hack - the biblio update timestamp should be used for each
103 # entry, but not sure if that's worth an extra database query for each bib
105 if (C4::Context->preference("marcflavour") eq "UNIMARC" ) {
106 $template->param('UNIMARC' => 1);
108 elsif (C4::Context->preference("marcflavour") eq "MARC21" ) {
109 $template->param('usmarc' => 1);
111 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
112 $template->param( 'OPACNoResultsFound' => C4::Context->preference('OPACNoResultsFound') );
114 if (C4::Context->preference('BakerTaylorEnabled')) {
116 BakerTaylorEnabled => 1,
117 BakerTaylorImageURL => &image_url(),
118 BakerTaylorLinkURL => &link_url(),
119 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
122 if (C4::Context->preference('TagsEnabled')) {
123 $template->param(TagsEnabled => 1);
124 foreach (qw(TagsShowOnList TagsInputOnList)) {
125 C4::Context->preference($_) and $template->param($_ => 1);
130 # Deprecated, but preserved because it's interesting :-)
131 # The same thing can be accomplished with mod_rewrite in
135 #my $uri = $cgi->url(-base => 1);
136 #my $relative_url = $cgi->url(-relative=>1);
137 #$uri.="/".$relative_url."?";
139 #my @cgi_params_list = $cgi->param();
140 #my $url_params = $cgi->Vars;
142 #for my $each_param_set (@cgi_params_list) {
143 # $uri.= join "", map "\&$each_param_set=".$_, split("\0",$url_params->{$each_param_set}) if $url_params->{$each_param_set};
145 #warn "New URI:$uri";
146 # Only re-write a URI if there are params or if it already hasn't been re-written
147 #unless (($cgi->param('r')) || (!$cgi->param()) ) {
148 # print $cgi->redirect( -uri=>$uri."&r=1",
149 # -cookie => $cookie);
155 my $branches = GetBranches(); # used later in *getRecords, probably should be internalized by those functions after caching in C4::Branch is established
157 searchdomainloop => GetBranchCategories(undef,'searchdomain'),
160 # load the language limits (for search)
161 my $languages_limit_loop = getAllLanguages();
162 $template->param(search_languages_loop => $languages_limit_loop,);
164 # load the Type stuff
165 my $itemtypes = GetItemTypes;
166 # the index parameter is different for item-level itemtypes
167 my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype';
171 my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes");
173 if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
174 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
175 my %row =( number=>$cnt++,
176 ccl => "$itype_or_itemtype,phr",
177 code => $thisitemtype,
178 selected => $selected,
179 description => $itemtypes->{$thisitemtype}->{'description'},
181 imageurl=> getitemtypeimagelocation( 'opac', $itemtypes->{$thisitemtype}->{'imageurl'} ),
183 $selected = 0; # set to zero after first pass through
184 push @itemtypesloop, \%row;
187 my $advsearchtypes = GetAuthorisedValues($advanced_search_types, '', 'opac');
188 for my $thisitemtype (@$advsearchtypes) {
191 ccl => $advanced_search_types,
192 code => $thisitemtype->{authorised_value},
193 selected => $selected,
194 description => $thisitemtype->{'lib'},
196 imageurl=> getitemtypeimagelocation( 'opac', $thisitemtype->{'imageurl'} ),
198 push @itemtypesloop, \%row;
201 $template->param(itemtypeloop => \@itemtypesloop);
203 # # load the itypes (Called item types in the template -- just authorized values for searching)
204 # my ($itypecount,@itype_loop) = GetCcodes();
205 # $template->param(itypeloop=>\@itype_loop,);
207 # The following should only be loaded if we're bringing up the advanced search template
208 if ( $template_type && $template_type eq 'advsearch' ) {
209 # load the servers (used for searching -- to do federated searching, etc.)
210 my $primary_servers_loop;# = displayPrimaryServers();
211 $template->param(outer_servers_loop => $primary_servers_loop,);
213 my $secondary_servers_loop;
214 $template->param(outer_sup_servers_loop => $secondary_servers_loop,);
216 # set the default sorting
217 if ( C4::Context->preference('OPACdefaultSortField')
218 && C4::Context->preference('OPACdefaultSortOrder') ) {
219 my $default_sort_by =
220 C4::Context->preference('OPACdefaultSortField') . '_'
221 . C4::Context->preference('OPACdefaultSortOrder');
222 $template->param( sort_by => $default_sort_by );
225 # determine what to display next to the search boxes (ie, boolean option
226 # shouldn't appear on the first one, scan indexes should, adding a new
227 # box should only appear on the last, etc.
228 my @search_boxes_array;
229 my $search_boxes_count = 3; # begin whith 3 boxes
230 for (my $i=1;$i<=$search_boxes_count;$i++) {
231 # if it's the first one, don't display boolean option, but show scan indexes
233 push @search_boxes_array,
239 # if it's the last one, show the 'add field' box
240 elsif ($i==$search_boxes_count) {
241 push @search_boxes_array,
248 push @search_boxes_array,
255 $template->param(uc( C4::Context->preference("marcflavour")) => 1, # we already did this for UNIMARC
257 search_boxes_loop => \@search_boxes_array);
259 # use the global setting by default
260 if ( C4::Context->preference("expandedSearchOption") == 1 ) {
261 $template->param( expanded_options => C4::Context->preference("expandedSearchOption") );
263 # but let the user override it
264 if (defined $cgi->param('expanded_options')) {
265 if ( ($cgi->param('expanded_options') == 0) || ($cgi->param('expanded_options') == 1 ) ) {
266 $template->param( expanded_options => $cgi->param('expanded_options'));
269 output_html_with_http_headers $cgi, $cookie, $template->output;
273 ### OK, if we're this far, we're performing an actual search
275 # Fetch the paramater list as a hash in scalar context:
276 # * returns paramater list as tied hash ref
277 # * we can edit the values by changing the key
278 # * multivalued CGI paramaters are returned as a packaged string separated by "\0" (null)
279 my $params = $cgi->Vars;
281 $tag = $params->{tag} if $params->{tag};
284 # String with params with the search criteria for the paging in opac-detail
285 my $pasarParams = '';
287 for (keys %$params) {
288 my @pasarParam = split("\0", $params->{$_});
289 for my $paramValue(@pasarParam) {
290 $pasarParams .= '&' if ($j > 0);
291 $pasarParams .= $_ . '=' . $paramValue;
296 # Params that can have more than one value
297 # sort by is used to sort the query
298 # in theory can have more than one but generally there's just one
301 if ( C4::Context->preference('OPACdefaultSortField')
302 && C4::Context->preference('OPACdefaultSortOrder') ) {
304 C4::Context->preference('OPACdefaultSortField') . '_'
305 . C4::Context->preference('OPACdefaultSortOrder');
308 my @allowed_sortby = qw /acqdate_asc acqdate_dsc author_az author_za call_number_asc call_number_dsc popularity_asc popularity_dsc pubdate_asc pubdate_dsc relevance title_az title_za/;
309 @sort_by = split("\0",$params->{'sort_by'}) if $params->{'sort_by'};
310 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
311 foreach my $sort (@sort_by) {
312 if ( $sort ~~ @allowed_sortby ) {
313 $template->param($sort => 1);
316 $template->param('sort_by' => $sort_by[0]);
318 # Use the servers defined, or just search our local catalog(default)
320 @servers = split("\0",$params->{'server'}) if $params->{'server'};
322 #FIXME: this should be handled using Context.pm
323 @servers = ("biblioserver");
324 # @servers = C4::Context->config("biblioserver");
327 # operators include boolean and proximity operators and are used
328 # to evaluate multiple operands
330 @operators = split("\0",$params->{'op'}) if $params->{'op'};
332 # indexes are query qualifiers, like 'title', 'author', etc. They
333 # can be single or multiple parameters separated by comma: kw,right-Truncation
335 @indexes = split("\0",$params->{'idx'}) if $params->{'idx'};
337 # if a simple index (only one) display the index used in the top search box
338 if ($indexes[0] && !$indexes[1]) {
339 $template->param("ms_".$indexes[0] => 1);
341 # an operand can be a single term, a phrase, or a complete ccl query
343 @operands = split("\0",$params->{'q'}) if $params->{'q'};
345 # if a simple search, display the value in the search box
346 if ($operands[0] && !$operands[1]) {
347 $template->param(ms_value => $operands[0]);
350 # limits are use to limit to results to a pre-defined category such as branch or language
352 @limits = split("\0",$params->{'limit'}) if $params->{'limit'};
354 if($params->{'multibranchlimit'}) {
355 push @limits, '('.join( " or ", map { "branch: $_ " } @{ GetBranchesInCategory( $params->{'multibranchlimit'} ) } ).')';
359 foreach my $limit(@limits) {
360 if ($limit =~/available/) {
364 $template->param(available => $available);
366 # append year limits if they exist
367 if ($params->{'limit-yr'}) {
368 if ($params->{'limit-yr'} =~ /\d{4}-\d{4}/) {
369 my ($yr1,$yr2) = split(/-/, $params->{'limit-yr'});
370 push @limits, "yr,st-numeric,ge=$yr1 and yr,st-numeric,le=$yr2";
372 elsif ($params->{'limit-yr'} =~ /\d{4}/) {
373 push @limits, "yr,st-numeric=$params->{'limit-yr'}";
376 #FIXME: Should return a error to the user, incorect date format specified
380 # Params that can only have one value
381 my $scan = $params->{'scan'};
382 my $count = C4::Context->preference('OPACnumSearchResults') || 20;
383 my $countRSS = C4::Context->preference('numSearchRSSResults') || 50;
384 my $results_per_page = $params->{'count'} || $count;
385 my $offset = $params->{'offset'} || 0;
386 my $page = $cgi->param('page') || 1;
387 $offset = ($page-1)*$results_per_page if $page>1;
389 my $expanded_facet = $params->{'expand'};
391 # Define some global variables
392 my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type);
396 ## I. BUILD THE QUERY
397 my $lang = C4::Templates::getlanguage($cgi, 'opac');
398 ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by, 0, $lang);
400 sub _input_cgi_parse ($) {
402 for my $this_cgi ( split('&',shift) ) {
403 next unless $this_cgi;
404 $this_cgi =~ /(.*?)=(.*)/;
405 push @elements, { input_name => $1, input_value => $2 };
410 ## parse the query_cgi string and put it into a form suitable for <input>s
411 my @query_inputs = _input_cgi_parse($query_cgi);
412 $template->param ( QUERY_INPUTS => \@query_inputs );
414 ## parse the limit_cgi string and put it into a form suitable for <input>s
415 my @limit_inputs = $limit_cgi ? _input_cgi_parse($limit_cgi) : ();
417 # add OPAC 'hidelostitems'
418 #if (C4::Context->preference('hidelostitems') == 1) {
419 # # either lost ge 0 or no value in the lost register
420 # $query ="($query) and ( (lost,st-numeric <= 0) or ( allrecords,AlwaysMatches='' not lost,AlwaysMatches='') )";
423 # add OPAC suppression - requires at least one item indexed with Suppress
424 if (C4::Context->preference('OpacSuppression')) {
425 $query = "($query) not Suppress=1";
428 $template->param ( LIMIT_INPUTS => \@limit_inputs );
429 $template->param ( OPACResultsSidebar => C4::Context->preference('OPACResultsSidebar'));
431 ## II. DO THE SEARCH AND GET THE RESULTS
432 my $total = 0; # the total results for the whole set
433 my $facets; # this object stores the faceted results that display on the left-hand of the results page
439 $query_cgi = "tag=" .$tag . "&" . $query_cgi;
440 my $taglist = get_tags({term=>$tag, approved=>1});
441 $results_hashref->{biblioserver}->{hits} = scalar (@$taglist);
442 my @biblist = (map {GetBiblioData($_->{biblionumber})} @$taglist);
443 my @marclist = (map {$_->{marc}} @biblist );
444 $DEBUG and printf STDERR "taglist (%s biblionumber)\nmarclist (%s records)\n", scalar(@$taglist), scalar(@marclist);
445 $results_hashref->{biblioserver}->{RECORDS} = \@marclist;
446 # FIXME: tag search and standard search should work together, not exclusively
447 # FIXME: No facets for tags search.
449 elsif (C4::Context->preference('NoZebra')) {
451 ($error, $results_hashref, $facets) = NZgetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan);
453 } elsif ($build_grouped_results) {
455 ($error, $results_hashref, $facets) = C4::Search::pazGetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan);
458 $pasarParams .= '&query=' . $query;
459 $pasarParams .= '&count=' . $results_per_page;
460 $pasarParams .= '&simple_query=' . $simple_query;
461 $pasarParams .= '&query_type=' . $query_type if ($query_type);
463 ($error, $results_hashref, $facets) = getRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan);
466 # This sorts the facets into alphabetical order
468 foreach my $f (@$facets) {
469 $f->{facets} = [ sort { uc($a->{facet_title_value}) cmp uc($b->{facet_title_value}) } @{ $f->{facets} } ];
471 @$facets = sort {$a->{expand} cmp $b->{expand}} @$facets;
474 # use Data::Dumper; print STDERR "-" x 25, "\n", Dumper($results_hashref);
476 $template->param(query_error => $error.$@);
477 output_html_with_http_headers $cgi, $cookie, $template->output;
481 # At this point, each server has given us a result set
482 # now we build that set for template display
483 my @sup_results_array;
484 for (my $i=0;$i<@servers;$i++) {
485 my $server = $servers[$i];
486 if ($server && $server =~/biblioserver/) { # this is the local bibliographic server
487 $hits = $results_hashref->{$server}->{"hits"};
488 my $page = $cgi->param('page') || 0;
490 if ($build_grouped_results) {
491 foreach my $group (@{ $results_hashref->{$server}->{"GROUPS"} }) {
492 # because pazGetRecords handles retieving only the records
493 # we want as specified by $offset and $results_per_page,
494 # we need to set the offset parameter of searchResults to 0
495 my @group_results = searchResults( 'opac', $query_desc, $group->{'group_count'},$results_per_page, 0, $scan,
496 $group->{"RECORDS"});
497 push @newresults, { group_label => $group->{'group_label'}, GROUP_RESULTS => \@group_results };
500 @newresults = searchResults('opac', $query_desc, $hits, $results_per_page, $offset, $scan,
501 $results_hashref->{$server}->{"RECORDS"});
504 # must define a value for size if not present in DB
505 # in order to avoid problems generated by the default size value in TT
506 foreach my $line (@newresults) {
507 if ( not exists $line->{'size'} ) { $line->{'size'} = "" }
508 # while we're checking each line, see if item is in the cart
509 if ( grep {$_ eq $line->{'biblionumber'}} @cart_list) {
510 $line->{'incart'} = 1;
515 if (C4::Context->preference('TagsEnabled') and
516 $tag_quantity = C4::Context->preference('TagsShowOnList')) {
517 foreach (@newresults) {
518 my $bibnum = $_->{biblionumber} or next;
519 $_->{itemsissued} = CountItemsIssued( $bibnum );
520 $_ ->{'TagLoop'} = get_tags({biblionumber=>$bibnum, approved=>1, 'sort'=>'-weight',
521 limit=>$tag_quantity });
524 if (C4::Context->preference('COinSinOPACResults')) {
525 foreach (@newresults) {
526 my $record = GetMarcBiblio($_->{'biblionumber'});
527 $_->{coins} = GetCOinSBiblio($record);
531 if ($results_hashref->{$server}->{"hits"}){
532 $total = $total + $results_hashref->{$server}->{"hits"};
535 # Opac search history
537 if (C4::Context->preference('EnableOpacSearchHistory')) {
540 # Getting the (maybe) already sent cookie
541 my $searchcookie = $cgi->cookie('KohaOpacRecentSearches');
543 $searchcookie = uri_unescape($searchcookie);
544 if (thaw($searchcookie)) {
545 @recentSearches = @{thaw($searchcookie)};
549 # Adding the new search if needed
550 if (!$borrowernumber || $borrowernumber eq '') {
551 # To a cookie (the user is not logged in)
552 if (($params->{'offset'}||'') eq '') {
553 push @recentSearches, {
554 "query_desc" => $query_desc || "unknown",
555 "query_cgi" => $query_cgi || "unknown",
559 $template->param(ShowOpacRecentSearchLink => 1);
562 shift @recentSearches if (@recentSearches > 15);
563 # Pushing the cookie back
564 $newsearchcookie = $cgi->cookie(
565 -name => 'KohaOpacRecentSearches',
566 # We uri_escape the whole freezed structure so we're sure we won't have any encoding problems
567 -value => uri_escape(freeze(\@recentSearches)),
570 $cookie = [$cookie, $newsearchcookie];
573 # To the session (the user is logged in)
574 if (($params->{'offset'}||'') eq '') {
575 AddSearchHistory($borrowernumber, $cgi->cookie("CGISESSID"), $query_desc, $query_cgi, $total);
576 $template->param(ShowOpacRecentSearchLink => 1);
580 ## If there's just one result, redirect to the detail page
581 if ($total == 1 && $format ne 'rss2'
582 && $format ne 'opensearchdescription' && $format ne 'atom') {
583 my $biblionumber=$newresults[0]->{biblionumber};
584 if (C4::Context->preference('BiblioDefaultView') eq 'isbd') {
585 print $cgi->redirect("/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=$biblionumber");
586 } elsif (C4::Context->preference('BiblioDefaultView') eq 'marc') {
587 print $cgi->redirect("/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=$biblionumber");
589 print $cgi->redirect("/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber");
594 if (!C4::Context->preference('NoZebra') && !$build_grouped_results) {
595 # We build the encrypted list of first OPACnumSearchResults biblios to pass with the search criteria for paging on opac-detail
596 $pasarParams .= '&listBiblios=';
598 foreach (@newresults) {
599 my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
600 $pasarParams .= $bibnum . ',';
602 last if ($j == $results_per_page);
604 chop $pasarParams if ($pasarParams =~ /,$/);
605 $pasarParams .= '&total=' . int($total) if ($pasarParams !~ /total=(?:[0-9]+)?/);
607 my $session = get_session($cgi->cookie("CGISESSID"));
608 $session->param('busc' => $pasarParams);
612 $template->param(total => $hits);
613 my $limit_cgi_not_availablity = $limit_cgi;
614 $limit_cgi_not_availablity =~ s/&limit=available//g if defined $limit_cgi_not_availablity;
615 $template->param(limit_cgi_not_availablity => $limit_cgi_not_availablity);
616 $template->param(limit_cgi => $limit_cgi);
617 $template->param(countrss => $countRSS );
618 $template->param(query_cgi => $query_cgi);
619 $template->param(query_desc => $query_desc);
620 $template->param(limit_desc => $limit_desc);
621 $template->param(offset => $offset);
622 $template->param(DisplayMultiPlaceHold => $DisplayMultiPlaceHold);
623 if ($query_desc || $limit_desc) {
624 $template->param(searchdesc => 1);
626 $template->param(stopwords_removed => "@$stopwords_removed") if $stopwords_removed;
627 $template->param(results_per_page => $results_per_page);
628 $template->param(SEARCH_RESULTS => \@newresults,
629 OPACItemsResultsDisplay => (C4::Context->preference("OPACItemsResultsDisplay") eq "itemdetails"?1:0),
631 if (C4::Context->preference("OPACLocalCoverImages")){
632 $template->param(OPACLocalCoverImages => 1);
633 $template->param(OPACLocalCoverImagesPriority => C4::Context->preference("OPACLocalCoverImagesPriority"));
635 ## Build the page numbers on the bottom of the page
637 # total number of pages there will be
638 my $pages = ceil($hits / $results_per_page);
639 # default page number
640 my $current_page_number = 1;
642 $current_page_number = ( $offset / $results_per_page + 1 );
644 my $previous_page_offset;
645 if ( $offset >= $results_per_page ) {
646 $previous_page_offset = $offset - $results_per_page;
648 my $next_page_offset = $offset + $results_per_page;
649 # If we're within the first 10 pages, keep it simple
650 #warn "current page:".$current_page_number;
651 if ($current_page_number < 10) {
652 # just show the first 10 pages
653 # Loop through the pages
654 my $pages_to_show = 10;
655 $pages_to_show = $pages if $pages<10;
656 for ($i=1; $i<=$pages_to_show;$i++) {
657 # the offset for this page
658 my $this_offset = (($i*$results_per_page)-$results_per_page);
659 # the page number for this page
660 my $this_page_number = $i;
661 # put it in the array
663 { offset => $this_offset,
664 pg => $this_page_number,
665 highlight => $this_page_number == $current_page_number,
666 sort_by => join ' ', @sort_by
672 # now, show twenty pages, with the current one smack in the middle
674 for ($i=$current_page_number; $i<=($current_page_number + 20 );$i++) {
675 my $this_offset = ((($i-9)*$results_per_page)-$results_per_page);
676 my $this_page_number = $i-9;
677 if ( $this_page_number <= $pages ) {
679 { offset => $this_offset,
680 pg => $this_page_number,
681 highlight => $this_page_number == $current_page_number,
682 sort_by => join ' ', @sort_by
688 $template->param( PAGE_NUMBERS => \@page_numbers,
689 previous_page_offset => $previous_page_offset) unless $pages < 2;
690 $template->param(next_page_offset => $next_page_offset) unless $pages eq $current_page_number;
694 $template->param(searchdesc => 1,query_desc => $query_desc,limit_desc => $limit_desc);
696 } # end of the if local
697 # asynchronously search the authority server
698 elsif ($server && $server =~/authorityserver/) { # this is the local authority server
699 my @inner_sup_results_array;
700 for my $sup_record ( @{$results_hashref->{$server}->{"RECORDS"}} ) {
701 my $marc_record_object = MARC::Record->new_from_usmarc($sup_record);
702 my $title_field = $marc_record_object->field(100);
703 push @inner_sup_results_array, {
704 'title' => $title_field->subfield('a'),
705 'link' => "&idx=an&q=".$marc_record_object->field('001')->as_string(),
708 my $servername = $server;
709 push @sup_results_array, { servername => $servername,
710 inner_sup_results_loop => \@inner_sup_results_array} if @inner_sup_results_array;
712 # FIXME: can add support for other targets as needed here
713 $template->param( outer_sup_results_loop => \@sup_results_array);
714 } #/end of the for loop
715 #$template->param(FEDERATED_RESULTS => \@results_array);
718 #classlist => $classlist,
721 facets_loop => $facets,
722 displayFacetCount=> C4::Context->preference('displayFacetCount')||0,
724 search_error => $error,
727 if ($query_desc || $limit_desc) {
728 $template->param(searchdesc => 1);
731 # VI. BUILD THE TEMPLATE
732 # Build drop-down list for 'Add To:' menu...
733 my $session = get_session($cgi->cookie("CGISESSID"));
735 my $pubshelves = $session->param('pubshelves');
736 my $barshelves = $session->param('barshelves');
737 foreach my $shelf (@$pubshelves) {
738 next if ( ($shelf->{'owner'} != ($borrowernumber ? $borrowernumber : -1)) && ($shelf->{'category'} < 3) );
739 push (@addpubshelves, $shelf);
742 if (@addpubshelves) {
743 $template->param( addpubshelves => scalar (@addpubshelves));
744 $template->param( addpubshelvesloop => \@addpubshelves);
747 if (defined $barshelves) {
748 $template->param( addbarshelves => scalar (@$barshelves));
749 $template->param( addbarshelvesloop => $barshelves);
752 my $content_type = ($format eq 'rss' or $format eq 'atom') ? $format : 'html';
754 # If GoogleIndicTransliteration system preference is On Set paramter to load Google's javascript in OPAC search screens
755 if (C4::Context->preference('GoogleIndicTransliteration')) {
756 $template->param('GoogleIndicTransliteration' => 1);
759 output_with_http_headers $cgi, $cookie, $template->output, $content_type;