From c3c0af3d0cf0eae20d4c01a7b0348806b8ca4b7d Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Tue, 6 Jan 2015 09:50:24 -0500
Subject: [PATCH] Bug 5144 [3] - Add message for patron

---
 C4/Reserves.pm                                     |    6 +++++-
 .../opac-tmpl/bootstrap/en/modules/opac-user.tt    |    7 +++++++
 opac/opac-reserve.pl                               |    6 ++++--
 opac/opac-user.pl                                  |   18 ++++++++----------
 4 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/C4/Reserves.pm b/C4/Reserves.pm
index e04c3fc..074a4c2 100644
--- a/C4/Reserves.pm
+++ b/C4/Reserves.pm
@@ -23,6 +23,7 @@ package C4::Reserves;
 
 use strict;
 #use warnings; FIXME - Bug 2505
+
 use C4::Context;
 use C4::Biblio;
 use C4::Members;
@@ -42,6 +43,9 @@ use Koha::Calendar;
 use Koha::Database;
 
 use List::MoreUtils qw( firstidx any );
+use Carp;
+
+use constant ALREADY_ON_HOLD => -1;
 
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
@@ -162,7 +166,7 @@ sub AddReserve {
     );
     if ( $count > 0 ) {
         carp("AddReserve: borrower $borrowernumber already has $count holds for biblionumber $biblionumber");
-        return;
+        return ALREADY_ON_HOLD;
     }
 
     my $fee =
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt
index f4cbddb..93c202d 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt
@@ -48,6 +48,13 @@
 
                     [% IF ( patronupdate ) %]<div class="alert alert-info"><h3>Thank you!</h3><p>Your corrections have been submitted to the library, and a staff member will update your record as soon as possible.</p></div>[% END %]
 
+                    [% IF already_on_hold %]
+                        <div class="alert alert-info">
+                            <h3>Notice:</h3>
+                            <p>One or more holds were not placed due to existing holds.</p>
+                        </div>
+                    [% END %]
+
                     [% IF ( BORROWER_INF.warndeparture ) %]
                         <div class="alert" id="warndeparture">
                             <strong>Please note:</strong><span> Your card will expire on <span id="warndeparture_date">[% BORROWER_INF.warndeparture | $KohaDates %]</span>. Please contact the library for more information.</span>
diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl
index ba778db..3d4662c 100755
--- a/opac/opac-reserve.pl
+++ b/opac/opac-reserve.pl
@@ -215,6 +215,7 @@ if ( $query->param('place_reserve') ) {
         &get_out($query, $cookie, $template->output);
     }
 
+    my $already_on_hold;
     while (@selectedItems) {
         my $biblioNum = shift(@selectedItems);
         my $itemNum   = shift(@selectedItems);
@@ -277,7 +278,7 @@ if ( $query->param('place_reserve') ) {
 
         # Here we actually do the reserveration. Stage 3.
         if ($canreserve) {
-            AddReserve(
+            my $ret = AddReserve(
                 $branch,      $borrowernumber,
                 $biblioNum,   'a',
                 [$biblioNum], $rank,
@@ -285,11 +286,12 @@ if ( $query->param('place_reserve') ) {
                 $notes,       $biblioData->{title},
                 $itemNum,     $found
             );
+            $already_on_hold++ if $ret == C4::Reserves::ALREADY_ON_HOLD;
             ++$reserve_cnt;
         }
     }
 
-    print $query->redirect("/cgi-bin/koha/opac-user.pl#opac-user-holds");
+    print $query->redirect("/cgi-bin/koha/opac-user.pl?already_on_hold=$already_on_hold#opac-user-holds");
     exit;
 }
 
diff --git a/opac/opac-user.pl b/opac/opac-user.pl
index ad4f339..8512645 100755
--- a/opac/opac-user.pl
+++ b/opac/opac-user.pl
@@ -383,17 +383,15 @@ if ( $borr->{'opacnote'} ) {
 }
 
 $template->param(
-    bor_messages_loop    => GetMessages( $borrowernumber, 'B', 'NONE' ),
-    waiting_count      => $wcount,
-    patronupdate => $patronupdate,
-    OpacRenewalAllowed => C4::Context->preference("OpacRenewalAllowed"),
-    userview => 1,
-);
-
-$template->param(
-    SuspendHoldsOpac => C4::Context->preference('SuspendHoldsOpac'),
+    userview                 => 1,
+    waiting_count            => $wcount,
+    patronupdate             => $patronupdate,
+    already_on_hold          => $query->param('already_on_hold'),
+    bor_messages_loop        => GetMessages( $borrowernumber, 'B', 'NONE' ),
+    OpacRenewalAllowed       => C4::Context->preference("OpacRenewalAllowed"),
+    SuspendHoldsOpac         => C4::Context->preference('SuspendHoldsOpac'),
     AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
-    OpacHoldNotes => C4::Context->preference('OpacHoldNotes'),
+    OpacHoldNotes            => C4::Context->preference('OpacHoldNotes'),
 );
 
 output_html_with_http_headers $query, $cookie, $template->output;
-- 
1.7.2.5