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