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
32 use C4::XISBN qw(get_xisbns get_biblio_from_xisbn);
36 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
38 template_name => "catalogue/detail.tmpl",
42 flagsrequired => { catalogue => 1 },
46 my $biblionumber = $query->param('biblionumber');
47 my $fw = GetFrameworkCode($biblionumber);
49 # Get Branches, Itemtypes and Locations
50 my $branches = GetBranches();
51 my $itemtypes = GetItemTypes();
54 # FIXME: move this to a pm, check waiting status for holds
55 my $dbh = C4::Context->dbh;
56 my $lsch = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category = 'SHELF_LOC'");
58 while (my $ldata = $lsch->fetchrow_hashref ) {
59 $locations{ $ldata->{'authorised_value'} } = $ldata->{'lib'};
62 # change back when ive fixed request.pl
63 my @items = &GetItemsInfo( $biblionumber, 'intra' );
64 my $dat = &GetBiblioData($biblionumber);
67 print $query->redirect("/cgi-bin/koha/koha-tmpl/errors/404.pl");
70 #coping with subscriptions
71 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
72 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
75 foreach my $subscription (@subscriptions) {
77 $cell{subscriptionid} = $subscription->{subscriptionid};
78 $cell{subscriptionnotes} = $subscription->{notes};
80 #get the three latest serials.
81 $cell{latestserials} =
82 GetLatestSerials( $subscription->{subscriptionid}, 3 );
85 $dat->{imageurl} = getitemtypeimagesrc() . "/".$itemtypes->{ $dat->{itemtype} }{imageurl};
86 $dat->{'count'} = @items;
89 foreach my $item (@items) {
91 # can place holds defaults to yes
92 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
94 # format some item fields for display
95 $item->{ $item->{'publictype'} } = 1;
96 $item->{imageurl} = getitemtypeimagesrc() . "/".$itemtypes->{ $item->{itype} }{imageurl};
97 $item->{datedue} = format_date($item->{datedue});
98 $item->{datelastseen} = format_date($item->{datelastseen});
99 $item->{onloan} = format_date($item->{onloan});
100 $item->{locationname} = $locations{$item->{location}};
101 # item damaged, lost, withdrawn loops
102 $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
103 if ($item->{damaged}) {
104 $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
108 my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($item->{itemnumber});
109 my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
111 if ( defined $reservedate ) {
112 $item->{backgroundcolor} = 'reserved';
113 $item->{reservedate} = format_date($reservedate);
114 $item->{ReservedForBorrowernumber} = $reservedfor;
115 $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
116 $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
117 $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname};
120 # FIXME: move this to a pm, check waiting status for holds
121 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W' AND cancellationdate IS NULL");
122 $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
123 while (my $wait_hashref = $sth2->fetchrow_hashref) {
124 $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
127 push @itemloop, $item;
130 $template->param( norequests => $norequests );
132 ## get notes and subjects from MARC record
133 my $dbh = C4::Context->dbh;
134 my $marcflavour = C4::Context->preference("marcflavour");
135 my $record = GetMarcBiblio($biblionumber);
136 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
137 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
138 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
141 MARCNOTES => $marcnotesarray,
142 MARCSUBJCTS => $marcsubjctsarray,
143 MARCAUTHORS => $marcauthorsarray
146 my @results = ( $dat, );
147 foreach ( keys %{$dat} ) {
148 $template->param( "$_" => $dat->{$_} . "" );
152 itemloop => \@itemloop,
153 biblionumber => $biblionumber,
155 subscriptions => \@subs,
156 subscriptionsnumber => $subscriptionsnumber,
157 subscriptiontitle => $dat->{title},
161 my $xisbn=$dat->{'isbn'};
162 $xisbn =~ s/(p|-| |:)//g;
163 $template->param(amazonisbn => $xisbn);
164 if (C4::Context->preference("FRBRizeEditions")==1) {
168 XISBNS => get_xisbns($xisbn)
171 if ($@) { warn "XISBN Failed $@"; }
173 if ( C4::Context->preference("AmazonContent") == 1 ) {
174 my $amazon_details = &get_amazon_details( $xisbn );
175 foreach my $result ( @{ $amazon_details->{Details} } ) {
176 $template->param( item_description => $result->{ProductDescription} );
177 $template->param( image => $result->{ImageUrlMedium} );
178 $template->param( list_price => $result->{ListPrice} );
179 $template->param( amazon_url => $result->{url} );
184 for my $details ( @{ $amazon_details->{Details} } ) {
186 next unless $details->{SimilarProducts};
187 for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
188 if (C4::Context->preference("AmazonSimilarItems") ) {
190 if (C4::Context->preference("XISBNAmazonSimilarItems") ) {
191 @xisbns = @{get_xisbns($product)};
194 push @xisbns, get_biblio_from_xisbn($product);
196 push @products, +{ product => \@xisbns };
199 next unless $details->{Reviews};
200 for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
201 $template->param( rating => $product * 20 );
203 for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
206 summary => $reviews->{Summary},
207 comment => $reviews->{Comment},
211 $template->param( SIMILAR_PRODUCTS => \@products );
212 $template->param( AMAZONREVIEWS => \@reviews );
215 output_html_with_http_headers $query, $cookie, $template->output;