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);
42 if (C4::Context->preference('BakerTaylorEnabled')) {
43 require C4::External::BakerTaylor;
44 import C4::External::BakerTaylor qw(&image_url &link_url);
49 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
51 template_name => "opac-detail.tmpl",
55 flagsrequired => { borrow => 1 },
59 my $biblionumber = $query->param('biblionumber') || $query->param('bib');
60 $template->param( biblionumber => $biblionumber );
61 # XSLT processing of some stuff
62 if (C4::Context->preference("XSLTDetailsDisplay") ) {
63 my $newxmlrecord = XSLTParse4Display($biblionumber,C4::Context->config('opachtdocs')."/prog/en/xslt/MARC21slim2OPACDetail.xsl");
64 $template->param('XSLTBloc' => $newxmlrecord);
67 # change back when ive fixed request.pl
68 my @all_items = &GetItemsInfo( $biblionumber, 'opac' );
70 @items = @all_items unless C4::Context->preference('hidelostitems');
72 if (C4::Context->preference('hidelostitems')) {
74 for my $itm (@all_items) {
75 push @items, $itm unless $itm->{itemlost};
78 my $dat = &GetBiblioData($biblionumber);
81 print $query->redirect("/cgi-bin/koha/errors/404.pl");
84 my $itemtypes = GetItemTypes();
86 my $itemtype = $dat->{'itemtype'};
88 $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
89 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
91 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'});
92 my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'} );
94 #coping with subscriptions
95 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
96 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
98 $dat->{'serial'}=1 if $subscriptionsnumber;
99 foreach my $subscription (@subscriptions) {
101 $cell{subscriptionid} = $subscription->{subscriptionid};
102 $cell{subscriptionnotes} = $subscription->{notes};
103 $cell{branchcode} = $subscription->{branchcode};
104 $cell{hasalert} = $subscription->{hasalert};
105 #get the three latest serials.
106 $cell{latestserials} =
107 GetLatestSerials( $subscription->{subscriptionid}, 3 );
111 $dat->{'count'} = scalar(@items);
113 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber ) );
116 my $branches = GetBranches();
118 for my $itm (@items) {
120 if ( (not $itm->{'wthdrawn'} )
121 && (not $itm->{'itemlost'} )
122 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
123 && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
124 && ($itm->{'itemnumber'} ) );
126 $itm->{ $itm->{'publictype'} } = 1;
127 $itm->{datedue} = format_date($itm->{datedue});
128 $itm->{datelastseen} = format_date($itm->{datelastseen});
130 #get collection code description, too
131 my $ccode= $itm->{'ccode'};
132 $itm->{'ccode'} = $collections->{$ccode} if(defined($collections) && exists($collections->{$ccode}));
133 $itm->{'location_description'} = $shelflocations->{$itm->{'location'} };
134 $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
135 $itm->{'description'} = $itemtypes->{$itemtype}->{'description'};
136 foreach (qw(ccode enumchron copynumber itemnotes)) {
137 $itemfields{$_} = 1 if ($itm->{$_});
140 # walk through the item-level authorised values and populate some images
141 my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
142 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
144 if ( $itm->{'itemlost'} ) {
145 my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
146 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
147 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
151 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
152 if ( $transfertwhen ne '' ) {
153 $itm->{transfertwhen} = format_date($transfertwhen);
154 $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
155 $itm->{transfertto} = $branches->{$transfertto}{branchname};
159 ## get notes and subjects from MARC record
160 my $dbh = C4::Context->dbh;
161 my $marcflavour = C4::Context->preference("marcflavour");
162 my $record = GetMarcBiblio($biblionumber);
163 my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
164 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
165 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
166 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
167 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
168 my $subtitle = C4::Biblio::get_koha_field_from_marc('bibliosubtitle', 'subtitle', $record, '');
171 MARCNOTES => $marcnotesarray,
172 MARCSUBJCTS => $marcsubjctsarray,
173 MARCAUTHORS => $marcauthorsarray,
174 MARCSERIES => $marcseriesarray,
175 MARCURLS => $marcurlsarray,
176 norequests => $norequests,
177 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
178 itemdata_ccode => $itemfields{ccode},
179 itemdata_enumchron => $itemfields{enumchron},
180 itemdata_copynumber => $itemfields{copynumber},
181 itemdata_itemnotes => $itemfields{itemnotes},
182 authorised_value_images => $biblio_authorised_value_images,
183 subtitle => $subtitle,
186 foreach ( keys %{$dat} ) {
187 $template->param( "$_" => $dat->{$_} . "" );
190 # COinS format FIXME: for books Only
192 ocoins => GetCOinSBiblio($biblionumber),
195 my $reviews = getreviews( $biblionumber, 1 );
196 my $loggedincommenter;
197 foreach ( @$reviews ) {
198 my $borrowerData = GetMember($_->{borrowernumber},'borrowernumber');
199 # setting some borrower info into this hash
200 $_->{title} = $borrowerData->{'title'};
201 $_->{surname} = $borrowerData->{'surname'};
202 $_->{firstname} = $borrowerData->{'firstname'};
203 $_->{userid} = $borrowerData->{'userid'};
204 $_->{datereviewed} = format_date($_->{datereviewed});
205 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
206 $_->{your_comment} = 1;
207 $loggedincommenter = 1;
212 if(C4::Context->preference("ISBD")) {
213 $template->param(ISBD => 1);
217 ITEM_RESULTS => \@items,
218 subscriptionsnumber => $subscriptionsnumber,
219 biblionumber => $biblionumber,
220 subscriptions => \@subs,
221 subscriptionsnumber => $subscriptionsnumber,
223 loggedincommenter => $loggedincommenter
226 sub isbn_cleanup ($) {
228 ($isbn) = $isbn =~ /([\d-]*[X]*)/;
231 $isbn =~ /\b(\d{13})\b/ or
232 $isbn =~ /\b(\d{10})\b/ or
233 $isbn =~ /\b(\d{9}X)\b/i
241 my $xisbn=$dat->{'isbn'};
242 (my $aisbn) = $xisbn =~ /([\d-]*[X]*)/;
244 $template->param(amazonisbn => $aisbn); # FIXME: so it is OK if the ISBN = 'XXXXX' ?
246 # these might be overkill, but they are better than the regexp above.
247 if ($clean = isbn_cleanup($xisbn)){
248 $template->param(clean_isbn => $clean);
251 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
255 XISBNS => get_xisbns($xisbn)
258 if ($@) { warn "XISBN Failed $@"; }
261 if ( C4::Context->preference("OPACAmazonContent") == 1 ) {
262 my $similar_products_exist;
263 my $amazon_details = &get_amazon_details( $xisbn, $record, $marcflavour );
264 my $item_attributes = \%{$amazon_details->{Items}->{Item}->{ItemAttributes}};
265 my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
266 for my $one_review (@$customer_reviews) {
267 $one_review->{Date} = format_date($one_review->{Date});
269 my @similar_products;
270 for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
271 # do we have any of these isbns in our collection?
272 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
273 # verify that there is at least one similar item
274 if (scalar(@$similar_biblionumbers)){
275 $similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
276 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
279 my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
280 my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating};
281 $template->param( OPACAmazonSimilarItems => $similar_products_exist );
282 $template->param( amazon_average_rating => $average_rating * 20);
283 $template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
284 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
285 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
287 # Shelf Browser Stuff
288 if (C4::Context->preference("OPACShelfBrowser")) {
289 # pick the first itemnumber unless one was selected by the user
290 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); # || $items[0]->{itemnumber};
291 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
292 # find the right cn_sort value for this item
293 my ($starting_cn_sort, $starting_homebranch, $starting_location);
294 my $sth_get_cn_sort = $dbh->prepare("SELECT cn_sort,homebranch,location from items where itemnumber=?");
295 $sth_get_cn_sort->execute($starting_itemnumber);
296 while (my $result = $sth_get_cn_sort->fetchrow_hashref()) {
297 $starting_cn_sort = $result->{'cn_sort'};
298 $starting_homebranch->{code} = $result->{'homebranch'};
299 $starting_homebranch->{description} = $branches->{$result->{'homebranch'}}{branchname};
300 $starting_location->{code} = $result->{'location'};
301 $starting_location->{description} = GetAuthorisedValueDesc('','', $result->{'location'} ,'','','LOC');
305 ## List of Previous Items
306 # order by cn_sort, which should include everything we need for ordering purposes (though not
307 # for limits, those need to be handled separately
308 my $sth_shelfbrowse_previous = $dbh->prepare("
312 ((cn_sort = ? AND itemnumber < ?) OR cn_sort < ?) AND
313 homebranch = ? AND location = ?
314 ORDER BY cn_sort DESC, itemnumber LIMIT 3
316 $sth_shelfbrowse_previous->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code});
318 while (my $this_item = $sth_shelfbrowse_previous->fetchrow_hashref()) {
319 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=?");
320 $sth_get_biblio->execute($this_item->{biblionumber});
321 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
322 $this_item->{'title'} = $this_biblio->{'title'};
323 if ($clean2 = isbn_cleanup($this_biblio->{'isbn'})) {
324 $this_item->{'isbn'} = $clean2;
326 $this_item->{'isbn'} = $this_biblio->{'isbn'};
329 unshift @previous_items, $this_item;
332 ## List of Next Items; this also intentionally catches the current item
333 my $sth_shelfbrowse_next = $dbh->prepare("
337 ((cn_sort = ? AND itemnumber >= ?) OR cn_sort > ?) AND
338 homebranch = ? AND location = ?
339 ORDER BY cn_sort, itemnumber LIMIT 3
341 $sth_shelfbrowse_next->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code});
343 while (my $this_item = $sth_shelfbrowse_next->fetchrow_hashref()) {
344 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=?");
345 $sth_get_biblio->execute($this_item->{biblionumber});
346 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
347 $this_item->{'title'} = $this_biblio->{'title'};
348 if ($clean2 = isbn_cleanup($this_biblio->{'isbn'})) {
349 $this_item->{'isbn'} = $clean2;
351 $this_item->{'isbn'} = $this_biblio->{'isbn'};
354 push @next_items, $this_item;
357 # alas, these won't auto-vivify, see http://www.perlmonks.org/?node_id=508481
358 my $shelfbrowser_next_itemnumber = $next_items[-1]->{itemnumber} if @next_items;
359 my $shelfbrowser_next_biblionumber = $next_items[-1]->{biblionumber} if @next_items;
362 starting_homebranch => $starting_homebranch->{description},
363 starting_location => $starting_location->{description},
364 starting_itemnumber => $starting_itemnumber,
365 shelfbrowser_prev_itemnumber => (@previous_items ? $previous_items[0]->{itemnumber} : 0),
366 shelfbrowser_next_itemnumber => $shelfbrowser_next_itemnumber,
367 shelfbrowser_prev_biblionumber => (@previous_items ? $previous_items[0]->{biblionumber} : 0),
368 shelfbrowser_next_biblionumber => $shelfbrowser_next_biblionumber,
369 PREVIOUS_SHELF_BROWSE => \@previous_items,
370 NEXT_SHELF_BROWSE => \@next_items,
374 if (C4::Context->preference("BakerTaylorEnabled")) {
376 BakerTaylorEnabled => 1,
377 BakerTaylorImageURL => &image_url(),
378 BakerTaylorLinkURL => &link_url(),
379 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
381 my ($bt_user, $bt_pass);
383 $bt_user = C4::Context->preference('BakerTaylorUsername') and
384 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
387 BakerTaylorContentURL =>
388 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
389 $bt_user,$bt_pass,$clean)
395 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
398 TagsShowOnDetail => $tag_quantity,
399 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
401 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
402 'sort'=>'-weight', limit=>$tag_quantity}));
405 output_html_with_http_headers $query, $cookie, $template->output;