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
33 use C4::XISBN qw(get_xisbns get_biblio_from_xisbn);
37 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
39 template_name => "catalogue/detail.tmpl",
43 flagsrequired => { catalogue => 1 },
47 my $biblionumber = $query->param('biblionumber');
48 my $fw = GetFrameworkCode($biblionumber);
50 # Get Branches, Itemtypes and Locations
51 my $branches = GetBranches();
52 my $itemtypes = GetItemTypes();
55 # FIXME: move this to a pm, check waiting status for holds
56 my $dbh = C4::Context->dbh;
57 my $lsch = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category = 'LOC'");
59 while (my $ldata = $lsch->fetchrow_hashref ) {
60 $locations{ $ldata->{'authorised_value'} } = $ldata->{'lib'};
63 # change back when ive fixed request.pl
64 my @items = &GetItemsInfo( $biblionumber, 'intra' );
65 my $dat = &GetBiblioData($biblionumber);
68 print $query->redirect("/cgi-bin/koha/koha-tmpl/errors/404.pl");
71 #coping with subscriptions
72 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
73 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
76 foreach my $subscription (@subscriptions) {
78 $cell{subscriptionid} = $subscription->{subscriptionid};
79 $cell{subscriptionnotes} = $subscription->{notes};
81 #get the three latest serials.
82 $cell{latestserials} =
83 GetLatestSerials( $subscription->{subscriptionid}, 3 );
86 $dat->{imageurl} = getitemtypeimagesrc() . "/".$itemtypes->{ $dat->{itemtype} }{imageurl};
87 $dat->{'count'} = @items;
90 foreach my $item (@items) {
92 # can place holds defaults to yes
93 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
95 # format some item fields for display
96 $item->{ $item->{'publictype'} } = 1;
97 $item->{imageurl} = getitemtypeimagesrc() . "/".$itemtypes->{ $item->{itype} }{imageurl};
98 $item->{datedue} = format_date($item->{datedue});
99 $item->{datelastseen} = format_date($item->{datelastseen});
100 $item->{onloan} = format_date($item->{onloan});
101 $item->{locationname} = $locations{$item->{location}};
102 # item damaged, lost, withdrawn loops
103 $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
104 if ($item->{damaged}) {
105 $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
109 my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($item->{itemnumber});
110 my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
112 if ( defined $reservedate ) {
113 $item->{backgroundcolor} = 'reserved';
114 $item->{reservedate} = format_date($reservedate);
115 $item->{ReservedForBorrowernumber} = $reservedfor;
116 $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
117 $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
118 $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname};
121 # Check the transit status
122 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber});
123 if ( $transfertwhen ne '' ) {
124 $item->{transfertwhen} = format_date($transfertwhen);
125 $item->{transfertfrom} = $branches->{$transfertfrom}{branchname};
126 $item->{transfertto} = $branches->{$transfertto}{branchname};
127 $item->{nocancel} = 1;
130 # FIXME: move this to a pm, check waiting status for holds
131 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W' AND cancellationdate IS NULL");
132 $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
133 while (my $wait_hashref = $sth2->fetchrow_hashref) {
134 $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
137 push @itemloop, $item;
140 $template->param( norequests => $norequests );
142 ## get notes and subjects from MARC record
143 my $dbh = C4::Context->dbh;
144 my $marcflavour = C4::Context->preference("marcflavour");
145 my $record = GetMarcBiblio($biblionumber);
146 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
147 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
148 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
151 MARCNOTES => $marcnotesarray,
152 MARCSUBJCTS => $marcsubjctsarray,
153 MARCAUTHORS => $marcauthorsarray
156 my @results = ( $dat, );
157 foreach ( keys %{$dat} ) {
158 $template->param( "$_" => $dat->{$_} . "" );
162 itemloop => \@itemloop,
163 biblionumber => $biblionumber,
165 subscriptions => \@subs,
166 subscriptionsnumber => $subscriptionsnumber,
167 subscriptiontitle => $dat->{title},
171 my $xisbn=$dat->{'isbn'};
172 $xisbn =~ s/(p|-| |:)//g;
173 $template->param(amazonisbn => $xisbn);
174 if (C4::Context->preference("FRBRizeEditions")==1) {
178 XISBNS => get_xisbns($xisbn)
181 if ($@) { warn "XISBN Failed $@"; }
183 if ( C4::Context->preference("AmazonContent") == 1 ) {
184 my $amazon_details = &get_amazon_details( $xisbn );
185 foreach my $result ( @{ $amazon_details->{Details} } ) {
186 $template->param( item_description => $result->{ProductDescription} );
187 $template->param( image => $result->{ImageUrlMedium} );
188 $template->param( list_price => $result->{ListPrice} );
189 $template->param( amazon_url => $result->{url} );
194 for my $details ( @{ $amazon_details->{Details} } ) {
196 next unless $details->{SimilarProducts};
197 for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
198 if (C4::Context->preference("AmazonSimilarItems") ) {
200 if (C4::Context->preference("XISBNAmazonSimilarItems") ) {
201 @xisbns = @{get_xisbns($product)};
204 push @xisbns, get_biblio_from_xisbn($product);
206 push @products, +{ product => \@xisbns };
209 next unless $details->{Reviews};
210 for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
211 $template->param( rating => $product * 20 );
213 for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
216 summary => $reviews->{Summary},
217 comment => $reviews->{Comment},
221 $template->param( SIMILAR_PRODUCTS => \@products );
222 $template->param( AMAZONREVIEWS => \@reviews );
225 output_html_with_http_headers $query, $cookie, $template->output;