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 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
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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #use warnings; FIXME - Bug 2505
24 use C4::Reports::Guided;
33 $debug = $ENV{DEBUG} || 0;
39 if ( C4::Context->config('supportdir') ) {
40 $base = C4::Context->config('supportdir');
43 $base = "/usr/share/koha/bin";
46 my $CONFIG_NAME = $ENV{'KOHA_CONF'};
48 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
50 template_name => "tools/scheduler.tt",
54 flagsrequired => { tools => 'schedule_tasks' },
59 my $mode = $input->param('mode');
60 my $id = $input->param('id');
62 if ( $mode eq 'job_add' ) {
64 # Retrieving the date according to the dateformat syspref
65 my $c4date = C4::Dates->new($input->param('startdate'));
67 # Formatting it for Schedule::At
68 my $startdate = join('', (split /-/, $c4date->output("iso")));
70 my $starttime = $input->param('starttime');
71 my $recurring = $input->param('recurring');
72 $starttime =~ s/\://g;
73 my $start = $startdate . $starttime;
74 my $report = $input->param('report');
75 my $format = $input->param('format');
76 my $email = $input->param('email');
78 "export KOHA_CONF=\"$CONFIG_NAME\"; " . $base
79 . "/cronjobs/runreport.pl $report --format=$format --to=$email";
82 my $frequency = $input->param('frequency');
83 add_cron_job( $start, $command );
86 unless ( add_at_job( $start, $command ) ) {
87 $template->param( job_add_failed => 1 );
92 if ( $mode eq 'job_change' ) {
93 my $jobid = $input->param('jobid');
94 if ( $input->param('delete') ) {
95 remove_at_job($jobid);
99 my $jobs = get_jobs();
101 foreach my $job ( values %$jobs ) {
105 @jobloop = sort { $a->{TIME} cmp $b->{TIME} } @jobloop;
107 my $reports = get_saved_reports();
109 foreach my $report (@$reports) {
110 $report->{'selected'} = 1 if $report->{'id'} eq $id;
114 $template->param( 'savedreports' => $reports );
115 $template->param( JOBS => \@jobloop );
116 my $time = localtime(time);
117 $template->param( 'time' => $time );
121 output_html_with_http_headers $input, $cookie, $template->output;