|
Lines 18-33
Link Here
|
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
|
|
21 |
use CGI qw ( -utf8 ); |
| 22 |
use Try::Tiny qw(try catch); |
| 23 |
|
| 21 |
use C4::Context; |
24 |
use C4::Context; |
| 22 |
use C4::Scheduler qw( add_at_job get_jobs remove_at_job ); |
25 |
use C4::Scheduler qw( add_at_job get_jobs remove_at_job ); |
| 23 |
use C4::Reports::Guided qw( get_saved_reports ); |
26 |
use C4::Reports::Guided qw( get_saved_reports ); |
| 24 |
use C4::Auth qw( get_template_and_user ); |
27 |
use C4::Auth qw( get_template_and_user ); |
| 25 |
use CGI qw ( -utf8 ); |
|
|
| 26 |
use C4::Output qw( output_html_with_http_headers ); |
28 |
use C4::Output qw( output_html_with_http_headers ); |
| 27 |
use Koha::DateUtils qw( dt_from_string );; |
29 |
|
|
|
30 |
use Koha::DateUtils qw( dt_from_string ); |
| 31 |
use Koha::Validator; |
| 28 |
|
32 |
|
| 29 |
my $input = CGI->new; |
33 |
my $input = CGI->new; |
| 30 |
my $base; |
34 |
my $base; |
|
|
35 |
my $rules = { |
| 36 |
id => 'digits_only', |
| 37 |
mode => [ q(), qw(job_add job_change) ], |
| 38 |
delete => [qw(Delete)], |
| 39 |
job_id => 'digits_only', |
| 40 |
starttime => qr/^\d{2}:?\d{2}$/, |
| 41 |
startdate => qr/^\d{4}-?\d{2}-?\d{2}$/, |
| 42 |
report => 'digits_only', |
| 43 |
format => [ q{}, qw( text html csv tsv ) ], |
| 44 |
email => 'email' |
| 45 |
}; |
| 31 |
|
46 |
|
| 32 |
if ( C4::Context->config('supportdir') ) { |
47 |
if ( C4::Context->config('supportdir') ) { |
| 33 |
$base = C4::Context->config('supportdir'); |
48 |
$base = C4::Context->config('supportdir'); |
|
Lines 47-55
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
Link Here
|
| 47 |
} |
62 |
} |
| 48 |
); |
63 |
); |
| 49 |
|
64 |
|
| 50 |
my $mode = $input->param('mode'); |
65 |
my $mode = $input->param('mode') // q{}; |
| 51 |
my $id = $input->param('id'); |
66 |
my $id = $input->param('id'); |
| 52 |
|
67 |
|
|
|
68 |
try { |
| 69 |
Koha::Validator->new({ rules => $rules })->check_hash(scalar $input->Vars); |
| 70 |
} catch { |
| 71 |
my $field = 'some field'; |
| 72 |
if ( ref($_) =~ /Koha::Exception/ ) { |
| 73 |
warn $_->full_message; |
| 74 |
$field = $_->parameter if $_->parameter; |
| 75 |
} |
| 76 |
$template->param( validation_failed => 1, invalid_field => $field ); |
| 77 |
output_html_with_http_headers $input, $cookie, $template->output; |
| 78 |
exit; |
| 79 |
}; |
| 80 |
|
| 53 |
if ( $mode eq 'job_add' ) { |
81 |
if ( $mode eq 'job_add' ) { |
| 54 |
|
82 |
|
| 55 |
my $startdate = dt_from_string( scalar $input->param('startdate'), 'iso' )->ymd; |
83 |
my $startdate = dt_from_string( scalar $input->param('startdate'), 'iso' )->ymd; |
|
Lines 59-81
if ( $mode eq 'job_add' ) {
Link Here
|
| 59 |
my $starttime = $input->param('starttime'); |
87 |
my $starttime = $input->param('starttime'); |
| 60 |
$starttime =~ s/\://g; |
88 |
$starttime =~ s/\://g; |
| 61 |
my $start = $startdate . $starttime; |
89 |
my $start = $startdate . $starttime; |
| 62 |
my $report = $input->param('report'); |
90 |
my $report = $input->param('report') // 0; |
| 63 |
my $format = $input->param('format'); |
91 |
my $format = $input->param('format') // q{}; |
| 64 |
my $email = $input->param('email'); |
92 |
my $email = $input->param('email') // q{}; |
| 65 |
my $command = |
93 |
my $command = |
| 66 |
"export KOHA_CONF=\"$CONFIG_NAME\"; " . |
94 |
"export KOHA_CONF=\"$CONFIG_NAME\"; " . |
| 67 |
"$base/cronjobs/runreport.pl $report --format=$format --to=$email"; |
95 |
"$base/cronjobs/runreport.pl $report --format=$format --to=$email"; |
| 68 |
|
96 |
|
| 69 |
#FIXME commit ea899bc55933cd74e4665d70b1c48cab82cd1257 added recurring parameter (it is not in template) and call to add_cron_job (undefined) |
|
|
| 70 |
# my $recurring = $input->param('recurring'); |
| 71 |
# if ($recurring) { |
| 72 |
# my $frequency = $input->param('frequency'); |
| 73 |
# add_cron_job( $start, $command ); |
| 74 |
# } |
| 75 |
# else { |
| 76 |
# #here was the the unless ( add_at_job |
| 77 |
# } |
| 78 |
|
| 79 |
unless ( add_at_job( $start, $command ) ) { |
97 |
unless ( add_at_job( $start, $command ) ) { |
| 80 |
$template->param( job_add_failed => 1 ); |
98 |
$template->param( job_add_failed => 1 ); |
| 81 |
} |
99 |
} |
| 82 |
- |
|
|