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