Add support for a remote mysql server.
[koha.git] / admin / branch_transfer_limits.pl
blob1b89efb8ce91b3ac21c6b48d9d006da63fed50ee
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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use strict;
21 use warnings;
23 use CGI;
24 use C4::Auth;
25 use C4::Context;
26 use C4::Output;
27 use C4::Koha;
28 use C4::Branch;
29 use C4::Circulation qw{ IsBranchTransferAllowed DeleteBranchTransferLimits CreateBranchTransferLimit };
31 my $input = new CGI;
33 my ($template, $loggedinuser, $cookie)
34 = get_template_and_user({template_name => "admin/branch_transfer_limits.tmpl",
35 query => $input,
36 type => "intranet",
37 flagsrequired => {borrowers => 1},
38 debug => 1,
39 });
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();
48 my @branch_loop;
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';
64 my @codes;
65 my @branchcodes;
67 my $sth;
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');
73 $sth->execute();
74 while ( my $row = $sth->fetchrow_hashref ) {
75 push( @codes, $row->{ $limitType } );
78 $sth = $dbh->prepare("SELECT branchcode FROM branches");
79 $sth->execute();
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);
91 if ( $isSet ) {
92 CreateBranchTransferLimit( $toBranch, $branchcode, $code );
98 ## Build branchcode loop
99 my @branchcode_loop;
100 foreach my $branchcode ( @branchcodes ) {
101 my %row_data;
102 $row_data{ branchcode } = $branchcode;
103 push ( @branchcode_loop, \%row_data );
105 my $branchcount = scalar(@branchcode_loop);
107 ## Build the default data
108 my @codes_loop;
109 foreach my $code ( @codes ) {
110 my @to_branch_loop;
111 my %row_data;
112 $row_data{ code } = $code;
113 $row_data{ to_branch_loop } = \@to_branch_loop;
114 foreach my $toBranch ( @branchcodes ) {
115 my %row_data;
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 );
128 $template->param(
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;