3 # Copyright 2000-2002 Katipo Communications
4 # copyright 2010 BibLibre
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
30 use C4
::Circulation
qw{ IsBranchTransferAllowed DeleteBranchTransferLimits CreateBranchTransferLimit
};
34 my ($template, $loggedinuser, $cookie)
35 = get_template_and_user
({template_name
=> "admin/branch_transfer_limits.tt",
38 flagsrequired
=> {parameters
=> 'parameters_remaining_permissions'},
42 my $dbh = C4
::Context
->dbh;
44 if((!defined($input->param('branchcode'))) & mybranch
() ne '')
46 $branchcode = mybranch
();
50 $branchcode = $input->param('branchcode');
53 my $branchname = GetBranchName
($branchcode);
55 # Getting the branches for user selection
56 my $branches = GetBranches
();
58 for my $thisbranch (sort { $branches->{$a}->{branchname
} cmp $branches->{$b}->{branchname
} } keys %$branches) {
59 my %row =(value
=> $thisbranch,
60 branchname
=> $branches->{$thisbranch}->{'branchname'},
61 selected
=> $thisbranch eq $branchcode ?
1 : 0,
63 push @branch_loop, \
%row;
67 # Set the template language for the correct limit type using $limitType
68 my $limitType = C4
::Context
->preference("BranchTransferLimitsType") || "ccode";
74 if ( $limitType eq 'ccode' ) {
75 $sth = $dbh->prepare('SELECT authorised_value AS ccode FROM authorised_values WHERE category = "CCODE"');
76 } elsif ( $limitType eq 'itemtype' ) {
77 $sth = $dbh->prepare('SELECT itemtype FROM itemtypes');
80 while ( my $row = $sth->fetchrow_hashref ) {
81 push( @codes, $row->{ $limitType } );
84 $sth = $dbh->prepare("SELECT branchcode FROM branches");
86 while ( my $row = $sth->fetchrow_hashref ) {
87 push( @branchcodes, $row->{'branchcode'} );
90 ## If Form Data Passed, Update the Database
91 if ( $input->param('updateLimits') ) {
92 DeleteBranchTransferLimits
($branchcode);
95 foreach my $code ( @codes ) {
96 foreach my $toBranch ( @branchcodes ) {
97 my $isSet = not $input->param( $code . "_" . $toBranch);
99 CreateBranchTransferLimit
( $toBranch, $branchcode, $code );
105 ## Build branchcode loop
107 foreach my $branchcode ( @branchcodes ) {
109 $row_data{ branchcode
} = $branchcode;
110 push ( @branchcode_loop, \
%row_data );
112 my $branchcount = scalar(@branchcode_loop);
114 ## Build the default data
116 foreach my $code ( @codes ) {
119 $row_data{ code
} = $code;
120 $row_data{ to_branch_loop
} = \
@to_branch_loop;
121 foreach my $toBranch ( @branchcodes ) {
123 my $isChecked = IsBranchTransferAllowed
( $toBranch, $branchcode, $code );
124 $row_data{ code
} = $code;
125 $row_data{ toBranch
} = $toBranch;
126 $row_data{ isChecked
} = $isChecked;
127 $row_data{ toBranchname
} = GetBranchName
($toBranch);
128 push( @to_branch_loop, \
%row_data );
131 push( @codes_loop, \
%row_data );
136 branchcount
=> $branchcount,
137 codes_loop
=> \
@codes_loop,
138 branch_loop
=> \
@branch_loop,
139 branchcode_loop
=> \
@branchcode_loop,
140 branchcode
=> $branchcode,
141 branchname
=> $branchname,
142 limitType
=> $limitType,
145 output_html_with_http_headers
$input, $cookie, $template->output;