Bug 13199: Test incoherence between 'en' sample notices and translated notices
[koha.git] / opac / opac-ISBDdetail.pl
index 9b5c031..c3c03c1 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 
 # Copyright 2000-2002 Katipo Communications
 #!/usr/bin/perl
 
 # Copyright 2000-2002 Katipo Communications
+# parts copyright 2010 BibLibre
 #
 # This file is part of Koha.
 #
 #
 # This file is part of Koha.
 #
@@ -20,8 +21,7 @@
 
 =head1 NAME
 
 
 =head1 NAME
 
-opac-ISBDdetail.pl : script to show a biblio in ISBD format
-
+opac-ISBDdetail.pl - script to show a biblio in ISBD format
 
 =head1 DESCRIPTION
 
 
 =head1 DESCRIPTION
 
@@ -29,7 +29,7 @@ This script needs a biblionumber as parameter
 
 It shows the biblio
 
 
 It shows the biblio
 
-The template is in <templates_dir>/catalogue/ISBDdetail.tmpl.
+The template is in <templates_dir>/catalogue/ISBDdetail.tt.
 this template must be divided into 11 "tabs".
 
 The first 10 tabs present the biblio, the 11th one presents
 this template must be divided into 11 "tabs".
 
 The first 10 tabs present the biblio, the 11th one presents
@@ -37,8 +37,6 @@ the items attached to the biblio
 
 =head1 FUNCTIONS
 
 
 =head1 FUNCTIONS
 
-=over 2
-
 =cut
 
 use strict;
 =cut
 
 use strict;
@@ -50,30 +48,53 @@ use C4::Output;
 use CGI;
 use MARC::Record;
 use C4::Biblio;
 use CGI;
 use MARC::Record;
 use C4::Biblio;
+use C4::Items;
 use C4::Acquisition;
 use C4::Review;
 use C4::Serials;    # uses getsubscriptionfrom biblionumber
 use C4::Koha;
 use C4::Members;    # GetMember
 use C4::Acquisition;
 use C4::Review;
 use C4::Serials;    # uses getsubscriptionfrom biblionumber
 use C4::Koha;
 use C4::Members;    # GetMember
-use C4::External::Amazon;
 
 my $query = CGI->new();
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
 
 my $query = CGI->new();
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
-        template_name   => "opac-ISBDdetail.tmpl",
+        template_name   => "opac-ISBDdetail.tt",
         query           => $query,
         type            => "opac",
         query           => $query,
         type            => "opac",
-        authnotrequired => 1,
+        authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
         debug           => 1,
     }
 );
 
 my $biblionumber = $query->param('biblionumber');
         debug           => 1,
     }
 );
 
 my $biblionumber = $query->param('biblionumber');
