More work on the scheduler
[koha.git] / tools / scheduler.pl
1 #!/usr/bin/perl
2
3 # Copyright 2007 Liblime Ltd
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
15 #
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
19
20 use strict;
21 use C4::Context;
22 use C4::Scheduler;
23 use C4::Reports;
24 use C4::Auth;                                                                                                                                              
25 use CGI;                                                                                                                                                   
26 use C4::Output;                                                                                                                                            
27
28 my $input = new CGI;
29
30 my $base = C4::Context->config('intranetdir');
31 my $command = "EXPORT KOHA_CONF=\"$CONFIG_NAME\"; ".$base."/tools/runreport.pl $report $format $email";
32
33 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
34             {
35                 template_name   => "tools/scheduler.tmpl",
36                 query           => $input,
37                 type            => "intranet",
38                 authnotrequired => 0,
39                 flagsrequired   => { editcatalogue => 1 },
40                 debug           => 1,
41             }
42         );
43
44 my $mode=$input->param('mode');
45
46 if ($mode eq 'job_add') {
47         my $startday   = $input->param('startday');
48         my $startmonth = $input->param('startmonth');
49         my $startyear  = $input->param('startyear');
50         my $starttime  = $input->param('starttime');
51         my $recurring = $input->param('recurring');     
52         $starttime  =~ s/\://g;
53         my $start = $startyear . $startmonth . $startday . $starttime;
54         my $report=$input->param('report');
55         my $format=$input->param('format');
56         my $email=$input->param('email');
57         if ($recurring){
58             my $frequency = $input->param('frequency');
59             add_cron_job($start,$command);
60         }
61         else {
62             add_at_job($start,$command);
63         }
64 }
65
66 if ($mode eq 'job_change'){
67         my $jobid = $input->param('jobid');
68         if ($input->param('delete')){
69                 remove_at_job($jobid);
70         }
71 }
72
73 my $jobs = get_jobs();
74 my @jobloop;
75  foreach my $job (values %$jobs) {
76      push @jobloop,$job;
77 }
78
79 @jobloop = sort {$a->{TIME} cmp $b->{TIME}} @jobloop;
80 my $reports = get_saved_reports();                                                                                                                     
81 $template->param( 'savedreports' => $reports ); 
82 $template->param(JOBS => \@jobloop);
83 my $time = localtime(time);
84 $template->param('time' => $time);
85 output_html_with_http_headers $input, $cookie, $template->output;