Commit 449fb3ff4c03f747975bf059fcb38e907542cbfc

Authored by Megan Watson
1 parent 3cb20a4f

KTS-2691

"Add the ability to enable / disable tasks within the scheduler"
Fixed.  Tasks can be set as enabled / disabled / system. System tasks can't be disabled.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7719 c91229c3-7414-0410-bfa2-8a42b809f60b
bin/scheduler.php
... ... @@ -96,7 +96,7 @@ function updateTask($aFieldValues, $iId) {
96 96 function getTaskList() {
97 97 $now = date('Y-m-d H:i:s'); //time();
98 98  
99   - $query = "SELECT * FROM scheduler_tasks WHERE is_complete = 0 AND run_time < '{$now}'";
  99 + $query = "SELECT * FROM scheduler_tasks WHERE is_complete = 0 AND run_time < '{$now}' AND status != 'disabled'";
100 100  
101 101 $result = DBUtil::getResultArray($query);
102 102  
... ...
plugins/ktcore/scheduler/scheduler.php
1 1 <?php
2 2 /**
3   - * $Id:$
  3 + * $Id:$
4 4 *
5 5 * KnowledgeTree Open Source Edition
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
8   - *
  8 + *
9 9 * This program is free software; you can redistribute it and/or modify it under
10 10 * the terms of the GNU General Public License version 3 as published by the
11 11 * Free Software Foundation.
12   - *
  12 + *
13 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 16 * details.
17   - *
  17 + *
18 18 * You should have received a copy of the GNU General Public License
19 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20   - *
  20 + *
21 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23   - *
  23 + *
24 24 * The interactive user interfaces in modified source and object code versions
25 25 * of this program must display Appropriate Legal Notices, as required under
26 26 * Section 5 of the GNU General Public License version 3.
27   - *
  27 + *
28 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 29 * these Appropriate Legal Notices must retain the display of the "Powered by
30   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  30 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
31 31 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
32   - * must display the words "Powered by KnowledgeTree" and retain the original
33   - * copyright notice.
  32 + * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * copyright notice.
34 34 * Contributor( s): ______________________________________
35 35 *
36 36 */
... ... @@ -47,7 +47,8 @@ class Scheduler
47 47 var $aParams = '';
48 48 var $sFreq = 'daily';
49 49 var $iStartTime = '';
50   -
  50 + var $sStatus = 'disabled';
  51 +
51 52 /**
52 53 * Constructor function - set the name of the task
53 54 */
... ... @@ -56,14 +57,14 @@ class Scheduler
56 57 $this->sFreq = 'daily';
57 58 $this->iStartTime = time();
58 59 }
59   -
  60 +
60 61 /**
61 62 * Set the name of the task
62 63 */
63 64 function setTaskName($sName) {
64 65 $this->sName = $sName;
65 66 }
66   -
  67 +
67 68 /**
68 69 * Set the path to the script from the KT base path
69 70 * For example: "/var/tasks/script.php" or "/bin/script.php"
... ... @@ -71,14 +72,14 @@ class Scheduler
71 72 function setScriptPath($sPath) {
72 73 $this->sPath = $sPath;
73 74 }
74   -
  75 +
75 76 /**
76 77 * Add a parameter pair to pass to the script
77 78 */
78 79 function addParameter($param, $value){
79 80 $this->aParams[$param] = $value;
80 81 }
81   -
  82 +
82 83 /**
83 84 * Set the frequency with which the task must be run
84 85 * Frequencies are: daily, weekly, monthly, hourly, half_hourly, quarter_hourly, 10mins, 5mins and once
... ... @@ -86,16 +87,34 @@ class Scheduler
86 87 function setFrequency($sFrequency) {
87 88 $this->sFreq = $sFrequency;
88 89 }
89   -
  90 +
90 91 /**
91   - * Set the time at which the task should first be run or if it is a once off, the time to run it.
  92 + * Set the time at which the task should first be run or if it is a once off, the time to run it.
92 93 * Time should be in datetime format.
93   - * By default the time is set to now.
  94 + * By default the time is set to now.
94 95 */
95 96 function setFirstRunTime($iTime) {
96 97 $this->iStartTime = !empty($iTime) ? $iTime : date('Y-m-d H:i:s');
97 98 }
98   -
  99 +
  100 + /**
  101 + * Set the task as enabled or disabled. If the task is already set as a system task, then ignore.
  102 + */
  103 + function setEnabled($bStatus = FALSE) {
  104 + if($bStatus && $this->sStatus != 'system'){
  105 + $this->sStatus = 'enabled';
  106 + }
  107 + }
  108 +
  109 + /**
  110 + * Set the task as a system task, this cannot be enabled or disabled.
  111 + */
  112 + function setAsSystemTask($bSystem = FALSE) {
  113 + if($bSystem){
  114 + $this->sStatus = 'system';
  115 + }
  116 + }
  117 +
99 118 /**
100 119 * Create a script - write it to the filesystem.
101 120 * Scripts are saved in the KT_DIR."/var/tasks/" directory.
... ... @@ -105,33 +124,33 @@ class Scheduler
105 124 // Path to scripts
106 125 $ktPath = '/var/tasks/';
107 126 $path = KT_DIR.$ktPath;
108   -
  127 +
109 128 if(!is_dir($path)){
110 129 mkdir($path, '0755');
111 130 }
112   -
  131 +
113 132 // Create script file
114 133 $sName = str_replace(' ', '_', $this->sName);
115 134 $sName = str_replace('', "'", $sName);
116 135 $sName = str_replace('', "&", $sName);
117 136 $sFileName = $sName.'_'.mt_rand(1, 999).'.php';
118   -
  137 +
119 138 while(file_exists($path.$sFileName)){
120 139 $sFileName = $sTask.'_'.mt_rand(1, 9999).'.php';
121 140 }
122   -
  141 +
123 142 $fp = fopen($path.$sFileName, 'wb');
124 143 fwrite($fp, $sScript);
125 144 fclose($fp);
126   -
  145 +
127 146 $this->sPath = $ktPath.$sFileName;
128 147 }
129   -
  148 +
130 149 /**
131 150 * Register the task in the scheduler
132 151 */
133 152 function registerTask(){
134   - schedulerUtil::registerTask($this->sName, $this->sPath, $this->aParams, $this->sFreq, $this->iStartTime);
  153 + schedulerUtil::registerTask($this->sName, $this->sPath, $this->aParams, $this->sFreq, $this->iStartTime, $this->sStatus);
135 154 }
136 155 }
137 156 ?>
... ...
plugins/ktcore/scheduler/schedulerDashlet.php
... ... @@ -5,32 +5,32 @@
5 5 * KnowledgeTree Open Source Edition
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
8   - *
  8 + *
