X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=tools%2Foverduerules.pl;h=1e5d920a0762b0c9f4656e2a6c949a6947abe791;hb=e579f5019a7d4b171c3cdfa5a07441ff34072dd7;hp=178a569129f784cf105b5d94f2f9293169614591;hpb=e20270fec4f6d34f01050bea4c5765d5b3c4ed33;p=srvgit diff --git a/tools/overduerules.pl b/tools/overduerules.pl index 178a569129..1e5d920a07 100755 --- a/tools/overduerules.pl +++ b/tools/overduerules.pl @@ -4,39 +4,36 @@ # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . -use strict; -use warnings; +use Modern::Perl; use CGI qw ( -utf8 ); use C4::Context; -use C4::Output; -use C4::Auth; -use C4::Koha; -use C4::Branch; +use C4::Output qw( output_html_with_http_headers ); +use C4::Auth qw( get_template_and_user ); use C4::Letters; use C4::Members; -use C4::Overdues; +use C4::Overdues qw( GetOverdueMessageTransportTypes ); +use Koha::Libraries; -our $input = new CGI; +use Koha::Patron::Categories; + +our $input = CGI->new; my $dbh = C4::Context->dbh; -my @categories = @{$dbh->selectall_arrayref( - 'SELECT description, categorycode FROM categories WHERE overduenoticerequired > 0', - { Slice => {} } -)}; -my @category_codes = map { $_->{categorycode} } @categories; +my @patron_categories = Koha::Patron::Categories->search( { overduenoticerequired => { '>' => 0 } } )->as_list; +my @category_codes = map { $_->categorycode } @patron_categories; our @rule_params = qw(delay letter debarred); # blank_row($category_code) - return true if the entire row is blank. @@ -59,27 +56,35 @@ sub blank_row { return 1; } -my $type=$input->param('type'); +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "tools/overduerules.tt", + query => $input, + type => "intranet", + flagsrequired => { tools => 'edit_notice_status_triggers' }, + } +); + +my $type = $input->param('type'); + my $branch = $input->param('branch'); +$branch = + defined $branch ? $branch + : C4::Context->preference('DefaultToLoggedInLibraryOverdueTriggers') ? C4::Context::mybranch() + : Koha::Libraries->search->count() == 1 ? undef + : undef; $branch ||= q{}; + my $op = $input->param('op'); $op ||= q{}; -my ($template, $loggedinuser, $cookie) - = get_template_and_user({template_name => "tools/overduerules.tt", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { tools => 'edit_notice_status_triggers'}, - debug => 1, - }); my $err=0; # save the values entered into tables my %temphash; my $input_saved = 0; if ($op eq 'save') { - my @names=$input->param(); + my @names=$input->multi_param(); my $sth_search = $dbh->prepare("SELECT count(*) AS total FROM overduerules WHERE branchcode=? AND categorycode=?"); my $sth_insert = $dbh->prepare("INSERT INTO overduerules (branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3) VALUES (?,?,?,?,?,?,?,?,?,?,?)"); @@ -87,14 +92,14 @@ if ($op eq 'save') { my $sth_delete=$dbh->prepare("DELETE FROM overduerules WHERE branchcode=? AND categorycode=?"); my $sth_insert_mtt = $dbh->prepare(" INSERT INTO overduerules_transport_types( - branchcode, categorycode, letternumber, message_transport_type + overduerules_id, letternumber, message_transport_type ) VALUES ( - ?, ?, ?, ? + (SELECT overduerules_id FROM overduerules WHERE branchcode = ? AND categorycode = ?), ?, ? ) "); my $sth_delete_mtt = $dbh->prepare(" DELETE FROM overduerules_transport_types - WHERE branchcode = ? AND categorycode = ? + WHERE overduerules_id = (SELECT overduerules_id FROM overduerules WHERE branchcode = ? AND categorycode = ?) "); foreach my $key (@names){ @@ -118,8 +123,8 @@ if ($op eq 'save') { foreach my $bor (keys %temphash){ # get category name if we need it for an error message - my $bor_category = GetBorrowercategory($bor); - my $bor_category_name = defined($bor_category) ? $bor_category->{description} : $bor; + my $bor_category = Koha::Patron::Categories->find($bor); + my $bor_category_name = $bor_category ? $bor_category->description : $bor; # Do some Checking here : delay1 < delay2 execute( $branch, $bor ); for my $letternumber ( 1..3 ) { - my @mtt = $input->param( "mtt${letternumber}-$bor" ); + my @mtt = $input->multi_param( "mtt${letternumber}-$bor" ); next unless @mtt; for my $mtt ( @mtt ) { $sth_insert_mtt->execute( $branch, $bor, $letternumber, $mtt); @@ -199,7 +204,6 @@ if ($op eq 'save') { $input_saved = 1; } } -my $branchloop = GetBranchesLoop($branch); my $letters = C4::Letters::GetLettersAvailableForALibrary( { @@ -208,11 +212,9 @@ my $letters = C4::Letters::GetLettersAvailableForALibrary( } ); -my @line_loop; - my $message_transport_types = C4::Letters::GetMessageTransportTypes(); my ( @first, @second, @third ); -for my $data (@categories) { +for my $patron_category (@patron_categories) { if (%temphash and not $input_saved){ # if we managed to save the form submission, don't # reuse %temphash, but take the values from the @@ -220,13 +222,13 @@ for my $data (@categories) { # bugs where the form submission was not correctly saved for my $i ( 1..3 ){ my %row = ( - overduename => $data->{'categorycode'}, - line => $data->{'description'} + overduename => $patron_category->categorycode, + line => $patron_category->description, ); - $row{delay}=$temphash{$data->{'categorycode'}}->{"delay$i"}; - $row{debarred}=$temphash{$data->{'categorycode'}}->{"debarred$i"}; - $row{selected_lettercode} = $temphash{ $data->{categorycode} }->{"letter$i"}; - my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $data->{'categorycode'}, $i) }; + $row{delay}=$temphash{$patron_category->categorycode}->{"delay$i"}; + $row{debarred}=$temphash{$patron_category->categorycode}->{"debarred$i"}; + $row{selected_lettercode} = $temphash{ $patron_category->categorycode }->{"letter$i"}; + my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $patron_category->categorycode, $i) }; my @mtts; for my $mtt ( @$message_transport_types ) { push @mtts, { @@ -246,19 +248,19 @@ for my $data (@categories) { } else { #getting values from table my $sth2=$dbh->prepare("SELECT * from overduerules WHERE branchcode=? AND categorycode=?"); - $sth2->execute($branch,$data->{'categorycode'}); + $sth2->execute($branch,$patron_category->categorycode); my $dat=$sth2->fetchrow_hashref; for my $i ( 1..3 ){ my %row = ( - overduename => $data->{'categorycode'}, - line => $data->{'description'} + overduename => $patron_category->categorycode, + line => $patron_category->description, ); $row{selected_lettercode} = $dat->{"letter$i"}; if ($dat->{"delay$i"}){$row{delay}=$dat->{"delay$i"};} if ($dat->{"debarred$i"}){$row{debarred}=$dat->{"debarred$i"};} - my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $data->{'categorycode'}, $i) }; + my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $patron_category->categorycode, $i) }; my @mtts; for my $mtt ( @$message_transport_types ) { push @mtts, { @@ -299,7 +301,6 @@ my @tabs = ( $template->param( table => ( @first or @second or @third ? 1 : 0 ), - branchloop => $branchloop, branch => $branch, tabs => \@tabs, message_transport_types => $message_transport_types,