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_biblio_from_xisbn);
38 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
40 template_name => "catalogue/detail.tmpl",
44 flagsrequired => { catalogue => 1 },
48 my $biblionumber = $query->param('biblionumber');
49 my $fw = GetFrameworkCode($biblionumber);
51 # Get Branches, Itemtypes and Locations
52 my $branches = GetBranches();
53 my $itemtypes = GetItemTypes();
56 # FIXME: move this to a pm, check waiting status for holds
57 my $dbh = C4::Context->dbh;
58 my $lsch = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category = 'LOC'");
60 while (my $ldata = $lsch->fetchrow_hashref ) {
61 $locations{ $ldata->{'authorised_value'} } = $ldata->{'lib'};
64 # change back when ive fixed request.pl
65 my @items = &GetItemsInfo( $biblionumber, 'intra' );
66 my $dat = &GetBiblioData($biblionumber);
69 print $query->redirect("/cgi-bin/koha/koha-tmpl/errors/404.pl");
73 #coping with subscriptions
74 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
75 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
78 foreach my $subscription (@subscriptions) {
80 $cell{subscriptionid} = $subscription->{subscriptionid};
81 $cell{subscriptionnotes} = $subscription->{notes};
83 #get the three latest serials.
84 $cell{latestserials} =
85 GetLatestSerials( $subscription->{subscriptionid}, 3 );
88 $dat->{imageurl} = getitemtypeimagesrc() . "/".$itemtypes->{ $dat->{itemtype} }{imageurl};
89 $dat->{'count'} = @items;
92 foreach my $item (@items) {
94 # can place holds defaults to yes
95 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
97 # format some item fields for display
98 $item->{ $item->{'publictype'} } = 1;
99 $item->{imageurl} = getitemtypeimagesrc() . "/".$itemtypes->{ $item->{itype} }{imageurl};
100 $item->{datedue} = format_date($item->{datedue});
101 $item->{datelastseen} = format_date($item->{datelastseen});
102 $item->{onloan} = format_date($item->{onloan});
103 $item->{locationname} = $locations{$item->{location}};
104 # item damaged, lost, withdrawn loops
105 $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
106 if ($item->{damaged}) {
107 $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
109 #get collection code description, too
110 $item->{'ccode'} = GetAuthorisedValueDesc('','', $item->{'ccode'} ,'','','ccode');
113 my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($item->{itemnumber});
114 my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
116 if ( defined $reservedate ) {
117 $item->{backgroundcolor} = 'reserved';
118 $item->{reservedate} = format_date($reservedate);
119 $item->{ReservedForBorrowernumber} = $reservedfor;
120 $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
121 $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
122 $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname};
125 # Check the transit status
126 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber});
127 if ( $transfertwhen ne '' ) {
128 $item->{transfertwhen} = format_date($transfertwhen);
129 $item->{transfertfrom} = $branches->{$transfertfrom}{branchname};
130 $item->{transfertto} = $branches->{$transfertto}{branchname};
131 $item->{nocancel} = 1;
134 # FIXME: move this to a pm, check waiting status for holds
135 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W' AND cancellationdate IS NULL");
136 $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
137 while (my $wait_hashref = $sth2->fetchrow_hashref) {
138 $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
141 push @itemloop, $item;
144 $template->param( norequests => $norequests );
146 ## get notes and subjects from MARC record
147 my $marcflavour = C4::Context->preference("marcflavour");
148 my $record = GetMarcBiblio($biblionumber);
149 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
150 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
151 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
154 MARCNOTES => $marcnotesarray,
155 MARCSUBJCTS => $marcsubjctsarray,
156 MARCAUTHORS => $marcauthorsarray
159 my @results = ( $dat, );
160 foreach ( keys %{$dat} ) {
161 $template->param( "$_" => $dat->{$_} . "" );
165 itemloop => \@itemloop,
166 biblionumber => $biblionumber,
168 subscriptions => \@subs,
169 subscriptionsnumber => $subscriptionsnumber,
170 subscriptiontitle => $dat->{title},
174 my $xisbn=$dat->{'isbn'};
175 $xisbn =~ s/(p|-| |:)//g;
176 $template->param(amazonisbn => $xisbn);
177 if (C4::Context->preference("FRBRizeEditions")==1) {
181 XISBNS => get_xisbns($xisbn)
184 if ($@) { warn "XISBN Failed $@"; }
186 if ( C4::Context->preference("AmazonContent") == 1 ) {
187 my $amazon_details = &get_amazon_details( $xisbn );
188 foreach my $result ( @{ $amazon_details->{Details} } ) {
189 $template->param( item_description => $result->{ProductDescription} );
190 $template->param( image => $result->{ImageUrlMedium} );
191 $template->param( list_price => $result->{ListPrice} );
192 $template->param( amazon_url => $result->{url} );
197 for my $details ( @{ $amazon_details->{Details} } ) {
199 next unless $details->{SimilarProducts};
200 for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
201 if (C4::Context->preference("AmazonSimilarItems") ) {
203 if (C4::Context->preference("XISBNAmazonSimilarItems") ) {
204 @xisbns = @{get_xisbns($product)};
207 push @xisbns, get_biblio_from_xisbn($product);
209 push @products, +{ product => \@xisbns };
212 next unless $details->{Reviews};
213 for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
214 $template->param( rating => $product * 20 );
216 for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
219 summary => $reviews->{Summary},
220 comment => $reviews->{Comment},
224 $template->param( SIMILAR_PRODUCTS => \@products );
225 $template->param( AMAZONREVIEWS => \@reviews );
228 output_html_with_http_headers $query, $cookie, $template->output;