MT 1587 (Follow-up) : CSV export for cart and shelves (export_format table creation)
[koha.git] / admin / branch_transfer_limits.pl
blob344b70cdf01e7dd2598784adbd358544a9cc0c14
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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 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 # Set the template language for the correct limit type
44 my $limit_phrase = 'Collection Code';
45 my $limitType = C4::Context->preference("BranchTransferLimitsType");
46 if ( $limitType eq 'itemtype' ) {
47 $limit_phrase = 'Item Type';
50 my @codes;
51 my @branchcodes;
53 my $sth;
54 if ( $limitType eq 'ccode' ) {
55 $sth = $dbh->prepare('SELECT authorised_value AS ccode FROM authorised_values WHERE category = "CCODE"');
56 } elsif ( $limitType eq 'itemtype' ) {
57 $sth = $dbh->prepare('SELECT itemtype FROM itemtypes');
59 $sth->execute();
60 while ( my $row = $sth->fetchrow_hashref ) {
61 push( @codes, $row->{ $limitType } );
64 $sth = $dbh->prepare("SELECT branchcode FROM branches");
65 $sth->execute();
66 while ( my $row = $sth->fetchrow_hashref ) {
67 push( @branchcodes, $row->{'branchcode'} );
70 ## If Form Data Passed, Update the Database
71 if ( $input->param('updateLimits') ) {
72 DeleteBranchTransferLimits();
74 foreach my $code ( @codes ) {
75 foreach my $toBranch ( @branchcodes ) {
76 foreach my $fromBranch ( @branchcodes ) {
77 my $isSet = $input->param( $code . "_" . $toBranch . "_" . $fromBranch );
78 if ( $isSet ) {
79 CreateBranchTransferLimit( $toBranch, $fromBranch, $code );
86 ## Build branchcode loop
87 my @branchcode_loop;
88 foreach my $branchcode ( @branchcodes ) {
89 my %row_data;
90 $row_data{ branchcode } = $branchcode;
91 push ( @branchcode_loop, \%row_data );
93 my $branchcount = scalar(@branchcode_loop);
95 ## Build the default data
96 my @codes_loop;
97 foreach my $code ( @codes ) {
98 my @to_branch_loop;
99 my %row_data;
100 $row_data{ code } = $code;
101 $row_data{ to_branch_loop } = \@to_branch_loop;
102 foreach my $toBranch ( @branchcodes ) {
103 my @from_branch_loop;
104 my %row_data;
105 $row_data{ code } = $code;
106 $row_data{ toBranch } = $toBranch;
107 $row_data{ from_branch_loop } = \@from_branch_loop;
109 foreach my $fromBranch ( @branchcodes ) {
110 my %row_data;
111 my $isChecked = ! IsBranchTransferAllowed( $toBranch, $fromBranch, $code );
112 $row_data{ code } = $code;
113 $row_data{ toBranch } = $toBranch;
114 $row_data{ fromBranch } = $fromBranch;
115 $row_data{ isChecked } = $isChecked;
117 push( @from_branch_loop, \%row_data );
120 push( @to_branch_loop, \%row_data );
123 push( @codes_loop, \%row_data );
127 $template->param(
128 branchcount => $branchcount,
129 codes_loop => \@codes_loop,
130 branchcode_loop => \@branchcode_loop,
131 limit_phrase => $limit_phrase,
134 output_html_with_http_headers $input, $cookie, $template->output;