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
24 use C4
::Dates qw
/format_date/;
26 use C4
::Serials
; #uses getsubscriptionfrom biblionumber
35 use C4
::XISBN
qw(get_xisbns get_biblionumber_from_isbn);
36 use C4
::External
::Amazon
;
37 use C4
::Search
; # enabled_staff_search_views
39 # use Smart::Comments;
41 my $query = CGI
->new();
42 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
44 template_name
=> "catalogue/detail.tmpl",
48 flagsrequired
=> { catalogue
=> 1 },
52 my $biblionumber = $query->param('biblionumber');
53 my $fw = GetFrameworkCode
($biblionumber);
55 ## get notes and subjects from MARC record
56 my $marcflavour = C4
::Context
->preference("marcflavour");
57 my $record = GetMarcBiblio
($biblionumber);
59 # some useful variables for enhanced content;
60 # in each case, we're grabbing the first value we find in
61 # the record and normalizing it
62 my $upc = GetNormalizedUPC
($record,$marcflavour);
63 my $ean = GetNormalizedEAN
($record,$marcflavour);
64 my $oclc = GetNormalizedOCLCNumber
($record,$marcflavour);
65 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
68 normalized_upc
=> $upc,
69 normalized_ean
=> $ean,
70 normalized_oclc
=> $oclc,
71 normalized_isbn
=> $isbn,
74 unless (defined($record)) {
75 print $query->redirect("/cgi-bin/koha/errors/404.pl");
79 my $marcnotesarray = GetMarcNotes
( $record, $marcflavour );
80 my $marcauthorsarray = GetMarcAuthors
( $record, $marcflavour );
81 my $marcsubjctsarray = GetMarcSubjects
( $record, $marcflavour );
82 my $marcseriesarray = GetMarcSeries
($record,$marcflavour);
83 my $marcurlsarray = GetMarcUrls
($record,$marcflavour);
84 my $subtitle = C4
::Biblio
::get_koha_field_from_marc
('bibliosubtitle', 'subtitle', $record, '');
86 # Get Branches, Itemtypes and Locations
87 my $branches = GetBranches
();
88 my $itemtypes = GetItemTypes
();
89 my $dbh = C4
::Context
->dbh;
91 # change back when ive fixed request.pl
92 my @items = &GetItemsInfo
( $biblionumber, 'intra' );
93 my $dat = &GetBiblioData
($biblionumber);
95 #coping with subscriptions
96 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
97 my @subscriptions = GetSubscriptions
( $dat->{title
}, $dat->{issn
}, $biblionumber );
99 $dat->{'serial'}=1 if $subscriptionsnumber;
100 foreach my $subscription (@subscriptions) {
102 my $serials_to_display;
103 $cell{subscriptionid
} = $subscription->{subscriptionid
};
104 $cell{subscriptionnotes
} = $subscription->{notes
};
105 $cell{branchcode
} = $subscription->{branchcode
};
106 $cell{hasalert
} = $subscription->{hasalert
};
107 #get the three latest serials.
108 $serials_to_display = $subscription->{staffdisplaycount
};
109 $serials_to_display = C4
::Context
->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
110 $cell{staffdisplaycount
} = $serials_to_display;
111 $cell{latestserials
} =
112 GetLatestSerials
( $subscription->{subscriptionid
}, $serials_to_display );
116 if ( defined $dat->{'itemtype'} ) {
117 $dat->{imageurl
} = getitemtypeimagelocation
( 'intranet', $itemtypes->{ $dat->{itemtype
} }{imageurl
} );
119 $dat->{'count'} = scalar @items;
120 my $shelflocations = GetKohaAuthorisedValues
('items.location', $fw);
121 my $collections = GetKohaAuthorisedValues
('items.ccode' , $fw);
122 my (@itemloop, %itemfields);
124 my $authvalcode_items_itemlost = GetAuthValCode
('items.itemlost',$fw);
125 my $authvalcode_items_damaged = GetAuthValCode
('items.damaged', $fw);
126 foreach my $item (@items) {
128 # can place holds defaults to yes
129 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
131 # format some item fields for display
132 if ( defined $item->{'publictype'} ) {
133 $item->{ $item->{'publictype'} } = 1;
135 $item->{imageurl
} = defined $item->{itype
} ? getitemtypeimagelocation
('intranet', $itemtypes->{ $item->{itype
} }{imageurl
})
138 foreach (qw(datedue datelastseen onloan)) {
139 $item->{$_} = format_date
($item->{$_});
141 # item damaged, lost, withdrawn loops
142 $item->{itemlostloop
} = GetAuthorisedValues
($authvalcode_items_itemlost, $item->{itemlost
}) if $authvalcode_items_itemlost;
143 if ($item->{damaged
}) {
144 $item->{itemdamagedloop
} = GetAuthorisedValues
($authvalcode_items_damaged, $item->{damaged
}) if $authvalcode_items_damaged;
146 #get shelf location and collection code description if they are authorised value.
147 my $shelfcode = $item->{'location'};
148 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
149 my $ccode = $item->{'ccode'};
150 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
151 foreach (qw(ccode enumchron copynumber uri)) {
152 $itemfields{$_} = 1 if ( $item->{$_} );
156 my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber
($item->{itemnumber
});
157 my $ItemBorrowerReserveInfo = GetMemberDetails
( $reservedfor, 0);
159 if (C4
::Context
->preference('HidePatronName')){
160 $item->{'hidepatronname'} = 1;
163 if ( defined $reservedate ) {
164 $item->{backgroundcolor
} = 'reserved';
165 $item->{reservedate
} = format_date
($reservedate);
166 $item->{ReservedForBorrowernumber
} = $reservedfor;
167 $item->{ReservedForSurname
} = $ItemBorrowerReserveInfo->{'surname'};
168 $item->{ReservedForFirstname
} = $ItemBorrowerReserveInfo->{'firstname'};
169 $item->{ExpectedAtLibrary
} = $branches->{$expectedAt}{branchname
};
170 $item->{cardnumber
} = $ItemBorrowerReserveInfo->{'cardnumber'};
173 # Check the transit status
174 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers
($item->{itemnumber
});
175 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
176 $item->{transfertwhen
} = format_date
($transfertwhen);
177 $item->{transfertfrom
} = $branches->{$transfertfrom}{branchname
};
178 $item->{transfertto
} = $branches->{$transfertto}{branchname
};
179 $item->{nocancel
} = 1;
182 # FIXME: move this to a pm, check waiting status for holds
183 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
184 $sth2->execute($item->{ReservedForBorrowernumber
},$item->{itemnumber
});
185 while (my $wait_hashref = $sth2->fetchrow_hashref) {
186 $item->{waitingdate
} = format_date
($wait_hashref->{waitingdate
});
189 push @itemloop, $item;
192 $template->param( norequests
=> $norequests );
194 MARCNOTES
=> $marcnotesarray,
195 MARCSUBJCTS
=> $marcsubjctsarray,
196 MARCAUTHORS
=> $marcauthorsarray,
197 MARCSERIES
=> $marcseriesarray,
198 MARCURLS
=> $marcurlsarray,
199 subtitle
=> $subtitle,
200 itemdata_ccode
=> $itemfields{ccode
},
201 itemdata_enumchron
=> $itemfields{enumchron
},
202 itemdata_uri
=> $itemfields{uri
},
203 itemdata_copynumber
=> $itemfields{copynumber
},
204 volinfo
=> $itemfields{enumchron
} || $dat->{'serial'} ,
205 z3950_search_params
=> C4
::Search
::z3950_search_args
($dat),
206 C4
::Search
::enabled_staff_search_views
,
209 my @results = ( $dat, );
210 foreach ( keys %{$dat} ) {
211 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
214 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
215 # method query not found?!?!
218 itemloop
=> \
@itemloop,
219 biblionumber
=> $biblionumber,
221 subscriptions
=> \
@subs,
222 subscriptionsnumber
=> $subscriptionsnumber,
223 subscriptiontitle
=> $dat->{title
},
226 # $debug and $template->param(debug_display => 1);
229 if (C4
::Context
->preference("FRBRizeEditions")==1) {
232 XISBNS
=> get_xisbns
($isbn)
235 if ($@
) { warn "XISBN Failed $@"; }
237 if ( C4
::Context
->preference("AmazonEnabled") == 1 ) {
238 $template->param( AmazonTld
=> get_amazon_tld
() );
239 my $amazon_reviews = C4
::Context
->preference("AmazonReviews");
240 my $amazon_similars = C4
::Context
->preference("AmazonSimilarItems");
242 if ( $amazon_reviews ) {
243 $template->param( AmazonReviews
=> 1 );
244 push( @services, 'EditorialReview' );
246 if ( $amazon_similars ) {
247 $template->param( AmazonSimilarItems
=> 1 );
248 push( @services, 'Similarities' );
250 my $amazon_details = &get_amazon_details
( $isbn, $record, $marcflavour, \
@services );
251 if ( $amazon_similars ) {
252 my $similar_products_exist;
253 my @similar_products;
254 for my $similar_product (@
{$amazon_details->{Items
}->{Item
}->[0]->{SimilarProducts
}->{SimilarProduct
}}) {
255 # do we have any of these isbns in our collection?
256 my $similar_biblionumbers = get_biblionumber_from_isbn
($similar_product->{ASIN
});
257 # verify that there is at least one similar item
258 if (scalar(@
$similar_biblionumbers)){
259 $similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
260 push @similar_products, +{ similar_biblionumbers
=> $similar_biblionumbers, title
=> $similar_product->{Title
}, ASIN
=> $similar_product->{ASIN
} };
263 $template->param( AmazonSimilarItems
=> $similar_products_exist );
264 $template->param( AMAZON_SIMILAR_PRODUCTS
=> \
@similar_products );
266 if ( $amazon_reviews ) {
267 my $item = $amazon_details->{Items
}->{Item
}->[0];
268 my $editorial_reviews = \@
{ $item->{EditorialReviews
}->{EditorialReview
} };
269 #my $customer_reviews = \@{$amazon_details->{Items}->{Item}->[0]->{CustomerReviews}->{Review}};
270 #my $average_rating = $amazon_details->{Items}->{Item}->[0]->{CustomerReviews}->{AverageRating} || 0;
271 #$template->param( amazon_average_rating => $average_rating * 20 );
272 #$template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
273 $template->param( AMAZON_EDITORIAL_REVIEWS
=> $editorial_reviews );
278 if (C4
::Context
->preference('OPACBaseURL')){
279 $template->param( OpacUrl
=> C4
::Context
->preference('OPACBaseURL') );
282 output_html_with_http_headers
$query, $cookie, $template->output;