9 9 * This program is free software; you can redistribute it and/or modify it under
10 10 * the terms of the GNU General Public License version 3 as published by the
11 11 * Free Software Foundation.
12   - *
  12 + *
13 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 16 * details.
17   - *
  17 + *
18 18 * You should have received a copy of the GNU General Public License
19 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20   - *
  20 + *
21 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23   - *
  23 + *
24 24 * The interactive user interfaces in modified source and object code versions
25 25 * of this program must display Appropriate Legal Notices, as required under
26 26 * Section 5 of the GNU General Public License version 3.
27   - *
  27 + *
28 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 29 * these Appropriate Legal Notices must retain the display of the "Powered by
30   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  30 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
31 31 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
32   - * must display the words "Powered by KnowledgeTree" and retain the original
33   - * copyright notice.
  32 + * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * copyright notice.
34 34 * Contributor( s): ______________________________________
35 35 *
36 36 */
... ... @@ -42,7 +42,7 @@ class schedulerDashlet extends KTBaseDashlet {
42 42 var $oUser;
43 43 var $sClass = "ktError";
44 44 var $aTimes = array();
45   -
  45 +
46 46 function schedulerDashlet() {
47 47 $this->sTitle = _kt('Scheduler');
48 48 }
... ... @@ -55,7 +55,7 @@ class schedulerDashlet extends KTBaseDashlet {
55 55 }
56 56 return false;
57 57 }
58   -
  58 +
