Merge remote-tracking branch 'origin/new/bug_8585'
[koha.git] / tools / scheduler.pl
blob4d732db3a575fe895044297d0c540673fe06434e
1 #!/usr/bin/perl
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
10 # version.
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.
20 use strict;
21 #use warnings; FIXME - Bug 2505
22 use C4::Context;
23 use C4::Scheduler;
24 use C4::Reports::Guided;
25 use C4::Auth;
26 use CGI;
27 use C4::Output;
28 use C4::Dates;
30 use vars qw($debug);
32 BEGIN {
33 $debug = $ENV{DEBUG} || 0;
36 my $input = new CGI;
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",
44 query => $input,
45 type => "intranet",
46 authnotrequired => 0,
47 flagsrequired => { tools => 'schedule_tasks' },
48 debug => 1,
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');
70 my $command =
71 "EXPORT KOHA_CONF=\"$CONFIG_NAME\"; " . $base
72 . "/tools/runreport.pl $report $format $email";
74 if ($recurring) {
75 my $frequency = $input->param('frequency');
76 add_cron_job( $start, $command );
78 else {
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();
93 my @jobloop;
94 foreach my $job ( values %$jobs ) {
95 push @jobloop, $job;
98 @jobloop = sort { $a->{TIME} cmp $b->{TIME} } @jobloop;
100 my $reports = get_saved_reports();
101 if ( defined $id ) {
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 );
111 $template->param(
112 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
113 dateformat => C4::Dates->new()->format(),
114 debug => $debug,
116 output_html_with_http_headers $input, $cookie, $template->output;