Bug 5786 - Move AllowOnShelfHolds and OPACItemHolds system prefs to the Circulation...
[koha.git] / opac / opac-detail.pl
index 224bf82..e0824d8 100755 (executable)
@@ -23,7 +23,7 @@
 use strict;
 use warnings;
 
-use CGI;
+use CGI qw ( -utf8 );
 use C4::Acquisition qw( SearchOrders );
 use C4::Auth qw(:DEFAULT get_session);
 use C4::Branch;
@@ -63,7 +63,7 @@ BEGIN {
 my $query = new CGI;
 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
     {
-        template_name   => "opac-detail.tmpl",
+        template_name   => "opac-detail.tt",
         query           => $query,
         type            => "opac",
         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
@@ -154,8 +154,10 @@ my $session = get_session($query->cookie("CGISESSID"));
 my %paging = (previous => {}, next => {});
 if ($session->param('busc')) {
     use C4::Search;
+    use URI::Escape;
 
     # Rebuild the string to store on session
+    # param value is URI encoded and params separator is HTML encode (&)
     sub rebuildBuscParam
     {
         my $arrParamsBusc = shift;
@@ -166,13 +168,13 @@ if ($session->param('busc')) {
             if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
                 if (defined($arrParamsBusc->{$_})) {
                     $pasarParams .= '&' if ($j);
-                    $pasarParams .= $_ . '=' . $arrParamsBusc->{$_};
+                    $pasarParams .= $_ . '=' . Encode::decode('UTF-8', uri_escape_utf8( $arrParamsBusc->{$_} ));
                     $j++;
                 }
             } else {
                 for my $value (@{$arrParamsBusc->{$_}}) {
                     $pasarParams .= '&' if ($j);
-                    $pasarParams .= $_ . '=' . $value;
+                    $pasarParams .= $_ . '=' . Encode::decode('UTF-8', uri_escape_utf8($value));
                     $j++;
                 }
             }
@@ -234,12 +236,12 @@ if ($session->param('busc')) {
     for (@arrBusc) {
         ($key, $value) = split(/=/, $_, 2);
         if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
-            $arrParamsBusc{$key} = $value;
+            $arrParamsBusc{$key} = uri_unescape($value);
         } else {
             unless (exists($arrParamsBusc{$key})) {
                 $arrParamsBusc{$key} = [];
             }
-            push @{$arrParamsBusc{$key}}, $value;
+            push @{$arrParamsBusc{$key}}, uri_unescape($value);
         }
     }
     my $searchAgain = 0;
@@ -312,7 +314,7 @@ if ($session->param('busc')) {
     for (@arrBusc) {
         unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
             $buscParam .= '&' unless ($j == 0);
-            $buscParam .= $_;
+            $buscParam .= $_; # string already URI encoded
             $j++;
         }
     }
@@ -435,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") );
 
@@ -625,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'};
@@ -689,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
@@ -1056,11 +1060,6 @@ if (C4::Context->preference("OPACURLOpenInNewWindow")) {
     $template->param(covernewwindow => 'false');
 }
 
-#Export options
-my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
-my @export_options = split(/\|/,$OpacExportOptions);
-$template->{VARS}->{'export_options'} = \@export_options;
-
 if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
     my $rating = GetRating( $biblionumber, $borrowernumber );
     $template->param(