Bug 18247: Remove SQL queries from branch_transfer_limit.pl
[koha-ffzg.git] / admin / branch_transfer_limits.pl
index 455c04a..35b1386 100755 (executable)
 use Modern::Perl;
 
 use CGI qw ( -utf8 );
-use C4::Auth;
+use C4::Auth qw( get_template_and_user );
 use C4::Context;
-use C4::Output;
-use C4::Koha;
-use C4::Circulation qw{ IsBranchTransferAllowed DeleteBranchTransferLimits CreateBranchTransferLimit };
+use C4::Output qw( output_html_with_http_headers );
+use C4::Circulation qw( DeleteBranchTransferLimits CreateBranchTransferLimit IsBranchTransferAllowed );
 
 my $input = CGI->new;
 
@@ -53,23 +52,13 @@ my $limitType = C4::Context->preference("BranchTransferLimitsType") || "ccode";
 my @codes;
 my @branchcodes;
 
-my $sth;
 if ( $limitType eq 'ccode' ) {
-       $sth = $dbh->prepare('SELECT authorised_value AS ccode FROM authorised_values WHERE category = "CCODE"');
+    @codes = Koha::AuthorisedValues->search({ category => 'CCODE' })->get_column('authorised_value');
 } elsif ( $limitType eq 'itemtype' ) {
-       $sth = $dbh->prepare('SELECT itemtype FROM itemtypes');
-}
-$sth->execute();
-while ( my $row = $sth->fetchrow_hashref ) {
-       push( @codes, $row->{ $limitType } );
-}
-
-$sth = $dbh->prepare("SELECT branchcode FROM branches");
-$sth->execute();
-while ( my $row = $sth->fetchrow_hashref ) {
-       push( @branchcodes, $row->{'branchcode'} );
+    @codes = Koha::ItemTypes->search->get_column('itemtype');
 }
 
+@branchcodes = Koha::Libraries->search->get_column('branchcode');
 ## If Form Data Passed, Update the Database
 if ( $input->param('updateLimits') ) {
     DeleteBranchTransferLimits($branchcode);