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 # Retrieving the date according to the dateformat syspref
57 my $c4date = C4::Dates->new($input->param('startdate'));
59 # Formatting it for Schedule::At
60 my $startdate = join('', (split /-/, $c4date->output("iso")));
62 my $starttime = $input->param('starttime');
63 my $recurring = $input->param('recurring');
64 $starttime =~ s/\://g;
65 my $start = $startdate . $starttime;
66 my $report = $input->param('report');
67 my $format = $input->param('format');
68 my $email = $input->param('email');
70 "EXPORT KOHA_CONF=\"$CONFIG_NAME\"; " . $base
71 . "/tools/runreport.pl $report $format $email";
74 my $frequency = $input->param('frequency');
75 add_cron_job( $start, $command );
78 unless ( add_at_job( $start, $command ) ) {
79 $template->param( job_add_failed => 1 );
84 if ( $mode eq 'job_change' ) {
85 my $jobid = $input->param('jobid');
86 if ( $input->param('delete') ) {
87 remove_at_job($jobid);
91 my $jobs = get_jobs();
93 foreach my $job ( values %$jobs ) {
97 @jobloop = sort { $a->{TIME} cmp $b->{TIME} } @jobloop;
99 my $reports = get_saved_reports();
101 foreach my $report (@$reports) {
102 $report->{'selected'} = 1 if $report->{'id'} eq $id;
106 $template->param( 'savedreports' => $reports );
107 $template->param( JOBS => \@jobloop );
108 my $time = localtime(time);
109 $template->param( 'time' => $time );
111 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
112 dateformat => C4::Dates->new()->format(),
115 output_html_with_http_headers $input, $cookie, $template->output;