add memcached questions to koha-install-log
[koha.git] / tools / scheduler.pl
blob5fae73d6132b9b407d4f66497a5951c2d40f6818
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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
20 use strict;
21 use C4::Context;
22 use C4::Scheduler;
23 use C4::Reports::Guided;
24 use C4::Auth;
25 use CGI;
26 use C4::Output;
27 use C4::Dates;
29 use vars qw($debug);
31 BEGIN {
32 $debug = $ENV{DEBUG} || 0;
35 my $input = new CGI;
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",
43 query => $input,
44 type => "intranet",
45 authnotrequired => 0,
46 flagsrequired => { tools => 'schedule_tasks' },
47 debug => 1,
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');
69 my $command =
70 "EXPORT KOHA_CONF=\"$CONFIG_NAME\"; " . $base
71 . "/tools/runreport.pl $report $format $email";
73 if ($recurring) {
74 my $frequency = $input->param('frequency');
75 add_cron_job( $start, $command );
77 else {
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();
92 my @jobloop;
93 foreach my $job ( values %$jobs ) {
94 push @jobloop, $job;
97 @jobloop = sort { $a->{TIME} cmp $b->{TIME} } @jobloop;
99 my $reports = get_saved_reports();
100 if ( defined $id ) {
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 );
110 $template->param(
111 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
112 dateformat => C4::Dates->new()->format(),
113 debug => $debug,
115 output_html_with_http_headers $input, $cookie, $template->output;