+$biblionumber = int($biblionumber);
+
+# get biblionumbers stored in the cart
+my @cart_list;
+
+if($query->cookie("bib_list")){
+    my $cart_list = $query->cookie("bib_list");
+    @cart_list = split(/\//, $cart_list);
+    if ( grep {$_ eq $biblionumber} @cart_list) {
+        $template->param( incart => 1 );
+    }
+}
 
 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
 
 my $marcflavour      = C4::Context->preference("marcflavour");
 
 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
 
 my $marcflavour      = C4::Context->preference("marcflavour");
+
+my @items = GetItemsInfo($biblionumber);
+if (scalar @items >= 1) {
+    my @hiddenitems = GetHiddenItemnumbers(@items);
+
+    if (scalar @hiddenitems == scalar @items ) {
+        print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
+        exit;
+    }
+}
+
 my $record = GetMarcBiblio($biblionumber);
 if ( ! $record ) {
     print $query->redirect("/cgi-bin/koha/errors/404.pl");
 my $record = GetMarcBiblio($biblionumber);
 if ( ! $record ) {
     print $query->redirect("/cgi-bin/koha/errors/404.pl");
@@ -86,7 +107,10 @@ my $upc = GetNormalizedUPC($record,$marcflavour);
 my $ean = GetNormalizedEAN($record,$marcflavour);
 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
 my $ean = GetNormalizedEAN($record,$marcflavour);
 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
-my $content_identifier_exists = 1 if ($isbn or $ean or $oclc or $upc);
+my $content_identifier_exists;
+if ( $isbn or $ean or $oclc or $upc ) {
+    $content_identifier_exists = 1;
+}
 $template->param(
     normalized_upc => $upc,
     normalized_ean => $ean,
 $template->param(
     normalized_upc => $upc,
     normalized_ean => $ean,
@@ -99,8 +123,8 @@ $template->param(
 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
 my $dbh = C4::Context->dbh;
 my $dat                 = TransformMarcToKoha( $dbh, $record );
 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
 my $dbh = C4::Context->dbh;
 my $dat                 = TransformMarcToKoha( $dbh, $record );
-my @subscriptions       =
-  GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
+
+my @subscriptions       = GetSubscriptions( $dat->{title}, $dat->{issn}, undef, $biblionumber );
 my @subs;
 foreach my $subscription (@subscriptions) {
     my %cell;
 my @subs;
 foreach my $subscription (@subscriptions) {
     my %cell;
@@ -123,10 +147,19 @@ $template->param(
     subscriptionsnumber => $subscriptionsnumber,
 );
 
     subscriptionsnumber => $subscriptionsnumber,
 );
 
-# my @blocs = split /\@/,$ISBD;
-# my @fields = $record->fields();
+my $norequests = 1;
 my $res = GetISBDView($biblionumber, "opac");
 
 my $res = GetISBDView($biblionumber, "opac");
 
+my $itemtypes = GetItemTypes();
+for my $itm (@items) {
+    $norequests = 0
+       if ( (not $itm->{'withdrawn'} )
+         && (not $itm->{'itemlost'} )
+         && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
+                && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
+         && ($itm->{'itemnumber'} ) );
+}
+
 my $reviews = getreviews( $biblionumber, 1 );
 foreach ( @$reviews ) {
     my $borrower_number_review = $_->{borrowernumber};
 my $reviews = getreviews( $biblionumber, 1 );
 foreach ( @$reviews ) {
     my $borrower_number_review = $_->{borrowernumber};
@@ -139,45 +172,39 @@ foreach ( @$reviews ) {
 
 
 $template->param(
 
 
 $template->param(
+    RequestOnOpac       => C4::Context->preference("RequestOnOpac"),
+    AllowOnShelfHolds   => C4::Context->preference('AllowOnShelfHolds'),
+    norequests   => $norequests,
     ISBD         => $res,
     biblionumber => $biblionumber,
     reviews             => $reviews,
 );
 
     ISBD         => $res,
     biblionumber => $biblionumber,
     reviews             => $reviews,
 );
 
-## Amazon.com stuff
-#not used unless preference set
-if ( C4::Context->preference("OPACAmazonEnabled") == 1 ) {
-
-    my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour );
-
-    foreach my $result ( @{ $amazon_details->{Details} } ) {
-        $template->param( item_description => $result->{ProductDescription} );
-        $template->param( image            => $result->{ImageUrlMedium} );
-        $template->param( list_price       => $result->{ListPrice} );
-        $template->param( amazon_url       => $result->{url} );
-    }
-
-    my @products;
-    my @reviews;
-    for my $details ( @{ $amazon_details->{Details} } ) {
-        next unless $details->{SimilarProducts};
-        for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
-            push @products, +{ Product => $product };
-        }
-        next unless $details->{Reviews};
-        for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
-            $template->param( rating => $product * 20 );
+#Export options
+my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
+my @export_options = split(/\|/,$OpacExportOptions);
+$template->{VARS}->{'export_options'} = \@export_options;
+
+#Search for title in links
+my $marccontrolnumber   = GetMarcControlnumber ($record, $marcflavour);
+my $marcissns = GetMarcISSN ( $record, $marcflavour );
+my $issn = $marcissns->[0] || '';
+
+if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
+    $dat->{title} =~ s/\/+$//; # remove trailing slash
+    $dat->{title} =~ s/\s+$//; # remove trailing space
+    $search_for_title = parametrized_url(
+        $search_for_title,
+        {
+            TITLE         => $dat->{title},
+            AUTHOR        => $dat->{author},
+            ISBN          => $isbn,
+            ISSN          => $issn,
+            CONTROLNUMBER => $marccontrolnumber,
+            BIBLIONUMBER  => $biblionumber,
         }
         }
-        for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
-            push @reviews,
-              +{
-                Summary => $reviews->{Summary},
-                Comment => $reviews->{Comment},
-              };
-        }
-    }
-    $template->param( SIMILAR_PRODUCTS => \@products );
-    $template->param( AMAZONREVIEWS    => \@reviews );
+    );
+    $template->param('OPACSearchForTitleIn' => $search_for_title);
 }
 
 output_html_with_http_headers $query, $cookie, $template->output;
 }
 
 output_html_with_http_headers $query, $cookie, $template->output;