(bug #4075) add use of getrecordvalue in opac-detail
[koha.git] / opac / opac-detail.pl
index 7ce4cf7..5940fb0 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;
 
@@ -61,13 +60,18 @@ 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") ) {
     $template->param(
-        'XSLTBloc' => XSLTParse4Display($biblionumber, $record, 'Detail') );
+        'XSLTBloc' => XSLTParse4Display($biblionumber, $record, C4::Context->preference("XSLTDetailsDisplay")) );
 }
 
 # change back when ive fixed request.pl
@@ -83,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'};
@@ -101,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};
@@ -177,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,
@@ -242,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 $@"; }
@@ -285,7 +266,7 @@ if ( C4::Context->preference("OPACAmazonEnabled") && C4::Context->preference("OP
     my $amazon_reviews  = C4::Context->preference("AmazonReviews");
     my $amazon_similars = C4::Context->preference("AmazonSimilarItems");
     my @services;
-    my $amazon_details = &get_amazon_details( $dat->{isbn}, $record, $marcflavour, \@services );
+    my $amazon_details = &get_amazon_details( $normalized_isbn, $record, $marcflavour, \@services );
 
     if ( $amazon_reviews ) {
        
@@ -374,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;
     }
@@ -413,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;
     }
@@ -448,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)
                );
        }
 }