3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2010 BibLibre
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 use C4
::Serials
; #uses getsubscriptionfrom biblionumber
34 use C4
::Tags
qw(get_tags);
35 use C4
::Dates qw
/format_date/;
36 use C4
::XISBN
qw(get_xisbns get_biblionumber_from_isbn);
37 use C4
::External
::Amazon
;
38 use C4
::External
::Syndetics
qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes );
41 use C4
::VirtualShelves
;
47 use List
::MoreUtils qw
/any none/;
50 if (C4
::Context
->preference('BakerTaylorEnabled')) {
51 require C4
::External
::BakerTaylor
;
52 import C4
::External
::BakerTaylor
qw(&image_url &link_url);
57 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
59 template_name
=> "opac-detail.tmpl",
62 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
63 flagsrequired
=> { borrow
=> 1 },
67 my $biblionumber = $query->param('biblionumber') || $query->param('bib');
69 $template->param( 'AllowOnShelfHolds' => C4
::Context
->preference('AllowOnShelfHolds') );
70 $template->param( 'ItemsIssued' => CountItemsIssued
( $biblionumber ) );
72 my $record = GetMarcBiblio
($biblionumber);
74 print $query->redirect("/cgi-bin/koha/errors/404.pl");
77 $template->param( biblionumber
=> $biblionumber );
81 # XSLT processing of some stuff
82 if (C4
::Context
->preference("OPACXSLTDetailsDisplay") ) {
83 $template->param( 'XSLTBloc' => XSLTParse4Display
($biblionumber, $record, 'Detail', 'opac') );
86 $template->param('OPACShowCheckoutName' => C4
::Context
->preference("OPACShowCheckoutName") );
87 # change back when ive fixed request.pl
88 my @all_items = GetItemsInfo
( $biblionumber );
91 # Getting items to be hidden
92 my @hiddenitems = GetHiddenItemnumbers
(@all_items);
94 # Are there items to hide?
95 my $hideitems = 1 if C4
::Context
->preference('hidelostitems') or scalar(@hiddenitems) > 0;
99 for my $itm (@all_items) {
100 if ( C4
::Context
->preference('hidelostitems') ) {
101 push @items, $itm unless $itm->{itemlost
} or any
{ $itm->{'itemnumber'} eq $_ } @hiddenitems;
103 push @items, $itm unless any
{ $itm->{'itemnumber'} eq $_ } @hiddenitems;
111 my $dat = &GetBiblioData
($biblionumber);
113 my $itemtypes = GetItemTypes
();
115 my $itemtype = $dat->{'itemtype'};
117 $dat->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
118 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
120 my $shelflocations =GetKohaAuthorisedValues
('items.location',$dat->{'frameworkcode'}, 'opac');
121 my $collections = GetKohaAuthorisedValues
('items.ccode',$dat->{'frameworkcode'}, 'opac');
123 #coping with subscriptions
124 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
125 my @subscriptions = GetSubscriptions
( undef, undef, $biblionumber );
128 $dat->{'serial'}=1 if $subscriptionsnumber;
129 foreach my $subscription (@subscriptions) {
130 my $serials_to_display;
132 $cell{subscriptionid
} = $subscription->{subscriptionid
};
133 $cell{subscriptionnotes
} = $subscription->{notes
};
134 $cell{missinglist
} = $subscription->{missinglist
};
135 $cell{opacnote
} = $subscription->{opacnote
};
136 $cell{histstartdate
} = format_date
($subscription->{histstartdate
});
137 $cell{histenddate
} = format_date
($subscription->{histenddate
});
138 $cell{branchcode
} = $subscription->{branchcode
};
139 $cell{branchname
} = GetBranchName
($subscription->{branchcode
});
140 $cell{hasalert
} = $subscription->{hasalert
};
141 #get the three latest serials.
142 $serials_to_display = $subscription->{opacdisplaycount
};
143 $serials_to_display = C4
::Context
->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
144 $cell{opacdisplaycount
} = $serials_to_display;
145 $cell{latestserials
} =
146 GetLatestSerials
( $subscription->{subscriptionid
}, $serials_to_display );
150 $dat->{'count'} = scalar(@items);
152 # If there is a lot of items, and the user has not decided
153 # to view them all yet, we first warn him
154 # TODO: The limit of 50 could be a syspref
155 my $viewallitems = $query->param('viewallitems');
156 if ($dat->{'count'} >= 50 && !$viewallitems) {
157 $template->param('lotsofitems' => 1);
160 my $biblio_authorised_value_images = C4
::Items
::get_authorised_value_images
( C4
::Biblio
::get_biblio_authorised_values
( $biblionumber, $record ) );
163 my $branches = GetBranches
();
165 for my $itm (@items) {
167 if ( (not $itm->{'wthdrawn'} )
168 && (not $itm->{'itemlost'} )
169 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
170 && (not $itemtypes->{$itm->{'itype'}}->{notforloan
} )
171 && ($itm->{'itemnumber'} ) );
173 if ( defined $itm->{'publictype'} ) {
174 # I can't actually find any case in which this is defined. --amoore 2008-12-09
175 $itm->{ $itm->{'publictype'} } = 1;
177 $itm->{datedue
} = format_date
($itm->{datedue
});
178 $itm->{datelastseen
} = format_date
($itm->{datelastseen
});
180 # get collection code description, too
181 if ( my $ccode = $itm->{'ccode'} ) {
182 $itm->{'ccode'} = $collections->{$ccode} if ( defined($collections) && exists( $collections->{$ccode} ) );
184 if ( defined $itm->{'location'} ) {
185 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
187 if (exists $itm->{itype
} && defined($itm->{itype
}) && exists $itemtypes->{ $itm->{itype
} }) {
188 $itm->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{ $itm->{itype
} }->{'imageurl'} );
189 $itm->{'description'} = $itemtypes->{ $itm->{itype
} }->{'description'};
191 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
192 $itemfields{$_} = 1 if ($itm->{$_});
195 # walk through the item-level authorised values and populate some images
196 my $item_authorised_value_images = C4
::Items
::get_authorised_value_images
( C4
::Items
::get_item_authorised_values
( $itm->{'itemnumber'} ) );
197 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
199 if ( $itm->{'itemlost'} ) {
200 my $lostimageinfo = List
::Util
::first
{ $_->{'category'} eq 'LOST' } @
$item_authorised_value_images;
201 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
202 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
205 if( $itm->{'count_reserves'}){
206 if( $itm->{'count_reserves'} eq "Waiting"){ $itm->{'waiting'} = 1; }
207 if( $itm->{'count_reserves'} eq "Reserved"){ $itm->{'onhold'} = 1; }
210 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers
($itm->{itemnumber
});
211 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
212 $itm->{transfertwhen
} = format_date
($transfertwhen);
213 $itm->{transfertfrom
} = $branches->{$transfertfrom}{branchname
};
214 $itm->{transfertto
} = $branches->{$transfertto}{branchname
};
218 ## get notes and subjects from MARC record
219 my $dbh = C4
::Context
->dbh;
220 my $marcflavour = C4
::Context
->preference("marcflavour");
221 my $marcnotesarray = GetMarcNotes
($record,$marcflavour);
222 my $marcisbnsarray = GetMarcISBN
($record,$marcflavour);
223 my $marcauthorsarray = GetMarcAuthors
($record,$marcflavour);
224 my $marcsubjctsarray = GetMarcSubjects
($record,$marcflavour);
225 my $marcseriesarray = GetMarcSeries
($record,$marcflavour);
226 my $marcurlsarray = GetMarcUrls
($record,$marcflavour);
227 my $subtitle = GetRecordValue
('subtitle', $record, GetFrameworkCode
($biblionumber));
230 MARCNOTES
=> $marcnotesarray,
231 MARCSUBJCTS
=> $marcsubjctsarray,
232 MARCAUTHORS
=> $marcauthorsarray,
233 MARCSERIES
=> $marcseriesarray,
234 MARCURLS
=> $marcurlsarray,
235 norequests
=> $norequests,
236 RequestOnOpac
=> C4
::Context
->preference("RequestOnOpac"),
237 itemdata_ccode
=> $itemfields{ccode
},
238 itemdata_enumchron
=> $itemfields{enumchron
},
239 itemdata_uri
=> $itemfields{uri
},
240 itemdata_copynumber
=> $itemfields{copynumber
},
241 itemdata_itemnotes
=> $itemfields{itemnotes
},
242 authorised_value_images
=> $biblio_authorised_value_images,
243 subtitle
=> $subtitle,
246 if (C4
::Context
->preference("AlternateHoldingsField") && scalar @items == 0) {
247 my $fieldspec = C4
::Context
->preference("AlternateHoldingsField");
248 my $subfields = substr $fieldspec, 3;
249 my $holdingsep = C4
::Context
->preference("AlternateHoldingsSeparator") || ' ';
250 my @alternateholdingsinfo = ();
251 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
253 for my $field (@holdingsfields) {
254 my %holding = ( holding
=> '' );
255 my $havesubfield = 0;
256 for my $subfield ($field->subfields()) {
257 if ((index $subfields, $$subfield[0]) >= 0) {
258 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
259 $holding{'holding'} .= $$subfield[1];
264 push(@alternateholdingsinfo, \
%holding);
269 ALTERNATEHOLDINGS
=> \
@alternateholdingsinfo,
273 foreach ( keys %{$dat} ) {
274 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
277 # some useful variables for enhanced content;
278 # in each case, we're grabbing the first value we find in
279 # the record and normalizing it
280 my $upc = GetNormalizedUPC
($record,$marcflavour);
281 my $ean = GetNormalizedEAN
($record,$marcflavour);
282 my $oclc = GetNormalizedOCLCNumber
($record,$marcflavour);
283 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
284 my $content_identifier_exists = 1 if ($isbn or $ean or $oclc or $upc);
286 normalized_upc
=> $upc,
287 normalized_ean
=> $ean,
288 normalized_oclc
=> $oclc,
289 normalized_isbn
=> $isbn,
290 content_identifier_exists
=> $content_identifier_exists,
293 # COinS format FIXME: for books Only
295 ocoins
=> GetCOinSBiblio
($biblionumber),
298 my $reviews = getreviews
( $biblionumber, 1 );
299 my $loggedincommenter;
300 foreach ( @
$reviews ) {
301 my $borrowerData = GetMember
('borrowernumber' => $_->{borrowernumber
});
302 # setting some borrower info into this hash
303 $_->{title
} = $borrowerData->{'title'};
304 $_->{surname
} = $borrowerData->{'surname'};
305 $_->{firstname
} = $borrowerData->{'firstname'};
306 $_->{userid
} = $borrowerData->{'userid'};
307 $_->{cardnumber
} = $borrowerData->{'cardnumber'};
308 $_->{datereviewed
} = format_date
($_->{datereviewed
});
309 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
310 $_->{your_comment
} = 1;
311 $loggedincommenter = 1;
316 if(C4
::Context
->preference("ISBD")) {
317 $template->param(ISBD
=> 1);
321 ITEM_RESULTS
=> \
@items,
322 subscriptionsnumber
=> $subscriptionsnumber,
323 biblionumber
=> $biblionumber,
324 subscriptions
=> \
@subs,
325 subscriptionsnumber
=> $subscriptionsnumber,
327 loggedincommenter
=> $loggedincommenter
332 if (C4
::Context
->preference("virtualshelves") ) {
333 $template->param( 'GetShelves' => GetBibliosShelves
( $biblionumber ) );
338 if (C4
::Context
->preference("OPACFRBRizeEditions")==1) {
341 XISBNS
=> get_xisbns
($isbn)
344 if ($@
) { warn "XISBN Failed $@"; }
348 my @sc_fields = $record->field(955);
349 my @serialcollections = ();
351 foreach my $sc_field (@sc_fields) {
354 $row_data{text
} = $sc_field->subfield('r');
355 $row_data{branch
} = $sc_field->subfield('9');
357 if ($row_data{text
} && $row_data{branch
}) {
358 push (@serialcollections, \
%row_data);
362 if (scalar(@serialcollections) > 0) {
364 serialcollection
=> 1,
365 serialcollections
=> \
@serialcollections);
369 if ( C4
::Context
->preference("OPACAmazonEnabled") ) {
370 $template->param( AmazonTld
=> get_amazon_tld
() );
371 my $amazon_reviews = C4
::Context
->preference("OPACAmazonReviews");
372 my $amazon_similars = C4
::Context
->preference("OPACAmazonSimilarItems");
374 if ( $amazon_reviews ) {
375 push( @services, 'EditorialReview', 'Reviews' );
377 if ( $amazon_similars ) {
378 push( @services, 'Similarities' );
380 my $amazon_details = &get_amazon_details
( $isbn, $record, $marcflavour, \
@services );
381 my $similar_products_exist;
382 if ( $amazon_reviews ) {
383 my $item = $amazon_details->{Items
}->{Item
}->[0];
384 my $customer_reviews = \@
{ $item->{CustomerReviews
}->{Review
} };
385 for my $one_review ( @
$customer_reviews ) {
386 $one_review->{Date
} = format_date
($one_review->{Date
});
388 my $editorial_reviews = \@
{ $item->{EditorialReviews
}->{EditorialReview
} };
389 my $average_rating = $item->{CustomerReviews
}->{AverageRating
} || 0;
390 $template->param( amazon_average_rating
=> $average_rating * 20);
391 $template->param( AMAZON_CUSTOMER_REVIEWS
=> $customer_reviews );
392 $template->param( AMAZON_EDITORIAL_REVIEWS
=> $editorial_reviews );
394 if ( $amazon_similars ) {
395 my $item = $amazon_details->{Items
}->{Item
}->[0];
396 my @similar_products;
397 for my $similar_product (@
{ $item->{SimilarProducts
}->{SimilarProduct
} }) {
398 # do we have any of these isbns in our collection?
399 my $similar_biblionumbers = get_biblionumber_from_isbn
($similar_product->{ASIN
});
400 # verify that there is at least one similar item
401 if (scalar(@
$similar_biblionumbers)){
402 $similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
403 push @similar_products, +{ similar_biblionumbers
=> $similar_biblionumbers, title
=> $similar_product->{Title
}, ASIN
=> $similar_product->{ASIN
} };
406 $template->param( OPACAmazonSimilarItems
=> $similar_products_exist );
407 $template->param( AMAZON_SIMILAR_PRODUCTS
=> \
@similar_products );
411 my $syndetics_elements;
413 if ( C4
::Context
->preference("SyndeticsEnabled") ) {
414 $template->param("SyndeticsEnabled" => 1);
415 $template->param("SyndeticsClientCode" => C4
::Context
->preference("SyndeticsClientCode"));
417 $syndetics_elements = &get_syndetics_index
($isbn,$upc,$oclc);
418 for my $element (values %$syndetics_elements) {
419 $template->param("Syndetics$element"."Exists" => 1 );
420 #warn "Exists: "."Syndetics$element"."Exists";
426 if ( C4
::Context
->preference("SyndeticsEnabled")
427 && C4
::Context
->preference("SyndeticsSummary")
428 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
430 my $syndetics_summary = &get_syndetics_summary
($isbn,$upc,$oclc, $syndetics_elements);
431 $template->param( SYNDETICS_SUMMARY
=> $syndetics_summary );
437 if ( C4
::Context
->preference("SyndeticsEnabled")
438 && C4
::Context
->preference("SyndeticsTOC")
439 && exists($syndetics_elements->{'TOC'}) ) {
441 my $syndetics_toc = &get_syndetics_toc
($isbn,$upc,$oclc);
442 $template->param( SYNDETICS_TOC
=> $syndetics_toc );
447 if ( C4
::Context
->preference("SyndeticsEnabled")
448 && C4
::Context
->preference("SyndeticsExcerpt")
449 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
451 my $syndetics_excerpt = &get_syndetics_excerpt
($isbn,$upc,$oclc);
452 $template->param( SYNDETICS_EXCERPT
=> $syndetics_excerpt );
457 if ( C4
::Context
->preference("SyndeticsEnabled")
458 && C4
::Context
->preference("SyndeticsReviews")) {
460 my $syndetics_reviews = &get_syndetics_reviews
($isbn,$upc,$oclc,$syndetics_elements);
461 $template->param( SYNDETICS_REVIEWS
=> $syndetics_reviews );
466 if ( C4
::Context
->preference("SyndeticsEnabled")
467 && C4
::Context
->preference("SyndeticsAuthorNotes")
468 && exists($syndetics_elements->{'ANOTES'}) ) {
470 my $syndetics_anotes = &get_syndetics_anotes
($isbn,$upc,$oclc);
471 $template->param( SYNDETICS_ANOTES
=> $syndetics_anotes );
476 # LibraryThingForLibraries ID Code and Tabbed View Option
477 if( C4
::Context
->preference('LibraryThingForLibrariesEnabled') )
479 $template->param(LibraryThingForLibrariesID
=>
480 C4
::Context
->preference('LibraryThingForLibrariesID') );
481 $template->param(LibraryThingForLibrariesTabbedView
=>
482 C4
::Context
->preference('LibraryThingForLibrariesTabbedView') );
487 if ( C4
::Context
->preference("Babeltheque") ) {
493 # Shelf Browser Stuff
494 if (C4
::Context
->preference("OPACShelfBrowser")) {
495 # pick the first itemnumber unless one was selected by the user
496 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); # || $items[0]->{itemnumber};
497 if (defined($starting_itemnumber)) {
498 $template->param( OpenOPACShelfBrowser
=> 1) if $starting_itemnumber;
499 my $nearby = GetNearbyItems
($starting_itemnumber,3);
502 starting_homebranch
=> $nearby->{starting_homebranch
}->{description
},
503 starting_location
=> $nearby->{starting_location
}->{description
},
504 starting_ccode
=> $nearby->{starting_ccode
}->{description
},
505 starting_itemnumber
=> $nearby->{starting_itemnumber
},
506 shelfbrowser_prev_itemnumber
=> $nearby->{prev_itemnumber
},
507 shelfbrowser_next_itemnumber
=> $nearby->{next_itemnumber
},
508 shelfbrowser_prev_biblionumber
=> $nearby->{prev_biblionumber
},
509 shelfbrowser_next_biblionumber
=> $nearby->{next_biblionumber
},
510 PREVIOUS_SHELF_BROWSE
=> $nearby->{prev
},
511 NEXT_SHELF_BROWSE
=> $nearby->{next},
516 if (C4
::Context
->preference("BakerTaylorEnabled")) {
518 BakerTaylorEnabled
=> 1,
519 BakerTaylorImageURL
=> &image_url
(),
520 BakerTaylorLinkURL
=> &link_url
(),
521 BakerTaylorBookstoreURL
=> C4
::Context
->preference('BakerTaylorBookstoreURL'),
523 my ($bt_user, $bt_pass);
525 $bt_user = C4
::Context
->preference('BakerTaylorUsername') and
526 $bt_pass = C4
::Context
->preference('BakerTaylorPassword') )
529 BakerTaylorContentURL
=>
530 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
531 $bt_user,$bt_pass,$isbn)
537 if (C4
::Context
->preference('TagsEnabled') and $tag_quantity = C4
::Context
->preference('TagsShowOnDetail')) {
540 TagsShowOnDetail
=> $tag_quantity,
541 TagsInputOnDetail
=> C4
::Context
->preference('TagsInputOnDetail')
543 $template->param(TagLoop
=> get_tags
({biblionumber
=>$biblionumber, approved
=>1,
544 'sort'=>'-weight', limit
=>$tag_quantity}));
547 if (C4
::Context
->preference("OPACURLOpenInNewWindow")) {
548 # These values are going to be read by Javascript, at least in the case
549 # of the google covers
550 $template->param(covernewwindow
=> 'true');
552 $template->param(covernewwindow
=> 'false');
555 #Search for title in links
556 my $marccontrolnumber = GetMarcControlnumber
($record, $marcflavour);
558 if (my $search_for_title = C4
::Context
->preference('OPACSearchForTitleIn')){
559 $dat->{author
} ?
$search_for_title =~ s/{AUTHOR}/$dat->{author}/g : $search_for_title =~ s/{AUTHOR}//g;
560 $dat->{title
} =~ s/\/+$//; # remove trailing slash
561 $dat->{title
} =~ s/\s+$//; # remove trailing space
562 $dat->{title
} ?
$search_for_title =~ s/{TITLE}/$dat->{title}/g : $search_for_title =~ s/{TITLE}//g;
563 $isbn ?
$search_for_title =~ s/{ISBN}/$isbn/g : $search_for_title =~ s/{ISBN}//g;
564 $marccontrolnumber ?
$search_for_title =~ s/{CONTROLNUMBER}/$marccontrolnumber/g : $search_for_title =~ s/{CONTROLNUMBER}//g;
565 $search_for_title =~ s/{BIBLIONUMBER}/$biblionumber/g;
566 $template->param('OPACSearchForTitleIn' => $search_for_title);
569 # We try to select the best default tab to show, according to what
570 # the user wants, and what's available for display
571 my $opac_serial_default = C4
::Context
->preference('opacSerialDefaultTab');
573 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
575 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
576 ?
'serialcollection' :
577 $opac_serial_default eq 'holdings' && $dat->{'count'} > 0
581 @serialcollections > 0
582 ?
'serialcollection' : 'subscription';
583 $template->param('defaulttab' => $defaulttab);
585 output_html_with_http_headers
$query, $cookie, $template->output;