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
38 use C4::VirtualShelves;
41 # use Smart::Comments;
43 my $query = CGI->new();
44 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
46 template_name => "catalogue/detail.tmpl",
50 flagsrequired => { catalogue => 1 },
54 my $biblionumber = $query->param('biblionumber');
55 my $fw = GetFrameworkCode($biblionumber);
57 ## get notes and subjects from MARC record
58 my $marcflavour = C4::Context->preference("marcflavour");
59 my $record = GetMarcBiblio($biblionumber);
61 # XSLT processing of some stuff
62 if (C4::Context->preference("XSLTDetailsDisplay") ) {
63 $template->param('XSLTDetailsDisplay' =>'1',
64 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, 'Detail','intranet') );
67 $template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
69 # some useful variables for enhanced content;
70 # in each case, we're grabbing the first value we find in
71 # the record and normalizing it
72 my $upc = GetNormalizedUPC($record,$marcflavour);
73 my $ean = GetNormalizedEAN($record,$marcflavour);
74 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
75 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
78 normalized_upc => $upc,
79 normalized_ean => $ean,
80 normalized_oclc => $oclc,
81 normalized_isbn => $isbn,
84 unless (defined($record)) {
85 print $query->redirect("/cgi-bin/koha/errors/404.pl");
89 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
90 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
91 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
92 my $marcseriesarray = GetMarcSeries($record,$marcflavour);
93 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
94 my $subtitle = GetRecordValue('subtitle', $record, $fw);
96 # Get Branches, Itemtypes and Locations
97 my $branches = GetBranches();
98 my $itemtypes = GetItemTypes();
99 my $dbh = C4::Context->dbh;
101 # change back when ive fixed request.pl
102 my @items = &GetItemsInfo( $biblionumber, 'intra' );
103 my $dat = &GetBiblioData($biblionumber);
106 my ( $holdcount, $holds ) = GetReservesFromBiblionumber($biblionumber,1);
108 #coping with subscriptions
109 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
110 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
113 foreach my $subscription (@subscriptions) {
115 my $serials_to_display;
116 $cell{subscriptionid} = $subscription->{subscriptionid};
117 $cell{subscriptionnotes} = $subscription->{notes};
118 $cell{branchcode} = $subscription->{branchcode};
119 $cell{branchname} = GetBranchName($subscription->{branchcode});
120 $cell{hasalert} = $subscription->{hasalert};
121 #get the three latest serials.
122 $serials_to_display = $subscription->{staffdisplaycount};
123 $serials_to_display = C4::Context->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
124 $cell{staffdisplaycount} = $serials_to_display;
125 $cell{latestserials} =
126 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
130 if ( defined $dat->{'itemtype'} ) {
131 $dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }{imageurl} );
133 $dat->{'count'} = scalar @items;
134 my $shelflocations = GetKohaAuthorisedValues('items.location', $fw);
135 my $collections = GetKohaAuthorisedValues('items.ccode' , $fw);
136 my (@itemloop, %itemfields);
138 my $authvalcode_items_itemlost = GetAuthValCode('items.itemlost',$fw);
139 my $authvalcode_items_damaged = GetAuthValCode('items.damaged', $fw);
140 foreach my $item (@items) {
142 # can place holds defaults to yes
143 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
145 # format some item fields for display
146 if ( defined $item->{'publictype'} ) {
147 $item->{ $item->{'publictype'} } = 1;
149 $item->{imageurl} = defined $item->{itype} ? getitemtypeimagelocation('intranet', $itemtypes->{ $item->{itype} }{imageurl})
152 foreach (qw(datedue datelastseen onloan)) {
153 $item->{$_} = format_date($item->{$_});
155 # item damaged, lost, withdrawn loops
156 $item->{itemlostloop} = GetAuthorisedValues($authvalcode_items_itemlost, $item->{itemlost}) if $authvalcode_items_itemlost;
157 if ($item->{damaged}) {
158 $item->{itemdamagedloop} = GetAuthorisedValues($authvalcode_items_damaged, $item->{damaged}) if $authvalcode_items_damaged;
160 #get shelf location and collection code description if they are authorised value.
161 my $shelfcode = $item->{'location'};
162 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
163 my $ccode = $item->{'ccode'};
164 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
165 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
166 $itemfields{$_} = 1 if ( $item->{$_} );
170 my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($item->{itemnumber});
171 my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
173 if (C4::Context->preference('HidePatronName')){
174 $item->{'hidepatronname'} = 1;
177 if ( defined $reservedate ) {
178 $item->{backgroundcolor} = 'reserved';
179 $item->{reservedate} = format_date($reservedate);
180 $item->{ReservedForBorrowernumber} = $reservedfor;
181 $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
182 $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
183 $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname};
184 $item->{Reservedcardnumber} = $ItemBorrowerReserveInfo->{'cardnumber'};
187 # Check the transit status
188 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber});
189 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
190 $item->{transfertwhen} = format_date($transfertwhen);
191 $item->{transfertfrom} = $branches->{$transfertfrom}{branchname};
192 $item->{transfertto} = $branches->{$transfertto}{branchname};
193 $item->{nocancel} = 1;
196 # FIXME: move this to a pm, check waiting status for holds
197 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
198 $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
199 while (my $wait_hashref = $sth2->fetchrow_hashref) {
200 $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
203 push @itemloop, $item;
206 $template->param( norequests => $norequests );
208 MARCNOTES => $marcnotesarray,
209 MARCSUBJCTS => $marcsubjctsarray,
210 MARCAUTHORS => $marcauthorsarray,
211 MARCSERIES => $marcseriesarray,
212 MARCURLS => $marcurlsarray,
213 subtitle => $subtitle,
214 itemdata_ccode => $itemfields{ccode},
215 itemdata_enumchron => $itemfields{enumchron},
216 itemdata_uri => $itemfields{uri},
217 itemdata_copynumber => $itemfields{copynumber},
218 volinfo => $itemfields{enumchron},
219 itemdata_itemnotes => $itemfields{itemnotes},
220 z3950_search_params => C4::Search::z3950_search_args($dat),
221 holdcount => $holdcount,
222 C4::Search::enabled_staff_search_views,
225 my @results = ( $dat, );
226 foreach ( keys %{$dat} ) {
227 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
230 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
231 # method query not found?!?!
234 itemloop => \@itemloop,
235 biblionumber => $biblionumber,
237 subscriptions => \@subs,
238 subscriptionsnumber => $subscriptionsnumber,
239 subscriptiontitle => $dat->{title},
242 # $debug and $template->param(debug_display => 1);
246 if (C4::Context->preference("virtualshelves") ) {
247 $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
251 if (C4::Context->preference("FRBRizeEditions")==1) {
254 XISBNS => get_xisbns($isbn)
257 if ($@) { warn "XISBN Failed $@"; }
259 if ( C4::Context->preference("AmazonEnabled") == 1 ) {
260 $template->param( AmazonTld => get_amazon_tld() );
261 my $amazon_reviews = C4::Context->preference("AmazonReviews");
262 my $amazon_similars = C4::Context->preference("AmazonSimilarItems");
264 if ( $amazon_reviews ) {
265 $template->param( AmazonReviews => 1 );
266 push( @services, 'EditorialReview' );
268 if ( $amazon_similars ) {
269 $template->param( AmazonSimilarItems => 1 );
270 push( @services, 'Similarities' );
272 my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour, \@services );
273 if ( $amazon_similars ) {
274 my $similar_products_exist;
275 my @similar_products;
276 for my $similar_product (@{$amazon_details->{Items}->{Item}->[0]->{SimilarProducts}->{SimilarProduct}}) {
277 # do we have any of these isbns in our collection?
278 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
279 # verify that there is at least one similar item
280 if (scalar(@$similar_biblionumbers)){
281 $similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
282 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
285 $template->param( AmazonSimilarItems => $similar_products_exist );
286 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
288 if ( $amazon_reviews ) {
289 my $item = $amazon_details->{Items}->{Item}->[0];
290 my $editorial_reviews = \@{ $item->{EditorialReviews}->{EditorialReview} };
291 #my $customer_reviews = \@{$amazon_details->{Items}->{Item}->[0]->{CustomerReviews}->{Review}};
292 #my $average_rating = $amazon_details->{Items}->{Item}->[0]->{CustomerReviews}->{AverageRating} || 0;
293 #$template->param( amazon_average_rating => $average_rating * 20 );
294 #$template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
295 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
300 if (C4::Context->preference('OPACBaseURL')){
301 $template->param( OpacUrl => C4::Context->preference('OPACBaseURL') );
304 output_html_with_http_headers $query, $cookie, $template->output;