Bug fix to OPAC shelf browsing query statement
[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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 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::Serials;
40 use C4::Members;
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 my $record       = GetMarcBiblio($biblionumber);
63 $template->param( biblionumber => $biblionumber );
64 # XSLT processing of some stuff
65 if (C4::Context->preference("XSLTDetailsDisplay") ) {
66     my $newxmlrecord = XSLTParse4Display($biblionumber, $record, C4::Context->config('opachtdocs')."/prog/en/xslt/MARC21slim2OPACDetail.xsl");
67     $template->param('XSLTBloc' => $newxmlrecord);
68 }
69
70 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") ); 
71 # change back when ive fixed request.pl
72 my @all_items = &GetItemsInfo( $biblionumber, 'opac' );
73 my @items;
74 @items = @all_items unless C4::Context->preference('hidelostitems');
75
76 if (C4::Context->preference('hidelostitems')) {
77     # Hide host items
78     for my $itm (@all_items) {
79         push @items, $itm unless $itm->{itemlost};
80     }
81 }
82 my $dat = &GetBiblioData($biblionumber);
83
84 if (!$dat) {
85     print $query->redirect("/cgi-bin/koha/errors/404.pl");
86     exit;
87 }
88 my $itemtypes = GetItemTypes();
89 # imageurl:
90 my $itemtype = $dat->{'itemtype'};
91 if ( $itemtype ) {
92     $dat->{'imageurl'}    = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
93     $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
94 }
95 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'});
96 my $collections =  GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'} );
97
98 #coping with subscriptions
99 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
100 my @subscriptions       = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
101
102 my @subs;
103 $dat->{'serial'}=1 if $subscriptionsnumber;
104 foreach my $subscription (@subscriptions) {
105     my $serials_to_display;
106     my %cell;
107     $cell{subscriptionid}    = $subscription->{subscriptionid};
108     $cell{subscriptionnotes} = $subscription->{notes};
109     $cell{branchcode}        = $subscription->{branchcode};
110     $cell{hasalert}          = $subscription->{hasalert};
111     #get the three latest serials.
112     $serials_to_display = $subscription->{opacdisplaycount};
113     $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
114         $cell{opacdisplaycount} = $serials_to_display;
115     $cell{latestserials} =
116       GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
117     push @subs, \%cell;
118 }
119
120 $dat->{'count'} = scalar(@items);
121
122 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) );
123
124 my $norequests = 1;
125 my $branches = GetBranches();
126 my %itemfields;
127 for my $itm (@items) {
128     $norequests = 0
129        if ( (not $itm->{'wthdrawn'} )
130          && (not $itm->{'itemlost'} )
131          && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
132                  && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
133          && ($itm->{'itemnumber'} ) );
134
135     if ( defined $itm->{'publictype'} ) {
136         # I can't actually find any case in which this is defined. --amoore 2008-12-09
137         $itm->{ $itm->{'publictype'} } = 1;
138     }
139     $itm->{datedue}      = format_date($itm->{datedue});
140     $itm->{datelastseen} = format_date($itm->{datelastseen});
141
142     # get collection code description, too
143     if ( my $ccode = $itm->{'ccode'} ) {
144         $itm->{'ccode'} = $collections->{$ccode} if ( defined($collections) && exists( $collections->{$ccode} ) );
145     }
146     if ( defined $itm->{'location'} ) {
147         $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
148     }
149     if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
150         $itm->{'imageurl'}    = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
151         $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{'description'};
152     }
153     foreach (qw(ccode enumchron copynumber itemnotes)) {
154         $itemfields{$_} = 1 if ($itm->{$_});
155     }
156
157      # walk through the item-level authorised values and populate some images
158      my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
159      # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
160
161      if ( $itm->{'itemlost'} ) {
162          my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
163          $itm->{'lostimageurl'}   = $lostimageinfo->{ 'imageurl' };
164          $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
165      }
166
167      if( $itm->{'count_reserves'}){
168           if( $itm->{'count_reserves'} eq "Waiting"){ $itm->{'waiting'} = 1; }
169           if( $itm->{'count_reserves'} eq "Reserved"){ $itm->{'onhold'} = 1; }
170      }
171     
172      my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
173      if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
174         $itm->{transfertwhen} = format_date($transfertwhen);
175         $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
176         $itm->{transfertto}   = $branches->{$transfertto}{branchname};
177      }
178 }
179
180 ## get notes and subjects from MARC record
181 my $dbh              = C4::Context->dbh;
182 my $marcflavour      = C4::Context->preference("marcflavour");
183 my $marcnotesarray   = GetMarcNotes   ($record,$marcflavour);
184 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
185 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
186 my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
187 my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
188 my $subtitle         = C4::Biblio::get_koha_field_from_marc('bibliosubtitle', 'subtitle', $record, '');
189
190     $template->param(
191                      MARCNOTES               => $marcnotesarray,
192                      MARCSUBJCTS             => $marcsubjctsarray,
193                      MARCAUTHORS             => $marcauthorsarray,
194                      MARCSERIES              => $marcseriesarray,
195                      MARCURLS                => $marcurlsarray,
196                      norequests              => $norequests,
197                      RequestOnOpac           => C4::Context->preference("RequestOnOpac"),
198                      itemdata_ccode          => $itemfields{ccode},
199                      itemdata_enumchron      => $itemfields{enumchron},
200                      itemdata_copynumber     => $itemfields{copynumber},
201                      itemdata_itemnotes          => $itemfields{itemnotes},
202                      authorised_value_images => $biblio_authorised_value_images,
203                      subtitle                => $subtitle,
204     );
205
206 foreach ( keys %{$dat} ) {
207     $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
208 }
209
210 # some useful variables for enhanced content;
211 # in each case, we're grabbing the first value we find in
212 # the record and normalizing it
213 my $upc = GetNormalizedUPC($record,$marcflavour);
214 my $ean = GetNormalizedEAN($record,$marcflavour);
215 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
216 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
217 my $content_identifier_exists = 1 if ($isbn or $ean or $oclc or $upc);
218 $template->param(
219         normalized_upc => $upc,
220         normalized_ean => $ean,
221         normalized_oclc => $oclc,
222         normalized_isbn => $isbn,
223         content_identifier_exists =>  $content_identifier_exists,
224 );
225
226 # COinS format FIXME: for books Only
227 my $coins_format;
228 my $fmt = substr $record->leader(), 6,2;
229 my $fmts;
230 $fmts->{'am'} = 'book';
231 $coins_format = $fmts->{$fmt};
232 $template->param(
233         ocoins_format => $coins_format,
234 );
235
236 my $reviews = getreviews( $biblionumber, 1 );
237 my $loggedincommenter;
238 foreach ( @$reviews ) {
239     my $borrowerData   = GetMember($_->{borrowernumber},'borrowernumber');
240     # setting some borrower info into this hash
241     $_->{title}     = $borrowerData->{'title'};
242     $_->{surname}   = $borrowerData->{'surname'};
243     $_->{firstname} = $borrowerData->{'firstname'};
244     $_->{userid}    = $borrowerData->{'userid'};
245     $_->{datereviewed} = format_date($_->{datereviewed});
246     if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
247                 $_->{your_comment} = 1;
248                 $loggedincommenter = 1;
249         }
250 }
251
252
253 if(C4::Context->preference("ISBD")) {
254         $template->param(ISBD => 1);
255 }
256
257 $template->param(
258     ITEM_RESULTS        => \@items,
259     subscriptionsnumber => $subscriptionsnumber,
260     biblionumber        => $biblionumber,
261     subscriptions       => \@subs,
262     subscriptionsnumber => $subscriptionsnumber,
263     reviews             => $reviews,
264     loggedincommenter   => $loggedincommenter
265 );
266
267 # XISBN Stuff
268 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
269     eval {
270         $template->param(
271             XISBNS => get_xisbns($isbn)
272         );
273     };
274     if ($@) { warn "XISBN Failed $@"; }
275 }
276 # Amazon.com Stuff
277 if ( C4::Context->preference("OPACAmazonEnabled") ) {
278     $template->param( AmazonTld => get_amazon_tld() );
279     my $amazon_reviews  = C4::Context->preference("OPACAmazonReviews");
280     my $amazon_similars = C4::Context->preference("OPACAmazonSimilarItems");
281     my @services;
282     if ( $amazon_reviews ) {
283         $template->param( OPACAmazonReviews => 1 );
284         push( @services, 'EditorialReview', 'Reviews' );
285     }
286     if ( $amazon_similars ) {
287         $template->param( OPACAmazonSimilarItems => 1 );
288         push( @services, 'Similarities' );
289     }
290     my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour, \@services );
291     my $similar_products_exist;
292     if ( $amazon_reviews ) {
293         my $item = $amazon_details->{Items}->{Item};
294         my $customer_reviews = \@{ $item->{CustomerReviews}->{Review} };
295         for my $one_review ( @$customer_reviews ) {
296             $one_review->{Date} = format_date($one_review->{Date});
297         }
298         my $editorial_reviews = \@{ $item->{EditorialReviews}->{EditorialReview} };
299         my $average_rating = $item->{CustomerReviews}->{AverageRating} || 0;
300         $template->param( amazon_average_rating    => $average_rating * 20);
301         $template->param( AMAZON_CUSTOMER_REVIEWS  => $customer_reviews );
302         $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
303     }
304     if ( $amazon_similars ) {
305         my $item = $amazon_details->{Items}->{Item};
306         my @similar_products;
307         for my $similar_product (@{ $item->{SimilarProducts}->{SimilarProduct} }) {
308             # do we have any of these isbns in our collection?
309             my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
310             # verify that there is at least one similar item
311             if (scalar(@$similar_biblionumbers)){
312                 $similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
313                 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN}  };
314             }
315         }
316         $template->param( OPACAmazonSimilarItems => $similar_products_exist );
317         $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
318     }
319 }
320
321 my $syndetics_elements;
322
323 if ( C4::Context->preference("SyndeticsEnabled") ) {
324         eval {
325     $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
326         for my $element (values %$syndetics_elements) {
327                 $template->param("Syndetics$element"."Exists" => 1 );
328                 #warn "Exists: "."Syndetics$element"."Exists";
329         }
330     };
331     warn $@ if $@;
332 }
333
334 if ( C4::Context->preference("SyndeticsEnabled")
335         && C4::Context->preference("SyndeticsSummary")
336         && (    $syndetics_elements->{'SUMMARY'}   =~ /SUMMARY/
337              || $syndetics_elements->{'AVSUMMARY'} =~ /AVSUMMARY/ ) ) {
338         eval {
339         my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements);
340         $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
341         };
342         warn $@ if $@;
343
344 }
345
346 if ( C4::Context->preference("SyndeticsEnabled")
347         && C4::Context->preference("SyndeticsTOC")
348         && $syndetics_elements->{'TOC'} =~ /TOC/) {
349         eval {
350     my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
351     $template->param( SYNDETICS_TOC => $syndetics_toc );
352         };
353         warn $@ if $@;
354 }
355
356 if ( C4::Context->preference("SyndeticsEnabled")
357     && C4::Context->preference("SyndeticsExcerpt")
358     && $syndetics_elements->{'DBCHAPTER'} =~ /DBCHAPTER/ ) {
359     eval {
360     my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
361     $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
362     };
363         warn $@ if $@;
364 }
365
366 if ( C4::Context->preference("SyndeticsEnabled")
367     && C4::Context->preference("SyndeticsReviews")) {
368     eval {
369     my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
370     $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
371     };
372         warn $@ if $@;
373 }
374
375 if ( C4::Context->preference("SyndeticsEnabled")
376     && C4::Context->preference("SyndeticsAuthorNotes")
377         && $syndetics_elements->{'ANOTES'} =~ /ANOTES/ ) {
378     eval {
379     my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
380     $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
381     };
382     warn $@ if $@;
383 }
384
385 # LibraryThingForLibraries ID Code and Tabbed View Option
386 if( C4::Context->preference('LibraryThingForLibrariesEnabled') ) 
387
388 $template->param(LibraryThingForLibrariesID =>
389 C4::Context->preference('LibraryThingForLibrariesID') ); 
390 $template->param(LibraryThingForLibrariesTabbedView =>
391 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
392
393
394
395 # Babelthèque
396 if ( C4::Context->preference("Babeltheque") ) {
397     $template->param( 
398         Babeltheque => 1,
399     );
400 }
401
402 # Shelf Browser Stuff
403 if (C4::Context->preference("OPACShelfBrowser")) {
404     # pick the first itemnumber unless one was selected by the user
405     my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); # || $items[0]->{itemnumber};
406     $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
407     # find the right cn_sort value for this item
408     my ($starting_cn_sort, $starting_homebranch, $starting_location);
409     my $sth_get_cn_sort = $dbh->prepare("SELECT cn_sort,homebranch,location from items where itemnumber=?");
410     $sth_get_cn_sort->execute($starting_itemnumber);
411     while (my $result = $sth_get_cn_sort->fetchrow_hashref()) {
412         $starting_cn_sort = $result->{'cn_sort'};
413         $starting_homebranch->{code} = $result->{'homebranch'};
414         $starting_homebranch->{description} = $branches->{$result->{'homebranch'}}{branchname};
415         $starting_location->{code} = $result->{'location'};
416         $starting_location->{description} = GetAuthorisedValueDesc('','',   $result->{'location'} ,'','','LOC');
417     
418     }
419     
420     ## List of Previous Items
421     # order by cn_sort, which should include everything we need for ordering purposes (though not
422     # for limits, those need to be handled separately
423     my $sth_shelfbrowse_previous;
424     if (defined $starting_location->{code}) {
425       $sth_shelfbrowse_previous = $dbh->prepare("
426         SELECT *
427         FROM items
428         WHERE
429             ((cn_sort = ? AND itemnumber < ?) OR cn_sort < ?) AND
430             homebranch = ? AND location = ?
431         ORDER BY cn_sort DESC, itemnumber LIMIT 3
432         ");
433       $sth_shelfbrowse_previous->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code});
434     } else {
435       $sth_shelfbrowse_previous = $dbh->prepare("
436         SELECT *
437         FROM items
438         WHERE
439             ((cn_sort = ? AND itemnumber < ?) OR cn_sort < ?) AND
440             homebranch = ?
441         ORDER BY cn_sort DESC, itemnumber LIMIT 3
442         ");
443       $sth_shelfbrowse_previous->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code});
444     }
445     my @previous_items;
446     while (my $this_item = $sth_shelfbrowse_previous->fetchrow_hashref()) {
447         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=?");
448         $sth_get_biblio->execute($this_item->{biblionumber});
449         while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
450                         $this_item->{'title'} = $this_biblio->{'title'};
451                         my $this_record = GetMarcBiblio($this_biblio->{'biblionumber'});
452                         $this_item->{'browser_normalized_upc'} = GetNormalizedUPC($this_record,$marcflavour);
453                         $this_item->{'browser_normalized_oclc'} = GetNormalizedOCLCNumber($this_record,$marcflavour);
454                         $this_item->{'browser_normalized_isbn'} = GetNormalizedISBN(undef,$this_record,$marcflavour);
455         }
456         unshift @previous_items, $this_item;
457     }
458     
459     ## List of Next Items; this also intentionally catches the current item
460     my $sth_shelfbrowse_next;
461     if (defined $starting_location->{code}) {
462       $sth_shelfbrowse_next = $dbh->prepare("
463         SELECT *
464         FROM items
465         WHERE
466             ((cn_sort = ? AND itemnumber >= ?) OR cn_sort > ?) AND
467             homebranch = ? AND location = ?
468         ORDER BY cn_sort, itemnumber LIMIT 3
469         ");
470       $sth_shelfbrowse_next->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code});
471     } else {
472       $sth_shelfbrowse_next = $dbh->prepare("
473         SELECT *
474         FROM items
475         WHERE
476             ((cn_sort = ? AND itemnumber >= ?) OR cn_sort > ?) AND
477             homebranch = ?
478         ORDER BY cn_sort, itemnumber LIMIT 3
479         ");
480       $sth_shelfbrowse_next->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code});
481     }
482     my @next_items;
483     while (my $this_item = $sth_shelfbrowse_next->fetchrow_hashref()) {
484         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=?");
485         $sth_get_biblio->execute($this_item->{biblionumber});
486         while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
487             $this_item->{'title'} = $this_biblio->{'title'};
488                         my $this_record = GetMarcBiblio($this_biblio->{'biblionumber'});
489             $this_item->{'browser_normalized_upc'} = GetNormalizedUPC($this_record,$marcflavour);
490             $this_item->{'browser_normalized_oclc'} = GetNormalizedOCLCNumber($this_record,$marcflavour);
491             $this_item->{'browser_normalized_isbn'} = GetNormalizedISBN(undef,$this_record,$marcflavour);
492         }
493         push @next_items, $this_item;
494     }
495     
496     # alas, these won't auto-vivify, see http://www.perlmonks.org/?node_id=508481
497     my $shelfbrowser_next_itemnumber = $next_items[-1]->{itemnumber} if @next_items;
498     my $shelfbrowser_next_biblionumber = $next_items[-1]->{biblionumber} if @next_items;
499     
500     $template->param(
501         starting_homebranch => $starting_homebranch->{description},
502         starting_location => $starting_location->{description},
503         starting_itemnumber => $starting_itemnumber,
504         shelfbrowser_prev_itemnumber => (@previous_items ? $previous_items[0]->{itemnumber} : 0),
505         shelfbrowser_next_itemnumber => $shelfbrowser_next_itemnumber,
506         shelfbrowser_prev_biblionumber => (@previous_items ? $previous_items[0]->{biblionumber} : 0),
507         shelfbrowser_next_biblionumber => $shelfbrowser_next_biblionumber,
508         PREVIOUS_SHELF_BROWSE => \@previous_items,
509         NEXT_SHELF_BROWSE => \@next_items,
510     );
511 }
512
513 if (C4::Context->preference("BakerTaylorEnabled")) {
514         $template->param(
515                 BakerTaylorEnabled  => 1,
516                 BakerTaylorImageURL => &image_url(),
517                 BakerTaylorLinkURL  => &link_url(),
518                 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
519         );
520         my ($bt_user, $bt_pass);
521         if ($isbn and
522                 $bt_user = C4::Context->preference('BakerTaylorUsername') and
523                 $bt_pass = C4::Context->preference('BakerTaylorPassword')    )
524         {
525                 $template->param(
526                 BakerTaylorContentURL   =>
527                 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
528                                 $bt_user,$bt_pass,$isbn)
529                 );
530         }
531 }
532
533 my $tag_quantity;
534 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
535         $template->param(
536                 TagsEnabled => 1,
537                 TagsShowOnDetail => $tag_quantity,
538                 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
539         );
540         $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
541                                                                 'sort'=>'-weight', limit=>$tag_quantity}));
542 }
543
544 output_html_with_http_headers $query, $cookie, $template->output;