fixing limit by availability, using nifty _ALLRECORDS in Zebra
authorJoshua Ferraro <jmf@liblime.com>
Sat, 24 Nov 2007 21:10:18 +0000 (15:10 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Sun, 25 Nov 2007 22:26:20 +0000 (16:26 -0600)
to handle NULL values

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Search.pm
etc/zebradb/biblios/etc/bib1.att
etc/zebradb/biblios/etc/record.abs
etc/zebradb/ccl.properties
misc/cronjobs/overduenotices-30.pl [new file with mode: 0755]
misc/cronjobs/overduenotices.pl [new file with mode: 0644]
misc/overduenotices-30.pl [deleted file]
misc/overduenotices.pl [deleted file]

index c277ff3..340378e 100644 (file)
@@ -838,10 +838,11 @@ sub buildQuery {
 
     # add limits
        my $group_OR_limits;
+       my $availability_limit;
     foreach my $this_limit (@limits) {
         if ( $this_limit =~ /available/ ) {
-                       # FIXME: switch to zebra search for null values
-            $limit .= " (($query and datedue=0000-00-00) or ($query and datedue=0000-00-00 not lost=1) or ($query and datedue=0000-00-00 not lost=2))";
+                       # available is defined as (items.notloan is NULL) and (items.itemlost > 0 or NULL) (last clause handles NULL values for lost in zebra)
+                       $availability_limit .="( ( allrecords,AlwaysMatches='' not onloan,AlwaysMatches='') and ((lost,st-numeric gt 0) or ( allrecords,AlwaysMatches='' not lost,AlwaysMatches='')) )";
                        $limit_cgi .= "&limit=available";
                        $limit_desc .="";
         }
@@ -867,6 +868,10 @@ sub buildQuery {
                $limit.=" and " if ($query || $limit );
                $limit.="($group_OR_limits)";
        }
+       if ($availability_limit) {
+               $limit.=" not " if ($query || $limit );
+               $limit.="$availability_limit";
+       }
        # normalize the strings
        for ($query, $query_desc, $limit, $limit_desc) {
                $_ =~ s/  / /g;    # remove extra spaces
index f5c8a8c..e4ed301 100644 (file)
@@ -117,37 +117,37 @@ att 9009                  cn-prefix
 att 9010                       cn-suffix
 
 # Items Index
-att 8001 withdrawn
-att 8002 lost
-att 8003 classification-source
-att 8004 materials-specified
-att 8005 damaged
-att 8006 restricted
-att 8007 cn-sort
-att 8008 notforloan
-att 8009 ccode
-att 8010 itemnumber
-att 8011 homebranch
-att 8012 holdingbranch
-att 8013 location
-att 8014 Date-of-acquisition
-att 8015 acqsource
-att 8016 coded-location-qualifier
-att 8017 price
-att 8018 stack
-att 8019 issues
-att 8020 renewals
-att 8021 reserves
-att 8022 Local-classification
-att 8023 barcode
-att 8024 onloan
-att 8025 datelastseen
-att 8026 datelastborrowed
-att 8027 copynumber
-att 8028 uri
-att 8029 replacementprice
-att 8030 replacementpricedate
-att 8031 itype
+att 8001                       withdrawn
+att 8002                       lost
+att 8003                       classification-source
+att 8004                       materials-specified
+att 8005                       damaged
+att 8006                       restricted
+att 8007                       cn-sort
+att 8008                       notforloan
+att 8009                       ccode
+att 8010                       itemnumber
+att 8011                       homebranch
+att 8012                       holdingbranch
+att 8013                       location
+att 8014                       Date-of-acquisition
+att 8015                       acqsource
+att 8016                       coded-location-qualifier
+att 8017                       price
+att 8018                       stack
+att 8019                       issues
+att 8020                       renewals
+att 8021                       reserves
+att 8022                       Local-classification
+att 8023                       barcode
+att 8024                       onloan
+att 8025                       datelastseen
+att 8026                       datelastborrowed
+att 8027                       copynumber
+att 8028                       uri
+att 8029                       replacementprice
+att 8030                       replacementpricedate
+att 8031                       itype
 
 ## Fixed Fields and other special indexes
 att 9901                       Extent
index f7f0d85..f356fe6 100644 (file)
@@ -227,11 +227,11 @@ melm 840          Title,Title-series
 
 ###############################
 # Koha Local-Use Biblio Indexes
-melm 999$c             Local-Number !:w,!:p,!:s
-melm 999$d             biblioitemnumber:n,!:s
-melm 942$0             totalissues:n,!:s
+melm 999$c             Local-Number:n,Local-Number:w,Local-Number:s
+melm 999$d             biblioitemnumber:n,biblioitemnumber:w,biblioitemnumber:s
+melm 942$0             totalissues:n,totalissues:s
 melm 942$2             cn-bib-source
-melm 942$6             cn-bib-sort:n,!:s
+melm 942$6             cn-bib-sort:n,cn-bib-sort:s
 melm 942$c             itemtype:w
 
 # need to check bib1
@@ -241,16 +241,16 @@ melm 942$k                cn-prefix
 melm 942$m             cn-suffix
 
 # Items Indexes
-melm 952$0             withdrawn:n,!:w
-melm 952$1             lost:n,!:w
+melm 952$0             withdrawn:n,withdrawn:w
+melm 952$1             lost,lost:n
 melm 952$2             classification-source
 melm 952$3             materials-specified     
-melm 952$4             damaged:n,!:w
-melm 952$5             restricted:n,!:w
-melm 952$6             cn-sort:n,!:s
-melm 952$7             notforloan:n,!:w
+melm 952$4             damaged:n,damaged:w
+melm 952$5             restricted:n,restricted:w
+melm 952$6             cn-sort:n,cn-sort:s
+melm 952$7             notforloan:n,notforloan:w
 melm 952$8             ccode
-melm 952$9             itemnumber:n,!:s
+melm 952$9             itemnumber:n,itemnumber:s
 melm 952$a             homebranch
 melm 952$b             holdingbranch
 melm 952$c             location
@@ -262,18 +262,18 @@ melm 952$f                coded-location-qualifier
 melm 952$g             price
 #melm 952$h            
 #melm 952$i            
-melm 952$j             stack:n,!:w
+melm 952$j             stack:n,stack:w
 #melm 952$k            
-melm 952$l             issues:n,!:w,!:s
-melm 952$m             renewals:n,!:w
-melm 952$n             reserves:n,!:w
+melm 952$l             issues:n,issues:w,issues:s
+melm 952$m             renewals:n,renewals:w
+melm 952$n             reserves:n,reserves:w
 melm 952$o             Local-classification:w,Local-classification:p,Local-classification:s
-melm 952$p             barcode,!:n
-melm 952$q             onloan:n,!:w
+melm 952$p             barcode,barcode:n
+melm 952$q             onloan:n,onloan:w
 melm 952$r             datelastseen
 melm 952$s             datelastborrowed
 melm 952$t             copynumber
-melm 952$u             uri:u,!:w
+melm 952$u             uri:u,url:w
 melm 952$v             replacementprice
 melm 952$w             replacementpricedate
 #melm 952$x
index c9a306c..1897565 100644 (file)
@@ -822,7 +822,9 @@ relevance 2=102
 rk 2=102
 rank relevance
 
+allrecords 1=_ALLRECORDS
 AlwaysMatches 2=103
+
 Within 2=104
 
 ### 3. BIB1 POSITION ATTRIBUTES
@@ -908,16 +910,16 @@ cn-prefix 1=9009
 cn-suffix 1=9010
 
 # Items Index
-withdrawn 1=8001 4=109
-lost 1=8002 4=109
+withdrawn 1=8001
+lost 1=8002
 classification-source 1=8003
 materials-specified 1=8004
-damaged 1=8005 4=109
-restricted 1=8006 4=109
+damaged 1=8005
+restricted 1=8006
 cn-sort 1=8007
-notforloan 1=8008 4=109
+notforloan 1=8008
 ccode 1=8009
-itemnumber 1=8010 4=109
+itemnumber 1=8010
 Code-institution 1=8011
 holdingbranch 1=8012
 location 1=8013
@@ -931,7 +933,7 @@ renewals 1=8020 4=109
 reserves 1=8021 4=109
 Local-classification 1=8022
 barcode 1=8023
-onloan 1=8024 4=109
+onloan 1=8024
 datelastseen 1=8025
 datelastborrowed 1=8026
 copynumber 1=8027
@@ -949,7 +951,6 @@ pl Place-publication
 # Extent
 #Extent 1=8001
 
-#Summary                       1=8002
 #att 8900            
 #Call-Number 1=8900
 #date-entered-on-file 1=8800
@@ -963,10 +964,6 @@ ff8-34 1=8834
 #att 8700            ff7-00
 #att 8701            ff7-01
 #att 8702            ff7-02
-#att 9520            withdrawn
-#att 9521            lost
-#lost 1=9521 4=109
-#att 9522            onloan
 
 ############## SUBJECT-RELATED
 # Topical Term
@@ -1017,9 +1014,6 @@ Illustration-code 1=Illustration-code
 #yr 1=8801 4=109 r=r
 
 ## STATUSES
-onloan 1=9522
-datedue 1=9522
-
 popularity 1=issues
 
 # Material Category
diff --git a/misc/cronjobs/overduenotices-30.pl b/misc/cronjobs/overduenotices-30.pl
new file mode 100755 (executable)
index 0000000..40e9922
--- /dev/null
@@ -0,0 +1,209 @@
+#!/usr/bin/perl -w
+#-----------------------------------
+# Script Name: overduenotices.pl
+# Script Version: 1.0
+# Date:  2003/9/7
+# Author:  Stephen Hedges (shedges@skemotah.com)
+# modified by Paul Poulain (paul@koha-fr.org)
+# modified by Henri-Damien LAURENT (henridamien@koha-fr.org)
+# Description: 
+#      This script runs a Koha report of items using overduerules tables and letters tool management.
+# Revision History:
+#    1.0  2003/9/7: original version
+#    1.5  2006/2/28: Modifications for managing Letters and overduerules
+#-----------------------------------
+# Copyright 2003 Skemotah Solutions
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+use strict;
+use C4::Context;
+use C4::Date;
+use Mail::Sendmail;  # comment out if not doing e-mail notices
+use Getopt::Long;
+
+my ($confirm, $nomail, $mybranch, $myborcat,$myborcatout, $letter, $MAX, $choice);
+GetOptions(
+    'c'    => \$confirm,
+    'n'        => \$nomail,
+    'max=s'    => \$MAX,
+    'all'      => \$choice,
+);
+unless ($confirm) {
+        print qq|
+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.
+You MUST edit this script for your library BEFORE you run it for the first time!
+See the comments in the script for directions on changing the script.
+This script has 2 parameters :
+        -c to confirm and remove this help & warning
+        -n to avoid sending any mail. Instead, all mail messages are printed on screen. Usefull for testing purposes.
+        -branch <branchcode> to select overdues for ONE specific branch.
+        -borcat <borcatcode> to select overdues for one borrower category,
+        -borcatout <borcatcode> to exclude this borrower category from overdunotices,
+        -max <MAX> MAXIMUM day count before stopping to send overdue notice,
+        -file <filename> to enter a specific filename to be read for message.
+        -all to include ALL the items that reader borrowed.
+
+Do you wish to continue? (y/n)
+|;
+        chomp($_ = <STDIN>);
+        exit unless (/^(y|Y|o|O)/i);  # comment these lines out once you've made the changes
+        
+}
+my $dbh = C4::Context->dbh;
+my $rqoverduebranches=$dbh->prepare("SELECT DISTINCT branchcode FROM overduerules WHERE delay1>0");
+$rqoverduebranches->execute;
+while (my ($branchcode)=$rqoverduebranches->fetchrow){
+    warn "branchcode : $branchcode";
+    my $branchname;
+    my $emailaddress;
+    if ($branchcode){
+        my $rqbranch=$dbh->prepare("SELECT * FROM branches WHERE branchcode = ?");
+        $rqbranch->execute($branchcode);
+        my $data = $rqbranch->fetchrow_hashref;
+        $emailaddress = $data->{branchemail};
+        $branchname = $data->{branchname};
+    }
+    $emailaddress=C4::Context->preference('KohaAdminEmailAddress') unless ($emailaddress);
+
+    #print STDERR "$emailaddress\n";
+    #
+    # BEGINNING OF PARAMETERS
+    #
+    my $rqoverduerules=$dbh->prepare("SELECT * FROM overduerules WHERE delay1>0 and branchcode = ?");
+    $rqoverduerules->execute($branchcode);
+    while (my $data=$rqoverduerules->fetchrow_hashref){
+        for (my $i=1; $i<=3;$i++){
+            #Two actions :
+            # A- Send a letter
+            # B- Debar
+            my $mindays = $data->{"delay$i"}; # the notice will be sent after mindays days (grace period)
+            my $rqdebarring=$dbh->prepare("UPDATE borrowers SET debarred=1 WHERE borrowernumber=?") if $data->{"debarred$i"};
+            my $maxdays = ($data->{"delay".($i+1)}?
+                            $data->{"delay".($i+1)}
+                            :($MAX?$MAX:365)); # issues being more than maxdays late are managed somewhere else. (borrower probably suspended)
+            #LETTER parameters
+            my $smtpserver = 'smtp.wanadoo.fr'; # your smtp server (the server who sent mails)
+            my $from = $emailaddress; # all the mails sent to the borrowers will appear coming from here.
+            my $mailtitle = 'Overdue'; # the title of the mails
+            $mailtitle = 'Issue status' if ($choice); # the title of the mails
+            my $librarymail = $emailaddress; # all notices without mail are sent (in 1 mail) to this mail address. They must then be managed manually.
+            my $letter = $data->{"letter$i"} if $data->{"letter$i"};
+            # 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=$letter;
+            #
+            # 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 $strsth = "SELECT COUNT(*), issues.borrowernumber,firstname,surname,address,address2,city,zipcode, email, MIN(date_due) as longest_issue FROM issues,borrowers,categories WHERE returndate IS NULL AND issues.borrowernumber=borrowers.borrowernumber AND borrowers.categorycode=categories.categorycode ";
+            $strsth .= " AND issues.branchcode='".$branchcode."' " if ($branchcode);
+            $strsth .= " AND borrowers.categorycode='".$data->{categorycode}."' " if ($data->{categorycode});
+            $strsth .= " AND categories.overduenoticerequired=1 GROUP BY issues.borrowernumber HAVING TO_DAYS(NOW())-TO_DAYS(longest_issue) BETWEEN $mindays and $maxdays ";
+            my $sth = $dbh->prepare ($strsth);
+#             warn "".$strsth;
+            my $sth2 = $dbh->prepare("SELECT biblio.title,biblio.author,items.barcode, issues.timestamp FROM issues,items,biblio WHERE items.itemnumber=issues.itemnumber and biblio.biblionumber=items.biblionumber AND issues.borrowernumber=? AND returndate IS NULL AND TO_DAYS(NOW())-TO_DAYS(date_due) BETWEEN $mindays and $maxdays");
+
+            $sth->execute;
+            # 
+            # my $itemcount = 0;
+            # my $row;
+            my $count = 0;   # to keep track of how many notices are printed
+            my $e_count = 0;   # and e-mailed
+            my $date=format_date(localtime);
+            my ($itemcount,$borrowernumber,$firstname,$lastname,$address1,$address2,$city,$postcode,$email);
+            
+            while (($itemcount, $borrowernumber, $firstname, $lastname, $address1, $address2, $city, $postcode, $email) = $sth->fetchrow) {
+                if ($data->{"debarred$i"}){
+                    #action taken is debarring
+                    $rqdebarring->execute($borrowernumber);
+                    warn "debarring $borrowernumber $firstname $lastname";
+                }
+                if ($letter){
+                    my $notice .= $mailtext;
+                    $notice =~ s/\<itemcount\>/$itemcount/g if ($itemcount);
+                    $notice =~ s/\<firstname\>/$firstname/g if ($firstname);
+                    $notice =~ s/\<lastname\>/$lastname/g if ($lastname);
+                    $notice =~ s/\<address1\>/$address1/g if ($address1);
+                    $notice =~ s/\<address2\>/$address2/g if ($address2);
+                    $notice =~ s/\<city\>/$city/g if ($city);
+                    $notice =~ s/\<postcode\>/$postcode/g if ($postcode);
+                    $notice =~ s/\<date\>/$date/g if ($date);
+                    $notice =~ s/\<bib\>/$branchname/g if ($branchname);
+    
+                    $sth2->execute($borrowernumber);
+                    my $titles="";
+                    my ($title, $author, $barcode, $issuedate);
+                    while (($title, $author, $barcode,$issuedate) = $sth2->fetchrow){
+                            $titles .= "       ".format_date($issuedate)."     ".($barcode?$barcode:"")."      ".($title?$title:"")."  ".($author?$author:"")."\n";
+                    }
+                    $notice =~ s/\<titles\>/$titles/g;
+                    $sth2->finish;
+                    # if not using e-mail notices, comment out the following lines
+                    if ($email) {   # or you might check for borrowers.preferredcont 
+                        if ($nomail) {
+                            print "TO => $email\n";
+                            print "FROM => $from\n";
+                            print "SUBJECT => $mailtitle\n";
+                            print "MESSAGE => $notice\n";
+                        } else {
+                            my %mail = ( To      => $email,
+                                        From    => $from,
+                                        Subject => $mailtitle,
+                                        Message => $notice,
+                                    );
+                            sendmail(%mail);
+                        }
+                        $e_count++
+                    } else {
+                        print OUTFILE $notice;
+                        $count++;
+                    }    # and comment this one out, too, if not using e-mail
+                }
+            }
+            $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";
+                $notice .= "$count overdue notices in file for printing\n\n";
+
+                $notice .= <ODUES>;
+                if ($nomail) {
+                    print "TO => $email\n" if $email;
+                    print "FROM => $from\n";
+                    print "SUBJECT => Koha overdue\n";
+                    print "MESSAGE => $notice\n";
+                } else {
+                    my %mail = (To      => $email,
+                                From    => $from,
+                                Subject => 'Koha overdues',
+                                Message => $notice,
+                            );
+                    sendmail(%mail);
+                }
+            }
+        }
+    }
+}
diff --git a/misc/cronjobs/overduenotices.pl b/misc/cronjobs/overduenotices.pl
new file mode 100644 (file)
index 0000000..349f4d3
--- /dev/null
@@ -0,0 +1,163 @@
+#!/usr/bin/perl -w
+#-----------------------------------
+# Script Name: overduenotices.pl
+# Script Version: 1.0
+# Date:  2003/9/7
+# Author:  Stephen Hedges (shedges@skemotah.com)
+# modified by Paul Poulain (paul@koha-fr.org)
+# Description: 
+#      This script runs a Koha report of items that
+#      are between 7 and 30 days overdue and generates
+#       a file that may be dumped to a printer.  The time period
+#      may be changed by editing the SQL statement handle
+#      prepared in line 52.  The actual wording of the overdue
+#      notices may be changed by editing the $notice variable
+#      in line 101.  The current notice text is formatted to
+#      fit the standard 34-line 'Speedimailer' form.
+# Revision History:
+#    1.0  2003/9/7: original version
+#-----------------------------------
+# Copyright 2003 Skemotah Solutions
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+use strict;
+use C4::Context;
+use C4::Date;
+use Mail::Sendmail;  # comment out if not doing e-mail notices
+use Getopt::Long;
+
+my ($confirm, $nomail);
+GetOptions(
+    'c'    => \$confirm,
+       'n'     => \$nomail,
+);
+unless ($confirm) {
+       print qq|
+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.
+You MUST edit this script for your library BEFORE you run it for the first time!
+See the comments in the script for directions on changing the script.
+This script has 2 parameters :
+       -c to confirm and remove this help & warning
+       -n to avoid sending any mail. Instead, all mail messages are printed on screen. Usefull for testing purposes.
+
+Do you wish to continue? (y/n)
+|;
+       chomp($_ = <STDIN>);
+       exit 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.server.com'; # your smtp server (the server who sent mails)
+my $from = 'librarianname@library.com'; # all the mails sent to the borrowers will appear coming from here.
+my $mailtitle = 'Overdues'; # the title of the mails
+my $librarymail = 'librarystaff@library.com'; # 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, the description of which follows, that are at\n       least a week overdue for return to the library or renewal:\n              title           author          barcode\n<titles>\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 COUNT(*), issues.borrowernumber,firstname,surname,streetaddress,physstreet,city,zipcode,emailaddress FROM issues,borrowers,categories WHERE returndate IS NULL AND TO_DAYS(NOW())-TO_DAYS(date_due) BETWEEN 0 and 500 AND issues.borrowernumber=borrowers.borrowernumber and borrowers.categorycode=categories.categorycode and categories.overduenoticerequired=1 group by issues.borrowernumber");
+my $sth2 = $dbh->prepare("SELECT biblio.title,biblio.author,items.barcode FROM issues,items,biblio WHERE items.itemnumber=issues.itemnumber and biblio.biblionumber=items.biblionumber AND issues.borrowernumber=? AND returndate IS NULL AND TO_DAYS(NOW())-TO_DAYS(date_due) BETWEEN 0 and 500");
+
+$sth->execute;
+# 
+# my $itemcount = 0;
+# my $row;
+my $count = 0;   # to keep track of how many notices are printed
+my $e_count = 0;   # and e-mailed
+my $date=localtime;
+my ($itemcount,$borrowernumber,$firstname,$lastname,$address1,$address2,$city,$postcode,$email);
+
+while (($itemcount,$borrowernumber,$firstname,$lastname,$address1,$address2,$city,$postcode,$email) = $sth->fetchrow) {
+               my $notice = $mailtext;
+               $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/\<city\>/$city/g;
+               $notice =~ s/\<postcode\>/$postcode/g;
+               $notice =~ s/\<date\>/$date/g;
+
+               $sth2->execute($borrowernumber);
+               my $titles="";
+               my ($title, $author, $barcode);
+               while (($title, $author, $barcode) = $sth2->fetchrow){
+                       $titles .= "            ".($title?$title:"")."  ".($author?$author:"")."        ".($barcode?$barcode:"")."\n";
+               }
+               $notice =~ s/\<titles\>/$titles/g;
+               $sth2->finish;
+       # if not using e-mail notices, comment out the following lines
+               if ($email) {   # or you might check for borrowers.preferredcont 
+                       if ($nomail) {
+                               print "TO => $email\n";
+                               print "FROM => $from\n";
+                               print "SUBJECT => $mailtitle\n";
+                               print "MESSAGE => $notice\n";
+                       } else {
+                               my %mail = ( To      => $email,
+                                                               From    => $from,
+                                                               Subject => $mailtitle,
+                                                               Message => $notice,
+                                       );
+                               sendmail(%mail);
+                       }
+                       $e_count++
+               } else {
+                       print OUTFILE $notice;
+                       $count++;
+               }    # and comment this one out, too, if not using e-mail
+
+}
+$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";
+               $notice .= "$count overdue notices in file for printing\n\n";
+
+               $notice .= <ODUES>;
+               if ($nomail) {
+                       print "TO => $email\n" if $email;
+                       print "FROM => $from\n";
+                       print "SUBJECT => Koha overdue\n";
+                       print "MESSAGE => $notice\n";
+               } else {
+                       my %mail = ( To      => $email,
+                                                       From    => $from,
+                                                       Subject => 'Koha overdues',
+                                                       Message => $notice,
+                               );
+                       sendmail(%mail);
+               }
+}
diff --git a/misc/overduenotices-30.pl b/misc/overduenotices-30.pl
deleted file mode 100755 (executable)
index 40e9922..0000000
+++ /dev/null
@@ -1,209 +0,0 @@
-#!/usr/bin/perl -w
-#-----------------------------------
-# Script Name: overduenotices.pl
-# Script Version: 1.0
-# Date:  2003/9/7
-# Author:  Stephen Hedges (shedges@skemotah.com)
-# modified by Paul Poulain (paul@koha-fr.org)
-# modified by Henri-Damien LAURENT (henridamien@koha-fr.org)
-# Description: 
-#      This script runs a Koha report of items using overduerules tables and letters tool management.
-# Revision History:
-#    1.0  2003/9/7: original version
-#    1.5  2006/2/28: Modifications for managing Letters and overduerules
-#-----------------------------------
-# Copyright 2003 Skemotah Solutions
-#
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
-#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
-
-use strict;
-use C4::Context;
-use C4::Date;
-use Mail::Sendmail;  # comment out if not doing e-mail notices
-use Getopt::Long;
-
-my ($confirm, $nomail, $mybranch, $myborcat,$myborcatout, $letter, $MAX, $choice);
-GetOptions(
-    'c'    => \$confirm,
-    'n'        => \$nomail,
-    'max=s'    => \$MAX,
-    'all'      => \$choice,
-);
-unless ($confirm) {
-        print qq|
-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.
-You MUST edit this script for your library BEFORE you run it for the first time!
-See the comments in the script for directions on changing the script.
-This script has 2 parameters :
-        -c to confirm and remove this help & warning
-        -n to avoid sending any mail. Instead, all mail messages are printed on screen. Usefull for testing purposes.
-        -branch <branchcode> to select overdues for ONE specific branch.
-        -borcat <borcatcode> to select overdues for one borrower category,
-        -borcatout <borcatcode> to exclude this borrower category from overdunotices,
-        -max <MAX> MAXIMUM day count before stopping to send overdue notice,
-        -file <filename> to enter a specific filename to be read for message.
-        -all to include ALL the items that reader borrowed.
-
-Do you wish to continue? (y/n)
-|;
-        chomp($_ = <STDIN>);
-        exit unless (/^(y|Y|o|O)/i);  # comment these lines out once you've made the changes
-        
-}
-my $dbh = C4::Context->dbh;
-my $rqoverduebranches=$dbh->prepare("SELECT DISTINCT branchcode FROM overduerules WHERE delay1>0");
-$rqoverduebranches->execute;
-while (my ($branchcode)=$rqoverduebranches->fetchrow){
-    warn "branchcode : $branchcode";
-    my $branchname;
-    my $emailaddress;
-    if ($branchcode){
-        my $rqbranch=$dbh->prepare("SELECT * FROM branches WHERE branchcode = ?");
-        $rqbranch->execute($branchcode);
-        my $data = $rqbranch->fetchrow_hashref;
-        $emailaddress = $data->{branchemail};
-        $branchname = $data->{branchname};
-    }
-    $emailaddress=C4::Context->preference('KohaAdminEmailAddress') unless ($emailaddress);
-
-    #print STDERR "$emailaddress\n";
-    #
-    # BEGINNING OF PARAMETERS
-    #
-    my $rqoverduerules=$dbh->prepare("SELECT * FROM overduerules WHERE delay1>0 and branchcode = ?");
-    $rqoverduerules->execute($branchcode);
-    while (my $data=$rqoverduerules->fetchrow_hashref){
-        for (my $i=1; $i<=3;$i++){
-            #Two actions :
-            # A- Send a letter
-            # B- Debar
-            my $mindays = $data->{"delay$i"}; # the notice will be sent after mindays days (grace period)
-            my $rqdebarring=$dbh->prepare("UPDATE borrowers SET debarred=1 WHERE borrowernumber=?") if $data->{"debarred$i"};
-            my $maxdays = ($data->{"delay".($i+1)}?
-                            $data->{"delay".($i+1)}
-                            :($MAX?$MAX:365)); # issues being more than maxdays late are managed somewhere else. (borrower probably suspended)
-            #LETTER parameters
-            my $smtpserver = 'smtp.wanadoo.fr'; # your smtp server (the server who sent mails)
-            my $from = $emailaddress; # all the mails sent to the borrowers will appear coming from here.
-            my $mailtitle = 'Overdue'; # the title of the mails
-            $mailtitle = 'Issue status' if ($choice); # the title of the mails
-            my $librarymail = $emailaddress; # all notices without mail are sent (in 1 mail) to this mail address. They must then be managed manually.
-            my $letter = $data->{"letter$i"} if $data->{"letter$i"};
-            # 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=$letter;
-            #
-            # 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 $strsth = "SELECT COUNT(*), issues.borrowernumber,firstname,surname,address,address2,city,zipcode, email, MIN(date_due) as longest_issue FROM issues,borrowers,categories WHERE returndate IS NULL AND issues.borrowernumber=borrowers.borrowernumber AND borrowers.categorycode=categories.categorycode ";
-            $strsth .= " AND issues.branchcode='".$branchcode."' " if ($branchcode);
-            $strsth .= " AND borrowers.categorycode='".$data->{categorycode}."' " if ($data->{categorycode});
-            $strsth .= " AND categories.overduenoticerequired=1 GROUP BY issues.borrowernumber HAVING TO_DAYS(NOW())-TO_DAYS(longest_issue) BETWEEN $mindays and $maxdays ";
-            my $sth = $dbh->prepare ($strsth);
-#             warn "".$strsth;
-            my $sth2 = $dbh->prepare("SELECT biblio.title,biblio.author,items.barcode, issues.timestamp FROM issues,items,biblio WHERE items.itemnumber=issues.itemnumber and biblio.biblionumber=items.biblionumber AND issues.borrowernumber=? AND returndate IS NULL AND TO_DAYS(NOW())-TO_DAYS(date_due) BETWEEN $mindays and $maxdays");
-
-            $sth->execute;
-            # 
-            # my $itemcount = 0;
-            # my $row;
-            my $count = 0;   # to keep track of how many notices are printed
-            my $e_count = 0;   # and e-mailed
-            my $date=format_date(localtime);
-            my ($itemcount,$borrowernumber,$firstname,$lastname,$address1,$address2,$city,$postcode,$email);
-            
-            while (($itemcount, $borrowernumber, $firstname, $lastname, $address1, $address2, $city, $postcode, $email) = $sth->fetchrow) {
-                if ($data->{"debarred$i"}){
-                    #action taken is debarring
-                    $rqdebarring->execute($borrowernumber);
-                    warn "debarring $borrowernumber $firstname $lastname";
-                }
-                if ($letter){
-                    my $notice .= $mailtext;
-                    $notice =~ s/\<itemcount\>/$itemcount/g if ($itemcount);
-                    $notice =~ s/\<firstname\>/$firstname/g if ($firstname);
-                    $notice =~ s/\<lastname\>/$lastname/g if ($lastname);
-                    $notice =~ s/\<address1\>/$address1/g if ($address1);
-                    $notice =~ s/\<address2\>/$address2/g if ($address2);
-                    $notice =~ s/\<city\>/$city/g if ($city);
-                    $notice =~ s/\<postcode\>/$postcode/g if ($postcode);
-                    $notice =~ s/\<date\>/$date/g if ($date);
-                    $notice =~ s/\<bib\>/$branchname/g if ($branchname);
-    
-                    $sth2->execute($borrowernumber);
-                    my $titles="";
-                    my ($title, $author, $barcode, $issuedate);
-                    while (($title, $author, $barcode,$issuedate) = $sth2->fetchrow){
-                            $titles .= "       ".format_date($issuedate)."     ".($barcode?$barcode:"")."      ".($title?$title:"")."  ".($author?$author:"")."\n";
-                    }
-                    $notice =~ s/\<titles\>/$titles/g;
-                    $sth2->finish;
-                    # if not using e-mail notices, comment out the following lines
-                    if ($email) {   # or you might check for borrowers.preferredcont 
-                        if ($nomail) {
-                            print "TO => $email\n";
-                            print "FROM => $from\n";
-                            print "SUBJECT => $mailtitle\n";
-                            print "MESSAGE => $notice\n";
-                        } else {
-                            my %mail = ( To      => $email,
-                                        From    => $from,
-                                        Subject => $mailtitle,
-                                        Message => $notice,
-                                    );
-                            sendmail(%mail);
-                        }
-                        $e_count++
-                    } else {
-                        print OUTFILE $notice;
-                        $count++;
-                    }    # and comment this one out, too, if not using e-mail
-                }
-            }
-            $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";
-                $notice .= "$count overdue notices in file for printing\n\n";
-
-                $notice .= <ODUES>;
-                if ($nomail) {
-                    print "TO => $email\n" if $email;
-                    print "FROM => $from\n";
-                    print "SUBJECT => Koha overdue\n";
-                    print "MESSAGE => $notice\n";
-                } else {
-                    my %mail = (To      => $email,
-                                From    => $from,
-                                Subject => 'Koha overdues',
-                                Message => $notice,
-                            );
-                    sendmail(%mail);
-                }
-            }
-        }
-    }
-}
diff --git a/misc/overduenotices.pl b/misc/overduenotices.pl
deleted file mode 100644 (file)
index 349f4d3..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-#!/usr/bin/perl -w
-#-----------------------------------
-# Script Name: overduenotices.pl
-# Script Version: 1.0
-# Date:  2003/9/7
-# Author:  Stephen Hedges (shedges@skemotah.com)
-# modified by Paul Poulain (paul@koha-fr.org)
-# Description: 
-#      This script runs a Koha report of items that
-#      are between 7 and 30 days overdue and generates
-#       a file that may be dumped to a printer.  The time period
-#      may be changed by editing the SQL statement handle
-#      prepared in line 52.  The actual wording of the overdue
-#      notices may be changed by editing the $notice variable
-#      in line 101.  The current notice text is formatted to
-#      fit the standard 34-line 'Speedimailer' form.
-# Revision History:
-#    1.0  2003/9/7: original version
-#-----------------------------------
-# Copyright 2003 Skemotah Solutions
-#
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
-#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
-
-use strict;
-use C4::Context;
-use C4::Date;
-use Mail::Sendmail;  # comment out if not doing e-mail notices
-use Getopt::Long;
-
-my ($confirm, $nomail);
-GetOptions(
-    'c'    => \$confirm,
-       'n'     => \$nomail,
-);
-unless ($confirm) {
-       print qq|
-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.
-You MUST edit this script for your library BEFORE you run it for the first time!
-See the comments in the script for directions on changing the script.
-This script has 2 parameters :
-       -c to confirm and remove this help & warning
-       -n to avoid sending any mail. Instead, all mail messages are printed on screen. Usefull for testing purposes.
-
-Do you wish to continue? (y/n)
-|;
-       chomp($_ = <STDIN>);
-       exit 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.server.com'; # your smtp server (the server who sent mails)
-my $from = 'librarianname@library.com'; # all the mails sent to the borrowers will appear coming from here.
-my $mailtitle = 'Overdues'; # the title of the mails
-my $librarymail = 'librarystaff@library.com'; # 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, the description of which follows, that are at\n       least a week overdue for return to the library or renewal:\n              title           author          barcode\n<titles>\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 COUNT(*), issues.borrowernumber,firstname,surname,streetaddress,physstreet,city,zipcode,emailaddress FROM issues,borrowers,categories WHERE returndate IS NULL AND TO_DAYS(NOW())-TO_DAYS(date_due) BETWEEN 0 and 500 AND issues.borrowernumber=borrowers.borrowernumber and borrowers.categorycode=categories.categorycode and categories.overduenoticerequired=1 group by issues.borrowernumber");
-my $sth2 = $dbh->prepare("SELECT biblio.title,biblio.author,items.barcode FROM issues,items,biblio WHERE items.itemnumber=issues.itemnumber and biblio.biblionumber=items.biblionumber AND issues.borrowernumber=? AND returndate IS NULL AND TO_DAYS(NOW())-TO_DAYS(date_due) BETWEEN 0 and 500");
-
-$sth->execute;
-# 
-# my $itemcount = 0;
-# my $row;
-my $count = 0;   # to keep track of how many notices are printed
-my $e_count = 0;   # and e-mailed
-my $date=localtime;
-my ($itemcount,$borrowernumber,$firstname,$lastname,$address1,$address2,$city,$postcode,$email);
-
-while (($itemcount,$borrowernumber,$firstname,$lastname,$address1,$address2,$city,$postcode,$email) = $sth->fetchrow) {
-               my $notice = $mailtext;
-               $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/\<city\>/$city/g;
-               $notice =~ s/\<postcode\>/$postcode/g;
-               $notice =~ s/\<date\>/$date/g;
-
-               $sth2->execute($borrowernumber);
-               my $titles="";
-               my ($title, $author, $barcode);
-               while (($title, $author, $barcode) = $sth2->fetchrow){
-                       $titles .= "            ".($title?$title:"")."  ".($author?$author:"")."        ".($barcode?$barcode:"")."\n";
-               }
-               $notice =~ s/\<titles\>/$titles/g;
-               $sth2->finish;
-       # if not using e-mail notices, comment out the following lines
-               if ($email) {   # or you might check for borrowers.preferredcont 
-                       if ($nomail) {
-                               print "TO => $email\n";
-                               print "FROM => $from\n";
-                               print "SUBJECT => $mailtitle\n";
-                               print "MESSAGE => $notice\n";
-                       } else {
-                               my %mail = ( To      => $email,
-                                                               From    => $from,
-                                                               Subject => $mailtitle,
-                                                               Message => $notice,
-                                       );
-                               sendmail(%mail);
-                       }
-                       $e_count++
-               } else {
-                       print OUTFILE $notice;
-                       $count++;
-               }    # and comment this one out, too, if not using e-mail
-
-}
-$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";
-               $notice .= "$count overdue notices in file for printing\n\n";
-
-               $notice .= <ODUES>;
-               if ($nomail) {
-                       print "TO => $email\n" if $email;
-                       print "FROM => $from\n";
-                       print "SUBJECT => Koha overdue\n";
-                       print "MESSAGE => $notice\n";
-               } else {
-                       my %mail = ( To      => $email,
-                                                       From    => $from,
-                                                       Subject => 'Koha overdues',
-                                                       Message => $notice,
-                               );
-                       sendmail(%mail);
-               }
-}