Merge remote-tracking branch 'kc/new/bug_4002' into kcmaster
[koha_gimpoz] / misc / cronjobs / notifyMailsOp.pl
index e2a086f..7c655c9 100755 (executable)
@@ -1,6 +1,15 @@
+#!/usr/bin/perl
 use strict;
+#use warnings; FIXME - Bug 2505
+use Carp;
+BEGIN {
+    # find Koha's Perl modules
+    # test carefully before changing this
+    use FindBin;
+    eval { require "$FindBin::Bin/../kohalib.pl" };
+}
 use C4::Context;
-use C4::Date;
+use C4::Dates qw/format_date/;
 use Mail::Sendmail;  # comment out if not doing e-mail notices
 use Getopt::Long;
 use C4::Circulation;
@@ -41,8 +50,6 @@ sub GetBorrowerNotifys{
                        AND
                        (notifys.borrowernumber=issues.borrowernumber AND notifys.itemnumber=issues.itemnumber)
                        AND
-                       issues.returndate IS NULL
-                       AND
                        notifys.borrowernumber=?
                        AND notify_send_date IS NULL");
                        $sth2->execute($borrowernumber);
@@ -195,12 +202,12 @@ foreach my $num (@getnofifys) {
                                                                'content-type' => 'text/html; charset="utf-8"',
                                        );
                                # if we don't have any content for the mail, we don't launch mail, but notify it in a file
-                                       if ($mailtext ne 'nonotifys') {
-                                       sendmail(%mail);
-                                       }
-                                       else {
-                                       print OUT $email ;
-                                       }
+                if ($mailtext ne 'nonotifys') {
+                    sendmail(%mail) or carp $Mail::Sendmail::error;
+                }
+                else {
+                    print OUT $email ;
+                }
                                        
 # now deal with the debarred mode
 #              if ($debarred eq 1) {