Bug 25898: Prohibit indirect object notation
[koha.git] / admin / branch_transfer_limits.pl
blob94a348e1206b63d48f81e7a3af874c0410c488f9
1 #!/usr/bin/perl
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>.
21 use Modern::Perl;
23 use CGI qw ( -utf8 );
24 use C4::Auth;
25 use C4::Context;
26 use C4::Output;
27 use C4::Koha;
28 use C4::Circulation qw{ IsBranchTransferAllowed DeleteBranchTransferLimits CreateBranchTransferLimit };
30 my $input = CGI->new;
32 my ($template, $loggedinuser, $cookie)
33 = get_template_and_user({template_name => "admin/branch_transfer_limits.tt",
34 query => $input,
35 type => "intranet",
36 flagsrequired => {parameters => 'manage_transfers'},
37 debug => 1,
38 });
40 my $dbh = C4::Context->dbh;
41 my $branchcode;
42 if((!defined($input->param('branchcode'))) & C4::Context::mybranch() ne '')
44 $branchcode = C4::Context::mybranch();
46 else
48 $branchcode = $input->param('branchcode');
51 # Set the template language for the correct limit type using $limitType
52 my $limitType = C4::Context->preference("BranchTransferLimitsType") || "ccode";
54 my @codes;
55 my @branchcodes;
57 my $sth;
58 if ( $limitType eq 'ccode' ) {
59 $sth = $dbh->prepare('SELECT authorised_value AS ccode FROM authorised_values WHERE category = "CCODE"');
60 } elsif ( $limitType eq 'itemtype' ) {
61 $sth = $dbh->prepare('SELECT itemtype FROM itemtypes');
63 $sth->execute();
64 while ( my $row = $sth->fetchrow_hashref ) {
65 push( @codes, $row->{ $limitType } );
68 $sth = $dbh->prepare("SELECT branchcode FROM branches");
69 $sth->execute();
70 while ( my $row = $sth->fetchrow_hashref ) {
71 push( @branchcodes, $row->{'branchcode'} );
74 ## If Form Data Passed, Update the Database
75 if ( $input->param('updateLimits') ) {
76 DeleteBranchTransferLimits($branchcode);
79 foreach my $code ( @codes ) {
80 foreach my $toBranch ( @branchcodes ) {
81 my $isSet = not $input->param( $code . "_" . $toBranch);
82 if ( $isSet ) {
83 CreateBranchTransferLimit( $toBranch, $branchcode, $code );
89 ## Build branchcode loop
90 my @branchcode_loop;
91 foreach my $branchcode ( @branchcodes ) {
92 my %row_data;
93 $row_data{ branchcode } = $branchcode;
94 push ( @branchcode_loop, \%row_data );
96 my $branchcount = scalar(@branchcode_loop);
98 ## Build the default data
99 my @codes_loop;
100 foreach my $code ( @codes ) {
101 my @to_branch_loop;
102 my %row_data;
103 $row_data{ code } = $code;
104 $row_data{ to_branch_loop } = \@to_branch_loop;
105 foreach my $toBranch ( @branchcodes ) {
106 my %row_data;
107 my $isChecked = IsBranchTransferAllowed( $toBranch, $branchcode, $code );
108 $row_data{ code } = $code;
109 $row_data{ toBranch } = $toBranch;
110 $row_data{ isChecked } = $isChecked;
111 push( @to_branch_loop, \%row_data );
114 push( @codes_loop, \%row_data );
118 $template->param(
119 branchcount => $branchcount,
120 codes_loop => \@codes_loop,
121 branchcode_loop => \@branchcode_loop,
122 branchcode => $branchcode,
123 limitType => $limitType,
126 output_html_with_http_headers $input, $cookie, $template->output;