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 get_biblio_from_xisbn);
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 if ( defined $itm->{'publictype'} ) {
129 # I can't actually find any case in which this is defined. --amoore 2008-12-09
130 $itm->{ $itm->{'publictype'} } = 1;
132 $itm->{datedue} = format_date($itm->{datedue});
133 $itm->{datelastseen} = format_date($itm->{datelastseen});
135 # get collection code description, too
136 if ( my $ccode = $itm->{'ccode'} ) {
137 $itm->{'ccode'} = $collections->{$ccode} if ( defined($collections) && exists( $collections->{$ccode} ) );
139 if ( defined $itm->{'location'} ) {
140 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
142 foreach (qw(ccode enumchron copynumber itemnotes)) {
143 $itemfields{$_} = 1 if ($itm->{$_});
146 # walk through the item-level authorised values and populate some images
147 my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
148 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
150 if ( $itm->{'itemlost'} ) {
151 my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
152 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
153 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
156 if( $itm->{'count_reserves'}){
157 if( $itm->{'count_reserves'} eq "Waiting"){ $itm->{'waiting'} = 1; }
158 if( $itm->{'count_reserves'} eq "Reserved"){ $itm->{'onhold'} = 1; }
161 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
162 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
163 $itm->{transfertwhen} = format_date($transfertwhen);
164 $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
165 $itm->{transfertto} = $branches->{$transfertto}{branchname};
169 ## get notes and subjects from MARC record
170 my $dbh = C4::Context->dbh;
171 my $marcflavour = C4::Context->preference("marcflavour");
172 my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
173 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
174 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
175 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
176 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
177 my $subtitle = C4::Biblio::get_koha_field_from_marc('bibliosubtitle', 'subtitle', $record, '');
180 MARCNOTES => $marcnotesarray,
181 MARCSUBJCTS => $marcsubjctsarray,
182 MARCAUTHORS => $marcauthorsarray,
183 MARCSERIES => $marcseriesarray,
184 MARCURLS => $marcurlsarray,
185 norequests => $norequests,
186 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
187 itemdata_ccode => $itemfields{ccode},
188 itemdata_enumchron => $itemfields{enumchron},
189 itemdata_copynumber => $itemfields{copynumber},
190 itemdata_itemnotes => $itemfields{itemnotes},
191 authorised_value_images => $biblio_authorised_value_images,
192 subtitle => $subtitle,
195 foreach ( keys %{$dat} ) {
196 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
199 # COinS format FIXME: for books Only
201 ocoins => GetCOinSBiblio($biblionumber),
204 my $reviews = getreviews( $biblionumber, 1 );
205 my $loggedincommenter;
206 foreach ( @$reviews ) {
207 my $borrowerData = GetMember($_->{borrowernumber},'borrowernumber');
208 # setting some borrower info into this hash
209 $_->{title} = $borrowerData->{'title'};
210 $_->{surname} = $borrowerData->{'surname'};
211 $_->{firstname} = $borrowerData->{'firstname'};
212 $_->{userid} = $borrowerData->{'userid'};
213 $_->{datereviewed} = format_date($_->{datereviewed});
214 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
215 $_->{your_comment} = 1;
216 $loggedincommenter = 1;
221 if(C4::Context->preference("ISBD")) {
222 $template->param(ISBD => 1);
226 ITEM_RESULTS => \@items,
227 subscriptionsnumber => $subscriptionsnumber,
228 biblionumber => $biblionumber,
229 subscriptions => \@subs,
230 subscriptionsnumber => $subscriptionsnumber,
232 loggedincommenter => $loggedincommenter
235 sub isbn_cleanup ($) {
237 ($isbn) = $isbn =~ /([\d-]*[X]*)/;
240 $isbn =~ /\b(\d{13})\b/ or
241 $isbn =~ /\b(\d{10})\b/ or
242 $isbn =~ /\b(\d{9}X)\b/i
250 my $xisbn=$dat->{'isbn'};
251 (my $aisbn) = $xisbn =~ /([\d-]*[X]*)/;
253 $template->param(amazonisbn => $aisbn); # FIXME: so it is OK if the ISBN = 'XXXXX' ?
255 # these might be overkill, but they are better than the regexp above.
256 if ($clean = isbn_cleanup($xisbn)){
257 $template->param(clean_isbn => $clean);
260 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
264 XISBNS => get_xisbns($xisbn)
267 if ($@) { warn "XISBN Failed $@"; }
270 if ( C4::Context->preference("OPACAmazonEnabled") ) {
271 $template->param( AmazonTld => get_amazon_tld() );
273 if ( C4::Context->preference("OPACAmazonEnabled") && C4::Context->preference("OPACAmazonSimilarItems") ) {
274 my $similar_products_exist;
275 my $amazon_details = &get_amazon_details( $xisbn, $record, $marcflavour );
276 my $item_attributes = \%{$amazon_details->{Items}->{Item}->{ItemAttributes}};
277 my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
278 for my $one_review (@$customer_reviews) {
279 $one_review->{Date} = format_date($one_review->{Date});
281 my @similar_products;
282 for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
283 # do we have any of these isbns in our collection?
284 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
285 # verify that there is at least one similar item
286 if (scalar(@$similar_biblionumbers)){
287 $similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
288 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
291 my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
292 my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating} || 0;
293 $template->param( OPACAmazonSimilarItems => $similar_products_exist );
294 $template->param( amazon_average_rating => $average_rating * 20);
295 $template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
296 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
297 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
299 # Shelf Browser Stuff
300 if (C4::Context->preference("OPACShelfBrowser")) {
301 # pick the first itemnumber unless one was selected by the user
302 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); # || $items[0]->{itemnumber};
303 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
304 # find the right cn_sort value for this item
305 my ($starting_cn_sort, $starting_homebranch, $starting_location);
306 my $sth_get_cn_sort = $dbh->prepare("SELECT cn_sort,homebranch,location from items where itemnumber=?");
307 $sth_get_cn_sort->execute($starting_itemnumber);
308 while (my $result = $sth_get_cn_sort->fetchrow_hashref()) {
309 $starting_cn_sort = $result->{'cn_sort'};
310 $starting_homebranch->{code} = $result->{'homebranch'};
311 $starting_homebranch->{description} = $branches->{$result->{'homebranch'}}{branchname};
312 $starting_location->{code} = $result->{'location'};
313 $starting_location->{description} = GetAuthorisedValueDesc('','', $result->{'location'} ,'','','LOC');
317 ## List of Previous Items
318 # order by cn_sort, which should include everything we need for ordering purposes (though not
319 # for limits, those need to be handled separately
320 my $sth_shelfbrowse_previous = $dbh->prepare("
324 ((cn_sort = ? AND itemnumber < ?) OR cn_sort < ?) AND
325 homebranch = ? AND location = ?
326 ORDER BY cn_sort DESC, itemnumber LIMIT 3
328 $sth_shelfbrowse_previous->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code});
330 while (my $this_item = $sth_shelfbrowse_previous->fetchrow_hashref()) {
331 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=?");
332 $sth_get_biblio->execute($this_item->{biblionumber});
333 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
334 $this_item->{'title'} = $this_biblio->{'title'};
335 if ($clean2 = isbn_cleanup($this_biblio->{'isbn'})) {
336 $this_item->{'isbn'} = $clean2;
338 $this_item->{'isbn'} = $this_biblio->{'isbn'};
341 unshift @previous_items, $this_item;
344 ## List of Next Items; this also intentionally catches the current item
345 my $sth_shelfbrowse_next = $dbh->prepare("
349 ((cn_sort = ? AND itemnumber >= ?) OR cn_sort > ?) AND
350 homebranch = ? AND location = ?
351 ORDER BY cn_sort, itemnumber LIMIT 3
353 $sth_shelfbrowse_next->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code});
355 while (my $this_item = $sth_shelfbrowse_next->fetchrow_hashref()) {
356 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=?");
357 $sth_get_biblio->execute($this_item->{biblionumber});
358 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
359 $this_item->{'title'} = $this_biblio->{'title'};
360 if ($clean2 = isbn_cleanup($this_biblio->{'isbn'})) {
361 $this_item->{'isbn'} = $clean2;
363 $this_item->{'isbn'} = $this_biblio->{'isbn'};
366 push @next_items, $this_item;
369 # alas, these won't auto-vivify, see http://www.perlmonks.org/?node_id=508481
370 my $shelfbrowser_next_itemnumber = $next_items[-1]->{itemnumber} if @next_items;
371 my $shelfbrowser_next_biblionumber = $next_items[-1]->{biblionumber} if @next_items;
374 starting_homebranch => $starting_homebranch->{description},
375 starting_location => $starting_location->{description},
376 starting_itemnumber => $starting_itemnumber,
377 shelfbrowser_prev_itemnumber => (@previous_items ? $previous_items[0]->{itemnumber} : 0),
378 shelfbrowser_next_itemnumber => $shelfbrowser_next_itemnumber,
379 shelfbrowser_prev_biblionumber => (@previous_items ? $previous_items[0]->{biblionumber} : 0),
380 shelfbrowser_next_biblionumber => $shelfbrowser_next_biblionumber,
381 PREVIOUS_SHELF_BROWSE => \@previous_items,
382 NEXT_SHELF_BROWSE => \@next_items,
386 if (C4::Context->preference("BakerTaylorEnabled")) {
388 BakerTaylorEnabled => 1,
389 BakerTaylorImageURL => &image_url(),
390 BakerTaylorLinkURL => &link_url(),
391 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
393 my ($bt_user, $bt_pass);
395 $bt_user = C4::Context->preference('BakerTaylorUsername') and
396 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
399 BakerTaylorContentURL =>
400 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
401 $bt_user,$bt_pass,$clean)
407 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
410 TagsShowOnDetail => $tag_quantity,
411 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
413 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
414 'sort'=>'-weight', limit=>$tag_quantity}));
417 output_html_with_http_headers $query, $cookie, $template->output;