oups... typo fix in z3950random field definition
[koha.git] / updatecharges.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 #script to update charges for overdue in database
6 #updates categoryitem
7 # is called by charges.pl
8 # written 1/1/2000 by chris@katipo.co.nz
9
10
11 # Copyright 2000-2002 Katipo Communications
12 #
13 # This file is part of Koha.
14 #
15 # Koha is free software; you can redistribute it and/or modify it under the
16 # terms of the GNU General Public License as published by the Free Software
17 # Foundation; either version 2 of the License, or (at your option) any later
18 # version.
19 #
20 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
21 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
22 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License along with
25 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
26 # Suite 330, Boston, MA  02111-1307 USA
27
28 use strict;
29 use CGI;
30 use C4::Context;
31 use C4::Output;
32
33 my $input = new CGI;
34 #print $input->header;
35 #print startpage();
36 #print startmenu('issue');
37
38
39 my $dbh = C4::Context->dbh;
40 #print $input->dump;
41 my @names=$input->param();
42
43 foreach my $key (@names){
44         $key =~ /(.*)\.(.*)/;
45   my $bor=$1;
46   my $cat=$2;
47   my $data=$input->param($key);
48   my @dat=split(',',$data);
49 #  print "$bor $cat $dat[0] $dat[1] $dat[2] <br> ";
50  my $sth_search = $dbh->prepare("select count(*) as total from categoryitem where categorycode=? and itemtype=?");
51  my $sth_insert = $dbh->prepare("insert into categoryitem (categorycode,itemtype,fine,firstremind,chargeperiod) values (?,?,?,?,?)");
52  my $sth_update=$dbh->prepare("Update categoryitem set fine=?,firstremind=?,chargeperiod=? where categorycode=? and itemtype=?");
53   $sth_search->execute($bor,$cat);
54   my $res = $sth_search->fetchrow_hashref();
55   if ($res->{total}) {
56         warn "UPDATE";
57         $sth_update->execute($dat[0],$dat[1],$dat[2],$bor,$cat);
58  } else {
59         warn "INSERT";
60         $sth_insert->execute($bor,$cat,$dat[0],$dat[1],$dat[2]);
61 }
62 }
63 print $input->redirect("/cgi-bin/koha/charges.pl");
64 #print endmenu('issue');
65 #print endpage();