3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
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
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.
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
28 use C4::Serials; #uses getsubscriptionfrom biblionumber
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 );
44 if (C4::Context->preference('BakerTaylorEnabled')) {
45 require C4::External::BakerTaylor;
46 import C4::External::BakerTaylor qw(&image_url &link_url);
51 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
53 template_name => "opac-detail.tmpl",
57 flagsrequired => { borrow => 1 },
61 my $biblionumber = $query->param('biblionumber') || $query->param('bib');
62 my $record = GetMarcBiblio($biblionumber);
63 $template->param( biblionumber => $biblionumber );
64 # XSLT processing of some stuff
65 if (C4::Context->preference("XSLTDetailsDisplay") ) {
66 my $newxmlrecord = XSLTParse4Display($biblionumber, $record, C4::Context->config('opachtdocs')."/prog/en/xslt/MARC21slim2OPACDetail.xsl");
67 $template->param('XSLTBloc' => $newxmlrecord);
70 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
71 # change back when ive fixed request.pl
72 my @all_items = &GetItemsInfo( $biblionumber, 'opac' );
74 @items = @all_items unless C4::Context->preference('hidelostitems');
76 if (C4::Context->preference('hidelostitems')) {
78 for my $itm (@all_items) {
79 push @items, $itm unless $itm->{itemlost};
82 my $dat = &GetBiblioData($biblionumber);
85 print $query->redirect("/cgi-bin/koha/errors/404.pl");
88 my $itemtypes = GetItemTypes();
90 my $itemtype = $dat->{'itemtype'};
92 $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
93 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
95 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'});
96 my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'} );
98 #coping with subscriptions
99 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
100 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
103 $dat->{'serial'}=1 if $subscriptionsnumber;
104 foreach my $subscription (@subscriptions) {
105 my $serials_to_display;
107 $cell{subscriptionid} = $subscription->{subscriptionid};
108 $cell{subscriptionnotes} = $subscription->{notes};
109 $cell{branchcode} = $subscription->{branchcode};
110 $cell{hasalert} = $subscription->{hasalert};
111 #get the three latest serials.
112 $serials_to_display = $subscription->{opacdisplaycount};
113 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
114 $cell{opacdisplaycount} = $serials_to_display;
115 $cell{latestserials} =
116 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
120 $dat->{'count'} = scalar(@items);
122 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) );
125 my $branches = GetBranches();
127 for my $itm (@items) {
129 if ( (not $itm->{'wthdrawn'} )
130 && (not $itm->{'itemlost'} )
131 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
132 && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
133 && ($itm->{'itemnumber'} ) );
135 if ( defined $itm->{'publictype'} ) {
136 # I can't actually find any case in which this is defined. --amoore 2008-12-09
137 $itm->{ $itm->{'publictype'} } = 1;
139 $itm->{datedue} = format_date($itm->{datedue});
140 $itm->{datelastseen} = format_date($itm->{datelastseen});
142 # get collection code description, too
143 if ( my $ccode = $itm->{'ccode'} ) {
144 $itm->{'ccode'} = $collections->{$ccode} if ( defined($collections) && exists( $collections->{$ccode} ) );
146 if ( defined $itm->{'location'} ) {
147 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
149 foreach (qw(ccode enumchron copynumber itemnotes)) {
150 $itemfields{$_} = 1 if ($itm->{$_});
153 # walk through the item-level authorised values and populate some images
154 my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
155 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
157 if ( $itm->{'itemlost'} ) {
158 my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
159 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
160 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
163 if( $itm->{'count_reserves'}){
164 if( $itm->{'count_reserves'} eq "Waiting"){ $itm->{'waiting'} = 1; }
165 if( $itm->{'count_reserves'} eq "Reserved"){ $itm->{'onhold'} = 1; }
168 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
169 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
170 $itm->{transfertwhen} = format_date($transfertwhen);
171 $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
172 $itm->{transfertto} = $branches->{$transfertto}{branchname};
176 ## get notes and subjects from MARC record
177 my $dbh = C4::Context->dbh;
178 my $marcflavour = C4::Context->preference("marcflavour");
179 my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
180 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
181 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
182 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
183 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
184 my $subtitle = C4::Biblio::get_koha_field_from_marc('bibliosubtitle', 'subtitle', $record, '');
187 MARCNOTES => $marcnotesarray,
188 MARCSUBJCTS => $marcsubjctsarray,
189 MARCAUTHORS => $marcauthorsarray,
190 MARCSERIES => $marcseriesarray,
191 MARCURLS => $marcurlsarray,
192 norequests => $norequests,
193 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
194 itemdata_ccode => $itemfields{ccode},
195 itemdata_enumchron => $itemfields{enumchron},
196 itemdata_copynumber => $itemfields{copynumber},
197 itemdata_itemnotes => $itemfields{itemnotes},
198 authorised_value_images => $biblio_authorised_value_images,
199 subtitle => $subtitle,
202 foreach ( keys %{$dat} ) {
203 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
206 # some useful variables for enhanced content;
207 # in each case, we're grabbing the first value we find in
208 # the record and normalizing it
209 my $upc = GetNormalizedUPC($record,$marcflavour);
210 my $ean = GetNormalizedEAN($record,$marcflavour);
211 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
212 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
213 my $content_identifier_exists = 1 if ($isbn or $ean or $oclc or $upc);
215 normalized_upc => $upc,
216 normalized_ean => $ean,
217 normalized_oclc => $oclc,
218 normalized_isbn => $isbn,
219 content_identifier_exists => $content_identifier_exists,
222 # COinS format FIXME: for books Only
224 my $fmt = substr $record->leader(), 6,2;
226 $fmts->{'am'} = 'book';
227 $coins_format = $fmts->{$fmt};
229 ocoins_format => $coins_format,
232 my $reviews = getreviews( $biblionumber, 1 );
233 my $loggedincommenter;
234 foreach ( @$reviews ) {
235 my $borrowerData = GetMember($_->{borrowernumber},'borrowernumber');
236 # setting some borrower info into this hash
237 $_->{title} = $borrowerData->{'title'};
238 $_->{surname} = $borrowerData->{'surname'};
239 $_->{firstname} = $borrowerData->{'firstname'};
240 $_->{userid} = $borrowerData->{'userid'};
241 $_->{datereviewed} = format_date($_->{datereviewed});
242 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
243 $_->{your_comment} = 1;
244 $loggedincommenter = 1;
249 if(C4::Context->preference("ISBD")) {
250 $template->param(ISBD => 1);
254 ITEM_RESULTS => \@items,
255 subscriptionsnumber => $subscriptionsnumber,
256 biblionumber => $biblionumber,
257 subscriptions => \@subs,
258 subscriptionsnumber => $subscriptionsnumber,
260 loggedincommenter => $loggedincommenter
264 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
267 XISBNS => get_xisbns($isbn)
270 if ($@) { warn "XISBN Failed $@"; }
273 if ( C4::Context->preference("OPACAmazonEnabled") ) {
274 $template->param( AmazonTld => get_amazon_tld() );
275 $template->param( OPACAmazonReviews => C4::Context->preference("OPACAmazonReviews") );
277 if ( C4::Context->preference("OPACAmazonEnabled") && C4::Context->preference("OPACAmazonSimilarItems") ) {
278 my $similar_products_exist;
279 my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour );
280 my $item_attributes = \%{$amazon_details->{Items}->{Item}->{ItemAttributes}};
281 my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
282 for my $one_review (@$customer_reviews) {
283 $one_review->{Date} = format_date($one_review->{Date});
285 my @similar_products;
286 for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
287 # do we have any of these isbns in our collection?
288 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
289 # verify that there is at least one similar item
290 if (scalar(@$similar_biblionumbers)){
291 $similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
292 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
295 my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
296 my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating} || 0;
297 $template->param( OPACAmazonSimilarItems => $similar_products_exist );
298 $template->param( amazon_average_rating => $average_rating * 20);
299 $template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
300 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
301 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
304 my $syndetics_elements;
306 if ( C4::Context->preference("SyndeticsEnabled") ) {
308 $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
309 for my $element (values %$syndetics_elements) {
310 $template->param("Syndetics$element"."Exists" => 1 );
311 #warn "Exists: "."Syndetics$element"."Exists";
317 if ( C4::Context->preference("SyndeticsEnabled")
318 && C4::Context->preference("SyndeticsSummary")
319 && $syndetics_elements->{'SUMMARY'} =~ /SUMMARY/) {
321 my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc);
322 $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
328 if ( C4::Context->preference("SyndeticsEnabled")
329 && C4::Context->preference("SyndeticsTOC")
330 && $syndetics_elements->{'TOC'} =~ /TOC/) {
332 my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
333 $template->param( SYNDETICS_TOC => $syndetics_toc );
338 if ( C4::Context->preference("SyndeticsEnabled")
339 && C4::Context->preference("SyndeticsExcerpt")
340 && $syndetics_elements->{'DBCHAPTER'} =~ /DBCHAPTER/ ) {
342 my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
343 $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
348 if ( C4::Context->preference("SyndeticsEnabled")
349 && C4::Context->preference("SyndeticsReviews")) {
351 my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
352 $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
357 if ( C4::Context->preference("SyndeticsEnabled")
358 && C4::Context->preference("SyndeticsAuthorNotes")
359 && $syndetics_elements->{'ANOTES'} =~ /ANOTES/ ) {
361 my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
362 $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
367 # LibraryThingForLibraries ID Code and Tabbed View Option
368 if( C4::Context->preference('LibraryThingForLibrariesEnabled') )
370 $template->param(LibraryThingForLibrariesID =>
371 C4::Context->preference('LibraryThingForLibrariesID') );
372 $template->param(LibraryThingForLibrariesTabbedView =>
373 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
378 if ( C4::Context->preference("Babeltheque") ) {
384 # Shelf Browser Stuff
385 if (C4::Context->preference("OPACShelfBrowser")) {
386 # pick the first itemnumber unless one was selected by the user
387 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); # || $items[0]->{itemnumber};
388 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
389 # find the right cn_sort value for this item
390 my ($starting_cn_sort, $starting_homebranch, $starting_location);
391 my $sth_get_cn_sort = $dbh->prepare("SELECT cn_sort,homebranch,location from items where itemnumber=?");
392 $sth_get_cn_sort->execute($starting_itemnumber);
393 while (my $result = $sth_get_cn_sort->fetchrow_hashref()) {
394 $starting_cn_sort = $result->{'cn_sort'};
395 $starting_homebranch->{code} = $result->{'homebranch'};
396 $starting_homebranch->{description} = $branches->{$result->{'homebranch'}}{branchname};
397 $starting_location->{code} = $result->{'location'};
398 $starting_location->{description} = GetAuthorisedValueDesc('','', $result->{'location'} ,'','','LOC');
402 ## List of Previous Items
403 # order by cn_sort, which should include everything we need for ordering purposes (though not
404 # for limits, those need to be handled separately
405 my $sth_shelfbrowse_previous = $dbh->prepare("
409 ((cn_sort = ? AND itemnumber < ?) OR cn_sort < ?) AND
410 homebranch = ? AND location = ?
411 ORDER BY cn_sort DESC, itemnumber LIMIT 3
413 $sth_shelfbrowse_previous->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code});
415 while (my $this_item = $sth_shelfbrowse_previous->fetchrow_hashref()) {
416 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=?");
417 $sth_get_biblio->execute($this_item->{biblionumber});
418 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
419 $this_item->{'title'} = $this_biblio->{'title'};
420 my $this_record = GetMarcBiblio($this_biblio->{'biblionumber'});
421 $this_item->{'browser_normalized_upc'} = GetNormalizedUPC($this_record,$marcflavour);
422 $this_item->{'browser_normalized_oclc'} = GetNormalizedOCLCNumber($this_record,$marcflavour);
423 $this_item->{'browser_normalized_isbn'} = GetNormalizedISBN(undef,$this_record,$marcflavour);
425 unshift @previous_items, $this_item;
428 ## List of Next Items; this also intentionally catches the current item
429 my $sth_shelfbrowse_next = $dbh->prepare("
433 ((cn_sort = ? AND itemnumber >= ?) OR cn_sort > ?) AND
434 homebranch = ? AND location = ?
435 ORDER BY cn_sort, itemnumber LIMIT 3
437 $sth_shelfbrowse_next->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code});
439 while (my $this_item = $sth_shelfbrowse_next->fetchrow_hashref()) {
440 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=?");
441 $sth_get_biblio->execute($this_item->{biblionumber});
442 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
443 $this_item->{'title'} = $this_biblio->{'title'};
444 my $this_record = GetMarcBiblio($this_biblio->{'biblionumber'});
445 $this_item->{'browser_normalized_upc'} = GetNormalizedUPC($this_record,$marcflavour);
446 $this_item->{'browser_normalized_oclc'} = GetNormalizedOCLCNumber($this_record,$marcflavour);
447 $this_item->{'browser_normalized_isbn'} = GetNormalizedISBN(undef,$this_record,$marcflavour);
449 push @next_items, $this_item;
452 # alas, these won't auto-vivify, see http://www.perlmonks.org/?node_id=508481
453 my $shelfbrowser_next_itemnumber = $next_items[-1]->{itemnumber} if @next_items;
454 my $shelfbrowser_next_biblionumber = $next_items[-1]->{biblionumber} if @next_items;
457 starting_homebranch => $starting_homebranch->{description},
458 starting_location => $starting_location->{description},
459 starting_itemnumber => $starting_itemnumber,
460 shelfbrowser_prev_itemnumber => (@previous_items ? $previous_items[0]->{itemnumber} : 0),
461 shelfbrowser_next_itemnumber => $shelfbrowser_next_itemnumber,
462 shelfbrowser_prev_biblionumber => (@previous_items ? $previous_items[0]->{biblionumber} : 0),
463 shelfbrowser_next_biblionumber => $shelfbrowser_next_biblionumber,
464 PREVIOUS_SHELF_BROWSE => \@previous_items,
465 NEXT_SHELF_BROWSE => \@next_items,
469 if (C4::Context->preference("BakerTaylorEnabled")) {
471 BakerTaylorEnabled => 1,
472 BakerTaylorImageURL => &image_url(),
473 BakerTaylorLinkURL => &link_url(),
474 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
476 my ($bt_user, $bt_pass);
478 $bt_user = C4::Context->preference('BakerTaylorUsername') and
479 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
482 BakerTaylorContentURL =>
483 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
484 $bt_user,$bt_pass,$isbn)
490 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
493 TagsShowOnDetail => $tag_quantity,
494 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
496 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
497 'sort'=>'-weight', limit=>$tag_quantity}));
500 output_html_with_http_headers $query, $cookie, $template->output;