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);
61 # Get Branches, Itemtypes and Locations
62 my $branches = GetBranches();
63 my $itemtypes = GetItemTypes();
65 # FIXME: move this to a pm, check waiting status for holds
66 my $dbh = C4::Context->dbh;
68 # change back when ive fixed request.pl
69 my @items = &GetItemsInfo( $biblionumber, 'intra' );
70 my $dat = &GetBiblioData($biblionumber);
73 print $query->redirect("/cgi-bin/koha/koha-tmpl/errors/404.pl");
77 #coping with subscriptions
78 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
79 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
84 foreach my $subscription (@subscriptions) {
86 $cell{subscriptionid} = $subscription->{subscriptionid};
87 $cell{subscriptionnotes} = $subscription->{notes};
89 #get the three latest serials.
90 $cell{latestserials} =
91 GetLatestSerials( $subscription->{subscriptionid}, 3 );
94 $dat->{imageurl} = getitemtypeimagesrc() . "/".$itemtypes->{ $dat->{itemtype} }{imageurl};
95 $dat->{'count'} = @items;
98 foreach my $item (@items) {
100 # can place holds defaults to yes
101 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
103 # format some item fields for display
104 $item->{ $item->{'publictype'} } = 1;
105 $item->{imageurl} = getitemtypeimagesrc() . "/".$itemtypes->{ $item->{itype} }{imageurl};
106 $item->{datedue} = format_date($item->{datedue});
107 $item->{datelastseen} = format_date($item->{datelastseen});
108 $item->{onloan} = format_date($item->{onloan});
109 # item damaged, lost, withdrawn loops
110 $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
111 if ($item->{damaged}) {
112 $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
114 #get shelf location and collection code description if they are authorised value.
115 my $shelflocations = GetKohaAuthorisedValues('items.location',$fw );
116 my $shelfcode= $item->{'location'};
117 $item->{'location'} = $shelflocations->{$shelfcode} if(defined($shelflocations) && exists($shelflocations->{$shelfcode}));
118 my $collections = GetKohaAuthorisedValues('items.ccode',$fw );
119 my $ccode= $item->{'ccode'};
120 $item->{'ccode'} = $collections->{$ccode} if(defined($collections) && exists($collections->{$ccode}));
123 my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($item->{itemnumber});
124 my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
126 if ( defined $reservedate ) {
127 $item->{backgroundcolor} = 'reserved';
128 $item->{reservedate} = format_date($reservedate);
129 $item->{ReservedForBorrowernumber} = $reservedfor;
130 $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
131 $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
132 $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname};
135 # Check the transit status
136 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber});
137 if ( $transfertwhen ne '' ) {
138 $item->{transfertwhen} = format_date($transfertwhen);
139 $item->{transfertfrom} = $branches->{$transfertfrom}{branchname};
140 $item->{transfertto} = $branches->{$transfertto}{branchname};
141 $item->{nocancel} = 1;
144 # FIXME: move this to a pm, check waiting status for holds
145 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
146 $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
147 while (my $wait_hashref = $sth2->fetchrow_hashref) {
148 $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
151 push @itemloop, $item;
154 $template->param( norequests => $norequests );
157 MARCNOTES => $marcnotesarray,
158 MARCSUBJCTS => $marcsubjctsarray,
159 MARCAUTHORS => $marcauthorsarray,
160 MARCSERIES => $marcseriesarray
163 my @results = ( $dat, );
164 foreach ( keys %{$dat} ) {
165 $template->param( "$_" => $dat->{$_} . "" );
169 itemloop => \@itemloop,
170 biblionumber => $biblionumber,
172 subscriptions => \@subs,
173 subscriptionsnumber => $subscriptionsnumber,
174 subscriptiontitle => $dat->{title},
178 my $xisbn=$dat->{'isbn'};
179 $xisbn =~ s/(p|-| |:)//g;
180 $template->param(amazonisbn => $xisbn);
181 if (C4::Context->preference("FRBRizeEditions")==1) {
185 XISBNS => get_xisbns($xisbn)
188 if ($@) { warn "XISBN Failed $@"; }
190 if ( C4::Context->preference("AmazonContent") == 1 ) {
191 my $similar_products_exist;
192 my $amazon_details = &get_amazon_details( $xisbn );
193 my $item_attributes = \%{$amazon_details->{Items}->{Item}->{ItemAttributes}};
194 my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
195 my @similar_products;
196 for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
197 # do we have any of these isbns in our collection?
198 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
199 # verify that there is at least one similar item
200 $similar_products_exist++ if ${@$similar_biblionumbers}[0];
201 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
203 my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
204 my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating};
205 $template->param( AmazonSimilarItems => $similar_products_exist );
206 $template->param( amazon_average_rating => $average_rating * 20);
207 $template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
208 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
209 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
211 output_html_with_http_headers $query, $cookie, $template->output;