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