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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 my $branchcode = $input->param('branchcode');
44 my $branchname = GetBranchName
($branchcode);
46 # Getting the branches for user selection
47 my $branches = GetBranches
();
49 for my $thisbranch (sort { $branches->{$a}->{branchname
} cmp $branches->{$b}->{branchname
} } keys %$branches) {
50 my %row =(value
=> $thisbranch,
51 branchname
=> $branches->{$thisbranch}->{'branchname'},
53 push @branch_loop, \
%row;
57 # Set the template language for the correct limit type
58 my $limit_phrase = 'Collection Code';
59 my $limitType = C4
::Context
->preference("BranchTransferLimitsType");
60 if ( $limitType eq 'itemtype' ) {
61 $limit_phrase = 'Item Type';
68 if ( $limitType eq 'ccode' ) {
69 $sth = $dbh->prepare('SELECT authorised_value AS ccode FROM authorised_values WHERE category = "CCODE"');
70 } elsif ( $limitType eq 'itemtype' ) {
71 $sth = $dbh->prepare('SELECT itemtype FROM itemtypes');
74 while ( my $row = $sth->fetchrow_hashref ) {
75 push( @codes, $row->{ $limitType } );
78 $sth = $dbh->prepare("SELECT branchcode FROM branches");
80 while ( my $row = $sth->fetchrow_hashref ) {
81 push( @branchcodes, $row->{'branchcode'} );
84 ## If Form Data Passed, Update the Database
85 if ( $input->param('updateLimits') ) {
86 DeleteBranchTransferLimits
();
88 foreach my $code ( @codes ) {
89 foreach my $toBranch ( @branchcodes ) {
90 my $isSet = not $input->param( $code . "_" . $toBranch);
92 CreateBranchTransferLimit
( $toBranch, $branchcode, $code );
98 ## Build branchcode loop
100 foreach my $branchcode ( @branchcodes ) {
102 $row_data{ branchcode
} = $branchcode;
103 push ( @branchcode_loop, \
%row_data );
105 my $branchcount = scalar(@branchcode_loop);
107 ## Build the default data
109 foreach my $code ( @codes ) {
112 $row_data{ code
} = $code;
113 $row_data{ to_branch_loop
} = \
@to_branch_loop;
114 foreach my $toBranch ( @branchcodes ) {
116 my $isChecked = IsBranchTransferAllowed
( $toBranch, $branchcode, $code );
117 $row_data{ code
} = $code;
118 $row_data{ toBranch
} = $toBranch;
119 $row_data{ isChecked
} = $isChecked;
120 $row_data{ toBranchname
} = GetBranchName
($toBranch);
121 push( @to_branch_loop, \
%row_data );
124 push( @codes_loop, \
%row_data );
129 branchcount
=> $branchcount,
130 codes_loop
=> \
@codes_loop,
131 branch_loop
=> \
@branch_loop,
132 branchcode_loop
=> \
@branchcode_loop,
133 branchcode
=> $branchcode,
134 branchname
=> $branchname,
135 limit_phrase
=> $limit_phrase,
138 output_html_with_http_headers
$input, $cookie, $template->output;