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