3 # Copyright 2007 Liblime Ltd
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use C4
::Reports
::Guided
;
32 $debug = $ENV{DEBUG} || 0;
38 if ( C4::Context->config('supportdir') ) {
39 $base = C4::Context->config('supportdir');
42 $base = "/usr/share/koha/bin";
45 my $CONFIG_NAME = $ENV{'KOHA_CONF'};
47 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
49 template_name => "tools/scheduler.tt",
52 flagsrequired => { tools => 'schedule_tasks' },
57 my $mode = $input->param('mode');
58 my $id = $input->param('id');
60 if ( $mode eq 'job_add' ) {
62 # Retrieving the date according to the dateformat syspref
63 my $c4date = output_pref({ dt => dt_from_string( scalar $input->param('startdate') ), dateformat => 'iso', dateonly => 1 });
65 # Formatting it for Schedule::At
66 my $startdate = join('', (split /-/, $c4date));
68 my $starttime = $input->param('starttime');
69 $starttime =~ s/\://g;
70 my $start = $startdate . $starttime;
71 my $report = $input->param('report');
72 my $format = $input->param('format');
73 my $email = $input->param('email');
75 "export KOHA_CONF=\"$CONFIG_NAME\"; " .
76 "$base/cronjobs/runreport.pl $report --format=$format --to=$email";
78 #FIXME commit ea899bc55933cd74e4665d70b1c48cab82cd1257 added recurring parameter (it is not in template) and call to add_cron_job (undefined)
79 # my $recurring = $input->param('recurring');
81 # my $frequency = $input->param('frequency');
82 # add_cron_job( $start, $command );
85 # #here was the the unless ( add_at_job
88 unless ( add_at_job( $start, $command ) ) {
89 $template->param( job_add_failed => 1 );
93 if ( $mode eq 'job_change' ) {
94 my $jobid = $input->param('jobid');
95 if ( $input->param('delete') ) {
96 remove_at_job($jobid);
100 my $jobs = get_jobs();
102 foreach my $job ( values %$jobs ) {
106 @jobloop = sort { $a->{TIME} cmp $b->{TIME} } @jobloop;
108 my $reports = get_saved_reports();
110 foreach my $report (@$reports) {
111 $report->{'selected'} = 1 if $report->{'id'} eq $id;
115 $template->param( 'savedreports' => $reports );
116 $template->param( JOBS => \@jobloop );
117 my $time = localtime(time);
118 $template->param( 'time' => $time );
122 output_html_with_http_headers $input, $cookie, $template->output;