Followup Adding system preference XSLT*FileName
[koha.git] / opac / opac-detail.pl
index 611cdc4..bf2ef9f 100755 (executable)
@@ -35,7 +35,6 @@ use C4::Dates qw/format_date/;
 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn get_biblio_from_xisbn);
 use C4::External::Amazon;
 use C4::Review;
-use C4::Serials;
 use C4::Members;
 use C4::XSLT;
 
@@ -58,7 +57,16 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
 );
 
 my $biblionumber = $query->param('biblionumber') || $query->param('bib');
+
+$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
+$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
+$template->param(C4::Search::enabled_opac_search_views);
+
 my $record       = GetMarcBiblio($biblionumber);
+if ( ! $record ) {
+    print $query->redirect("/cgi-bin/koha/errors/404.pl");
+    exit;
+}
 $template->param( biblionumber => $biblionumber );
 # XSLT processing of some stuff
 if (C4::Context->preference("XSLTDetailsDisplay") ) {
@@ -79,10 +87,6 @@ if (C4::Context->preference('hidelostitems')) {
 }
 my $dat = &GetBiblioData($biblionumber);
 
-if (!$dat) {
-    print $query->redirect("/cgi-bin/koha/errors/404.pl");
-    exit;
-}
 my $itemtypes = GetItemTypes();
 # imageurl:
 my $itemtype = $dat->{'itemtype'};
@@ -97,7 +101,7 @@ my $collections =  GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}
 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
 my @subscriptions       = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
 my @subs;
