[Koha-cvs] CVS: koha/misc overduenotices.pl,1.1,1.1.4.1

Paul POULAIN tipaul at users.sourceforge.net
Tue Mar 1 14:11:46 CET 2005


Update of /cvsroot/koha/koha/misc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13423/misc

Modified Files:
      Tag: rel_2_2
	overduenotices.pl 
Log Message:
some changes in the script :
* moving all parameters at start of script => easier to maintain
* sending overdues for borrowers without mail to a "koha admin mail".
* ignoring borrowers with "overduenoticerequired" set to 0 (= don't send overduenotice)
* removing "print" to have a silent script (ie can be put in crontab)

Index: overduenotices.pl
===================================================================
RCS file: /cvsroot/koha/koha/misc/overduenotices.pl,v
retrieving revision 1.1
retrieving revision 1.1.4.1
diff -C2 -r1.1 -r1.1.4.1
*** overduenotices.pl	11 Sep 2003 22:37:07 -0000	1.1
--- overduenotices.pl	1 Mar 2005 13:11:43 -0000	1.1.4.1
***************
*** 5,8 ****
--- 5,9 ----
  # Date:  2003/9/7
  # Author:  Stephen Hedges (shedges at skemotah.com)
+ # modified by Paul Poulain (paul at koha-fr.org)
  # Description: 
  #	This script runs a Koha report of items that
***************
*** 35,38 ****
--- 36,42 ----
  
  use strict;
+ use C4::Context;
+ use C4::Date;
+ use Mail::Sendmail;  # comment out if not doing e-mail notices
  
  print "This script will send overdue notices by e-mail and prepare a file of\nnotices for printing if the borrower does not have e-mail.\nYou MUST edit this script for your library BEFORE you run it for the first time!\nSee the comments in the script for directions on changing the script.\n\nDo you wish to continue? (y/n) ";
***************
*** 40,55 ****
  die unless (/^y/i);  # comment these lines out once you've made the changes
  
  open OUTFILE, ">overdues" or die "Cannot open file overdues: $!";
  
- use C4::Context;
- use Mail::Sendmail;  # comment out if not doing e-mail notices
- 
  # set the e-mail server -- comment out if not doing e-mail notices
! unshift @{$Mail::Sendmail::mailcfg{'smtp'}} , 'alma.athenscounty.lib.oh.us';
  #                                         set your own mail server name here
  
  my $dbh = C4::Context->dbh;
! my $sth = $dbh->prepare ("SELECT issues.borrowernumber,firstname,surname,streetaddress,physstreet,city,zipcode,emailaddress FROM issues,borrowers WHERE returndate IS NULL AND TO_DAYS(NOW())-TO_DAYS(date_due) BETWEEN 7 and 30 AND issues.borrowernumber=borrowers.borrowernumber ORDER BY issues.borrowernumber");
! my $first_borrno = $dbh->prepare ("SELECT borrowernumber FROM issues WHERE returndate IS NULL AND TO_DAYS(NOW())-TO_DAYS(date_due) BETWEEN 7 and 30 ORDER BY borrowernumber");
  my $get_date = $dbh->prepare ("SELECT CURDATE()");
  
--- 44,73 ----
  die unless (/^y/i);  # comment these lines out once you've made the changes
  
+ #
+ # BEGINNING OF PARAMETERS
+ #
+ my $mindays = 7 # the notice will be sent after mindays days (grace period)
+ my $maxdays = 30 # issues being more than maxdays late are managed somewhere else. (borrower probably suspended)
+ my $smtpserver = 'smtp.yourserver.com'; # your smtp server (the server who sent mails)
+ my $from = 'library at yourname.org';
+ my $mailtitle = 'Overdue library items';
+ my $librarymail = 'library at yourname.org'; # all notices without mail are sent (in 1 mail) to this mail address. They must then be managed manually.
+ # this parameter (the last) is the text of the mail that is sent.
+ # this text contains fields that are replaced by their value. Those fields must be written between brackets
+ # The following fields are available :
+ # <date> <itemcount> <firstname> <lastname> <address1> <address2> <address3> <city> <postcode>
+ my $mailtext = "\n\n\nDear library borrower\n\n\n       <date>\n\n       According to our records, you have <itemcount> items that are at\n       least a week overdue for return to the library or renewal.\n       If you have registered a password with the library, you may use it\n       and your library card to login at http://XXX.org\n       to check the status of your account, or you may call any of our branch\n       Please be advised that all library services will be blocked\n       if items are allowed to go more than 30 days overdue.\n\n       Thank you for using your public libraries.\n\n\n                                             <firstname> <lastname>\n                                             <address1>\n                                             <address2>\n                                             <city>  <postcode>\n\n\n\n\n\n";
+ #
+ # END OF PARAMETERS
+ #
  open OUTFILE, ">overdues" or die "Cannot open file overdues: $!";
  
  # set the e-mail server -- comment out if not doing e-mail notices
! unshift @{$Mail::Sendmail::mailcfg{'smtp'}} , $smtpserver;
  #                                         set your own mail server name here
  
  my $dbh = C4::Context->dbh;
! my $sth = $dbh->prepare ("SELECT issues.borrowernumber,firstname,surname,streetaddress,physstreet,city,zipcode,emailaddress FROM issues,borrowers,categorie WHERE returndate IS NULL AND TO_DAYS(NOW())-TO_DAYS(date_due) BETWEEN $mindays and $maxdays AND issues.borrowernumber=borrowers.borrowernumber and borrowers.categorycode=categories.categorycode and categories.overduenoticerequired=1 ORDER BY issues.borrowernumber");
! my $first_borrno = $dbh->prepare ("SELECT borrowernumber FROM issues WHERE returndate IS NULL AND TO_DAYS(NOW())-TO_DAYS(date_due) BETWEEN $mindays and $maxdays ORDER BY borrowernumber");
  my $get_date = $dbh->prepare ("SELECT CURDATE()");
  
***************
*** 57,64 ****
  my $daydate = $get_date->fetchrow_arrayref;
  my $rawdate = $daydate->[0];
! my @dates = split /-/, $rawdate;              # split and reformat date
! my $date = "$dates[1]/$dates[2]/$dates[0]";
! $get_date->finish;
! 
  $first_borrno->execute;               # get first borrowernumber
  my $firstborr = $first_borrno->fetchrow_arrayref;
--- 75,79 ----
  my $daydate = $get_date->fetchrow_arrayref;
  my $rawdate = $daydate->[0];
! my $date = format_date($rawdate);
  $first_borrno->execute;               # get first borrowernumber
  my $firstborr = $first_borrno->fetchrow_arrayref;
***************
*** 77,143 ****
      my $borrno = $row->[0];
      if ($itemcount==0) {    # store values for first borrower
! 	$firstname = $row->[1];
! 	$lastname = $row->[2];
! 	$address1 = $row->[3];
! 	$address2 = $row->[4];
! 	unless ($address2) {
! 	    $address2 = '';
! 	}
! 	$city = $row->[5];
! 	unless ($city) {
! 	    $city = '';
! 	}
! 	$postcode = $row->[6];
! 	unless ($postcode) {
! 	    $postcode = '';
! 	}
! 	$email = $row->[7];
      }
      if ($borrno == $borrowernumber) {     # next borrower yet?
! 	$itemcount++;
! 	next;
      } else {
! 	$borrowernumber = $borrno;
! 	my $notice = "\n\n\n       Athens County Library Services\n       95 W. Washington Street\n       Nelsonville, OH  45674\n\n\n       $date\n\n       According to our records, you have $itemcount items that are at\n       least a week overdue for return to the library or renewal.\n       If you have registered a password with the library, you may use it\n       and your library card to login at http://koha.athenscounty.lib.oh.us\n       to check the status of your account, or you may call any of the\n       Athens County public libraries.  (Athens: 592-4272;\n       Nelsonville: 753-2118; The Plains: 797-4579; Albany: 698-3059;\n       Glouster: 767-3670; Coolville: 667-3354; and Chauncey: 797-2512)\n       Please be advised that all library services will be blocked\n       if items are allowed to go more than 30 days overdue.\n\n       Thank you for using your public libraries.\n\n\n                                             $firstname $lastname\n                                             $address1\n                                             $address2\n                                             $city  $postcode\n\n\n\n\n\n";
  
! # if not using e-mail notices, comment out the following lines
! 	if ($email) {   # or you might check for borrowers.preferredcont 
  	    my %mail = ( To      => $email,
!                          From    => 'nelpl at athenscounty.lib.oh.us',
!                          Subject => 'Overdue library items',
                           Message => $notice,
  			 );
  	    sendmail(%mail);
- 	    $e_count++
- 	} else {
- # if not using e-mail notices, comment out the above lines
- 
- 	    print $notice;
- 	    print OUTFILE $notice;
- 	    $count++;
- 	}    # and comment this one out, too, if not using e-mail
- 
- 	$itemcount = 1;   #start the count for next notice
- 	$firstname = $row->[1]; # and store the new values
- 	$lastname = $row->[2];
- 	$address1 = $row->[3];
- 	$address2 = $row->[4];
- 	unless ($address2) {
- 	    $address2 = '';
- 	}
- 	$city = $row->[5];
- 	unless ($city) {
- 	    $city = '';
- 	}
- 	$postcode = $row->[6];
- 	unless ($postcode) {
- 	    $postcode = '';
- 	}
- 	$email = $row->[7];
-     }
- }
- $sth->finish;
- close OUTFILE;
  
