Bug 15207: Avoid warnings when adding constraint course_reserves_ibfk_2
[koha.git] / opac / opac-detail.pl
index b8cd194..6d71bed 100755 (executable)
@@ -6,18 +6,18 @@
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 
 use strict;
@@ -40,7 +40,6 @@ use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syn
 use C4::Review;
 use C4::Ratings;
 use C4::Members;
-use C4::VirtualShelves;
 use C4::XSLT;
 use C4::ShelfBrowser;
 use C4::Reserves;
@@ -53,6 +52,8 @@ use Koha::DateUtils;
 use C4::HTML5Media;
 use C4::CourseReserves qw(GetItemCourseReservesInfo);
 
+use Koha::Virtualshelves;
+
 BEGIN {
        if (C4::Context->preference('BakerTaylorEnabled')) {
                require C4::External::BakerTaylor;
@@ -67,7 +68,6 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
         query           => $query,
         type            => "opac",
         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
-        flagsrequired   => { borrow => 1 },
     }
 );
 
@@ -437,12 +437,7 @@ if ($session->param('busc')) {
 }
 
 
-
-$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
-
-
-
 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
 $template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") );
 
@@ -527,7 +522,7 @@ my $itemtypes = GetItemTypes();
 my $itemtype = $dat->{'itemtype'};
 if ( $itemtype ) {
     $dat->{'imageurl'}    = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
-    $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
+    $dat->{'description'} = $itemtypes->{$itemtype}->{translated_description};
 }
 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
 my $collections =  GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac');
@@ -535,7 +530,7 @@ my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$dat->{'frameworkco
 
 #coping with subscriptions
 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
-my @subscriptions       = GetSubscriptions($dat->{'title'}, $dat->{'issn'}, $ean, $biblionumber );
+my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
 
 my @subs;
 $dat->{'serial'}=1 if $subscriptionsnumber;
@@ -627,15 +622,21 @@ if ( not $viewallitems and @items > $max_items_to_display ) {
         items_count => scalar( @items ),
     );
 } else {
+  my $allow_onshelf_holds;
+  my $borrower = GetMember( 'borrowernumber' => $borrowernumber );
   for my $itm (@items) {
     $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
     $itm->{priority} = $priority{ $itm->{itemnumber} };
     $norequests = 0
-       if ( (not $itm->{'withdrawn'} )
-         && (not $itm->{'itemlost'} )
-         && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
-                && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
-         && ($itm->{'itemnumber'} ) );
+      if $norequests
+        && !$itm->{'withdrawn'}
+        && !$itm->{'itemlost'}
+        && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'})
+        && !$itemtypes->{$itm->{'itype'}}->{notforloan}
+        && $itm->{'itemnumber'};
+
+    $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed( $itm, $borrower )
+      unless $allow_onshelf_holds;
 
     # get collection code description, too
     my $ccode = $itm->{'ccode'};
@@ -647,7 +648,7 @@ if ( not $viewallitems and @items > $max_items_to_display ) {
     }
     if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
         $itm->{'imageurl'}    = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
-        $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{'description'};
+        $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{translated_description};
     }
     foreach (qw(ccode enumchron copynumber itemnotes uri)) {
         $itemfields{$_} = 1 if ($itm->{$_});
@@ -691,6 +692,7 @@ if ( not $viewallitems and @items > $max_items_to_display ) {
         push @itemloop, $itm;
     }
   }
+  $template->param( 'AllowOnShelfHolds' => $allow_onshelf_holds );
 }
 
 # Display only one tab if one items list is empty
@@ -702,24 +704,29 @@ if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
 }
 
 ## get notes and subjects from MARC record
-my $dbh              = C4::Context->dbh;
+if (!C4::Context->preference("OPACXSLTDetailsDisplay") ) {
+    my $marcisbnsarray   = GetMarcISBN    ($record,$marcflavour);
+    my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
+    my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
+    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
+    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
+    my $marchostsarray   = GetMarcHosts($record,$marcflavour);
+
+    $template->param(
+        MARCSUBJCTS => $marcsubjctsarray,
+        MARCAUTHORS => $marcauthorsarray,
+        MARCSERIES  => $marcseriesarray,
+        MARCURLS    => $marcurlsarray,
+        MARCISBNS   => $marcisbnsarray,
+        MARCHOSTS   => $marchostsarray,
+    );
+}
+
 my $marcnotesarray   = GetMarcNotes   ($record,$marcflavour);
-my $marcisbnsarray   = GetMarcISBN    ($record,$marcflavour);
-my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
-my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
-my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
-my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
-my $marchostsarray  = GetMarcHosts($record,$marcflavour);
 my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
 
     $template->param(
                      MARCNOTES               => $marcnotesarray,
-                     MARCSUBJCTS             => $marcsubjctsarray,
-                     MARCAUTHORS             => $marcauthorsarray,
-                     MARCSERIES              => $marcseriesarray,
-                     MARCURLS                => $marcurlsarray,
-                     MARCISBNS               => $marcisbnsarray,
-                     MARCHOSTS               => $marchostsarray,
                      norequests              => $norequests,
                      RequestOnOpac           => C4::Context->preference("RequestOnOpac"),
                      itemdata_ccode          => $itemfields{ccode},
@@ -838,12 +845,19 @@ $template->param(
 );
 
 # Lists
-
 if (C4::Context->preference("virtualshelves") ) {
-   $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
+    my $shelves = Koha::Virtualshelves->search(
+        {
+            biblionumber => $biblionumber,
+            category => 2,
+        },
+        {
+            join => 'virtualshelfcontents',
+        }
+    );
+    $template->param( shelves => $shelves );
 }
 
-
 # XISBN Stuff
 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
     eval {
@@ -1091,6 +1105,19 @@ if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
     $template->param('OPACSearchForTitleIn' => $search_for_title);
 }
 
+#IDREF
+if ( C4::Context->preference("IDREF") ) {
+    # If the record comes from the SUDOC
+    if ( $record->field('009') ) {
+        my $unimarc3 = $record->field("009")->data;
+        if ( $unimarc3 =~ /^\d+$/ ) {
+            $template->param(
+                IDREF => 1,
+            );
+        }
+    }
+}
+
 # We try to select the best default tab to show, according to what
 # the user wants, and what's available for display
 my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab');