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 get_biblio_from_xisbn);
35 use C4::External::Amazon;
36 use C4::External::Syndetics qw(get_syndetics_summary get_syndetics_toc get_syndetics_excerpt );
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 );
100 $dat->{'serial'}=1 if $subscriptionsnumber;
101 foreach my $subscription (@subscriptions) {
103 $cell{subscriptionid} = $subscription->{subscriptionid};
104 $cell{subscriptionnotes} = $subscription->{notes};
105 $cell{branchcode} = $subscription->{branchcode};
106 $cell{hasalert} = $subscription->{hasalert};
107 #get the three latest serials.
108 $cell{latestserials} =
109 GetLatestSerials( $subscription->{subscriptionid}, 3 );
113 $dat->{'count'} = scalar(@items);
115 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) );
118 my $branches = GetBranches();
120 for my $itm (@items) {
122 if ( (not $itm->{'wthdrawn'} )
123 && (not $itm->{'itemlost'} )
124 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
125 && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
126 && ($itm->{'itemnumber'} ) );
128 $itm->{ $itm->{'publictype'} } = 1;
129 $itm->{datedue} = format_date($itm->{datedue});
130 $itm->{datelastseen} = format_date($itm->{datelastseen});
132 #get collection code description, too
133 my $ccode= $itm->{'ccode'};
134 $itm->{'ccode'} = $collections->{$ccode} if(defined($collections) && exists($collections->{$ccode}));
135 $itm->{'location_description'} = $shelflocations->{$itm->{'location'} };
136 $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
137 $itm->{'description'} = $itemtypes->{$itemtype}->{'description'};
138 foreach (qw(ccode enumchron copynumber itemnotes)) {
139 $itemfields{$_} = 1 if ($itm->{$_});
142 # walk through the item-level authorised values and populate some images
143 my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
144 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
146 if ( $itm->{'itemlost'} ) {
147 my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
148 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
149 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
153 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
154 if ( $transfertwhen ne '' ) {
155 $itm->{transfertwhen} = format_date($transfertwhen);
156 $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
157 $itm->{transfertto} = $branches->{$transfertto}{branchname};
161 ## get notes and subjects from MARC record
162 my $dbh = C4::Context->dbh;
163 my $marcflavour = C4::Context->preference("marcflavour");
164 my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
165 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
166 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
167 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
168 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
169 my $subtitle = C4::Biblio::get_koha_field_from_marc('bibliosubtitle', 'subtitle', $record, '');
172 MARCNOTES => $marcnotesarray,
173 MARCSUBJCTS => $marcsubjctsarray,
174 MARCAUTHORS => $marcauthorsarray,
175 MARCSERIES => $marcseriesarray,
176 MARCURLS => $marcurlsarray,
177 norequests => $norequests,
178 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
179 itemdata_ccode => $itemfields{ccode},
180 itemdata_enumchron => $itemfields{enumchron},
181 itemdata_copynumber => $itemfields{copynumber},
182 itemdata_itemnotes => $itemfields{itemnotes},
183 authorised_value_images => $biblio_authorised_value_images,
184 subtitle => $subtitle,
187 foreach ( keys %{$dat} ) {
188 $template->param( "$_" => $dat->{$_} . "" );
191 # COinS format FIXME: for books Only
193 my $fmt = substr $record->leader(), 6,2;
195 $fmts->{'am'} = 'book';
196 $coins_format = $fmts->{$fmt};
198 ocoins_format => $coins_format,
201 my $reviews = getreviews( $biblionumber, 1 );
202 my $loggedincommenter;
203 foreach ( @$reviews ) {
204 my $borrowerData = GetMember($_->{borrowernumber},'borrowernumber');
205 # setting some borrower info into this hash
206 $_->{title} = $borrowerData->{'title'};
207 $_->{surname} = $borrowerData->{'surname'};
208 $_->{firstname} = $borrowerData->{'firstname'};
209 $_->{userid} = $borrowerData->{'userid'};
210 $_->{datereviewed} = format_date($_->{datereviewed});
211 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
212 $_->{your_comment} = 1;
213 $loggedincommenter = 1;
218 if(C4::Context->preference("ISBD")) {
219 $template->param(ISBD => 1);
223 ITEM_RESULTS => \@items,
224 subscriptionsnumber => $subscriptionsnumber,
225 biblionumber => $biblionumber,
226 subscriptions => \@subs,
227 subscriptionsnumber => $subscriptionsnumber,
229 loggedincommenter => $loggedincommenter
232 sub isbn_cleanup ($) {
234 ($isbn) = $isbn =~ /([\d-]*[X]*)/;
237 $isbn =~ /\b(\d{13})\b/ or
238 $isbn =~ /\b(\d{10})\b/ or
239 $isbn =~ /\b(\d{9}X)\b/i
247 my $xisbn=$dat->{'isbn'};
248 (my $aisbn) = $xisbn =~ /([\d-]*[X]*)/;
250 $template->param(amazonisbn => $aisbn); # FIXME: so it is OK if the ISBN = 'XXXXX' ?
252 # these might be overkill, but they are better than the regexp above.
253 if ($clean = isbn_cleanup($xisbn)){
254 $template->param(clean_isbn => $clean);
257 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
261 XISBNS => get_xisbns($xisbn)
264 if ($@) { warn "XISBN Failed $@"; }
267 if ( C4::Context->preference("OPACAmazonContent") == 1 ) {
268 my $similar_products_exist;
269 my $amazon_details = &get_amazon_details( $xisbn, $record, $marcflavour );
270 my $item_attributes = \%{$amazon_details->{Items}->{Item}->{ItemAttributes}};
271 my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
272 for my $one_review (@$customer_reviews) {
273 $one_review->{Date} = format_date($one_review->{Date});
275 my @similar_products;
276 for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
277 # do we have any of these isbns in our collection?
278 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
279 # verify that there is at least one similar item
280 if (scalar(@$similar_biblionumbers)){
281 $similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
282 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
285 my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
286 my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating};
287 $template->param( OPACAmazonSimilarItems => $similar_products_exist );
288 $template->param( amazon_average_rating => $average_rating * 20);
289 $template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
290 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
291 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
294 if ( C4::Context->preference("SyndeticsEnabled") && C4::Context->preference("SyndeticsSummary") ) {
296 my $syndetics_summary = &get_syndetics_summary($xisbn);
297 $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
301 if ( C4::Context->preference("SyndeticsEnabled") && C4::Context->preference("SyndeticsTOC") ) {
303 my $syndetics_toc = &get_syndetics_toc($xisbn);
304 $template->param( SYNDETICS_TOC => $syndetics_toc );
308 if ( C4::Context->preference("SyndeticsEnabled") && C4::Context->preference("SyndeticsTOC") ) {
310 my $syndetics_excerpt = &get_syndetics_excerpt($xisbn);
311 $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
315 # Shelf Browser Stuff
316 if (C4::Context->preference("OPACShelfBrowser")) {
317 # pick the first itemnumber unless one was selected by the user
318 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); # || $items[0]->{itemnumber};
319 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
320 # find the right cn_sort value for this item
321 my ($starting_cn_sort, $starting_homebranch, $starting_location);
322 my $sth_get_cn_sort = $dbh->prepare("SELECT cn_sort,homebranch,location from items where itemnumber=?");
323 $sth_get_cn_sort->execute($starting_itemnumber);
324 while (my $result = $sth_get_cn_sort->fetchrow_hashref()) {
325 $starting_cn_sort = $result->{'cn_sort'};
326 $starting_homebranch->{code} = $result->{'homebranch'};
327 $starting_homebranch->{description} = $branches->{$result->{'homebranch'}}{branchname};
328 $starting_location->{code} = $result->{'location'};
329 $starting_location->{description} = GetAuthorisedValueDesc('','', $result->{'location'} ,'','','LOC');
333 ## List of Previous Items
334 # order by cn_sort, which should include everything we need for ordering purposes (though not
335 # for limits, those need to be handled separately
336 my $sth_shelfbrowse_previous = $dbh->prepare("
340 ((cn_sort = ? AND itemnumber < ?) OR cn_sort < ?) AND
341 homebranch = ? AND location = ?
342 ORDER BY cn_sort DESC, itemnumber LIMIT 3
344 $sth_shelfbrowse_previous->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code});
346 while (my $this_item = $sth_shelfbrowse_previous->fetchrow_hashref()) {
347 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=?");
348 $sth_get_biblio->execute($this_item->{biblionumber});
349 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
350 $this_item->{'title'} = $this_biblio->{'title'};
351 if ($clean2 = isbn_cleanup($this_biblio->{'isbn'})) {
352 $this_item->{'isbn'} = $clean2;
354 $this_item->{'isbn'} = $this_biblio->{'isbn'};
357 unshift @previous_items, $this_item;
360 ## List of Next Items; this also intentionally catches the current item
361 my $sth_shelfbrowse_next = $dbh->prepare("
365 ((cn_sort = ? AND itemnumber >= ?) OR cn_sort > ?) AND
366 homebranch = ? AND location = ?
367 ORDER BY cn_sort, itemnumber LIMIT 3
369 $sth_shelfbrowse_next->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code});
371 while (my $this_item = $sth_shelfbrowse_next->fetchrow_hashref()) {
372 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=?");
373 $sth_get_biblio->execute($this_item->{biblionumber});
374 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
375 $this_item->{'title'} = $this_biblio->{'title'};
376 if ($clean2 = isbn_cleanup($this_biblio->{'isbn'})) {
377 $this_item->{'isbn'} = $clean2;
379 $this_item->{'isbn'} = $this_biblio->{'isbn'};
382 push @next_items, $this_item;
385 # alas, these won't auto-vivify, see http://www.perlmonks.org/?node_id=508481
386 my $shelfbrowser_next_itemnumber = $next_items[-1]->{itemnumber} if @next_items;
387 my $shelfbrowser_next_biblionumber = $next_items[-1]->{biblionumber} if @next_items;
390 starting_homebranch => $starting_homebranch->{description},
391 starting_location => $starting_location->{description},
392 starting_itemnumber => $starting_itemnumber,
393 shelfbrowser_prev_itemnumber => (@previous_items ? $previous_items[0]->{itemnumber} : 0),
394 shelfbrowser_next_itemnumber => $shelfbrowser_next_itemnumber,
395 shelfbrowser_prev_biblionumber => (@previous_items ? $previous_items[0]->{biblionumber} : 0),
396 shelfbrowser_next_biblionumber => $shelfbrowser_next_biblionumber,
397 PREVIOUS_SHELF_BROWSE => \@previous_items,
398 NEXT_SHELF_BROWSE => \@next_items,
402 if (C4::Context->preference("BakerTaylorEnabled")) {
404 BakerTaylorEnabled => 1,
405 BakerTaylorImageURL => &image_url(),
406 BakerTaylorLinkURL => &link_url(),
407 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
409 my ($bt_user, $bt_pass);
411 $bt_user = C4::Context->preference('BakerTaylorUsername') and
412 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
415 BakerTaylorContentURL =>
416 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
417 $bt_user,$bt_pass,$clean)
423 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
426 TagsShowOnDetail => $tag_quantity,
427 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
429 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
430 'sort'=>'-weight', limit=>$tag_quantity}));
433 output_html_with_http_headers $query, $cookie, $template->output;