3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
24 use C4::Dates qw/format_date/;
26 use C4::Serials; #uses getsubscriptionfrom biblionumber
33 use C4::Members; # to use GetMember
35 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn);
36 use C4::External::Amazon;
37 use C4::Search; # enabled_staff_search_views
38 use C4::VirtualShelves;
41 # use Smart::Comments;
43 my $query = CGI->new();
44 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
46 template_name => "catalogue/detail.tmpl",
50 flagsrequired => { catalogue => 1 },
54 my $biblionumber = $query->param('biblionumber');
55 my $record = GetMarcBiblio($biblionumber);
57 if ( not defined $record ) {
58 # biblionumber invalid -> report and exit
59 $template->param( unknownbiblionumber => 1,
60 biblionumber => $biblionumber );
61 output_html_with_http_headers $query, $cookie, $template->output;
65 if($query->cookie("holdfor")){
66 my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
68 holdfor => $query->cookie("holdfor"),
69 holdfor_surname => $holdfor_patron->{'surname'},
70 holdfor_firstname => $holdfor_patron->{'firstname'},
71 holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
75 my $fw = GetFrameworkCode($biblionumber);
76 my $showallitems = $query->param('showallitems');
77 my $marcflavour = C4::Context->preference("marcflavour");
79 # XSLT processing of some stuff
80 if (C4::Context->preference("XSLTDetailsDisplay") ) {
81 $template->param('XSLTDetailsDisplay' =>'1',
82 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, 'Detail','intranet') );
85 $template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
87 # some useful variables for enhanced content;
88 # in each case, we're grabbing the first value we find in
89 # the record and normalizing it
90 my $upc = GetNormalizedUPC($record,$marcflavour);
91 my $ean = GetNormalizedEAN($record,$marcflavour);
92 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
93 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
96 normalized_upc => $upc,
97 normalized_ean => $ean,
98 normalized_oclc => $oclc,
99 normalized_isbn => $isbn,
102 unless (defined($record)) {
103 print $query->redirect("/cgi-bin/koha/errors/404.pl");
107 my $dat = &GetBiblioData($biblionumber);
109 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
110 my $marcisbnsarray = GetMarcISBN( $record, $marcflavour );
111 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
112 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
113 my $marcseriesarray = GetMarcSeries($record,$marcflavour);
114 my $marcurlsarray = GetMarcUrls ($record,$marcflavour,$dat->{issn});
115 my $subtitle = GetRecordValue('subtitle', $record, $fw);
117 # Get Branches, Itemtypes and Locations
118 my $branches = GetBranches();
119 my $itemtypes = GetItemTypes();
120 my $dbh = C4::Context->dbh;
122 my @all_items = GetItemsInfo( $biblionumber );
124 for my $itm (@all_items) {
125 push @items, $itm unless ( $itm->{itemlost} && GetHideLostItemsPreference($borrowernumber) && !$showallitems);
129 my ( $holdcount, $holds ) = GetReservesFromBiblionumber($biblionumber,1);
131 #coping with subscriptions
132 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
133 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
136 foreach my $subscription (@subscriptions) {
138 my $serials_to_display;
139 $cell{subscriptionid} = $subscription->{subscriptionid};
140 $cell{subscriptionnotes} = $subscription->{notes};
141 $cell{branchcode} = $subscription->{branchcode};
142 $cell{branchname} = GetBranchName($subscription->{branchcode});
143 $cell{hasalert} = $subscription->{hasalert};
144 #get the three latest serials.
145 $serials_to_display = $subscription->{staffdisplaycount};
146 $serials_to_display = C4::Context->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
147 $cell{staffdisplaycount} = $serials_to_display;
148 $cell{latestserials} =
149 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
153 if ( defined $dat->{'itemtype'} ) {
154 $dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }{imageurl} );
157 $dat->{'count'} = scalar @all_items;
158 $dat->{'showncount'} = scalar @items;
159 $dat->{'hiddencount'} = scalar @all_items - scalar @items;
161 my $shelflocations = GetKohaAuthorisedValues('items.location', $fw);
162 my $collections = GetKohaAuthorisedValues('items.ccode' , $fw);
163 my (@itemloop, %itemfields);
165 my $authvalcode_items_itemlost = GetAuthValCode('items.itemlost',$fw);
166 my $authvalcode_items_damaged = GetAuthValCode('items.damaged', $fw);
167 foreach my $item (@items) {
169 $item->{homebranch} = GetBranchName($item->{homebranch});
171 # can place holds defaults to yes
172 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
174 # format some item fields for display
175 if ( defined $item->{'publictype'} ) {
176 $item->{ $item->{'publictype'} } = 1;
178 $item->{imageurl} = defined $item->{itype} ? getitemtypeimagelocation('intranet', $itemtypes->{ $item->{itype} }{imageurl})
181 foreach (qw(datedue datelastseen onloan)) {
182 $item->{$_} = format_date($item->{$_});
184 # item damaged, lost, withdrawn loops
185 $item->{itemlostloop} = GetAuthorisedValues($authvalcode_items_itemlost, $item->{itemlost}) if $authvalcode_items_itemlost;
186 if ($item->{damaged}) {
187 $item->{itemdamagedloop} = GetAuthorisedValues($authvalcode_items_damaged, $item->{damaged}) if $authvalcode_items_damaged;
189 #get shelf location and collection code description if they are authorised value.
190 my $shelfcode = $item->{'location'};
191 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
192 my $ccode = $item->{'ccode'};
193 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
194 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
195 $itemfields{$_} = 1 if ( $item->{$_} );
199 my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($item->{itemnumber});
200 my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
202 if (C4::Context->preference('HidePatronName')){
203 $item->{'hidepatronname'} = 1;
206 if ( defined $reservedate ) {
207 $item->{backgroundcolor} = 'reserved';
208 $item->{reservedate} = format_date($reservedate);
209 $item->{ReservedForBorrowernumber} = $reservedfor;
210 $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
211 $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
212 $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname};
213 $item->{Reservedcardnumber} = $ItemBorrowerReserveInfo->{'cardnumber'};
216 # Check the transit status
217 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber});
218 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
219 $item->{transfertwhen} = format_date($transfertwhen);
220 $item->{transfertfrom} = $branches->{$transfertfrom}{branchname};
221 $item->{transfertto} = $branches->{$transfertto}{branchname};
222 $item->{nocancel} = 1;
225 # FIXME: move this to a pm, check waiting status for holds
226 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
227 $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
228 while (my $wait_hashref = $sth2->fetchrow_hashref) {
229 $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
232 push @itemloop, $item;
235 $template->param( norequests => $norequests );
237 MARCNOTES => $marcnotesarray,
238 MARCSUBJCTS => $marcsubjctsarray,
239 MARCAUTHORS => $marcauthorsarray,
240 MARCSERIES => $marcseriesarray,
241 MARCURLS => $marcurlsarray,
242 MARCISBNS => $marcisbnsarray,
243 subtitle => $subtitle,
244 itemdata_ccode => $itemfields{ccode},
245 itemdata_enumchron => $itemfields{enumchron},
246 itemdata_uri => $itemfields{uri},
247 itemdata_copynumber => $itemfields{copynumber},
248 volinfo => $itemfields{enumchron},
249 itemdata_itemnotes => $itemfields{itemnotes},
250 z3950_search_params => C4::Search::z3950_search_args($dat),
251 holdcount => $holdcount,
252 C4::Search::enabled_staff_search_views,
255 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
256 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
257 my $subfields = substr $fieldspec, 3;
258 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
259 my @alternateholdingsinfo = ();
260 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
262 for my $field (@holdingsfields) {
263 my %holding = ( holding => '' );
264 my $havesubfield = 0;
265 for my $subfield ($field->subfields()) {
266 if ((index $subfields, $$subfield[0]) >= 0) {
267 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
268 $holding{'holding'} .= $$subfield[1];
273 push(@alternateholdingsinfo, \%holding);
278 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
282 my @results = ( $dat, );
283 foreach ( keys %{$dat} ) {
284 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
287 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
288 # method query not found?!?!
291 itemloop => \@itemloop,
292 biblionumber => $biblionumber,
294 subscriptions => \@subs,
295 subscriptionsnumber => $subscriptionsnumber,
296 subscriptiontitle => $dat->{title},
299 # $debug and $template->param(debug_display => 1);
303 if (C4::Context->preference("virtualshelves") ) {
304 $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
308 if (C4::Context->preference("FRBRizeEditions")==1) {
311 XISBNS => get_xisbns($isbn)
314 if ($@) { warn "XISBN Failed $@"; }
316 if ( C4::Context->preference("AmazonEnabled") == 1 ) {
317 $template->param( AmazonTld => get_amazon_tld() );
318 my $amazon_reviews = C4::Context->preference("AmazonReviews");
319 my $amazon_similars = C4::Context->preference("AmazonSimilarItems");
321 if ( $amazon_reviews ) {
322 $template->param( AmazonReviews => 1 );
323 push( @services, 'EditorialReview' );
325 if ( $amazon_similars ) {
326 $template->param( AmazonSimilarItems => 1 );
327 push( @services, 'Similarities' );
329 my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour, \@services );
330 if ( $amazon_similars ) {
331 my $similar_products_exist;
332 my @similar_products;
333 for my $similar_product (@{$amazon_details->{Items}->{Item}->[0]->{SimilarProducts}->{SimilarProduct}}) {
334 # do we have any of these isbns in our collection?
335 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
336 # verify that there is at least one similar item
337 if (scalar(@$similar_biblionumbers)){
338 $similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
339 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
342 $template->param( AmazonSimilarItems => $similar_products_exist );
343 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
345 if ( $amazon_reviews ) {
346 my $item = $amazon_details->{Items}->{Item}->[0];
347 my $editorial_reviews = \@{ $item->{EditorialReviews}->{EditorialReview} };
348 #my $customer_reviews = \@{$amazon_details->{Items}->{Item}->[0]->{CustomerReviews}->{Review}};
349 #my $average_rating = $amazon_details->{Items}->{Item}->[0]->{CustomerReviews}->{AverageRating} || 0;
350 #$template->param( amazon_average_rating => $average_rating * 20 );
351 #$template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
352 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
357 if (C4::Context->preference('OPACBaseURL')){
358 $template->param( OpacUrl => C4::Context->preference('OPACBaseURL') );
361 output_html_with_http_headers $query, $cookie, $template->output;