Commit 77d3d61a42f5f6a61fa135d60cdd6160509769a8

Authored by Megan Watson
1 parent bc6fbad2

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