- print "$e_count overdue notices e-mailed\n";
- print "$count overdue notices in file for printing\n\n";
--- 92,177 ----
      my $borrno = $row->[0];
      if ($itemcount==0) {    # store values for first borrower
! 		$firstname = $row->[1];
! 		$lastname = $row->[2];
! 		$address1 = $row->[3];
! 		$address2 = $row->[4];
! 		unless ($address2) {
! 			$address2 = '';
! 		}
! 		$city = $row->[5];
! 		unless ($city) {
! 			$city = '';
! 		}
! 		$postcode = $row->[6];
! 		unless ($postcode) {
! 			$postcode = '';
! 		}
! 		$email = $row->[7];
      }
      if ($borrno == $borrowernumber) {     # next borrower yet?
! 		$itemcount++;
! 		next;
      } else {
! 		$borrowernumber = $borrno;
! 		my $notice = $mailtext;
! 		$notice =~ s/\<date\>/$date/g;
! 		$notice =~ s/\<itemcount\>/$itemcount/g;
! 		$notice =~ s/\<firstname\>/$firstname/g;
! 		$notice =~ s/\<lastname\>/$lastname/g;
! 		$notice =~ s/\<address1\>/$address1/g;
! 		$notice =~ s/\<address2\>/$address2/g;
! 		$notice =~ s/\<address3\>/$address3/g;
! 		$notice =~ s/\<city\>/$city/g;
! 		$notice =~ s/\<postcode\>/$postcode/g;
! 	
! 	# if not using e-mail notices, comment out the following lines
! 		if ($email) {   # or you might check for borrowers.preferredcont 
! 			my %mail = ( To      => $email,
! 							From    => $from,
! 							Subject => $mailtitle,
! 							Message => $notice,
! 				);
! 			sendmail(%mail);
! 			$e_count++
! 		} else {
! 		# if not using e-mail notices, comment out the above lines
! 			print $notice;
! 			print OUTFILE $notice;
! 			$count++;
! 		}    # and comment this one out, too, if not using e-mail
! 
! 		$itemcount = 1;   #start the count for next notice
! 		$firstname = $row->[1]; # and store the new values
! 		$lastname = $row->[2];
! 		$address1 = $row->[3];
! 		$address2 = $row->[4];
! 		unless ($address2) {
! 			$address2 = '';
! 		}
! 		$city = $row->[5];
! 		unless ($city) {
! 			$city = '';
! 		}
! 		$postcode = $row->[6];
! 		unless ($postcode) {
! 			$postcode = '';
! 		}
! 		$email = $row->[7];
! 	}
! }
! $sth->finish;
! close OUTFILE;
! # if some notices have to be printed & managed by the library, send them to library mail address.
! if ($count) {
! 		open ODUES, "overdues" or die "Cannot open file overdues: $!";
! 		my $notice = "$e_count overdue notices e-mailed\n";
! 		my $notice .= "$count overdue notices in file for printing\n\n";
  
! 		my $notice .= <ODUES>;
  	    my %mail = ( To      => $email,
!                          From    => $from,
!                          Subject => 'Koha overdues',
                           Message => $notice,
  			 );
  	    sendmail(%mail);
  





More information about the Koha-cvs mailing list