Context.pm - BEGIN block VERSION and vars related to export.
[koha.git] / admin / issuingrules.pl
blob477637b478c4c4a85c6cdeaaceeaf11ecd30adaa
1 #!/usr/bin/perl
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
10 # version.
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
20 use strict;
21 use CGI;
22 use C4::Context;
23 use C4::Output;
24 use C4::Auth;
25 use C4::Koha;
26 use C4::Branch; # GetBranches
28 my $input = new CGI;
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');
36 # my $flagsrequired;
37 # $flagsrequired->{circulation}=1;
38 my ($template, $loggedinuser, $cookie)
39 = get_template_and_user({template_name => "admin/issuingrules.tmpl",
40 query => $input,
41 type => "intranet",
42 authnotrequired => 0,
43 flagsrequired => {parameters => 1},
44 debug => 1,
45 });
46 # save the values entered
47 if ($op eq 'save') {
48 my @names=$input->param();
49 my $sth_search = $dbh->prepare("SELECT count(*) AS total FROM issuingrules WHERE branchcode=? and categorycode=? and itemtype=?");
51 my $sth_Iinsert = $dbh->prepare("INSERT INTO issuingrules (branchcode,categorycode,itemtype,maxissueqty,issuelength,rentaldiscount) VALUES (?,?,?,?,?,?)");
52 my $sth_Iupdate=$dbh->prepare("UPDATE issuingrules SET maxissueqty=?, issuelength=?, rentaldiscount=? WHERE branchcode=? AND categorycode=? AND itemtype=?");
53 my $sth_Idelete=$dbh->prepare("DELETE FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=? AND fine=0");
54 foreach my $key (@names){
55 # ISSUES
56 if ($key =~ /I-(.*)-(.*)\.(.*)/) {
57 my $br = $1; # branch
58 my $bor = $2; # borrower category
59 my $cat = $3; # item type
60 my $data=$input->param($key);
61 my ($issuelength,$maxissueqty,$rentaldiscount)=split(',',$data);
62 $sth_search->execute($br,$bor,$cat);
63 my $res = $sth_search->fetchrow_hashref();
64 if ($res->{'total'} >0) {
65 $sth_Iupdate->execute($maxissueqty,$issuelength,$rentaldiscount,$br,$bor,$cat);
66 } else {
67 $sth_Iinsert->execute($br,$bor,$cat,$maxissueqty,$issuelength,$rentaldiscount);
72 my $branches = GetBranches;
73 my @branchloop;
74 foreach my $thisbranch (keys %$branches) {
75 my $selected = 1 if $thisbranch eq $branch;
76 my %row =(value => $thisbranch,
77 selected => $selected,
78 branchname => $branches->{$thisbranch}->{'branchname'},
80 push @branchloop, \%row;
83 my $sth=$dbh->prepare("SELECT description,categorycode FROM categories ORDER BY description");
84 $sth->execute;
85 my @trow3;
86 my @title_loop;
87 while (my $data=$sth->fetchrow_hashref){
88 my %row = (in_title => $data->{'description'});
89 push @title_loop,\%row;
90 push @trow3,$data->{'categorycode'};
93 my %row = (in_title => "*");
94 push @title_loop, \%row;
95 push @trow3,'*';
97 $sth->finish;
98 $sth=$dbh->prepare("Select description,itemtype from itemtypes order by description");
99 $sth->execute;
100 my $toggle= 1;
101 my @row_loop;
102 my @itemtypes;
103 while (my $row=$sth->fetchrow_hashref){
104 push @itemtypes,\$row;
106 my $line;
107 $line->{itemtype} = "*";
108 $line->{description} = "*";
109 push @itemtypes,\$line;
111 foreach my $data (@itemtypes) {
112 my @trow2;
113 my @cell_loop;
114 if ( $toggle eq 1 ) {
115 $toggle = 0;
116 } else {
117 $toggle = 1;
119 for (my $i=0;$i<=$#trow3;$i++){
120 my $sth2=$dbh->prepare("SELECT * FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?");
121 $sth2->execute($branch,$trow3[$i],$$data->{'itemtype'});
122 my $dat=$sth2->fetchrow_hashref;
123 $sth2->finish;
124 my $fine=$dat->{'fine'};
125 my $maxissueqty = $dat->{'maxissueqty'};
126 my $issuelength = $dat->{'issuelength'};
127 my $issuingvalue;
128 $issuingvalue = "$issuelength,$maxissueqty" if $maxissueqty ne '';
129 my %row = (issuingname => "I-$branch-$trow3[$i].$$data->{itemtype}",
130 issuingvalue => $issuingvalue,
131 toggle => $toggle,
133 push @cell_loop,\%row;
135 my %row = (categorycode => $$data->{description},
136 total => ($$data->{itemtype} eq '*'?1:0),
137 cell =>\@cell_loop
139 push @row_loop, \%row;
142 $sth->finish;
143 $template->param(title => \@title_loop,
144 row => \@row_loop,
145 branchloop => \@branchloop,
146 branch => $branch,
148 output_html_with_http_headers $input, $cookie, $template->output;