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
35 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn get_biblio_from_xisbn);
38 # use Smart::Comments;
41 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
43 template_name => "catalogue/detail.tmpl",
47 flagsrequired => { catalogue => 1 },
51 my $biblionumber = $query->param('biblionumber');
52 my $fw = GetFrameworkCode($biblionumber);
54 ## get notes and subjects from MARC record
55 my $marcflavour = C4::Context->preference("marcflavour");
56 my $record = GetMarcBiblio($biblionumber);
58 unless (defined($record)) {
59 print $query->redirect("/cgi-bin/koha/errors/404.pl");
63 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
64 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
65 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
66 my $marcseriesarray = GetMarcSeries($record,$marcflavour);
67 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
68 my $subtitle = C4::Biblio::get_koha_field_from_marc('bibliosubtitle', 'subtitle', $record, '');
70 # Get Branches, Itemtypes and Locations
71 my $branches = GetBranches();
72 my $itemtypes = GetItemTypes();
74 # FIXME: move this to a pm, check waiting status for holds
75 my $dbh = C4::Context->dbh;
77 # change back when ive fixed request.pl
78 my @items = &GetItemsInfo( $biblionumber, 'intra' );
79 my $dat = &GetBiblioData($biblionumber);
81 #coping with subscriptions
82 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
83 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
85 $dat->{'serial'}=1 if $subscriptionsnumber;
86 foreach my $subscription (@subscriptions) {
88 $cell{subscriptionid} = $subscription->{subscriptionid};
89 $cell{subscriptionnotes} = $subscription->{notes};
90 $cell{branchcode} = $subscription->{branchcode};
91 $cell{hasalert} = $subscription->{hasalert};
92 #get the three latest serials.
93 $cell{latestserials} =
94 GetLatestSerials( $subscription->{subscriptionid}, 3 );
98 if ( defined $dat->{'itemtype'} ) {
99 $dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }{imageurl} );
101 $dat->{'count'} = scalar @items;
102 my $shelflocations = GetKohaAuthorisedValues('items.location', $fw);
103 my $collections = GetKohaAuthorisedValues('items.ccode' , $fw);
104 my (@itemloop, %itemfields);
106 foreach my $item (@items) {
108 # can place holds defaults to yes
109 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
111 # format some item fields for display
112 if ( defined $item->{'publictype'} ) {
113 $item->{ $item->{'publictype'} } = 1;
115 $item->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $item->{itype} }{imageurl} );
116 foreach (qw(datedue datelastseen onloan)) {
117 $item->{$_} = format_date($item->{$_});
119 # item damaged, lost, withdrawn loops
120 $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
121 if ($item->{damaged}) {
122 $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
124 #get shelf location and collection code description if they are authorised value.
125 my $shelfcode = $item->{'location'};
126 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
127 my $ccode = $item->{'ccode'};
128 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
129 foreach (qw(ccode enumchron copynumber)) {
130 $itemfields{$_} = 1 if ( $item->{$_} );
134 my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($item->{itemnumber});
135 my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
137 if ( defined $reservedate ) {
138 $item->{backgroundcolor} = 'reserved';
139 $item->{reservedate} = format_date($reservedate);
140 $item->{ReservedForBorrowernumber} = $reservedfor;
141 $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
142 $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
143 $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname};
146 # Check the transit status
147 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber});
148 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
149 $item->{transfertwhen} = format_date($transfertwhen);
150 $item->{transfertfrom} = $branches->{$transfertfrom}{branchname};
151 $item->{transfertto} = $branches->{$transfertto}{branchname};
152 $item->{nocancel} = 1;
155 # FIXME: move this to a pm, check waiting status for holds
156 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
157 $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
158 while (my $wait_hashref = $sth2->fetchrow_hashref) {
159 $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
162 push @itemloop, $item;
165 $template->param( norequests => $norequests );
167 MARCNOTES => $marcnotesarray,
168 MARCSUBJCTS => $marcsubjctsarray,
169 MARCAUTHORS => $marcauthorsarray,
170 MARCSERIES => $marcseriesarray,
171 MARCURLS => $marcurlsarray,
172 subtitle => $subtitle,
173 itemdata_ccode => $itemfields{ccode},
174 itemdata_enumchron => $itemfields{enumchron},
175 itemdata_copynumber => $itemfields{copynumber},
176 volinfo => $itemfields{enumchron} || $dat->{'serial'} ,
179 my @results = ( $dat, );
180 foreach ( keys %{$dat} ) {
181 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
185 itemloop => \@itemloop,
186 biblionumber => $biblionumber,
188 subscriptions => \@subs,
189 subscriptionsnumber => $subscriptionsnumber,
190 subscriptiontitle => $dat->{title},
193 # $debug and $template->param(debug_display => 1);
196 my $xisbn=$dat->{'isbn'};
197 $xisbn =~ /(\d*[X]*)/ if ( $xisbn );
198 $template->param(amazonisbn => $1); # FIXME: so it is OK if the ISBN = 'XXXXX' ?
199 if (C4::Context->preference("FRBRizeEditions")==1) {
203 XISBNS => get_xisbns($xisbn)
206 if ($@) { warn "XISBN Failed $@"; }
208 if ( C4::Context->preference("AmazonContent") == 1 ) {
209 my $similar_products_exist;
210 my $amazon_details = &get_amazon_details( $xisbn, $record, $marcflavour );
211 my $item_attributes = \%{$amazon_details->{Items}->{Item}->{ItemAttributes}};
212 my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
213 my @similar_products;
214 for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
215 # do we have any of these isbns in our collection?
216 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
217 # verify that there is at least one similar item
218 if (scalar(@$similar_biblionumbers)){
219 $similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
220 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
223 my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
224 my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating};
225 $template->param( AmazonSimilarItems => $similar_products_exist );
226 $template->param( amazon_average_rating => $average_rating * 20);
227 $template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
228 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
229 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
231 output_html_with_http_headers $query, $cookie, $template->output;