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