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 #-----------------------------------
17 # find Koha's Perl modules
18 # test carefully before changing this
20 eval { require "$FindBin::Bin/../kohalib.pl" };
26 my $dbh = C4::Context->dbh;
27 my $message; # e-mail message
28 my $admin = "root@localhost"; #To
29 my @library = "root@localhost"; #From
30 # get biblionumbers of unfilled reserves
31 my $bibnos_sth=$dbh->prepare("SELECT DISTINCT biblionumber FROM reserves WHERE cancellationdate IS NULL AND found IS NULL AND priority>0");
32 my $get_sth=$dbh->prepare("SELECT * FROM reserves WHERE biblionumber=? AND cancellationdate IS NULL AND found IS NULL ORDER BY reservedate,priority");
33 # checking reservedate avoids overwriting legitimate duplicate reserves
34 my $put_sth=$dbh->prepare("UPDATE reserves SET priority=? WHERE biblionumber=? AND borrowernumber=? AND reservedate=?");
35 my $count_sth=$dbh->prepare("SELECT COUNT(itemnumber) FROM items WHERE biblionumber=?");
36 my $dvd_sth=$dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber=?");
38 $bibnos_sth->execute();
40 while (my $number=$bibnos_sth->fetchrow_arrayref) {
41 my $bibliono=$number->[0];
43 $get_sth->execute($bibliono);
46 while (my $data=$get_sth->fetchrow_hashref){
48 my $bibno = $data->{'biblionumber'};
49 my $borrno = $data->{'borrowernumber'};
50 my $resdate = $data->{'reservedate'};
52 my $date1 = DateCalc("today","- 60 days"); # calculate date 60 days ago
53 my $date2 = ParseDate($resdate);
54 my $flag = Date_Cmp($date2,$date1);
55 if ($flag<0) { # date1 is later
56 $dvd_sth->execute($bibno);
57 while (my $itemtype=$dvd_sth->fetchrow_arrayref) {
58 my $it = $itemtype->[0];
61 $message .= "Check $bibno\n";
62 # print "Check $bibno\n";
65 $message .= "$bibno has no itemtype\n";
66 # print "$bibno has no itemtype\n";
72 $put_sth->execute($priority,$bibno,$borrno,$resdate);
76 $count_sth->execute($bibliono); # get item count
77 my $itemcount=$count_sth->fetchrow;
78 if (($priority/4)>$itemcount) { # no more than 4 reserves per item
79 $dvd_sth->execute($bibliono);
80 while (my $itemtype=$dvd_sth->fetchrow_arrayref) {
81 my $it = $itemtype->[0];
84 $message .= "Check $bibliono\n";
85 # print "Check $bibliono\n";
88 $message .= "$bibliono has no itemtype\n"
89 # print "$bibliono has no itemtype\n";
100 my %mail = ( To => '$admin',
102 Subject => 'Reserve problems',