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("XSLTResultsDisplay") ) {
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 $imgdir = getitemtypeimagesrc();
85 my $itemtypes = GetItemTypes();
87 my $itemtype = $dat->{'itemtype'};
89 $dat->{'imageurl'} = $imgdir."/".$itemtypes->{$itemtype}->{'imageurl'};
90 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
92 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'});
93 my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'} );
95 #coping with subscriptions
96 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
97 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
99 $dat->{'serial'}=1 if $subscriptionsnumber;
100 foreach my $subscription (@subscriptions) {
102 $cell{subscriptionid} = $subscription->{subscriptionid};
103 $cell{subscriptionnotes} = $subscription->{notes};
104 $cell{branchcode} = $subscription->{branchcode};
105 $cell{hasalert} = $subscription->{hasalert};
106 #get the three latest serials.
107 $cell{latestserials} =
108 GetLatestSerials( $subscription->{subscriptionid}, 3 );
112 $dat->{'count'} = scalar(@items);
114 #adding RequestOnOpac filter to allow or not the display of plce reserve button
115 # FIXME - use me or delete me.
117 if (C4::Context->preference("RequestOnOpac")) {
121 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber ) );
124 my $branches = GetBranches();
126 for my $itm (@items) {
127 $norequests = 0 && $norequests
128 if ( (not $itm->{'wthdrawn'} )
129 && (not $itm->{'itemlost'} )
130 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
131 && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
132 && ($itm->{'itemnumber'} ) );
134 $itm->{ $itm->{'publictype'} } = 1;
135 $itm->{datedue} = format_date($itm->{datedue});
136 $itm->{datelastseen} = format_date($itm->{datelastseen});
138 #get collection code description, too
139 my $ccode= $itm->{'ccode'};
140 $itm->{'ccode'} = $collections->{$ccode} if(defined($collections) && exists($collections->{$ccode}));
141 $itm->{'location_description'} = $shelflocations->{$itm->{'location'} };
142 $itm->{'imageurl'} = $imgdir."/".$itemtypes->{ $itm->{itype} }->{'imageurl'};
143 $itm->{'description'} = $itemtypes->{$itemtype}->{'description'};
144 $itemfields{ccode} = 1 if($itm->{ccode});
145 $itemfields{enumchron} = 1 if($itm->{enumchron});
146 $itemfields{copynumber} = 1 if($itm->{copynumber});
147 $itemfields{itemnotes} = 1 if($itm->{itemnotes});
149 # walk through the item-level authorised values and populate some images
150 my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
151 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
153 if ( $itm->{'itemlost'} ) {
154 my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
155 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
156 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
160 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
161 if ( $transfertwhen ne '' ) {
162 $itm->{transfertwhen} = format_date($transfertwhen);
163 $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
164 $itm->{transfertto} = $branches->{$transfertto}{branchname};
168 ## get notes and subjects from MARC record
169 my $dbh = C4::Context->dbh;
170 my $marcflavour = C4::Context->preference("marcflavour");
171 my $record = GetMarcBiblio($biblionumber);
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 => $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( "$_" => $dat->{$_} . "" );
199 # COinS format FIXME: for books Only
201 my $fmt = substr $record->leader(), 6,2;
203 $fmts->{'am'} = 'book';
204 $coins_format = $fmts->{$fmt};
206 ocoins_format => $coins_format,
209 my $reviews = getreviews( $biblionumber, 1 );
210 my $loggedincommenter;
211 foreach ( @$reviews ) {
212 my $borrowerData = GetMember($_->{borrowernumber},'borrowernumber');
213 # setting some borrower info into this hash
214 $_->{title} = $borrowerData->{'title'};
215 $_->{surname} = $borrowerData->{'surname'};
216 $_->{firstname} = $borrowerData->{'firstname'};
217 $_->{userid} = $borrowerData->{'userid'};
218 $_->{datereviewed} = format_date($_->{datereviewed});
219 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
220 $_->{your_comment} = 1;
221 $loggedincommenter = 1;
226 if(C4::Context->preference("ISBD")) {
227 $template->param(ISBD => 1);
231 ITEM_RESULTS => \@items,
232 subscriptionsnumber => $subscriptionsnumber,
233 biblionumber => $biblionumber,
234 subscriptions => \@subs,
235 subscriptionsnumber => $subscriptionsnumber,
237 loggedincommenter => $loggedincommenter
240 sub isbn_cleanup ($) {
243 $isbn =~ /\b(\d{13})\b/ or
244 $isbn =~ /\b(\d{10})\b/ or
245 $isbn =~ /\b(\d{9}X)\b/i
253 my $xisbn=$dat->{'isbn'};
254 $xisbn =~ /(\d*[X]*)/;
255 $template->param(amazonisbn => $1); # FIXME: so it is OK if the ISBN = 'XXXXX' ?
257 # these might be overkill, but they are better than the regexp above.
258 if ($clean = isbn_cleanup($xisbn)){
259 $template->param(clean_isbn => $clean);
262 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
266 XISBNS => get_xisbns($xisbn)
269 if ($@) { warn "XISBN Failed $@"; }
272 if ( C4::Context->preference("OPACAmazonContent") == 1 ) {
273 my $similar_products_exist;
274 my $amazon_details = &get_amazon_details( $xisbn );
275 my $item_attributes = \%{$amazon_details->{Items}->{Item}->{ItemAttributes}};
276 my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
277 for my $one_review (@$customer_reviews) {
278 $one_review->{Date} = format_date($one_review->{Date});
280 my @similar_products;
281 for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
282 # do we have any of these isbns in our collection?
283 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
284 # verify that there is at least one similar item
285 $similar_products_exist++ if ${@$similar_biblionumbers}[0];
286 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
288 my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
289 my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating};
290 $template->param( OPACAmazonSimilarItems => $similar_products_exist );
291 $template->param( amazon_average_rating => $average_rating * 20);
292 $template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
293 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
294 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
296 # Shelf Browser Stuff
297 if (C4::Context->preference("OPACShelfBrowser")) {
298 # pick the first itemnumber unless one was selected by the user
299 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); # || $items[0]->{itemnumber};
300 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
301 # find the right cn_sort value for this item
302 my ($starting_cn_sort, $starting_homebranch, $starting_location);
303 my $sth_get_cn_sort = $dbh->prepare("SELECT cn_sort,homebranch,location from items where itemnumber=?");
304 $sth_get_cn_sort->execute($starting_itemnumber);
305 while (my $result = $sth_get_cn_sort->fetchrow_hashref()) {
306 $starting_cn_sort = $result->{'cn_sort'};
307 $starting_homebranch->{code} = $result->{'homebranch'};
308 $starting_homebranch->{description} = $branches->{$result->{'homebranch'}}{branchname};
309 $starting_location->{code} = $result->{'location'};
310 $starting_location->{description} = GetAuthorisedValueDesc('','', $result->{'location'} ,'','','LOC');
314 ## List of Previous Items
315 # order by cn_sort, which should include everything we need for ordering purposes (though not
316 # for limits, those need to be handled separately
317 my $sth_shelfbrowse_previous = $dbh->prepare("SELECT * FROM items WHERE CONCAT(cn_sort,itemnumber) <= ? AND homebranch=? AND location=? ORDER BY CONCAT(cn_sort,itemnumber) DESC LIMIT 3");
318 $sth_shelfbrowse_previous->execute($starting_cn_sort.$starting_itemnumber, $starting_homebranch->{code}, $starting_location->{code});
320 while (my $this_item = $sth_shelfbrowse_previous->fetchrow_hashref()) {
321 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=?");
322 $sth_get_biblio->execute($this_item->{biblionumber});
323 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
324 $this_item->{'title'} = $this_biblio->{'title'};
325 if ($clean2 = isbn_cleanup($this_biblio->{'isbn'})) {
326 $this_item->{'isbn'} = $clean2;
328 $this_item->{'isbn'} = $this_biblio->{'isbn'};
331 unshift @previous_items, $this_item;
333 my $throwaway = pop @previous_items;
334 ## List of Next Items
335 my $sth_shelfbrowse_next = $dbh->prepare("SELECT * FROM items WHERE CONCAT(cn_sort,itemnumber) >= ? AND homebranch=? AND location=? ORDER BY CONCAT(cn_sort,itemnumber) ASC LIMIT 3");
336 $sth_shelfbrowse_next->execute($starting_cn_sort.$starting_itemnumber, $starting_homebranch->{code}, $starting_location->{code});
338 while (my $this_item = $sth_shelfbrowse_next->fetchrow_hashref()) {
339 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=?");
340 $sth_get_biblio->execute($this_item->{biblionumber});
341 while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
342 $this_item->{'title'} = $this_biblio->{'title'};
343 if ($clean2 = isbn_cleanup($this_biblio->{'isbn'})) {
344 $this_item->{'isbn'} = $clean2;
346 $this_item->{'isbn'} = $this_biblio->{'isbn'};
349 push @next_items, $this_item;
352 # alas, these won't auto-vivify, see http://www.perlmonks.org/?node_id=508481
353 my $shelfbrowser_next_itemnumber = $next_items[-1]->{itemnumber} if @next_items;
354 my $shelfbrowser_next_biblionumber = $next_items[-1]->{biblionumber} if @next_items;
357 starting_homebranch => $starting_homebranch->{description},
358 starting_location => $starting_location->{description},
359 shelfbrowser_prev_itemnumber => $previous_items[0]->{itemnumber},
360 shelfbrowser_next_itemnumber => $shelfbrowser_next_itemnumber,
361 shelfbrowser_prev_biblionumber => $previous_items[0]->{biblionumber},
362 shelfbrowser_next_biblionumber => $shelfbrowser_next_biblionumber,
363 PREVIOUS_SHELF_BROWSE => \@previous_items,
364 NEXT_SHELF_BROWSE => \@next_items,
368 if (C4::Context->preference("BakerTaylorEnabled")) {
370 BakerTaylorEnabled => 1,
371 BakerTaylorImageURL => &image_url(),
372 BakerTaylorLinkURL => &link_url(),
373 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
375 my ($bt_user, $bt_pass);
377 $bt_user = C4::Context->preference('BakerTaylorUsername') and
378 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
381 BakerTaylorContentURL =>
382 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
383 $bt_user,$bt_pass,$clean)
389 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
392 TagsShowOnDetail => $tag_quantity,
393 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
395 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
396 'sort'=>'-weight', limit=>$tag_quantity}));
399 output_html_with_http_headers $query, $cookie, $template->output;