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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
23 use C4::Reports::Guided;
32 $debug = $ENV{DEBUG} || 0;
37 my $base = C4::Context->config('intranetdir');
38 my $CONFIG_NAME = $ENV{'KOHA_CONF'};
40 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
42 template_name => "tools/scheduler.tmpl",
46 flagsrequired => { tools => 'schedule_tasks' },
51 my $mode = $input->param('mode');
52 my $id = $input->param('id');
54 if ( $mode eq 'job_add' ) {
56 join( '', ( split m|/|, $input->param('startdate') )[ 2, 0, 1 ] );
57 my $starttime = $input->param('starttime');
58 my $recurring = $input->param('recurring');
59 $starttime =~ s/\://g;
60 my $start = $startdate . $starttime;
61 my $report = $input->param('report');
62 my $format = $input->param('format');
63 my $email = $input->param('email');
65 "EXPORT KOHA_CONF=\"$CONFIG_NAME\"; " . $base
66 . "/tools/runreport.pl $report $format $email";
69 my $frequency = $input->param('frequency');
70 add_cron_job( $start, $command );
73 unless ( add_at_job( $start, $command ) ) {
74 $template->param( job_add_failed => 1 );
79 if ( $mode eq 'job_change' ) {
80 my $jobid = $input->param('jobid');
81 if ( $input->param('delete') ) {
82 remove_at_job($jobid);
86 my $jobs = get_jobs();
88 foreach my $job ( values %$jobs ) {
92 @jobloop = sort { $a->{TIME} cmp $b->{TIME} } @jobloop;
94 my $reports = get_saved_reports();
96 foreach my $report (@$reports) {
97 $report->{'selected'} = 1 if $report->{'id'} eq $id;
101 $template->param( 'savedreports' => $reports );
102 $template->param( JOBS => \@jobloop );
103 my $time = localtime(time);
104 $template->param( 'time' => $time );
106 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
107 dateformat => C4::Dates->new()->format(),
110 output_html_with_http_headers $input, $cookie, $template->output;