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
33 use C4::Members; # to use GetMember
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 if($query->cookie("holdfor")){
55 my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
57 holdfor => $query->cookie("holdfor"),
58 holdfor_surname => $holdfor_patron->{'surname'},
59 holdfor_firstname => $holdfor_patron->{'firstname'},
60 holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
64 my $biblionumber = $query->param('biblionumber');
65 my $fw = GetFrameworkCode($biblionumber);
67 ## get notes and subjects from MARC record
68 my $marcflavour = C4::Context->preference("marcflavour");
69 my $record = GetMarcBiblio($biblionumber);
71 # XSLT processing of some stuff
72 if (C4::Context->preference("XSLTDetailsDisplay") ) {
73 $template->param('XSLTDetailsDisplay' =>'1',
74 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, 'Detail','intranet') );
77 $template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
79 # some useful variables for enhanced content;
80 # in each case, we're grabbing the first value we find in
81 # the record and normalizing it
82 my $upc = GetNormalizedUPC($record,$marcflavour);
83 my $ean = GetNormalizedEAN($record,$marcflavour);
84 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
85 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
88 normalized_upc => $upc,
89 normalized_ean => $ean,
90 normalized_oclc => $oclc,
91 normalized_isbn => $isbn,
94 unless (defined($record)) {
95 print $query->redirect("/cgi-bin/koha/errors/404.pl");
99 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
100 my $marcisbnsarray = GetMarcISBN( $record, $marcflavour );
101 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
102 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
103 my $marcseriesarray = GetMarcSeries($record,$marcflavour);
104 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
105 my $subtitle = GetRecordValue('subtitle', $record, $fw);
107 # Get Branches, Itemtypes and Locations
108 my $branches = GetBranches();
109 my $itemtypes = GetItemTypes();
110 my $dbh = C4::Context->dbh;
112 # change back when ive fixed request.pl
113 my @items = &GetItemsInfo( $biblionumber, 'intra' );
114 my $dat = &GetBiblioData($biblionumber);
117 my ( $holdcount, $holds ) = GetReservesFromBiblionumber($biblionumber,1);
119 #coping with subscriptions
120 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
121 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
124 foreach my $subscription (@subscriptions) {
126 my $serials_to_display;
127 $cell{subscriptionid} = $subscription->{subscriptionid};
128 $cell{subscriptionnotes} = $subscription->{notes};
129 $cell{branchcode} = $subscription->{branchcode};
130 $cell{branchname} = GetBranchName($subscription->{branchcode});
131 $cell{hasalert} = $subscription->{hasalert};
132 #get the three latest serials.
133 $serials_to_display = $subscription->{staffdisplaycount};
134 $serials_to_display = C4::Context->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
135 $cell{staffdisplaycount} = $serials_to_display;
136 $cell{latestserials} =
137 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
141 if ( defined $dat->{'itemtype'} ) {
142 $dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }{imageurl} );
144 $dat->{'count'} = scalar @items;
145 my $shelflocations = GetKohaAuthorisedValues('items.location', $fw);
146 my $collections = GetKohaAuthorisedValues('items.ccode' , $fw);
147 my (@itemloop, %itemfields);
149 my $authvalcode_items_itemlost = GetAuthValCode('items.itemlost',$fw);
150 my $authvalcode_items_damaged = GetAuthValCode('items.damaged', $fw);
151 foreach my $item (@items) {
153 $item->{homebranch} = GetBranchName($item->{homebranch});
155 # can place holds defaults to yes
156 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
158 # format some item fields for display
159 if ( defined $item->{'publictype'} ) {
160 $item->{ $item->{'publictype'} } = 1;
162 $item->{imageurl} = defined $item->{itype} ? getitemtypeimagelocation('intranet', $itemtypes->{ $item->{itype} }{imageurl})
165 foreach (qw(datedue datelastseen onloan)) {
166 $item->{$_} = format_date($item->{$_});
168 # item damaged, lost, withdrawn loops
169 $item->{itemlostloop} = GetAuthorisedValues($authvalcode_items_itemlost, $item->{itemlost}) if $authvalcode_items_itemlost;
170 if ($item->{damaged}) {
171 $item->{itemdamagedloop} = GetAuthorisedValues($authvalcode_items_damaged, $item->{damaged}) if $authvalcode_items_damaged;
173 #get shelf location and collection code description if they are authorised value.
174 my $shelfcode = $item->{'location'};
175 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
176 my $ccode = $item->{'ccode'};
177 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
178 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
179 $itemfields{$_} = 1 if ( $item->{$_} );
183 my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($item->{itemnumber});
184 my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
186 if (C4::Context->preference('HidePatronName')){
187 $item->{'hidepatronname'} = 1;
190 if ( defined $reservedate ) {
191 $item->{backgroundcolor} = 'reserved';
192 $item->{reservedate} = format_date($reservedate);
193 $item->{ReservedForBorrowernumber} = $reservedfor;
194 $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
195 $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
196 $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname};
197 $item->{Reservedcardnumber} = $ItemBorrowerReserveInfo->{'cardnumber'};
200 # Check the transit status
201 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber});
202 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
203 $item->{transfertwhen} = format_date($transfertwhen);
204 $item->{transfertfrom} = $branches->{$transfertfrom}{branchname};
205 $item->{transfertto} = $branches->{$transfertto}{branchname};
206 $item->{nocancel} = 1;
209 # FIXME: move this to a pm, check waiting status for holds
210 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
211 $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
212 while (my $wait_hashref = $sth2->fetchrow_hashref) {
213 $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
216 push @itemloop, $item;
219 $template->param( norequests => $norequests );
221 MARCNOTES => $marcnotesarray,
222 MARCSUBJCTS => $marcsubjctsarray,
223 MARCAUTHORS => $marcauthorsarray,
224 MARCSERIES => $marcseriesarray,
225 MARCURLS => $marcurlsarray,
226 MARCISBNS => $marcisbnsarray,
227 subtitle => $subtitle,
228 itemdata_ccode => $itemfields{ccode},
229 itemdata_enumchron => $itemfields{enumchron},
230 itemdata_uri => $itemfields{uri},
231 itemdata_copynumber => $itemfields{copynumber},
232 volinfo => $itemfields{enumchron},
233 itemdata_itemnotes => $itemfields{itemnotes},
234 z3950_search_params => C4::Search::z3950_search_args($dat),
235 holdcount => $holdcount,
236 C4::Search::enabled_staff_search_views,
239 my @results = ( $dat, );
240 foreach ( keys %{$dat} ) {
241 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
244 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
245 # method query not found?!?!
248 itemloop => \@itemloop,
249 biblionumber => $biblionumber,
251 subscriptions => \@subs,
252 subscriptionsnumber => $subscriptionsnumber,
253 subscriptiontitle => $dat->{title},
256 # $debug and $template->param(debug_display => 1);
260 if (C4::Context->preference("virtualshelves") ) {
261 $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
265 if (C4::Context->preference("FRBRizeEditions")==1) {
268 XISBNS => get_xisbns($isbn)
271 if ($@) { warn "XISBN Failed $@"; }
273 if ( C4::Context->preference("AmazonEnabled") == 1 ) {
274 $template->param( AmazonTld => get_amazon_tld() );
275 my $amazon_reviews = C4::Context->preference("AmazonReviews");
276 my $amazon_similars = C4::Context->preference("AmazonSimilarItems");
278 if ( $amazon_reviews ) {
279 $template->param( AmazonReviews => 1 );
280 push( @services, 'EditorialReview' );
282 if ( $amazon_similars ) {
283 $template->param( AmazonSimilarItems => 1 );
284 push( @services, 'Similarities' );
286 my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour, \@services );
287 if ( $amazon_similars ) {
288 my $similar_products_exist;
289 my @similar_products;
290 for my $similar_product (@{$amazon_details->{Items}->{Item}->[0]->{SimilarProducts}->{SimilarProduct}}) {
291 # do we have any of these isbns in our collection?
292 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
293 # verify that there is at least one similar item
294 if (scalar(@$similar_biblionumbers)){
295 $similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
296 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
299 $template->param( AmazonSimilarItems => $similar_products_exist );
300 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
302 if ( $amazon_reviews ) {
303 my $item = $amazon_details->{Items}->{Item}->[0];
304 my $editorial_reviews = \@{ $item->{EditorialReviews}->{EditorialReview} };
305 #my $customer_reviews = \@{$amazon_details->{Items}->{Item}->[0]->{CustomerReviews}->{Review}};
306 #my $average_rating = $amazon_details->{Items}->{Item}->[0]->{CustomerReviews}->{AverageRating} || 0;
307 #$template->param( amazon_average_rating => $average_rating * 20 );
308 #$template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
309 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
314 if (C4::Context->preference('OPACBaseURL')){
315 $template->param( OpacUrl => C4::Context->preference('OPACBaseURL') );
318 output_html_with_http_headers $query, $cookie, $template->output;