ec5d207d8fd57c2eeafefe8f7745b9f72b3f0879
[koha.git] / misc / cronjobs / j2a.pl
1 #!/usr/bin/perl 
2 #run nightly -- changes J to A on someone's 18th birthday
3 use strict;
4 #use warnings; FIXME - Bug 2505
5 BEGIN {
6     # find Koha's Perl modules
7     # test carefully before changing this
8     use FindBin;
9     eval { require "$FindBin::Bin/../kohalib.pl" };
10 }
11
12 use C4::Context;
13 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
14                                             = localtime(time);
15 $year +=1900;
16 $mon +=1; if ($mon < 10) {$mon = "0".$mon;}
17 if ($mday < 10) {$mday = "0".$mday;}
18
19 $year -=18; #18 year olds here: if your J turns to A before this change here
20 my $dbh=C4::Context->dbh;
21
22 #get today's date, format it and subtract 18 yrs.
23 my $itsyourbirthday = "$year-$mon-$mday";
24
25 my $query=qq|UPDATE borrowers 
26            SET categorycode='A',
27             guarantorid ='0'     
28            WHERE dateofbirth<=? 
29            AND dateofbirth!='0000-00-00' 
30            AND categorycode IN (select categorycode from categories where category_type='C')|;
31 my $sth=$dbh->prepare($query);
32 my $res = $sth->execute($itsyourbirthday) or die "can't execute";
33 print "$res\n"; #did it work?
34 $dbh->disconnect();