From 195d4028322a1b474124726987dc55c2a8c524f5 Mon Sep 17 00:00:00 2001
From: Adrien Saurat <adrien.saurat@biblibre.com>
Date: Fri, 28 Dec 2012 16:37:59 +0100
Subject: [PATCH] Bug 9329: OPAC, new warning when the card has expired

---
 koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt |    6 ++++++
 opac/opac-user.pl                                |   21 ++++++++++++---------
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt
index c28d84f..c0c19a1 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt
@@ -89,6 +89,12 @@ $.tablesorter.addParser({
         </div>
         [% END %]
 
+        [% IF ( BORROWER_INF.warnexpired ) %]
+        <div class="dialog alert" id="warnexpired">
+                <strong>Please note:</strong><span> Your card has expired. Please contact the library for more information.</span>
+        </div>
+        [% END %]
+
         [% IF ( patron_flagged ) %]
 		<div class="dialog alert">
         <ul>
diff --git a/opac/opac-user.pl b/opac/opac-user.pl
index 1c942d5..63d9134 100755
--- a/opac/opac-user.pl
+++ b/opac/opac-user.pl
@@ -125,17 +125,20 @@ my @bordat;
 $bordat[0] = $borr;
 
 # Warningdate is the date that the warning starts appearing
-if ( $borr->{dateexpiry} && C4::Context->preference('NotifyBorrowerDeparture') &&
-    Date_to_Days(Add_Delta_Days($warning_year,$warning_month,$warning_day,- C4::Context->preference('NotifyBorrowerDeparture'))) <
-    Date_to_Days( $today_year, $today_month, $today_day ) )
-{
-    # borrower card soon to expire, warn the borrower
-    $borr->{'warndeparture'} = $borr->{dateexpiry};
-    if (C4::Context->preference('ReturnBeforeExpiry')){
-        $borr->{'returnbeforeexpiry'} = 1;
-    }
+if ( $borr->{dateexpiry} && Date_to_Days( $today_year, $today_month, $today_day ) > Date_to_Days( $warning_year, $warning_month, $warning_day ) ) {
+    $borr->{'warnexpired'} = 1;
+}
+elsif ( $borr->{dateexpiry} && C4::Context->preference('NotifyBorrowerDeparture') &&
+        Date_to_Days(Add_Delta_Days($warning_year, $warning_month, $warning_day,- C4::Context->preference('NotifyBorrowerDeparture'))) <
+        Date_to_Days( $today_year, $today_month, $today_day ) ) {
+        # borrower card soon to expire, warn the borrower
+        $borr->{'warndeparture'} = $borr->{dateexpiry};
+        if (C4::Context->preference('ReturnBeforeExpiry')){
+            $borr->{'returnbeforeexpiry'} = 1;
+        }
 }
 
+
 $template->param(   BORROWER_INFO     => \@bordat,
                     borrowernumber    => $borrowernumber,
                     patron_flagged    => $borr->{flagged},
-- 
1.7.5.4