Bug 15172: Serial enumchron/sequence not visible when returning/checking in Items
[koha.git] / admin / branch_transfer_limits.pl
blob0adc9583c13852e8bf132ed0a1d729f3fb27ca70
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 strict;
22 use warnings;
24 use CGI qw ( -utf8 );
25 use C4::Auth;
26 use C4::Context;
27 use C4::Output;
28 use C4::Koha;
29 use C4::Branch;
30 use C4::Circulation qw{ IsBranchTransferAllowed DeleteBranchTransferLimits CreateBranchTransferLimit };
32 my $input = new CGI;
34 my ($template, $loggedinuser, $cookie)
35 = get_template_and_user({template_name => "admin/branch_transfer_limits.tt",
36 query => $input,
37 type => "intranet",
38 flagsrequired => {parameters => 'parameters_remaining_permissions'},
39 debug => 1,
40 });
42 my $dbh = C4::Context->dbh;
43 my $branchcode;
44 if((!defined($input->param('branchcode'))) & mybranch() ne '')
46 $branchcode = mybranch();
48 else
50 $branchcode = $input->param('branchcode');
53 my $branchname = GetBranchName($branchcode);
55 # Getting the branches for user selection
56 my $branches = GetBranches();
57 my @branch_loop;
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";
70 my @codes;
71 my @branchcodes;
73 my $sth;
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');
79 $sth->execute();
80 while ( my $row = $sth->fetchrow_hashref ) {
81 push( @codes, $row->{ $limitType } );
84 $sth = $dbh->prepare("SELECT branchcode FROM branches");
85 $sth->execute();
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);
98 if ( $isSet ) {
99 CreateBranchTransferLimit( $toBranch, $branchcode, $code );
105 ## Build branchcode loop
106 my @branchcode_loop;
107 foreach my $branchcode ( @branchcodes ) {
108 my %row_data;
109 $row_data{ branchcode } = $branchcode;
110 push ( @branchcode_loop, \%row_data );
112 my $branchcount = scalar(@branchcode_loop);
114 ## Build the default data
115 my @codes_loop;
116 foreach my $code ( @codes ) {
117 my @to_branch_loop;
118 my %row_data;
119 $row_data{ code } = $code;
120 $row_data{ to_branch_loop } = \@to_branch_loop;
121 foreach my $toBranch ( @branchcodes ) {
122 my %row_data;
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 );
135 $template->param(
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;