Bug 4920 - neworderempty.tmpl shouldn't call calcNeworderTotal() onload
[koha.git] / admin / branch_transfer_limits.pl
blob64d2a70ff553fc293071297c53ff8b8e6f737ca7
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;
42 my $branchcode;
43 if((!defined($input->param('branchcode'))) & mybranch() ne '')
45 $branchcode = mybranch();
47 else
49 $branchcode = $input->param('branchcode');
52 my $branchname = GetBranchName($branchcode);
54 # Getting the branches for user selection
55 my $branches = GetBranches();
56 my @branch_loop;
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';
72 my @codes;
73 my @branchcodes;
75 my $sth;
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');
81 $sth->execute();
82 while ( my $row = $sth->fetchrow_hashref ) {
83 push( @codes, $row->{ $limitType } );
86 $sth = $dbh->prepare("SELECT branchcode FROM branches");
87 $sth->execute();
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);
99 if ( $isSet ) {
100 CreateBranchTransferLimit( $toBranch, $branchcode, $code );
106 ## Build branchcode loop
107 my @branchcode_loop;
108 foreach my $branchcode ( @branchcodes ) {
109 my %row_data;
110 $row_data{ branchcode } = $branchcode;
111 push ( @branchcode_loop, \%row_data );
113 my $branchcount = scalar(@branchcode_loop);
115 ## Build the default data
116 my @codes_loop;
117 foreach my $code ( @codes ) {
118 my @to_branch_loop;
119 my %row_data;
120 $row_data{ code } = $code;
121 $row_data{ to_branch_loop } = \@to_branch_loop;
122 foreach my $toBranch ( @branchcodes ) {
123 my %row_data;
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 );
136 $template->param(
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;