59 59 /**
60 60 * Get the last and next run times for the scheduler.
61 61 * @return bool true if scheduler is overdue
... ... @@ -63,26 +63,26 @@ class schedulerDashlet extends KTBaseDashlet {
63 63 function checkOverDue() {
64 64 $this->aTimes = schedulerUtil::checkLastRunTime();
65 65 $sNextRunTime = $this->aTimes['nextruntime'];
66   -
  66 +
67 67 $iNow = time();
68 68 $iNext = strtotime($sNextRunTime);
69   -
  69 +
70 70 if($iNow > $iNext){
71 71 $iDif = $iNow - $iNext;
72   -
  72 +
73 73 // if it hasn't run for a whole day then display dashlet alert.
74 74 if($iDif > 60*60*24) {
75 75 return true;
76 76 }
77 77 }
78   -
  78 +
79 79 return false;
80 80 }
81   -
  81 +
82 82 /**
83 83 * Calculate the time difference in days/hours/minutes
84 84 */
85   - function renderTime($iDif, $iUnit, $iRemainder, $sUnit, $sRemainder) {
  85 + function renderTime($iDif, $iUnit, $iRemainder, $sUnit, $sRemainder) {
86 86 // days
87 87 $iTime = round($iDif / $iUnit, 2);
88 88 $aRemainder = explode('.', $iTime);
... ... @@ -95,48 +95,48 @@ class schedulerDashlet extends KTBaseDashlet {
95 95 $time = floor($iTime).' '.$sUnit.$remainder;
96 96 return $time;
97 97 }
98   -
  98 +
99 99 /**
100 100 * Get the last and next run times for the scheduler
101 101 */
102 102 function getRunTimes() {
103 103 $bDue = FALSE;
104   -
  104 +
105 105 // Check when the scheduler last ran and when the next task run time should be
106 106 $aTimes = $this->aTimes;
107   - $sLastRunTime = $aTimes['lastruntime'];
  107 + $sLastRunTime = $aTimes['lastruntime'];
108 108 $sNextRunTime = $aTimes['nextruntime'];
109   -
  109 +
110 110 // Check if scheduler has missed the last run
111 111 $iNow = time();
112 112 $iNext = strtotime($sNextRunTime);
113   -
  113 +
114 114 if($iNow > $iNext){
115 115 $bDue = TRUE;
116 116 $iDif = $iNow - $iNext;
117 117 }else{
118 118 $iDif = $iNext - $iNow;
119 119 }
120   -
  120 +
121 121 $time = $iDif.' '._kt('seconds'); $remainder = '';
122 122 // Get the difference in easy units of time
123   - if($iDif >= 60*60*24*7){
  123 + if($iDif >= 60*60*24*7){
124 124 // weeks
125 125 $time = ' '.schedulerDashlet::renderTime($iDif, 60*60*24*7, 7, _kt('week(s)'), _kt('day(s)'));
126   - }else if($iDif >= 60*60*24){
127   - // days
  126 + }else if($iDif >= 60*60*24){
  127 + // days
128 128 $time = ' '.schedulerDashlet::renderTime($iDif, 60*60*24, 24, _kt('day(s)'), _kt('hour(s)'));
129   - }else if($iDif >= 60*60){
  129 + }else if($iDif >= 60*60){
130 130 // hours
131 131 $time = ' '.schedulerDashlet::renderTime($iDif, 60*60, 60, _kt('hour(s)'), _kt('minute(s)'));
132   - }else if($iDif >= 60){
  132 + }else if($iDif >= 60){
133 133 // minutes
134 134 $time = ' '.schedulerDashlet::renderTime($iDif, 60, 60, _kt('minute(s)'), _kt('second(s)'));
135 135 }
136   -
  136 +
137 137 return array('lasttime' => $sLastRunTime, 'timedif' => $time, 'due' => $bDue);
138 138 }
139   -
  139 +
140 140 function render() {
141 141 $bWin = false;
142 142 if(OS_WINDOWS){
... ... @@ -146,11 +146,11 @@ class schedulerDashlet extends KTBaseDashlet {
146 146 $sLastTime = $aTimes['lasttime'];
147 147 $sTimeDif = $aTimes['timedif'];
148 148 $bDue = $aTimes['due'];
149   -
150   -
  149 +
  150 +
151 151 $oKTConfig =& KTConfig::getSingleton();
152 152 $rootUrl = $oKTConfig->get("rootUrl");
153   -
  153 +
154 154 if($oKTConfig->get("ui/morphEnabled") == '1') {
155 155 $sImg = $rootUrl.'/skins/kts_'.$oKTConfig->get("ui/morphTo");
156 156 }else{
... ... @@ -158,9 +158,9 @@ class schedulerDashlet extends KTBaseDashlet {
158 158 }
159 159 $sImgPlus = $sImg.'/bullet_toggle_plus.png';
160 160 $sImgMinus = $sImg.'/bullet_toggle_minus.png';
161   -
  161 +
162 162 $sPath = KT_DIR.'/bin/scheduler.php';
163   - $sOnClick = " var cron = document.getElementById('cronguide');
  163 + $sOnClick = " var cron = document.getElementById('cronguide');
164 164 var icon = document.getElementById('scheduler_icon');
165 165 if(cron.style.visibility == 'hidden'){
166 166 cron.style.visibility = 'visible'; cron.style.display = 'block';
... ... @@ -169,9 +169,10 @@ class schedulerDashlet extends KTBaseDashlet {
169 169 cron.style.visibility = 'hidden'; cron.style.display = 'none';
170 170 icon.src = '{$sImgPlus}';
171 171 }";
172   -
  172 +
173 173 $sAdmin = KTUtil::ktLink('admin.php', 'misc/scheduler');
174   -
  174 + $sAdminLink = "<a href='{$sAdmin}'>"._kt('Administration page').'</a>';
  175 +
175 176 $oTemplating =& KTTemplating::getSingleton();
176 177 $oTemplate = $oTemplating->loadTemplate('ktcore/dashlets/scheduler');
177 178  
... ... @@ -181,7 +182,7 @@ class schedulerDashlet extends KTBaseDashlet {
181 182 'isDue' => $bDue,
182 183 'bWin' => $bWin,
183 184 'sPath' => $sPath,
184   - 'sAdmin' => $sAdmin,
  185 + 'sAdminLink' => $sAdminLink,
185 186 'sImg' => $sImgPlus,
186 187 'onClick' => $sOnClick,
187 188 );
... ...
plugins/ktcore/scheduler/schedulerEntity.php
... ... @@ -52,6 +52,7 @@ class schedulerEntity extends KTEntity
52 52 var $iRun_time;
53 53 var $iPrevious_run_time;
54 54 var $iRun_duration;
  55 + var $sStatus;
55 56  
56 57 var $_aFieldToSelect = array(
57 58 'iId' => 'id',
... ... @@ -62,7 +63,8 @@ class schedulerEntity extends KTEntity
62 63 'iFrequency' => 'frequency',
63 64 'iRun_time' => 'run_time',
64 65 'iPrevious_run_time' => 'previous_run_time',
65   - 'iRun_duration' => 'run_duration'
  66 + 'iRun_duration' => 'run_duration',
  67 + 'sStatus' => 'status'
66 68 );
67 69  
68 70 function _table () {
... ... @@ -78,6 +80,7 @@ class schedulerEntity extends KTEntity
78 80 function getParams() { return $this->sScript_params; }
79 81 function getIsComplete() { return $this->bIs_complete; }
80 82 function getFrequency() { return $this->iFrequency; }
  83 + function getStatus() { return $this->sStatus; }
81 84  
82 85 function getFrequencyByLang() {
83 86 $aFrequencies = array(
... ... @@ -117,6 +120,7 @@ class schedulerEntity extends KTEntity
117 120 function setRunTime($sValue) { return $this->iRun_time = date('Y-m-d H:i:s', $sValue); }
118 121 function setPrevious($sValue) { return $this->iPrevious_run_time = date('Y-m-d H:i:s', $sValue); }
119 122 function setRunDuration($sValue) { return $this->iRun_duration = $sValue; }
  123 + function setStatus($sValue) { return $this->sStatus = $sValue; }
120 124  
121 125 function get($iId) {
122 126 return KTEntityUtil::get('schedulerEntity', $iId);
... ... @@ -124,10 +128,11 @@ class schedulerEntity extends KTEntity
124 128  
125 129 function getTasksToRun() {
126 130 $aOptions = array('multi' => true);
127   - $aFields = array('is_complete', 'run_time');
  131 + $aFields = array('is_complete', 'run_time', 'status');
128 132 $aValues = array();
129 133 $aValues[] = array('type' => 'equals', 'value' => '0');
130 134 $aValues[] = array('type' => 'before', 'value' => time());
  135 + $aValues[] = array('type' => 'nequals', 'value' => 'disabled');
131 136  
132 137 return KTEntityUtil::getBy('schedulerEntity', $aFields, $aValues, $aOptions);
133 138 }
... ... @@ -139,9 +144,10 @@ class schedulerEntity extends KTEntity
139 144  
140 145 function getLastRunTime($date) {
141 146 $aOptions = array('multi' => true, 'orderby' => 'previous_run_time DESC');
142   - $aFields = array('previous_run_time');
  147 + $aFields = array('previous_run_time', 'status');
143 148 $aValues = array();
144 149 $aValues[] = array('type' => 'before', 'value' => $date);
  150 + $aValues[] = array('type' => 'nequals', 'value' => 'disabled');
145 151  
146 152 return KTEntityUtil::getBy('schedulerEntity', $aFields, $aValues, $aOptions);
147 153 }
... ... @@ -175,11 +181,40 @@ class schedulerEntity extends KTEntity
175 181 }
176 182  
177 183 /**
  184 + * Display the task name. If the task is disabled then grey it out.
  185 + *
  186 + */
  187 + function getTaskDiv() {
  188 + $sId = $this->getId();
  189 + $sStatus = $this->getStatus();
  190 +
  191 + $sDiv = "<span id='font{$sId}' ";
  192 + $sDiv .= ($sStatus != 'disabled') ? 'class="">' : 'class="descriptiveText">';
  193 + $sDiv .= $this->getTask().'</span>';
  194 + return $sDiv;
  195 + }
  196 +
  197 + function getFreqDiv() {
  198 + $sId = $this->getId();
  199 + $sStatus = $this->getStatus();
  200 + $sFreqs = $this->getFrequencyByLang();
  201 +
  202 + $sLink = "<a href='#' id='freqDrop{$sId}' onclick='javascript: showFrequencyDiv(\"{$sId}\");'";
  203 + $sLink .= ($sStatus == 'disabled') ? 'style="visibility: hidden;" >' : '>';
  204 + $sLink .= "<div id='div{$sId}'>$sFreqs</div></a>";
  205 + return $sLink;
  206 + }
  207 +
  208 + /**
178 209 * Get a link to alter the frequency of a task
179 210 */
180 211 function getAlterFreqLink() {
181 212 $sId = $this->getId();
182   - $sLink = "<a href='#' onclick='javascript: showFrequencyDiv({$sId});'>"._kt('Alter frequency')."</a>";
  213 + $sStatus = $this->getStatus();
  214 +
  215 + $sLink = "<a href='#' id='freqLink{$this->getId()}' onclick='javascript: showFrequencyDiv({$sId});'";
  216 + $sLink .= ($sStatus == 'disabled') ? 'style="visibility: hidden;" >' : '>';
  217 + $sLink .= _kt('Alter frequency')."</a>";
183 218 return $sLink;
184 219 }
185 220  
... ... @@ -188,9 +223,33 @@ class schedulerEntity extends KTEntity
188 223 */
189 224 function getRunNowLink() {
190 225 $sId = $this->getId();
  226 + $sStatus = $this->getStatus();
191 227 $sUrl = KTUtil::ktLink('admin.php', 'misc/scheduler', 'action=updateRunTime');
192   - $sLink = "<a href='#' onclick='javascript: runOnNext(\"{$sId}\", \"{$sUrl}\");'>"._kt('Run on next iteration')."</a>";
  228 +
  229 + $sLink = "<a href='#' id='runnowLink{$this->getId()}' onclick='javascript: runOnNext(\"{$sId}\", \"{$sUrl}\");'";
  230 + $sLink .= ($sStatus == 'disabled') ? 'style="visibility: hidden;" >' : '>';
  231 + $sLink .= _kt('Run on next iteration')."</a>";
  232 + return $sLink;
  233 + }
  234 +
  235 + /**
  236 + * Run the task on the next iteration
  237 + */
  238 + function getStatusLink() {
  239 + $sId = $this->getId();
  240 + $sStatus = $this->getStatus();
  241 + if($sStatus == 'system'){
  242 + return '';
  243 + }
  244 +
  245 + $sDisableText = _kt('Disable task');
  246 + $sEnableText = _kt('Enable task');
  247 +
  248 + $sLinkText = ($sStatus == 'enabled') ? $sDisableText : $sEnableText;
  249 + $sUrl = KTUtil::ktLink('admin.php', 'misc/scheduler', 'action=updateStatus');
  250 + $sLink = "<a id='statusLink{$this->getId()}' href='#'
  251 + onclick='javascript: toggleStatus(\"{$sId}\", \"{$sUrl}\", \"{$sDisableText}\", \"{$sEnableText}\");'>{$sLinkText}</a>";
193 252 return $sLink;
194 253 }
195 254 }
196 255 -?>
  256 +?>
197 257 \ No newline at end of file
... ...
plugins/ktcore/scheduler/schedulerUtil.php
... ... @@ -77,7 +77,7 @@ class schedulerUtil extends KTUtil
77 77 /**
78 78 * Method to register a task in the schedule
79 79 */
80   - function registerTask($sTask, $sUrl, $aParams, $sFreq, $iStartTime = NULL) {
  80 + function registerTask($sTask, $sUrl, $aParams, $sFreq, $iStartTime = NULL, $sStatus = 'disabled') {
81 81 // Run task on next iteration if no start time given
82 82 $iStartTime = (!empty($iStartTime)) ? strtotime($iStartTime) : time();
83 83  
... ... @@ -101,6 +101,7 @@ class schedulerUtil extends KTUtil
101 101 $aTask['run_time'] = $dNextTime;
102 102 $aTask['previous_run_time'] = $dStartTime;
103 103 $aTask['run_duration'] = '0';
  104 + $sTask['status'] = $sStatus;
104 105  
105 106 $oEntity = schedulerEntity::createFromArray($aTask);
106 107 if (PEAR::isError($oEntity)){
... ... @@ -127,6 +128,7 @@ class schedulerUtil extends KTUtil
127 128 $aTask['is_complete'] = '0';
128 129 $aTask['run_time'] = date('Y-m-d H:i:s');
129 130 $aTask['run_duration'] = '0';
  131 + $aTask['status'] = 'enabled';
130 132  
131 133 $oEntity = schedulerEntity::createFromArray($aTask);
132 134 if (PEAR::isError($oEntity)){
... ... @@ -232,6 +234,29 @@ class schedulerUtil extends KTUtil
232 234 }
233 235  
234 236 /**
  237 + * Toggle whether a task is enabled or disabled. If its a system task, then ignore.
  238 + */
  239 + function toggleStatus($id) {
  240 + $oScheduler = schedulerEntity::get($id);
  241 +
  242 + if (PEAR::isError($oScheduler)){
  243 + return _kt('Object can\'t be created');
  244 + }
  245 +
  246 + $sStatus = $oScheduler->getStatus();
  247 +
  248 + if($sStatus == 'system'){
  249 + // ignore
  250 + return $sStatus;
  251 + }
  252 +
  253 + $sNewStatus = ($sStatus == 'enabled') ? 'disabled' : 'enabled';
  254 + $oScheduler->setStatus($sNewStatus);
  255 + $oScheduler->update();
  256 + return $sNewStatus;
  257 + }
  258 +
  259 + /**
235 260 * Check the last run time of the scheduler
236 261 */
237 262 function checkLastRunTime() {
... ...
plugins/ktcore/scheduler/taskScheduler.php
... ... @@ -120,5 +120,13 @@ class manageSchedulerDispatcher extends KTAdminDispatcher
120 120 schedulerUtil::updateRunTime($id, $iNextTime);
121 121 return $iNextTime;
122 122 }
  123 +
  124 + /**
  125 + * Toggle the enable/disable on the task
  126 + */
  127 + function do_updateStatus() {
  128 + $fId = schedulerUtil::arrayGet($_REQUEST, 'fId');
  129 + schedulerUtil::toggleStatus($fId);
  130 + }
123 131 }
124 132 ?>
... ...
resources/js/scheduler.js
... ... @@ -28,6 +28,38 @@ var runOnNext = function(fId, sUrl) {
28 28 var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, "fId="+fId);
29 29 }
30 30  
  31 +//<!-- Enable / disable the task -->
  32 +var toggleStatus = function(fId, sUrl, sDisableText, sEnableText) {
  33 +
  34 + var statusLink = document.getElementById('statusLink'+fId);
  35 + var freqLink = document.getElementById('freqLink'+fId);
  36 + var runnowLink = document.getElementById('runnowLink'+fId);
  37 + var freqDrop = document.getElementById('freqDrop'+fId);
  38 + var fontClass = document.getElementById('font'+fId);
  39 + var freqDiv = document.getElementById('div'+fId);
  40 +
  41 + var callback = {
  42 + success: function(o) {
  43 + if(statusLink.innerHTML == sDisableText){
  44 + statusLink.innerHTML = sEnableText;
  45 + freqLink.style.visibility = "hidden";
  46 + runnowLink.style.visibility = "hidden";
  47 + freqDrop.style.visibility = "hidden";
  48 + fontClass.className = 'descriptiveText';
  49 + freqDiv.style.display = "none";
  50 + }else{
  51 + statusLink.innerHTML = sDisableText;
  52 + freqLink.style.visibility = "visible";
  53 + runnowLink.style.visibility = "visible";
  54 + freqDrop.style.visibility = "visible";
  55 + freqDiv.style.display = "block";
  56 + fontClass.className = '';
  57 + }
  58 + }
  59 + }
  60 + var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, "fId="+fId);
  61 +}
  62 +
31 63 var showFrequencyDiv = function(fId) {
32 64 var formDiv = document.getElementById('formDiv');
33 65 var fInput = document.getElementById('fId');
... ...
templates/ktcore/dashlets/scheduler.smarty
... ... @@ -5,7 +5,7 @@
5 5 {else}
6 6 <span class="descriptiveText">{i18n}No tasks have been run yet.{/i18n}</span>
7 7 {/if}
8   -&nbsp;<span><a href="{$sAdmin}">Administration page</a></span>
  8 +&nbsp;<span class="descriptiveText">{i18n arg_link=$sAdminLink}This can be configured via the #link#.{/i18n}</span>
9 9  
10 10 <p>
11 11 {if !$lasttime}
... ...
templates/ktcore/scheduler.smarty
... ... @@ -28,15 +28,13 @@
28 28  
29 29 <tr class="{cycle name=rows values=",odd"}">
30 30 <td width='2%'>
31   - {$i++}
  31 + {$i++}
32 32 </td>
33 33 <td>
34   - {$task->getTask()}
  34 + {$task->getTaskDiv()}
35 35 </td>
36   - <td id="tblCol"><a href="#" onclick="javascript: showFrequencyDiv('{$task->getId()}');">
37   - <div id="div{$task->getId()}">
38   - {$task->getFrequencyByLang()}
39   - </div></a>
  36 + <td id="tblCol">
  37 + {$task->getFreqDiv()}
40 38 </td>
41 39 <td>
42 40 <div id="runDiv{$task->getId()}">
... ... @@ -49,11 +47,11 @@
49 47 </div>
50 48 {$task->getPrevious(TRUE)}
51 49 </td>
52   - <td>
  50 + <td width="10%">
53 51 {$task->getRunDuration()}
54 52 </td>
55 53 <td>
56   - {$task->getAlterFreqLink()}&nbsp;&nbsp;{$task->getRunNowLink()}
  54 + {$task->getAlterFreqLink()}&nbsp;&nbsp;{$task->getRunNowLink()}&nbsp;&nbsp;{$task->getStatusLink()}
57 55 </td>
58 56 </tr>
59 57  
... ... @@ -70,7 +68,7 @@
70 68  
71 69 <div id="formDiv" style="display: none; visibility: hidden;">
72 70 <form name="changefreq" id="changefreq" method="post" action="{$sUrl}">
73   -
  71 +
74 72 <select name="frequency" id="frequency">
75 73 {html_options options=$aFrequencies}
76 74 </select>
... ...