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