2 #-----------------------------------
3 # Script Name: reservefix.pl
4 # Script Version: 1.0.0
6 # Author: Stephen Hedges shedges@skemotah.com
7 # Description: fixes priority of reserves
8 # It also e-mails a list of 'problem' reserves
10 # Usage: reservefix.pl.
12 # 1.0.0 2004/02/22: original version
13 #-----------------------------------
15 use lib '/usr/local/koha/intranet/modules/';
22 my $dbh = C4::Context->dbh;
23 my $message; # e-mail message
24 my $admin = "root@localhost"; #To
25 my @library = "root@localhost"; #From
26 # get biblionumbers of unfilled reserves
27 my $bibnos_sth=$dbh->prepare("SELECT DISTINCT biblionumber FROM reserves WHERE cancellationdate IS NULL AND found IS NULL AND priority>0");
28 my $get_sth=$dbh->prepare("SELECT * FROM reserves WHERE biblionumber=? AND cancellationdate IS NULL AND found IS NULL ORDER BY reservedate,priority");
29 # checking reservedate avoids overwriting legitimate duplicate reserves
30 my $put_sth=$dbh->prepare("UPDATE reserves SET priority=? WHERE biblionumber=? AND borrowernumber=? AND reservedate=?");
31 my $count_sth=$dbh->prepare("SELECT COUNT(itemnumber) FROM items WHERE biblionumber=?");
32 my $dvd_sth=$dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber=?");
34 $bibnos_sth->execute();
36 while (my $number=$bibnos_sth->fetchrow_arrayref) {
37 my $bibliono=$number->[0];
39 $get_sth->execute($bibliono);
42 while (my $data=$get_sth->fetchrow_hashref){
44 my $bibno = $data->{'biblionumber'};
45 my $borrno = $data->{'borrowernumber'};
46 my $resdate = $data->{'reservedate'};
48 my $date1 = DateCalc("today","- 60 days"); # calculate date 60 days ago
49 my $date2 = ParseDate($resdate);
50 my $flag = Date_Cmp($date2,$date1);
51 if ($flag<0) { # date1 is later
52 $dvd_sth->execute($bibno);
53 while (my $itemtype=$dvd_sth->fetchrow_arrayref) {
54 my $it = $itemtype->[0];
57 $message .= "Check $bibno\n";
58 # print "Check $bibno\n";
61 $message .= "$bibno has no itemtype\n";
62 # print "$bibno has no itemtype\n";
68 $put_sth->execute($priority,$bibno,$borrno,$resdate);
72 $count_sth->execute($bibliono); # get item count
73 my $itemcount=$count_sth->fetchrow;
74 if (($priority/4)>$itemcount) { # no more than 4 reserves per item
75 $dvd_sth->execute($bibliono);
76 while (my $itemtype=$dvd_sth->fetchrow_arrayref) {
77 my $it = $itemtype->[0];
80 $message .= "Check $bibliono\n";
81 # print "Check $bibliono\n";
84 $message .= "$bibliono has no itemtype\n"
85 # print "$bibliono has no itemtype\n";
96 my %mail = ( To => '$admin',
98 Subject => 'Reserve problems',