Bug 11337: Remove the C4::Serials::GetSubscriptions routine
[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 qw ( -utf8 );
27 use C4::Acquisition qw( SearchOrders );
28 use C4::Auth qw(:DEFAULT get_session);
29 use C4::Branch;
30 use C4::Koha;
31 use C4::Serials;    #uses getsubscriptionfrom biblionumber
32 use C4::Output;
33 use C4::Biblio;
34 use C4::Items;
35 use C4::Circulation;
36 use C4::Tags qw(get_tags);
37 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn);
38 use C4::External::Amazon;
39 use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes );
40 use C4::Review;
41 use C4::Ratings;
42 use C4::Members;
43 use C4::VirtualShelves;
44 use C4::XSLT;
45 use C4::ShelfBrowser;
46 use C4::Reserves;
47 use C4::Charset;
48 use MARC::Record;
49 use MARC::Field;
50 use List::MoreUtils qw/any none/;
51 use C4::Images;
52 use Koha::DateUtils;
53 use C4::HTML5Media;
54 use C4::CourseReserves qw(GetItemCourseReservesInfo);
55
56 BEGIN {
57         if (C4::Context->preference('BakerTaylorEnabled')) {
58                 require C4::External::BakerTaylor;
59                 import C4::External::BakerTaylor qw(&image_url &link_url);
60         }
61 }
62
63 my $query = new CGI;
64 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
65     {
66         template_name   => "opac-detail.tt",
67         query           => $query,
68         type            => "opac",
69         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
70         flagsrequired   => { borrow => 1 },
71     }
72 );
73
74 my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0;
75 $biblionumber = int($biblionumber);
76
77 my @all_items = GetItemsInfo($biblionumber);
78 my @hiddenitems;
79 if (scalar @all_items >= 1) {
80     push @hiddenitems, GetHiddenItemnumbers(@all_items);
81
82     if (scalar @hiddenitems == scalar @all_items ) {
83         print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
84         exit;
85     }
86 }
87
88 my $record       = GetMarcBiblio($biblionumber);
89 if ( ! $record ) {
90     print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
91     exit;
92 }
93
94 # redirect if opacsuppression is enabled and biblio is suppressed
95 if (C4::Context->preference('OpacSuppression')) {
96     # FIXME hardcoded; the suppression flag ought to be materialized
97     # as a column on biblio or the like
98     my $opacsuppressionfield = '942';
99     my $opacsuppressionfieldvalue = $record->field($opacsuppressionfield);
100     # redirect to opac-blocked info page or 404?
101     my $opacsuppressionredirect;
102     if ( C4::Context->preference("OpacSuppressionRedirect") ) {
103         $opacsuppressionredirect = "/cgi-bin/koha/opac-blocked.pl";
104     } else {
105         $opacsuppressionredirect = "/cgi-bin/koha/errors/404.pl";
106     }
107     if ( $opacsuppressionfieldvalue &&
108          $opacsuppressionfieldvalue->subfield("n") &&
109          $opacsuppressionfieldvalue->subfield("n") == 1) {
110         # if OPAC suppression by IP address
111         if (C4::Context->preference('OpacSuppressionByIPRange')) {
112             my $IPAddress = $ENV{'REMOTE_ADDR'};
113             my $IPRange = C4::Context->preference('OpacSuppressionByIPRange');
114             if ($IPAddress !~ /^$IPRange/)  {
115                 print $query->redirect($opacsuppressionredirect);
116                 exit;
117             }
118         } else {
119             print $query->redirect($opacsuppressionredirect);
120             exit;
121         }
122     }
123 }
124
125 $template->param( biblionumber => $biblionumber );
126
127 # get biblionumbers stored in the cart
128 my @cart_list;
129
130 if($query->cookie("bib_list")){
131     my $cart_list = $query->cookie("bib_list");
132     @cart_list = split(/\//, $cart_list);
133     if ( grep {$_ eq $biblionumber} @cart_list) {
134         $template->param( incart => 1 );
135     }
136 }
137
138
139 SetUTF8Flag($record);
140 my $marcflavour      = C4::Context->preference("marcflavour");
141 my $ean = GetNormalizedEAN( $record, $marcflavour );
142
143 # XSLT processing of some stuff
144 if (C4::Context->preference("OPACXSLTDetailsDisplay") ) {
145     $template->param( 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "OPACXSLTDetailsDisplay" ) );
146 }
147
148 my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
149 $template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
150
151 # We look for the busc param to build the simple paging from the search
152 if ($OpacBrowseResults) {
153 my $session = get_session($query->cookie("CGISESSID"));
154 my %paging = (previous => {}, next => {});
155 if ($session->param('busc')) {
156     use C4::Search;
157     use URI::Escape;
158
159     # Rebuild the string to store on session
160     # param value is URI encoded and params separator is HTML encode (&)
161     sub rebuildBuscParam
162     {
163         my $arrParamsBusc = shift;
164
165         my $pasarParams = '';
166         my $j = 0;
167         for (keys %$arrParamsBusc) {
168             if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
169                 if (defined($arrParamsBusc->{$_})) {
170                     $pasarParams .= '&' if ($j);
171                     $pasarParams .= $_ . '=' . Encode::decode('UTF-8', uri_escape_utf8( $arrParamsBusc->{$_} ));
172                     $j++;
173                 }
174             } else {
175                 for my $value (@{$arrParamsBusc->{$_}}) {
176                     $pasarParams .= '&' if ($j);
177                     $pasarParams .= $_ . '=' . Encode::decode('UTF-8', uri_escape_utf8($value));
178                     $j++;
179                 }
180             }
181         }
182         return $pasarParams;
183     }#rebuildBuscParam
184
185     # Search given the current values from the busc param
186     sub searchAgain
187     {
188         my ($arrParamsBusc, $offset, $results_per_page) = @_;
189
190         my $expanded_facet = $arrParamsBusc->{'expand'};
191         my $branches = GetBranches();
192         my $itemtypes = GetItemTypes;
193         my @servers;
194         @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
195         @servers = ("biblioserver") unless (@servers);
196
197         my ($default_sort_by, @sort_by);
198         $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
199         @sort_by = @{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
200         $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
201         my ($error, $results_hashref, $facets);
202         eval {
203             ($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'});
204         };
205         my $hits;
206         my @newresults;
207         for (my $i=0;$i<@servers;$i++) {
208             my $server = $servers[$i];
209             $hits = $results_hashref->{$server}->{"hits"};
210             @newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
211         }
212         return \@newresults;
213     }#searchAgain
214
215     # Build the current list of biblionumbers in this search
216     sub buildListBiblios
217     {
218         my ($newresultsRef, $results_per_page) = @_;
219
220         my $listBiblios = '';
221         my $j = 0;
222         foreach (@$newresultsRef) {
223             my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
224             $listBiblios .= $bibnum . ',';
225             $j++;
226             last if ($j == $results_per_page);
227         }
228         chop $listBiblios if ($listBiblios =~ /,$/);
229         return $listBiblios;
230     }#buildListBiblios
231
232     my $busc = $session->param("busc");
233     my @arrBusc = split(/\&(?:amp;)?/, $busc);
234     my ($key, $value);
235     my %arrParamsBusc = ();
236     for (@arrBusc) {
237         ($key, $value) = split(/=/, $_, 2);
238         if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
239             $arrParamsBusc{$key} = uri_unescape($value);
240         } else {
241             unless (exists($arrParamsBusc{$key})) {
242                 $arrParamsBusc{$key} = [];
243             }
244             push @{$arrParamsBusc{$key}}, uri_unescape($value);
245         }
246     }
247     my $searchAgain = 0;
248     my $count = C4::Context->preference('OPACnumSearchResults') || 20;
249     my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count;
250     $arrParamsBusc{'count'} = $results_per_page;
251     my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0;
252     # The value OPACnumSearchResults has changed and the search has to be rebuild
253     if ($count != $results_per_page) {
254         if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
255             my $indexBiblio = 0;
256             my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
257             for (@arrBibliosAux) {
258                 last if ($_ == $biblionumber);
259                 $indexBiblio++;
260             }
261             $indexBiblio += $offset;
262             $offset = int($indexBiblio / $count) * $count;
263             $arrParamsBusc{'offset'} = $offset;
264         }
265         $arrParamsBusc{'count'} = $count;
266         $results_per_page = $count;
267         my $newresultsRef = searchAgain(\%arrParamsBusc, $offset, $results_per_page);
268         $arrParamsBusc{'listBiblios'} = buildListBiblios($newresultsRef, $results_per_page);
269         delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
270         delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
271         delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
272         delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
273         my $newbusc = rebuildBuscParam(\%arrParamsBusc);
274         $session->param("busc" => $newbusc);
275         @arrBusc = split(/\&(?:amp;)?/, $newbusc);
276     } else {
277         my $modifyListBiblios = 0;
278         # We come from a previous click
279         if (exists($arrParamsBusc{'previous'})) {
280             $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
281             delete $arrParamsBusc{'previous'};
282         } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
283             $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
284             delete $arrParamsBusc{'next'};
285         }
286         if ($modifyListBiblios) {
287             if (exists($arrParamsBusc{'newlistBiblios'})) {
288                 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
289                 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
290                 my @arrAux = split(',', $listBibliosAux);
291                 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
292                 if ($modifyListBiblios == 1) {
293                     $arrParamsBusc{'next'} = $arrAux[0];
294                     $paging{'next'}->{biblionumber} = $arrAux[0];
295                 }else {
296                     $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
297                     $paging{'previous'}->{biblionumber} = $arrAux[$#arrAux];
298                 }
299             } else {
300                 delete $arrParamsBusc{'listBiblios'};
301             }
302             my $offsetAux = $arrParamsBusc{'offset'};
303             $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
304             $arrParamsBusc{'offsetSearch'} = $offsetAux;
305             $offset = $arrParamsBusc{'offset'};
306             my $newbusc = rebuildBuscParam(\%arrParamsBusc);
307             $session->param("busc" => $newbusc);
308             @arrBusc = split(/\&(?:amp;)?/, $newbusc);
309         }
310     }
311     my $buscParam = '';
312     my $j = 0;
313     # Rebuild the query for the button "back to results"
314     for (@arrBusc) {
315         unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
316             $buscParam .= '&amp;' unless ($j == 0);
317             $buscParam .= $_; # string already URI encoded
318             $j++;
319         }
320     }
321     $template->param('busc' => $buscParam);
322     my $offsetSearch;
323     my @arrBiblios;
324     # We are inside the list of biblios and we don't have to search
325     if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
326         @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
327         if (@arrBiblios) {
328             # We are at the first item of the list
329             if ($arrBiblios[0] == $biblionumber) {
330                 if (@arrBiblios > 1) {
331                     for (my $j = 1; $j < @arrBiblios; $j++) {
332                         next unless ($arrBiblios[$j]);
333                         $paging{'next'}->{biblionumber} = $arrBiblios[$j];
334                         last;
335                     }
336                 }
337                 # search again if we are not at the first searching list
338                 if ($offset && !$arrParamsBusc{'previous'}) {
339                     $searchAgain = 1;
340                     $offsetSearch = $offset - $results_per_page;
341                 }
342             # we are at the last item of the list
343             } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
344                 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
345                     next unless ($arrBiblios[$j]);
346                     $paging{'previous'}->{biblionumber} = $arrBiblios[$j];
347                     last;
348                 }
349                 if (!$offset) {
350                     # search again if we are at the first list and there is more results
351                     $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
352                 } else {
353                     # search again if we aren't at the first list and there is more results
354                     $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
355                 }
356                 $offsetSearch = $offset + $results_per_page if ($searchAgain);
357             } else {
358                 for (my $j = 1; $j < $#arrBiblios; $j++) {
359                     if ($arrBiblios[$j] == $biblionumber) {
360                         for (my $z = $j - 1; $z >= 0; $z--) {
361                             next unless ($arrBiblios[$z]);
362                             $paging{'previous'}->{biblionumber} = $arrBiblios[$z];
363                             last;
364                         }
365                         for (my $z = $j + 1; $z < @arrBiblios; $z++) {
366                             next unless ($arrBiblios[$z]);
367                             $paging{'next'}->{biblionumber} = $arrBiblios[$z];
368                             last;
369                         }
370                         last;
371                     }
372                 }
373             }
374         }
375         $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
376     }
377     if ($searchAgain) {
378         my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page);
379         my @newresults = @$newresultsRef;
380         # build the new listBiblios
381         my $listBiblios = buildListBiblios(\@newresults, $results_per_page);
382         unless (exists($arrParamsBusc{'listBiblios'})) {
383             $arrParamsBusc{'listBiblios'} = $listBiblios;
384             @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
385         } else {
386             $arrParamsBusc{'newlistBiblios'} = $listBiblios;
387         }
388         # From the new list we build again the next and previous result
389         if (@arrBiblios) {
390             if ($arrBiblios[0] == $biblionumber) {
391                 for (my $j = $#newresults; $j >= 0; $j--) {
392                     next unless ($newresults[$j]);
393                     $paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber};
394                     $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber};
395                     $arrParamsBusc{'offsetSearch'} = $offsetSearch;
396                    last;
397                 }
398             } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
399                 for (my $j = 0; $j < @newresults; $j++) {
400                     next unless ($newresults[$j]);
401                     $paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber};
402                     $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber};
403                     $arrParamsBusc{'offsetSearch'} = $offsetSearch;
404                     last;
405                 }
406             }
407         }
408         # build new busc param
409         my $newbusc = rebuildBuscParam(\%arrParamsBusc);
410         $session->param("busc" => $newbusc);
411     }
412     my ($numberBiblioPaging, $dataBiblioPaging);
413     # Previous biblio
414     $numberBiblioPaging = $paging{'previous'}->{biblionumber};
415     if ($numberBiblioPaging) {
416         $template->param( 'previousBiblionumber' => $numberBiblioPaging );
417         $dataBiblioPaging = GetBiblioData($numberBiblioPaging);
418         $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
419     }
420     # Next biblio
421     $numberBiblioPaging = $paging{'next'}->{biblionumber};
422     if ($numberBiblioPaging) {
423         $template->param( 'nextBiblionumber' => $numberBiblioPaging );
424         $dataBiblioPaging = GetBiblioData($numberBiblioPaging);
425         $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
426     }
427     # Partial list of biblio results
428     my @listResults;
429     for (my $j = 0; $j < @arrBiblios; $j++) {
430         next unless ($arrBiblios[$j]);
431         $dataBiblioPaging = GetBiblioData($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber);
432         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]};
433     }
434     $template->param('listResults' => \@listResults) if (@listResults);
435     $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
436 }
437 }
438
439
440 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
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       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
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
598 # Get items on order
599 my ( @itemnumbers_on_order );
600 if ( C4::Context->preference('OPACAcquisitionDetails' ) ) {
601     my $orders = C4::Acquisition::SearchOrders({
602         biblionumber => $biblionumber,
603         ordered => 1,
604     });
605     my $total_quantity = 0;
606     for my $order ( @$orders ) {
607         if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) {
608             for my $itemnumber ( C4::Acquisition::GetItemnumbersFromOrder( $order->{ordernumber} ) ) {
609                 push @itemnumbers_on_order, $itemnumber;
610             }
611         }
612         $total_quantity += $order->{quantity};
613     }
614     $template->{VARS}->{acquisition_details} = {
615         total_quantity => $total_quantity,
616     };
617 }
618
619 if ( not $viewallitems and @items > $max_items_to_display ) {
620     $template->param(
621         too_many_items => 1,
622         items_count => scalar( @items ),
623     );
624 } else {
625   my $allow_onshelf_holds;
626   my $borrower = GetMember( 'borrowernumber' => $borrowernumber );
627   for my $itm (@items) {
628     $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
629     $itm->{priority} = $priority{ $itm->{itemnumber} };
630     $norequests = 0
631       if $norequests
632         && !$itm->{'withdrawn'}
633         && !$itm->{'itemlost'}
634         && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'})
635         && !$itemtypes->{$itm->{'itype'}}->{notforloan}
636         && $itm->{'itemnumber'};
637
638     $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed( $itm, $borrower )
639       unless $allow_onshelf_holds;
640
641     # get collection code description, too
642     my $ccode = $itm->{'ccode'};
643     $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} );
644     my $copynumber = $itm->{'copynumber'};
645     $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
646     if ( defined $itm->{'location'} ) {
647         $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
648     }
649     if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
650         $itm->{'imageurl'}    = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
651         $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{'description'};
652     }
653     foreach (qw(ccode enumchron copynumber itemnotes uri)) {
654         $itemfields{$_} = 1 if ($itm->{$_});
655     }
656
657      # walk through the item-level authorised values and populate some images
658      my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
659      # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
660
661      if ( $itm->{'itemlost'} ) {
662          my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
663          $itm->{'lostimageurl'}   = $lostimageinfo->{ 'imageurl' };
664          $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
665      }
666      my $reserve_status = C4::Reserves::GetReserveStatus($itm->{itemnumber});
667       if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
668       if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
669     
670      my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
671      if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
672         $itm->{transfertwhen} = $transfertwhen;
673         $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
674         $itm->{transfertto}   = $branches->{$transfertto}{branchname};
675      }
676     
677     if (    C4::Context->preference('OPACAcquisitionDetails')
678         and C4::Context->preference('AcqCreateItem') eq 'ordering' )
679     {
680         $itm->{on_order} = 1
681           if grep /^$itm->{itemnumber}$/, @itemnumbers_on_order;
682     }
683
684     my $itembranch = $itm->{$separatebranch};
685     if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
686         if ($itembranch and $itembranch eq $currentbranch) {
687             push @itemloop, $itm;
688         } else {
689             push @otheritemloop, $itm;
690         }
691     } else {
692         push @itemloop, $itm;
693     }
694   }
695   $template->param( 'AllowOnShelfHolds' => $allow_onshelf_holds );
696 }
697
698 # Display only one tab if one items list is empty
699 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
700     $template->param(SeparateHoldings => 0);
701     if (scalar(@itemloop) == 0) {
702         @itemloop = @otheritemloop;
703     }
704 }
705
706 ## get notes and subjects from MARC record
707 my $dbh              = C4::Context->dbh;
708 my $marcnotesarray   = GetMarcNotes   ($record,$marcflavour);
709 my $marcisbnsarray   = GetMarcISBN    ($record,$marcflavour);
710 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
711 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
712 my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
713 my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
714 my $marchostsarray  = GetMarcHosts($record,$marcflavour);
715 my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
716
717     $template->param(
718                      MARCNOTES               => $marcnotesarray,
719                      MARCSUBJCTS             => $marcsubjctsarray,
720                      MARCAUTHORS             => $marcauthorsarray,
721                      MARCSERIES              => $marcseriesarray,
722                      MARCURLS                => $marcurlsarray,
723                      MARCISBNS               => $marcisbnsarray,
724                      MARCHOSTS               => $marchostsarray,
725                      norequests              => $norequests,
726                      RequestOnOpac           => C4::Context->preference("RequestOnOpac"),
727                      itemdata_ccode          => $itemfields{ccode},
728                      itemdata_enumchron      => $itemfields{enumchron},
729                      itemdata_uri            => $itemfields{uri},
730                      itemdata_copynumber     => $itemfields{copynumber},
731                      itemdata_itemnotes          => $itemfields{itemnotes},
732                      authorised_value_images => $biblio_authorised_value_images,
733                      subtitle                => $subtitle,
734                      OpacStarRatings         => C4::Context->preference("OpacStarRatings"),
735     );
736
737 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
738     my $fieldspec = C4::Context->preference("AlternateHoldingsField");
739     my $subfields = substr $fieldspec, 3;
740     my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
741     my @alternateholdingsinfo = ();
742     my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
743
744     for my $field (@holdingsfields) {
745         my %holding = ( holding => '' );
746         my $havesubfield = 0;
747         for my $subfield ($field->subfields()) {
748             if ((index $subfields, $$subfield[0]) >= 0) {
749                 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
750                 $holding{'holding'} .= $$subfield[1];
751                 $havesubfield++;
752             }
753         }
754         if ($havesubfield) {
755             push(@alternateholdingsinfo, \%holding);
756         }
757     }
758
759     $template->param(
760         ALTERNATEHOLDINGS   => \@alternateholdingsinfo,
761         );
762 }
763
764 foreach ( keys %{$dat} ) {
765     $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
766 }
767
768 # some useful variables for enhanced content;
769 # in each case, we're grabbing the first value we find in
770 # the record and normalizing it
771 my $upc = GetNormalizedUPC($record,$marcflavour);
772 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
773 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
774 my $content_identifier_exists;
775 if ( $isbn or $ean or $oclc or $upc ) {
776     $content_identifier_exists = 1;
777 }
778 $template->param(
779         normalized_upc => $upc,
780         normalized_ean => $ean,
781         normalized_oclc => $oclc,
782         normalized_isbn => $isbn,
783         content_identifier_exists =>  $content_identifier_exists,
784 );
785
786 # COinS format FIXME: for books Only
787 $template->param(
788     ocoins => GetCOinSBiblio($record),
789 );
790
791 my $libravatar_enabled = 0;
792 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto')) {
793     eval {
794         require Libravatar::URL;
795         Libravatar::URL->import();
796     };
797     if (!$@ ) {
798         $libravatar_enabled = 1;
799     }
800 }
801
802 my $reviews = getreviews( $biblionumber, 1 );
803 my $loggedincommenter;
804
805
806
807
808 foreach ( @$reviews ) {
809     my $borrowerData   = GetMember('borrowernumber' => $_->{borrowernumber});
810     # setting some borrower info into this hash
811     $_->{title}     = $borrowerData->{'title'};
812     $_->{surname}   = $borrowerData->{'surname'};
813     $_->{firstname} = $borrowerData->{'firstname'};
814     if ($libravatar_enabled and $borrowerData->{'email'}) {
815         $_->{avatarurl} = libravatar_url(email => $borrowerData->{'email'}, https => $ENV{HTTPS});
816     }
817     $_->{userid}    = $borrowerData->{'userid'};
818     $_->{cardnumber}    = $borrowerData->{'cardnumber'};
819
820     if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
821                 $_->{your_comment} = 1;
822                 $loggedincommenter = 1;
823         }
824 }
825
826
827 if(C4::Context->preference("ISBD")) {
828         $template->param(ISBD => 1);
829 }
830
831 $template->param(
832     itemloop            => \@itemloop,
833     otheritemloop       => \@otheritemloop,
834     subscriptionsnumber => $subscriptionsnumber,
835     biblionumber        => $biblionumber,
836     subscriptions       => \@subs,
837     subscriptionsnumber => $subscriptionsnumber,
838     reviews             => $reviews,
839     loggedincommenter   => $loggedincommenter
840 );
841
842 # Lists
843
844 if (C4::Context->preference("virtualshelves") ) {
845    $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
846 }
847
848
849 # XISBN Stuff
850 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
851     eval {
852         $template->param(
853             XISBNS => get_xisbns($isbn)
854         );
855     };
856     if ($@) { warn "XISBN Failed $@"; }
857 }
858
859 # Serial Collection
860 my @sc_fields = $record->field(955);
861 my @lc_fields = $marcflavour eq 'UNIMARC'
862     ? $record->field(930)
863     : $record->field(852);
864 my @serialcollections = ();
865
866 foreach my $sc_field (@sc_fields) {
867     my %row_data;
868
869     $row_data{text}    = $sc_field->subfield('r');
870     $row_data{branch}  = $sc_field->subfield('9');
871     foreach my $lc_field (@lc_fields) {
872         $row_data{itemcallnumber} = $marcflavour eq 'UNIMARC'
873             ? $lc_field->subfield('a') # 930$a
874             : $lc_field->subfield('h') # 852$h
875             if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
876     }
877
878     if ($row_data{text} && $row_data{branch}) { 
879         push (@serialcollections, \%row_data);
880     }
881 }
882
883 if (scalar(@serialcollections) > 0) {
884     $template->param(
885         serialcollection  => 1,
886         serialcollections => \@serialcollections);
887 }
888
889 # Local cover Images stuff
890 if (C4::Context->preference("OPACLocalCoverImages")){
891                 $template->param(OPACLocalCoverImages => 1);
892 }
893
894 # HTML5 Media
895 if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'opac') ) {
896     $template->param( C4::HTML5Media->gethtml5media($record));
897 }
898
899 my $syndetics_elements;
900
901 if ( C4::Context->preference("SyndeticsEnabled") ) {
902     $template->param("SyndeticsEnabled" => 1);
903     $template->param("SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode"));
904         eval {
905             $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
906             for my $element (values %$syndetics_elements) {
907                 $template->param("Syndetics$element"."Exists" => 1 );
908                 #warn "Exists: "."Syndetics$element"."Exists";
909         }
910     };
911     warn $@ if $@;
912 }
913
914 if ( C4::Context->preference("SyndeticsEnabled")
915         && C4::Context->preference("SyndeticsSummary")
916         && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
917         eval {
918             my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements);
919             $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
920         };
921         warn $@ if $@;
922
923 }
924
925 if ( C4::Context->preference("SyndeticsEnabled")
926         && C4::Context->preference("SyndeticsTOC")
927         && exists($syndetics_elements->{'TOC'}) ) {
928         eval {
929     my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
930     $template->param( SYNDETICS_TOC => $syndetics_toc );
931         };
932         warn $@ if $@;
933 }
934
935 if ( C4::Context->preference("SyndeticsEnabled")
936     && C4::Context->preference("SyndeticsExcerpt")
937     && exists($syndetics_elements->{'DBCHAPTER'}) ) {
938     eval {
939     my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
940     $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
941     };
942         warn $@ if $@;
943 }
944
945 if ( C4::Context->preference("SyndeticsEnabled")
946     && C4::Context->preference("SyndeticsReviews")) {
947     eval {
948     my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
949     $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
950     };
951         warn $@ if $@;
952 }
953
954 if ( C4::Context->preference("SyndeticsEnabled")
955     && C4::Context->preference("SyndeticsAuthorNotes")
956         && exists($syndetics_elements->{'ANOTES'}) ) {
957     eval {
958     my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
959     $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
960     };
961     warn $@ if $@;
962 }
963
964 # LibraryThingForLibraries ID Code and Tabbed View Option
965 if( C4::Context->preference('LibraryThingForLibrariesEnabled') ) 
966
967 $template->param(LibraryThingForLibrariesID =>
968 C4::Context->preference('LibraryThingForLibrariesID') ); 
969 $template->param(LibraryThingForLibrariesTabbedView =>
970 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
971
972
973 # Novelist Select
974 if( C4::Context->preference('NovelistSelectEnabled') ) 
975
976 $template->param(NovelistSelectProfile => C4::Context->preference('NovelistSelectProfile') ); 
977 $template->param(NovelistSelectPassword => C4::Context->preference('NovelistSelectPassword') ); 
978 $template->param(NovelistSelectView => C4::Context->preference('NovelistSelectView') ); 
979
980
981
982 # Babelthèque
983 if ( C4::Context->preference("Babeltheque") ) {
984     $template->param( 
985         Babeltheque => 1,
986         Babeltheque_url_js => C4::Context->preference("Babeltheque_url_js"),
987     );
988 }
989
990 # Social Networks
991 if ( C4::Context->preference( "SocialNetworks" ) ) {
992     $template->param( current_url => C4::Context->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
993     $template->param( SocialNetworks => 1 );
994 }
995
996 # Shelf Browser Stuff
997 if (C4::Context->preference("OPACShelfBrowser")) {
998     my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
999     if (defined($starting_itemnumber)) {
1000         $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
1001         my $nearby = GetNearbyItems($starting_itemnumber);
1002
1003         $template->param(
1004             starting_itemnumber => $starting_itemnumber,
1005             starting_homebranch => $nearby->{starting_homebranch}->{description},
1006             starting_location => $nearby->{starting_location}->{description},
1007             starting_ccode => $nearby->{starting_ccode}->{description},
1008             shelfbrowser_prev_item => $nearby->{prev_item},
1009             shelfbrowser_next_item => $nearby->{next_item},
1010             shelfbrowser_items => $nearby->{items},
1011         );
1012
1013         # in which tab shelf browser should open ?
1014         if (grep { $starting_itemnumber == $_->{itemnumber} } @itemloop) {
1015             $template->param(shelfbrowser_tab => 'holdings');
1016         } else {
1017             $template->param(shelfbrowser_tab => 'otherholdings');
1018         }
1019     }
1020 }
1021
1022 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("OPACAmazonCoverImages"));
1023
1024 if (C4::Context->preference("BakerTaylorEnabled")) {
1025         $template->param(
1026                 BakerTaylorEnabled  => 1,
1027                 BakerTaylorImageURL => &image_url(),
1028                 BakerTaylorLinkURL  => &link_url(),
1029                 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
1030         );
1031         my ($bt_user, $bt_pass);
1032         if ($isbn and
1033                 $bt_user = C4::Context->preference('BakerTaylorUsername') and
1034                 $bt_pass = C4::Context->preference('BakerTaylorPassword')    )
1035         {
1036                 $template->param(
1037                 BakerTaylorContentURL   =>
1038                 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
1039                                 $bt_user,$bt_pass,$isbn)
1040                 );
1041         }
1042 }
1043
1044 my $tag_quantity;
1045 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
1046         $template->param(
1047                 TagsEnabled => 1,
1048                 TagsShowOnDetail => $tag_quantity,
1049                 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
1050         );
1051         $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
1052                                                                 'sort'=>'-weight', limit=>$tag_quantity}));
1053 }
1054
1055 if (C4::Context->preference("OPACURLOpenInNewWindow")) {
1056     # These values are going to be read by Javascript, at least in the case
1057     # of the google covers
1058     $template->param(covernewwindow => 'true');
1059 } else {
1060     $template->param(covernewwindow => 'false');
1061 }
1062
1063 if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
1064     my $rating = GetRating( $biblionumber, $borrowernumber );
1065     $template->param(
1066         rating_value   => $rating->{'rating_value'},
1067         rating_total   => $rating->{'rating_total'},
1068         rating_avg     => $rating->{'rating_avg'},
1069         rating_avg_int => $rating->{'rating_avg_int'},
1070         borrowernumber => $borrowernumber
1071     );
1072 }
1073
1074 #Search for title in links
1075 my $marccontrolnumber   = GetMarcControlnumber ($record, $marcflavour);
1076 my $marcissns = GetMarcISSN ( $record, $marcflavour );
1077 my $issn = $marcissns->[0] || '';
1078
1079 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
1080     $dat->{title} =~ s/\/+$//; # remove trailing slash
1081     $dat->{title} =~ s/\s+$//; # remove trailing space
1082     $search_for_title = parametrized_url(
1083         $search_for_title,
1084         {
1085             TITLE         => $dat->{title},
1086             AUTHOR        => $dat->{author},
1087             ISBN          => $isbn,
1088             ISSN          => $issn,
1089             CONTROLNUMBER => $marccontrolnumber,
1090             BIBLIONUMBER  => $biblionumber,
1091         }
1092     );
1093     $template->param('OPACSearchForTitleIn' => $search_for_title);
1094 }
1095
1096 # We try to select the best default tab to show, according to what
1097 # the user wants, and what's available for display
1098 my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab');
1099 my $defaulttab = 
1100     $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1101         ? 'subscriptions' :
1102     $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1103         ? 'serialcollection' :
1104     $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1105         ? 'holdings' :
1106     $subscriptionsnumber
1107         ? 'subscriptions' :
1108     @serialcollections > 0 
1109         ? 'serialcollection' : 'subscriptions';
1110 $template->param('defaulttab' => $defaulttab);
1111
1112 if (C4::Context->preference('OPACLocalCoverImages') == 1) {
1113     my @images = ListImagesForBiblio($biblionumber);
1114     $template->{VARS}->{localimages} = \@images;
1115 }
1116
1117 $template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksReviews');
1118 $template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
1119 $template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
1120 $template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopupAuthorsSearch');
1121
1122 if (C4::Context->preference('OpacHighlightedWords')) {
1123     $template->{VARS}->{query_desc} = $query->param('query_desc');
1124 }
1125 $template->{VARS}->{'trackclicks'} = C4::Context->preference('TrackClicks');
1126
1127 if ( C4::Context->preference('UseCourseReserves') ) {
1128     foreach my $i ( @items ) {
1129         $i->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $i->{'itemnumber'} );
1130     }
1131 }
1132
1133 $template->param(
1134     'OpacLocationBranchToDisplay'         => C4::Context->preference('OpacLocationBranchToDisplay') ,
1135     'OpacLocationBranchToDisplayShelving' => C4::Context->preference('OpacLocationBranchToDisplayShelving'),
1136 );
1137
1138 output_html_with_http_headers $query, $cookie, $template->output;