Bug 12528 - Enable staff to deny message setting access to patrons on the OPAC
[koha.git] / opac / opac-user.pl
index 9d1f9b2..413c26d 100755 (executable)
@@ -35,12 +35,14 @@ use C4::Items;
 use C4::Letters;
 use C4::Branch; # GetBranches
 use Koha::DateUtils;
-use Koha::Borrower::Debarments qw(IsDebarred);
+use Koha::Patron::Debarments qw(IsDebarred);
 use Koha::Holds;
 use Koha::Database;
+use Koha::Patron::Messages;
 
 use constant ATTRIBUTE_SHOW_BARCODE => 'SHOW_BCODE';
 
+use Scalar::Util qw(looks_like_number);
 use Date::Calc qw(
   Today
   Add_Delta_Days
@@ -107,14 +109,18 @@ if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
     $borr->{'amountoverzero'} = 1;
 }
 my $no_renewal_amt = C4::Context->preference( 'OPACFineNoRenewals' );
-$no_renewal_amt ||= 0;
+$no_renewal_amt = undef unless looks_like_number( $no_renewal_amt );
 
-if (  C4::Context->preference( 'OpacRenewalAllowed' ) && $borr->{amountoutstanding} > $no_renewal_amt ) {
+if (   C4::Context->preference('OpacRenewalAllowed')
+    && defined($no_renewal_amt)
+    && $borr->{amountoutstanding} > $no_renewal_amt )
+{
     $borr->{'flagged'} = 1;
     $canrenew = 0;
     $template->param(
         renewal_blocked_fines => sprintf( '%.02f', $no_renewal_amt ),
-        renewal_blocked_fines_amountoutstanding => sprintf( '%.02f', $borr->{amountoutstanding} ),
+        renewal_blocked_fines_amountoutstanding =>
+          sprintf( '%.02f', $borr->{amountoutstanding} ),
     );
 }
 
@@ -307,7 +313,13 @@ if (C4::Context->preference("OPACAmazonCoverImages") or
         $template->param(JacketImages=>1);
 }
 
-if ( GetMessagesCount( $borrowernumber, 'B' ) ) {
+my $patron_messages = Koha::Patron::Messages->search(
+    {
+        borrowernumber => $borrowernumber,
+        message_type => 'B',
+    }
+);
+if ( $patron_messages->count ) {
     $template->param( bor_messages => 1 );
 }
 
@@ -334,14 +346,14 @@ if (   C4::Context->preference('AllowPatronToSetCheckoutsVisibilityForGuarantor'
 
 $template->param(
     borrower                 => $borr,
-    bor_messages_loop        => GetMessages( $borrowernumber, 'B', 'NONE' ),
+    patron_messages          => $patron_messages,
     patronupdate             => $patronupdate,
     OpacRenewalAllowed       => C4::Context->preference("OpacRenewalAllowed"),
     userview                 => 1,
     SuspendHoldsOpac         => C4::Context->preference('SuspendHoldsOpac'),
     AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
     OpacHoldNotes            => C4::Context->preference('OpacHoldNotes'),
-    failed_holds             => $query->param('failed_holds'),
+    failed_holds             => scalar $query->param('failed_holds'),
 );
 
 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };