Files needed by the scheduler
authorChris Cormack <crc@liblime.com>
Mon, 29 Oct 2007 18:19:57 +0000 (13:19 -0500)
committerJoshua Ferraro <jmf@liblime.com>
Mon, 29 Oct 2007 21:11:33 +0000 (16:11 -0500)
Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Scheduler.pm [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/modules/tools/scheduler.tmpl [new file with mode: 0644]
tools/runreport.pl [new file with mode: 0755]

diff --git a/C4/Scheduler.pm b/C4/Scheduler.pm
new file mode 100644 (file)
index 0000000..961df0e
--- /dev/null
@@ -0,0 +1,95 @@
+package C4::Scheduler;
+
+# Copyright 2007 Liblime Ltd
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+use strict;
+require Exporter;
+
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
+use C4::Context;
+use Smart::Comments;
+use Schedule::At;
+# set the version for version checking
+$VERSION = 0.01;
+
+@ISA = qw(Exporter);
+@EXPORT =
+  qw(get_jobs get_job add_job remove_job);
+
+=head1 NAME
+
+C4::Scheduler - Module for running jobs with the unix at command
+
+=head1 SYNOPSIS
+
+  use C4::Scheduler;
+
+=head1 DESCRIPTION
+
+
+=head1 METHODS
+
+=over 2
+
+=cut
+
+=item get_jobs();
+
+This will return all scheduled jobs
+
+=cut
+
+sub get_jobs {
+       my %jobs = Schedule::At::getJobs();
+       return (\%jobs);
+}
+
+=item get_job($id)
+
+This will return the job with the given id
+
+=cut
+
+sub get_job {
+       my ($id)=@_;
+       my %jobs = chedule::At::getJobs(JOBID => $id);
+}
+
+=item add_job ($time,$command)
+
+Given a timestamp and a command this will schedule the job to run at that time
+
+=cut
+
+sub add_job {
+       my ($time,$command) = @_;
+       Schedule::At::add(TIME => $time, COMMAND => $command, TAG => $command);
+}
+
+sub remove_job {
+       my ($jobid)=@_;
+       Schedule::At::remove(JOBID => $jobid);
+}
+
+=head1 AUTHOR
+
+Chris Cormack <crc@liblime.com>
+
+=cut
+
+1;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/scheduler.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/scheduler.tmpl
new file mode 100644 (file)
index 0000000..3b4c2e2
--- /dev/null
@@ -0,0 +1,130 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+<!-- TMPL_INCLUDE NAME="header.inc" -->
+<!-- TMPL_INCLUDE NAME="circ-search.inc" -->
+
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/circ/circulation.pl">Reports</a> &rsaquo; <strong>Guided Reports Wizard </strong></div>
+
+<div id="doc3" class="yui-t2">
+
+   <div id="bd">
+    <div id="yui-main">
+    <div class="yui-b">
+
+<div id="main">
+<form name="form1" action="scheduler.pl" method="post">
+<input type="hidden" name="mode" value="job_add">
+
+<table border="0" cellspacing="0" cellpadding="0">
+<tr><td>Current server time is</td>
+<td><!-- TMPL_VAR NAME="time" --></td></tr>
+<tr><td class="cell">Time</td>
+<td class="cell"><input type="text" name="starttime" value="" maxlength="5" size="5" /></td>
+<td class="cell"><select name="startday">
+<option value="01">1</option>                  
+<option value="02">2</option>
+<option value="03">3</option>
+<option value="04">4</option>
+<option value="05">5</option>
+<option value="06">6</option>
+<option value="07">7</option>
+<option value="08">8</option>
+<option value="09">9</option>
+<option value="10">10</option>
+<option value="11">11</option>
+<option value="12">12</option>
+<option value="13">13</option>
+<option value="14">14</option>
+<option value="15">15</option>
+<option value="16">16</option>
+<option value="17">17</option>
+<option value="18">18</option>
+<option value="19">19</option>         
+<option value="20">20</option>
+<option value="21">21</option>
+<option value="22">22</option>
+<option value="23">23</option>
+<option value="24">24</option>
+<option value="25">25</option>                                                                                                         
+<option value="26">26</option>
+<option value="27">27</option>
+<option value="28">28</option>
+<option value="29">29</option>
+<option value="30">30</option>
+<option value="31">31</option>
+
+</select>
+</td>
+<td class="cell"><select name="startmonth">
+<option value="01">Jan</option>
+<option value="02">Feb</option>
+<option value="03">Mar</option>
+<option value="04">Apr</option>                
+<option value="05">May</option>
+<option value="06">Jun</option>
+<option value="07">Jul</option>
+<option value="08">Aug</option>
+<option value="09">Sep</option>
+<option value="10">Oct</option>
+<option value="11">Nov</option>
+<option value="12">Dec</option>
+</select>
+</td>
+<td class="cell"><select name="startyear">
+<option value="2007">2007</option>
+<option value="2008">2008</option>
+
+</select>
+</td>
+</tr>
+<tr><td class="cell">Report</td><td>
+<select name="report">
+<!-- TMPL_LOOP NAME="savedreports" -->                                   
+<option value="<!-- TMPL_VAR NAME="id" -->"><!-- TMPL_VAR NAME="report_name"--></option>                  
+<!-- /TMPL_LOOP -->
+</select>
+</tr>
+<tr><td class="cell">Output Format</td>
+<td><select name="format">
+<option value="text">Text</option>
+</select></td>
+</tr>
+<tr><td class="cell">Email</td>
+<td>
+<input type=text name=email>
+</td></tr>
+<tr><td><input class="submit-button" type="submit" value="Add">
+</td></tr>
+</table>
+</form>
+  
+<h2>Jobs already entered</h2>
+<table>
+<tr>
+<th>Date/Time</th>
+<th>Action</th>
+<th>&nbsp;</th>
+</tr>
+<TMPL_LOOP NAME="JOBS">
+<form action="scheduler.pl" method="post">
+<input type=hidden name=mode value="job_change">
+
+<tr>
+<td><TMPL_VAR NAME="TIME"></td>
+<td><TMPL_VAR NAME="TAG"></td>
+<td><input type="submit" value="Edit"/>&nbsp;<input type="submit" name="delete" value="Delete" /></td>
+</tr>
+<input type=hidden name=jobid value="<TMPL_VAR NAME="JOBID">">
+</form>
+</TMPL_LOOP>
+</table>
+
+
+</div>
+</div>
+</div>
+<div class="yui-b">
+<!-- TMPL_INCLUDE NAME="guided-reports-view.inc" -->
+</div>
+</div>
+<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
diff --git a/tools/runreport.pl b/tools/runreport.pl
new file mode 100755 (executable)
index 0000000..e920bee
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+
+# fix this line
+use C4::Reports;
+
+use Mail::Sendmail;
+
+
+my ($report,$format,$email) = @ARGV;
+
+my ($sql,$type) = get_saved_report($report);
+my $results = execute_query($sql,$type,$format); 
+my $message;
+if ($format eq 'text'){
+       $message="<table>$results</table>";     
+}
+
+if ($email){
+       my $to      = $email;
+       # should be koha admin email
+    my $from    = 'crc@liblime.com';
+    my $subject = 'Automated job run';
+    my %mail    = (
+                       To      => $to,
+                       From    => $from,
+                       Subject => $subject,
+                       Message => $message 
+                   );
+                                                                                                                                                           
+       if (not(sendmail %mail)) { 
+                  warn "mail not sent";
+                  }
+       }