3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
25 use C4::Interface::CGI::Output;
29 my $dbh = C4::Context->dbh;
31 my $type=$input->param('type');
32 my $branch = $input->param('branch');
33 $branch="" unless $branch;
34 my $op = $input->param('op');
37 # $flagsrequired->{circulation}=1;
38 my ($template, $loggedinuser, $cookie)
39 = get_template_and_user({template_name => "tools/overduerules.tmpl",
43 flagsrequired => {parameters => 1, tools => 1},
48 # save the values entered into tables
51 my @names=$input->param();
52 my $sth_search = $dbh->prepare("select count(*) as total from overduerules where branchcode=? and categorycode=?");
54 my $sth_insert = $dbh->prepare("insert into overduerules (branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3) values (?,?,?,?,?,?,?,?,?,?,?)");
55 my $sth_update=$dbh->prepare("Update overduerules set delay1=?, letter1=?, debarred1=?, delay2=?, letter2=?, debarred2=?, delay3=?, letter3=?, debarred3=? where branchcode=? and categorycode=?");
56 my $sth_delete=$dbh->prepare("delete from overduerules where branchcode=? and categorycode=?");
57 foreach my $key (@names){
59 if ($key =~ /(.*)([1-3])-(.*)/) {
60 my $type = $1; # data type
61 my $num = $2; # From 1 to 3
62 my $bor = $3; # borrower category
63 $temphash{$bor}->{"$type$num"}=$input->param("$key") if (($input->param("$key") ne "") or ($input->param("$key")>0));
66 foreach my $bor (keys %temphash){
67 # Do some Checking here : delay1 < delay2 <delay3 all of them being numbers
68 # Raise error if not true
69 if ($temphash{$bor}->{delay1}=~/[^0-9]/ and $temphash{$bor}->{delay1} ne ""){
70 $template->param("ERROR"=>1,"ERRORDELAY"=>"delay1","BORERR"=>$bor);
72 } elsif ($temphash{$bor}->{delay2}=~/[^0-9]/ and $temphash{$bor}->{delay2} ne ""){
73 $template->param("ERROR"=>1,"ERRORDELAY"=>"delay2","BORERR"=>$bor);
75 } elsif ($temphash{$bor}->{delay3}=~/[^0-9]/ and $temphash{$bor}->{delay3} ne ""){
76 $template->param("ERROR"=>1,"ERRORDELAY"=>"delay3","BORERR"=>$bor);
78 }elsif ($temphash{$bor}->{delay3} and ($temphash{$bor}->{delay3}<=$temphash{$bor}->{delay2}
79 or $temphash{$bor}->{delay3}<=$temphash{$bor}->{delay1})
80 or $temphash{$bor}->{delay2} and ($temphash{$bor}->{delay2}<=$temphash{$bor}->{delay1})){
81 $template->param("ERROR"=>1,"ERRORORDER"=>1,"BORERR"=>$bor);
85 if (($temphash{$bor}->{delay1} and ($temphash{$bor}->{"letter1"} or $temphash{$bor}->{"debarred1"}))
86 or ($temphash{$bor}->{delay2} and ($temphash{$bor}->{"letter2"} or $temphash{$bor}->{"debarred2"}))
87 or ($temphash{$bor}->{delay3} and ($temphash{$bor}->{"letter3"} or $temphash{$bor}->{"debarred3"}))) {
88 $sth_search->execute($branch,$bor);
89 my $res = $sth_search->fetchrow_hashref();
90 if ($res->{'total'}>0) {
92 ($temphash{$bor}->{"delay1"}?$temphash{$bor}->{"delay1"}:0),
93 ($temphash{$bor}->{"letter1"}?$temphash{$bor}->{"letter1"}:""),
94 ($temphash{$bor}->{"debarred1"}?$temphash{$bor}->{"debarred1"}:0),
95 ($temphash{$bor}->{"delay2"}?$temphash{$bor}->{"delay2"}:0),
96 ($temphash{$bor}->{"letter2"}?$temphash{$bor}->{"letter2"}:""),
97 ($temphash{$bor}->{"debarred2"}?$temphash{$bor}->{"debarred2"}:0),
98 ($temphash{$bor}->{"delay3"}?$temphash{$bor}->{"delay3"}:0),
99 ($temphash{$bor}->{"letter3"}?$temphash{$bor}->{"letter3"}:""),
100 ($temphash{$bor}->{"debarred3"}?$temphash{$bor}->{"debarred3"}:0),
104 $sth_insert->execute($branch,$bor,
105 ($temphash{$bor}->{"delay1"}?$temphash{$bor}->{"delay1"}:0),
106 ($temphash{$bor}->{"letter1"}?$temphash{$bor}->{"letter1"}:""),
107 ($temphash{$bor}->{"debarred1"}?$temphash{$bor}->{"debarred1"}:0),
108 ($temphash{$bor}->{"delay2"}?$temphash{$bor}->{"delay2"}:0),
109 ($temphash{$bor}->{"letter2"}?$temphash{$bor}->{"letter2"}:""),
110 ($temphash{$bor}->{"debarred2"}?$temphash{$bor}->{"debarred2"}:0),
111 ($temphash{$bor}->{"delay3"}?$temphash{$bor}->{"delay3"}:0),
112 ($temphash{$bor}->{"letter3"}?$temphash{$bor}->{"letter3"}:""),
113 ($temphash{$bor}->{"debarred3"}?$temphash{$bor}->{"debarred3"}:0)
119 unless ($err) {$template->param(datasaved=>1);}
121 my $branches = getbranches;
123 foreach my $thisbranch (keys %$branches) {
124 my $selected = 1 if $thisbranch eq $branch;
125 my %row =(value => $thisbranch,
126 selected => $selected,
127 branchname => $branches->{$thisbranch}->{'branchname'},
129 push @branchloop, \%row;
132 my ($countletters,$letters) = getletters("circulation");
134 my $sth=$dbh->prepare("Select description,categorycode from categories where overduenoticerequired>0 order by description");
139 while (my $data=$sth->fetchrow_hashref){
140 if ( $toggle eq 1 ) {
145 my %row = ( overduename => $data->{'categorycode'},
147 line => $data->{'description'}
150 for (my $i=1;$i<=3;$i++){
151 $row{"delay$i"}=$temphash{$data->{'categorycode'}}->{"delay$i"};
152 $row{"debarred$i"}=$temphash{$data->{'categorycode'}}->{"debarred$i"};
155 foreach my $thisletter (keys %$letters) {
156 my $selected = 1 if $thisletter eq $temphash{$data->{'categorycode'}}->{"letter$i"};
157 my %letterrow =(value => $thisletter,
158 selected => $selected,
159 lettername => $letters->{$thisletter},
161 push @letterloop, \%letterrow;
163 $row{"letterloop$i"}=\@letterloop;
166 $row{"letter$i"}=$temphash{$data->{'categorycode'}}->{"letter$i"};
170 #getting values from table
171 my $sth2=$dbh->prepare("SELECT * from overduerules WHERE branchcode=? and categorycode=?");
172 $sth2->execute($branch,$data->{'categorycode'});
173 my $dat=$sth2->fetchrow_hashref;
174 for (my $i=1;$i<=3;$i++){
177 foreach my $thisletter (keys %$letters) {
178 my $selected = 1 if $thisletter eq $dat->{"letter$i"};
179 my %letterrow =(value => $thisletter,
180 selected => $selected,
181 lettername => $letters->{$thisletter},
183 push @letterloop, \%letterrow;
185 $row{"letterloop$i"}=\@letterloop;
188 if ($dat->{"letter$i"}){$row{"letter$i"}=$dat->{"letter$i"};}
190 if ($dat->{"delay$i"}){$row{"delay$i"}=$dat->{"delay$i"};}
191 if ($dat->{"debarred$i"}){$row{"debarred$i"}=$dat->{"debarred$i"};}
195 push @line_loop,\%row;
199 $template->param(table=> \@line_loop,
200 branchloop => \@branchloop,
202 output_html_with_http_headers $input, $cookie, $template->output;