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
29 use C4
::Circulation
qw{ IsBranchTransferAllowed DeleteBranchTransferLimits CreateBranchTransferLimit
};
33 my ($template, $loggedinuser, $cookie)
34 = get_template_and_user
({template_name
=> "admin/branch_transfer_limits.tmpl",
37 flagsrequired
=> {borrowers
=> 1},
41 my $dbh = C4
::Context
->dbh;
43 # Set the template language for the correct limit type
44 my $limit_phrase = 'Collection Code';
45 my $limitType = C4
::Context
->preference("BranchTransferLimitsType");
46 if ( $limitType eq 'itemtype' ) {
47 $limit_phrase = 'Item Type';
54 if ( $limitType eq 'ccode' ) {
55 $sth = $dbh->prepare('SELECT authorised_value AS ccode FROM authorised_values WHERE category = "CCODE"');
56 } elsif ( $limitType eq 'itemtype' ) {
57 $sth = $dbh->prepare('SELECT itemtype FROM itemtypes');
60 while ( my $row = $sth->fetchrow_hashref ) {
61 push( @codes, $row->{ $limitType } );
64 $sth = $dbh->prepare("SELECT branchcode FROM branches");
66 while ( my $row = $sth->fetchrow_hashref ) {
67 push( @branchcodes, $row->{'branchcode'} );
70 ## If Form Data Passed, Update the Database
71 if ( $input->param('updateLimits') ) {
72 DeleteBranchTransferLimits
();
74 foreach my $code ( @codes ) {
75 foreach my $toBranch ( @branchcodes ) {
76 foreach my $fromBranch ( @branchcodes ) {
77 my $isSet = $input->param( $code . "_" . $toBranch . "_" . $fromBranch );
79 CreateBranchTransferLimit
( $toBranch, $fromBranch, $code );
86 ## Build branchcode loop
88 foreach my $branchcode ( @branchcodes ) {
90 $row_data{ branchcode
} = $branchcode;
91 push ( @branchcode_loop, \
%row_data );
93 my $branchcount = scalar(@branchcode_loop);
95 ## Build the default data
97 foreach my $code ( @codes ) {
100 $row_data{ code
} = $code;
101 $row_data{ to_branch_loop
} = \
@to_branch_loop;
102 foreach my $toBranch ( @branchcodes ) {
103 my @from_branch_loop;
105 $row_data{ code
} = $code;
106 $row_data{ toBranch
} = $toBranch;
107 $row_data{ from_branch_loop
} = \
@from_branch_loop;
109 foreach my $fromBranch ( @branchcodes ) {
111 my $isChecked = ! IsBranchTransferAllowed
( $toBranch, $fromBranch, $code );
112 $row_data{ code
} = $code;
113 $row_data{ toBranch
} = $toBranch;
114 $row_data{ fromBranch
} = $fromBranch;
115 $row_data{ isChecked
} = $isChecked;
117 push( @from_branch_loop, \
%row_data );
120 push( @to_branch_loop, \
%row_data );
123 push( @codes_loop, \
%row_data );
128 branchcount
=> $branchcount,
129 codes_loop
=> \
@codes_loop,
130 branchcode_loop
=> \
@branchcode_loop,
131 limit_phrase
=> $limit_phrase,
134 output_html_with_http_headers
$input, $cookie, $template->output;