Bug 10195: hide bib details page for OPAC-suppressed bibs
[koha.git] / opac / opac-detail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2010 BibLibre
5 # Copyright 2011 KohaAloha, NZ
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22
23 use strict;
24 use warnings;
25
26 use CGI;
27 use C4::Auth qw(:DEFAULT get_session);
28 use C4::Branch;
29 use C4::Koha;
30 use C4::Serials;    #uses getsubscriptionfrom biblionumber
31 use C4::Output;
32 use C4::Biblio;
33 use C4::Items;
34 use C4::Circulation;
35 use C4::Tags qw(get_tags);
36 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn);
37 use C4::External::Amazon;
38 use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes );
39 use C4::Review;
40 use C4::Ratings;
41 use C4::Members;
42 use C4::VirtualShelves;
43 use C4::XSLT;
44 use C4::ShelfBrowser;
45 use C4::Reserves;
46 use C4::Charset;
47 use MARC::Record;
48 use MARC::Field;
49 use List::MoreUtils qw/any none/;
50 use C4::Images;
51 use Koha::DateUtils;
52 use C4::HTML5Media;
53 use C4::CourseReserves qw(GetItemCourseReservesInfo);
54
55 BEGIN {
56         if (C4::Context->preference('BakerTaylorEnabled')) {
57                 require C4::External::BakerTaylor;
58                 import C4::External::BakerTaylor qw(&image_url &link_url);
59         }
60 }
61
62 my $query = new CGI;
63 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
64     {
65         template_name   => "opac-detail.tmpl",
66         query           => $query,
67         type            => "opac",
68         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
69         flagsrequired   => { borrow => 1 },
70     }
71 );
72
73 my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0;
74 $biblionumber = int($biblionumber);
75
76 my @all_items = GetItemsInfo($biblionumber);
77 my @hiddenitems;
78 if (scalar @all_items >= 1) {
79     push @hiddenitems, GetHiddenItemnumbers(@all_items);
80
81     if (scalar @hiddenitems == scalar @all_items ) {
82         print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
83         exit;
84     }
85 }
86
87 my $record       = GetMarcBiblio($biblionumber);
88 if ( ! $record ) {
89     print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
90     exit;
91 }
92
93 # redirect if opacsuppression is enabled and biblio is suppressed
94 if (C4::Context->preference('OpacSuppression')) {
95     my $opacsuppressionfield = '942';
96     my $opacsuppressionfieldvalue = $record->field($opacsuppressionfield);
97     # redirect to opac-blocked info page or 404?
98     my $opacsuppressionredirect;
99     if ( C4::Context->preference("OpacSuppressionRedirect") ) {
100         $opacsuppressionredirect = "/cgi-bin/koha/opac-blocked.pl";
101     }
102     else {
103         $opacsuppressionredirect = "/cgi-bin/koha/errors/404.pl";
104     }
105     if ( $opacsuppressionfieldvalue->subfield("n") == 1) {
106         # if OPAC suppression by IP address
107         if (C4::Context->preference('OpacSuppressionByIPRange')) {
108             my $IPAddress = $ENV{'REMOTE_ADDR'};
109             my $IPRange = C4::Context->preference('OpacSuppressionByIPRange');
110             if ($IPAddress !~ /^$IPRange/)  {
111                 print $query->redirect($opacsuppressionredirect);
112                 exit;
113             }
114          }
115         else {
116             print $query->redirect($opacsuppressionredirect);
117             exit;
118         }
119     }
120 }
121
122 $template->param( biblionumber => $biblionumber );
123
124 # get biblionumbers stored in the cart
125 my @cart_list;
126
127 if($query->cookie("bib_list")){
128     my $cart_list = $query->cookie("bib_list");
129     @cart_list = split(/\//, $cart_list);
130     if ( grep {$_ eq $biblionumber} @cart_list) {
131         $template->param( incart => 1 );
132     }
133 }
134
135
136 SetUTF8Flag($record);
137 my $marcflavour      = C4::Context->preference("marcflavour");
138 my $ean = GetNormalizedEAN( $record, $marcflavour );
139
140 # XSLT processing of some stuff
141 if (C4::Context->preference("OPACXSLTDetailsDisplay") ) {
142     $template->param( 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "OPACXSLTDetailsDisplay" ) );
143 }
144
145 my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
146 $template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
147
148 # We look for the busc param to build the simple paging from the search
149 if ($OpacBrowseResults) {
150 my $session = get_session($query->cookie("CGISESSID"));
151 my %paging = (previous => {}, next => {});
152 if ($session->param('busc')) {
153     use C4::Search;
154
155     # Rebuild the string to store on session
156     sub rebuildBuscParam
157     {
158         my $arrParamsBusc = shift;
159
160         my $pasarParams = '';
161         my $j = 0;
162         for (keys %$arrParamsBusc) {
163             if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
164                 if (defined($arrParamsBusc->{$_})) {
165                     $pasarParams .= '&' if ($j);
166                     $pasarParams .= $_ . '=' . $arrParamsBusc->{$_};
167                     $j++;
168                 }
169             } else {
170                 for my $value (@{$arrParamsBusc->{$_}}) {
171                     $pasarParams .= '&' if ($j);
172                     $pasarParams .= $_ . '=' . $value;
173                     $j++;
174                 }
175             }
176         }
177         return $pasarParams;
178     }#rebuildBuscParam
179
180     # Search given the current values from the busc param
181     sub searchAgain
182     {
183         my ($arrParamsBusc, $offset, $results_per_page) = @_;
184
185         my $expanded_facet = $arrParamsBusc->{'expand'};
186         my $branches = GetBranches();
187         my $itemtypes = GetItemTypes;
188         my @servers;
189         @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
190         @servers = ("biblioserver") unless (@servers);
191
192         my ($default_sort_by, @sort_by);
193         $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
194         @sort_by = @{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
195         $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
196         my ($error, $results_hashref, $facets);
197         eval {
198             ($error, $results_hashref, $facets) = getRecords($arrParamsBusc->{'query'},$arrParamsBusc->{'simple_query'},\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$itemtypes,$arrParamsBusc->{'query_type'},$arrParamsBusc->{'scan'});
199         };
200         my $hits;
201         my @newresults;
202         for (my $i=0;$i<@servers;$i++) {
203             my $server = $servers[$i];
204             $hits = $results_hashref->{$server}->{"hits"};
205             @newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
206         }
207         return \@newresults;
208     }#searchAgain
209
210     # Build the current list of biblionumbers in this search
211     sub buildListBiblios
212     {
213         my ($newresultsRef, $results_per_page) = @_;
214
215         my $listBiblios = '';
216         my $j = 0;
217         foreach (@$newresultsRef) {
218             my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
219             $listBiblios .= $bibnum . ',';
220             $j++;
221             last if ($j == $results_per_page);
222         }
223         chop $listBiblios if ($listBiblios =~ /,$/);
224         return $listBiblios;
225     }#buildListBiblios
226
227     my $busc = $session->param("busc");
228     my @arrBusc = split(/\&(?:amp;)?/, $busc);
229     my ($key, $value);
230     my %arrParamsBusc = ();
231     for (@arrBusc) {
232         ($key, $value) = split(/=/, $_, 2);
233         if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
234             $arrParamsBusc{$key} = $value;
235         } else {
236             unless (exists($arrParamsBusc{$key})) {
237                 $arrParamsBusc{$key} = [];
238             }
239             push @{$arrParamsBusc{$key}}, $value;
240         }
241     }
242     my $searchAgain = 0;
243     my $count = C4::Context->preference('OPACnumSearchResults') || 20;
244     my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count;
245     $arrParamsBusc{'count'} = $results_per_page;
246     my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0;
247     # The value OPACnumSearchResults has changed and the search has to be rebuild
248     if ($count != $results_per_page) {
249         if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
250             my $indexBiblio = 0;
251             my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
252             for (@arrBibliosAux) {
253                 last if ($_ == $biblionumber);
254                 $indexBiblio++;
255             }
256             $indexBiblio += $offset;
257             $offset = int($indexBiblio / $count) * $count;
258             $arrParamsBusc{'offset'} = $offset;
259         }
260         $arrParamsBusc{'count'} = $count;
261         $results_per_page = $count;
262         my $newresultsRef = searchAgain(\%arrParamsBusc, $offset, $results_per_page);
263         $arrParamsBusc{'listBiblios'} = buildListBiblios($newresultsRef, $results_per_page);
264         delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
265         delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
266         delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
267         delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
268         my $newbusc = rebuildBuscParam(\%arrParamsBusc);
269         $session->param("busc" => $newbusc);
270         @arrBusc = split(/\&(?:amp;)?/, $newbusc);
271     } else {
272         my $modifyListBiblios = 0;
273         # We come from a previous click
274         if (exists($arrParamsBusc{'previous'})) {
275             $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
276             delete $arrParamsBusc{'previous'};
277         } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
278             $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
279             delete $arrParamsBusc{'next'};
280         }
281         if ($modifyListBiblios) {
282             if (exists($arrParamsBusc{'newlistBiblios'})) {
283                 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
284                 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
285                 my @arrAux = split(',', $listBibliosAux);
286                 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
287                 if ($modifyListBiblios == 1) {
288                     $arrParamsBusc{'next'} = $arrAux[0];
289                     $paging{'next'}->{biblionumber} = $arrAux[0];
290                 }else {
291                     $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
292                     $paging{'previous'}->{biblionumber} = $arrAux[$#arrAux];
293                 }
294             } else {
295                 delete $arrParamsBusc{'listBiblios'};
296             }
297             my $offsetAux = $arrParamsBusc{'offset'};
298             $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
299             $arrParamsBusc{'offsetSearch'} = $offsetAux;
300             $offset = $arrParamsBusc{'offset'};
301             my $newbusc = rebuildBuscParam(\%arrParamsBusc);
302             $session->param("busc" => $newbusc);
303             @arrBusc = split(/\&(?:amp;)?/, $newbusc);
304         }
305     }
306     my $buscParam = '';
307     my $j = 0;
308     # Rebuild the query for the button "back to results"
309     for (@arrBusc) {
310         unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
311             $buscParam .= '&amp;' unless ($j == 0);
312             $buscParam .= $_;
313             $j++;
314         }
315     }
316     $template->param('busc' => $buscParam);
317     my $offsetSearch;
318     my @arrBiblios;
319     # We are inside the list of biblios and we don't have to search
320     if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
321         @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
322         if (@arrBiblios) {
323             # We are at the first item of the list
324             if ($arrBiblios[0] == $biblionumber) {
325                 if (@arrBiblios > 1) {
326                     for (my $j = 1; $j < @arrBiblios; $j++) {
327                         next unless ($arrBiblios[$j]);
328                         $paging{'next'}->{biblionumber} = $arrBiblios[$j];
329                         last;
330                     }
331                 }
332                 # search again if we are not at the first searching list
333                 if ($offset && !$arrParamsBusc{'previous'}) {
334                     $searchAgain = 1;
335                     $offsetSearch = $offset - $results_per_page;
336                 }
337             # we are at the last item of the list
338             } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
339                 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
340                     next unless ($arrBiblios[$j]);
341                     $paging{'previous'}->{biblionumber} = $arrBiblios[$j];
342                     last;
343                 }
344                 if (!$offset) {
345                     # search again if we are at the first list and there is more results
346                     $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
347                 } else {
348                     # search again if we aren't at the first list and there is more results
349                     $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
350                 }
351                 $offsetSearch = $offset + $results_per_page if ($searchAgain);
352             } else {
353                 for (my $j = 1; $j < $#arrBiblios; $j++) {
354                     if ($arrBiblios[$j] == $biblionumber) {
355                         for (my $z = $j - 1; $z >= 0; $z--) {
356                             next unless ($arrBiblios[$z]);
357                             $paging{'previous'}->{biblionumber} = $arrBiblios[$z];
358                             last;
359                         }
360                         for (my $z = $j + 1; $z < @arrBiblios; $z++) {
361                             next unless ($arrBiblios[$z]);
362                             $paging{'next'}->{biblionumber} = $arrBiblios[$z];
363                             last;
364                         }
365                         last;
366                     }
367                 }
368             }
369         }
370         $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
371     }
372     if ($searchAgain) {
373         my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page);
374         my @newresults = @$newresultsRef;
375         # build the new listBiblios
376         my $listBiblios = buildListBiblios(\@newresults, $results_per_page);
377         unless (exists($arrParamsBusc{'listBiblios'})) {
378             $arrParamsBusc{'listBiblios'} = $listBiblios;
379             @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
380         } else {
381             $arrParamsBusc{'newlistBiblios'} = $listBiblios;
382         }
383         # From the new list we build again the next and previous result
384         if (@arrBiblios) {
385             if ($arrBiblios[0] == $biblionumber) {
386                 for (my $j = $#newresults; $j >= 0; $j--) {
387                     next unless ($newresults[$j]);
388                     $paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber};
389                     $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber};
390                     $arrParamsBusc{'offsetSearch'} = $offsetSearch;
391                    last;
392                 }
393             } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
394                 for (my $j = 0; $j < @newresults; $j++) {
395                     next unless ($newresults[$j]);
396                     $paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber};
397                     $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber};
398                     $arrParamsBusc{'offsetSearch'} = $offsetSearch;
399                     last;
400                 }
401             }
402         }
403         # build new busc param
404         my $newbusc = rebuildBuscParam(\%arrParamsBusc);
405         $session->param("busc" => $newbusc);
406     }
407     my ($numberBiblioPaging, $dataBiblioPaging);
408     # Previous biblio
409     $numberBiblioPaging = $paging{'previous'}->{biblionumber};
410     if ($numberBiblioPaging) {
411         $template->param( 'previousBiblionumber' => $numberBiblioPaging );
412         $dataBiblioPaging = GetBiblioData($numberBiblioPaging);
413         $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
414     }
415     # Next biblio
416     $numberBiblioPaging = $paging{'next'}->{biblionumber};
417     if ($numberBiblioPaging) {
418         $template->param( 'nextBiblionumber' => $numberBiblioPaging );
419         $dataBiblioPaging = GetBiblioData($numberBiblioPaging);
420         $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
421     }
422     # Partial list of biblio results
423     my @listResults;
424     for (my $j = 0; $j < @arrBiblios; $j++) {
425         next unless ($arrBiblios[$j]);
426         $dataBiblioPaging = GetBiblioData($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber);
427         push @listResults, {index => $j + 1 + $offset, biblionumber => $arrBiblios[$j], title => ($arrBiblios[$j] == $biblionumber)?'':$dataBiblioPaging->{title}, author => ($arrBiblios[$j] != $biblionumber && $dataBiblioPaging->{author})?$dataBiblioPaging->{author}:'', url => ($arrBiblios[$j] == $biblionumber)?'':'opac-detail.pl?biblionumber=' . $arrBiblios[$j]};
428     }
429     $template->param('listResults' => \@listResults) if (@listResults);
430     $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
431 }
432 }
433
434
435
436 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
437 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
438
439
440
441 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
442 $template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") );
443
444 # adding items linked via host biblios
445
446 my $analyticfield = '773';
447 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
448     $analyticfield = '773';
449 } elsif ($marcflavour eq 'UNIMARC') {
450     $analyticfield = '461';
451 }
452 foreach my $hostfield ( $record->field($analyticfield)) {
453     my $hostbiblionumber = $hostfield->subfield("0");
454     my $linkeditemnumber = $hostfield->subfield("9");
455     my @hostitemInfos = GetItemsInfo($hostbiblionumber);
456     foreach my $hostitemInfo (@hostitemInfos){
457         if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
458             push(@all_items, $hostitemInfo);
459         }
460     }
461 }
462
463 my @items;
464
465 # Are there items to hide?
466 my $hideitems;
467 $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0;
468
469 # Hide items
470 if ($hideitems) {
471     for my $itm (@all_items) {
472         if  ( C4::Context->preference('hidelostitems') ) {
473             push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
474         } else {
475             push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
476     }
477 }
478 } else {
479     # Or not
480     @items = @all_items;
481 }
482
483 my $branches = GetBranches();
484 my $branch = '';
485 if (C4::Context->userenv){
486     $branch = C4::Context->userenv->{branch};
487 }
488 if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) {
489     if (
490         ( ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
491         ||
492         C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
493     ) {
494         my $branchname;
495         if ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
496             $branchname = $branches->{$branch}->{'branchname'};
497         }
498         elsif (  C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
499             $branchname = $branches->{ $ENV{'BRANCHCODE'} }->{'branchname'};
500         }
501
502         my @our_items;
503         my @other_items;
504
505         foreach my $item ( @items ) {
506            if ( $item->{'branchname'} eq $branchname ) {
507                $item->{'this_branch'} = 1;
508                push( @our_items, $item );
509            } else {
510                push( @other_items, $item );
511            }
512         }
513
514         @items = ( @our_items, @other_items );
515     }
516 }
517
518 my $dat = &GetBiblioData($biblionumber);
519
520 my $itemtypes = GetItemTypes();
521 # imageurl:
522 my $itemtype = $dat->{'itemtype'};
523 if ( $itemtype ) {
524     $dat->{'imageurl'}    = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
525     $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
526 }
527 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
528 my $collections =  GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac');
529 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$dat->{'frameworkcode'}, 'opac');
530
531 #coping with subscriptions
532 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
533 my @subscriptions       = GetSubscriptions($dat->{'title'}, $dat->{'issn'}, $ean, $biblionumber );
534
535 my @subs;
536 $dat->{'serial'}=1 if $subscriptionsnumber;
537 foreach my $subscription (@subscriptions) {
538     my $serials_to_display;
539     my %cell;
540     $cell{subscriptionid}    = $subscription->{subscriptionid};
541     $cell{subscriptionnotes} = $subscription->{notes};
542     $cell{missinglist}       = $subscription->{missinglist};
543     $cell{opacnote}          = $subscription->{opacnote};
544     $cell{histstartdate}     = $subscription->{histstartdate};
545     $cell{histenddate}       = $subscription->{histenddate};
546     $cell{branchcode}        = $subscription->{branchcode};
547     $cell{branchname}        = GetBranchName($subscription->{branchcode});
548     $cell{hasalert}          = $subscription->{hasalert};
549     $cell{callnumber}        = $subscription->{callnumber};
550     $cell{closed}            = $subscription->{closed};
551     #get the three latest serials.
552     $serials_to_display = $subscription->{opacdisplaycount};
553     $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
554         $cell{opacdisplaycount} = $serials_to_display;
555     $cell{latestserials} =
556       GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
557     push @subs, \%cell;
558 }
559
560 $dat->{'count'} = scalar(@items);
561
562
563 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) );
564
565 my (%item_reserves, %priority);
566 my ($show_holds_count, $show_priority);
567 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
568     m/holds/o and $show_holds_count = 1;
569     m/priority/ and $show_priority = 1;
570 }
571 my $has_hold;
572 if ( $show_holds_count || $show_priority) {
573     my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
574     $template->param( holds_count  => scalar( @$reserves ) ) if $show_holds_count;
575     foreach (@$reserves) {
576         $item_reserves{ $_->{itemnumber} }++ if $_->{itemnumber};
577         if ($show_priority && $_->{borrowernumber} == $borrowernumber) {
578             $has_hold = 1;
579             $_->{itemnumber}
580                 ? ($priority{ $_->{itemnumber} } = $_->{priority})
581                 : ($template->param( priority => $_->{priority} ));
582         }
583     }
584 }
585 $template->param( show_priority => $has_hold ) ;
586
587 my $norequests = 1;
588 my %itemfields;
589 my (@itemloop, @otheritemloop);
590 my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
591 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
592     $template->param(SeparateHoldings => 1);
593 }
594 my $separatebranch = C4::Context->preference('OpacSeparateHoldingsBranch');
595 my $viewallitems = $query->param('viewallitems');
596 my $max_items_to_display = C4::Context->preference('OpacMaxItemsToDisplay') // 50;
597 if ( not $viewallitems and @items > $max_items_to_display ) {
598     $template->param(
599         too_many_items => 1,
600         items_count => scalar( @items ),
601     );
602 } else {
603   for my $itm (@items) {
604     $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
605     $itm->{priority} = $priority{ $itm->{itemnumber} };
606     $norequests = 0
607        if ( (not $itm->{'withdrawn'} )
608          && (not $itm->{'itemlost'} )
609          && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
610                  && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
611          && ($itm->{'itemnumber'} ) );
612
613     # get collection code description, too
614     my $ccode = $itm->{'ccode'};
615     $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} );
616     my $copynumber = $itm->{'copynumber'};
617     $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
618     if ( defined $itm->{'location'} ) {
619         $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
620     }
621     if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
622         $itm->{'imageurl'}    = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
623         $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{'description'};
624     }
625     foreach (qw(ccode enumchron copynumber itemnotes uri)) {
626         $itemfields{$_} = 1 if ($itm->{$_});
627     }
628
629      # walk through the item-level authorised values and populate some images
630      my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
631      # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
632
633      if ( $itm->{'itemlost'} ) {
634          my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
635          $itm->{'lostimageurl'}   = $lostimageinfo->{ 'imageurl' };
636          $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
637      }
638      my $reserve_status = C4::Reserves::GetReserveStatus($itm->{itemnumber});
639       if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
640       if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
641     
642      my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
643      if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
644         $itm->{transfertwhen} = $transfertwhen;
645         $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
646         $itm->{transfertto}   = $branches->{$transfertto}{branchname};
647      }
648     my $itembranch = $itm->{$separatebranch};
649     if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
650         if ($itembranch and $itembranch eq $currentbranch) {
651             push @itemloop, $itm;
652         } else {
653             push @otheritemloop, $itm;
654         }
655     } else {
656         push @itemloop, $itm;
657     }
658   }
659 }
660
661 # Display only one tab if one items list is empty
662 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
663     $template->param(SeparateHoldings => 0);
664     if (scalar(@itemloop) == 0) {
665         @itemloop = @otheritemloop;
666     }
667 }
668
669 ## get notes and subjects from MARC record
670 my $dbh              = C4::Context->dbh;
671 my $marcnotesarray   = GetMarcNotes   ($record,$marcflavour);
672 my $marcisbnsarray   = GetMarcISBN    ($record,$marcflavour);
673 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
674 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
675 my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
676 my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
677 my $marchostsarray  = GetMarcHosts($record,$marcflavour);
678 my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
679
680     $template->param(
681                      MARCNOTES               => $marcnotesarray,
682                      MARCSUBJCTS             => $marcsubjctsarray,
683                      MARCAUTHORS             => $marcauthorsarray,
684                      MARCSERIES              => $marcseriesarray,
685                      MARCURLS                => $marcurlsarray,
686                      MARCISBNS               => $marcisbnsarray,
687                      MARCHOSTS               => $marchostsarray,
688                      norequests              => $norequests,
689                      RequestOnOpac           => C4::Context->preference("RequestOnOpac"),
690                      itemdata_ccode          => $itemfields{ccode},
691                      itemdata_enumchron      => $itemfields{enumchron},
692                      itemdata_uri            => $itemfields{uri},
693                      itemdata_copynumber     => $itemfields{copynumber},
694                      itemdata_itemnotes          => $itemfields{itemnotes},
695                      authorised_value_images => $biblio_authorised_value_images,
696                      subtitle                => $subtitle,
697                      OpacStarRatings         => C4::Context->preference("OpacStarRatings"),
698     );
699
700 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
701     my $fieldspec = C4::Context->preference("AlternateHoldingsField");
702     my $subfields = substr $fieldspec, 3;
703     my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
704     my @alternateholdingsinfo = ();
705     my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
706
707     for my $field (@holdingsfields) {
708         my %holding = ( holding => '' );
709         my $havesubfield = 0;
710         for my $subfield ($field->subfields()) {
711             if ((index $subfields, $$subfield[0]) >= 0) {
712                 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
713                 $holding{'holding'} .= $$subfield[1];
714                 $havesubfield++;
715             }
716         }
717         if ($havesubfield) {
718             push(@alternateholdingsinfo, \%holding);
719         }
720     }
721
722     $template->param(
723         ALTERNATEHOLDINGS   => \@alternateholdingsinfo,
724         );
725 }
726
727 foreach ( keys %{$dat} ) {
728     $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
729 }
730
731 # some useful variables for enhanced content;
732 # in each case, we're grabbing the first value we find in
733 # the record and normalizing it
734 my $upc = GetNormalizedUPC($record,$marcflavour);
735 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
736 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
737 my $content_identifier_exists;
738 if ( $isbn or $ean or $oclc or $upc ) {
739     $content_identifier_exists = 1;
740 }
741 $template->param(
742         normalized_upc => $upc,
743         normalized_ean => $ean,
744         normalized_oclc => $oclc,
745         normalized_isbn => $isbn,
746         content_identifier_exists =>  $content_identifier_exists,
747 );
748
749 # COinS format FIXME: for books Only
750 $template->param(
751     ocoins => GetCOinSBiblio($record),
752 );
753
754 my $libravatar_enabled = 0;
755 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto')) {
756     eval {
757         require Libravatar::URL;
758         Libravatar::URL->import();
759     };
760     if (!$@ ) {
761         $libravatar_enabled = 1;
762     }
763 }
764
765 my $reviews = getreviews( $biblionumber, 1 );
766 my $loggedincommenter;
767
768
769
770
771 foreach ( @$reviews ) {
772     my $borrowerData   = GetMember('borrowernumber' => $_->{borrowernumber});
773     # setting some borrower info into this hash
774     $_->{title}     = $borrowerData->{'title'};
775     $_->{surname}   = $borrowerData->{'surname'};
776     $_->{firstname} = $borrowerData->{'firstname'};
777     if ($libravatar_enabled and $borrowerData->{'email'}) {
778         $_->{avatarurl} = libravatar_url(email => $borrowerData->{'email'}, https => $ENV{HTTPS});
779     }
780     $_->{userid}    = $borrowerData->{'userid'};
781     $_->{cardnumber}    = $borrowerData->{'cardnumber'};
782
783     if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
784                 $_->{your_comment} = 1;
785                 $loggedincommenter = 1;
786         }
787 }
788
789
790 if(C4::Context->preference("ISBD")) {
791         $template->param(ISBD => 1);
792 }
793
794 $template->param(
795     itemloop            => \@itemloop,
796     otheritemloop       => \@otheritemloop,
797     subscriptionsnumber => $subscriptionsnumber,
798     biblionumber        => $biblionumber,
799     subscriptions       => \@subs,
800     subscriptionsnumber => $subscriptionsnumber,
801     reviews             => $reviews,
802     loggedincommenter   => $loggedincommenter
803 );
804
805 # Lists
806
807 if (C4::Context->preference("virtualshelves") ) {
808    $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
809 }
810
811
812 # XISBN Stuff
813 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
814     eval {
815         $template->param(
816             XISBNS => get_xisbns($isbn)
817         );
818     };
819     if ($@) { warn "XISBN Failed $@"; }
820 }
821
822 # Serial Collection
823 my @sc_fields = $record->field(955);
824 my @lc_fields = $marcflavour eq 'UNIMARC'
825     ? $record->field(930)
826     : $record->field(852);
827 my @serialcollections = ();
828
829 foreach my $sc_field (@sc_fields) {
830     my %row_data;
831
832     $row_data{text}    = $sc_field->subfield('r');
833     $row_data{branch}  = $sc_field->subfield('9');
834     foreach my $lc_field (@lc_fields) {
835         $row_data{itemcallnumber} = $marcflavour eq 'UNIMARC'
836             ? $lc_field->subfield('a') # 930$a
837             : $lc_field->subfield('h') # 852$h
838             if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
839     }
840
841     if ($row_data{text} && $row_data{branch}) { 
842         push (@serialcollections, \%row_data);
843     }
844 }
845
846 if (scalar(@serialcollections) > 0) {
847     $template->param(
848         serialcollection  => 1,
849         serialcollections => \@serialcollections);
850 }
851
852 # Local cover Images stuff
853 if (C4::Context->preference("OPACLocalCoverImages")){
854                 $template->param(OPACLocalCoverImages => 1);
855 }
856
857 # HTML5 Media
858 if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'opac') ) {
859     $template->param( C4::HTML5Media->gethtml5media($record));
860 }
861
862 my $syndetics_elements;
863
864 if ( C4::Context->preference("SyndeticsEnabled") ) {
865     $template->param("SyndeticsEnabled" => 1);
866     $template->param("SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode"));
867         eval {
868             $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
869             for my $element (values %$syndetics_elements) {
870                 $template->param("Syndetics$element"."Exists" => 1 );
871                 #warn "Exists: "."Syndetics$element"."Exists";
872         }
873     };
874     warn $@ if $@;
875 }
876
877 if ( C4::Context->preference("SyndeticsEnabled")
878         && C4::Context->preference("SyndeticsSummary")
879         && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
880         eval {
881             my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements);
882             $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
883         };
884         warn $@ if $@;
885
886 }
887
888 if ( C4::Context->preference("SyndeticsEnabled")
889         && C4::Context->preference("SyndeticsTOC")
890         && exists($syndetics_elements->{'TOC'}) ) {
891         eval {
892     my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
893     $template->param( SYNDETICS_TOC => $syndetics_toc );
894         };
895         warn $@ if $@;
896 }
897
898 if ( C4::Context->preference("SyndeticsEnabled")
899     && C4::Context->preference("SyndeticsExcerpt")
900     && exists($syndetics_elements->{'DBCHAPTER'}) ) {
901     eval {
902     my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
903     $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
904     };
905         warn $@ if $@;
906 }
907
908 if ( C4::Context->preference("SyndeticsEnabled")
909     && C4::Context->preference("SyndeticsReviews")) {
910     eval {
911     my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
912     $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
913     };
914         warn $@ if $@;
915 }
916
917 if ( C4::Context->preference("SyndeticsEnabled")
918     && C4::Context->preference("SyndeticsAuthorNotes")
919         && exists($syndetics_elements->{'ANOTES'}) ) {
920     eval {
921     my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
922     $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
923     };
924     warn $@ if $@;
925 }
926
927 # LibraryThingForLibraries ID Code and Tabbed View Option
928 if( C4::Context->preference('LibraryThingForLibrariesEnabled') ) 
929
930 $template->param(LibraryThingForLibrariesID =>
931 C4::Context->preference('LibraryThingForLibrariesID') ); 
932 $template->param(LibraryThingForLibrariesTabbedView =>
933 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
934
935
936 # Novelist Select
937 if( C4::Context->preference('NovelistSelectEnabled') ) 
938
939 $template->param(NovelistSelectProfile => C4::Context->preference('NovelistSelectProfile') ); 
940 $template->param(NovelistSelectPassword => C4::Context->preference('NovelistSelectPassword') ); 
941 $template->param(NovelistSelectView => C4::Context->preference('NovelistSelectView') ); 
942
943
944
945 # Babelthèque
946 if ( C4::Context->preference("Babeltheque") ) {
947     $template->param( 
948         Babeltheque => 1,
949         Babeltheque_url_js => C4::Context->preference("Babeltheque_url_js"),
950     );
951 }
952
953 # Social Networks
954 if ( C4::Context->preference( "SocialNetworks" ) ) {
955     $template->param( current_url => C4::Context->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
956     $template->param( SocialNetworks => 1 );
957 }
958
959 # Shelf Browser Stuff
960 if (C4::Context->preference("OPACShelfBrowser")) {
961     my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
962     if (defined($starting_itemnumber)) {
963         $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
964         my $nearby = GetNearbyItems($starting_itemnumber);
965
966         $template->param(
967             starting_itemnumber => $starting_itemnumber,
968             starting_homebranch => $nearby->{starting_homebranch}->{description},
969             starting_location => $nearby->{starting_location}->{description},
970             starting_ccode => $nearby->{starting_ccode}->{description},
971             shelfbrowser_prev_item => $nearby->{prev_item},
972             shelfbrowser_next_item => $nearby->{next_item},
973             shelfbrowser_items => $nearby->{items},
974         );
975
976         # in which tab shelf browser should open ?
977         if (grep { $starting_itemnumber == $_->{itemnumber} } @itemloop) {
978             $template->param(shelfbrowser_tab => 'holdings');
979         } else {
980             $template->param(shelfbrowser_tab => 'otherholdings');
981         }
982     }
983 }
984
985 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("OPACAmazonCoverImages"));
986
987 if (C4::Context->preference("BakerTaylorEnabled")) {
988         $template->param(
989                 BakerTaylorEnabled  => 1,
990                 BakerTaylorImageURL => &image_url(),
991                 BakerTaylorLinkURL  => &link_url(),
992                 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
993         );
994         my ($bt_user, $bt_pass);
995         if ($isbn and
996                 $bt_user = C4::Context->preference('BakerTaylorUsername') and
997                 $bt_pass = C4::Context->preference('BakerTaylorPassword')    )
998         {
999                 $template->param(
1000                 BakerTaylorContentURL   =>
1001                 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
1002                                 $bt_user,$bt_pass,$isbn)
1003                 );
1004         }
1005 }
1006
1007 my $tag_quantity;
1008 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
1009         $template->param(
1010                 TagsEnabled => 1,
1011                 TagsShowOnDetail => $tag_quantity,
1012                 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
1013         );
1014         $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
1015                                                                 'sort'=>'-weight', limit=>$tag_quantity}));
1016 }
1017
1018 if (C4::Context->preference("OPACURLOpenInNewWindow")) {
1019     # These values are going to be read by Javascript, at least in the case
1020     # of the google covers
1021     $template->param(covernewwindow => 'true');
1022 } else {
1023     $template->param(covernewwindow => 'false');
1024 }
1025
1026 #Export options
1027 my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
1028 my @export_options = split(/\|/,$OpacExportOptions);
1029 $template->{VARS}->{'export_options'} = \@export_options;
1030
1031 if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
1032     my $rating = GetRating( $biblionumber, $borrowernumber );
1033     $template->param(
1034         rating_value   => $rating->{'rating_value'},
1035         rating_total   => $rating->{'rating_total'},
1036         rating_avg     => $rating->{'rating_avg'},
1037         rating_avg_int => $rating->{'rating_avg_int'},
1038         borrowernumber => $borrowernumber
1039     );
1040 }
1041
1042 #Search for title in links
1043 my $marccontrolnumber   = GetMarcControlnumber ($record, $marcflavour);
1044 my $marcissns = GetMarcISSN ( $record, $marcflavour );
1045 my $issn = $marcissns->[0] || '';
1046
1047 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
1048     $dat->{title} =~ s/\/+$//; # remove trailing slash
1049     $dat->{title} =~ s/\s+$//; # remove trailing space
1050     $search_for_title = parametrized_url(
1051         $search_for_title,
1052         {
1053             TITLE         => $dat->{title},
1054             AUTHOR        => $dat->{author},
1055             ISBN          => $isbn,
1056             ISSN          => $issn,
1057             CONTROLNUMBER => $marccontrolnumber,
1058             BIBLIONUMBER  => $biblionumber,
1059         }
1060     );
1061     $template->param('OPACSearchForTitleIn' => $search_for_title);
1062 }
1063
1064 # We try to select the best default tab to show, according to what
1065 # the user wants, and what's available for display
1066 my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab');
1067 my $defaulttab = 
1068     $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1069         ? 'subscriptions' :
1070     $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1071         ? 'serialcollection' :
1072     $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1073         ? 'holdings' :
1074     $subscriptionsnumber
1075         ? 'subscriptions' :
1076     @serialcollections > 0 
1077         ? 'serialcollection' : 'subscriptions';
1078 $template->param('defaulttab' => $defaulttab);
1079
1080 if (C4::Context->preference('OPACLocalCoverImages') == 1) {
1081     my @images = ListImagesForBiblio($biblionumber);
1082     $template->{VARS}->{localimages} = \@images;
1083 }
1084
1085 $template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksReviews');
1086 $template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
1087 $template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
1088 $template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopupAuthorsSearch');
1089
1090 if (C4::Context->preference('OpacHighlightedWords')) {
1091     $template->{VARS}->{query_desc} = $query->param('query_desc');
1092 }
1093 $template->{VARS}->{'trackclicks'} = C4::Context->preference('TrackClicks');
1094
1095 if ( C4::Context->preference('UseCourseReserves') ) {
1096     foreach my $i ( @items ) {
1097         $i->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $i->{'itemnumber'} );
1098     }
1099 }
1100
1101 output_html_with_http_headers $query, $cookie, $template->output;