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
23 use C4::Date qw/format_date/;
25 use C4::Serials; #uses getsubscriptionfrom biblionumber
34 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn get_biblio_from_xisbn);
37 # use Smart::Comments;
40 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
42 template_name => "catalogue/detail.tmpl",
46 flagsrequired => { catalogue => 1 },
50 my $biblionumber = $query->param('biblionumber');
51 my $fw = GetFrameworkCode($biblionumber);
53 ## get notes and subjects from MARC record
54 my $marcflavour = C4::Context->preference("marcflavour");
55 my $record = GetMarcBiblio($biblionumber);
56 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
57 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
58 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
59 my $marcseriesarray = GetMarcSeries($record,$marcflavour);
60 my $subtitle = C4::Biblio::get_koha_field_from_marc('bibliosubtitle', 'subtitle', $record, '');
62 # Get Branches, Itemtypes and Locations
63 my $branches = GetBranches();
64 my $itemtypes = GetItemTypes();
66 # FIXME: move this to a pm, check waiting status for holds
67 my $dbh = C4::Context->dbh;
69 # change back when ive fixed request.pl
70 my @items = &GetItemsInfo( $biblionumber, 'intra' );
71 my $dat = &GetBiblioData($biblionumber);
74 print $query->redirect("/cgi-bin/koha/koha-tmpl/errors/404.pl");
78 #coping with subscriptions
79 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
80 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
85 foreach my $subscription (@subscriptions) {
87 $cell{subscriptionid} = $subscription->{subscriptionid};
88 $cell{subscriptionnotes} = $subscription->{notes};
90 #get the three latest serials.
91 $cell{latestserials} =
92 GetLatestSerials( $subscription->{subscriptionid}, 3 );
95 $dat->{imageurl} = getitemtypeimagesrc() . "/".$itemtypes->{ $dat->{itemtype} }{imageurl};
96 $dat->{'count'} = @items;
99 foreach my $item (@items) {
101 # can place holds defaults to yes
102 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
104 # format some item fields for display
105 $item->{ $item->{'publictype'} } = 1;
106 $item->{imageurl} = getitemtypeimagesrc() . "/".$itemtypes->{ $item->{itype} }{imageurl};
107 $item->{datedue} = format_date($item->{datedue});
108 $item->{datelastseen} = format_date($item->{datelastseen});
109 $item->{onloan} = format_date($item->{onloan});
110 # item damaged, lost, withdrawn loops
111 $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
112 if ($item->{damaged}) {
113 $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
115 #get shelf location and collection code description if they are authorised value.
116 my $shelflocations = GetKohaAuthorisedValues('items.location',$fw );
117 my $shelfcode= $item->{'location'};
118 $item->{'location'} = $shelflocations->{$shelfcode} if(defined($shelflocations) && exists($shelflocations->{$shelfcode}));
119 my $collections = GetKohaAuthorisedValues('items.ccode',$fw );
120 my $ccode= $item->{'ccode'};
121 $item->{'ccode'} = $collections->{$ccode} if(defined($collections) && exists($collections->{$ccode}));
124 my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($item->{itemnumber});
125 my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
127 if ( defined $reservedate ) {
128 $item->{backgroundcolor} = 'reserved';
129 $item->{reservedate} = format_date($reservedate);
130 $item->{ReservedForBorrowernumber} = $reservedfor;
131 $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
132 $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
133 $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname};
136 # Check the transit status
137 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber});
138 if ( $transfertwhen ne '' ) {
139 $item->{transfertwhen} = format_date($transfertwhen);
140 $item->{transfertfrom} = $branches->{$transfertfrom}{branchname};
141 $item->{transfertto} = $branches->{$transfertto}{branchname};
142 $item->{nocancel} = 1;
145 # FIXME: move this to a pm, check waiting status for holds
146 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
147 $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
148 while (my $wait_hashref = $sth2->fetchrow_hashref) {
149 $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
152 push @itemloop, $item;
155 $template->param( norequests => $norequests );
158 MARCNOTES => $marcnotesarray,
159 MARCSUBJCTS => $marcsubjctsarray,
160 MARCAUTHORS => $marcauthorsarray,
161 MARCSERIES => $marcseriesarray,
162 subtitle => $subtitle,
165 my @results = ( $dat, );
166 foreach ( keys %{$dat} ) {
167 $template->param( "$_" => $dat->{$_} . "" );
171 itemloop => \@itemloop,
172 biblionumber => $biblionumber,
174 subscriptions => \@subs,
175 subscriptionsnumber => $subscriptionsnumber,
176 subscriptiontitle => $dat->{title},
180 my $xisbn=$dat->{'isbn'};
181 $xisbn =~ s/(p|-| |:)//g;
182 $template->param(amazonisbn => $xisbn);
183 if (C4::Context->preference("FRBRizeEditions")==1) {
187 XISBNS => get_xisbns($xisbn)
190 if ($@) { warn "XISBN Failed $@"; }
192 if ( C4::Context->preference("AmazonContent") == 1 ) {
193 my $similar_products_exist;
194 my $amazon_details = &get_amazon_details( $xisbn );
195 my $item_attributes = \%{$amazon_details->{Items}->{Item}->{ItemAttributes}};
196 my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
197 my @similar_products;
198 for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
199 # do we have any of these isbns in our collection?
200 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
201 # verify that there is at least one similar item
202 $similar_products_exist++ if ${@$similar_biblionumbers}[0];
203 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
205 my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
206 my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating};
207 $template->param( AmazonSimilarItems => $similar_products_exist );
208 $template->param( amazon_average_rating => $average_rating * 20);
209 $template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
210 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
211 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
213 output_html_with_http_headers $query, $cookie, $template->output;