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
27 use C4::Serials; #uses getsubscriptionfrom biblionumber
32 use C4::Tags qw(get_tags);
33 use C4::Dates qw/format_date/;
34 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn);
35 use C4::External::Amazon;
36 use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes );
43 if (C4::Context->preference('BakerTaylorEnabled')) {
44 require C4::External::BakerTaylor;
45 import C4::External::BakerTaylor qw(&image_url &link_url);
50 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
52 template_name => "opac-detail.tmpl",
56 flagsrequired => { borrow => 1 },
60 my $biblionumber = $query->param('biblionumber') || $query->param('bib');
61 my $record = GetMarcBiblio($biblionumber);
62 $template->param( biblionumber => $biblionumber );
63 # XSLT processing of some stuff
64 if (C4::Context->preference("XSLTDetailsDisplay") ) {
65 my $newxmlrecord = XSLTParse4Display($biblionumber, $record, C4::Context->config('opachtdocs')."/prog/en/xslt/MARC21slim2OPACDetail.xsl");
66 $template->param('XSLTBloc' => $newxmlrecord);
69 # change back when ive fixed request.pl
70 my @all_items = &GetItemsInfo( $biblionumber, 'opac' );
72 @items = @all_items unless C4::Context->preference('hidelostitems');
74 if (C4::Context->preference('hidelostitems')) {
76 for my $itm (@all_items) {
77 push @items, $itm unless $itm->{itemlost};
80 my $dat = &GetBiblioData($biblionumber);
83 print $query->redirect("/cgi-bin/koha/errors/404.pl");
86 my $itemtypes = GetItemTypes();
88 my $itemtype = $dat->{'itemtype'};
90 $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
91 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
93 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'});
94 my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'} );
96 #coping with subscriptions
97 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
98 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
101 $dat->{'serial'}=1 if $subscriptionsnumber;
102 foreach my $subscription (@subscriptions) {
103 my $serials_to_display;
105 $cell{subscriptionid} = $subscription->{subscriptionid};
106 $cell{subscriptionnotes} = $subscription->{notes};
107 $cell{branchcode} = $subscription->{branchcode};
108 $cell{hasalert} = $subscription->{hasalert};
109 #get the three latest serials.
110 $serials_to_display = $subscription->{opacdisplaycount};
111 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
112 $cell{opacdisplaycount} = $serials_to_display;
113 $cell{latestserials} =
114 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
118 $dat->{'count'} = scalar(@items);
120 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) );
123 my $branches = GetBranches();
125 for my $itm (@items) {
127 if ( (not $itm->{'wthdrawn'} )
128 && (not $itm->{'itemlost'} )
129 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
130 && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
131 && ($itm->{'itemnumber'} ) );
133 $itm->{ $itm->{'publictype'} } = 1;
134 $itm->{datedue} = format_date($itm->{datedue});
135 $itm->{datelastseen} = format_date($itm->{datelastseen});
137 #get collection code description, too
138 my $ccode= $itm->{'ccode'};
139 $itm->{'ccode'} = $collections->{$ccode} if(defined($collections) && exists($collections->{$ccode}));
140 $itm->{'location_description'} = $shelflocations->{$itm->{'location'} };
141 $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
142 $itm->{'description'} = $itemtypes->{$itemtype}->{'description'};
143 foreach (qw(ccode enumchron copynumber itemnotes)) {
144 $itemfields{$_} = 1 if ($itm->{$_});
147 # walk through the item-level authorised values and populate some images
148 my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
149 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
151 if ( $itm->{'itemlost'} ) {
152 my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
153 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
154 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
158 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
159 if ( $transfertwhen ne '' ) {
160 $itm->{transfertwhen} = format_date($transfertwhen);
161 $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
162 $itm->{transfertto} = $branches->{$transfertto}{branchname};
166 ## get notes and subjects from MARC record
167 my $dbh = C4::Context->dbh;
168 my $marcflavour = C4::Context->preference("marcflavour");
169 my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
170 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
171 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
172 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
173 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
174 my $subtitle = C4::Biblio::get_koha_field_from_marc('bibliosubtitle', 'subtitle', $record, '');
177 MARCNOTES => $marcnotesarray,
178 MARCSUBJCTS => $marcsubjctsarray,
179 MARCAUTHORS => $marcauthorsarray,
180 MARCSERIES => $marcseriesarray,
181 MARCURLS => $marcurlsarray,
182 norequests => $norequests,
183 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
184 itemdata_ccode => $itemfields{ccode},
185 itemdata_enumchron => $itemfields{enumchron},
186 itemdata_copynumber => $itemfields{copynumber},
187 itemdata_itemnotes => $itemfields{itemnotes},
188 authorised_value_images => $biblio_authorised_value_images,
189 subtitle => $subtitle,
192 foreach ( keys %{$dat} ) {
193 $template->param( "$_" => $dat->{$_} . "" );
196 # some useful variables for enhanced content;
197 # in each case, we're grabbing the first value we find in
198 # the record and normalizing it
199 my $upc = GetNormalizedUPC($record,$marcflavour);
200 my $ean = GetNormalizedEAN($record,$marcflavour);
201 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
202 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
203 my $content_identifier_exists = 1 if ($isbn or $ean or $oclc or $upc);
205 normalized_upc => $upc,
206 normalized_ean => $ean,
207 normalized_oclc => $oclc,
208 normalized_isbn => $isbn,
209 content_identifier_exists => $content_identifier_exists,
212 # COinS format FIXME: for books Only
214 my $fmt = substr $record->leader(), 6,2;
216 $fmts->{'am'} = 'book';
217 $coins_format = $fmts->{$fmt};
219 ocoins_format => $coins_format,
222 my $reviews = getreviews( $biblionumber, 1 );
223 my $loggedincommenter;
224 foreach ( @$reviews ) {
225 my $borrowerData = GetMember($_->{borrowernumber},'borrowernumber');
226 # setting some borrower info into this hash
227 $_->{title} = $borrowerData->{'title'};
228 $_->{surname} = $borrowerData->{'surname'};
229 $_->{firstname} = $borrowerData->{'firstname'};
230 $_->{userid} = $borrowerData->{'userid'};
231 $_->{datereviewed} = format_date($_->{datereviewed});
232 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
233 $_->{your_comment} = 1;
234 $loggedincommenter = 1;
239 if(C4::Context->preference("ISBD")) {
240 $template->param(ISBD => 1);
244 ITEM_RESULTS => \@items,
245 subscriptionsnumber => $subscriptionsnumber,
246 biblionumber => $biblionumber,
247 subscriptions => \@subs,
248 subscriptionsnumber => $subscriptionsnumber,
250 loggedincommenter => $loggedincommenter
254 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
257 XISBNS => get_xisbns($isbn)
260 if ($@) { warn "XISBN Failed $@"; }
263 if ( C4::Context->preference("OPACAmazonEnabled") ) {
264 $template->param( AmazonTld => get_amazon_tld() );
266 if ( C4::Context->preference("OPACAmazonEnabled") && C4::Context->preference("OPACAmazonSimilarItems") ) {
267 my $similar_products_exist;
268 my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour );
269 my $item_attributes = \%{$amazon_details->{Items}->{Item}->{ItemAttributes}};
270 my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
271 for my $one_review (@$customer_reviews) {
272 $one_review->{Date} = format_date($one_review->{Date});
274 my @similar_products;
275 for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
276 # do we have any of these isbns in our collection?
277 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
278 # verify that there is at least one similar item
279 if (scalar(@$similar_biblionumbers)){
280 $similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
281 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
284 my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
285 my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating};
286 $template->param( OPACAmazonSimilarItems => $similar_products_exist );
287 $template->param( amazon_average_rating => $average_rating * 20);
288 $template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
289 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
290 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
293 my $syndetics_elements;
295 if ( C4::Context->preference("SyndeticsEnabled") ) {
297 $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
298 for my $element (values %$syndetics_elements) {
299 $template->param("Syndetics$element"."Exists" => 1 );
300 #warn "Exists: "."Syndetics$element"."Exists";
306 if ( C4::Context->preference("SyndeticsEnabled")
307 && C4::Context->preference("SyndeticsSummary")
308 && $syndetics_elements->{'SUMMARY'} =~ /SUMMARY/) {
310 my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc);
311 $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
317 if ( C4::Context->preference("SyndeticsEnabled")
318 && C4::Context->preference("SyndeticsTOC")
319 && $syndetics_elements->{'TOC'} =~ /TOC/) {
321 my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
322 $template->param( SYNDETICS_TOC => $syndetics_toc );
327 if ( C4::Context->preference("SyndeticsEnabled")
328 && C4::Context->preference("SyndeticsExcerpt")
329 && $syndetics_elements->{'DBCHAPTER'} =~ /DBCHAPTER/ ) {
331 my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
332 $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
337 if ( C4::Context->preference("SyndeticsEnabled")
338 && C4::Context->preference("SyndeticsReviews")) {
340 my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
341 $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
346 if ( C4::Context->preference("SyndeticsEnabled")
347 && C4::Context->preference("SyndeticsAuthorNotes")
348 && $syndetics_elements->{'ANOTES'} =~ /ANOTES/ ) {
350 my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
351 $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
357 if ( C4::Context->preference("Babeltheque") ) {
363 # Shelf Browser Stuff
364 if (C4::Context->preference("OPACShelfBrowser")) {
365 # pick the first itemnumber unless one was selected by the user
366 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); # || $items[0]->{itemnumber};
367 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
368 # find the right cn_sort value for this item
369 my ($starting_cn_sort, $starting_homebranch, $starting_location);
370 my $sth_get_cn_sort = $dbh->prepare("SELECT cn_sort,homebranch,location from items where itemnumber=?");
371 $sth_get_cn_sort->execute($starting_itemnumber);
372 while (my $result = $sth_get_cn_sort->fetchrow_hashref()) {
373 $starting_cn_sort = $result->{'cn_sort'};
374 $starting_homebranch->{code} = $result->{'homebranch'};
375 $starting_homebranch->{description} = $branches->{$result->{'homebranch'}}{branchname};
376 $starting_location->{code} = $result->{'location'};
377 $starting_location->{description} = GetAuthorisedValueDesc('','', $result->{'location'} ,'','','LOC');
381 ## List of Previous Items
382 # order by cn_sort, which should include everything we need for ordering purposes (though not
383 # for limits, those need to be handled separately
384 my $sth_shelfbrowse_previous = $dbh->prepare("
388 ((cn_sort = ? AND itemnumber < ?) OR cn_sort < ?) AND
389 homebranch = ? AND location = ?
390 ORDER BY cn_sort DESC, itemnumber LIMIT 3
392 $sth_shelfbrowse_previous->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code});
394 while (my $this_item = $sth_shelfbrowse_previous->fetchrow_hashref()) {
395 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=?");
396 $sth_get_biblio->execute($this_item->{biblionumber});
397 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
398 $this_item->{'title'} = $this_biblio->{'title'};
399 my $this_record = GetMarcBiblio($this_biblio->{'biblionumber'});
400 $this_item->{'browser_normalized_upc'} = GetNormalizedUPC($this_record,$marcflavour);
401 $this_item->{'browser_normalized_oclc'} = GetNormalizedOCLCNumber($this_record,$marcflavour);
402 $this_item->{'browser_normalized_isbn'} = GetNormalizedISBN(undef,$this_record,$marcflavour);
404 unshift @previous_items, $this_item;
407 ## List of Next Items; this also intentionally catches the current item
408 my $sth_shelfbrowse_next = $dbh->prepare("
412 ((cn_sort = ? AND itemnumber >= ?) OR cn_sort > ?) AND
413 homebranch = ? AND location = ?
414 ORDER BY cn_sort, itemnumber LIMIT 3
416 $sth_shelfbrowse_next->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code});
418 while (my $this_item = $sth_shelfbrowse_next->fetchrow_hashref()) {
419 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=?");
420 $sth_get_biblio->execute($this_item->{biblionumber});
421 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
422 $this_item->{'title'} = $this_biblio->{'title'};
423 my $this_record = GetMarcBiblio($this_biblio->{'biblionumber'});
424 $this_item->{'browser_normalized_upc'} = GetNormalizedUPC($this_record,$marcflavour);
425 $this_item->{'browser_normalized_oclc'} = GetNormalizedOCLCNumber($this_record,$marcflavour);
426 $this_item->{'browser_normalized_isbn'} = GetNormalizedISBN(undef,$this_record,$marcflavour);
428 push @next_items, $this_item;
431 # alas, these won't auto-vivify, see http://www.perlmonks.org/?node_id=508481
432 my $shelfbrowser_next_itemnumber = $next_items[-1]->{itemnumber} if @next_items;
433 my $shelfbrowser_next_biblionumber = $next_items[-1]->{biblionumber} if @next_items;
436 starting_homebranch => $starting_homebranch->{description},
437 starting_location => $starting_location->{description},
438 starting_itemnumber => $starting_itemnumber,
439 shelfbrowser_prev_itemnumber => (@previous_items ? $previous_items[0]->{itemnumber} : 0),
440 shelfbrowser_next_itemnumber => $shelfbrowser_next_itemnumber,
441 shelfbrowser_prev_biblionumber => (@previous_items ? $previous_items[0]->{biblionumber} : 0),
442 shelfbrowser_next_biblionumber => $shelfbrowser_next_biblionumber,
443 PREVIOUS_SHELF_BROWSE => \@previous_items,
444 NEXT_SHELF_BROWSE => \@next_items,
448 if (C4::Context->preference("BakerTaylorEnabled")) {
450 BakerTaylorEnabled => 1,
451 BakerTaylorImageURL => &image_url(),
452 BakerTaylorLinkURL => &link_url(),
453 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
455 my ($bt_user, $bt_pass);
457 $bt_user = C4::Context->preference('BakerTaylorUsername') and
458 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
461 BakerTaylorContentURL =>
462 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
463 $bt_user,$bt_pass,$isbn)
469 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
472 TagsShowOnDetail => $tag_quantity,
473 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
475 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
476 'sort'=>'-weight', limit=>$tag_quantity}));
479 output_html_with_http_headers $query, $cookie, $template->output;