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;
38 my $base = C4::Context->config('intranetdir');
39 my $CONFIG_NAME = $ENV{'KOHA_CONF'};
41 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
43 template_name => "tools/scheduler.tmpl",
47 flagsrequired => { tools => 'schedule_tasks' },
52 my $mode = $input->param('mode');
53 my $id = $input->param('id');
55 if ( $mode eq 'job_add' ) {
57 # Retrieving the date according to the dateformat syspref
58 my $c4date = C4::Dates->new($input->param('startdate'));
60 # Formatting it for Schedule::At
61 my $startdate = join('', (split /-/, $c4date->output("iso")));
63 my $starttime = $input->param('starttime');
64 my $recurring = $input->param('recurring');
65 $starttime =~ s/\://g;
66 my $start = $startdate . $starttime;
67 my $report = $input->param('report');
68 my $format = $input->param('format');
69 my $email = $input->param('email');
71 "EXPORT KOHA_CONF=\"$CONFIG_NAME\"; " . $base
72 . "/tools/runreport.pl $report $format $email";
75 my $frequency = $input->param('frequency');
76 add_cron_job( $start, $command );
79 unless ( add_at_job( $start, $command ) ) {
80 $template->param( job_add_failed => 1 );
85 if ( $mode eq 'job_change' ) {
86 my $jobid = $input->param('jobid');
87 if ( $input->param('delete') ) {
88 remove_at_job($jobid);
92 my $jobs = get_jobs();
94 foreach my $job ( values %$jobs ) {
98 @jobloop = sort { $a->{TIME} cmp $b->{TIME} } @jobloop;
100 my $reports = get_saved_reports();
102 foreach my $report (@$reports) {
103 $report->{'selected'} = 1 if $report->{'id'} eq $id;
107 $template->param( 'savedreports' => $reports );
108 $template->param( JOBS => \@jobloop );
109 my $time = localtime(time);
110 $template->param( 'time' => $time );
112 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
113 dateformat => C4::Dates->new()->format(),
116 output_html_with_http_headers $input, $cookie, $template->output;