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") );
89 $template->param( ocoins => GetCOinSBiblio($record) );
91 # some useful variables for enhanced content;
92 # in each case, we're grabbing the first value we find in
93 # the record and normalizing it
94 my $upc = GetNormalizedUPC($record,$marcflavour);
95 my $ean = GetNormalizedEAN($record,$marcflavour);
96 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
97 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
100 normalized_upc => $upc,
101 normalized_ean => $ean,
102 normalized_oclc => $oclc,
103 normalized_isbn => $isbn,
106 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
107 my $marcisbnsarray = GetMarcISBN( $record, $marcflavour );
108 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
109 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
110 my $marcseriesarray = GetMarcSeries($record,$marcflavour);
111 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
112 my $marchostsarray = GetMarcHosts($record,$marcflavour);
113 my $subtitle = GetRecordValue('subtitle', $record, $fw);
115 # Get Branches, Itemtypes and Locations
116 my $branches = GetBranches();
117 my $itemtypes = GetItemTypes();
118 my $dbh = C4::Context->dbh;
120 my @all_items = GetItemsInfo( $biblionumber );
122 for my $itm (@all_items) {
123 push @items, $itm unless ( $itm->{itemlost} && GetHideLostItemsPreference($borrowernumber) && !$showallitems);
126 # flag indicating existence of at least one item linked via a host record
128 # adding items linked via host biblios
129 my @hostitems = GetHostItemsInfo($record);
132 push (@items,@hostitems);
135 my $dat = &GetBiblioData($biblionumber);
138 my ( $holdcount, $holds ) = GetReservesFromBiblionumber($biblionumber,1);
140 #coping with subscriptions
141 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
142 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
145 foreach my $subscription (@subscriptions) {
147 my $serials_to_display;
148 $cell{subscriptionid} = $subscription->{subscriptionid};
149 $cell{subscriptionnotes} = $subscription->{notes};
150 $cell{branchcode} = $subscription->{branchcode};
151 $cell{branchname} = GetBranchName($subscription->{branchcode});
152 $cell{hasalert} = $subscription->{hasalert};
153 #get the three latest serials.
154 $serials_to_display = $subscription->{staffdisplaycount};
155 $serials_to_display = C4::Context->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
156 $cell{staffdisplaycount} = $serials_to_display;
157 $cell{latestserials} =
158 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
162 if ( defined $dat->{'itemtype'} ) {
163 $dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }{imageurl} );
166 $dat->{'count'} = scalar @all_items + @hostitems;
167 $dat->{'showncount'} = scalar @items + @hostitems;
168 $dat->{'hiddencount'} = scalar @all_items + @hostitems - scalar @items;
170 my $shelflocations = GetKohaAuthorisedValues('items.location', $fw);
171 my $collections = GetKohaAuthorisedValues('items.ccode' , $fw);
172 my (@itemloop, %itemfields);
174 my $authvalcode_items_itemlost = GetAuthValCode('items.itemlost',$fw);
175 my $authvalcode_items_damaged = GetAuthValCode('items.damaged', $fw);
178 my $materials_flag; # set this if the items have anything in the materials field
179 foreach my $item (@items) {
181 $item->{homebranch} = GetBranchName($item->{homebranch});
183 # can place holds defaults to yes
184 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
186 # format some item fields for display
187 if ( defined $item->{'publictype'} ) {
188 $item->{ $item->{'publictype'} } = 1;
190 $item->{imageurl} = defined $item->{itype} ? getitemtypeimagelocation('intranet', $itemtypes->{ $item->{itype} }{imageurl})
193 foreach (qw(datedue datelastseen onloan)) {
194 $item->{$_} = format_date($item->{$_});
196 # item damaged, lost, withdrawn loops
197 $item->{itemlostloop} = GetAuthorisedValues($authvalcode_items_itemlost, $item->{itemlost}) if $authvalcode_items_itemlost;
198 if ($item->{damaged}) {
199 $item->{itemdamagedloop} = GetAuthorisedValues($authvalcode_items_damaged, $item->{damaged}) if $authvalcode_items_damaged;
201 #get shelf location and collection code description if they are authorised value.
202 my $shelfcode = $item->{'location'};
203 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
204 my $ccode = $item->{'ccode'};
205 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
206 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
207 $itemfields{$_} = 1 if ( $item->{$_} );
211 my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($item->{itemnumber});
212 my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
214 if (C4::Context->preference('HidePatronName')){
215 $item->{'hidepatronname'} = 1;
218 if ( defined $reservedate ) {
219 $item->{backgroundcolor} = 'reserved';
220 $item->{reservedate} = format_date($reservedate);
221 $item->{ReservedForBorrowernumber} = $reservedfor;
222 $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
223 $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
224 $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname};
225 $item->{Reservedcardnumber} = $ItemBorrowerReserveInfo->{'cardnumber'};
228 # Check the transit status
229 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber});
230 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
231 $item->{transfertwhen} = format_date($transfertwhen);
232 $item->{transfertfrom} = $branches->{$transfertfrom}{branchname};
233 $item->{transfertto} = $branches->{$transfertto}{branchname};
234 $item->{nocancel} = 1;
237 # FIXME: move this to a pm, check waiting status for holds
238 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
239 $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
240 while (my $wait_hashref = $sth2->fetchrow_hashref) {
241 $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
244 # item has a host number if its biblio number does not match the current bib
245 if ($item->{biblionumber} ne $biblionumber){
246 $item->{hostbiblionumber} = $item->{biblionumber};
247 $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
250 #count if item is used in analytical bibliorecords
251 my $countanalytics= GetAnalyticsCount($item->{itemnumber});
252 if ($countanalytics > 0){
254 $item->{countanalytics} = $countanalytics;
256 if ($item->{'materials'} ne ''){
259 push @itemloop, $item;
262 $template->param( norequests => $norequests );
264 MARCNOTES => $marcnotesarray,
265 MARCSUBJCTS => $marcsubjctsarray,
266 MARCAUTHORS => $marcauthorsarray,
267 MARCSERIES => $marcseriesarray,
268 MARCURLS => $marcurlsarray,
269 MARCISBNS => $marcisbnsarray,
270 MARCHOSTS => $marchostsarray,
271 subtitle => $subtitle,
272 itemdata_ccode => $itemfields{ccode},
273 itemdata_enumchron => $itemfields{enumchron},
274 itemdata_uri => $itemfields{uri},
275 itemdata_copynumber => $itemfields{copynumber},
276 volinfo => $itemfields{enumchron},
277 itemdata_itemnotes => $itemfields{itemnotes},
278 z3950_search_params => C4::Search::z3950_search_args($dat),
279 holdcount => $holdcount,
280 hostrecords => $hostrecords,
281 analytics_flag => $analytics_flag,
282 C4::Search::enabled_staff_search_views,
283 materials => $materials_flag,
286 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
287 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
288 my $subfields = substr $fieldspec, 3;
289 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
290 my @alternateholdingsinfo = ();
291 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
293 for my $field (@holdingsfields) {
294 my %holding = ( holding => '' );
295 my $havesubfield = 0;
296 for my $subfield ($field->subfields()) {
297 if ((index $subfields, $$subfield[0]) >= 0) {
298 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
299 $holding{'holding'} .= $$subfield[1];
304 push(@alternateholdingsinfo, \%holding);
309 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
313 my @results = ( $dat, );
314 foreach ( keys %{$dat} ) {
315 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
318 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
319 # method query not found?!?!
322 itemloop => \@itemloop,
323 biblionumber => $biblionumber,
324 ($analyze? 'analyze':'detailview') =>1,
325 subscriptions => \@subs,
326 subscriptionsnumber => $subscriptionsnumber,
327 subscriptiontitle => $dat->{title},
330 # $debug and $template->param(debug_display => 1);
334 if (C4::Context->preference("virtualshelves") ) {
335 $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
339 if (C4::Context->preference("FRBRizeEditions")==1) {
342 XISBNS => get_xisbns($isbn)
345 if ($@) { warn "XISBN Failed $@"; }
347 if ( C4::Context->preference("AmazonEnabled") == 1 ) {
348 $template->param( AmazonTld => get_amazon_tld() );
349 my $amazon_reviews = C4::Context->preference("AmazonReviews");
350 my $amazon_similars = C4::Context->preference("AmazonSimilarItems");
352 if ( $amazon_reviews ) {
353 $template->param( AmazonReviews => 1 );
354 push( @services, 'EditorialReview' );
356 if ( $amazon_similars ) {
357 $template->param( AmazonSimilarItems => 1 );
358 push( @services, 'Similarities' );
360 my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour, \@services );
361 if ( $amazon_similars ) {
362 my $similar_products_exist;
363 my @similar_products;
364 for my $similar_product (@{$amazon_details->{Items}->{Item}->[0]->{SimilarProducts}->{SimilarProduct}}) {
365 # do we have any of these isbns in our collection?
366 my $similar_biblionumbers = get_biblionumber_from_isbn($similar_product->{ASIN});
367 # verify that there is at least one similar item
368 if (scalar(@$similar_biblionumbers)){
369 $similar_products_exist++ if ($similar_biblionumbers && $similar_biblionumbers->[0]);
370 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN} };
373 $template->param( AmazonSimilarItems => $similar_products_exist );
374 $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
376 if ( $amazon_reviews ) {
377 my $item = $amazon_details->{Items}->{Item}->[0];
378 my $editorial_reviews = \@{ $item->{EditorialReviews}->{EditorialReview} };
379 #my $customer_reviews = \@{$amazon_details->{Items}->{Item}->[0]->{CustomerReviews}->{Review}};
380 #my $average_rating = $amazon_details->{Items}->{Item}->[0]->{CustomerReviews}->{AverageRating} || 0;
381 #$template->param( amazon_average_rating => $average_rating * 20 );
382 #$template->param( AMAZON_CUSTOMER_REVIEWS => $customer_reviews );
383 $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews );
388 if (C4::Context->preference('OPACBaseURL')){
389 $template->param( OpacUrl => C4::Context->preference('OPACBaseURL') );
392 output_html_with_http_headers $query, $cookie, $template->output;