Commit 3cfd1245319f385226d37e402632d3981b8f16e3

Authored by megan_w
1 parent 13ba214c

KTS-3381

"Two workflows with the same name can be created"
Fixed. The copy now outputs an error if the same name (with or without spaces) is used.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen




git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/branches/3.5.2c-Release-Branch@8511 c91229c3-7414-0410-bfa2-8a42b809f60b
plugins/ktcore/admin/workflowsv2.php
1 <?php 1 <?php
2 /** 2 /**
3 * $Id$ 3 * $Id$
4 - * 4 + *
5 * KnowledgeTree Open Source Edition 5 * KnowledgeTree Open Source Edition
6 * Document Management Made Simple 6 * Document Management Made Simple
7 * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited 7 * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
8 - * 8 + *
9 * This program is free software; you can redistribute it and/or modify it under 9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 3 as published by the 10 * the terms of the GNU General Public License version 3 as published by the
11 * Free Software Foundation. 11 * Free Software Foundation.
12 - * 12 + *
13 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * details. 16 * details.
17 - * 17 + *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 - * 20 + *
21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23 - * 23 + *
24 * The interactive user interfaces in modified source and object code versions 24 * The interactive user interfaces in modified source and object code versions
25 * of this program must display Appropriate Legal Notices, as required under 25 * of this program must display Appropriate Legal Notices, as required under
26 * Section 5 of the GNU General Public License version 3. 26 * Section 5 of the GNU General Public License version 3.
27 - * 27 + *
28 * In accordance with Section 7(b) of the GNU General Public License version 3, 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 * these Appropriate Legal Notices must retain the display of the "Powered by 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 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices 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 * Contributor( s): ______________________________________ 34 * Contributor( s): ______________________________________
35 */ 35 */
36 36
37 // core 37 // core
38 require_once(KT_LIB_DIR . "/dispatcher.inc.php"); 38 require_once(KT_LIB_DIR . "/dispatcher.inc.php");
39 39
40 -// workflow 40 +// workflow
41 require_once(KT_LIB_DIR . '/workflow/workflow.inc.php'); 41 require_once(KT_LIB_DIR . '/workflow/workflow.inc.php');
42 require_once(KT_LIB_DIR . '/workflow/workflowstate.inc.php'); 42 require_once(KT_LIB_DIR . '/workflow/workflowstate.inc.php');
43 require_once(KT_LIB_DIR . '/workflow/workflowtransition.inc.php'); 43 require_once(KT_LIB_DIR . '/workflow/workflowtransition.inc.php');
@@ -56,11 +56,11 @@ require_once(KT_LIB_DIR . &#39;/widgets/portlet.inc.php&#39;); @@ -56,11 +56,11 @@ require_once(KT_LIB_DIR . &#39;/widgets/portlet.inc.php&#39;);
56 require_once(KT_LIB_DIR . '/widgets/forms.inc.php'); 56 require_once(KT_LIB_DIR . '/widgets/forms.inc.php');
57 //require_once(KT_DIR . "/thirdparty/pear/GraphViz.php"); 57 //require_once(KT_DIR . "/thirdparty/pear/GraphViz.php");
58 58
59 -class WorkflowNavigationPortlet extends KTPortlet { 59 +class WorkflowNavigationPortlet extends KTPortlet {
60 var $oWorkflow; 60 var $oWorkflow;
61 var $sHelpPage = 'ktcore/admin/workflow.html'; 61 var $sHelpPage = 'ktcore/admin/workflow.html';
62 var $bActive = true; 62 var $bActive = true;
63 - 63 +
64 function WorkflowNavigationPortlet($sTitle, $oWorkflow = null) { 64 function WorkflowNavigationPortlet($sTitle, $oWorkflow = null) {
65 $this->oWorkflow = $oWorkflow; 65 $this->oWorkflow = $oWorkflow;
66 parent::KTPortlet($sTitle); 66 parent::KTPortlet($sTitle);
@@ -68,22 +68,22 @@ class WorkflowNavigationPortlet extends KTPortlet { @@ -68,22 +68,22 @@ class WorkflowNavigationPortlet extends KTPortlet {
68 68
69 function render() { 69 function render() {
70 if (is_null($this->oWorkflow)) { return _kt('No Workflow Selected.'); } 70 if (is_null($this->oWorkflow)) { return _kt('No Workflow Selected.'); }
71 - 71 +
72 $aAdminPages = array(); 72 $aAdminPages = array();
73 $aAdminPages[] = array('name' => _kt('Overview'), 'query' => 'action=view&fWorkflowId=' . $this->oWorkflow->getId()); 73 $aAdminPages[] = array('name' => _kt('Overview'), 'query' => 'action=view&fWorkflowId=' . $this->oWorkflow->getId());
74 $aAdminPages[] = array('name' => _kt('States and Transitions'), 'query' => 'action=basic&fWorkflowId=' . $this->oWorkflow->getId()); 74 $aAdminPages[] = array('name' => _kt('States and Transitions'), 'query' => 'action=basic&fWorkflowId=' . $this->oWorkflow->getId());
75 $aAdminPages[] = array('name' => _kt('Security'), 'query' => 'action=security&fWorkflowId=' . $this->oWorkflow->getId()); 75 $aAdminPages[] = array('name' => _kt('Security'), 'query' => 'action=security&fWorkflowId=' . $this->oWorkflow->getId());
76 $aAdminPages[] = array('name' => _kt('Workflow Effects'), 'query' => 'action=effects&fWorkflowId=' . $this->oWorkflow->getId()); 76 $aAdminPages[] = array('name' => _kt('Workflow Effects'), 'query' => 'action=effects&fWorkflowId=' . $this->oWorkflow->getId());
77 - $aAdminPages[] = array('name' => _kt('Select different workflow'), 'query' => 'action=main');  
78 -  
79 - $oTemplating =& KTTemplating::getSingleton(); 77 + $aAdminPages[] = array('name' => _kt('Select different workflow'), 'query' => 'action=main');
  78 +
  79 + $oTemplating =& KTTemplating::getSingleton();
80 $oTemplate = $oTemplating->loadTemplate("ktcore/workflow/admin_portlet"); 80 $oTemplate = $oTemplating->loadTemplate("ktcore/workflow/admin_portlet");
81 $aTemplateData = array( 81 $aTemplateData = array(
82 "context" => $this, 82 "context" => $this,
83 "aAdminPages" => $aAdminPages, 83 "aAdminPages" => $aAdminPages,
84 ); 84 );
85 85
86 - return $oTemplate->render($aTemplateData); 86 + return $oTemplate->render($aTemplateData);
87 } 87 }
88 } 88 }
89 89
@@ -94,47 +94,47 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -94,47 +94,47 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
94 var $HAVE_GRAPHVIZ; 94 var $HAVE_GRAPHVIZ;
95 95
96 function predispatch() { 96 function predispatch() {
97 - $this->persistParams(array('fWorkflowId', 'fStateId', 'fTransitionId'));  
98 - 97 + $this->persistParams(array('fWorkflowId', 'fStateId', 'fTransitionId'));
  98 +
99 $iWorkflowId = KTUtil::arrayGet($_REQUEST, 'fWorkflowId'); 99 $iWorkflowId = KTUtil::arrayGet($_REQUEST, 'fWorkflowId');
100 $iStateId = KTUtil::arrayGet($_REQUEST, 'fStateId'); 100 $iStateId = KTUtil::arrayGet($_REQUEST, 'fStateId');
101 - $iTransitionId = KTUtil::arrayGet($_REQUEST, 'fTransitionId');  
102 - 101 + $iTransitionId = KTUtil::arrayGet($_REQUEST, 'fTransitionId');
  102 +
103 if (!is_null($iWorkflowId)) { 103 if (!is_null($iWorkflowId)) {
104 $oWorkflow =& KTWorkflow::get($iWorkflowId); 104 $oWorkflow =& KTWorkflow::get($iWorkflowId);
105 if (!PEAR::isError($oWorkflow)) { 105 if (!PEAR::isError($oWorkflow)) {
106 $this->oWorkflow =& $oWorkflow; 106 $this->oWorkflow =& $oWorkflow;
107 } 107 }
108 } 108 }
109 - 109 +
110 if (!is_null($iStateId)) { 110 if (!is_null($iStateId)) {
111 $oState =& KTWorkflowState::get($iStateId); 111 $oState =& KTWorkflowState::get($iStateId);
112 if (!PEAR::isError($oState)) { 112 if (!PEAR::isError($oState)) {
113 $this->oState =& $oState; 113 $this->oState =& $oState;
114 } 114 }
115 } 115 }
116 - 116 +
117 if (!is_null($iTransitionId)) { 117 if (!is_null($iTransitionId)) {
118 $oTransition =& KTWorkflowTransition::get($iTransitionId); 118 $oTransition =& KTWorkflowTransition::get($iTransitionId);
119 if (!PEAR::isError($oTransition)) { 119 if (!PEAR::isError($oTransition)) {
120 $this->oTransition =& $oTransition; 120 $this->oTransition =& $oTransition;
121 } 121 }
122 } 122 }
123 - 123 +
124 $this->aBreadcrumbs[] = array( 124 $this->aBreadcrumbs[] = array(
125 'url' => $_SERVER['PHP_SELF'], 125 'url' => $_SERVER['PHP_SELF'],
126 'name' => _kt('Workflows'), 126 'name' => _kt('Workflows'),
127 ); 127 );
128 - 128 +
129 if (!is_null($this->oWorkflow)) { 129 if (!is_null($this->oWorkflow)) {
130 $this->oPage->addPortlet(new WorkflowNavigationPortlet(_kt("Workflow Administration"), $this->oWorkflow)); 130 $this->oPage->addPortlet(new WorkflowNavigationPortlet(_kt("Workflow Administration"), $this->oWorkflow));
131 - 131 +
132 $this->aBreadcrumbs[] = array( 132 $this->aBreadcrumbs[] = array(
133 'url' => KTUtil::addQueryStringSelf(sprintf('action=view&fWorkflowId=%d', $iWorkflowId)), 133 'url' => KTUtil::addQueryStringSelf(sprintf('action=view&fWorkflowId=%d', $iWorkflowId)),
134 'name' => $this->oWorkflow->getName(), 134 'name' => $this->oWorkflow->getName(),
135 - ); 135 + );
136 } 136 }
137 - 137 +
138 $this->HAVE_GRAPHVIZ = false; 138 $this->HAVE_GRAPHVIZ = false;
139 /* $dotCommand = KTUtil::findCommand("ui/dot", 'dot'); 139 /* $dotCommand = KTUtil::findCommand("ui/dot", 'dot');
140 if (!empty($dotCommand)) { 140 if (!empty($dotCommand)) {
@@ -146,16 +146,16 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -146,16 +146,16 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
146 146
147 function do_main() { 147 function do_main() {
148 $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/list'); 148 $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/list');
149 - 149 +
150 $aWorkflows = KTWorkflow::getList(); 150 $aWorkflows = KTWorkflow::getList();
151 - 151 +
152 $oTemplate->setData(array( 152 $oTemplate->setData(array(
153 'context' => $this, 153 'context' => $this,
154 'workflows' => $aWorkflows, 154 'workflows' => $aWorkflows,
155 )); 155 ));
156 return $oTemplate->render(); 156 return $oTemplate->render();
157 } 157 }
158 - 158 +
159 function do_branchConfirm() { 159 function do_branchConfirm() {
160 $submit = KTUtil::arrayGet($_REQUEST, 'submit' , array()); 160 $submit = KTUtil::arrayGet($_REQUEST, 'submit' , array());
161 if (array_key_exists('copy',$submit)) { 161 if (array_key_exists('copy',$submit)) {
@@ -174,29 +174,37 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -174,29 +174,37 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
174 } 174 }
175 $this->errorRedirectToMain(_kt('No action specified.')); 175 $this->errorRedirectToMain(_kt('No action specified.'));
176 } 176 }
177 - 177 +
178 function do_copy() { 178 function do_copy() {
179 - $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Copy Workflow')); 179 + $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Copy Workflow'));
180 $selection = KTUtil::arrayGet($_REQUEST, 'workflowSelect' , array()); 180 $selection = KTUtil::arrayGet($_REQUEST, 'workflowSelect' , array());
181 $this->oPage->setTitle('Copy Workflow'); 181 $this->oPage->setTitle('Copy Workflow');
182 - 182 +
183 // get selected workflow from database 183 // get selected workflow from database
184 $oSelWorkflow = KTWorkflow::get($selection); 184 $oSelWorkflow = KTWorkflow::get($selection);
185 - 185 +
186 $oTemplating =& KTTemplating::getSingleton(); 186 $oTemplating =& KTTemplating::getSingleton();
187 $oTemplate = $oTemplating->loadTemplate('ktcore/workflow/admin/copy'); 187 $oTemplate = $oTemplating->loadTemplate('ktcore/workflow/admin/copy');
188 $oTemplate->setData(array( 188 $oTemplate->setData(array(
189 'context' => $this, 189 'context' => $this,
190 'workFlowName' => $oSelWorkflow->getName(), 190 'workFlowName' => $oSelWorkflow->getName(),
191 'workFlowId' => $oSelWorkflow->getId(), 191 'workFlowId' => $oSelWorkflow->getId(),
192 - 192 +
193 )); 193 ));
194 return $oTemplate; 194 return $oTemplate;
195 } 195 }
196 -  
197 - function do_confirmCopy(){ 196 +
  197 + function do_confirmCopy(){
198 $oSelWorkflow = KTWorkflow::get(KTUtil::arrayGet($_REQUEST, 'workflowId' , array())); 198 $oSelWorkflow = KTWorkflow::get(KTUtil::arrayGet($_REQUEST, 'workflowId' , array()));
199 $sWorkflowName = KTUtil::arrayGet($_REQUEST, 'workflowName' , array()); 199 $sWorkflowName = KTUtil::arrayGet($_REQUEST, 'workflowName' , array());
  200 +
  201 + // Check that the workflow does not exist already
  202 + $sWorkflowName = str_replace(array(' ', ' '), array(' ', ' '), $sWorkflowName);
  203 + $oWorkflow = KTWorkflow::getByName($sWorkflowName);
  204 + if (!PEAR::isError($oWorkflow)) {
  205 + return $this->errorRedirectToMain(_kt("A workflow with that name already exists. Please choose a different name for this workflow."));
  206 + }
  207 +
200 // create the initial workflow 208 // create the initial workflow
201 $oNewWorkflow = KTWorkflow::createFromArray(array( 209 $oNewWorkflow = KTWorkflow::createFromArray(array(
202 'name' => $sWorkflowName, 210 'name' => $sWorkflowName,
@@ -206,10 +214,10 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -206,10 +214,10 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
206 214
207 // get selected workflow states from database 215 // get selected workflow states from database
208 $oSelWorkflowStates = KTWorkflowState::getByWorkflow($oSelWorkflow); 216 $oSelWorkflowStates = KTWorkflowState::getByWorkflow($oSelWorkflow);
209 - 217 +
210 // array to store map of old and new states 218 // array to store map of old and new states
211 $aStatesMap = array(); 219 $aStatesMap = array();
212 - 220 +
213 // create new states and build old-to-new map 221 // create new states and build old-to-new map
214 foreach ($oSelWorkflowStates as $oOldState) { 222 foreach ($oSelWorkflowStates as $oOldState) {
215 $oNewState = KTWorkflowState::createFromArray(array( 223 $oNewState = KTWorkflowState::createFromArray(array(
@@ -222,7 +230,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -222,7 +230,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
222 if (PEAR::isError($oNewState)) { 230 if (PEAR::isError($oNewState)) {
223 $oForm->errorRedirectToMain(sprintf(_kt("Unexpected failure cloning state: %s"), $oNewState->getMessage())); 231 $oForm->errorRedirectToMain(sprintf(_kt("Unexpected failure cloning state: %s"), $oNewState->getMessage()));
224 } 232 }
225 - 233 +
226 // Get all state permission assignments for old workflow transitions and copy for copied workflow state permission assignments 234 // Get all state permission assignments for old workflow transitions and copy for copied workflow state permission assignments
227 $aPermissionAssignments = KTWorkflowStatePermissionAssignment::getByState($oOldState); 235 $aPermissionAssignments = KTWorkflowStatePermissionAssignment::getByState($oOldState);
228 if(count($aPermissionAssignments) > 0){ 236 if(count($aPermissionAssignments) > 0){
@@ -230,13 +238,13 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -230,13 +238,13 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
230 for($i=0;$i<count($aStatesMap[oldId]);$i++){ 238 for($i=0;$i<count($aStatesMap[oldId]);$i++){
231 if($aStatesMap[oldId][$i] == $oPermAssign->getStateId()){ 239 if($aStatesMap[oldId][$i] == $oPermAssign->getStateId()){
232 $iStateId = $aStatesMap[newId][$i]; 240 $iStateId = $aStatesMap[newId][$i];
233 - 241 +
234 $res = KTWorkflowStatePermissionAssignment::createFromArray(array( 242 $res = KTWorkflowStatePermissionAssignment::createFromArray(array(
235 'iStateId' => $iStateId, 243 'iStateId' => $iStateId,
236 'iPermissionId' => $oPermAssign->getPermissionId(), 244 'iPermissionId' => $oPermAssign->getPermissionId(),
237 'iDescriptorId' => $oPermAssign->getDescriptorId(), 245 'iDescriptorId' => $oPermAssign->getDescriptorId(),
238 )); 246 ));
239 - 247 +
240 if (PEAR::isError($res)) { 248 if (PEAR::isError($res)) {
241 return $this->errorRedirectToMain(sprintf(_kt("Unable to copy state permission assignment: %s"), $res->getMessage())); 249 return $this->errorRedirectToMain(sprintf(_kt("Unable to copy state permission assignment: %s"), $res->getMessage()));
242 } 250 }
@@ -244,21 +252,21 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -244,21 +252,21 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
244 } 252 }
245 } 253 }
246 } 254 }
247 - 255 +
248 // Copy all disabled actions for states 256 // Copy all disabled actions for states
249 $aDisabled = KTWorkflowUtil::getDisabledActionsForState($oOldState); 257 $aDisabled = KTWorkflowUtil::getDisabledActionsForState($oOldState);
250 $res = KTWorkflowUtil::setDisabledActionsForState($oNewState, $aDisabled); 258 $res = KTWorkflowUtil::setDisabledActionsForState($oNewState, $aDisabled);
251 - 259 +
252 // Copy all enabled actions for states 260 // Copy all enabled actions for states
253 $aDisabled = KTWorkflowUtil::getEnabledActionsForState($oOldState); 261 $aDisabled = KTWorkflowUtil::getEnabledActionsForState($oOldState);
254 $res = KTWorkflowUtil::setEnabledActionsForState($oNewState, $aDisabled); 262 $res = KTWorkflowUtil::setEnabledActionsForState($oNewState, $aDisabled);
255 - 263 +
256 if (PEAR::isError($res)) { 264 if (PEAR::isError($res)) {
257 return $this->errorRedirectToMain(sprintf(_kt("Unable to copy disabled state actions: %s"), $res->getMessage())); 265 return $this->errorRedirectToMain(sprintf(_kt("Unable to copy disabled state actions: %s"), $res->getMessage()));
258 } 266 }
259 } 267 }
260 -  
261 - // update workflow and set initial state 268 +
  269 + // update workflow and set initial state
262 for($i=0;$i<count($aStatesMap[oldId]);$i++){ 270 for($i=0;$i<count($aStatesMap[oldId]);$i++){
263 if($oSelWorkflow->getStartStateId() == $aStatesMap[oldId][$i]){ 271 if($oSelWorkflow->getStartStateId() == $aStatesMap[oldId][$i]){
264 $oNewWorkflow->setStartStateId($aStatesMap[newId][$i]); 272 $oNewWorkflow->setStartStateId($aStatesMap[newId][$i]);
@@ -268,20 +276,20 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -268,20 +276,20 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
268 } 276 }
269 } 277 }
270 } 278 }
271 - 279 +
272 // set controlled workflow actions 280 // set controlled workflow actions
273 $aWFActions = KTWorkflowUtil::getControlledActionsForWorkflow($oSelWorkflow); 281 $aWFActions = KTWorkflowUtil::getControlledActionsForWorkflow($oSelWorkflow);
274 $res = KTWorkflowUtil::setControlledActionsForWorkflow($oNewWorkflow, $aWFActions); 282 $res = KTWorkflowUtil::setControlledActionsForWorkflow($oNewWorkflow, $aWFActions);
275 if (PEAR::isError($res)) { 283 if (PEAR::isError($res)) {
276 $this->errorRedirectToMain(sprintf(_kt("Failed to copy workflow controlled actions: %s"), $res->getMessage())); 284 $this->errorRedirectToMain(sprintf(_kt("Failed to copy workflow controlled actions: %s"), $res->getMessage()));
277 } 285 }
278 - 286 +
279 // get selected workflow transitions from database 287 // get selected workflow transitions from database
280 $oSelWorkflowTransitions = KTWorkflowTransition::getByWorkflow($oSelWorkflow); 288 $oSelWorkflowTransitions = KTWorkflowTransition::getByWorkflow($oSelWorkflow);
281 - 289 +
282 // array to store map of old and new transitions 290 // array to store map of old and new transitions
283 $aTransitionsMap = array(); 291 $aTransitionsMap = array();
284 - 292 +
285 // copy transitions for workflow 293 // copy transitions for workflow
286 foreach ($oSelWorkflowTransitions as $oOldTransition) { 294 foreach ($oSelWorkflowTransitions as $oOldTransition) {
287 for($i=0;$i<count($aStatesMap[oldId]);$i++){ 295 for($i=0;$i<count($aStatesMap[oldId]);$i++){
@@ -297,16 +305,16 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -297,16 +305,16 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
297 'GuardPermissionId' => null, 305 'GuardPermissionId' => null,
298 'GuardGroupId' => null, 306 'GuardGroupId' => null,
299 'GuardRoleId' => null, 307 'GuardRoleId' => null,
300 - 'GuardConditionId' => null, 308 + 'GuardConditionId' => null,
301 )); 309 ));
302 - 310 +
303 $aTransitionsMap[oldId][] = $oOldTransition->getId(); 311 $aTransitionsMap[oldId][] = $oOldTransition->getId();
304 $aTransitionsMap[newId][] = $oNewTransition->getId(); 312 $aTransitionsMap[newId][] = $oNewTransition->getId();
305 - 313 +
306 if (PEAR::isError($oNewTransition)) { 314 if (PEAR::isError($oNewTransition)) {
307 - $this->errorRedirectToMain(sprintf(_kt("Failed to copy transition: %s"), $oTransition->getMessage())); 315 + $this->errorRedirectToMain(sprintf(_kt("Failed to copy transition: %s"), $oTransition->getMessage()));
308 } 316 }
309 - 317 +
310 // map source transitions onto states 318 // map source transitions onto states
311 $aOldTransitionSources = KTWorkflowAdminUtil::getSourceStates($oOldTransition); 319 $aOldTransitionSources = KTWorkflowAdminUtil::getSourceStates($oOldTransition);
312 $aSourceStates = array(); 320 $aSourceStates = array();
@@ -320,23 +328,23 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -320,23 +328,23 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
320 } 328 }
321 $res = KTWorkflowAdminUtil::saveTransitionSources($oNewTransition, $aSourceStates); 329 $res = KTWorkflowAdminUtil::saveTransitionSources($oNewTransition, $aSourceStates);
322 if (PEAR::isError($res)) { 330 if (PEAR::isError($res)) {
323 - $this->errorRedirectToMain(sprintf(_kt("Failed to set transition origins: %s"), $res->getMessage())); 331 + $this->errorRedirectToMain(sprintf(_kt("Failed to set transition origins: %s"), $res->getMessage()));
324 } 332 }
325 -  
326 - // Get all triggers for old workflow transitions and copy for copied workflow transitions 333 +
  334 + // Get all triggers for old workflow transitions and copy for copied workflow transitions
327 $aTriggers = KTWorkflowTriggerInstance::getByTransition($oOldTransition); 335 $aTriggers = KTWorkflowTriggerInstance::getByTransition($oOldTransition);
328 if(count($aTriggers) > 0){ 336 if(count($aTriggers) > 0){
329 foreach ($aTriggers as $oTrigger) { 337 foreach ($aTriggers as $oTrigger) {
330 for($i=0;$i<count($aTransitionsMap[oldId]);$i++){ 338 for($i=0;$i<count($aTransitionsMap[oldId]);$i++){
331 if($aTransitionsMap[oldId][$i] == $oTrigger->getTransitionId()){ 339 if($aTransitionsMap[oldId][$i] == $oTrigger->getTransitionId()){
332 $iTransitionId = $aTransitionsMap[newId][$i]; 340 $iTransitionId = $aTransitionsMap[newId][$i];
333 - 341 +
334 $res = KTWorkflowTriggerInstance::createFromArray(array( 342 $res = KTWorkflowTriggerInstance::createFromArray(array(
335 'transitionid' => $iTransitionId, 343 'transitionid' => $iTransitionId,
336 'namespace' => $oTrigger->getNamespace(), 344 'namespace' => $oTrigger->getNamespace(),
337 'config' => $oTrigger->getConfigArrayText(), 345 'config' => $oTrigger->getConfigArrayText(),
338 )); 346 ));
339 - 347 +
340 if (PEAR::isError($res)) { 348 if (PEAR::isError($res)) {
341 return $this->errorRedirectToMain(sprintf(_kt("Unable to add trigger: %s"), $res->getMessage())); 349 return $this->errorRedirectToMain(sprintf(_kt("Unable to add trigger: %s"), $res->getMessage()));
342 } 350 }
@@ -347,24 +355,24 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -347,24 +355,24 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
347 } 355 }
348 return $this->successRedirectToMain(sprintf(_kt("%s successfully copied as %s"), $oSelWorkflow->getName(), $oNewWorkflow->getName())); 356 return $this->successRedirectToMain(sprintf(_kt("%s successfully copied as %s"), $oSelWorkflow->getName(), $oNewWorkflow->getName()));
349 } 357 }
350 - 358 +
351 function do_newWorkflow() { 359 function do_newWorkflow() {
352 // subdispatch this to the NewWorkflowWizard. 360 // subdispatch this to the NewWorkflowWizard.
353 require_once(dirname(__FILE__) . '/workflow/newworkflow.inc.php'); 361 require_once(dirname(__FILE__) . '/workflow/newworkflow.inc.php');
354 - 362 +
355 $oSubDispatcher =& new KTNewWorkflowWizard; 363 $oSubDispatcher =& new KTNewWorkflowWizard;
356 $oSubDispatcher->redispatch('wizard', null, $this); 364 $oSubDispatcher->redispatch('wizard', null, $this);
357 exit(0); 365 exit(0);
358 } 366 }
359 - 367 +
360 // -------------------- Overview ----------------- 368 // -------------------- Overview -----------------
361 // basic view page. 369 // basic view page.
362 370
363 function do_view() { 371 function do_view() {
364 - $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/view');  
365 - 372 + $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/view');
  373 +
366 $this->oPage->setBreadcrumbDetails(_kt("Overview")); 374 $this->oPage->setBreadcrumbDetails(_kt("Overview"));
367 - 375 +
368 if (!$this->oWorkflow->getIsEnabled()) { 376 if (!$this->oWorkflow->getIsEnabled()) {
369 $this->addInfoMessage(_kt("This workflow is currently marked as disabled. No new documents can be assigned to this workflow until it is enabled. To change this, please edit the workflow's base properties.")); 377 $this->addInfoMessage(_kt("This workflow is currently marked as disabled. No new documents can be assigned to this workflow until it is enabled. To change this, please edit the workflow's base properties."));
370 } 378 }
@@ -372,34 +380,34 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -372,34 +380,34 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
372 if ($this->oWorkflow->getStartStateId() == false) { 380 if ($this->oWorkflow->getStartStateId() == false) {
373 $this->addErrorMessage(_kt("No start state is specified for this workflow. No new documents can be assigned to this workflow until one is assigned. To change this, please edit the workflow's base properties.")); 381 $this->addErrorMessage(_kt("No start state is specified for this workflow. No new documents can be assigned to this workflow until one is assigned. To change this, please edit the workflow's base properties."));
374 } 382 }
375 - 383 +
376 // for the basic view 384 // for the basic view
377 $start_state_id = $this->oWorkflow->getStartStateId(); 385 $start_state_id = $this->oWorkflow->getStartStateId();
378 $oState = KTWorkflowState::get($start_state_id); 386 $oState = KTWorkflowState::get($start_state_id);
379 387
380 if (PEAR::isError($oState)) { 388 if (PEAR::isError($oState)) {
381 - $state_name = _kt('No starting state.'); 389 + $state_name = _kt('No starting state.');
382 } else { 390 } else {
383 $state_name = $oState->getName(); 391 $state_name = $oState->getName();
384 } 392 }
385 - 393 +
386 // we want to "outsource" some of the analysis 394 // we want to "outsource" some of the analysis
387 - 395 +
388 if ($this->HAVE_GRAPHVIZ) { 396 if ($this->HAVE_GRAPHVIZ) {
389 - $graph_data = $this->get_graph($this->oWorkflow); 397 + $graph_data = $this->get_graph($this->oWorkflow);
390 if (!empty($graph_data['errors'])) { 398 if (!empty($graph_data['errors'])) {
391 foreach ($graph_data['errors'] as $error) { 399 foreach ($graph_data['errors'] as $error) {
392 $this->addErrorMessage($error); 400 $this->addErrorMessage($error);
393 } 401 }
394 } 402 }
395 - 403 +
396 if (!empty($graph_data['info'])) { 404 if (!empty($graph_data['info'])) {
397 foreach ($graph_data['info'] as $info) { 405 foreach ($graph_data['info'] as $info) {
398 $this->addInfoMessage($info); 406 $this->addInfoMessage($info);
399 } 407 }
400 } 408 }
401 } 409 }
402 - 410 +
403 $oTemplate->setData(array( 411 $oTemplate->setData(array(
404 'context' => $this, 412 'context' => $this,
405 'workflow_name' => $this->oWorkflow->getName(), 413 'workflow_name' => $this->oWorkflow->getName(),
@@ -409,26 +417,26 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -409,26 +417,26 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
409 )); 417 ));
410 return $oTemplate->render(); 418 return $oTemplate->render();
411 } 419 }
412 - 420 +
413 function form_coreedit() { 421 function form_coreedit() {
414 $oForm = new KTForm; 422 $oForm = new KTForm;
415 - 423 +
416 $oForm->setOptions(array( 424 $oForm->setOptions(array(
417 'context' => $this, 425 'context' => $this,
418 'action' => 'setcore', 426 'action' => 'setcore',
419 'fail_action' => 'editcore', 427 'fail_action' => 'editcore',
420 - 'cancel_action' => 'view', 428 + 'cancel_action' => 'view',
421 'label' => _kt('Edit Workflow Details'), 429 'label' => _kt('Edit Workflow Details'),
422 'submit_label' => _kt('Update Workflow Details'), 430 'submit_label' => _kt('Update Workflow Details'),
423 )); 431 ));
424 - 432 +
425 $oForm->setWidgets(array( 433 $oForm->setWidgets(array(
426 array('ktcore.widgets.string',array( 434 array('ktcore.widgets.string',array(
427 'label' => _kt("Workflow Name"), 435 'label' => _kt("Workflow Name"),
428 - 'description' => _kt("Each workflow must have a unique name."), 436 + 'description' => _kt("Each workflow must have a unique name."),
429 'name' => 'workflow_name', 437 'name' => 'workflow_name',
430 - 'required' => true,  
431 - 'value' => sanitizeForHTML($this->oWorkflow->getName()), 438 + 'required' => true,
  439 + 'value' => sanitizeForHTML($this->oWorkflow->getName()),
432 )), 440 )),
433 array('ktcore.widgets.entityselection', array( 441 array('ktcore.widgets.entityselection', array(
434 'label' => _kt("Starting State"), 442 'label' => _kt("Starting State"),
@@ -446,7 +454,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -446,7 +454,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
446 'value' => $this->oWorkflow->getIsEnabled(), 454 'value' => $this->oWorkflow->getIsEnabled(),
447 )), 455 )),
448 )); 456 ));
449 - 457 +
450 $oForm->setValidators(array( 458 $oForm->setValidators(array(
451 array('ktcore.validators.string', array( 459 array('ktcore.validators.string', array(
452 'test' => 'workflow_name', 460 'test' => 'workflow_name',
@@ -460,90 +468,90 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -460,90 +468,90 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
460 array('ktcore.validators.boolean', array( 468 array('ktcore.validators.boolean', array(
461 'test' => 'enabled', 469 'test' => 'enabled',
462 'output' => 'enabled', 470 'output' => 'enabled',
463 - )) 471 + ))
464 )); 472 ));
465 - 473 +
466 return $oForm; 474 return $oForm;
467 } 475 }
468 - 476 +
469 function do_editcore() { 477 function do_editcore() {
470 478
471 - $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/edit_core'); 479 + $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/edit_core');
472 $this->oPage->setBreadcrumbDetails(_kt("Edit Details")); 480 $this->oPage->setBreadcrumbDetails(_kt("Edit Details"));
473 481
474 - $oForm = $this->form_coreedit();  
475 - 482 + $oForm = $this->form_coreedit();
  483 +
476 $oTemplate->setData(array( 484 $oTemplate->setData(array(
477 'context' => $this, 485 'context' => $this,
478 'workflow_name' => $this->oWorkflow->getName(), 486 'workflow_name' => $this->oWorkflow->getName(),
479 'edit_form' => $oForm, 487 'edit_form' => $oForm,
480 )); 488 ));
481 - return $oTemplate->render(); 489 + return $oTemplate->render();
482 } 490 }
483 - 491 +
484 function do_setcore() { 492 function do_setcore() {
485 - $oForm = $this->form_coreedit(); 493 + $oForm = $this->form_coreedit();
486 $res = $oForm->validate(); 494 $res = $oForm->validate();
487 $data = $res['results']; 495 $data = $res['results'];
488 $errors = $res['errors']; 496 $errors = $res['errors'];
489 if (!empty($errors)) { 497 if (!empty($errors)) {
490 $oForm->handleError(); 498 $oForm->handleError();
491 } 499 }
492 - 500 +
493 $this->startTransaction(); 501 $this->startTransaction();
494 $this->oWorkflow->setName($data['workflow_name']); 502 $this->oWorkflow->setName($data['workflow_name']);
495 - $this->oWorkflow->setHumanName($data['workflow_name']);  
496 - $this->oWorkflow->setStartStateId($data['start_state']->getId());  
497 - $this->oWorkflow->setIsEnabled($data['enabled']); 503 + $this->oWorkflow->setHumanName($data['workflow_name']);
  504 + $this->oWorkflow->setStartStateId($data['start_state']->getId());
  505 + $this->oWorkflow->setIsEnabled($data['enabled']);
498 $res = $this->oWorkflow->update(); 506 $res = $this->oWorkflow->update();
499 if (PEAR::isError($res)) { 507 if (PEAR::isError($res)) {
500 $oForm->handleError(sprintf(_kt("Failed to update workflow: %s"), $res->getMessage())); 508 $oForm->handleError(sprintf(_kt("Failed to update workflow: %s"), $res->getMessage()));
501 } 509 }
502 - 510 +
503 $this->successRedirectTo("view",_kt("Workflow updated.")); 511 $this->successRedirectTo("view",_kt("Workflow updated."));
504 } 512 }
505 - 513 +
506 // ----------------- Basic - States & Transition --------------------- 514 // ----------------- Basic - States & Transition ---------------------
507 function breadcrumbs_basic() { 515 function breadcrumbs_basic() {
508 $this->aBreadcrumbs[] = array( 516 $this->aBreadcrumbs[] = array(
509 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("", "basic")), 517 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("", "basic")),
510 'name' => _kt("States and Transitions"), 518 'name' => _kt("States and Transitions"),
511 - ); 519 + );
512 } 520 }
513 - 521 +
514 function do_basic() { 522 function do_basic() {
515 - $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/basic_overview'); 523 + $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/basic_overview');
516 $this->breadcrumbs_basic(); 524 $this->breadcrumbs_basic();
517 $this->oPage->setBreadcrumbDetails(_kt("Overview")); 525 $this->oPage->setBreadcrumbDetails(_kt("Overview"));
518 - 526 +
519 $aStates = KTWorkflowState::getByWorkflow($this->oWorkflow); 527 $aStates = KTWorkflowState::getByWorkflow($this->oWorkflow);
520 - $aTransitions = KTWorkflowTransition::getByWorkflow($this->oWorkflow);  
521 - 528 + $aTransitions = KTWorkflowTransition::getByWorkflow($this->oWorkflow);
  529 +
522 530
523 if ($this->HAVE_GRAPHVIZ) { 531 if ($this->HAVE_GRAPHVIZ) {
524 - $graph_data = $this->get_graph($this->oWorkflow); 532 + $graph_data = $this->get_graph($this->oWorkflow);
525 if (!empty($graph_data['errors'])) { 533 if (!empty($graph_data['errors'])) {
526 foreach ($graph_data['errors'] as $error) { 534 foreach ($graph_data['errors'] as $error) {
527 $this->addErrorMessage($error); 535 $this->addErrorMessage($error);
528 } 536 }
529 } 537 }
530 - 538 +
531 if (!empty($graph_data['info'])) { 539 if (!empty($graph_data['info'])) {
532 foreach ($graph_data['info'] as $info) { 540 foreach ($graph_data['info'] as $info) {
533 $this->addInfoMessage($info); 541 $this->addInfoMessage($info);
534 } 542 }
535 } 543 }
536 } 544 }
537 - 545 +
538 $oTemplate->setData(array( 546 $oTemplate->setData(array(
539 'context' => $this, 547 'context' => $this,
540 'workflow_name' => $this->oWorkflow->getName(), 548 'workflow_name' => $this->oWorkflow->getName(),
541 'states' => $aStates, 549 'states' => $aStates,
542 'transitions' => $aTransitions, 550 'transitions' => $aTransitions,
543 )); 551 ));
544 - return $oTemplate->render();  
545 - }  
546 - 552 + return $oTemplate->render();
  553 + }
  554 +
547 function form_transitionconnections() { 555 function form_transitionconnections() {
548 $oForm = new KTForm; 556 $oForm = new KTForm;
549 $oForm->setOptions(array( 557 $oForm->setOptions(array(
@@ -555,21 +563,21 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -555,21 +563,21 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
555 'fail_action' => 'transitionconnections', // consistency - this is not really used. 563 'fail_action' => 'transitionconnections', // consistency - this is not really used.
556 'context' => $this, 564 'context' => $this,
557 )); 565 ));
558 - 566 +
559 return $oForm; 567 return $oForm;
560 } 568 }
561 - 569 +
562 function do_transitionconnections() { 570 function do_transitionconnections() {
563 // we don't use a traditional form here, since the grid is too complex 571 // we don't use a traditional form here, since the grid is too complex
564 // and its essentially one-shot. 572 // and its essentially one-shot.
565 - // 573 + //
566 // 574 //
567 $oForm = $this->form_transitionconnections(); 575 $oForm = $this->form_transitionconnections();
568 $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/configure_process'); 576 $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/configure_process');
569 - 577 +
570 $this->breadcrumbs_basic(); 578 $this->breadcrumbs_basic();
571 $this->oPage->setBreadcrumbDetails(_kt("Edit Transition Connections")); 579 $this->oPage->setBreadcrumbDetails(_kt("Edit Transition Connections"));
572 - 580 +
573 // we want to re-use this for *subsets*. 581 // we want to re-use this for *subsets*.
574 $transition_ids = KTUtil::arrayGet($_REQUEST, 'transition_ids'); 582 $transition_ids = KTUtil::arrayGet($_REQUEST, 'transition_ids');
575 $bRestrict = is_array($transition_ids); 583 $bRestrict = is_array($transition_ids);
@@ -584,65 +592,65 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -584,65 +592,65 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
584 continue; 592 continue;
585 } 593 }
586 } 594 }
587 - 595 +
588 $sources = KTWorkflowAdminUtil::getSourceStates($oTransition, array('ids' => true)); 596 $sources = KTWorkflowAdminUtil::getSourceStates($oTransition, array('ids' => true));
589 $aSources = array(); 597 $aSources = array();
590 foreach ($sources as $source) { $aSources[$source] = $source; } 598 foreach ($sources as $source) { $aSources[$source] = $source; }
591 $availability[$oTransition->getId()] = $aSources; 599 $availability[$oTransition->getId()] = $aSources;
592 } 600 }
593 -  
594 - 601 +
  602 +
595 if ($bRestrict) { 603 if ($bRestrict) {
596 $transitions = $final_transitions; 604 $transitions = $final_transitions;
597 } 605 }
598 - 606 +
599 607
600 if ($this->HAVE_GRAPHVIZ) { 608 if ($this->HAVE_GRAPHVIZ) {
601 - $graph_data = $this->get_graph($this->oWorkflow); 609 + $graph_data = $this->get_graph($this->oWorkflow);
602 if (!empty($graph_data['errors'])) { 610 if (!empty($graph_data['errors'])) {
603 foreach ($graph_data['errors'] as $error) { 611 foreach ($graph_data['errors'] as $error) {
604 $this->addErrorMessage($error); 612 $this->addErrorMessage($error);
605 } 613 }
606 } 614 }
607 - 615 +
608 if (!empty($graph_data['info'])) { 616 if (!empty($graph_data['info'])) {
609 foreach ($graph_data['info'] as $info) { 617 foreach ($graph_data['info'] as $info) {
610 $this->addInfoMessage($info); 618 $this->addInfoMessage($info);
611 } 619 }
612 } 620 }
613 - }  
614 - 621 + }
  622 +
615 $oTemplate->setData(array( 623 $oTemplate->setData(array(
616 'context' => $this, 624 'context' => $this,
617 'form' => $oForm, 625 'form' => $oForm,
618 'states' => KTWorkflowState::getByWorkflow($this->oWorkflow), 626 'states' => KTWorkflowState::getByWorkflow($this->oWorkflow),
619 'transitions' => $transitions, 627 'transitions' => $transitions,
620 'availability' => $availability, 628 'availability' => $availability,
621 - ));  
622 - 629 + ));
  630 +
623 return $oTemplate->render(); 631 return $oTemplate->render();
624 } 632 }
625 - 633 +
626 function do_setconnections() { 634 function do_setconnections() {
627 - // we *must* ensure that transitions are not set to originate from their 635 + // we *must* ensure that transitions are not set to originate from their
628 // destination. 636 // destination.
629 - // 637 + //
630 // we can ignore it here, because its dealt with in workflowadminutil 638 // we can ignore it here, because its dealt with in workflowadminutil
631 - 639 +
632 $to = (array) KTUtil::arrayGet($_REQUEST, 'fTo'); 640 $to = (array) KTUtil::arrayGet($_REQUEST, 'fTo');
633 $from = (array) KTUtil::arrayGet($_REQUEST, 'fFrom'); 641 $from = (array) KTUtil::arrayGet($_REQUEST, 'fFrom');
634 642
635 // we do not trust any of this data. 643 // we do not trust any of this data.
636 $states = KTWorkflowState::getByWorkflow($this->oWorkflow); 644 $states = KTWorkflowState::getByWorkflow($this->oWorkflow);
637 $states = KTUtil::keyArray($states); 645 $states = KTUtil::keyArray($states);
638 - $transitions = KTWorkflowTransition::getByWorkflow($this->oWorkflow); 646 + $transitions = KTWorkflowTransition::getByWorkflow($this->oWorkflow);
639 647
640 $this->startTransaction(); 648 $this->startTransaction();
641 649
642 foreach ($transitions as $oTransition) { 650 foreach ($transitions as $oTransition) {
643 $dest_id = $to[$oTransition->getId()]; 651 $dest_id = $to[$oTransition->getId()];
644 $oDestState = $states[$dest_id]; 652 $oDestState = $states[$dest_id];
645 - 653 +
646 if (!is_null($oDestState)) { 654 if (!is_null($oDestState)) {
647 $oTransition->setTargetStateId($dest_id); 655 $oTransition->setTargetStateId($dest_id);
648 $res = $oTransition->update(); 656 $res = $oTransition->update();
@@ -650,7 +658,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -650,7 +658,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
650 $this->errorRedirectTo('basic', sprintf(_kt("Unexpected error updating transition: %s"), $res->getMessage())); 658 $this->errorRedirectTo('basic', sprintf(_kt("Unexpected error updating transition: %s"), $res->getMessage()));
651 } 659 }
652 } 660 }
653 - 661 +
654 // hook up source states. 662 // hook up source states.
655 $source_state_ids = array(); 663 $source_state_ids = array();
656 $sources = (array) $from[$oTransition->getId()]; 664 $sources = (array) $from[$oTransition->getId()];
@@ -658,11 +666,11 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -658,11 +666,11 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
658 foreach ($sources as $state_id => $discard) { 666 foreach ($sources as $state_id => $discard) {
659 // test existence 667 // test existence
660 $oState = $states[$state_id]; 668 $oState = $states[$state_id];
661 - if (!is_null($oState) && ($dest_id != $state_id)) { 669 + if (!is_null($oState) && ($dest_id != $state_id)) {
662 $source_state_ids[] = $oState->getId(); 670 $source_state_ids[] = $oState->getId();
663 - } 671 + }
664 } 672 }
665 - 673 +
666 $aFromTransitionID = array_keys($_REQUEST['fFrom']); 674 $aFromTransitionID = array_keys($_REQUEST['fFrom']);
667 //run through all transitions to change 675 //run through all transitions to change
668 foreach ($aFromTransitionID as $iCurrentId) 676 foreach ($aFromTransitionID as $iCurrentId)
@@ -673,13 +681,13 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -673,13 +681,13 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
673 } 681 }
674 } 682 }
675 if (PEAR::isError($res)) { 683 if (PEAR::isError($res)) {
676 - $this->errorRedirectTo('basic', sprintf(_kt("Failed to set transition origins: %s"), $res->getMessage())); 684 + $this->errorRedirectTo('basic', sprintf(_kt("Failed to set transition origins: %s"), $res->getMessage()));
677 } 685 }
678 - }  
679 - 686 + }
  687 +
680 $this->successRedirectTo('basic', _kt("Workflow process updated.")); 688 $this->successRedirectTo('basic', _kt("Workflow process updated."));
681 } 689 }
682 - 690 +
683 function form_addstates() { 691 function form_addstates() {
684 $oForm = new KTForm; 692 $oForm = new KTForm;
685 $oForm->setOptions(array( 693 $oForm->setOptions(array(
@@ -690,7 +698,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -690,7 +698,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
690 'cancel_action' => 'basic', 698 'cancel_action' => 'basic',
691 'fail_action' => 'addstates', 699 'fail_action' => 'addstates',
692 )); 700 ));
693 - 701 +
694 $oForm->setWidgets(array( 702 $oForm->setWidgets(array(
695 array('ktcore.widgets.text',array( 703 array('ktcore.widgets.text',array(
696 'label' => _kt('New States'), 704 'label' => _kt('New States'),
@@ -705,17 +713,17 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -705,17 +713,17 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
705 array('ktcore.validators.string', array( 713 array('ktcore.validators.string', array(
706 'test' => 'states', 714 'test' => 'states',
707 'output' => 'states', 715 'output' => 'states',
708 - 'max_length' => 9999, 716 + 'max_length' => 9999,
709 )), 717 )),
710 )); 718 ));
711 - 719 +
712 return $oForm; 720 return $oForm;
713 } 721 }
714 - 722 +
715 function do_addstates() { 723 function do_addstates() {
716 $oForm = $this->form_addstates(); 724 $oForm = $this->form_addstates();
717 - $this->breadcrumbs_basic();  
718 - $this->oPage->setBreadcrumbDetails(_kt("Add States")); 725 + $this->breadcrumbs_basic();
  726 + $this->oPage->setBreadcrumbDetails(_kt("Add States"));
719 $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/add_states'); 727 $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/add_states');
720 $oTemplate->setData(array( 728 $oTemplate->setData(array(
721 'context' => $this, 729 'context' => $this,
@@ -723,16 +731,16 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -723,16 +731,16 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
723 )); 731 ));
724 return $oTemplate->render(); 732 return $oTemplate->render();
725 } 733 }
726 - 734 +
727 function do_createstates() { 735 function do_createstates() {
728 $oForm = $this->form_addstates(); 736 $oForm = $this->form_addstates();
729 $res = $oForm->validate(); 737 $res = $oForm->validate();
730 $data = $res['results']; 738 $data = $res['results'];
731 $errors = $res['errors']; 739 $errors = $res['errors'];
732 $extra_errors = array(); 740 $extra_errors = array();
733 - 741 +
734 // we want to check for duplicates, empties, etc. 742 // we want to check for duplicates, empties, etc.
735 - 743 +
736 $initial_states = (array) explode("\n", $data['states']); 744 $initial_states = (array) explode("\n", $data['states']);
737 $failed = array(); 745 $failed = array();
738 $old_states = array(); 746 $old_states = array();
@@ -742,35 +750,35 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -742,35 +750,35 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
742 if (empty($state_name)) { 750 if (empty($state_name)) {
743 continue; 751 continue;
744 } 752 }
745 - 753 +
746 if ($states[$state_name]) { 754 if ($states[$state_name]) {
747 $failed[] = $state_name; 755 $failed[] = $state_name;
748 continue; 756 continue;
749 } 757 }
750 - 758 +
751 // check for pre-existing states. 759 // check for pre-existing states.
752 $exists = KTWorkflowState::nameExists($sName, $this->oWorkflow); 760 $exists = KTWorkflowState::nameExists($sName, $this->oWorkflow);
753 if ($exists) { 761 if ($exists) {
754 $old_states[] = $sName; 762 $old_states[] = $sName;
755 } 763 }
756 - 764 +
757 $states[$state_name] = $state_name; 765 $states[$state_name] = $state_name;
758 } 766 }
759 if (empty($states)) { 767 if (empty($states)) {
760 $extra_errors['states'][] = _kt('You must provide at least one state name.'); 768 $extra_errors['states'][] = _kt('You must provide at least one state name.');
761 } 769 }
762 if (!empty($failed)) { 770 if (!empty($failed)) {
763 - $extra_errors['states'][] = sprintf(_kt("You cannot have duplicate state names: %s"), implode(', ', $failed)); 771 + $extra_errors['states'][] = sprintf(_kt("You cannot have duplicate state names: %s"), implode(', ', $failed));
764 } 772 }
765 if (!empty($old_states)) { 773 if (!empty($old_states)) {
766 - $extra_errors['states'][] = sprintf(_kt("You cannot use state names that are in use: %s"), implode(', ', $old_states)); 774 + $extra_errors['states'][] = sprintf(_kt("You cannot use state names that are in use: %s"), implode(', ', $old_states));
767 } 775 }
768 - 776 +
769 // handle any errors. 777 // handle any errors.
770 if (!empty($errors) || !empty($extra_errors)) { 778 if (!empty($errors) || !empty($extra_errors)) {
771 $oForm->handleError(null, $extra_errors); 779 $oForm->handleError(null, $extra_errors);
772 } 780 }
773 - 781 +
774 $this->startTransaction(); 782 $this->startTransaction();
775 // now act 783 // now act
776 foreach ($states as $state_name) { 784 foreach ($states as $state_name) {
@@ -783,11 +791,11 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -783,11 +791,11 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
783 $oForm->handleError(sprintf(_kt("Unexpected failure creating state: %s"), $oState->getMessage())); 791 $oForm->handleError(sprintf(_kt("Unexpected failure creating state: %s"), $oState->getMessage()));
784 } 792 }
785 } 793 }
786 - 794 +
787 $this->successRedirectTo('basic', _kt("New States Created.")); 795 $this->successRedirectTo('basic', _kt("New States Created."));
788 } 796 }
789 -  
790 - 797 +
  798 +
791 function form_addtransitions() { 799 function form_addtransitions() {
792 $oForm = new KTForm; 800 $oForm = new KTForm;
793 $oForm->setOptions(array( 801 $oForm->setOptions(array(
@@ -798,7 +806,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -798,7 +806,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
798 'cancel_action' => 'basic', 806 'cancel_action' => 'basic',
799 'fail_action' => 'addtransitions', 807 'fail_action' => 'addtransitions',
800 )); 808 ));
801 - 809 +
802 $oForm->setWidgets(array( 810 $oForm->setWidgets(array(
803 array('ktcore.widgets.text',array( 811 array('ktcore.widgets.text',array(
804 'label' => _kt('Transitions'), 812 'label' => _kt('Transitions'),
@@ -806,23 +814,23 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -806,23 +814,23 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
806 'important_description' => _kt('Please enter a list of transitions, one per line. Transition names must be unique.'), 814 'important_description' => _kt('Please enter a list of transitions, one per line. Transition names must be unique.'),
807 'required' => false, 815 'required' => false,
808 'name' => 'transitions', 816 'name' => 'transitions',
809 - )), 817 + )),
810 )); 818 ));
811 $oForm->setValidators(array( 819 $oForm->setValidators(array(
812 array('ktcore.validators.string', array( 820 array('ktcore.validators.string', array(
813 'test' => 'transitions', 821 'test' => 'transitions',
814 'output' => 'transitions', 822 'output' => 'transitions',
815 - 'max_length' => 9999, 823 + 'max_length' => 9999,
816 )), 824 )),
817 )); 825 ));
818 - 826 +
819 return $oForm; 827 return $oForm;
820 } 828 }
821 - 829 +
822 function do_addtransitions() { 830 function do_addtransitions() {
823 $oForm = $this->form_addtransitions(); 831 $oForm = $this->form_addtransitions();
824 - $this->breadcrumbs_basic();  
825 - $this->oPage->setBreadcrumbDetails(_kt("Add Transitions")); 832 + $this->breadcrumbs_basic();
  833 + $this->oPage->setBreadcrumbDetails(_kt("Add Transitions"));
826 $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/add_transitions'); 834 $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/add_transitions');
827 $oTemplate->setData(array( 835 $oTemplate->setData(array(
828 'context' => $this, 836 'context' => $this,
@@ -830,16 +838,16 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -830,16 +838,16 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
830 )); 838 ));
831 return $oTemplate->render(); 839 return $oTemplate->render();
832 } 840 }
833 - 841 +
834 function do_createtransitions() { 842 function do_createtransitions() {
835 $oForm = $this->form_addtransitions(); 843 $oForm = $this->form_addtransitions();
836 $res = $oForm->validate(); 844 $res = $oForm->validate();
837 $data = $res['results']; 845 $data = $res['results'];
838 $errors = $res['errors']; 846 $errors = $res['errors'];
839 $extra_errors = array(); 847 $extra_errors = array();
840 - 848 +
841 // we want to check for duplicates, empties, etc. 849 // we want to check for duplicates, empties, etc.
842 - 850 +
843 $initial_transitions = (array) explode("\n", $data['transitions']); 851 $initial_transitions = (array) explode("\n", $data['transitions']);
844 $failed = array(); 852 $failed = array();
845 $old_transitions = array(); 853 $old_transitions = array();
@@ -849,35 +857,35 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -849,35 +857,35 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
849 if (empty($transition_name)) { 857 if (empty($transition_name)) {
850 continue; 858 continue;
851 } 859 }
852 - 860 +
853 if ($transitions[$transition_name]) { 861 if ($transitions[$transition_name]) {
854 $failed[] = $transition_name; 862 $failed[] = $transition_name;
855 continue; 863 continue;
856 } 864 }
857 - 865 +
858 // check for pre-existing states. 866 // check for pre-existing states.
859 $exists = KTWorkflowTransition::nameExists($sName, $this->oWorkflow); 867 $exists = KTWorkflowTransition::nameExists($sName, $this->oWorkflow);
860 if ($exists) { 868 if ($exists) {
861 $old_transitions[] = $sName; 869 $old_transitions[] = $sName;
862 } 870 }
863 - 871 +
864 $transitions[$transition_name] = $transition_name; 872 $transitions[$transition_name] = $transition_name;
865 } 873 }
866 if (empty($transitions)) { 874 if (empty($transitions)) {
867 $extra_errors['transitions'][] = _kt('You must provide at least one transition name.'); 875 $extra_errors['transitions'][] = _kt('You must provide at least one transition name.');
868 } 876 }
869 if (!empty($failed)) { 877 if (!empty($failed)) {
870 - $extra_errors['transitions'][] = sprintf(_kt("You cannot have duplicate transition names: %s"), implode(', ', $failed)); 878 + $extra_errors['transitions'][] = sprintf(_kt("You cannot have duplicate transition names: %s"), implode(', ', $failed));
871 } 879 }
872 if (!empty($old_states)) { 880 if (!empty($old_states)) {
873 - $extra_errors['transitions'][] = sprintf(_kt("You cannot use transition names that are in use: %s"), implode(', ', $old_transitions)); 881 + $extra_errors['transitions'][] = sprintf(_kt("You cannot use transition names that are in use: %s"), implode(', ', $old_transitions));
874 } 882 }
875 - 883 +
876 // handle any errors. 884 // handle any errors.
877 if (!empty($errors) || !empty($extra_errors)) { 885 if (!empty($errors) || !empty($extra_errors)) {
878 $oForm->handleError(null, $extra_errors); 886 $oForm->handleError(null, $extra_errors);
879 } 887 }
880 - 888 +
881 $this->startTransaction(); 889 $this->startTransaction();
882 $transition_ids = array(); 890 $transition_ids = array();
883 $oState = KTWorkflowState::get($this->oWorkflow->getStartStateId()); 891 $oState = KTWorkflowState::get($this->oWorkflow->getStartStateId());
@@ -890,26 +898,26 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -890,26 +898,26 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
890 "GuardPermissionId" => null, 898 "GuardPermissionId" => null,
891 "GuardGroupId" => null, 899 "GuardGroupId" => null,
892 "GuardRoleId" => null, 900 "GuardRoleId" => null,
893 - "GuardConditionId" => null, 901 + "GuardConditionId" => null,
894 )); 902 ));
895 if (PEAR::isError($oTransition)) { 903 if (PEAR::isError($oTransition)) {
896 $oForm->handleError(sprintf(_kt("Unexpected failure creating transition: %s"), $oTransition->getMessage())); 904 $oForm->handleError(sprintf(_kt("Unexpected failure creating transition: %s"), $oTransition->getMessage()));
897 } 905 }
898 $transition_ids[] = $oTransition->getId(); 906 $transition_ids[] = $oTransition->getId();
899 } 907 }
900 - 908 +
901 $transition_ids_query = array(); 909 $transition_ids_query = array();
902 foreach ($transition_ids as $id) { 910 foreach ($transition_ids as $id) {
903 $transition_ids_query[] = sprintf('transition_ids[%s]=%s',$id, $id); 911 $transition_ids_query[] = sprintf('transition_ids[%s]=%s',$id, $id);
904 } 912 }
905 $transition_ids_query = implode('&', $transition_ids_query); 913 $transition_ids_query = implode('&', $transition_ids_query);
906 - 914 +
907 $this->successRedirectTo('transitionconnections', _kt("New Transitions Created."), $transition_ids_query); 915 $this->successRedirectTo('transitionconnections', _kt("New Transitions Created."), $transition_ids_query);
908 } 916 }
909 - 917 +
910 function form_editstate($oState) { 918 function form_editstate($oState) {
911 $oForm = new KTForm; 919 $oForm = new KTForm;
912 - 920 +
913 $oForm->setOptions(array( 921 $oForm->setOptions(array(
914 'context' => $this, 922 'context' => $this,
915 'label' => _kt('Edit State'), 923 'label' => _kt('Edit State'),
@@ -918,7 +926,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -918,7 +926,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
918 'fail_action' => 'editstate', 926 'fail_action' => 'editstate',
919 'cancel_action' => 'basic', 927 'cancel_action' => 'basic',
920 )); 928 ));
921 - 929 +
922 $oForm->setWidgets(array( 930 $oForm->setWidgets(array(
923 array('ktcore.widgets.string', array( 931 array('ktcore.widgets.string', array(
924 'name' => 'name', 932 'name' => 'name',
@@ -928,79 +936,79 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -928,79 +936,79 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
928 'value' => sanitizeForHTML($oState->getName()), 936 'value' => sanitizeForHTML($oState->getName()),
929 )), 937 )),
930 )); 938 ));
931 - 939 +
932 $oForm->setValidators(array( 940 $oForm->setValidators(array(
933 array('ktcore.validators.string', array( 941 array('ktcore.validators.string', array(
934 'test' => 'name', 942 'test' => 'name',
935 'output' => 'name', 943 'output' => 'name',
936 )), 944 )),
937 )); 945 ));
938 - 946 +
939 return $oForm; 947 return $oForm;
940 } 948 }
941 - 949 +
942 function do_editstate() { 950 function do_editstate() {
943 $this->aBreadcrumbs[] = array( 951 $this->aBreadcrumbs[] = array(
944 'name' => $this->oState->getHumanName(), 952 'name' => $this->oState->getHumanName(),
945 - );  
946 - 953 + );
  954 +
947 // remember that we check for state, 955 // remember that we check for state,
948 // and its null if none or an error was passed. 956 // and its null if none or an error was passed.
949 if (is_null($this->oState)) { 957 if (is_null($this->oState)) {
950 $this->errorRedirectTo('basic', _kt("No state specified.")); 958 $this->errorRedirectTo('basic', _kt("No state specified."));
951 } 959 }
952 - 960 +
953 $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/admin/edit_state'); 961 $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/admin/edit_state');
954 $this->oPage->setBreadcrumbDetails(_kt('Manage State')); 962 $this->oPage->setBreadcrumbDetails(_kt('Manage State'));
955 - 963 +
956 $oForm = $this->form_editstate($this->oState); 964 $oForm = $this->form_editstate($this->oState);
957 - 965 +
958 $oTemplate->setData(array( 966 $oTemplate->setData(array(
959 'context' => $this, 967 'context' => $this,
960 - 'edit_form' => $oForm, 968 + 'edit_form' => $oForm,
961 )); 969 ));
962 - 970 +
963 return $oTemplate->render(); 971 return $oTemplate->render();
964 } 972 }
965 - 973 +
966 function do_savestate() { 974 function do_savestate() {
967 $oForm = $this->form_editstate($this->oState); 975 $oForm = $this->form_editstate($this->oState);
968 $res = $oForm->validate(); 976 $res = $oForm->validate();
969 $data = $res['results']; 977 $data = $res['results'];
970 $errors = $res['errors']; 978 $errors = $res['errors'];
971 $extra_errors = array(); 979 $extra_errors = array();
972 - 980 +
973 // check if any *other* states have this name. 981 // check if any *other* states have this name.
974 if ($data['name'] == $this->oState->getName()) { 982 if ($data['name'] == $this->oState->getName()) {
975 $this->successRedirectTo('editstate',_kt("No change in name.")); 983 $this->successRedirectTo('editstate',_kt("No change in name."));
976 - }  
977 - 984 + }
  985 +
978 // otherwise we're looking for something different if there's a conflict. 986 // otherwise we're looking for something different if there's a conflict.
979 - 987 +
980 if (KTWorkflowState::nameExists($data['name'], $this->oWorkflow)) { 988 if (KTWorkflowState::nameExists($data['name'], $this->oWorkflow)) {
981 $extra_errors['name'][] = _kt('There is already a state with that name in this workflow.'); 989 $extra_errors['name'][] = _kt('There is already a state with that name in this workflow.');
982 } 990 }
983 - 991 +
984 if (!empty($errors) || !empty($extra_errors)) { 992 if (!empty($errors) || !empty($extra_errors)) {
985 $oForm->handleError(null, $extra_errors); 993 $oForm->handleError(null, $extra_errors);
986 } 994 }
987 - 995 +
988 $this->startTransaction(); 996 $this->startTransaction();
989 - 997 +
990 $this->oState->setName($data['name']); 998 $this->oState->setName($data['name']);
991 - $this->oState->setHumanName($data['name']); 999 + $this->oState->setHumanName($data['name']);
992 $res = $this->oState->update(); 1000 $res = $this->oState->update();
993 - 1001 +
994 if (PEAR::isError($res)) { 1002 if (PEAR::isError($res)) {
995 $oForm->handleError(sprintf(_kt("Unable to update state: %s"), $res->getMessage())); 1003 $oForm->handleError(sprintf(_kt("Unable to update state: %s"), $res->getMessage()));
996 } 1004 }
997 - 1005 +
998 $this->successRedirectTo('basic', _kt("State updated.")); 1006 $this->successRedirectTo('basic', _kt("State updated."));
999 } 1007 }
1000 - 1008 +
1001 function form_edittransition($oTransition) { 1009 function form_edittransition($oTransition) {
1002 $oForm = new KTForm; 1010 $oForm = new KTForm;
1003 - 1011 +
1004 $oForm->setOptions(array( 1012 $oForm->setOptions(array(
1005 'context' => $this, 1013 'context' => $this,
1006 'label' => _kt('Edit Transition'), 1014 'label' => _kt('Edit Transition'),
@@ -1009,7 +1017,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1009,7 +1017,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1009 'fail_action' => 'edittransition', 1017 'fail_action' => 'edittransition',
1010 'cancel_action' => 'basic', 1018 'cancel_action' => 'basic',
1011 )); 1019 ));
1012 - 1020 +
1013 $oForm->setWidgets(array( 1021 $oForm->setWidgets(array(
1014 array('ktcore.widgets.string', array( 1022 array('ktcore.widgets.string', array(
1015 'name' => 'name', 1023 'name' => 'name',
@@ -1019,100 +1027,100 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1019,100 +1027,100 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1019 'value' => sanitizeForHTML($oTransition->getName()), 1027 'value' => sanitizeForHTML($oTransition->getName()),
1020 )), 1028 )),
1021 )); 1029 ));
1022 - 1030 +
1023 $oForm->setValidators(array( 1031 $oForm->setValidators(array(
1024 array('ktcore.validators.string', array( 1032 array('ktcore.validators.string', array(
1025 'test' => 'name', 1033 'test' => 'name',
1026 'output' => 'name', 1034 'output' => 'name',
1027 )), 1035 )),
1028 )); 1036 ));
1029 - 1037 +
1030 return $oForm; 1038 return $oForm;
1031 } 1039 }
1032 - 1040 +
1033 function do_edittransition() { 1041 function do_edittransition() {
1034 $this->aBreadcrumbs[] = array( 1042 $this->aBreadcrumbs[] = array(
1035 'name' => $this->oTransition->getHumanName(), 1043 'name' => $this->oTransition->getHumanName(),
1036 ); 1044 );
1037 - 1045 +
1038 // remember that we check for state, 1046 // remember that we check for state,
1039 // and its null if none or an error was passed. 1047 // and its null if none or an error was passed.
1040 if (is_null($this->oTransition)) { 1048 if (is_null($this->oTransition)) {
1041 $this->errorRedirectTo('basic', _kt("No transition specified.")); 1049 $this->errorRedirectTo('basic', _kt("No transition specified."));
1042 } 1050 }
1043 - 1051 +
1044 $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/admin/edit_transition'); 1052 $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/admin/edit_transition');
1045 $this->oPage->setBreadcrumbDetails(_kt('Manage Transition')); 1053 $this->oPage->setBreadcrumbDetails(_kt('Manage Transition'));
1046 - 1054 +
1047 $oForm = $this->form_edittransition($this->oTransition); 1055 $oForm = $this->form_edittransition($this->oTransition);
1048 - 1056 +
1049 $oTemplate->setData(array( 1057 $oTemplate->setData(array(
1050 'context' => $this, 1058 'context' => $this,
1051 - 'edit_form' => $oForm, 1059 + 'edit_form' => $oForm,
1052 )); 1060 ));
1053 - 1061 +
1054 return $oTemplate->render(); 1062 return $oTemplate->render();
1055 } 1063 }
1056 - 1064 +
1057 function do_savetransition() { 1065 function do_savetransition() {
1058 $oForm = $this->form_edittransition($this->oTransition); 1066 $oForm = $this->form_edittransition($this->oTransition);
1059 $res = $oForm->validate(); 1067 $res = $oForm->validate();
1060 $data = $res['results']; 1068 $data = $res['results'];
1061 $errors = $res['errors']; 1069 $errors = $res['errors'];
1062 $extra_errors = array(); 1070 $extra_errors = array();
1063 - 1071 +
1064 // check if any *other* states have this name. 1072 // check if any *other* states have this name.
1065 if ($data['name'] == $this->oTransition->getName()) { 1073 if ($data['name'] == $this->oTransition->getName()) {
1066 $this->successRedirectTo('edittransition',_kt("No change in name.")); 1074 $this->successRedirectTo('edittransition',_kt("No change in name."));
1067 - }  
1068 - 1075 + }
  1076 +
1069 // otherwise we're looking for something different if there's a conflict. 1077 // otherwise we're looking for something different if there's a conflict.
1070 - 1078 +
1071 if (KTWorkflowTransition::nameExists($data['name'], $this->oWorkflow)) { 1079 if (KTWorkflowTransition::nameExists($data['name'], $this->oWorkflow)) {
1072 $extra_errors['name'][] = _kt('There is already a transition with that name in this workflow.'); 1080 $extra_errors['name'][] = _kt('There is already a transition with that name in this workflow.');
1073 } 1081 }
1074 - 1082 +
1075 if (!empty($errors) || !empty($extra_errors)) { 1083 if (!empty($errors) || !empty($extra_errors)) {
1076 $oForm->handleError(null, $extra_errors); 1084 $oForm->handleError(null, $extra_errors);
1077 } 1085 }
1078 - 1086 +
1079 $this->startTransaction(); 1087 $this->startTransaction();
1080 - 1088 +
1081 $this->oTransition->setName($data['name']); 1089 $this->oTransition->setName($data['name']);
1082 - $this->oTransition->setHumanName($data['name']); 1090 + $this->oTransition->setHumanName($data['name']);
1083 $res = $this->oTransition->update(); 1091 $res = $this->oTransition->update();
1084 - 1092 +
1085 if (PEAR::isError($res)) { 1093 if (PEAR::isError($res)) {
1086 $oForm->handleError(sprintf(_kt("Unable to update transition: %s"), $res->getMessage())); 1094 $oForm->handleError(sprintf(_kt("Unable to update transition: %s"), $res->getMessage()));
1087 } 1095 }
1088 - 1096 +
1089 $this->successRedirectTo('basic', _kt("Transition updated.")); 1097 $this->successRedirectTo('basic', _kt("Transition updated."));
1090 } 1098 }
1091 - 1099 +
1092 1100
1093 function do_deletetransition() { 1101 function do_deletetransition() {
1094 $this->startTransaction(); 1102 $this->startTransaction();
1095 - 1103 +
1096 if (is_null($this->oTransition)) { 1104 if (is_null($this->oTransition)) {
1097 return $this->errorRedirectTo("basic", _kt("No transition selected")); 1105 return $this->errorRedirectTo("basic", _kt("No transition selected"));
1098 } 1106 }
1099 - 1107 +
1100 // grab all the triggers 1108 // grab all the triggers
1101 $aTriggers = KTWorkflowTriggerInstance::getByTransition($this->oTransition); 1109 $aTriggers = KTWorkflowTriggerInstance::getByTransition($this->oTransition);
1102 foreach ($aTriggers as $oTrigger) { 1110 foreach ($aTriggers as $oTrigger) {
1103 $res = $oTrigger->delete(); 1111 $res = $oTrigger->delete();
1104 if (PEAR::isError($res)) { 1112 if (PEAR::isError($res)) {
1105 $this->errorRedirectTo("basic", sprintf(_kt("Failed to clear trigger: %s"), $res->getMessage())); 1113 $this->errorRedirectTo("basic", sprintf(_kt("Failed to clear trigger: %s"), $res->getMessage()));
1106 - } 1114 + }
1107 } 1115 }
1108 - 1116 +
1109 $res = $this->oTransition->delete(); 1117 $res = $this->oTransition->delete();
1110 if (PEAR::isError($res)) { 1118 if (PEAR::isError($res)) {
1111 $this->errorRedirectTo("basic", sprintf(_kt("Failed to clear transition: %s"), $res->getMessage())); 1119 $this->errorRedirectTo("basic", sprintf(_kt("Failed to clear transition: %s"), $res->getMessage()));
1112 - }  
1113 - 1120 + }
  1121 +
1114 $this->successRedirectTo('basic', _kt("Transition deleted.")); 1122 $this->successRedirectTo('basic', _kt("Transition deleted."));
1115 - } 1123 + }
1116 1124
1117 function form_deletestate() { 1125 function form_deletestate() {
1118 $oForm = new KTForm; 1126 $oForm = new KTForm;
@@ -1127,7 +1135,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1127,7 +1135,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1127 )); 1135 ));
1128 $other_states = sprintf('id != %d', $this->oState->getId()); 1136 $other_states = sprintf('id != %d', $this->oState->getId());
1129 $other_states .= sprintf(' AND workflow_id = %d', $this->oWorkflow->getId()); 1137 $other_states .= sprintf(' AND workflow_id = %d', $this->oWorkflow->getId());
1130 - 1138 +
1131 $oForm->setWidgets(array( 1139 $oForm->setWidgets(array(
1132 array('ktcore.widgets.entityselection', array( 1140 array('ktcore.widgets.entityselection', array(
1133 'vocab' => KTWorkflowState::getList($other_states), 1141 'vocab' => KTWorkflowState::getList($other_states),
@@ -1142,56 +1150,56 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1142,56 +1150,56 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1142 $oForm->setValidators(array( 1150 $oForm->setValidators(array(
1143 array('ktcore.validators.entity', array( 1151 array('ktcore.validators.entity', array(
1144 'test' => 'replacement', 1152 'test' => 'replacement',
1145 - 'output' => 'replacement', 1153 + 'output' => 'replacement',
1146 'class' => 'KTWorkflowState', 1154 'class' => 'KTWorkflowState',
1147 )), 1155 )),
1148 )); 1156 ));
1149 return $oForm; 1157 return $oForm;
1150 } 1158 }
1151 - 1159 +
1152 function do_replacestate() { 1160 function do_replacestate() {
1153 - $this->breadcrumbs_basic(); 1161 + $this->breadcrumbs_basic();
1154 $this->oPage->setBreadcrumbDetails(_kt("Delete State")); 1162 $this->oPage->setBreadcrumbDetails(_kt("Delete State"));
1155 $oForm = $this->form_deletestate(); 1163 $oForm = $this->form_deletestate();
1156 return $oForm->renderPage(_kt("Delete State")); 1164 return $oForm->renderPage(_kt("Delete State"));
1157 } 1165 }
1158 - 1166 +
1159 function do_deletestate() { 1167 function do_deletestate() {
1160 $oForm = $this->form_deletestate(); 1168 $oForm = $this->form_deletestate();
1161 $res = $oForm->validate(); 1169 $res = $oForm->validate();
1162 - 1170 +
1163 $errors = $res['errors']; 1171 $errors = $res['errors'];
1164 $data = $res['results']; 1172 $data = $res['results'];
1165 - 1173 +
1166 if (!empty($errors)) { 1174 if (!empty($errors)) {
1167 return $oForm->handleError(); 1175 return $oForm->handleError();
1168 } 1176 }
1169 - 1177 +
1170 $this->startTransaction(); 1178 $this->startTransaction();
1171 - 1179 +
1172 if (is_null($this->oState)) { 1180 if (is_null($this->oState)) {
1173 return $this->errorRedirectTo("basic", _kt("No state selected")); 1181 return $this->errorRedirectTo("basic", _kt("No state selected"));
1174 } 1182 }
1175 - 1183 +
1176 $replacement = $data['replacement']; 1184 $replacement = $data['replacement'];
1177 -  
1178 - KTWorkflowUtil::replaceState($this->oState, $replacement);  
1179 - 1185 +
  1186 + KTWorkflowUtil::replaceState($this->oState, $replacement);
  1187 +
1180 if ($this->oWorkflow->getStartStateId() == $this->oState->getId()) { 1188 if ($this->oWorkflow->getStartStateId() == $this->oState->getId()) {
1181 $this->oWorkflow->setStartStateId($replacement->getId()); 1189 $this->oWorkflow->setStartStateId($replacement->getId());
1182 $res = $this->oWorkflow->update(); 1190 $res = $this->oWorkflow->update();
1183 if (PEAR::isError($res)) { 1191 if (PEAR::isError($res)) {
1184 $this->errorRedirectTo("basic", sprintf(_kt("Failed to update workflow: %s"), $res->getMessage())); 1192 $this->errorRedirectTo("basic", sprintf(_kt("Failed to update workflow: %s"), $res->getMessage()));
1185 - }  
1186 - }  
1187 - 1193 + }
  1194 + }
  1195 +
1188 $res = $this->oState->delete(); 1196 $res = $this->oState->delete();
1189 if (PEAR::isError($res)) { 1197 if (PEAR::isError($res)) {
1190 $this->errorRedirectTo("basic", sprintf(_kt("Failed to delete state: %s"), $res->getMessage())); 1198 $this->errorRedirectTo("basic", sprintf(_kt("Failed to delete state: %s"), $res->getMessage()));
1191 - }  
1192 - 1199 + }
  1200 +
1193 $this->successRedirectTo('basic', _kt("State deleted.")); 1201 $this->successRedirectTo('basic', _kt("State deleted."));
1194 - } 1202 + }
1195 1203
1196 function breadcrumbs_security() { 1204 function breadcrumbs_security() {
1197 $this->aBreadcrumbs[] = array( 1205 $this->aBreadcrumbs[] = array(
@@ -1199,32 +1207,32 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1199,32 +1207,32 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1199 'name' => _kt("Security"), 1207 'name' => _kt("Security"),
1200 ); 1208 );
1201 } 1209 }
1202 - 1210 +
1203 // ----------------- Security --------------------- 1211 // ----------------- Security ---------------------
1204 function do_security() { 1212 function do_security() {
1205 - $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/security_overview'); 1213 + $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/security_overview');
1206 $this->breadcrumbs_security(); 1214 $this->breadcrumbs_security();
1207 -  
1208 - 1215 +
  1216 +
1209 $oTemplate->setData(array( 1217 $oTemplate->setData(array(
1210 'context' => $this, 1218 'context' => $this,
1211 'workflow_name' => $this->oWorkflow->getName(), 1219 'workflow_name' => $this->oWorkflow->getName(),
1212 )); 1220 ));
1213 - return $oTemplate->render(); 1221 + return $oTemplate->render();
1214 } 1222 }
1215 -  
1216 - 1223 +
  1224 +
1217 // == PERMISSIONS 1225 // == PERMISSIONS
1218 function do_permissionsoverview() { 1226 function do_permissionsoverview() {
1219 $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/permissions_overview'); 1227 $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/permissions_overview');
1220 $this->breadcrumbs_security(); 1228 $this->breadcrumbs_security();
1221 - $this->oPage->setBreadcrumbDetails(_kt("Permissions Overview")); 1229 + $this->oPage->setBreadcrumbDetails(_kt("Permissions Overview"));
1222 // we want to give a complete overview. 1230 // we want to give a complete overview.
1223 // this involves a grid of: 1231 // this involves a grid of:
1224 // permission permissions 1232 // permission permissions
1225 // state x - 1233 // state x -
1226 // state - x 1234 // state - x
1227 - 1235 +
1228 $aStates = KTWorkflowState::getByWorkflow($this->oWorkflow); 1236 $aStates = KTWorkflowState::getByWorkflow($this->oWorkflow);
1229 $aUsefulPermissions = KTPermission::getDocumentRelevantList(); 1237 $aUsefulPermissions = KTPermission::getDocumentRelevantList();
1230 $aPermissionGrid = array(); 1238 $aPermissionGrid = array();
@@ -1233,14 +1241,14 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1233,14 +1241,14 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1233 $perms = array(); 1241 $perms = array();
1234 $aStatePermAssigns = KTWorkflowStatePermissionAssignment::getByState($oState); 1242 $aStatePermAssigns = KTWorkflowStatePermissionAssignment::getByState($oState);
1235 $aControllers[$oState->getId()] = (!empty($aStatePermAssigns)); 1243 $aControllers[$oState->getId()] = (!empty($aStatePermAssigns));
1236 - 1244 +
1237 foreach ($aStatePermAssigns as $oPermAssign) { 1245 foreach ($aStatePermAssigns as $oPermAssign) {
1238 $perms[$oPermAssign->getPermissionId()] = $oPermAssign; // we only care about non-null in *this* map. 1246 $perms[$oPermAssign->getPermissionId()] = $oPermAssign; // we only care about non-null in *this* map.
1239 } 1247 }
1240 - 1248 +
1241 $aPermissionGrid[$oState->getId()] = $perms; 1249 $aPermissionGrid[$oState->getId()] = $perms;
1242 } 1250 }
1243 - 1251 +
1244 $oTemplate->setData(array( 1252 $oTemplate->setData(array(
1245 'context' => $this, 1253 'context' => $this,
1246 'controllers' => $aControllers, 1254 'controllers' => $aControllers,
@@ -1250,7 +1258,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1250,7 +1258,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1250 )); 1258 ));
1251 return $oTemplate->render(); 1259 return $oTemplate->render();
1252 } 1260 }
1253 - 1261 +
1254 function form_managepermissions() { 1262 function form_managepermissions() {
1255 $oForm = new KTForm; 1263 $oForm = new KTForm;
1256 $oForm->setOptions(array( 1264 $oForm->setOptions(array(
@@ -1261,35 +1269,35 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1261,35 +1269,35 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1261 'cancel_action' => 'permissionsoverview', 1269 'cancel_action' => 'permissionsoverview',
1262 'context' => $this, 1270 'context' => $this,
1263 )); 1271 ));
1264 - 1272 +
1265 return $oForm; 1273 return $oForm;
1266 } 1274 }
1267 - 1275 +
1268 // == PERMISSIONS 1276 // == PERMISSIONS
1269 function do_managepermissions() { 1277 function do_managepermissions() {
1270 $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/managepermissions'); 1278 $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/managepermissions');
1271 -  
1272 - $oForm = $this->form_managepermissions();  
1273 - 1279 +
  1280 + $oForm = $this->form_managepermissions();
  1281 +
1274 $this->breadcrumbs_security(); 1282 $this->breadcrumbs_security();
1275 $this->aBreadcrumbs[] = array( 1283 $this->aBreadcrumbs[] = array(
1276 'name' => _kt("Document Permissions"), 1284 'name' => _kt("Document Permissions"),
1277 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("fStateId=","permissionsoverview",true)), 1285 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("fStateId=","permissionsoverview",true)),
1278 - ); 1286 + );
1279 $this->aBreadcrumbs[] = array( 1287 $this->aBreadcrumbs[] = array(
1280 'name' => $this->oState->getHumanName(), 1288 'name' => $this->oState->getHumanName(),
1281 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","managepermissions",true)), 1289 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","managepermissions",true)),
1282 ); 1290 );
1283 $this->oPage->setBreadcrumbDetails(_kt("Manage Permissions")); 1291 $this->oPage->setBreadcrumbDetails(_kt("Manage Permissions"));
1284 - 1292 +
1285 $aUsefulPermissions = KTPermission::getDocumentRelevantList(); 1293 $aUsefulPermissions = KTPermission::getDocumentRelevantList();
1286 $aPermissionGrid = array(); 1294 $aPermissionGrid = array();
1287 $aStatePermAssigns = KTWorkflowStatePermissionAssignment::getByState($this->oState); 1295 $aStatePermAssigns = KTWorkflowStatePermissionAssignment::getByState($this->oState);
1288 -  
1289 - foreach ($aStatePermAssigns as $oPermAssign) { 1296 +
  1297 + foreach ($aStatePermAssigns as $oPermAssign) {
1290 $aPermissionGrid[$oPermAssign->getPermissionId()] = $oPermAssign; 1298 $aPermissionGrid[$oPermAssign->getPermissionId()] = $oPermAssign;
1291 } 1299 }
1292 - 1300 +
1293 $oTemplate->setData(array( 1301 $oTemplate->setData(array(
1294 'context' => $this, 1302 'context' => $this,
1295 'perm_grid' => $aPermissionGrid, 1303 'perm_grid' => $aPermissionGrid,
@@ -1297,20 +1305,20 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1297,20 +1305,20 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1297 'form' => $oForm, 1305 'form' => $oForm,
1298 )); 1306 ));
1299 return $oTemplate->render(); 1307 return $oTemplate->render();
1300 - } 1308 + }
1301 1309
1302 function do_setcontrolledpermissions() { 1310 function do_setcontrolledpermissions() {
1303 $active = (array) KTUtil::arrayGet($_REQUEST, 'fControlled'); 1311 $active = (array) KTUtil::arrayGet($_REQUEST, 'fControlled');
1304 - 1312 +
1305 $aUsefulPerms = KTPermission::getDocumentRelevantList(); 1313 $aUsefulPerms = KTPermission::getDocumentRelevantList();
1306 $aStatePermAssigns = KTWorkflowStatePermissionAssignment::getByState($this->oState); 1314 $aStatePermAssigns = KTWorkflowStatePermissionAssignment::getByState($this->oState);
1307 - $aStatePermAssigns = KTUtil::keyArray($aStatePermAssigns, 'getPermissionId'); 1315 + $aStatePermAssigns = KTUtil::keyArray($aStatePermAssigns, 'getPermissionId');
1308 $assigns = array(); 1316 $assigns = array();
1309 1317
1310 - $this->startTransaction(); 1318 + $this->startTransaction();
1311 // delete those who don't know want 1319 // delete those who don't know want
1312 // create those we don't have. 1320 // create those we don't have.
1313 - 1321 +
1314 foreach ($aStatePermAssigns as $perm_id => $assign) { 1322 foreach ($aStatePermAssigns as $perm_id => $assign) {
1315 if (!$active[$perm_id]) { 1323 if (!$active[$perm_id]) {
1316 $assign->delete(); 1324 $assign->delete();
@@ -1332,35 +1340,35 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1332,35 +1340,35 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1332 } 1340 }
1333 } 1341 }
1334 } 1342 }
1335 - 1343 +
1336 $this->successRedirectTo("managepermissions", _kt("Controlled permission updated.")); 1344 $this->successRedirectTo("managepermissions", _kt("Controlled permission updated."));
1337 } 1345 }
1338 1346
1339 // == PERMISSIONS 1347 // == PERMISSIONS
1340 function do_allocatepermissions() { 1348 function do_allocatepermissions() {
1341 $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/allocate_permissions'); 1349 $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/allocate_permissions');
1342 -  
1343 - $oForm = $this->form_managepermissions(); 1350 +
  1351 + $oForm = $this->form_managepermissions();
1344 1352
1345 $this->breadcrumbs_security(); 1353 $this->breadcrumbs_security();
1346 $this->aBreadcrumbs[] = array( 1354 $this->aBreadcrumbs[] = array(
1347 'name' => _kt("Document Permissions"), 1355 'name' => _kt("Document Permissions"),
1348 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("fStateId=","permissionsoverview",true)), 1356 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("fStateId=","permissionsoverview",true)),
1349 - ); 1357 + );
1350 $this->aBreadcrumbs[] = array( 1358 $this->aBreadcrumbs[] = array(
1351 'name' => $this->oState->getHumanName(), 1359 'name' => $this->oState->getHumanName(),
1352 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","managepermissions",true)), 1360 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","managepermissions",true)),
1353 ); 1361 );
1354 $this->oPage->setBreadcrumbDetails(_kt("Allocate Permissions")); 1362 $this->oPage->setBreadcrumbDetails(_kt("Allocate Permissions"));
1355 - 1363 +
1356 $aUsefulPermissions = KTPermission::getDocumentRelevantList(); 1364 $aUsefulPermissions = KTPermission::getDocumentRelevantList();
1357 $aPermissionGrid = array(); 1365 $aPermissionGrid = array();
1358 $aStatePermAssigns = KTWorkflowStatePermissionAssignment::getByState($this->oState); 1366 $aStatePermAssigns = KTWorkflowStatePermissionAssignment::getByState($this->oState);
1359 -  
1360 - foreach ($aStatePermAssigns as $oPermAssign) { 1367 +
  1368 + foreach ($aStatePermAssigns as $oPermAssign) {
1361 $aPermissionGrid[$oPermAssign->getPermissionId()] = $oPermAssign; 1369 $aPermissionGrid[$oPermAssign->getPermissionId()] = $oPermAssign;
1362 } 1370 }
1363 - 1371 +
1364 $aPermissionsToJSON = array(); 1372 $aPermissionsToJSON = array();
1365 foreach($aUsefulPermissions as $oP) { 1373 foreach($aUsefulPermissions as $oP) {
1366 $perm_id = $oP->getId(); 1374 $perm_id = $oP->getId();
@@ -1371,7 +1379,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1371,7 +1379,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1371 1379
1372 $oJSON = new Services_JSON; 1380 $oJSON = new Services_JSON;
1373 $sJSONPermissions = $oJSON->encode($aPermissionsToJSON); 1381 $sJSONPermissions = $oJSON->encode($aPermissionsToJSON);
1374 - 1382 +
1375 $oTemplate->setData(array( 1383 $oTemplate->setData(array(
1376 'context' => $this, 1384 'context' => $this,
1377 'perm_grid' => $aPermissionGrid, 1385 'perm_grid' => $aPermissionGrid,
@@ -1381,8 +1389,8 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1381,8 +1389,8 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1381 'args' => $this->meldPersistQuery("","setpermissionallocations",true), 1389 'args' => $this->meldPersistQuery("","setpermissionallocations",true),
1382 )); 1390 ));
1383 return $oTemplate->render(); 1391 return $oTemplate->render();
1384 - }  
1385 - 1392 + }
  1393 +
1386 // JSON helper. from permissions. 1394 // JSON helper. from permissions.
1387 1395
1388 function &_getPermissionsMap() { 1396 function &_getPermissionsMap() {
@@ -1403,7 +1411,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1403,7 +1411,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1403 $aRoleIds = $oDescriptor->getRoles(); 1411 $aRoleIds = $oDescriptor->getRoles();
1404 foreach ($aRoleIds as $iId) { 1412 foreach ($aRoleIds as $iId) {
1405 $aPermissionsMap['role'][$iId][$iPermissionId] = true; 1413 $aPermissionsMap['role'][$iId][$iPermissionId] = true;
1406 - } 1414 + }
1407 } 1415 }
1408 return $aPermissionsMap; 1416 return $aPermissionsMap;
1409 } 1417 }
@@ -1413,19 +1421,19 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1413,19 +1421,19 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1413 if($sFilter == false && $optFilter != null) { 1421 if($sFilter == false && $optFilter != null) {
1414 $sFilter = $optFilter; 1422 $sFilter = $optFilter;
1415 } 1423 }
1416 - 1424 +
1417 $bSelected = KTUtil::arrayGet($_REQUEST, 'selected', false); 1425 $bSelected = KTUtil::arrayGet($_REQUEST, 'selected', false);
1418 - 1426 +
1419 $aEntityList = array('off' => _kt('-- Please filter --')); 1427 $aEntityList = array('off' => _kt('-- Please filter --'));
1420 - 1428 +
1421 // get permissions map 1429 // get permissions map
1422 $aPermissionsMap =& $this->_getPermissionsMap(); 1430 $aPermissionsMap =& $this->_getPermissionsMap();
1423 - 1431 +
1424 if($bSelected || $sFilter && trim($sFilter)) { 1432 if($bSelected || $sFilter && trim($sFilter)) {
1425 if(!$bSelected) { 1433 if(!$bSelected) {
1426 $aEntityList = array(); 1434 $aEntityList = array();
1427 } 1435 }
1428 - 1436 +
1429 $aGroups = Group::getList(sprintf('name like "%%%s%%"', $sFilter)); 1437 $aGroups = Group::getList(sprintf('name like "%%%s%%"', $sFilter));
1430 foreach($aGroups as $oGroup) { 1438 foreach($aGroups as $oGroup) {
1431 $aPerm = @array_keys($aPermissionsMap['group'][$oGroup->getId()]); 1439 $aPerm = @array_keys($aPermissionsMap['group'][$oGroup->getId()]);
@@ -1447,7 +1455,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1447,7 +1455,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1447 'name' => $oGroup->getName(), 1455 'name' => $oGroup->getName(),
1448 'permissions' => $aPerm, 1456 'permissions' => $aPerm,
1449 'id' => $oGroup->getId()); 1457 'id' => $oGroup->getId());
1450 - } 1458 + }
1451 } 1459 }
1452 1460
1453 $aRoles = Role::getList(sprintf('name like "%%%s%%"', $sFilter)); 1461 $aRoles = Role::getList(sprintf('name like "%%%s%%"', $sFilter));
@@ -1456,9 +1464,9 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1456,9 +1464,9 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1456 if(!is_array($aPerm)) { 1464 if(!is_array($aPerm)) {
1457 $aPerm = array(); 1465 $aPerm = array();
1458 } 1466 }
1459 - 1467 +
1460 if($bSelected) { 1468 if($bSelected) {
1461 - if(count($aPerm)) 1469 + if(count($aPerm))
1462 $aEntityList['r'.$oRole->getId()] = array('type' => 'role', 1470 $aEntityList['r'.$oRole->getId()] = array('type' => 'role',
1463 'display' => 'Role: ' . $oRole->getName(), 1471 'display' => 'Role: ' . $oRole->getName(),
1464 'name' => $oRole->getName(), 1472 'name' => $oRole->getName(),
@@ -1473,92 +1481,92 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1473,92 +1481,92 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1473 'id' => $oRole->getId()); 1481 'id' => $oRole->getId());
1474 } 1482 }
1475 } 1483 }
1476 - } 1484 + }
1477 return $aEntityList; 1485 return $aEntityList;
1478 } 1486 }
1479 - 1487 +
1480 1488
1481 function do_setpermissionallocations() { 1489 function do_setpermissionallocations() {
1482 $aPermissionAllowed = (array) KTUtil::arrayGet($_REQUEST, 'foo'); // thanks BD. 1490 $aPermissionAllowed = (array) KTUtil::arrayGet($_REQUEST, 'foo'); // thanks BD.
1483 - 1491 +
1484 $this->startTransaction(); 1492 $this->startTransaction();
1485 - 1493 +
1486 $aStatePermAssigns = KTWorkflowStatePermissionAssignment::getByState($this->oState); 1494 $aStatePermAssigns = KTWorkflowStatePermissionAssignment::getByState($this->oState);
1487 - 1495 +
1488 // we now walk the alloc'd perms, and go. 1496 // we now walk the alloc'd perms, and go.
1489 foreach ($aStatePermAssigns as $oPermAssign) { 1497 foreach ($aStatePermAssigns as $oPermAssign) {
1490 $aAllowed = (array) $aPermissionAllowed[$oPermAssign->getPermissionId()]; // is already role, group, etc. 1498 $aAllowed = (array) $aPermissionAllowed[$oPermAssign->getPermissionId()]; // is already role, group, etc.
1491 - $oDescriptor = KTPermissionUtil::getOrCreateDescriptor($aAllowed);  
1492 - if (PEAR::isError($oDescriptor)) { $this->errorRedirectTo('allocatepermissions', _kt('Failed to allocate as specified.')); }  
1493 - 1499 + $oDescriptor = KTPermissionUtil::getOrCreateDescriptor($aAllowed);
  1500 + if (PEAR::isError($oDescriptor)) { $this->errorRedirectTo('allocatepermissions', _kt('Failed to allocate as specified.')); }
  1501 +
1494 $oPermAssign->setDescriptorId($oDescriptor->getId()); 1502 $oPermAssign->setDescriptorId($oDescriptor->getId());
1495 $res = $oPermAssign->update(); 1503 $res = $oPermAssign->update();
1496 - if (PEAR::isError($res)) { $this->errorRedirectTo('allocatepermissions', _kt('Failed to allocate as specified.')); } 1504 + if (PEAR::isError($res)) { $this->errorRedirectTo('allocatepermissions', _kt('Failed to allocate as specified.')); }
1497 } 1505 }
1498 - 1506 +
1499 KTPermissionUtil::updatePermissionLookupForState($this->oState); 1507 KTPermissionUtil::updatePermissionLookupForState($this->oState);
1500 - 1508 +
1501 $this->successRedirectTo('managepermissions', _kt('Permissions Allocated.')); 1509 $this->successRedirectTo('managepermissions', _kt('Permissions Allocated.'));
1502 } 1510 }
1503 - 1511 +
1504 // ACTIONS 1512 // ACTIONS
1505 - 1513 +
1506 function do_actionsoverview() { 1514 function do_actionsoverview() {
1507 - $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/actions_overview'); 1515 + $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/actions_overview');
1508 $this->oPage->setBreadcrumbDetails(_kt("Actions")); 1516 $this->oPage->setBreadcrumbDetails(_kt("Actions"));
1509 - $this->breadcrumbs_security(); 1517 + $this->breadcrumbs_security();
1510 $actions = KTUtil::keyArray(KTDocumentActionUtil::getAllDocumentActions(), 'getName'); 1518 $actions = KTUtil::keyArray(KTDocumentActionUtil::getAllDocumentActions(), 'getName');
1511 $blacklist = array('ktcore.actions.document.displaydetails'); 1519 $blacklist = array('ktcore.actions.document.displaydetails');
1512 - 1520 +
1513 foreach ($blacklist as $name) { 1521 foreach ($blacklist as $name) {
1514 - unset($actions[$name]); 1522 + unset($actions[$name]);
1515 } 1523 }
1516 - 1524 +
1517 $states = KTWorkflowState::getByWorkflow($this->oWorkflow); 1525 $states = KTWorkflowState::getByWorkflow($this->oWorkflow);
1518 $action_grid = array(); 1526 $action_grid = array();
1519 foreach ($states as $oState) { 1527 foreach ($states as $oState) {
1520 $state_actions = array(); 1528 $state_actions = array();
1521 $disabled = KTWorkflowUtil::getDisabledActionsForState($oState); 1529 $disabled = KTWorkflowUtil::getDisabledActionsForState($oState);
1522 - 1530 +
1523 foreach ($disabled as $name) { 1531 foreach ($disabled as $name) {
1524 $state_actions[$name] = $name; 1532 $state_actions[$name] = $name;
1525 } 1533 }
1526 - 1534 +
1527 $action_grid[$oState->getId()] = $state_actions; 1535 $action_grid[$oState->getId()] = $state_actions;
1528 } 1536 }
1529 - 1537 +
1530 $oTemplate->setData(array( 1538 $oTemplate->setData(array(
1531 'context' => $this, 1539 'context' => $this,
1532 'states' => $states, 1540 'states' => $states,
1533 'actions' => $actions, 1541 'actions' => $actions,
1534 'grid' => $action_grid, 1542 'grid' => $action_grid,
1535 )); 1543 ));
1536 - return $oTemplate->render();  
1537 - }  
1538 - 1544 + return $oTemplate->render();
  1545 + }
  1546 +
1539 function do_editactions() { 1547 function do_editactions() {
1540 - $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/actions_edit'); 1548 + $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/actions_edit');
1541 $this->oPage->setBreadcrumbDetails(_kt("Edit Actions")); 1549 $this->oPage->setBreadcrumbDetails(_kt("Edit Actions"));
1542 $actions = KTUtil::keyArray(KTDocumentActionUtil::getAllDocumentActions(), 'getName'); 1550 $actions = KTUtil::keyArray(KTDocumentActionUtil::getAllDocumentActions(), 'getName');
1543 $blacklist = array('ktcore.actions.document.displaydetails'); 1551 $blacklist = array('ktcore.actions.document.displaydetails');
1544 - $this->breadcrumbs_security(); 1552 + $this->breadcrumbs_security();
1545 foreach ($blacklist as $name) { 1553 foreach ($blacklist as $name) {
1546 - unset($actions[$name]); 1554 + unset($actions[$name]);
1547 } 1555 }
1548 - 1556 +
1549 $states = KTWorkflowState::getByWorkflow($this->oWorkflow); 1557 $states = KTWorkflowState::getByWorkflow($this->oWorkflow);
1550 $action_grid = array(); 1558 $action_grid = array();
1551 foreach ($states as $oState) { 1559 foreach ($states as $oState) {
1552 $state_actions = array(); 1560 $state_actions = array();
1553 $disabled = KTWorkflowUtil::getDisabledActionsForState($oState); 1561 $disabled = KTWorkflowUtil::getDisabledActionsForState($oState);
1554 - 1562 +
1555 foreach ($disabled as $name) { 1563 foreach ($disabled as $name) {
1556 $state_actions[$name] = $name; 1564 $state_actions[$name] = $name;
1557 } 1565 }
1558 - 1566 +
1559 $action_grid[$oState->getId()] = $state_actions; 1567 $action_grid[$oState->getId()] = $state_actions;
1560 } 1568 }
1561 - 1569 +
1562 $oTemplate->setData(array( 1570 $oTemplate->setData(array(
1563 'context' => $this, 1571 'context' => $this,
1564 'states' => $states, 1572 'states' => $states,
@@ -1566,13 +1574,13 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1566,13 +1574,13 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1566 'grid' => $action_grid, 1574 'grid' => $action_grid,
1567 'args' => $this->meldPersistQuery("","saveactions", true), 1575 'args' => $this->meldPersistQuery("","saveactions", true),
1568 )); 1576 ));
1569 - return $oTemplate->render();  
1570 - }  
1571 - 1577 + return $oTemplate->render();
  1578 + }
  1579 +
1572 function do_saveactions() { 1580 function do_saveactions() {
1573 $disabled_actions = (array) $_REQUEST['fActions']; 1581 $disabled_actions = (array) $_REQUEST['fActions'];
1574 1582
1575 - 1583 +
1576 $states = KTWorkflowState::getByWorkflow($this->oWorkflow); 1584 $states = KTWorkflowState::getByWorkflow($this->oWorkflow);
1577 $actions = KTUtil::keyArray(KTDocumentActionUtil::getAllDocumentActions(), 'getName'); 1585 $actions = KTUtil::keyArray(KTDocumentActionUtil::getAllDocumentActions(), 'getName');
1578 1586
@@ -1593,10 +1601,10 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1593,10 +1601,10 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1593 } 1601 }
1594 1602
1595 $this->successRedirectTo('actionsoverview', _kt('Disabled actions updated.')); 1603 $this->successRedirectTo('actionsoverview', _kt('Disabled actions updated.'));
1596 - } 1604 + }
1597 1605
1598 function do_transitionsecurityoverview() { 1606 function do_transitionsecurityoverview() {
1599 - $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/transition_guards_overview'); 1607 + $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/transition_guards_overview');
1600 $this->oPage->setBreadcrumbDetails(_kt("Overview")); 1608 $this->oPage->setBreadcrumbDetails(_kt("Overview"));
1601 $this->oPage->setTitle(_kt("Transition Restrictions Overview")); 1609 $this->oPage->setTitle(_kt("Transition Restrictions Overview"));
1602 $this->breadcrumbs_security(); 1610 $this->breadcrumbs_security();
@@ -1604,32 +1612,32 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1604,32 +1612,32 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1604 'name' => _kt("Transition Restrictions"), 1612 'name' => _kt("Transition Restrictions"),
1605 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("", "transitionsecurityoverview", true)), 1613 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("", "transitionsecurityoverview", true)),
1606 ); 1614 );
1607 - 1615 +
1608 $transitions = KTWorkflowTransition::getByWorkflow($this->oWorkflow); 1616 $transitions = KTWorkflowTransition::getByWorkflow($this->oWorkflow);
1609 - 1617 +
1610 $oTemplate->setData(array( 1618 $oTemplate->setData(array(
1611 'context' => $this, 1619 'context' => $this,
1612 'transitions' => $transitions, 1620 'transitions' => $transitions,
1613 )); 1621 ));
1614 - return $oTemplate->render();  
1615 - }  
1616 - 1622 + return $oTemplate->render();
  1623 + }
  1624 +
1617 // helper 1625 // helper
1618 function describeTransitionGuards($oTransition) { 1626 function describeTransitionGuards($oTransition) {
1619 $restrictions = KTWorkflowUtil::getGuardTriggersForTransition($oTransition); 1627 $restrictions = KTWorkflowUtil::getGuardTriggersForTransition($oTransition);
1620 - 1628 +
1621 if (empty($restrictions)) { 1629 if (empty($restrictions)) {
1622 return _kt("No restrictions in place for this transition."); 1630 return _kt("No restrictions in place for this transition.");
1623 } 1631 }
1624 - 1632 +
1625 $restriction_text = array(); 1633 $restriction_text = array();
1626 foreach ($restrictions as $oGuard) { 1634 foreach ($restrictions as $oGuard) {
1627 $restriction_text[] = $oGuard->getConfigDescription(); 1635 $restriction_text[] = $oGuard->getConfigDescription();
1628 } 1636 }
1629 - 1637 +
1630 return implode('. ', $restriction_text); 1638 return implode('. ', $restriction_text);
1631 } 1639 }
1632 - 1640 +
1633 function form_addtransitionguard() { 1641 function form_addtransitionguard() {
1634 $oForm = new KTForm; 1642 $oForm = new KTForm;
1635 $oForm->setOptions(array( 1643 $oForm->setOptions(array(
@@ -1637,11 +1645,11 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1637,11 +1645,11 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1637 'label' => _kt("Add New Transition Restriction"), 1645 'label' => _kt("Add New Transition Restriction"),
1638 'action' => 'addguard', 1646 'action' => 'addguard',
1639 'cancel_action' => 'manageguards', 1647 'cancel_action' => 'manageguards',
1640 - 'fail_action' => 'manageguards', 1648 + 'fail_action' => 'manageguards',
1641 'submit_label' => _kt("Add Restriction"), 1649 'submit_label' => _kt("Add Restriction"),
1642 'context' => $this, 1650 'context' => $this,
1643 )); 1651 ));
1644 - 1652 +
1645 $oTriggerSingleton =& KTWorkflowTriggerRegistry::getSingleton(); 1653 $oTriggerSingleton =& KTWorkflowTriggerRegistry::getSingleton();
1646 $aTriggerList = $oTriggerSingleton->listWorkflowTriggers(); 1654 $aTriggerList = $oTriggerSingleton->listWorkflowTriggers();
1647 $vocab = array(); 1655 $vocab = array();
@@ -1651,7 +1659,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1651,7 +1659,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1651 $actions = array(); 1659 $actions = array();
1652 if ($aInfo['guard']) { 1660 if ($aInfo['guard']) {
1653 $actions[] = _kt('Guard'); 1661 $actions[] = _kt('Guard');
1654 - } else { 1662 + } else {
1655 continue; 1663 continue;
1656 } 1664 }
1657 if ($aInfo['action']) { 1665 if ($aInfo['action']) {
@@ -1659,8 +1667,8 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1659,8 +1667,8 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1659 } 1667 }
1660 $sActStr = implode(', ', $actions); 1668 $sActStr = implode(', ', $actions);
1661 $vocab[$ns] = sprintf(_kt("%s (%s)"), $aInfo['name'], $sActStr); 1669 $vocab[$ns] = sprintf(_kt("%s (%s)"), $aInfo['name'], $sActStr);
1662 - }  
1663 - 1670 + }
  1671 +
1664 $oForm->setWidgets(array( 1672 $oForm->setWidgets(array(
1665 array('ktcore.widgets.selection', array( 1673 array('ktcore.widgets.selection', array(
1666 'label' => _kt("Restriction Type"), 1674 'label' => _kt("Restriction Type"),
@@ -1670,7 +1678,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1670,7 +1678,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1670 'required' => true, 1678 'required' => true,
1671 )), 1679 )),
1672 )); 1680 ));
1673 - 1681 +
1674 $oForm->setValidators(array( 1682 $oForm->setValidators(array(
1675 array('ktcore.validators.string', array( 1683 array('ktcore.validators.string', array(
1676 'test' => 'guard_name', 1684 'test' => 'guard_name',
@@ -1678,10 +1686,10 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1678,10 +1686,10 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1678 )), 1686 )),
1679 )); 1687 ));
1680 return $oForm; 1688 return $oForm;
1681 - }  
1682 - 1689 + }
  1690 +
1683 function do_manageguards() { 1691 function do_manageguards() {
1684 - $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/restrictions_edit'); 1692 + $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/restrictions_edit');
1685 $this->oPage->setBreadcrumbDetails(_kt("Manage Restrictions")); 1693 $this->oPage->setBreadcrumbDetails(_kt("Manage Restrictions"));
1686 $this->breadcrumbs_security(); 1694 $this->breadcrumbs_security();
1687 $this->aBreadcrumbs[] = array( 1695 $this->aBreadcrumbs[] = array(
@@ -1693,21 +1701,21 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1693,21 +1701,21 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1693 ); 1701 );
1694 $restrictions = KTWorkflowUtil::getGuardTriggersForTransition($this->oTransition); 1702 $restrictions = KTWorkflowUtil::getGuardTriggersForTransition($this->oTransition);
1695 $add_form = $this->form_addtransitionguard(); 1703 $add_form = $this->form_addtransitionguard();
1696 - 1704 +
1697 $oTemplate->setData(array( 1705 $oTemplate->setData(array(
1698 'context' => $this, 1706 'context' => $this,
1699 'add_form' => $add_form, 1707 'add_form' => $add_form,
1700 'aGuardTriggers' => $restrictions, 1708 'aGuardTriggers' => $restrictions,
1701 )); 1709 ));
1702 - return $oTemplate->render();  
1703 - }  
1704 - 1710 + return $oTemplate->render();
  1711 + }
  1712 +
1705 function do_addguard() { 1713 function do_addguard() {
1706 $oForm = $this->form_addtransitionguard(); 1714 $oForm = $this->form_addtransitionguard();
1707 $res = $oForm->validate(); 1715 $res = $oForm->validate();
1708 $data = $res['results']; 1716 $data = $res['results'];
1709 $errors = $res['errors']; 1717 $errors = $res['errors'];
1710 - 1718 +
1711 if (!empty($errors)) { 1719 if (!empty($errors)) {
1712 return $oForm->handleError(); 1720 return $oForm->handleError();
1713 } 1721 }
@@ -1726,7 +1734,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1726,7 +1734,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1726 'namespace' => KTUtil::arrayGet($data, 'guard_name'), 1734 'namespace' => KTUtil::arrayGet($data, 'guard_name'),
1727 'config' => array(), 1735 'config' => array(),
1728 )); 1736 ));
1729 - 1737 +
1730 if (PEAR::isError($oTriggerConfig)) { 1738 if (PEAR::isError($oTriggerConfig)) {
1731 return $oForm->handleError(_kt('Unable to add trigger.') . $oTriggerConfig->getMessage()); 1739 return $oForm->handleError(_kt('Unable to add trigger.') . $oTriggerConfig->getMessage());
1732 } 1740 }
@@ -1734,14 +1742,14 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1734,14 +1742,14 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1734 // now, if the trigger is editable... 1742 // now, if the trigger is editable...
1735 $oTrigger->loadConfig($oTriggerConfig); 1743 $oTrigger->loadConfig($oTriggerConfig);
1736 if ($oTrigger->bIsConfigurable) { 1744 if ($oTrigger->bIsConfigurable) {
1737 - $this->successRedirectTo('editguardtrigger', _kt("New restriction added. This restriction requires configuration: please specify this below."), array('fTriggerInstanceId' => $oTriggerConfig->getId())); 1745 + $this->successRedirectTo('editguardtrigger', _kt("New restriction added. This restriction requires configuration: please specify this below."), array('fTriggerInstanceId' => $oTriggerConfig->getId()));
1738 } else { 1746 } else {
1739 $this->successRedirectTo('manageguards', _kt("New restriction added.")); 1747 $this->successRedirectTo('manageguards', _kt("New restriction added."));
1740 } 1748 }
1741 - exit(0); 1749 + exit(0);
1742 } 1750 }
1743 -  
1744 - 1751 +
  1752 +
1745 function do_editguardtrigger() { 1753 function do_editguardtrigger() {
1746 $this->oPage->setBreadcrumbDetails(_kt("Edit Restriction")); 1754 $this->oPage->setBreadcrumbDetails(_kt("Edit Restriction"));
1747 $this->breadcrumbs_security(); 1755 $this->breadcrumbs_security();
@@ -1753,7 +1761,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1753,7 +1761,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1753 'name' => $this->oTransition->getHumanName(), 1761 'name' => $this->oTransition->getHumanName(),
1754 ); 1762 );
1755 1763
1756 - $oTriggerInstance =& KTWorkflowTriggerInstance::get($_REQUEST['fTriggerInstanceId']); 1764 + $oTriggerInstance =& KTWorkflowTriggerInstance::get($_REQUEST['fTriggerInstanceId']);
1757 if (PEAR::isError($oTriggerInstance)) { 1765 if (PEAR::isError($oTriggerInstance)) {
1758 return $this->errorRedirectTo('manageguards', _kt('Unable to load trigger.')); 1766 return $this->errorRedirectTo('manageguards', _kt('Unable to load trigger.'));
1759 } 1767 }
@@ -1776,12 +1784,12 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1776,12 +1784,12 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1776 // }}} 1784 // }}}
1777 1785
1778 function do_saveguardtrigger() { 1786 function do_saveguardtrigger() {
1779 - $oTriggerInstance =& KTWorkflowTriggerInstance::get($_REQUEST['fTriggerInstanceId']); 1787 + $oTriggerInstance =& KTWorkflowTriggerInstance::get($_REQUEST['fTriggerInstanceId']);
1780 if (PEAR::isError($oTriggerInstance)) { 1788 if (PEAR::isError($oTriggerInstance)) {
1781 $this->errorRedirectTo('manageguards', _kt('Unable to load trigger.')); 1789 $this->errorRedirectTo('manageguards', _kt('Unable to load trigger.'));
1782 - exit(0); 1790 + exit(0);
1783 } 1791 }
1784 - 1792 +
1785 $KTWFTriggerReg =& KTWorkflowTriggerRegistry::getSingleton(); 1793 $KTWFTriggerReg =& KTWorkflowTriggerRegistry::getSingleton();
1786 1794
1787 $this->startTransaction(); 1795 $this->startTransaction();
@@ -1792,19 +1800,19 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1792,19 +1800,19 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1792 exit(0); 1800 exit(0);
1793 } 1801 }
1794 $oTrigger->loadConfig($oTriggerInstance); 1802 $oTrigger->loadConfig($oTriggerInstance);
1795 - 1803 +
1796 $res = $oTrigger->saveConfiguration(); 1804 $res = $oTrigger->saveConfiguration();
1797 if (PEAR::isError($res)) { 1805 if (PEAR::isError($res)) {
1798 $this->errorRedirectTo('manageguards', _kt('Unable to save trigger: ') . $res->getMessage()); 1806 $this->errorRedirectTo('manageguards', _kt('Unable to save trigger: ') . $res->getMessage());
1799 - exit(0); 1807 + exit(0);
1800 } 1808 }
1801 - 1809 +
1802 $this->successRedirectTo('manageguards', _kt('Trigger saved.')); 1810 $this->successRedirectTo('manageguards', _kt('Trigger saved.'));
1803 - exit(0); 1811 + exit(0);
1804 } 1812 }
1805 1813
1806 function do_deleteguardtrigger() { 1814 function do_deleteguardtrigger() {
1807 - $oTriggerInstance =& KTWorkflowTriggerInstance::get($_REQUEST['fTriggerInstanceId']); 1815 + $oTriggerInstance =& KTWorkflowTriggerInstance::get($_REQUEST['fTriggerInstanceId']);
1808 if (PEAR::isError($oTriggerInstance)) { 1816 if (PEAR::isError($oTriggerInstance)) {
1809 return $this->errorRedirectTo('manageguards', _kt('Unable to load trigger.')); 1817 return $this->errorRedirectTo('manageguards', _kt('Unable to load trigger.'));
1810 } 1818 }
@@ -1819,18 +1827,18 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1819,18 +1827,18 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1819 exit(0); 1827 exit(0);
1820 } 1828 }
1821 $oTrigger->loadConfig($oTriggerInstance); 1829 $oTrigger->loadConfig($oTriggerInstance);
1822 - 1830 +
1823 $res = $oTriggerInstance->delete(); 1831 $res = $oTriggerInstance->delete();
1824 if (PEAR::isError($res)) { 1832 if (PEAR::isError($res)) {
1825 $this->errorRedirectTo('editTransition', _kt('Unable to delete trigger: ') . $res->getMessage(), 'fWorkflowId=' . $oWorkflow->getId() . '&fTransitionId=' . $oTransition->getId()); 1833 $this->errorRedirectTo('editTransition', _kt('Unable to delete trigger: ') . $res->getMessage(), 'fWorkflowId=' . $oWorkflow->getId() . '&fTransitionId=' . $oTransition->getId());
1826 - exit(0); 1834 + exit(0);
1827 } 1835 }
1828 - 1836 +
1829 $this->successRedirectTo('manageguards', _kt('Trigger deleted.')); 1837 $this->successRedirectTo('manageguards', _kt('Trigger deleted.'));
1830 - exit(0); 1838 + exit(0);
1831 } 1839 }
1832 1840
1833 - 1841 +
1834 // ----------------- Effects --------------------- 1842 // ----------------- Effects ---------------------
1835 function breadcrumb_effects() { 1843 function breadcrumb_effects() {
1836 $this->aBreadcrumbs[] = array( 1844 $this->aBreadcrumbs[] = array(
@@ -1838,19 +1846,19 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1838,19 +1846,19 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1838 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","effects",true)), 1846 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","effects",true)),
1839 ); 1847 );
1840 } 1848 }
1841 - 1849 +
1842 function do_effects() { 1850 function do_effects() {
1843 - $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/effects_overview'); 1851 + $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/effects_overview');
1844 $this->breadcrumb_effects(); 1852 $this->breadcrumb_effects();
1845 -  
1846 - 1853 +
  1854 +
1847 $oTemplate->setData(array( 1855 $oTemplate->setData(array(
1848 'context' => $this, 1856 'context' => $this,
1849 'workflow_name' => $this->oWorkflow->getName(), 1857 'workflow_name' => $this->oWorkflow->getName(),
1850 )); 1858 ));
1851 - return $oTemplate->render();  
1852 - }  
1853 - 1859 + return $oTemplate->render();
  1860 + }
  1861 +
1854 1862
1855 function form_addtransitionaction() { 1863 function form_addtransitionaction() {
1856 $oForm = new KTForm; 1864 $oForm = new KTForm;
@@ -1859,11 +1867,11 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1859,11 +1867,11 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1859 'label' => _kt("Add New Transition Action"), 1867 'label' => _kt("Add New Transition Action"),
1860 'action' => 'addactiontrigger', 1868 'action' => 'addactiontrigger',
1861 'cancel_action' => 'managetransitionactions', 1869 'cancel_action' => 'managetransitionactions',
1862 - 'fail_action' => 'managetransitionactions', 1870 + 'fail_action' => 'managetransitionactions',
1863 'submit_label' => _kt("Add Action"), 1871 'submit_label' => _kt("Add Action"),
1864 'context' => $this, 1872 'context' => $this,
1865 )); 1873 ));
1866 - 1874 +
1867 $oTriggerSingleton =& KTWorkflowTriggerRegistry::getSingleton(); 1875 $oTriggerSingleton =& KTWorkflowTriggerRegistry::getSingleton();
1868 $aTriggerList = $oTriggerSingleton->listWorkflowTriggers(); 1876 $aTriggerList = $oTriggerSingleton->listWorkflowTriggers();
1869 $vocab = array(); 1877 $vocab = array();
@@ -1873,16 +1881,16 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1873,16 +1881,16 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1873 $actions = array(); 1881 $actions = array();
1874 if ($aInfo['guard']) { 1882 if ($aInfo['guard']) {
1875 $actions[] = _kt('Guard'); 1883 $actions[] = _kt('Guard');
1876 - } 1884 + }
1877 if ($aInfo['action']) { 1885 if ($aInfo['action']) {
1878 $actions[] = _kt('Action'); 1886 $actions[] = _kt('Action');
1879 - } else { 1887 + } else {
1880 continue; 1888 continue;
1881 } 1889 }
1882 $sActStr = implode(', ', $actions); 1890 $sActStr = implode(', ', $actions);
1883 $vocab[$ns] = sprintf(_kt("%s (%s)"), $aInfo['name'], $sActStr); 1891 $vocab[$ns] = sprintf(_kt("%s (%s)"), $aInfo['name'], $sActStr);
1884 - }  
1885 - 1892 + }
  1893 +
1886 $oForm->setWidgets(array( 1894 $oForm->setWidgets(array(
1887 array('ktcore.widgets.selection', array( 1895 array('ktcore.widgets.selection', array(
1888 'label' => _kt("Action/Effect Type"), 1896 'label' => _kt("Action/Effect Type"),
@@ -1892,7 +1900,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1892,7 +1900,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1892 'required' => true, 1900 'required' => true,
1893 )), 1901 )),
1894 )); 1902 ));
1895 - 1903 +
1896 $oForm->setValidators(array( 1904 $oForm->setValidators(array(
1897 array('ktcore.validators.string', array( 1905 array('ktcore.validators.string', array(
1898 'test' => 'action_name', 1906 'test' => 'action_name',
@@ -1900,74 +1908,74 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1900,74 +1908,74 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1900 )), 1908 )),
1901 )); 1909 ));
1902 return $oForm; 1910 return $oForm;
1903 - } 1911 + }
1904 1912
1905 function do_transitionactions() { 1913 function do_transitionactions() {
1906 - $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/transition_effects_overview');  
1907 - $this->breadcrumb_effects(); 1914 + $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/transition_effects_overview');
  1915 + $this->breadcrumb_effects();
1908 $this->aBreadcrumbs[] = array( 1916 $this->aBreadcrumbs[] = array(
1909 'name' => _kt("Transition Effects"), 1917 'name' => _kt("Transition Effects"),
1910 - 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","transitionactions",true)), 1918 + 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","transitionactions",true)),
1911 ); 1919 );
1912 $this->oPage->setBreadcrumbDetails(_kt("Overview")); 1920 $this->oPage->setBreadcrumbDetails(_kt("Overview"));
1913 $this->oPage->setTitle(_kt("Transition Effects Overview")); 1921 $this->oPage->setTitle(_kt("Transition Effects Overview"));
1914 - 1922 +
1915 $aTransitions = KTWorkflowTransition::getByWorkflow($this->oWorkflow); 1923 $aTransitions = KTWorkflowTransition::getByWorkflow($this->oWorkflow);
1916 - 1924 +
1917 $oTemplate->setData(array( 1925 $oTemplate->setData(array(
1918 'context' => $this, 1926 'context' => $this,
1919 'transitions' => $aTransitions, 1927 'transitions' => $aTransitions,
1920 )); 1928 ));
1921 - return $oTemplate->render();  
1922 - }  
1923 -  
1924 - 1929 + return $oTemplate->render();
  1930 + }
  1931 +
  1932 +
1925 // helper 1933 // helper
1926 function describeTransitionActions($oTransition) { 1934 function describeTransitionActions($oTransition) {
1927 $actions = KTWorkflowUtil::getActionTriggersForTransition($oTransition); 1935 $actions = KTWorkflowUtil::getActionTriggersForTransition($oTransition);
1928 - 1936 +
1929 if (empty($actions)) { 1937 if (empty($actions)) {
1930 return '&mdash;'; 1938 return '&mdash;';
1931 } 1939 }
1932 - 1940 +
1933 $action_text = array(); 1941 $action_text = array();
1934 foreach ($actions as $oAction) { 1942 foreach ($actions as $oAction) {
1935 $action_text[] = $oAction->getConfigDescription(); 1943 $action_text[] = $oAction->getConfigDescription();
1936 } 1944 }
1937 - 1945 +
1938 return implode('. ', $action_text); 1946 return implode('. ', $action_text);
1939 } 1947 }
1940 - 1948 +
1941 1949
1942 function do_managetransitionactions() { 1950 function do_managetransitionactions() {
1943 - $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/transition_actions_edit');  
1944 - $this->breadcrumb_effects(); 1951 + $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/transition_actions_edit');
  1952 + $this->breadcrumb_effects();
1945 $this->aBreadcrumbs[] = array( 1953 $this->aBreadcrumbs[] = array(
1946 'name' => _kt("Transition Effects"), 1954 'name' => _kt("Transition Effects"),
1947 - 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","transitionactions",true)), 1955 + 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","transitionactions",true)),
1948 ); 1956 );
1949 $this->aBreadcrumbs[] = array( 1957 $this->aBreadcrumbs[] = array(
1950 'name' => $this->oTransition->getHumanName(), 1958 'name' => $this->oTransition->getHumanName(),
1951 - ); 1959 + );
1952 $this->oPage->setBreadcrumbDetails(_kt("Manage Transition Actions")); 1960 $this->oPage->setBreadcrumbDetails(_kt("Manage Transition Actions"));
1953 - 1961 +
1954 $actions = KTWorkflowUtil::getActionTriggersForTransition($this->oTransition); 1962 $actions = KTWorkflowUtil::getActionTriggersForTransition($this->oTransition);
1955 $add_form = $this->form_addtransitionaction(); 1963 $add_form = $this->form_addtransitionaction();
1956 - 1964 +
1957 $oTemplate->setData(array( 1965 $oTemplate->setData(array(
1958 'context' => $this, 1966 'context' => $this,
1959 'add_form' => $add_form, 1967 'add_form' => $add_form,
1960 'aActionTriggers' => $actions, 1968 'aActionTriggers' => $actions,
1961 )); 1969 ));
1962 - return $oTemplate->render();  
1963 - }  
1964 - 1970 + return $oTemplate->render();
  1971 + }
  1972 +
1965 function do_addactiontrigger() { 1973 function do_addactiontrigger() {
1966 $oForm = $this->form_addtransitionaction(); 1974 $oForm = $this->form_addtransitionaction();
1967 $res = $oForm->validate(); 1975 $res = $oForm->validate();
1968 $data = $res['results']; 1976 $data = $res['results'];
1969 $errors = $res['errors']; 1977 $errors = $res['errors'];
1970 - 1978 +
1971 if (!empty($errors)) { 1979 if (!empty($errors)) {
1972 return $oForm->handleError(); 1980 return $oForm->handleError();
1973 } 1981 }
@@ -1986,7 +1994,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1986,7 +1994,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1986 'namespace' => KTUtil::arrayGet($data, 'action_name'), 1994 'namespace' => KTUtil::arrayGet($data, 'action_name'),
1987 'config' => array(), 1995 'config' => array(),
1988 )); 1996 ));
1989 - 1997 +
1990 if (PEAR::isError($oTriggerConfig)) { 1998 if (PEAR::isError($oTriggerConfig)) {
1991 return $oForm->handleError(_kt('Unable to add trigger.') . $oTriggerConfig->getMessage()); 1999 return $oForm->handleError(_kt('Unable to add trigger.') . $oTriggerConfig->getMessage());
1992 } 2000 }
@@ -1994,26 +2002,26 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -1994,26 +2002,26 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1994 // now, if the trigger is editable... 2002 // now, if the trigger is editable...
1995 $oTrigger->loadConfig($oTriggerConfig); 2003 $oTrigger->loadConfig($oTriggerConfig);
1996 if ($oTrigger->bIsConfigurable) { 2004 if ($oTrigger->bIsConfigurable) {
1997 - $this->successRedirectTo('editactiontrigger', _kt("New action added. This action requires configuration: please specify this below."), array('fTriggerInstanceId' => $oTriggerConfig->getId())); 2005 + $this->successRedirectTo('editactiontrigger', _kt("New action added. This action requires configuration: please specify this below."), array('fTriggerInstanceId' => $oTriggerConfig->getId()));
1998 } else { 2006 } else {
1999 $this->successRedirectTo('managetransitionactions', _kt("New restriction added.")); 2007 $this->successRedirectTo('managetransitionactions', _kt("New restriction added."));
2000 } 2008 }
2001 - exit(0); 2009 + exit(0);
2002 } 2010 }
2003 -  
2004 - 2011 +
  2012 +
2005 function do_editactiontrigger() { 2013 function do_editactiontrigger() {
2006 - $this->breadcrumb_effects(); 2014 + $this->breadcrumb_effects();
2007 $this->aBreadcrumbs[] = array( 2015 $this->aBreadcrumbs[] = array(
2008 'name' => _kt("Transition Effects"), 2016 'name' => _kt("Transition Effects"),
2009 - 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","transitionactions",true)), 2017 + 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","transitionactions",true)),
2010 ); 2018 );
2011 $this->aBreadcrumbs[] = array( 2019 $this->aBreadcrumbs[] = array(
2012 'name' => $this->oTransition->getHumanName(), 2020 'name' => $this->oTransition->getHumanName(),
2013 - ); 2021 + );
2014 $this->oPage->setBreadcrumbDetails(_kt("Edit Transition Action")); 2022 $this->oPage->setBreadcrumbDetails(_kt("Edit Transition Action"));
2015 -  
2016 - $oTriggerInstance =& KTWorkflowTriggerInstance::get($_REQUEST['fTriggerInstanceId']); 2023 +
  2024 + $oTriggerInstance =& KTWorkflowTriggerInstance::get($_REQUEST['fTriggerInstanceId']);
2017 if (PEAR::isError($oTriggerInstance)) { 2025 if (PEAR::isError($oTriggerInstance)) {
2018 return $this->errorRedirectTo('managetransitionactions', _kt('Unable to load trigger.')); 2026 return $this->errorRedirectTo('managetransitionactions', _kt('Unable to load trigger.'));
2019 } 2027 }
@@ -2036,12 +2044,12 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2036,12 +2044,12 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2036 // }}} 2044 // }}}
2037 2045
2038 function do_saveactiontrigger() { 2046 function do_saveactiontrigger() {
2039 - $oTriggerInstance =& KTWorkflowTriggerInstance::get($_REQUEST['fTriggerInstanceId']); 2047 + $oTriggerInstance =& KTWorkflowTriggerInstance::get($_REQUEST['fTriggerInstanceId']);
2040 if (PEAR::isError($oTriggerInstance)) { 2048 if (PEAR::isError($oTriggerInstance)) {
2041 $this->errorRedirectTo('managetransitionactions', _kt('Unable to load trigger.')); 2049 $this->errorRedirectTo('managetransitionactions', _kt('Unable to load trigger.'));
2042 - exit(0); 2050 + exit(0);
2043 } 2051 }
2044 - 2052 +
2045 $KTWFTriggerReg =& KTWorkflowTriggerRegistry::getSingleton(); 2053 $KTWFTriggerReg =& KTWorkflowTriggerRegistry::getSingleton();
2046 2054
2047 $this->startTransaction(); 2055 $this->startTransaction();
@@ -2052,19 +2060,19 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2052,19 +2060,19 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2052 exit(0); 2060 exit(0);
2053 } 2061 }
2054 $oTrigger->loadConfig($oTriggerInstance); 2062 $oTrigger->loadConfig($oTriggerInstance);
2055 - 2063 +
2056 $res = $oTrigger->saveConfiguration(); 2064 $res = $oTrigger->saveConfiguration();
2057 if (PEAR::isError($res)) { 2065 if (PEAR::isError($res)) {
2058 $this->errorRedirectTo('managetransitionactions', _kt('Unable to save trigger: ') . $res->getMessage()); 2066 $this->errorRedirectTo('managetransitionactions', _kt('Unable to save trigger: ') . $res->getMessage());
2059 - exit(0); 2067 + exit(0);
2060 } 2068 }
2061 - 2069 +
2062 $this->successRedirectTo('managetransitionactions', _kt('Trigger saved.')); 2070 $this->successRedirectTo('managetransitionactions', _kt('Trigger saved.'));
2063 - exit(0); 2071 + exit(0);
2064 } 2072 }
2065 2073
2066 function do_deleteactiontrigger() { 2074 function do_deleteactiontrigger() {
2067 - $oTriggerInstance =& KTWorkflowTriggerInstance::get($_REQUEST['fTriggerInstanceId']); 2075 + $oTriggerInstance =& KTWorkflowTriggerInstance::get($_REQUEST['fTriggerInstanceId']);
2068 if (PEAR::isError($oTriggerInstance)) { 2076 if (PEAR::isError($oTriggerInstance)) {
2069 return $this->errorRedirectTo('managetransitionactions', _kt('Unable to load trigger.')); 2077 return $this->errorRedirectTo('managetransitionactions', _kt('Unable to load trigger.'));
2070 } 2078 }
@@ -2079,24 +2087,24 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2079,24 +2087,24 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2079 exit(0); 2087 exit(0);
2080 } 2088 }
2081 $oTrigger->loadConfig($oTriggerInstance); 2089 $oTrigger->loadConfig($oTriggerInstance);
2082 - 2090 +
2083 $res = $oTriggerInstance->delete(); 2091 $res = $oTriggerInstance->delete();
2084 if (PEAR::isError($res)) { 2092 if (PEAR::isError($res)) {
2085 $this->errorRedirectTo('managetransitionactions', _kt('Unable to delete trigger: ') . $res->getMessage(), 'fWorkflowId=' . $oWorkflow->getId() . '&fTransitionId=' . $oTransition->getId()); 2093 $this->errorRedirectTo('managetransitionactions', _kt('Unable to delete trigger: ') . $res->getMessage(), 'fWorkflowId=' . $oWorkflow->getId() . '&fTransitionId=' . $oTransition->getId());
2086 - exit(0); 2094 + exit(0);
2087 } 2095 }
2088 - 2096 +
2089 $this->successRedirectTo('managetransitionactions', _kt('Trigger deleted.')); 2097 $this->successRedirectTo('managetransitionactions', _kt('Trigger deleted.'));
2090 - exit(0); 2098 + exit(0);
2091 } 2099 }
2092 - 2100 +
2093 function do_managenotifications() { 2101 function do_managenotifications() {
2094 - $this->breadcrumb_effects(); 2102 + $this->breadcrumb_effects();
2095 $this->aBreadcrumbs[] = array( 2103 $this->aBreadcrumbs[] = array(
2096 'name' => _kt("Notifications"), 2104 'name' => _kt("Notifications"),
2097 - 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","managenotifications",true)), 2105 + 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","managenotifications",true)),
2098 ); 2106 );
2099 - 2107 +
2100 $oTemplate =& $this->oValidator->validateTemplate("ktcore/workflow/admin/manage_notifications"); 2108 $oTemplate =& $this->oValidator->validateTemplate("ktcore/workflow/admin/manage_notifications");
2101 $oTemplate->setData(array( 2109 $oTemplate->setData(array(
2102 'context' => $this, 2110 'context' => $this,
@@ -2104,14 +2112,14 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2104,14 +2112,14 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2104 )); 2112 ));
2105 return $oTemplate->render(); 2113 return $oTemplate->render();
2106 } 2114 }
2107 - 2115 +
2108 function describeStateNotifications($oState) { 2116 function describeStateNotifications($oState) {
2109 $aAllowed = KTWorkflowUtil::getInformedForState($oState); 2117 $aAllowed = KTWorkflowUtil::getInformedForState($oState);
2110 - 2118 +
2111 $aUsers = array(); 2119 $aUsers = array();
2112 $aGroups = array(); 2120 $aGroups = array();
2113 $aRoles = array(); 2121 $aRoles = array();
2114 - 2122 +
2115 foreach (KTUtil::arrayGet($aAllowed,'user',array()) as $iUserId) { 2123 foreach (KTUtil::arrayGet($aAllowed,'user',array()) as $iUserId) {
2116 $oU = User::get($iUserId); 2124 $oU = User::get($iUserId);
2117 if (PEAR::isError($oU) || ($oU == false)) { 2125 if (PEAR::isError($oU) || ($oU == false)) {
@@ -2120,7 +2128,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2120,7 +2128,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2120 $aUsers[] = $oU->getName(); 2128 $aUsers[] = $oU->getName();
2121 } 2129 }
2122 } 2130 }
2123 - 2131 +
2124 foreach (KTUtil::arrayGet($aAllowed,'group',array()) as $iGroupId) { 2132 foreach (KTUtil::arrayGet($aAllowed,'group',array()) as $iGroupId) {
2125 $oG = Group::get($iGroupId); 2133 $oG = Group::get($iGroupId);
2126 if (PEAR::isError($oG) || ($oG == false)) { 2134 if (PEAR::isError($oG) || ($oG == false)) {
@@ -2129,7 +2137,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2129,7 +2137,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2129 $aGroups[] = $oG->getName(); 2137 $aGroups[] = $oG->getName();
2130 } 2138 }
2131 } 2139 }
2132 - 2140 +
2133 foreach (KTUtil::arrayGet($aAllowed,'role',array()) as $iRoleId) { 2141 foreach (KTUtil::arrayGet($aAllowed,'role',array()) as $iRoleId) {
2134 $oR = Role::get($iRoleId); 2142 $oR = Role::get($iRoleId);
2135 if (PEAR::isError($oR) || ($oR == false)) { 2143 if (PEAR::isError($oR) || ($oR == false)) {
@@ -2138,33 +2146,33 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2138,33 +2146,33 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2138 $aRoles[] = $oR->getName(); 2146 $aRoles[] = $oR->getName();
2139 } 2147 }
2140 } 2148 }
2141 - 2149 +
2142 $sNotify = ''; 2150 $sNotify = '';
2143 if (!empty($aUsers)) { 2151 if (!empty($aUsers)) {
2144 $sNotify .= '<em>' . _kt('Users') . ':</em> '; 2152 $sNotify .= '<em>' . _kt('Users') . ':</em> ';
2145 $sNotify .= implode(', ', $aUsers); 2153 $sNotify .= implode(', ', $aUsers);
2146 } 2154 }
2147 - 2155 +
2148 if (!empty($aGroups)) { 2156 if (!empty($aGroups)) {
2149 if (!empty($sNotify)) { $sNotify .= ' &mdash; '; } 2157 if (!empty($sNotify)) { $sNotify .= ' &mdash; '; }
2150 $sNotify .= '<em>' . _kt('Groups') . ':</em> '; 2158 $sNotify .= '<em>' . _kt('Groups') . ':</em> ';
2151 $sNotify .= implode(', ', $aGroups); 2159 $sNotify .= implode(', ', $aGroups);
2152 } 2160 }
2153 - 2161 +
2154 if (!empty($aRoles)) { 2162 if (!empty($aRoles)) {
2155 if (!empty($sNotify)) { $sNotify .= ' &mdash; '; } 2163 if (!empty($sNotify)) { $sNotify .= ' &mdash; '; }
2156 $sNotify .= '<em>' . _kt('Roles') . ':</em> '; 2164 $sNotify .= '<em>' . _kt('Roles') . ':</em> ';
2157 $sNotify .= implode(', ', $aRoles); 2165 $sNotify .= implode(', ', $aRoles);
2158 } 2166 }
2159 - 2167 +
2160 if (empty($sNotify)) { $sNotify = _kt('No notifications.'); } 2168 if (empty($sNotify)) { $sNotify = _kt('No notifications.'); }
2161 - 2169 +
2162 return $sNotify; 2170 return $sNotify;
2163 } 2171 }
2164 - 2172 +
2165 function descriptorToJSON($aAllowed) { 2173 function descriptorToJSON($aAllowed) {
2166 - $values = array();  
2167 - 2174 + $values = array();
  2175 +
2168 foreach (KTUtil::arrayGet($aAllowed,'user',array()) as $oU) { 2176 foreach (KTUtil::arrayGet($aAllowed,'user',array()) as $oU) {
2169 if (!is_object($oU)) { 2177 if (!is_object($oU)) {
2170 $iUserId = $oU; 2178 $iUserId = $oU;
@@ -2193,7 +2201,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2193,7 +2201,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2193 $values[sprintf("groups[%d]", $iGroupId)] = sprintf(_kt('Group: %s'), $oG->getName()); 2201 $values[sprintf("groups[%d]", $iGroupId)] = sprintf(_kt('Group: %s'), $oG->getName());
2194 } 2202 }
2195 } 2203 }
2196 - 2204 +
2197 foreach (KTUtil::arrayGet($aAllowed,'role',array()) as $oR) { 2205 foreach (KTUtil::arrayGet($aAllowed,'role',array()) as $oR) {
2198 if (!is_object($oR)) { 2206 if (!is_object($oR)) {
2199 $iRoleId = $oR; 2207 $iRoleId = $oR;
@@ -2208,10 +2216,10 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2208,10 +2216,10 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2208 $values[sprintf("roles[%d]", $iRoleId)] = sprintf(_kt('Role: %s'), $oR->getName()); 2216 $values[sprintf("roles[%d]", $iRoleId)] = sprintf(_kt('Role: %s'), $oR->getName());
2209 } 2217 }
2210 } 2218 }
2211 - 2219 +
2212 return $values; 2220 return $values;
2213 } 2221 }
2214 - 2222 +
2215 function form_editnotifications($oState) { 2223 function form_editnotifications($oState) {
2216 $oForm = new KTForm; 2224 $oForm = new KTForm;
2217 $oForm->setOptions(array( 2225 $oForm->setOptions(array(
@@ -2232,7 +2240,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2232,7 +2240,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2232 'src' => KTUtil::addQueryStringSelf($this->meldPersistQuery(array('json_action'=> 'notificationusers'), "json")), 2240 'src' => KTUtil::addQueryStringSelf($this->meldPersistQuery(array('json_action'=> 'notificationusers'), "json")),
2233 'value' => $this->descriptorToJSON($preval), 2241 'value' => $this->descriptorToJSON($preval),
2234 )), 2242 )),
2235 - )); 2243 + ));
2236 $oForm->setValidators(array( 2244 $oForm->setValidators(array(
2237 array('ktcore.validators.array', array( 2245 array('ktcore.validators.array', array(
2238 'test' => 'users', 2246 'test' => 'users',
@@ -2241,25 +2249,25 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2241,25 +2249,25 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2241 )); 2249 ));
2242 return $oForm; 2250 return $oForm;
2243 } 2251 }
2244 - 2252 +
2245 function do_editnotifications() { 2253 function do_editnotifications() {
2246 - $this->breadcrumb_effects(); 2254 + $this->breadcrumb_effects();
2247 $this->aBreadcrumbs[] = array( 2255 $this->aBreadcrumbs[] = array(
2248 'name' => _kt("Notifications"), 2256 'name' => _kt("Notifications"),
2249 - 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","managenotifications",true)), 2257 + 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","managenotifications",true)),
2250 ); 2258 );
2251 $this->aBreadcrumbs[] = array( 2259 $this->aBreadcrumbs[] = array(
2252 'name' => $this->oState->getHumanName(), 2260 'name' => $this->oState->getHumanName(),
2253 - ); 2261 + );
2254 $this->oPage->setBreadcrumbDetails(_kt("Edit State Notifications")); 2262 $this->oPage->setBreadcrumbDetails(_kt("Edit State Notifications"));
2255 - 2263 +
2256 $oForm = $this->form_editnotifications($this->oState); 2264 $oForm = $this->form_editnotifications($this->oState);
2257 - return $oForm->renderPage(); 2265 + return $oForm->renderPage();
2258 } 2266 }
2259 - 2267 +
2260 function do_savenotifications() { 2268 function do_savenotifications() {
2261 2269
2262 - 2270 +
2263 $oForm = $this->form_editnotifications($this->oState); 2271 $oForm = $this->form_editnotifications($this->oState);
2264 $res = $oForm->validate(); 2272 $res = $oForm->validate();
2265 2273
@@ -2273,62 +2281,62 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2273,62 +2281,62 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2273 // 2281 //
2274 // because its not *really* isolated properly, we need to post-process 2282 // because its not *really* isolated properly, we need to post-process
2275 // the data. 2283 // the data.
2276 - 2284 +
2277 // we need the old one 2285 // we need the old one
2278 $aAllowed = KTWorkflowUtil::getInformedForState($this->oState); 2286 $aAllowed = KTWorkflowUtil::getInformedForState($this->oState);
2279 - 2287 +
2280 $user_pattern = '|users\[(.*)\]|'; 2288 $user_pattern = '|users\[(.*)\]|';
2281 $group_pattern = '|groups\[(.*)\]|'; 2289 $group_pattern = '|groups\[(.*)\]|';
2282 - $role_pattern = '|roles\[(.*)\]|';  
2283 - 2290 + $role_pattern = '|roles\[(.*)\]|';
  2291 +
2284 $user = KTUtil::arrayGet($aAllowed, 'user', array()); 2292 $user = KTUtil::arrayGet($aAllowed, 'user', array());
2285 $group = KTUtil::arrayGet($aAllowed, 'group', array()); 2293 $group = KTUtil::arrayGet($aAllowed, 'group', array());
2286 $role = KTUtil::arrayGet($aAllowed, 'role', array()); 2294 $role = KTUtil::arrayGet($aAllowed, 'role', array());
2287 - 2295 +
2288 // do a quick overpass 2296 // do a quick overpass
2289 - $newAllowed = array(); 2297 + $newAllowed = array();
2290 if (!empty($user)) { $newAllowed['user'] = array_combine($user, $user); } 2298 if (!empty($user)) { $newAllowed['user'] = array_combine($user, $user); }
2291 - else { $newAllowed['user'] = array(); } 2299 + else { $newAllowed['user'] = array(); }
2292 if (!empty($group)) { $newAllowed['group'] = array_combine($group, $group); } 2300 if (!empty($group)) { $newAllowed['group'] = array_combine($group, $group); }
2293 else { $newAllowed['group'] = array(); } 2301 else { $newAllowed['group'] = array(); }
2294 - if (!empty($role)) { $newAllowed['role'] = array_combine($role, $role); }  
2295 - else { $newAllowed['role'] = array(); }  
2296 -  
2297 - $added = explode(',', $data['users']['added']);  
2298 - $removed = explode(',', $data['users']['removed']);  
2299 - 2302 + if (!empty($role)) { $newAllowed['role'] = array_combine($role, $role); }
  2303 + else { $newAllowed['role'] = array(); }
  2304 +
  2305 + $added = explode(',', $data['users']['added']);
  2306 + $removed = explode(',', $data['users']['removed']);
  2307 +
2300 foreach ($added as $akey) { 2308 foreach ($added as $akey) {
2301 $matches = array(); 2309 $matches = array();
2302 if (preg_match($user_pattern, $akey, $matches)) { $newAllowed['user'][$matches[1]] = $matches[1]; } 2310 if (preg_match($user_pattern, $akey, $matches)) { $newAllowed['user'][$matches[1]] = $matches[1]; }
2303 else if (preg_match($group_pattern, $akey, $matches)) { $newAllowed['group'][$matches[1]] = $matches[1]; } 2311 else if (preg_match($group_pattern, $akey, $matches)) { $newAllowed['group'][$matches[1]] = $matches[1]; }
2304 - else if (preg_match($role_pattern, $akey, $matches)) { $newAllowed['role'][$matches[1]] = $matches[1]; } 2312 + else if (preg_match($role_pattern, $akey, $matches)) { $newAllowed['role'][$matches[1]] = $matches[1]; }
2305 } 2313 }
2306 - 2314 +
2307 foreach ($removed as $akey) { 2315 foreach ($removed as $akey) {
2308 $matches = array(); 2316 $matches = array();
2309 if (preg_match($user_pattern, $akey, $matches)) { unset($newAllowed['user'][$matches[1]]); } 2317 if (preg_match($user_pattern, $akey, $matches)) { unset($newAllowed['user'][$matches[1]]); }
2310 else if (preg_match($group_pattern, $akey, $matches)) { unset($newAllowed['group'][$matches[1]]); } 2318 else if (preg_match($group_pattern, $akey, $matches)) { unset($newAllowed['group'][$matches[1]]); }
2311 else if (preg_match($role_pattern, $akey, $matches)) { unset($newAllowed['role'][$matches[1]]); } 2319 else if (preg_match($role_pattern, $akey, $matches)) { unset($newAllowed['role'][$matches[1]]); }
2312 - }  
2313 - 2320 + }
  2321 +
2314 // FIXME check that these are all users. 2322 // FIXME check that these are all users.
2315 -  
2316 - $res = KTWorkflowUtil::setInformedForState($this->oState, $newAllowed); 2323 +
  2324 + $res = KTWorkflowUtil::setInformedForState($this->oState, $newAllowed);
2317 if (PEAR::isError($res)) { 2325 if (PEAR::isError($res)) {
2318 return $oForm->handleError($res->getMessage()); 2326 return $oForm->handleError($res->getMessage());
2319 } 2327 }
2320 - 2328 +
2321 $this->successRedirectTo("managenotifications", _kt("Notifications updated.")); 2329 $this->successRedirectTo("managenotifications", _kt("Notifications updated."));
2322 } 2330 }
2323 - 2331 +
2324 function json_notificationusers() { 2332 function json_notificationusers() {
2325 $sFilter = KTUtil::arrayGet($_REQUEST, 'filter', false); 2333 $sFilter = KTUtil::arrayGet($_REQUEST, 'filter', false);
2326 if ($sFilter == false) { 2334 if ($sFilter == false) {
2327 - $values = array('off' => _kt('-- Please filter --')); // default 2335 + $values = array('off' => _kt('-- Please filter --')); // default
2328 } 2336 }
2329 $sFilter = trim($sFilter); 2337 $sFilter = trim($sFilter);
2330 $values = array('off' => _kt('-- Please filter --')); // default 2338 $values = array('off' => _kt('-- Please filter --')); // default
2331 - 2339 +
2332 if (!empty($sFilter)) { 2340 if (!empty($sFilter)) {
2333 $allowed = array(); 2341 $allowed = array();
2334 $q = sprintf('name like "%%%s%%"', DBUtil::escapeSimple($sFilter)); 2342 $q = sprintf('name like "%%%s%%"', DBUtil::escapeSimple($sFilter));
@@ -2338,29 +2346,29 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2338,29 +2346,29 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2338 $aRoles = Role::getList($q); 2346 $aRoles = Role::getList($q);
2339 2347
2340 $empty = true; 2348 $empty = true;
2341 - 2349 +
2342 if (!PEAR::isError($aUsers)) { 2350 if (!PEAR::isError($aUsers)) {
2343 $allowed['user'] = $aUsers; 2351 $allowed['user'] = $aUsers;
2344 - if (!empty($aUsers)) { 2352 + if (!empty($aUsers)) {
2345 $empty = false; 2353 $empty = false;
2346 } 2354 }
2347 } 2355 }
2348 2356
2349 if (!PEAR::isError($aGroups)) { 2357 if (!PEAR::isError($aGroups)) {
2350 $allowed['group'] = $aGroups; 2358 $allowed['group'] = $aGroups;
2351 - if (!empty($aGroups)) { 2359 + if (!empty($aGroups)) {
2352 $empty = false; 2360 $empty = false;
2353 - } 2361 + }
2354 } 2362 }
2355 - 2363 +
2356 if (!PEAR::isError($aRole)) { 2364 if (!PEAR::isError($aRole)) {
2357 $allowed['role'] = $aRoles; 2365 $allowed['role'] = $aRoles;
2358 - if (!empty($aRoles)) { 2366 + if (!empty($aRoles)) {
2359 $empty = false; 2367 $empty = false;
2360 } 2368 }
2361 -  
2362 - }  
2363 - 2369 +
  2370 + }
  2371 +
2364 if ($empty) { 2372 if ($empty) {
2365 $values = array('off'=>'-- No results --'); // default 2373 $values = array('off'=>'-- No results --'); // default
2366 } else { 2374 } else {
@@ -2370,78 +2378,78 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2370,78 +2378,78 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2370 2378
2371 return $values; 2379 return $values;
2372 } 2380 }
2373 - 2381 +
2374 /* ---------------- GraphViz / DOT support --------------- */ 2382 /* ---------------- GraphViz / DOT support --------------- */
2375 // 2383 //
2376 // FIXME detect and handle the support issues sanely. 2384 // FIXME detect and handle the support issues sanely.
2377 - 2385 +
2378 var $state_names; 2386 var $state_names;
2379 - var $transition_names;  
2380 - 2387 + var $transition_names;
  2388 +
2381 function get_graph($oWorkflow) { 2389 function get_graph($oWorkflow) {
2382 - 2390 +
2383 $fontsize = 11.0; 2391 $fontsize = 11.0;
2384 $fontname = "Times-Roman"; 2392 $fontname = "Times-Roman";
2385 - 2393 +
2386 $opts = array( 2394 $opts = array(
2387 'fontsize' => $fontsize, 2395 'fontsize' => $fontsize,
2388 'fontname' => $fontname, 2396 'fontname' => $fontname,
2389 - );  
2390 - 2397 + );
  2398 +
2391 $graph = new Image_GraphViz(true, $opts); 2399 $graph = new Image_GraphViz(true, $opts);
2392 - $graph->dotCommand = $this->dotCommand; 2400 + $graph->dotCommand = $this->dotCommand;
2393 2401
2394 // we need all states & transitions 2402 // we need all states & transitions
2395 // FIXME do we want guards? 2403 // FIXME do we want guards?
2396 - 2404 +
2397 // we want to enable link-editing, and indicate that transitions "converge" 2405 // we want to enable link-editing, and indicate that transitions "converge"
2398 // so we use a temporary "node" for transitions 2406 // so we use a temporary "node" for transitions
2399 // we also use a "fake" URL which we catch later 2407 // we also use a "fake" URL which we catch later
2400 // so we can give good "alt" tags. 2408 // so we can give good "alt" tags.
2401 - 2409 +
2402 $states = KTWorkflowState::getByWorkflow($oWorkflow); 2410 $states = KTWorkflowState::getByWorkflow($oWorkflow);
2403 $transitions = KTWorkflowTransition::getByWorkflow($oWorkflow); 2411 $transitions = KTWorkflowTransition::getByWorkflow($oWorkflow);
2404 2412
2405 $this->state_names = array(); 2413 $this->state_names = array();
2406 $this->transition_names = array(); 2414 $this->transition_names = array();
2407 - 2415 +
2408 $state_opts = array( 2416 $state_opts = array(
2409 'shape' => 'box', 2417 'shape' => 'box',
2410 - 'fontsize' => $fontsize,  
2411 - 'fontname' => $fontname, 2418 + 'fontsize' => $fontsize,
  2419 + 'fontname' => $fontname,
2412 ); 2420 );
2413 2421
2414 $transition_opts = array( 2422 $transition_opts = array(
2415 'shape' => 'box', 2423 'shape' => 'box',
2416 'color' => '#ffffff', 2424 'color' => '#ffffff',
2417 - 'fontsize' => $fontsize,  
2418 - 'fontname' => $fontname, 2425 + 'fontsize' => $fontsize,
  2426 + 'fontname' => $fontname,
2419 ); 2427 );
2420 2428
2421 $finaltransition_opts = array( 2429 $finaltransition_opts = array(
2422 - 'color' => '#333333', 2430 + 'color' => '#333333',
2423 ); 2431 );
2424 - 2432 +
2425 $sourcetransition_opts = array( 2433 $sourcetransition_opts = array(
2426 - 'color' => '#999999', 2434 + 'color' => '#999999',
2427 ); 2435 );
2428 - 2436 +
2429 // to make this a little more useful, we want to cascade our output from 2437 // to make this a little more useful, we want to cascade our output from
2430 // start to end states - this will tend to give a better output. 2438 // start to end states - this will tend to give a better output.
2431 // 2439 //
2432 - // to do this, we need to order our nodes in terms of "nearness" to the 2440 + // to do this, we need to order our nodes in terms of "nearness" to the
2433 // initial node. 2441 // initial node.
2434 - 2442 +
2435 $processing_nodes = array(); 2443 $processing_nodes = array();
2436 $sorted_ids = array(); 2444 $sorted_ids = array();
2437 - 2445 +
2438 $availability = array(); 2446 $availability = array();
2439 $sources = array(); 2447 $sources = array();
2440 $destinations = array(); 2448 $destinations = array();
2441 - 2449 +
2442 $states = KTUtil::keyArray($states); 2450 $states = KTUtil::keyArray($states);
2443 - $transitions = KTUtil::keyArray($transitions);  
2444 - 2451 + $transitions = KTUtil::keyArray($transitions);
  2452 +
2445 foreach ($transitions as $tid => $oTransition) { 2453 foreach ($transitions as $tid => $oTransition) {
2446 $sources[$tid] = KTWorkflowAdminUtil::getSourceStates($oTransition, array('ids' => true)); 2454 $sources[$tid] = KTWorkflowAdminUtil::getSourceStates($oTransition, array('ids' => true));
2447 $destinations[$tid] = $oTransition->getTargetStateId(); 2455 $destinations[$tid] = $oTransition->getTargetStateId();
@@ -2451,7 +2459,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2451,7 +2459,7 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2451 $availability[$sourcestateid] = $av; 2459 $availability[$sourcestateid] = $av;
2452 } 2460 }
2453 } 2461 }
2454 - 2462 +
2455 //var_dump($sources); exit(0); 2463 //var_dump($sources); exit(0);
2456 2464
2457 //var_dump($availability); exit(0); 2465 //var_dump($availability); exit(0);
@@ -2462,10 +2470,10 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2462,10 +2470,10 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2462 2470
2463 if (!$processing_nodes[$active]) { 2471 if (!$processing_nodes[$active]) {
2464 // mark that we've seen this node 2472 // mark that we've seen this node
2465 - 2473 +
2466 $processing_nodes[$active] = true; 2474 $processing_nodes[$active] = true;
2467 $sorted[] = $active; 2475 $sorted[] = $active;
2468 - 2476 +
2469 // now add all reachable nodes to the *end* of the queue. 2477 // now add all reachable nodes to the *end* of the queue.
2470 foreach ((array) $availability[$active] as $tid) { 2478 foreach ((array) $availability[$active] as $tid) {
2471 $next = $destinations[$tid]; 2479 $next = $destinations[$tid];
@@ -2474,76 +2482,76 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2474,76 +2482,76 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2474 } 2482 }
2475 } 2483 }
2476 } 2484 }
2477 - //var_dump($processing); 2485 + //var_dump($processing);
2478 } 2486 }
2479 - 2487 +
2480 //var_dump($sorted); exit(0); 2488 //var_dump($sorted); exit(0);
2481 2489
2482 foreach ($sorted as $sid) { 2490 foreach ($sorted as $sid) {
2483 - 2491 +
2484 $oState = $states[$sid]; 2492 $oState = $states[$sid];
2485 - 2493 +
2486 $this->state_names[$oState->getId()] = $oState->getHumanName(); 2494 $this->state_names[$oState->getId()] = $oState->getHumanName();
2487 - 2495 +
2488 $local_opts = array( 2496 $local_opts = array(
2489 'URL' => sprintf("s%d", $oState->getId()), 2497 'URL' => sprintf("s%d", $oState->getId()),
2490 'label' => $oState->getHumanName(), 2498 'label' => $oState->getHumanName(),
2491 'color' => '#666666', 2499 'color' => '#666666',
2492 ); 2500 );
2493 if ($oState->getId() == $oWorkflow->getStartStateId()) { 2501 if ($oState->getId() == $oWorkflow->getStartStateId()) {
2494 - $local_opts['color'] = '#000000';  
2495 - $local_opts['style'] = 'filled';  
2496 - $local_opts['fillcolor'] = '#cccccc'; 2502 + $local_opts['color'] = '#000000';
  2503 + $local_opts['style'] = 'filled';
  2504 + $local_opts['fillcolor'] = '#cccccc';
2497 } 2505 }
2498 - 2506 +
2499 $graph->addNode( 2507 $graph->addNode(
2500 sprintf('state%d', $oState->getId()), 2508 sprintf('state%d', $oState->getId()),
2501 - KTUtil::meldOptions($state_opts, $local_opts)); 2509 + KTUtil::meldOptions($state_opts, $local_opts));
2502 } 2510 }
2503 - 2511 +
2504 foreach ($transitions as $tid => $oTransition) { 2512 foreach ($transitions as $tid => $oTransition) {
2505 $name = sprintf('transition%d', $tid); 2513 $name = sprintf('transition%d', $tid);
2506 - $this->transition_names[$oTransition->getId()] = $oTransition->getHumanName();  
2507 - // we "cheat" and use  
2508 - 2514 + $this->transition_names[$oTransition->getId()] = $oTransition->getHumanName();
  2515 + // we "cheat" and use
  2516 +
2509 $graph->addNode( 2517 $graph->addNode(
2510 $name, 2518 $name,
2511 - KTUtil::meldOptions($transition_opts, 2519 + KTUtil::meldOptions($transition_opts,
2512 array( 2520 array(
2513 'URL' => sprintf("t%d", $tid), 2521 'URL' => sprintf("t%d", $tid),
2514 'label' => $oTransition->getHumanName(), 2522 'label' => $oTransition->getHumanName(),
2515 ) 2523 )
2516 )); 2524 ));
2517 - 2525 +
2518 $dest = sprintf("state%d", $oTransition->getTargetStateId()); 2526 $dest = sprintf("state%d", $oTransition->getTargetStateId());
2519 2527
2520 - 2528 +
2521 $graph->addEdge( 2529 $graph->addEdge(
2522 array($name => $dest), 2530 array($name => $dest),
2523 $finaltransition_opts 2531 $finaltransition_opts
2524 - );  
2525 - 2532 + );
  2533 +
2526 foreach ($sources[$tid] as $source_id) { 2534 foreach ($sources[$tid] as $source_id) {
2527 $source_name = sprintf("state%d", $source_id); 2535 $source_name = sprintf("state%d", $source_id);
2528 $graph->addEdge( 2536 $graph->addEdge(
2529 array($source_name => $name), 2537 array($source_name => $name),
2530 $sourcetransition_opts 2538 $sourcetransition_opts
2531 - ); 2539 + );
2532 } 2540 }
2533 } 2541 }
2534 - 2542 +
2535 // some simple analysis 2543 // some simple analysis
2536 - 2544 +
2537 $errors = array(); 2545 $errors = array();
2538 $info = array(); 2546 $info = array();
2539 - 2547 +
2540 $sourceless_transitions = array(); 2548 $sourceless_transitions = array();
2541 foreach ($transitions as $tid => $oTransition) { 2549 foreach ($transitions as $tid => $oTransition) {
2542 if (empty($sources[$tid])) { 2550 if (empty($sources[$tid])) {
2543 $sourceless_transitions[] = $oTransition->getHumanName(); 2551 $sourceless_transitions[] = $oTransition->getHumanName();
2544 } 2552 }
2545 } 2553 }
2546 - 2554 +
2547 if (!empty($sourceless_transitions)) { 2555 if (!empty($sourceless_transitions)) {
2548 $errors[] = sprintf(_kt("Some transitions have no source states: %s"), implode(', ', $sourceless_transitions)); 2556 $errors[] = sprintf(_kt("Some transitions have no source states: %s"), implode(', ', $sourceless_transitions));
2549 } 2557 }
@@ -2566,26 +2574,26 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2566,26 +2574,26 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2566 2574
2567 return $data; 2575 return $data;
2568 } 2576 }
2569 - 2577 +
2570 function do_graphimage() { 2578 function do_graphimage() {
2571 header('Content-Type: image/jpeg'); 2579 header('Content-Type: image/jpeg');
2572 $graph = $this->get_graph($this->oWorkflow); 2580 $graph = $this->get_graph($this->oWorkflow);
2573 $graph['graph']->image('jpeg'); 2581 $graph['graph']->image('jpeg');
2574 - exit(0); 2582 + exit(0);
2575 } 2583 }
2576 - 2584 +
2577 function do_graphrepresentation() { 2585 function do_graphrepresentation() {
2578 $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/graphrep'); 2586 $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/graphrep');
2579 - 2587 +
2580 // this is not ideal 2588 // this is not ideal
2581 // is there no way to get graphviz to give us this more "usefully" 2589 // is there no way to get graphviz to give us this more "usefully"
2582 - $graph = $this->get_graph($this->oWorkflow); 2590 + $graph = $this->get_graph($this->oWorkflow);
2583 $rdata = $graph['graph']->fetch("imap"); 2591 $rdata = $graph['graph']->fetch("imap");
2584 - 2592 +
2585 // we can skip some of this. 2593 // we can skip some of this.
2586 $data = explode("\n", $rdata); 2594 $data = explode("\n", $rdata);
2587 $data = array_slice($data, 1, -1); 2595 $data = array_slice($data, 1, -1);
2588 - 2596 +
2589 if (false) { 2597 if (false) {
2590 print '<pre>'; 2598 print '<pre>';
2591 print print_r($data, true); exit(0); 2599 print print_r($data, true); exit(0);
@@ -2593,20 +2601,20 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2593,20 +2601,20 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2593 $pat = '|^([\w]+). # rect, circle, etc. 2601 $pat = '|^([\w]+). # rect, circle, etc.
2594 ([^ ]+). # href 2602 ([^ ]+). # href
2595 ([\d]+), # x0 2603 ([\d]+), # x0
2596 - ([\d]+). # x1 2604 + ([\d]+). # x1
2597 ([\d]+), # y0 2605 ([\d]+), # y0
2598 - ([\d]+) # y1 2606 + ([\d]+) # y1
2599 |x'; 2607 |x';
2600 - 2608 +
2601 $coords = array(); 2609 $coords = array();
2602 foreach ($data as $row) { 2610 foreach ($data as $row) {
2603 $matches = array(); 2611 $matches = array();
2604 if (preg_match($pat, $row, $matches)) { 2612 if (preg_match($pat, $row, $matches)) {
2605 $rowdata = array_slice($matches, 1); 2613 $rowdata = array_slice($matches, 1);
2606 list($shape, $href, $x0, $y0, $x1, $y1) = $rowdata; 2614 list($shape, $href, $x0, $y0, $x1, $y1) = $rowdata;
2607 - 2615 +
2608 // FIXME sanity check, we only handle "rect" 2616 // FIXME sanity check, we only handle "rect"
2609 - 2617 +
2610 $real_href = null; 2618 $real_href = null;
2611 $m = array(); 2619 $m = array();
2612 $alt = null; 2620 $alt = null;
@@ -2615,8 +2623,8 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2615,8 +2623,8 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2615 $real_href = KTUtil::addQueryStringSelf($this->meldPersistQuery(array('fStateId' => $m[2]), "editstate")); 2623 $real_href = KTUtil::addQueryStringSelf($this->meldPersistQuery(array('fStateId' => $m[2]), "editstate"));
2616 $alt = sprintf('Edit State "%s"', $this->state_names[$m[2]]); 2624 $alt = sprintf('Edit State "%s"', $this->state_names[$m[2]]);
2617 } else { 2625 } else {
2618 - $real_href = KTUtil::addQueryStringSelf($this->meldPersistQuery(array('fTransitionId' => $m[2]), "edittransition"));  
2619 - $alt = sprintf('Edit Transition "%s"', $this->transition_names[$m[2]]); 2626 + $real_href = KTUtil::addQueryStringSelf($this->meldPersistQuery(array('fTransitionId' => $m[2]), "edittransition"));
  2627 + $alt = sprintf('Edit Transition "%s"', $this->transition_names[$m[2]]);
2620 } 2628 }
2621 } 2629 }
2622 $coords[] = array( 2630 $coords[] = array(
@@ -2625,12 +2633,12 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2625,12 +2633,12 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2625 'coords' => sprintf("%d,%d,%d,%d", $x0, $y0, $x1, $y1), 2633 'coords' => sprintf("%d,%d,%d,%d", $x0, $y0, $x1, $y1),
2626 'alt' => $alt, 2634 'alt' => $alt,
2627 ); 2635 );
2628 -  
2629 2636
2630 - }  
2631 - } 2637 +
  2638 + }
  2639 + }
2632 if (false) { 2640 if (false) {
2633 - print '<pre>'; var_dump($coords); exit(0); 2641 + print '<pre>'; var_dump($coords); exit(0);
2634 } 2642 }
2635 $oTemplate->setData(array( 2643 $oTemplate->setData(array(
2636 'context' => $this, 2644 'context' => $this,
@@ -2639,8 +2647,8 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { @@ -2639,8 +2647,8 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
2639 print $oTemplate->render(); 2647 print $oTemplate->render();
2640 exit(0); 2648 exit(0);
2641 } 2649 }
2642 -  
2643 - 2650 +
  2651 +
2644 } 2652 }
2645 2653
2646 ?> 2654 ?>