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();
45 my $analyze = $query->param('analyze');
47 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
49 template_name => 'catalogue/detail.tmpl',
53 flagsrequired => { catalogue => 1 },
57 my $biblionumber = $query->param('biblionumber');
58 my $record = GetMarcBiblio($biblionumber);
60 if ( not defined $record ) {
61 # biblionumber invalid -> report and exit
62 $template->param( unknownbiblionumber => 1,
63 biblionumber => $biblionumber );
64 output_html_with_http_headers $query, $cookie, $template->output;
68 if($query->cookie("holdfor")){
69 my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
71 holdfor => $query->cookie("holdfor"),
72 holdfor_surname => $holdfor_patron->{'surname'},
73 holdfor_firstname => $holdfor_patron->{'firstname'},
74 holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
78 my $fw = GetFrameworkCode($biblionumber);
79 my $showallitems = $query->param('showallitems');
80 my $marcflavour = C4::Context->preference("marcflavour");
82 # XSLT processing of some stuff
83 if (C4::Context->preference("XSLTDetailsDisplay") ) {
84 $template->param('XSLTDetailsDisplay' =>'1',
85 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, 'Detail','intranet') );
88 $template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
90 # some useful variables for enhanced content;
91 # in each case, we're grabbing the first value we find in
92 # the record and normalizing it
93 my $upc = GetNormalizedUPC($record,$marcflavour);
94 my $ean = GetNormalizedEAN($record,$marcflavour);
95 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
96 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
99 normalized_upc => $upc,
100 normalized_ean => $ean,
101 normalized_oclc => $oclc,
102 normalized_isbn => $isbn,
105 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
106 my $marcisbnsarray = GetMarcISBN( $record, $marcflavour );
107 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
108 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
109 my $marcseriesarray = GetMarcSeries($record,$marcflavour);
110 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
111 my $marchostsarray = GetMarcHosts($record,$marcflavour);
112 my $subtitle = GetRecordValue('subtitle', $record, $fw);
113 my $partnum = GetRecordValue('partnum', $record, $fw);
114 my $partname = GetRecordValue('partname', $record, $fw);
115 my $medium = GetRecordValue('medium', $record, $fw);
116 my $responsibility = GetRecordValue('responsibility', $record, $fw);
117 my $impressum = GetRecordValue('impressum', $record, $fw);
118 my $oldcall = GetRecordValue('oldcall', $record, $fw);
119 my $udc = GetRecordValue('udc', $record, $fw);
120 my $textholding = GetRecordValue('textholding', $record, $fw);
122 # Get Branches, Itemtypes and Locations
123 my $branches = GetBranches();
124 my $itemtypes = GetItemTypes();
125 my $dbh = C4::Context->dbh;
127 my @all_items = GetItemsInfo( $biblionumber );
129 for my $itm (@all_items) {
130 push @items, $itm unless ( $itm->{itemlost} && GetHideLostItemsPreference($borrowernumber) && !$showallitems);
133 # flag indicating existence of at least one item linked via a host record
135 # adding items linked via host biblios
136 my @hostitems = GetHostItemsInfo($record);
139 push (@items,@hostitems);
142 my $dat = &GetBiblioData($biblionumber);
145 my ( $holdcount, $holds ) = GetReservesFromBiblionumber($biblionumber,1);
147 #coping with subscriptions
148 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
149 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
152 foreach my $subscription (@subscriptions) {
154 my $serials_to_display;
155 $cell{subscriptionid} = $subscription->{subscriptionid};
156 $cell{subscriptionnotes} = $subscription->{notes};
157 $cell{branchcode} = $subscription->{branchcode};
158 $cell{branchname} = GetBranchName($subscription->{branchcode});
159 $cell{hasalert} = $subscription->{hasalert};
160 #get the three latest serials.
161 $serials_to_display = $subscription->{staffdisplaycount};
162 $serials_to_display = C4::Context->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
163 $cell{staffdisplaycount} = $serials_to_display;
164 $cell{latestserials} =
165 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
169 if ( defined $dat->{'itemtype'} ) {
170 $dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }{imageurl} );
173 $dat->{'count'} = scalar @all_items + @hostitems;
174 $dat->{'showncount'} = scalar @items + @hostitems;
175 $dat->{'hiddencount'} = scalar @all_items + @hostitems - scalar @items;
177 my $shelflocations = GetKohaAuthorisedValues('items.location', $fw);
178 my $collections = GetKohaAuthorisedValues('items.ccode' , $fw);
179 my (@itemloop, %itemfields);
181 my $authvalcode_items_itemlost = GetAuthValCode('items.itemlost',$fw);
182 my $authvalcode_items_damaged = GetAuthValCode('items.damaged', $fw);
185 foreach my $item (@items) {
187 $item->{homebranch} = GetBranchName($item->{homebranch});
189 # can place holds defaults to yes
190 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
192 # format some item fields for display
193 if ( defined $item->{'publictype'} ) {
194 $item->{ $item->{'publictype'} } = 1;
196 $item->{imageurl} = defined $item->{itype} ? getitemtypeimagelocation('intranet', $itemtypes->{ $item->{itype} }{imageurl})
199 foreach (qw(datedue datelastseen onloan)) {
200 $item->{$_} = format_date($item->{$_});
202 # item damaged, lost, withdrawn loops
203 $item->{itemlostloop} = GetAuthorisedValues($authvalcode_items_itemlost, $item->{itemlost}) if $authvalcode_items_itemlost;
204 if ($item->{damaged}) {
205 $item->{itemdamagedloop} = GetAuthorisedValues($authvalcode_items_damaged, $item->{damaged}) if $authvalcode_items_damaged;
207 #get shelf location and collection code description if they are authorised value.
208 my $shelfcode = $item->{'location'};
209 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
210 my $ccode = $item->{'ccode'};
211 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
212 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
213 $itemfields{$_} = 1 if ( $item->{$_} );
217 my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($item->{itemnumber});
218 my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
220 if (C4::Context->preference('HidePatronName')){
221 $item->{'hidepatronname'} = 1;
224 if ( defined $reservedate ) {
225 $item->{backgroundcolor} = 'reserved';
226 $item->{reservedate} = format_date($reservedate);
227 $item->{ReservedForBorrowernumber} = $reservedfor;
228 $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
229 $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
230 $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname};
231 $item->{Reservedcardnumber} = $ItemBorrowerReserveInfo->{'cardnumber'};
234 # Check the transit status
235 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber});
236 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
237 $item->{transfertwhen} = format_date($transfertwhen);
238 $item->{transfertfrom} = $branches->{$transfertfrom}{branchname};
239 $item->{transfertto} = $branches->{$transfertto}{branchname};
240 $item->{nocancel} = 1;
243 # FIXME: move this to a pm, check waiting status for holds
244 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
245 $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
246 while (my $wait_hashref = $sth2->fetchrow_hashref) {
247 $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
250 # item has a host number if its biblio number does not match the current bib
251 if ($item->{biblionumber} ne $biblionumber){
252 $item->{hostbiblionumber} = $item->{biblionumber};
253 $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
256 #count if item is used in analytical bibliorecords
257 my $countanalytics= GetAnalyticsCount($item->{itemnumber});
258 if ($countanalytics > 0){
260 $item->{countanalytics} = $countanalytics;
263 push @itemloop, $item;
266 $template->param( norequests => $norequests );
268 MARCNOTES => $marcnotesarray,
269 MARCSUBJCTS => $marcsubjctsarray,
270 MARCAUTHORS => $marcauthorsarray,
271 MARCSERIES => $marcseriesarray,
272 MARCURLS => $marcurlsarray,
273 MARCISBNS => $marcisbnsarray,
274 MARCHOSTS => $marchostsarray,
275 subtitle => $subtitle,
277 partname => $partname,
279 responsibility => $responsibility,
280 impressum => $impressum,
283 textholding => $textholding,
284 itemdata_ccode => $itemfields{ccode},
285 itemdata_enumchron => $itemfields{enumchron},
286 itemdata_uri => $itemfields{uri},
287 itemdata_copynumber => $itemfields{copynumber},
288 volinfo => $itemfields{enumchron},
289 itemdata_itemnotes => $itemfields{itemnotes},
290 z3950_search_params => C4::Search::z3950_search_args($dat),
291 holdcount => $holdcount,
292 hostrecords => $hostrecords,
293 analytics_flag => $analytics_flag,
294 C4::Search::enabled_staff_search_views,
297 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
298 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
299 my $subfields = substr $fieldspec, 3;
300 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
301 my @alternateholdingsinfo = ();
302 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
304 for my $field (@holdingsfields) {
305 my %holding = ( holding => '' );
306 my $havesubfield = 0;
307 for my $subfield ($field->subfields()) {
308 if ((index $subfields, $$subfield[0]) >= 0) {
309 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
310 $holding{'holding'} .= $$subfield[1];
315 push(@alternateholdingsinfo, \%holding);
320 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
324 my @results = ( $dat, );
325 foreach ( keys %{$dat} ) {
326 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
329 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
330 # method query not found?!?!
333 itemloop => \@itemloop,
334 biblionumber => $biblionumber,
335 ($analyze? 'analyze':'detailview') =>1,
336 subscriptions => \@subs,
337 subscriptionsnumber => $subscriptionsnumber,
338 subscriptiontitle => $dat->{title},
341 # $debug and $template->param(debug_display => 1);
345 if (C4::Context->preference("virtualshelves") ) {
346 $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
350 if (C4::Context->preference("FRBRizeEditions")==1) {
353 XISBNS => get_xisbns($isbn)
356 if ($@) { warn "XISBN Failed $@"; }
358 if ( C4::Context->preference("AmazonEnabled") == 1 ) {
359 $template->param( AmazonTld => get_amazon_tld() );
360 my $amazon_reviews = C4::Context->preference("AmazonReviews");
361 my $amazon_similars = C4::Context->preference("AmazonSimilarItems");
363 if ( $amazon_reviews ) {
364 $template->param( AmazonReviews => 1 );
365 push( @services, 'EditorialReview' );
367 if ( $amazon_similars ) {
368 $template->param( AmazonSimilarItems => 1 );
369 push( @services, 'Similarities' );
371 my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour, \@services );
372 if ( $amazon_similars ) {
373 my $similar_products_exist;
374 my @similar_products;
375 for my $similar_product (@{$amazon_details->{Items}->{Item}->[0]->{SimilarProducts}->{SimilarProduct}}) {
376 # do we have any of these isbns in our collection?
377 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
378 # verify that there is at least one similar item
379 if (scalar(@$similar_biblionumbers)){
380 $similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
381 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
384 $template->param( AmazonSimilarItems => $similar_products_exist );
385 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
387 if ( $amazon_reviews ) {
388 my $item = $amazon_details->{Items}->{Item}->[0];
389 my $editorial_reviews = \@{ $item->{EditorialReviews}->{EditorialReview} };
390 #my $customer_reviews = \@{$amazon_details->{Items}->{Item}->[0]->{CustomerReviews}->{Review}};
391 #my $average_rating = $amazon_details->{Items}->{Item}->[0]->{CustomerReviews}->{AverageRating} || 0;
392 #$template->param( amazon_average_rating => $average_rating * 20 );
393 #$template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
394 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
399 if (C4::Context->preference('OPACBaseURL')){
400 $template->param( OpacUrl => C4::Context->preference('OPACBaseURL') );
403 output_html_with_http_headers $query, $cookie, $template->output;