diff --git a/bin/scheduler.php b/bin/scheduler.php
index e51162e..5101cd5 100644
--- a/bin/scheduler.php
+++ b/bin/scheduler.php
@@ -96,7 +96,7 @@ function updateTask($aFieldValues, $iId) {
function getTaskList() {
$now = date('Y-m-d H:i:s'); //time();
- $query = "SELECT * FROM scheduler_tasks WHERE is_complete = 0 AND run_time < '{$now}'";
+ $query = "SELECT * FROM scheduler_tasks WHERE is_complete = 0 AND run_time < '{$now}' AND status != 'disabled'";
$result = DBUtil::getResultArray($query);
diff --git a/plugins/ktcore/scheduler/scheduler.php b/plugins/ktcore/scheduler/scheduler.php
index 8f379c8..78ff4a0 100644
--- a/plugins/ktcore/scheduler/scheduler.php
+++ b/plugins/ktcore/scheduler/scheduler.php
@@ -1,36 +1,36 @@
.
- *
+ *
* You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
* Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
- *
+ *
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
- *
+ *
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
- * KnowledgeTree" logo and retain the original copyright notice. If the display of the
+ * KnowledgeTree" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
- * must display the words "Powered by KnowledgeTree" and retain the original
- * copyright notice.
+ * must display the words "Powered by KnowledgeTree" and retain the original
+ * copyright notice.
* Contributor( s): ______________________________________
*
*/
@@ -47,7 +47,8 @@ class Scheduler
var $aParams = '';
var $sFreq = 'daily';
var $iStartTime = '';
-
+ var $sStatus = 'disabled';
+
/**
* Constructor function - set the name of the task
*/
@@ -56,14 +57,14 @@ class Scheduler
$this->sFreq = 'daily';
$this->iStartTime = time();
}
-
+
/**
* Set the name of the task
*/
function setTaskName($sName) {
$this->sName = $sName;
}
-
+
/**
* Set the path to the script from the KT base path
* For example: "/var/tasks/script.php" or "/bin/script.php"
@@ -71,14 +72,14 @@ class Scheduler
function setScriptPath($sPath) {
$this->sPath = $sPath;
}
-
+
/**
* Add a parameter pair to pass to the script
*/
function addParameter($param, $value){
$this->aParams[$param] = $value;
}
-
+
/**
* Set the frequency with which the task must be run
* Frequencies are: daily, weekly, monthly, hourly, half_hourly, quarter_hourly, 10mins, 5mins and once
@@ -86,16 +87,34 @@ class Scheduler
function setFrequency($sFrequency) {
$this->sFreq = $sFrequency;
}
-
+
/**
- * Set the time at which the task should first be run or if it is a once off, the time to run it.
+ * Set the time at which the task should first be run or if it is a once off, the time to run it.
* Time should be in datetime format.
- * By default the time is set to now.
+ * By default the time is set to now.
*/
function setFirstRunTime($iTime) {
$this->iStartTime = !empty($iTime) ? $iTime : date('Y-m-d H:i:s');
}
-
+
+ /**
+ * Set the task as enabled or disabled. If the task is already set as a system task, then ignore.
+ */
+ function setEnabled($bStatus = FALSE) {
+ if($bStatus && $this->sStatus != 'system'){
+ $this->sStatus = 'enabled';
+ }
+ }
+
+ /**
+ * Set the task as a system task, this cannot be enabled or disabled.
+ */
+ function setAsSystemTask($bSystem = FALSE) {
+ if($bSystem){
+ $this->sStatus = 'system';
+ }
+ }
+
/**
* Create a script - write it to the filesystem.
* Scripts are saved in the KT_DIR."/var/tasks/" directory.
@@ -105,33 +124,33 @@ class Scheduler
// Path to scripts
$ktPath = '/var/tasks/';
$path = KT_DIR.$ktPath;
-
+
if(!is_dir($path)){
mkdir($path, '0755');
}
-
+
// Create script file
$sName = str_replace(' ', '_', $this->sName);
$sName = str_replace('', "'", $sName);
$sName = str_replace('', "&", $sName);
$sFileName = $sName.'_'.mt_rand(1, 999).'.php';
-
+
while(file_exists($path.$sFileName)){
$sFileName = $sTask.'_'.mt_rand(1, 9999).'.php';
}
-
+
$fp = fopen($path.$sFileName, 'wb');
fwrite($fp, $sScript);
fclose($fp);
-
+
$this->sPath = $ktPath.$sFileName;
}
-
+
/**
* Register the task in the scheduler
*/
function registerTask(){
- schedulerUtil::registerTask($this->sName, $this->sPath, $this->aParams, $this->sFreq, $this->iStartTime);
+ schedulerUtil::registerTask($this->sName, $this->sPath, $this->aParams, $this->sFreq, $this->iStartTime, $this->sStatus);
}
}
?>
diff --git a/plugins/ktcore/scheduler/schedulerDashlet.php b/plugins/ktcore/scheduler/schedulerDashlet.php
index 3329acb..3fa4aab 100644
--- a/plugins/ktcore/scheduler/schedulerDashlet.php
+++ b/plugins/ktcore/scheduler/schedulerDashlet.php
@@ -5,32 +5,32 @@
* KnowledgeTree Open Source Edition
* Document Management Made Simple
* Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
- *
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation.
- *
+ *
* This program 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 this program. If not, see .
- *
+ *
* You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
* Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
- *
+ *
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
- *
+ *
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
- * KnowledgeTree" logo and retain the original copyright notice. If the display of the
+ * KnowledgeTree" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
- * must display the words "Powered by KnowledgeTree" and retain the original
- * copyright notice.
+ * must display the words "Powered by KnowledgeTree" and retain the original
+ * copyright notice.
* Contributor( s): ______________________________________
*
*/
@@ -42,7 +42,7 @@ class schedulerDashlet extends KTBaseDashlet {
var $oUser;
var $sClass = "ktError";
var $aTimes = array();
-
+
function schedulerDashlet() {
$this->sTitle = _kt('Scheduler');
}
@@ -55,7 +55,7 @@ class schedulerDashlet extends KTBaseDashlet {
}
return false;
}
-
+
/**
* Get the last and next run times for the scheduler.
* @return bool true if scheduler is overdue
@@ -63,26 +63,26 @@ class schedulerDashlet extends KTBaseDashlet {
function checkOverDue() {
$this->aTimes = schedulerUtil::checkLastRunTime();
$sNextRunTime = $this->aTimes['nextruntime'];
-
+
$iNow = time();
$iNext = strtotime($sNextRunTime);
-
+
if($iNow > $iNext){
$iDif = $iNow - $iNext;
-
+
// if it hasn't run for a whole day then display dashlet alert.
if($iDif > 60*60*24) {
return true;
}
}
-
+
return false;
}
-
+
/**
* Calculate the time difference in days/hours/minutes
*/
- function renderTime($iDif, $iUnit, $iRemainder, $sUnit, $sRemainder) {
+ function renderTime($iDif, $iUnit, $iRemainder, $sUnit, $sRemainder) {
// days
$iTime = round($iDif / $iUnit, 2);
$aRemainder = explode('.', $iTime);
@@ -95,48 +95,48 @@ class schedulerDashlet extends KTBaseDashlet {
$time = floor($iTime).' '.$sUnit.$remainder;
return $time;
}
-
+
/**
* Get the last and next run times for the scheduler
*/
function getRunTimes() {
$bDue = FALSE;
-
+
// Check when the scheduler last ran and when the next task run time should be
$aTimes = $this->aTimes;
- $sLastRunTime = $aTimes['lastruntime'];
+ $sLastRunTime = $aTimes['lastruntime'];
$sNextRunTime = $aTimes['nextruntime'];
-
+
// Check if scheduler has missed the last run
$iNow = time();
$iNext = strtotime($sNextRunTime);
-
+
if($iNow > $iNext){
$bDue = TRUE;
$iDif = $iNow - $iNext;
}else{
$iDif = $iNext - $iNow;
}
-
+
$time = $iDif.' '._kt('seconds'); $remainder = '';
// Get the difference in easy units of time
- if($iDif >= 60*60*24*7){
+ if($iDif >= 60*60*24*7){
// weeks
$time = ' '.schedulerDashlet::renderTime($iDif, 60*60*24*7, 7, _kt('week(s)'), _kt('day(s)'));
- }else if($iDif >= 60*60*24){
- // days
+ }else if($iDif >= 60*60*24){
+ // days
$time = ' '.schedulerDashlet::renderTime($iDif, 60*60*24, 24, _kt('day(s)'), _kt('hour(s)'));
- }else if($iDif >= 60*60){
+ }else if($iDif >= 60*60){
// hours
$time = ' '.schedulerDashlet::renderTime($iDif, 60*60, 60, _kt('hour(s)'), _kt('minute(s)'));
- }else if($iDif >= 60){
+ }else if($iDif >= 60){
// minutes
$time = ' '.schedulerDashlet::renderTime($iDif, 60, 60, _kt('minute(s)'), _kt('second(s)'));
}
-
+
return array('lasttime' => $sLastRunTime, 'timedif' => $time, 'due' => $bDue);
}
-
+
function render() {
$bWin = false;
if(OS_WINDOWS){
@@ -146,11 +146,11 @@ class schedulerDashlet extends KTBaseDashlet {
$sLastTime = $aTimes['lasttime'];
$sTimeDif = $aTimes['timedif'];
$bDue = $aTimes['due'];
-
-
+
+
$oKTConfig =& KTConfig::getSingleton();
$rootUrl = $oKTConfig->get("rootUrl");
-
+
if($oKTConfig->get("ui/morphEnabled") == '1') {
$sImg = $rootUrl.'/skins/kts_'.$oKTConfig->get("ui/morphTo");
}else{
@@ -158,9 +158,9 @@ class schedulerDashlet extends KTBaseDashlet {
}
$sImgPlus = $sImg.'/bullet_toggle_plus.png';
$sImgMinus = $sImg.'/bullet_toggle_minus.png';
-
+
$sPath = KT_DIR.'/bin/scheduler.php';
- $sOnClick = " var cron = document.getElementById('cronguide');
+ $sOnClick = " var cron = document.getElementById('cronguide');
var icon = document.getElementById('scheduler_icon');
if(cron.style.visibility == 'hidden'){
cron.style.visibility = 'visible'; cron.style.display = 'block';
@@ -169,9 +169,10 @@ class schedulerDashlet extends KTBaseDashlet {
cron.style.visibility = 'hidden'; cron.style.display = 'none';
icon.src = '{$sImgPlus}';
}";
-
+
$sAdmin = KTUtil::ktLink('admin.php', 'misc/scheduler');
-
+ $sAdminLink = ""._kt('Administration page').'';
+
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate('ktcore/dashlets/scheduler');
@@ -181,7 +182,7 @@ class schedulerDashlet extends KTBaseDashlet {
'isDue' => $bDue,
'bWin' => $bWin,
'sPath' => $sPath,
- 'sAdmin' => $sAdmin,
+ 'sAdminLink' => $sAdminLink,
'sImg' => $sImgPlus,
'onClick' => $sOnClick,
);
diff --git a/plugins/ktcore/scheduler/schedulerEntity.php b/plugins/ktcore/scheduler/schedulerEntity.php
index 86824b7..fb60fbe 100644
--- a/plugins/ktcore/scheduler/schedulerEntity.php
+++ b/plugins/ktcore/scheduler/schedulerEntity.php
@@ -52,6 +52,7 @@ class schedulerEntity extends KTEntity
var $iRun_time;
var $iPrevious_run_time;
var $iRun_duration;
+ var $sStatus;
var $_aFieldToSelect = array(
'iId' => 'id',
@@ -62,7 +63,8 @@ class schedulerEntity extends KTEntity
'iFrequency' => 'frequency',
'iRun_time' => 'run_time',
'iPrevious_run_time' => 'previous_run_time',
- 'iRun_duration' => 'run_duration'
+ 'iRun_duration' => 'run_duration',
+ 'sStatus' => 'status'
);
function _table () {
@@ -78,6 +80,7 @@ class schedulerEntity extends KTEntity
function getParams() { return $this->sScript_params; }
function getIsComplete() { return $this->bIs_complete; }
function getFrequency() { return $this->iFrequency; }
+ function getStatus() { return $this->sStatus; }
function getFrequencyByLang() {
$aFrequencies = array(
@@ -117,6 +120,7 @@ class schedulerEntity extends KTEntity
function setRunTime($sValue) { return $this->iRun_time = date('Y-m-d H:i:s', $sValue); }
function setPrevious($sValue) { return $this->iPrevious_run_time = date('Y-m-d H:i:s', $sValue); }
function setRunDuration($sValue) { return $this->iRun_duration = $sValue; }
+ function setStatus($sValue) { return $this->sStatus = $sValue; }
function get($iId) {
return KTEntityUtil::get('schedulerEntity', $iId);
@@ -124,10 +128,11 @@ class schedulerEntity extends KTEntity
function getTasksToRun() {
$aOptions = array('multi' => true);
- $aFields = array('is_complete', 'run_time');
+ $aFields = array('is_complete', 'run_time', 'status');
$aValues = array();
$aValues[] = array('type' => 'equals', 'value' => '0');
$aValues[] = array('type' => 'before', 'value' => time());
+ $aValues[] = array('type' => 'nequals', 'value' => 'disabled');
return KTEntityUtil::getBy('schedulerEntity', $aFields, $aValues, $aOptions);
}
@@ -139,9 +144,10 @@ class schedulerEntity extends KTEntity
function getLastRunTime($date) {
$aOptions = array('multi' => true, 'orderby' => 'previous_run_time DESC');
- $aFields = array('previous_run_time');
+ $aFields = array('previous_run_time', 'status');
$aValues = array();
$aValues[] = array('type' => 'before', 'value' => $date);
+ $aValues[] = array('type' => 'nequals', 'value' => 'disabled');
return KTEntityUtil::getBy('schedulerEntity', $aFields, $aValues, $aOptions);
}
@@ -175,11 +181,40 @@ class schedulerEntity extends KTEntity
}
/**
+ * Display the task name. If the task is disabled then grey it out.
+ *
+ */
+ function getTaskDiv() {
+ $sId = $this->getId();
+ $sStatus = $this->getStatus();
+
+ $sDiv = "' : 'class="descriptiveText">';
+ $sDiv .= $this->getTask().'';
+ return $sDiv;
+ }
+
+ function getFreqDiv() {
+ $sId = $this->getId();
+ $sStatus = $this->getStatus();
+ $sFreqs = $this->getFrequencyByLang();
+
+ $sLink = "' : '>';
+ $sLink .= "$sFreqs
";
+ return $sLink;
+ }
+
+ /**
* Get a link to alter the frequency of a task
*/
function getAlterFreqLink() {
$sId = $this->getId();
- $sLink = ""._kt('Alter frequency')."";
+ $sStatus = $this->getStatus();
+
+ $sLink = "' : '>';
+ $sLink .= _kt('Alter frequency')."";
return $sLink;
}
@@ -188,9 +223,33 @@ class schedulerEntity extends KTEntity
*/
function getRunNowLink() {
$sId = $this->getId();
+ $sStatus = $this->getStatus();
$sUrl = KTUtil::ktLink('admin.php', 'misc/scheduler', 'action=updateRunTime');
- $sLink = ""._kt('Run on next iteration')."";
+
+ $sLink = "' : '>';
+ $sLink .= _kt('Run on next iteration')."";
+ return $sLink;
+ }
+
+ /**
+ * Run the task on the next iteration
+ */
+ function getStatusLink() {
+ $sId = $this->getId();
+ $sStatus = $this->getStatus();
+ if($sStatus == 'system'){
+ return '';
+ }
+
+ $sDisableText = _kt('Disable task');
+ $sEnableText = _kt('Enable task');
+
+ $sLinkText = ($sStatus == 'enabled') ? $sDisableText : $sEnableText;
+ $sUrl = KTUtil::ktLink('admin.php', 'misc/scheduler', 'action=updateStatus');
+ $sLink = "{$sLinkText}";
return $sLink;
}
}
-?>
+?>
\ No newline at end of file
diff --git a/plugins/ktcore/scheduler/schedulerUtil.php b/plugins/ktcore/scheduler/schedulerUtil.php
index c1feef3..5839787 100644
--- a/plugins/ktcore/scheduler/schedulerUtil.php
+++ b/plugins/ktcore/scheduler/schedulerUtil.php
@@ -77,7 +77,7 @@ class schedulerUtil extends KTUtil
/**
* Method to register a task in the schedule
*/
- function registerTask($sTask, $sUrl, $aParams, $sFreq, $iStartTime = NULL) {
+ function registerTask($sTask, $sUrl, $aParams, $sFreq, $iStartTime = NULL, $sStatus = 'disabled') {
// Run task on next iteration if no start time given
$iStartTime = (!empty($iStartTime)) ? strtotime($iStartTime) : time();
@@ -101,6 +101,7 @@ class schedulerUtil extends KTUtil
$aTask['run_time'] = $dNextTime;
$aTask['previous_run_time'] = $dStartTime;
$aTask['run_duration'] = '0';
+ $sTask['status'] = $sStatus;
$oEntity = schedulerEntity::createFromArray($aTask);
if (PEAR::isError($oEntity)){
@@ -127,6 +128,7 @@ class schedulerUtil extends KTUtil
$aTask['is_complete'] = '0';
$aTask['run_time'] = date('Y-m-d H:i:s');
$aTask['run_duration'] = '0';
+ $aTask['status'] = 'enabled';
$oEntity = schedulerEntity::createFromArray($aTask);
if (PEAR::isError($oEntity)){
@@ -232,6 +234,29 @@ class schedulerUtil extends KTUtil
}
/**
+ * Toggle whether a task is enabled or disabled. If its a system task, then ignore.
+ */
+ function toggleStatus($id) {
+ $oScheduler = schedulerEntity::get($id);
+
+ if (PEAR::isError($oScheduler)){
+ return _kt('Object can\'t be created');
+ }
+
+ $sStatus = $oScheduler->getStatus();
+
+ if($sStatus == 'system'){
+ // ignore
+ return $sStatus;
+ }
+
+ $sNewStatus = ($sStatus == 'enabled') ? 'disabled' : 'enabled';
+ $oScheduler->setStatus($sNewStatus);
+ $oScheduler->update();
+ return $sNewStatus;
+ }
+
+ /**
* Check the last run time of the scheduler
*/
function checkLastRunTime() {
diff --git a/plugins/ktcore/scheduler/taskScheduler.php b/plugins/ktcore/scheduler/taskScheduler.php
index dec074b..61a31a9 100644
--- a/plugins/ktcore/scheduler/taskScheduler.php
+++ b/plugins/ktcore/scheduler/taskScheduler.php
@@ -120,5 +120,13 @@ class manageSchedulerDispatcher extends KTAdminDispatcher
schedulerUtil::updateRunTime($id, $iNextTime);
return $iNextTime;
}
+
+ /**
+ * Toggle the enable/disable on the task
+ */
+ function do_updateStatus() {
+ $fId = schedulerUtil::arrayGet($_REQUEST, 'fId');
+ schedulerUtil::toggleStatus($fId);
+ }
}
?>
diff --git a/resources/js/scheduler.js b/resources/js/scheduler.js
index c0e3111..3e9f89e 100644
--- a/resources/js/scheduler.js
+++ b/resources/js/scheduler.js
@@ -28,6 +28,38 @@ var runOnNext = function(fId, sUrl) {
var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, "fId="+fId);
}
+//
+var toggleStatus = function(fId, sUrl, sDisableText, sEnableText) {
+
+ var statusLink = document.getElementById('statusLink'+fId);
+ var freqLink = document.getElementById('freqLink'+fId);
+ var runnowLink = document.getElementById('runnowLink'+fId);
+ var freqDrop = document.getElementById('freqDrop'+fId);
+ var fontClass = document.getElementById('font'+fId);
+ var freqDiv = document.getElementById('div'+fId);
+
+ var callback = {
+ success: function(o) {
+ if(statusLink.innerHTML == sDisableText){
+ statusLink.innerHTML = sEnableText;
+ freqLink.style.visibility = "hidden";
+ runnowLink.style.visibility = "hidden";
+ freqDrop.style.visibility = "hidden";
+ fontClass.className = 'descriptiveText';
+ freqDiv.style.display = "none";
+ }else{
+ statusLink.innerHTML = sDisableText;
+ freqLink.style.visibility = "visible";
+ runnowLink.style.visibility = "visible";
+ freqDrop.style.visibility = "visible";
+ freqDiv.style.display = "block";
+ fontClass.className = '';
+ }
+ }
+ }
+ var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, "fId="+fId);
+}
+
var showFrequencyDiv = function(fId) {
var formDiv = document.getElementById('formDiv');
var fInput = document.getElementById('fId');
diff --git a/templates/ktcore/dashlets/scheduler.smarty b/templates/ktcore/dashlets/scheduler.smarty
index f166fa9..34a69bb 100644
--- a/templates/ktcore/dashlets/scheduler.smarty
+++ b/templates/ktcore/dashlets/scheduler.smarty
@@ -5,7 +5,7 @@
{else}
{i18n}No tasks have been run yet.{/i18n}
{/if}
- Administration page
+ {i18n arg_link=$sAdminLink}This can be configured via the #link#.{/i18n}
{if !$lasttime}
diff --git a/templates/ktcore/scheduler.smarty b/templates/ktcore/scheduler.smarty
index aca962c..2a5d4dc 100644
--- a/templates/ktcore/scheduler.smarty
+++ b/templates/ktcore/scheduler.smarty
@@ -28,15 +28,13 @@
|
- {$i++}
+ {$i++}
|
- {$task->getTask()}
+ {$task->getTaskDiv()}
|
-
-
- {$task->getFrequencyByLang()}
-
+ |
+ {$task->getFreqDiv()}
|
@@ -49,11 +47,11 @@
{$task->getPrevious(TRUE)}
|
-
+ |
{$task->getRunDuration()}
|
- {$task->getAlterFreqLink()} {$task->getRunNowLink()}
+ {$task->getAlterFreqLink()} {$task->getRunNowLink()} {$task->getStatusLink()}
|
@@ -70,7 +68,7 @@