Merge remote-tracking branch 'kc/new/bug_6351' into kcmaster
[koha.git] / opac / opac-detail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2010 BibLibre
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21
22 use strict;
23 use warnings;
24
25 use CGI;
26 use C4::Auth;
27 use C4::Branch;
28 use C4::Koha;
29 use C4::Serials;    #uses getsubscriptionfrom biblionumber
30 use C4::Output;
31 use C4::Biblio;
32 use C4::Items;
33 use C4::Circulation;
34 use C4::Tags qw(get_tags);
35 use C4::Dates qw/format_date/;
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::Members;
41 use C4::VirtualShelves;
42 use C4::XSLT;
43 use C4::ShelfBrowser;
44 use C4::Charset;
45 use MARC::Record;
46 use MARC::Field;
47 use List::MoreUtils qw/any none/;
48
49 BEGIN {
50         if (C4::Context->preference('BakerTaylorEnabled')) {
51                 require C4::External::BakerTaylor;
52                 import C4::External::BakerTaylor qw(&image_url &link_url);
53         }
54 }
55
56 my $query = new CGI;
57 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
58     {
59         template_name   => "opac-detail.tmpl",
60         query           => $query,
61         type            => "opac",
62         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
63         flagsrequired   => { borrow => 1 },
64     }
65 );
66
67 my $biblionumber = $query->param('biblionumber') || $query->param('bib');
68
69 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
70 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
71
72 my $record       = GetMarcBiblio($biblionumber);
73 if ( ! $record ) {
74     print $query->redirect("/cgi-bin/koha/errors/404.pl");
75     exit;
76 }
77 $template->param( biblionumber => $biblionumber );
78
79 SetUTF8Flag($record);
80
81 # XSLT processing of some stuff
82 if (C4::Context->preference("OPACXSLTDetailsDisplay") ) {
83     $template->param( 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, 'Detail', 'opac') );
84 }
85
86 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") ); 
87 # change back when ive fixed request.pl
88 my @all_items = GetItemsInfo( $biblionumber );
89 my @items;
90
91 # Getting items to be hidden
92 my @hiddenitems = GetHiddenItemnumbers(@all_items);
93
94 # Are there items to hide?
95 my $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0;
96
97 # Hide items
98 if ($hideitems) {
99     for my $itm (@all_items) {
100         if  ( C4::Context->preference('hidelostitems') ) {
101             push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
102         } else {
103             push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
104     }
105 }
106 } else {
107     # Or not
108     @items = @all_items;
109 }
110
111 my $dat = &GetBiblioData($biblionumber);
112
113 my $itemtypes = GetItemTypes();
114 # imageurl:
115 my $itemtype = $dat->{'itemtype'};
116 if ( $itemtype ) {
117     $dat->{'imageurl'}    = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
118     $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
119 }
120 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
121 my $collections =  GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac');
122
123 #coping with subscriptions
124 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
125 my @subscriptions       = GetSubscriptions( undef, undef, $biblionumber );
126
127 my @subs;
128 $dat->{'serial'}=1 if $subscriptionsnumber;
129 foreach my $subscription (@subscriptions) {
130     my $serials_to_display;
131     my %cell;
132     $cell{subscriptionid}    = $subscription->{subscriptionid};
133     $cell{subscriptionnotes} = $subscription->{notes};
134     $cell{missinglist}       = $subscription->{missinglist};
135     $cell{opacnote}          = $subscription->{opacnote};
136     $cell{histstartdate}     = format_date($subscription->{histstartdate});
137     $cell{histenddate}       = format_date($subscription->{histenddate});
138     $cell{branchcode}        = $subscription->{branchcode};
139     $cell{branchname}        = GetBranchName($subscription->{branchcode});
140     $cell{hasalert}          = $subscription->{hasalert};
141     #get the three latest serials.
142     $serials_to_display = $subscription->{opacdisplaycount};
143     $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
144         $cell{opacdisplaycount} = $serials_to_display;
145     $cell{latestserials} =
146       GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
147     push @subs, \%cell;
148 }
149
150 $dat->{'count'} = scalar(@items);
151
152 # If there is a lot of items, and the user has not decided
153 # to view them all yet, we first warn him
154 # TODO: The limit of 50 could be a syspref
155 my $viewallitems = $query->param('viewallitems');
156 if ($dat->{'count'} >= 50 && !$viewallitems) {
157     $template->param('lotsofitems' => 1);
158 }
159
160 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) );
161
162 my $norequests = 1;
163 my $branches = GetBranches();
164 my %itemfields;
165 for my $itm (@items) {
166     $norequests = 0
167        if ( (not $itm->{'wthdrawn'} )
168          && (not $itm->{'itemlost'} )
169          && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
170                  && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
171          && ($itm->{'itemnumber'} ) );
172
173     if ( defined $itm->{'publictype'} ) {
174         # I can't actually find any case in which this is defined. --amoore 2008-12-09
175         $itm->{ $itm->{'publictype'} } = 1;
176     }
177     $itm->{datedue}      = format_date($itm->{datedue});
178     $itm->{datelastseen} = format_date($itm->{datelastseen});
179
180     # get collection code description, too
181     if ( my $ccode = $itm->{'ccode'} ) {
182         $itm->{'ccode'} = $collections->{$ccode} if ( defined($collections) && exists( $collections->{$ccode} ) );
183     }
184     if ( defined $itm->{'location'} ) {
185         $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
186     }
187     if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
188         $itm->{'imageurl'}    = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
189         $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{'description'};
190     }
191     foreach (qw(ccode enumchron copynumber itemnotes uri)) {
192         $itemfields{$_} = 1 if ($itm->{$_});
193     }
194
195      # walk through the item-level authorised values and populate some images
196      my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
197      # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
198
199      if ( $itm->{'itemlost'} ) {
200          my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
201          $itm->{'lostimageurl'}   = $lostimageinfo->{ 'imageurl' };
202          $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
203      }
204
205      if( $itm->{'count_reserves'}){
206           if( $itm->{'count_reserves'} eq "Waiting"){ $itm->{'waiting'} = 1; }
207           if( $itm->{'count_reserves'} eq "Reserved"){ $itm->{'onhold'} = 1; }
208      }
209     
210      my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
211      if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
212         $itm->{transfertwhen} = format_date($transfertwhen);
213         $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
214         $itm->{transfertto}   = $branches->{$transfertto}{branchname};
215      }
216 }
217
218 ## get notes and subjects from MARC record
219 my $dbh              = C4::Context->dbh;
220 my $marcflavour      = C4::Context->preference("marcflavour");
221 my $marcnotesarray   = GetMarcNotes   ($record,$marcflavour);
222 my $marcisbnsarray   = GetMarcISBN    ($record,$marcflavour);
223 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
224 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
225 my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
226 my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
227 my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
228
229     $template->param(
230                      MARCNOTES               => $marcnotesarray,
231                      MARCSUBJCTS             => $marcsubjctsarray,
232                      MARCAUTHORS             => $marcauthorsarray,
233                      MARCSERIES              => $marcseriesarray,
234                      MARCURLS                => $marcurlsarray,
235                      norequests              => $norequests,
236                      RequestOnOpac           => C4::Context->preference("RequestOnOpac"),
237                      itemdata_ccode          => $itemfields{ccode},
238                      itemdata_enumchron      => $itemfields{enumchron},
239                      itemdata_uri            => $itemfields{uri},
240                      itemdata_copynumber     => $itemfields{copynumber},
241                      itemdata_itemnotes          => $itemfields{itemnotes},
242                      authorised_value_images => $biblio_authorised_value_images,
243                      subtitle                => $subtitle,
244     );
245
246 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
247     my $fieldspec = C4::Context->preference("AlternateHoldingsField");
248     my $subfields = substr $fieldspec, 3;
249     my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
250     my @alternateholdingsinfo = ();
251     my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
252
253     for my $field (@holdingsfields) {
254         my %holding = ( holding => '' );
255         my $havesubfield = 0;
256         for my $subfield ($field->subfields()) {
257             if ((index $subfields, $$subfield[0]) >= 0) {
258                 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
259                 $holding{'holding'} .= $$subfield[1];
260                 $havesubfield++;
261             }
262         }
263         if ($havesubfield) {
264             push(@alternateholdingsinfo, \%holding);
265         }
266     }
267
268     $template->param(
269         ALTERNATEHOLDINGS   => \@alternateholdingsinfo,
270         );
271 }
272
273 foreach ( keys %{$dat} ) {
274     $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
275 }
276
277 # some useful variables for enhanced content;
278 # in each case, we're grabbing the first value we find in
279 # the record and normalizing it
280 my $upc = GetNormalizedUPC($record,$marcflavour);
281 my $ean = GetNormalizedEAN($record,$marcflavour);
282 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
283 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
284 my $content_identifier_exists;
285 if ( $isbn or $ean or $oclc or $upc ) {
286     $content_identifier_exists = 1;
287 }
288 $template->param(
289         normalized_upc => $upc,
290         normalized_ean => $ean,
291         normalized_oclc => $oclc,
292         normalized_isbn => $isbn,
293         content_identifier_exists =>  $content_identifier_exists,
294 );
295
296 # COinS format FIXME: for books Only
297 $template->param(
298     ocoins => GetCOinSBiblio($biblionumber),
299 );
300
301 my $libravatar_enabled = 0;
302 eval 'use Libravatar::URL';
303 if (!$@ and C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto')) {
304     $libravatar_enabled = 1;
305 }
306
307 my $reviews = getreviews( $biblionumber, 1 );
308 my $loggedincommenter;
309 foreach ( @$reviews ) {
310     my $borrowerData   = GetMember('borrowernumber' => $_->{borrowernumber});
311     # setting some borrower info into this hash
312     $_->{title}     = $borrowerData->{'title'};
313     $_->{surname}   = $borrowerData->{'surname'};
314     $_->{firstname} = $borrowerData->{'firstname'};
315     if ($libravatar_enabled and $borrowerData->{'email'}) {
316         $_->{avatarurl} = libravatar_url(email => $borrowerData->{'email'}, https => $ENV{HTTPS});
317     }
318     $_->{userid}    = $borrowerData->{'userid'};
319     $_->{cardnumber}    = $borrowerData->{'cardnumber'};
320     $_->{datereviewed} = format_date($_->{datereviewed});
321     if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
322                 $_->{your_comment} = 1;
323                 $loggedincommenter = 1;
324         }
325 }
326
327
328 if(C4::Context->preference("ISBD")) {
329         $template->param(ISBD => 1);
330 }
331
332 $template->param(
333     ITEM_RESULTS        => \@items,
334     subscriptionsnumber => $subscriptionsnumber,
335     biblionumber        => $biblionumber,
336     subscriptions       => \@subs,
337     subscriptionsnumber => $subscriptionsnumber,
338     reviews             => $reviews,
339     loggedincommenter   => $loggedincommenter
340 );
341
342 # Lists
343
344 if (C4::Context->preference("virtualshelves") ) {
345    $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
346 }
347
348
349 # XISBN Stuff
350 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
351     eval {
352         $template->param(
353             XISBNS => get_xisbns($isbn)
354         );
355     };
356     if ($@) { warn "XISBN Failed $@"; }
357 }
358
359 # Serial Collection
360 my @sc_fields = $record->field(955);
361 my @serialcollections = ();
362
363 foreach my $sc_field (@sc_fields) {
364     my %row_data;
365
366     $row_data{text}    = $sc_field->subfield('r');
367     $row_data{branch}  = $sc_field->subfield('9');
368
369     if ($row_data{text} && $row_data{branch}) { 
370         push (@serialcollections, \%row_data);
371     }
372 }
373
374 if (scalar(@serialcollections) > 0) {
375     $template->param(
376         serialcollection  => 1,
377         serialcollections => \@serialcollections);
378 }
379
380 # Amazon.com Stuff
381 if ( C4::Context->preference("OPACAmazonEnabled") ) {
382     $template->param( AmazonTld => get_amazon_tld() );
383     my $amazon_reviews  = C4::Context->preference("OPACAmazonReviews");
384     my $amazon_similars = C4::Context->preference("OPACAmazonSimilarItems");
385     my @services;
386     if ( $amazon_reviews ) {
387         push( @services, 'EditorialReview', 'Reviews' );
388     }
389     if ( $amazon_similars ) {
390         push( @services, 'Similarities' );
391     }
392     my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour, \@services );
393     my $similar_products_exist;
394     if ( $amazon_reviews ) {
395         my $item = $amazon_details->{Items}->{Item}->[0];
396         my $customer_reviews = \@{ $item->{CustomerReviews}->{Review} };
397         for my $one_review ( @$customer_reviews ) {
398             $one_review->{Date} = format_date($one_review->{Date});
399         }
400         my $editorial_reviews = \@{ $item->{EditorialReviews}->{EditorialReview} };
401         my $average_rating = $item->{CustomerReviews}->{AverageRating} || 0;
402         $template->param( amazon_average_rating    => $average_rating * 20);
403         $template->param( AMAZON_CUSTOMER_REVIEWS  => $customer_reviews );
404         $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
405     }
406     if ( $amazon_similars ) {
407         my $item = $amazon_details->{Items}->{Item}->[0];
408         my @similar_products;
409         for my $similar_product (@{ $item->{SimilarProducts}->{SimilarProduct} }) {
410             # do we have any of these isbns in our collection?
411             my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
412             # verify that there is at least one similar item
413             if (scalar(@$similar_biblionumbers)){
414                 $similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
415                 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN}  };
416             }
417         }
418         $template->param( OPACAmazonSimilarItems => $similar_products_exist );
419         $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
420     }
421 }
422
423 my $syndetics_elements;
424
425 if ( C4::Context->preference("SyndeticsEnabled") ) {
426     $template->param("SyndeticsEnabled" => 1);
427     $template->param("SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode"));
428         eval {
429             $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
430             for my $element (values %$syndetics_elements) {
431                 $template->param("Syndetics$element"."Exists" => 1 );
432                 #warn "Exists: "."Syndetics$element"."Exists";
433         }
434     };
435     warn $@ if $@;
436 }
437
438 if ( C4::Context->preference("SyndeticsEnabled")
439         && C4::Context->preference("SyndeticsSummary")
440         && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
441         eval {
442             my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements);
443             $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
444         };
445         warn $@ if $@;
446
447 }
448
449 if ( C4::Context->preference("SyndeticsEnabled")
450         && C4::Context->preference("SyndeticsTOC")
451         && exists($syndetics_elements->{'TOC'}) ) {
452         eval {
453     my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
454     $template->param( SYNDETICS_TOC => $syndetics_toc );
455         };
456         warn $@ if $@;
457 }
458
459 if ( C4::Context->preference("SyndeticsEnabled")
460     && C4::Context->preference("SyndeticsExcerpt")
461     && exists($syndetics_elements->{'DBCHAPTER'}) ) {
462     eval {
463     my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
464     $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
465     };
466         warn $@ if $@;
467 }
468
469 if ( C4::Context->preference("SyndeticsEnabled")
470     && C4::Context->preference("SyndeticsReviews")) {
471     eval {
472     my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
473     $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
474     };
475         warn $@ if $@;
476 }
477
478 if ( C4::Context->preference("SyndeticsEnabled")
479     && C4::Context->preference("SyndeticsAuthorNotes")
480         && exists($syndetics_elements->{'ANOTES'}) ) {
481     eval {
482     my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
483     $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
484     };
485     warn $@ if $@;
486 }
487
488 # LibraryThingForLibraries ID Code and Tabbed View Option
489 if( C4::Context->preference('LibraryThingForLibrariesEnabled') ) 
490
491 $template->param(LibraryThingForLibrariesID =>
492 C4::Context->preference('LibraryThingForLibrariesID') ); 
493 $template->param(LibraryThingForLibrariesTabbedView =>
494 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
495
496
497
498 # Babelthèque
499 if ( C4::Context->preference("Babeltheque") ) {
500     $template->param( 
501         Babeltheque => 1,
502     );
503 }
504
505 # Shelf Browser Stuff
506 if (C4::Context->preference("OPACShelfBrowser")) {
507     # pick the first itemnumber unless one was selected by the user
508     my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); # || $items[0]->{itemnumber};
509     if (defined($starting_itemnumber)) {
510         $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
511         my $nearby = GetNearbyItems($starting_itemnumber,3);
512
513         $template->param(
514             starting_homebranch => $nearby->{starting_homebranch}->{description},
515             starting_location => $nearby->{starting_location}->{description},
516             starting_ccode => $nearby->{starting_ccode}->{description},
517             starting_itemnumber => $nearby->{starting_itemnumber},
518             shelfbrowser_prev_itemnumber => $nearby->{prev_itemnumber},
519             shelfbrowser_next_itemnumber => $nearby->{next_itemnumber},
520             shelfbrowser_prev_biblionumber => $nearby->{prev_biblionumber},
521             shelfbrowser_next_biblionumber => $nearby->{next_biblionumber},
522             PREVIOUS_SHELF_BROWSE => $nearby->{prev},
523             NEXT_SHELF_BROWSE => $nearby->{next},
524         );
525     }
526 }
527
528 if (C4::Context->preference("BakerTaylorEnabled")) {
529         $template->param(
530                 BakerTaylorEnabled  => 1,
531                 BakerTaylorImageURL => &image_url(),
532                 BakerTaylorLinkURL  => &link_url(),
533                 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
534         );
535         my ($bt_user, $bt_pass);
536         if ($isbn and
537                 $bt_user = C4::Context->preference('BakerTaylorUsername') and
538                 $bt_pass = C4::Context->preference('BakerTaylorPassword')    )
539         {
540                 $template->param(
541                 BakerTaylorContentURL   =>
542                 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
543                                 $bt_user,$bt_pass,$isbn)
544                 );
545         }
546 }
547
548 my $tag_quantity;
549 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
550         $template->param(
551                 TagsEnabled => 1,
552                 TagsShowOnDetail => $tag_quantity,
553                 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
554         );
555         $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
556                                                                 'sort'=>'-weight', limit=>$tag_quantity}));
557 }
558
559 if (C4::Context->preference("OPACURLOpenInNewWindow")) {
560     # These values are going to be read by Javascript, at least in the case
561     # of the google covers
562     $template->param(covernewwindow => 'true');
563 } else {
564     $template->param(covernewwindow => 'false');
565 }
566
567 #Search for title in links
568 my $marccontrolnumber   = GetMarcControlnumber   ($record, $marcflavour);
569
570 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
571     $dat->{author} ? $search_for_title =~ s/{AUTHOR}/$dat->{author}/g : $search_for_title =~ s/{AUTHOR}//g;
572     $dat->{title} =~ s/\/+$//; # remove trailing slash
573     $dat->{title} =~ s/\s+$//; # remove trailing space
574     $dat->{title} ? $search_for_title =~ s/{TITLE}/$dat->{title}/g : $search_for_title =~ s/{TITLE}//g;
575     $isbn ? $search_for_title =~ s/{ISBN}/$isbn/g : $search_for_title =~ s/{ISBN}//g;
576     $marccontrolnumber ? $search_for_title =~ s/{CONTROLNUMBER}/$marccontrolnumber/g : $search_for_title =~ s/{CONTROLNUMBER}//g;
577     $search_for_title =~ s/{BIBLIONUMBER}/$biblionumber/g;
578  $template->param('OPACSearchForTitleIn' => $search_for_title);
579 }
580
581 # We try to select the best default tab to show, according to what
582 # the user wants, and what's available for display
583 my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab');
584 my $defaulttab = 
585     $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
586         ? 'subscriptions' :
587     $opac_serial_default eq 'serialcollection' && @serialcollections > 0
588         ? 'serialcollection' :
589     $opac_serial_default eq 'holdings' && $dat->{'count'} > 0
590         ? 'holdings' :
591     $subscriptionsnumber
592         ? 'subscriptions' :
593     @serialcollections > 0 
594         ? 'serialcollection' : 'subscription';
595 $template->param('defaulttab' => $defaulttab);
596
597 output_html_with_http_headers $query, $cookie, $template->output;