Merge commit 'origin/master' into bl-sopac
[koha.git] / opac / opac-search.pl
1 #!/usr/bin/perl
2 # Script to perform searching
3 # Mostly copied from search.pl, see POD there
4 use strict;            # always use
5 use warnings;
6
7 ## STEP 1. Load things that are used in both search page and
8 # results page and decide which template to load, operations 
9 # to perform, etc.
10 ## load Koha modules
11 use C4::Context;
12 use C4::Output;
13 use C4::Auth qw(:DEFAULT get_session);
14 use C4::Search;
15 use C4::Biblio;  # GetBiblioData
16 use C4::Koha;
17 use C4::Tags qw(get_tags);
18 use POSIX qw(ceil floor strftime);
19 use C4::Branch; # GetBranches
20
21 # create a new CGI object
22 # FIXME: no_undef_params needs to be tested
23 use CGI qw('-no_undef_params');
24 my $cgi = new CGI;
25
26 BEGIN {
27         if (C4::Context->preference('BakerTaylorEnabled')) {
28                 require C4::External::BakerTaylor;
29                 import C4::External::BakerTaylor qw(&image_url &link_url);
30         }
31 }
32
33 my ($template,$borrowernumber,$cookie);
34
35 # decide which template to use
36 my $template_name;
37 my $template_type = 'basic';
38 my @params = $cgi->param("limit");
39
40 my $format = $cgi->param("format") || '';
41 my $build_grouped_results = C4::Context->preference('OPACGroupResults');
42 if ($format =~ /(rss|atom|opensearchdescription)/) {
43         $template_name = 'opac-opensearch.tmpl';
44 }
45 elsif ($build_grouped_results) {
46     $template_name = 'opac-results-grouped.tmpl';
47 }
48 elsif ((@params>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) ) {
49         $template_name = 'opac-results.tmpl';
50 }
51 else {
52     $template_name = 'opac-advsearch.tmpl';
53     $template_type = 'advsearch';
54 }
55 # load the template
56 ($template, $borrowernumber, $cookie) = get_template_and_user({
57     template_name => $template_name,
58     query => $cgi,
59     type => "opac",
60     authnotrequired => 1,
61     }
62 );
63
64 if ($format eq 'rss2' or $format eq 'opensearchdescription' or $format eq 'atom') {
65         $template->param($format => 1);
66     $template->param(timestamp => strftime("%Y-%m-%dT%H:%M:%S-00:00", gmtime)) if ($format eq 'atom'); 
67     # FIXME - the timestamp is a hack - the biblio update timestamp should be used for each
68     # entry, but not sure if that's worth an extra database query for each bib
69 }
70 if (C4::Context->preference("marcflavour") eq "UNIMARC" ) {
71     $template->param('UNIMARC' => 1);
72 }
73 elsif (C4::Context->preference("marcflavour") eq "MARC21" ) {
74     $template->param('usmarc' => 1);
75 }
76 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
77
78 if (C4::Context->preference('BakerTaylorEnabled')) {
79         $template->param(
80                 BakerTaylorEnabled  => 1,
81                 BakerTaylorImageURL => &image_url(),
82                 BakerTaylorLinkURL  => &link_url(),
83                 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
84         );
85 }
86 if (C4::Context->preference('TagsEnabled')) {
87         $template->param(TagsEnabled => 1);
88         foreach (qw(TagsShowOnList TagsInputOnList)) {
89                 C4::Context->preference($_) and $template->param($_ => 1);
90         }
91 }
92
93 ## URI Re-Writing
94 # Deprecated, but preserved because it's interesting :-)
95 # The same thing can be accomplished with mod_rewrite in
96 # a more elegant way
97 #                  
98 #my $rewrite_flag;
99 #my $uri = $cgi->url(-base => 1);
100 #my $relative_url = $cgi->url(-relative=>1);
101 #$uri.="/".$relative_url."?";
102 #warn "URI:$uri";
103 #my @cgi_params_list = $cgi->param();
104 #my $url_params = $cgi->Vars;
105 #
106 #for my $each_param_set (@cgi_params_list) {
107 #    $uri.= join "",  map "\&$each_param_set=".$_, split("\0",$url_params->{$each_param_set}) if $url_params->{$each_param_set};
108 #}
109 #warn "New URI:$uri";
110 # Only re-write a URI if there are params or if it already hasn't been re-written
111 #unless (($cgi->param('r')) || (!$cgi->param()) ) {
112 #    print $cgi->redirect(     -uri=>$uri."&r=1",
113 #                            -cookie => $cookie);
114 #    exit;
115 #}
116
117 # load the branches
118 my $mybranch = ( C4::Context->preference('SearchMyLibraryFirst') && C4::Context->userenv && C4::Context->userenv->{branch} ) ? C4::Context->userenv->{branch} : '';
119 my $branches = GetBranches();   # used later in *getRecords, probably should be internalized by those functions after caching in C4::Branch is established
120 $template->param(
121     branchloop       => GetBranchesLoop($mybranch, 0),
122     searchdomainloop => GetBranchCategories(undef,'searchdomain'),
123 );
124
125 # load the Type stuff
126 my $itemtypes = GetItemTypes;
127 # the index parameter is different for item-level itemtypes
128 my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype';
129 my @itemtypesloop;
130 my $selected=1;
131 my $cnt;
132 my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes");
133
134 if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
135         foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
136         my %row =(  number=>$cnt++,
137                                 ccl => $itype_or_itemtype,
138                 code => $thisitemtype,
139                 selected => $selected,
140                 description => $itemtypes->{$thisitemtype}->{'description'},
141                 count5 => $cnt % 4,
142                 imageurl=> getitemtypeimagelocation( 'opac', $itemtypes->{$thisitemtype}->{'imageurl'} ),
143             );
144         $selected = 0; # set to zero after first pass through
145         push @itemtypesloop, \%row;
146         }
147 } else {
148     my $advsearchtypes = GetAuthorisedValues($advanced_search_types);
149         for my $thisitemtype (sort {$a->{'lib'} cmp $b->{'lib'}} @$advsearchtypes) {
150                 my %row =(
151                                 number=>$cnt++,
152                                 ccl => $advanced_search_types,
153                 code => $thisitemtype->{authorised_value},
154                 selected => $selected,
155                 description => $thisitemtype->{'lib'},
156                 count5 => $cnt % 4,
157                 imageurl=> getitemtypeimagelocation( 'opac', $thisitemtype->{'imageurl'} ),
158             );
159                 push @itemtypesloop, \%row;
160         }
161 }
162 $template->param(itemtypeloop => \@itemtypesloop);
163
164 # # load the itypes (Called item types in the template -- just authorized values for searching)
165 # my ($itypecount,@itype_loop) = GetCcodes();
166 # $template->param(itypeloop=>\@itype_loop,);
167
168 # The following should only be loaded if we're bringing up the advanced search template
169 if ( $template_type && $template_type eq 'advsearch' ) {
170
171     # load the servers (used for searching -- to do federated searching, etc.)
172     my $primary_servers_loop;# = displayPrimaryServers();
173     $template->param(outer_servers_loop =>  $primary_servers_loop,);
174     
175     my $secondary_servers_loop;
176     $template->param(outer_sup_servers_loop => $secondary_servers_loop,);
177
178     # set the default sorting
179     my $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') 
180         if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
181     $template->param($default_sort_by => 1);
182
183     # determine what to display next to the search boxes (ie, boolean option
184     # shouldn't appear on the first one, scan indexes should, adding a new
185     # box should only appear on the last, etc.
186     my @search_boxes_array;
187     my $search_boxes_count = C4::Context->preference("OPACAdvSearchInputCount") || 3;
188     for (my $i=1;$i<=$search_boxes_count;$i++) {
189         # if it's the first one, don't display boolean option, but show scan indexes
190         if ($i==1) {
191             push @search_boxes_array,
192                 {
193                 scan_index => 1,
194                 };
195         
196         }
197         # if it's the last one, show the 'add field' box
198         elsif ($i==$search_boxes_count) {
199             push @search_boxes_array,
200                 {
201                 boolean => 1,
202                 add_field => 1,
203                 };
204         }
205         else {
206             push @search_boxes_array,
207                 {
208                 boolean => 1,
209                 };
210         }
211
212     }
213     $template->param(uc(C4::Context->preference("marcflavour")) => 1,   # we already did this for UNIMARC
214                                           advsearch => 1,
215                       search_boxes_loop => \@search_boxes_array);
216
217 # use the global setting by default
218         if ( C4::Context->preference("expandedSearchOption") == 1 ) {
219                 $template->param( expanded_options => C4::Context->preference("expandedSearchOption") );
220         }
221         # but let the user override it
222         if (defined $cgi->param('expanded_options')) {
223             if ( ($cgi->param('expanded_options') == 0) || ($cgi->param('expanded_options') == 1 ) ) {
224             $template->param( expanded_options => $cgi->param('expanded_options'));
225             }
226         }
227     output_html_with_http_headers $cgi, $cookie, $template->output;
228     exit;
229 }
230
231 ### OK, if we're this far, we're performing an actual search
232
233 # Fetch the paramater list as a hash in scalar context:
234 #  * returns paramater list as tied hash ref
235 #  * we can edit the values by changing the key
236 #  * multivalued CGI paramaters are returned as a packaged string separated by "\0" (null)
237 my $params = $cgi->Vars;
238 my $tag;
239 $tag = $params->{tag} if $params->{tag};
240
241 # Params that can have more than one value
242 # sort by is used to sort the query
243 # in theory can have more than one but generally there's just one
244 my @sort_by;
245 my $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') 
246     if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
247
248 @sort_by = split("\0",$params->{'sort_by'}) if $params->{'sort_by'};
249 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
250 foreach my $sort (@sort_by) {
251     $template->param($sort => 1);   # FIXME: security hole.  can set any TMPL_VAR here
252 }
253 $template->param('sort_by' => $sort_by[0]);
254
255 # Use the servers defined, or just search our local catalog(default)
256 my @servers;
257 @servers = split("\0",$params->{'server'}) if $params->{'server'};
258 unless (@servers) {
259     #FIXME: this should be handled using Context.pm
260     @servers = ("biblioserver");
261     # @servers = C4::Context->config("biblioserver");
262 }
263
264 # operators include boolean and proximity operators and are used
265 # to evaluate multiple operands
266 my @operators;
267 @operators = split("\0",$params->{'op'}) if $params->{'op'};
268
269 # indexes are query qualifiers, like 'title', 'author', etc. They
270 # can be single or multiple parameters separated by comma: kw,right-Truncation 
271 my @indexes;
272 @indexes = split("\0",$params->{'idx'}) if $params->{'idx'};
273
274 # if a simple index (only one)  display the index used in the top search box
275 if ($indexes[0] && !$indexes[1]) {
276     $template->param("ms_".$indexes[0] => 1);
277 }
278 # an operand can be a single term, a phrase, or a complete ccl query
279 my @operands;
280 @operands = split("\0",$params->{'q'}) if $params->{'q'};
281
282 # if a simple search, display the value in the search box
283 if ($operands[0] && !$operands[1]) {
284     $template->param(ms_value => $operands[0]);
285 }
286
287 # limits are use to limit to results to a pre-defined category such as branch or language
288 my @limits;
289 @limits = split("\0",$params->{'limit'}) if $params->{'limit'};
290
291 if($params->{'multibranchlimit'}) {
292 push @limits, join(" or ", map { "branch: $_ "}  @{GetBranchesInCategory($params->{'multibranchlimit'})}) ;
293 }
294
295 my $available;
296 foreach my $limit(@limits) {
297     if ($limit =~/available/) {
298         $available = 1;
299     }
300 }
301 $template->param(available => $available);
302
303 # append year limits if they exist
304 if ($params->{'limit-yr'}) {
305     if ($params->{'limit-yr'} =~ /\d{4}-\d{4}/) {
306         my ($yr1,$yr2) = split(/-/, $params->{'limit-yr'});
307         push @limits, "yr,st-numeric,ge=$yr1 and yr,st-numeric,le=$yr2";
308     }
309     elsif ($params->{'limit-yr'} =~ /\d{4}/) {
310         push @limits, "yr,st-numeric=$params->{'limit-yr'}";
311     }
312     else {
313         #FIXME: Should return a error to the user, incorect date format specified
314     }
315 }
316
317 # Params that can only have one value
318 my $scan = $params->{'scan'};
319 my $count = C4::Context->preference('OPACnumSearchResults') || 20;
320 my $results_per_page = $params->{'count'} || $count;
321 my $offset = $params->{'offset'} || 0;
322 my $page = $cgi->param('page') || 1;
323 $offset = ($page-1)*$results_per_page if $page>1;
324 my $hits;
325 my $expanded_facet = $params->{'expand'};
326
327 # Define some global variables
328 my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type);
329
330 my @results;
331
332 ## I. BUILD THE QUERY
333 ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by);
334
335 sub _input_cgi_parse ($) { 
336     my @elements;
337     for my $this_cgi ( split('&',shift) ) {
338         next unless $this_cgi;
339         $this_cgi =~ /(.*?)=(.*)/;
340         push @elements, { input_name => $1, input_value => $2 };
341     }
342     return @elements;
343 }
344
345 ## parse the query_cgi string and put it into a form suitable for <input>s
346 my @query_inputs = _input_cgi_parse($query_cgi);
347 $template->param ( QUERY_INPUTS => \@query_inputs );
348
349 ## parse the limit_cgi string and put it into a form suitable for <input>s
350 my @limit_inputs = $limit_cgi ? _input_cgi_parse($limit_cgi) : ();
351
352 # add OPAC 'hidelostitems'
353 if (C4::Context->preference('hidelostitems') == 1) {
354     # either lost ge 0 or no value in the lost register
355     $query ="($query) and ( (lost,st-numeric <= 0) or ( allrecords,AlwaysMatches='' not lost,AlwaysMatches='') )";
356 }
357
358 # add OPAC suppression - requires at least one item indexed with Suppress
359 if (C4::Context->preference('OpacSuppression')) {
360     $query = "($query) not Suppress=1";
361 }
362
363 $template->param ( LIMIT_INPUTS => \@limit_inputs );
364
365 ## II. DO THE SEARCH AND GET THE RESULTS
366 my $total = 0; # the total results for the whole set
367 my $facets; # this object stores the faceted results that display on the left-hand of the results page
368 my @results_array;
369 my $results_hashref;
370 my @coins;
371
372 if ($tag) {
373         $query_cgi = "tag=" .$tag . "&" . $query_cgi;
374         my $taglist = get_tags({term=>$tag, approved=>1});
375         $results_hashref->{biblioserver}->{hits} = scalar (@$taglist);
376         my @biblist  = (map {GetBiblioData($_->{biblionumber})} @$taglist);
377         my @marclist = (map {$_->{marc}} @biblist );
378         $DEBUG and printf STDERR "taglist (%s biblionumber)\nmarclist (%s records)\n", scalar(@$taglist), scalar(@marclist);
379         $results_hashref->{biblioserver}->{RECORDS} = \@marclist;
380         # FIXME: tag search and standard search should work together, not exclusively
381         # FIXME: No facets for tags search.
382 }
383 elsif (C4::Context->preference('NoZebra')) {
384     eval {
385         ($error, $results_hashref, $facets) = NZgetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan);
386     };
387 } elsif ($build_grouped_results) {
388     eval {
389         ($error, $results_hashref, $facets) = C4::Search::pazGetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan);
390     };
391 } else {
392     eval {
393         ($error, $results_hashref, $facets) = getRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan);
394     };
395 }
396 # use Data::Dumper; print STDERR "-" x 25, "\n", Dumper($results_hashref);
397 if ($@ || $error) {
398     $template->param(query_error => $error.$@);
399     output_html_with_http_headers $cgi, $cookie, $template->output;
400     exit;
401 }
402
403 # At this point, each server has given us a result set
404 # now we build that set for template display
405 my @sup_results_array;
406 for (my $i=0;$i<=@servers;$i++) {
407     my $server = $servers[$i];
408     if ($server && $server =~/biblioserver/) { # this is the local bibliographic server
409         $hits = $results_hashref->{$server}->{"hits"};
410         my $page = $cgi->param('page') || 0;
411         my @newresults;
412         if ($build_grouped_results) {
413             foreach my $group (@{ $results_hashref->{$server}->{"GROUPS"} }) {
414                 # because pazGetRecords handles retieving only the records
415                 # we want as specified by $offset and $results_per_page,
416                 # we need to set the offset parameter of searchResults to 0
417                 my @group_results = searchResults( $query_desc, $group->{'group_count'},$results_per_page, 0, $scan,
418                                                    @{ $group->{"RECORDS"} });
419                 push @newresults, { group_label => $group->{'group_label'}, GROUP_RESULTS => \@group_results };
420             }
421         } else {
422             @newresults = searchResults( $query_desc,$hits,$results_per_page,$offset,$scan,@{$results_hashref->{$server}->{"RECORDS"}});
423         }
424                 my $tag_quantity;
425                 if (C4::Context->preference('TagsEnabled') and
426                         $tag_quantity = C4::Context->preference('TagsShowOnList')) {
427                         foreach (@newresults) {
428                                 my $bibnum = $_->{biblionumber} or next;
429                                 $_->{itemsissued} = CountItemsIssued( $bibnum );
430                                 $_ ->{'TagLoop'} = get_tags({biblionumber=>$bibnum, approved=>1, 'sort'=>'-weight',
431                                                                                 limit=>$tag_quantity });
432                         }
433                 }
434                 foreach (@newresults) {
435                     $_->{coins} = GetCOinSBiblio($_->{'biblionumber'});
436                 }
437       
438         if ($results_hashref->{$server}->{"hits"}){
439             $total = $total + $results_hashref->{$server}->{"hits"};
440         }
441         ## If there's just one result, redirect to the detail page
442         if ($total == 1) {         
443             my $biblionumber=$newresults[0]->{biblionumber};
444             if (C4::Context->preference('BiblioDefaultView') eq 'isbd') {
445                 print $cgi->redirect("/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=$biblionumber");
446             } elsif  (C4::Context->preference('BiblioDefaultView') eq 'marc') {
447                 print $cgi->redirect("/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=$biblionumber");
448             } else {
449                 print $cgi->redirect("/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber");
450             } 
451             exit;
452         }
453         if ($hits) {
454             $template->param(total => $hits);
455             my $limit_cgi_not_availablity = $limit_cgi;
456             $limit_cgi_not_availablity =~ s/&limit=available//g if defined $limit_cgi_not_availablity;
457             $template->param(limit_cgi_not_availablity => $limit_cgi_not_availablity);
458             $template->param(limit_cgi => $limit_cgi);
459             $template->param(query_cgi => $query_cgi);
460             $template->param(query_desc => $query_desc);
461             $template->param(limit_desc => $limit_desc);
462             if ($query_desc || $limit_desc) {
463                 $template->param(searchdesc => 1);
464             }
465             $template->param(stopwords_removed => "@$stopwords_removed") if $stopwords_removed;
466             $template->param(results_per_page =>  $results_per_page);
467             $template->param(SEARCH_RESULTS => \@newresults,
468                                 OPACItemsResultsDisplay => (C4::Context->preference("OPACItemsResultsDisplay") eq "itemdetails"?1:0),
469                             );
470             ## Build the page numbers on the bottom of the page
471             my @page_numbers;
472             # total number of pages there will be
473             my $pages = ceil($hits / $results_per_page);
474             # default page number
475             my $current_page_number = 1;
476             $current_page_number = ($offset / $results_per_page + 1) if $offset;
477             my $previous_page_offset = $offset - $results_per_page unless ($offset - $results_per_page <0);
478             my $next_page_offset = $offset + $results_per_page;
479             # If we're within the first 10 pages, keep it simple
480             #warn "current page:".$current_page_number;
481             if ($current_page_number < 10) {
482                 # just show the first 10 pages
483                 # Loop through the pages
484                 my $pages_to_show = 10;
485                 $pages_to_show = $pages if $pages<10;
486                 for ($i=1; $i<=$pages_to_show;$i++) {
487                     # the offset for this page
488                     my $this_offset = (($i*$results_per_page)-$results_per_page);
489                     # the page number for this page
490                     my $this_page_number = $i;
491                     # it should only be highlighted if it's the current page
492                     my $highlight = 1 if ($this_page_number == $current_page_number);
493                     # put it in the array
494                     push @page_numbers, { offset => $this_offset, pg => $this_page_number, highlight => $highlight, sort_by => join " ",@sort_by };
495                                 
496                 }
497                         
498             }
499             # now, show twenty pages, with the current one smack in the middle
500             else {
501                 for ($i=$current_page_number; $i<=($current_page_number + 20 );$i++) {
502                     my $this_offset = ((($i-9)*$results_per_page)-$results_per_page);
503                     my $this_page_number = $i-9;
504                     my $highlight = 1 if ($this_page_number == $current_page_number);
505                     if ($this_page_number <= $pages) {
506                         push @page_numbers, { offset => $this_offset, pg => $this_page_number, highlight => $highlight, sort_by => join " ",@sort_by };
507                     }
508                 }
509                         
510             }
511             $template->param(   PAGE_NUMBERS => \@page_numbers,
512                                 previous_page_offset => $previous_page_offset) unless $pages < 2;
513             $template->param(next_page_offset => $next_page_offset) unless $pages eq $current_page_number;
514          }
515         # no hits
516         else {
517             $template->param(searchdesc => 1,query_desc => $query_desc,limit_desc => $limit_desc);
518         }
519     } # end of the if local
520     # asynchronously search the authority server
521     elsif ($server && $server =~/authorityserver/) { # this is the local authority server
522         my @inner_sup_results_array;
523         for my $sup_record ( @{$results_hashref->{$server}->{"RECORDS"}} ) {
524             my $marc_record_object = MARC::Record->new_from_usmarc($sup_record);
525             my $title_field = $marc_record_object->field(100);
526              warn "Authority Found: ".$marc_record_object->as_formatted();
527             push @inner_sup_results_array, {
528                 'title' => $title_field->subfield('a'),
529                 'link' => "&amp;idx=an&amp;q=".$marc_record_object->field('001')->as_string(),
530             };
531         }
532         my $servername = $server;
533         push @sup_results_array, {  servername => $servername,
534                                     inner_sup_results_loop => \@inner_sup_results_array} if @inner_sup_results_array;
535     }
536     # FIXME: can add support for other targets as needed here
537     $template->param(           outer_sup_results_loop => \@sup_results_array);
538 } #/end of the for loop
539 #$template->param(FEDERATED_RESULTS => \@results_array);
540
541 $template->param(
542             #classlist => $classlist,
543             total => $total,
544             opacfacets => 1,
545             facets_loop => $facets,
546             scan => $scan,
547             search_error => $error,
548 );
549
550 if ($query_desc || $limit_desc) {
551     $template->param(searchdesc => 1);
552 }
553
554 # VI. BUILD THE TEMPLATE
555 # Build drop-down list for 'Add To:' menu...
556 my $session = get_session($cgi->cookie("CGISESSID"));
557 my @addpubshelves;
558 my $pubshelves = $session->param('pubshelves');
559 my $barshelves = $session->param('barshelves');
560 foreach my $shelf (@$pubshelves) {
561         next if ( ($shelf->{'owner'} != ($borrowernumber ? $borrowernumber : -1)) && ($shelf->{'category'} < 3) );
562         push (@addpubshelves, $shelf);
563 }
564
565 if (@addpubshelves) {
566         $template->param( addpubshelves     => scalar (@addpubshelves));
567         $template->param( addpubshelvesloop => \@addpubshelves);
568 }
569
570 if (defined $barshelves) {
571         $template->param( addbarshelves     => scalar (@$barshelves));
572         $template->param( addbarshelvesloop => $barshelves);
573 }
574
575 my $content_type = ($format eq 'rss' or $format eq 'atom') ? $format : 'html';
576
577 # If GoogleIndicTransliteration system preference is On Set paramter to load Google's javascript in OPAC search screens 
578 if (C4::Context->preference('GoogleIndicTransliteration')) {
579         $template->param('GoogleIndicTransliteration' => 1);
580 }
581
582 output_with_http_headers $cgi, $cookie, $template->output, $content_type;