-$dat->{'serial'}=1 if $subscriptionsnumber;
+$dat->{'serials'}=1 if $subscriptionsnumber;
 foreach my $subscription (@subscriptions) {
     my %cell;
     $cell{subscriptionid}    = $subscription->{subscriptionid};
@@ -173,14 +177,18 @@ for my $itm (@items) {
 ## get notes and subjects from MARC record
 my $dbh              = C4::Context->dbh;
 my $marcflavour      = C4::Context->preference("marcflavour");
-my $marcnotesarray   = GetMarcNotes   ($record,$marcflavour);
-my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
-my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
-my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
-my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
-my $subtitle         = C4::Biblio::get_koha_field_from_marc('bibliosubtitle', 'subtitle', $record, '');
+my $normalized_isbn  = GetNormalizedISBN($dat->{isbn},$record,$marcflavour);
+my $marcnotesarray   = GetMarcNotes     ($record,$marcflavour);
+my $marcauthorsarray = GetMarcAuthors   ($record,$marcflavour);
+my $marcsubjctsarray = GetMarcSubjects  ($record,$marcflavour);
+my $marcseriesarray  = GetMarcSeries    ($record,$marcflavour);
+my $marcurlsarray    = GetMarcUrls      ($record,$marcflavour);
+my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
 
     $template->param(
+                     normalized_oclc         => GetNormalizedOCLCNumber($record,$marcflavour),
+                     normalized_upc          => GetNormalizedUPC       ($record,$marcflavour),
+                     normalized_isbn         => $normalized_isbn,
                      MARCNOTES               => $marcnotesarray,
                      MARCSUBJCTS             => $marcsubjctsarray,
                      MARCAUTHORS             => $marcauthorsarray,
@@ -238,36 +246,13 @@ $template->param(
     loggedincommenter   => $loggedincommenter
 );
 
-sub isbn_cleanup ($) {
-       my $isbn=shift;
-    ($isbn) = $isbn =~ /([\d-]*[X]*)/;
-    $isbn =~ s/-//g;
-       if (
-               $isbn =~ /\b(\d{13})\b/ or
-               $isbn =~ /\b(\d{10})\b/ or 
-               $isbn =~ /\b(\d{9}X)\b/i
-       ) {
-               return $1;
-       }
-       return undef;
-}
 
 # XISBN Stuff
-my $xisbn=$dat->{'isbn'};
-(my $aisbn) = $xisbn =~ /([\d-]*[X]*)/;
-$aisbn =~ s/-//g;
-$template->param(amazonisbn => $aisbn);                # FIXME: so it is OK if the ISBN = 'XXXXX' ?
-my ($clean,$clean2);
-# these might be overkill, but they are better than the regexp above.
-if ($clean = isbn_cleanup($xisbn)){
-       $template->param(clean_isbn => $clean);
-}
 
 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
     eval {
         $template->param(
-            xisbn => $xisbn,
-            XISBNS => get_xisbns($xisbn)
+            XISBNS => get_xisbns($normalized_isbn)
         );
     };
     if ($@) { warn "XISBN Failed $@"; }
@@ -280,7 +265,11 @@ if ( C4::Context->preference("OPACAmazonEnabled") && C4::Context->preference("OP
     my $similar_products_exist;
     my $amazon_reviews  = C4::Context->preference("AmazonReviews");
     my $amazon_similars = C4::Context->preference("AmazonSimilarItems");
+    my @services;
+    my $amazon_details = &get_amazon_details( $normalized_isbn, $record, $marcflavour, \@services );
+
     if ( $amazon_reviews ) {
+       
         my $item = $amazon_details->{Items}->{Item}->[0];
         my $customer_reviews = \@{ $item->{CustomerReviews}->{Review} };
         for my $one_review ( @$customer_reviews ) {
@@ -304,14 +293,10 @@ if ( C4::Context->preference("OPACAmazonEnabled") && C4::Context->preference("OP
                 push @similar_products, +{ similar_biblionumbers => $similar_biblionumbers, title => $similar_product->{Title}, ASIN => $similar_product->{ASIN}  };
             }
         }
-    }
-    my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
-    my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating} || 0;
-    $template->param( OPACAmazonSimilarItems => $similar_products_exist );
-    $template->param( amazon_average_rating => $average_rating * 20);
-    $template->param( AMAZON_CUSTOMER_REVIEWS    => $customer_reviews );
-    $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
-    $template->param( AMAZON_EDITORIAL_REVIEWS    => $editorial_reviews );
+       $template->param( OPACAmazonSimilarItems => $similar_products_exist );
+       $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
+    }    
+    
 }
 
 # Babelthèque
@@ -370,11 +355,6 @@ if (C4::Context->preference("OPACShelfBrowser")) {
         $sth_get_biblio->execute($this_item->{biblionumber});
         while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
             $this_item->{'title'} = $this_biblio->{'title'};
-            if ($clean2 = isbn_cleanup($this_biblio->{'isbn'})) {
-                $this_item->{'isbn'} = $clean2;
-            } else { 
-                $this_item->{'isbn'} = $this_biblio->{'isbn'};
-            }
         }
         unshift @previous_items, $this_item;
     }
@@ -409,11 +389,6 @@ if (C4::Context->preference("OPACShelfBrowser")) {
         $sth_get_biblio->execute($this_item->{biblionumber});
         while (my $this_biblio = $sth_get_biblio->fetchrow_hashref()) {
             $this_item->{'title'} = $this_biblio->{'title'};
-            if ($clean2 = isbn_cleanup($this_biblio->{'isbn'})) {
-                $this_item->{'isbn'} = $clean2;
-            } else { 
-                $this_item->{'isbn'} = $this_biblio->{'isbn'};
-            }
         }
         push @next_items, $this_item;
     }
@@ -444,14 +419,14 @@ if (C4::Context->preference("BakerTaylorEnabled")) {
                BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
        );
        my ($bt_user, $bt_pass);
-       if ($clean and
+       if ($normalized_isbn and
                $bt_user = C4::Context->preference('BakerTaylorUsername') and
                $bt_pass = C4::Context->preference('BakerTaylorPassword')    )
        {
                $template->param(
                BakerTaylorContentURL   =>
                sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
-                               $bt_user,$bt_pass,$clean)
+                               $bt_user,$bt_pass,$normalized_isbn)
                );
        }
 }