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 if((!defined($input->param('branchcode'))) & mybranch
() ne '')
45 $branchcode = mybranch
();
49 $branchcode = $input->param('branchcode');
52 my $branchname = GetBranchName
($branchcode);
54 # Getting the branches for user selection
55 my $branches = GetBranches
();
57 for my $thisbranch (sort { $branches->{$a}->{branchname
} cmp $branches->{$b}->{branchname
} } keys %$branches) {
58 my %row =(value
=> $thisbranch,
59 branchname
=> $branches->{$thisbranch}->{'branchname'},
61 push @branch_loop, \
%row;
65 # Set the template language for the correct limit type
66 my $limit_phrase = 'Collection Code';
67 my $limitType = C4
::Context
->preference("BranchTransferLimitsType");
68 if ( $limitType eq 'itemtype' ) {
69 $limit_phrase = 'Item Type';
76 if ( $limitType eq 'ccode' ) {
77 $sth = $dbh->prepare('SELECT authorised_value AS ccode FROM authorised_values WHERE category = "CCODE"');
78 } elsif ( $limitType eq 'itemtype' ) {
79 $sth = $dbh->prepare('SELECT itemtype FROM itemtypes');
82 while ( my $row = $sth->fetchrow_hashref ) {
83 push( @codes, $row->{ $limitType } );
86 $sth = $dbh->prepare("SELECT branchcode FROM branches");
88 while ( my $row = $sth->fetchrow_hashref ) {
89 push( @branchcodes, $row->{'branchcode'} );
92 ## If Form Data Passed, Update the Database
93 if ( $input->param('updateLimits') ) {
94 DeleteBranchTransferLimits
();
96 foreach my $code ( @codes ) {
97 foreach my $toBranch ( @branchcodes ) {
98 my $isSet = not $input->param( $code . "_" . $toBranch);
100 CreateBranchTransferLimit
( $toBranch, $branchcode, $code );
106 ## Build branchcode loop
108 foreach my $branchcode ( @branchcodes ) {
110 $row_data{ branchcode
} = $branchcode;
111 push ( @branchcode_loop, \
%row_data );
113 my $branchcount = scalar(@branchcode_loop);
115 ## Build the default data
117 foreach my $code ( @codes ) {
120 $row_data{ code
} = $code;
121 $row_data{ to_branch_loop
} = \
@to_branch_loop;
122 foreach my $toBranch ( @branchcodes ) {
124 my $isChecked = IsBranchTransferAllowed
( $toBranch, $branchcode, $code );
125 $row_data{ code
} = $code;
126 $row_data{ toBranch
} = $toBranch;
127 $row_data{ isChecked
} = $isChecked;
128 $row_data{ toBranchname
} = GetBranchName
($toBranch);
129 push( @to_branch_loop, \
%row_data );
132 push( @codes_loop, \
%row_data );
137 branchcount
=> $branchcount,
138 codes_loop
=> \
@codes_loop,
139 branch_loop
=> \
@branch_loop,
140 branchcode_loop
=> \
@branchcode_loop,
141 branchcode
=> $branchcode,
142 branchname
=> $branchname,
143 limit_phrase
=> $limit_phrase,
146 output_html_with_http_headers
$input, $cookie, $template->output;