[795] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * -------------------------------------------- * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 7 | * under the terms of the GNU General Public License as published by the * |
---|
| 8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 9 | * option) any later version. * |
---|
| 10 | \**************************************************************************/ |
---|
| 11 | |
---|
[2372] | 12 | require_once(dirname(__FILE__) . SEP . 'common.inc.php'); /* including common deifinitions */ |
---|
[795] | 13 | require_once(dirname(__FILE__) . SEP . 'class.WorkflowUtils.inc.php' ); /* superclass source code */ |
---|
| 14 | require_once(dirname(__FILE__) . SEP . 'class.basecontroller.inc.php' ); /* module controller */ |
---|
| 15 | require_once(dirname(__FILE__) . SEP . 'class.basemodel.inc.php' ); /* module logic */ |
---|
| 16 | |
---|
| 17 | /** |
---|
| 18 | * @package Workflow |
---|
| 19 | * @author Mauricio Luiz Viani - viani@celepar.pr.gov.br |
---|
| 20 | * @author Sidnei Augusto Drovetto Jr. - drovetto@gmail.com |
---|
| 21 | * @author Carlos Eduardo Nogueira Goncalves - cadu.br@gmail.com |
---|
| 22 | * @license GPL |
---|
| 23 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 24 | */ |
---|
| 25 | class run_activity extends WorkflowUtils |
---|
[3061] | 26 | { |
---|
[795] | 27 | /** |
---|
| 28 | * @var array $public_functions func |
---|
| 29 | * @access public |
---|
| 30 | */ |
---|
| 31 | var $public_functions = array( |
---|
| 32 | 'go' => true, |
---|
| 33 | 'goAjax' => true |
---|
| 34 | ); |
---|
| 35 | /** |
---|
| 36 | * @var object $runtime Runtime Object from the workflow engine |
---|
| 37 | * @access public |
---|
| 38 | */ |
---|
| 39 | var $runtime; |
---|
| 40 | // This is the object we'll be running to obtain the rigth activity |
---|
| 41 | //var $base_activity; |
---|
| 42 | //This is the right activity object |
---|
| 43 | /** |
---|
| 44 | * @var object $activity Activity engine object. |
---|
| 45 | * @access public |
---|
| 46 | */ |
---|
| 47 | var $activity; |
---|
| 48 | /** |
---|
| 49 | * @var object $process Process engine object. Used to retrieve at least paths and configuration values |
---|
| 50 | * @access public |
---|
| 51 | */ |
---|
[3061] | 52 | var $process; |
---|
[795] | 53 | /** |
---|
| 54 | * @var object $GUI GUI engine object. Act carefully with it. |
---|
| 55 | * @access public |
---|
| 56 | */ |
---|
| 57 | var $GUI; |
---|
| 58 | /** |
---|
| 59 | * @var array $message a message array |
---|
| 60 | * @access public |
---|
| 61 | */ |
---|
| 62 | var $message = Array(); |
---|
| 63 | /** |
---|
[3061] | 64 | * @var object $categories categorie object for categories |
---|
[795] | 65 | * @access public |
---|
| 66 | */ |
---|
| 67 | var $categories; |
---|
| 68 | /** |
---|
[3061] | 69 | * @var array $conf |
---|
[795] | 70 | * @access public |
---|
| 71 | */ |
---|
[3061] | 72 | var $conf = array(); |
---|
[795] | 73 | /** |
---|
| 74 | * @var $wf_template local activity template |
---|
| 75 | * @access public |
---|
| 76 | */ |
---|
| 77 | var $wf_template; |
---|
[3061] | 78 | /** |
---|
[795] | 79 | * @var object $instance |
---|
| 80 | * @access public |
---|
| 81 | */ |
---|
| 82 | var $instance; |
---|
[3061] | 83 | /** |
---|
[795] | 84 | * @var object $activity_type The type of activity |
---|
| 85 | * @access public |
---|
| 86 | */ |
---|
| 87 | var $activity_type; |
---|
| 88 | // then we retain all usefull vars as members, to make them avaible in user's source code |
---|
| 89 | // theses are data which can be set before the user code and which are not likely to change because of the user code |
---|
[3061] | 90 | /** |
---|
| 91 | * @var int $process_id The process id |
---|
[795] | 92 | * @access public |
---|
| 93 | */ |
---|
| 94 | var $process_id; |
---|
[3061] | 95 | /** |
---|
| 96 | * @var int $activity_id The activity id |
---|
[795] | 97 | * @access public |
---|
| 98 | */ |
---|
| 99 | var $activity_id; |
---|
[3061] | 100 | /** |
---|
[795] | 101 | * @var int $process_name The process name |
---|
| 102 | * @access public |
---|
| 103 | */ |
---|
| 104 | var $process_name; |
---|
[3061] | 105 | /** |
---|
| 106 | * @var int $process_version The process_version |
---|
[795] | 107 | * @access public |
---|
| 108 | */ |
---|
| 109 | var $process_version; |
---|
[3061] | 110 | /** |
---|
| 111 | * @var int $activity_name The process id |
---|
[795] | 112 | * @access public |
---|
| 113 | */ |
---|
| 114 | var $activity_name; |
---|
[3061] | 115 | /** |
---|
| 116 | * @var int $user_name The user name |
---|
[795] | 117 | * @access public |
---|
| 118 | */ |
---|
| 119 | var $user_name; |
---|
[3061] | 120 | /** |
---|
| 121 | * @var int $view_activity activity id of the view activity avaible for this process |
---|
[795] | 122 | * @access public |
---|
| 123 | */ |
---|
| 124 | var $view_activity; |
---|
[3061] | 125 | // theses 4 vars aren't avaible for the user code, they're set only after this user code was executed |
---|
| 126 | /** |
---|
| 127 | * @var int $instance_id Instance id |
---|
[795] | 128 | * @access public |
---|
| 129 | */ |
---|
| 130 | var $instance_id=0; |
---|
[3061] | 131 | /** |
---|
| 132 | * @var string $instance_name Instance name |
---|
[795] | 133 | * @access public |
---|
| 134 | */ |
---|
| 135 | var $instance_name=''; |
---|
[3061] | 136 | /** |
---|
| 137 | * @var int $instance_owner Instance owner id |
---|
[795] | 138 | * @access public |
---|
| 139 | */ |
---|
| 140 | var $instance_owner=0; |
---|
[3061] | 141 | /** |
---|
| 142 | * @var string $owner_name Owner name |
---|
[795] | 143 | * @access public |
---|
| 144 | */ |
---|
| 145 | var $owner_name=''; |
---|
[3061] | 146 | |
---|
[795] | 147 | /** |
---|
| 148 | * @var bool $print_mode print mode |
---|
| 149 | * @access public |
---|
| 150 | */ |
---|
| 151 | var $print_mode = false; |
---|
| 152 | /** |
---|
| 153 | * @var bool $enable_print_mode print mode |
---|
| 154 | * @access public |
---|
| 155 | */ |
---|
| 156 | var $enable_print_mode = false; |
---|
[3061] | 157 | |
---|
[795] | 158 | /** |
---|
| 159 | * @var array $act_role_names of roles associated with the activity, usefull for lists of users associated with theses roles |
---|
[3061] | 160 | * @access public |
---|
[795] | 161 | */ |
---|
| 162 | var $act_role_names= Array(); |
---|
[3061] | 163 | |
---|
[795] | 164 | /** |
---|
| 165 | * @var array $agents Array of ui_agent objects |
---|
| 166 | * @access public |
---|
| 167 | */ |
---|
| 168 | var $agents = Array(); |
---|
| 169 | |
---|
| 170 | /** |
---|
| 171 | * @var object $smarty holds a Smarty instance |
---|
| 172 | * @access public |
---|
| 173 | */ |
---|
[3061] | 174 | var $smarty; |
---|
[795] | 175 | /** |
---|
| 176 | * @var array $wf holds a global environment vector |
---|
| 177 | * @access public |
---|
| 178 | */ |
---|
[3061] | 179 | var $wf; |
---|
[795] | 180 | /** |
---|
| 181 | * @var $download_mode activates download mode |
---|
| 182 | * @access public |
---|
| 183 | */ |
---|
[3061] | 184 | var $download_mode; |
---|
[795] | 185 | /** |
---|
| 186 | * @var string $_template_name holds the template's file name |
---|
| 187 | * @access public |
---|
| 188 | */ |
---|
[3061] | 189 | var $_template_name = null; |
---|
[795] | 190 | /** |
---|
| 191 | * @var bool Indicates wether the current instance is a child instance or not |
---|
| 192 | * @access public |
---|
| 193 | */ |
---|
| 194 | var $isChildInstance = false; |
---|
[3061] | 195 | |
---|
[2588] | 196 | /** |
---|
| 197 | * @var object Stores a 'workflow_smarty' object |
---|
| 198 | * @access private |
---|
| 199 | */ |
---|
[795] | 200 | private $workflowSmarty = null; |
---|
[2588] | 201 | |
---|
[795] | 202 | /** |
---|
[3061] | 203 | * @var object Log Object |
---|
| 204 | * @access private |
---|
| 205 | */ |
---|
| 206 | private $logger = null; |
---|
| 207 | |
---|
| 208 | /** |
---|
[795] | 209 | * Constructor |
---|
[3061] | 210 | * |
---|
| 211 | * @access public |
---|
[795] | 212 | */ |
---|
| 213 | function run_activity() |
---|
| 214 | { |
---|
| 215 | parent::WorkflowUtils(); |
---|
[2372] | 216 | |
---|
| 217 | /** |
---|
| 218 | * We should always use newInstance to instantiate |
---|
| 219 | * 'workflow_wfruntime' |
---|
| 220 | */ |
---|
| 221 | $this->runtime = &Factory::newInstance('workflow_wfruntime'); |
---|
[795] | 222 | $this->runtime->setDebug(_DEBUG); |
---|
[2372] | 223 | $this->GUI = &Factory::getInstance('workflow_gui'); |
---|
| 224 | $this->categories = &Factory::getInstance('categories'); |
---|
[795] | 225 | |
---|
[2372] | 226 | $this->workflowSmarty = &Factory::getInstance('workflow_smarty', false); |
---|
[2588] | 227 | |
---|
[3061] | 228 | // never configure a log of type "firebug" here. This will make goAjax stop running well =( |
---|
| 229 | $this->logger = &Factory::getInstance('Logger', array('file')); |
---|
| 230 | |
---|
[795] | 231 | // TODO: open a new connection to the database under a different username to allow privilege handling on tables |
---|
| 232 | unset($this->db); |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | /** |
---|
| 236 | * This function is used to run all activities for specified instances. it could be interactive activities |
---|
| 237 | * or automatic activities. this second case is the reason why we return some values |
---|
| 238 | * @param int $activityId is the activity_id it run |
---|
| 239 | * @param int $iid is the instance id it run for |
---|
| 240 | * @param $auto is true by default |
---|
| 241 | * @return mixed AN ARRAY, or at least true or false. This array can contain : |
---|
| 242 | * a key 'failure' with an error string the engine will retrieve in instance error messages in case of |
---|
| 243 | * failure (this will mark your execution as Bad), |
---|
| 244 | * a key 'debug' with a debug string the engine will retrieve in instance error messages, |
---|
| 245 | */ |
---|
| 246 | function go($activity_id=0, $iid=0, $auto=0) |
---|
| 247 | { |
---|
[3061] | 248 | $totalTime = microtime(true); |
---|
| 249 | |
---|
[795] | 250 | $result=Array(); |
---|
| 251 | |
---|
| 252 | if ($iid) |
---|
| 253 | { |
---|
| 254 | $_REQUEST['iid'] = $iid; |
---|
| 255 | } |
---|
| 256 | $iid = $_REQUEST['iid']; |
---|
| 257 | |
---|
| 258 | //$activity_id is set when we are in auto mode. In interactive mode we get if from POST or GET |
---|
| 259 | if (!$activity_id) |
---|
| 260 | { |
---|
| 261 | $activity_id = (int)get_var('activity_id', array('GET','POST'), 0); |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | // load activity and instance |
---|
| 265 | if (!$activity_id) |
---|
| 266 | { |
---|
| 267 | $result['failure'] = $this->runtime->fail(lang('Cannot run unknown activity'), true, _DEBUG, $auto); |
---|
| 268 | return $result; |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | //initalising activity and instance objects inside the WfRuntime object |
---|
| 272 | if (!($this->runtime->loadRuntime($activity_id,$iid))) |
---|
| 273 | { |
---|
| 274 | $result['failure'] = $this->runtime->fail(lang('Cannot run the activity'), true, _DEBUG, $auto); |
---|
| 275 | return $result; |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | $activity =& $this->runtime->getActivity($activity_id, true, true); |
---|
| 279 | $this->activity =& $activity; |
---|
| 280 | // the instance is avaible with $instance or $this->instance |
---|
| 281 | // note that for standalone activities this instance can be an empty instance object, but false is a bad value |
---|
| 282 | //$this->instance =& $this->runtime->loadInstance($iid); |
---|
| 283 | |
---|
| 284 | // HERE IS A BIG POINT: we map the instance to a runtime object |
---|
| 285 | // user code will manipulate a stance, thinking it's an instance, but it is |
---|
| 286 | // in fact a WfRuntime object, mapping all instance functions |
---|
| 287 | $this->instance =& $this->runtime; |
---|
| 288 | $instance =& $this->instance; |
---|
| 289 | $GLOBALS['workflow']['wf_runtime'] =& $this->runtime; |
---|
| 290 | if (!($instance)) |
---|
| 291 | { |
---|
| 292 | $result['failure'] = $this->runtime->fail(lang('Cannot run the activity without instance'), true, _DEBUG, $auto); |
---|
| 293 | return $result; |
---|
| 294 | } |
---|
| 295 | $this->instance_id = $instance->getInstanceId(); |
---|
| 296 | |
---|
| 297 | // load process |
---|
| 298 | $this->process =& $this->runtime->getProcess(); |
---|
| 299 | if (!($this->process)) |
---|
| 300 | { |
---|
| 301 | $result['failure'] = $this->runtime->fail(lang('Cannot run the activity without her process').$instance, true, _DEBUG, $auto); |
---|
| 302 | return $result; |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | //set some global variables needed |
---|
| 306 | $GLOBALS['workflow']['__leave_activity']=false; |
---|
| 307 | $GLOBALS['user'] = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
| 308 | |
---|
| 309 | //load role names, just an information |
---|
| 310 | $this->act_role_names = $activity->getActivityRoleNames(); |
---|
| 311 | |
---|
| 312 | //set some other usefull vars |
---|
| 313 | $this->activity_type = $activity->getType(); |
---|
| 314 | $this->process_id = $activity->getProcessId(); |
---|
| 315 | $this->activity_id = $activity_id; |
---|
| 316 | $this->process_name = $this->process->getName(); |
---|
| 317 | $this->process_version = $this->process->getVersion(); |
---|
| 318 | $this->activity_name = $activity->getName(); |
---|
[2372] | 319 | $this->user_name = $GLOBALS['phpgw']->accounts->id2name($GLOBALS['user']); |
---|
[795] | 320 | $this->view_activity = $this->GUI->gui_get_process_view_activity($this->process_id); |
---|
| 321 | |
---|
| 322 | //we set them in $GLOBALS['workflow'] as well |
---|
| 323 | $GLOBALS['workflow']['wf_activity_type'] =& $this->activity_type; |
---|
| 324 | $GLOBALS['workflow']['wf_process_id'] =& $this->process_id; |
---|
| 325 | $GLOBALS['workflow']['wf_activity_id'] =& $this->activity_id; |
---|
| 326 | $GLOBALS['workflow']['wf_process_name'] =& $this->process_name; |
---|
| 327 | $GLOBALS['workflow']['wf_normalized_name'] = $this->process->getNormalizedName(); |
---|
| 328 | $GLOBALS['workflow']['wf_process_version'] =& $this->process_version; |
---|
| 329 | $GLOBALS['workflow']['wf_activity_name'] =& $this->activity_name; |
---|
| 330 | $GLOBALS['workflow']['wf_user_name'] =& $this->user_name; |
---|
| 331 | $GLOBALS['workflow']['wf_user_id'] =& $GLOBALS['user']; |
---|
| 332 | $GLOBALS['workflow']['wf_view_activity'] =& $this->view_activity; |
---|
[2061] | 333 | $GLOBALS['workflow']['wf_webserver_url'] = $GLOBALS['phpgw_info']['server']['webserver_url']; |
---|
[795] | 334 | $GLOBALS['workflow']['wf_workflow_path'] = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'; |
---|
| 335 | $GLOBALS['workflow']['wf_resources_path'] = $GLOBALS['phpgw_info']['server']['webserver_url'] . SEP . 'workflow/redirect.php?pid=' . $this->process_id . '&file='; |
---|
[2372] | 336 | $GLOBALS['workflow']['wf_default_resources_path'] = Factory::getInstance('TemplateServer')->generateLink('processes'); |
---|
| 337 | $GLOBALS['workflow']['wf_workflow_resources_path'] = Factory::getInstance('TemplateServer')->generateLink(''); |
---|
[795] | 338 | $GLOBALS['workflow']['wf_activity_url'] = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'index.php?menuaction=workflow.'.get_class($this).'.go&activity_id='.$activity_id; |
---|
[2372] | 339 | $GLOBALS['workflow']['wf_user_cnname'] = Factory::getInstance('WorkflowLDAP')->getName($GLOBALS['user']); |
---|
[795] | 340 | $GLOBALS['workflow']['wf_back_link'] = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'.SEP.'index.php?start_tab=1'; |
---|
| 341 | $GLOBALS['workflow']['wf_js_path'] = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'.SEP.'js'.SEP.'jscode'; |
---|
| 342 | $GLOBALS['workflow']['wf_user_activities'] = $this->GUI->gui_list_user_activities($GLOBALS['user'], '0', '-1', 'ga.wf_name__ASC', '', '', false, true, true, true, ''); |
---|
| 343 | if ($iid) |
---|
| 344 | $GLOBALS['workflow']['wf_instance_url'] = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'index.php?menuaction=workflow.'.get_class($this).'.go&activity_id='.$activity_id."&iid=".$iid; |
---|
| 345 | else |
---|
| 346 | unset($GLOBALS['workflow']['wf_instance_url']); |
---|
| 347 | $wf =& $GLOBALS['workflow']; |
---|
| 348 | |
---|
| 349 | /* path to the local functions developed by Celepar */ |
---|
| 350 | $functions = PHPGW_SERVER_ROOT . SEP . 'workflow' . SEP . 'inc' . SEP . 'local' . SEP . 'functions' . SEP . 'local.functions.php'; |
---|
| 351 | |
---|
| 352 | /* activate local functions */ |
---|
| 353 | require_once($functions); |
---|
| 354 | |
---|
| 355 | //get configuration options with default values if no init was done before |
---|
| 356 | $myconf = array( |
---|
| 357 | 'execute_activities_in_debug_mode' => 0, |
---|
| 358 | 'execute_activities_using_secure_connection' => 0 |
---|
| 359 | ); |
---|
| 360 | //this will give use asked options and som others used by WfRuntime |
---|
| 361 | $this->conf =& $this->runtime->getConfigValues($myconf); |
---|
| 362 | if ($this->conf['execute_activities_using_secure_connection']) |
---|
| 363 | { |
---|
| 364 | if (($GLOBALS['phpgw_info']['server']['use_https'] > 0) && ($_SERVER['HTTPS'] != 'on') && (!isset($GLOBALS['workflow']['job']['processID']))) |
---|
| 365 | { |
---|
| 366 | header("Location: https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"); |
---|
| 367 | exit; |
---|
| 368 | } |
---|
| 369 | } |
---|
| 370 | |
---|
| 371 | if ($auto && (!$this->isChildInstance) && $activity->isInteractive()) |
---|
| 372 | { |
---|
| 373 | $actualUser = $GLOBALS['user']; |
---|
| 374 | $actualUserGroups = $_SESSION['phpgw_info']['workflow']['user_groups']; |
---|
| 375 | foreach ($instance->instance->activities as $actTmp) |
---|
| 376 | { |
---|
| 377 | if ($actTmp['wf_activity_id'] == $activity_id) |
---|
| 378 | { |
---|
| 379 | $newUser = $actTmp['wf_user']; |
---|
| 380 | break; |
---|
| 381 | } |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | /* pretend to be the user */ |
---|
| 385 | $_SESSION['phpgw_info']['workflow']['user_groups'] = galaxia_retrieve_user_groups($newUser); |
---|
| 386 | $_SESSION['phpgw_info']['workflow']['account_id'] = $newUser; |
---|
| 387 | $GLOBALS['phpgw_info']['user']['account_id'] = $newUser; |
---|
| 388 | $GLOBALS['workflow']['wf_user_id'] = $newUser; |
---|
| 389 | $GLOBALS['user'] = $newUser; |
---|
| 390 | |
---|
| 391 | /* check some permissions */ |
---|
[2372] | 392 | if (($newUser == '*') || (!$this->runtime->checkUserRun($newUser)) || (Factory::getInstance('WorkflowLDAP')->getName($newUser) === false)) |
---|
[795] | 393 | { |
---|
| 394 | $_SESSION['phpgw_info']['workflow']['user_groups'] = $actualUserGroups; |
---|
| 395 | $_SESSION['phpgw_info']['workflow']['account_id'] = $actualUser; |
---|
| 396 | $GLOBALS['phpgw_info']['user']['account_id'] = $actualUser; |
---|
| 397 | $GLOBALS['workflow']['wf_user_id'] = $actualUser; |
---|
| 398 | $GLOBALS['user'] = $actualUser; |
---|
| 399 | |
---|
| 400 | return false; |
---|
| 401 | } |
---|
[2372] | 402 | $smarty = Factory::getInstance('process_smarty'); |
---|
[795] | 403 | } |
---|
| 404 | |
---|
| 405 | // run the activity |
---|
| 406 | //interactive section |
---|
| 407 | if (!$auto && $activity->isInteractive()) |
---|
| 408 | { |
---|
| 409 | |
---|
| 410 | $this->print_mode = get_var('print_mode', array('POST','GET'), false); |
---|
| 411 | $this->download_mode = get_var('download_mode', array('POST','GET'), false); |
---|
| 412 | |
---|
[2372] | 413 | $smarty = Factory::getInstance('process_smarty'); |
---|
[795] | 414 | |
---|
| 415 | $smarty->template_dir = GALAXIA_PROCESSES.SEP.$this->process->getNormalizedName().SEP.'code'.SEP.'templates'; |
---|
| 416 | $smarty->compile_dir = GALAXIA_PROCESSES.SEP.$this->process->getNormalizedName().SEP.'smarty'.SEP.'compiled'; |
---|
| 417 | $smarty->config_dir = GALAXIA_PROCESSES.SEP.$this->process->getNormalizedName().SEP.'code'.SEP.'templates'; |
---|
| 418 | $smarty->cache_dir = GALAXIA_PROCESSES.SEP.$this->process->getNormalizedName().SEP.'smarty'.SEP.'cache'; |
---|
| 419 | $smarty->plugins_dir[] = PHPGW_SERVER_ROOT.SEP.'workflow'.SEP.'inc'.SEP.'smarty'.SEP.'wf_plugins'; |
---|
| 420 | |
---|
| 421 | $GLOBALS['phpgw']->template =& $smarty; |
---|
| 422 | $this->wf_template =& $smarty; |
---|
| 423 | $_template_name = null; |
---|
| 424 | |
---|
| 425 | //set resource path to use in templates |
---|
| 426 | $smarty->assign('wf_resources_path',$GLOBALS['workflow']['wf_resources_path']); |
---|
| 427 | $smarty->assign('wf_default_resources_path', $GLOBALS['workflow']['wf_default_resources_path']); |
---|
| 428 | $smarty->assign('wf_workflow_resources_path', $GLOBALS['workflow']['wf_workflow_resources_path']); |
---|
| 429 | $smarty->assign('wf_workflow_path',$GLOBALS['workflow']['wf_workflow_path']); |
---|
| 430 | $smarty->assign('wf_js_path',$GLOBALS['workflow']['wf_js_path']); |
---|
| 431 | $smarty->assign('wf_back_link',$GLOBALS['workflow']['wf_back_link']); |
---|
| 432 | $smarty->assign('wf_activity_url',$GLOBALS['workflow']['wf_activity_url']); |
---|
[2588] | 433 | |
---|
[795] | 434 | /* register the prefilter smarty plugin wf_default_template */ |
---|
| 435 | $smarty->load_filter('pre', 'wf_default_template'); |
---|
| 436 | } |
---|
| 437 | |
---|
| 438 | if ($this->conf['execute_activities_in_debug_mode']) |
---|
| 439 | { |
---|
| 440 | ini_set('display_errors',true); |
---|
| 441 | error_reporting(E_ALL & ~E_NOTICE); |
---|
| 442 | } |
---|
| 443 | |
---|
| 444 | /* BEGIN WORKFLOW MVC SETTINGS */ |
---|
[3061] | 445 | $env = array(); //create settings vector |
---|
[795] | 446 | $env['view'] =& $smarty; //view layer instance |
---|
| 447 | $env['template_file'] =& $_template_name; //template file to be shown |
---|
[3061] | 448 | $env['dao'] =& Factory::newInstance('wf_db'); //data access object instance |
---|
[795] | 449 | $env['workflow'] =& $GLOBALS['workflow']; //workflow environment information |
---|
| 450 | $env['instance'] =& $instance; //process manager instance |
---|
| 451 | $env['activity'] =& $activity; //activity manager instance |
---|
[2372] | 452 | $security =& Factory::newInstance('SecurityUtils'); //input sanitizer class |
---|
[795] | 453 | $env['request'] =& $security->process($_REQUEST); //sanitizes input data from client |
---|
[2372] | 454 | $env['factory'] =& Factory::getInstance('ProcessWrapperFactory'); //instantiation controller class |
---|
[3061] | 455 | $env['natural'] =& Factory::newInstance('wf_natural'); //data access object instance for mainframe |
---|
[795] | 456 | /* END WORKFLOW MVC SETTINGS */ |
---|
| 457 | |
---|
| 458 | $GLOBALS['workflow_env'] = &$env; |
---|
[2588] | 459 | |
---|
| 460 | /** |
---|
| 461 | * [__leave_activity] is setted if needed in the xxx_pre code or by the user in his code |
---|
| 462 | * HERE the user code is 'executed'. Note that we do not use include_once or require_once because |
---|
| 463 | * it could the same code several times with automatic activities looping in the graph and it still |
---|
| 464 | * need to be executed |
---|
| 465 | */ |
---|
[795] | 466 | $_engineProcessCodeDirectory = GALAXIA_PROCESSES . SEP . $this->process->getNormalizedName(). SEP . 'code'; |
---|
| 467 | $_engineCompilerDirectory = GALAXIA_LIBRARY . SEP . 'compiler'; |
---|
| 468 | $_engineFiles = array(); |
---|
| 469 | |
---|
| 470 | /* generate the list of needed files */ |
---|
| 471 | $_engineFiles[] = "{$_engineProcessCodeDirectory}/shared.php"; |
---|
| 472 | $_engineFiles[] = "{$_engineCompilerDirectory}/_shared_pre.php"; |
---|
| 473 | $_engineFiles[] = "{$_engineCompilerDirectory}/{$activity->getType()}_pre.php"; |
---|
| 474 | if ($activity->getAgents() !== false) |
---|
| 475 | $_engineFiles[] = "{$_engineCompilerDirectory}/agents_pre.php"; |
---|
| 476 | $_engineFiles[] = "{$_engineProcessCodeDirectory}/activities/{$activity->getNormalizedName()}.php"; |
---|
| 477 | $_engineFiles[] = "{$_engineCompilerDirectory}/{$activity->getType()}_pos.php"; |
---|
| 478 | if ($activity->getAgents() !== false) |
---|
| 479 | $_engineFiles[] = "{$_engineCompilerDirectory}/agents_pos.php"; |
---|
| 480 | $_engineFiles[] = "{$_engineCompilerDirectory}/_shared_pos.php"; |
---|
| 481 | |
---|
| 482 | /* check if the required files exists */ |
---|
| 483 | foreach ($_engineFiles as $_engineFile) |
---|
| 484 | if (!file_exists($_engineFile)) |
---|
| 485 | return array('failure' => $this->runtime->fail(lang('the following file could not be found: %1', $_engineFile), true, _DEBUG)); |
---|
| 486 | |
---|
| 487 | /* activate the security policy */ |
---|
[2372] | 488 | Factory::getInstance('WorkflowSecurity')->enableSecurityPolicy(); |
---|
[795] | 489 | |
---|
[2372] | 490 | /** |
---|
[2588] | 491 | * Here we are going to use our new Security static class. |
---|
[2372] | 492 | * From now, the factory frontend (static) will forward |
---|
| 493 | * the messages for the process factory instead of Workflow |
---|
| 494 | * factory. |
---|
| 495 | */ |
---|
| 496 | Security::enable(); |
---|
| 497 | |
---|
[795] | 498 | /* include the files */ |
---|
[3061] | 499 | $processTime = microtime(true); |
---|
| 500 | |
---|
[795] | 501 | foreach ($_engineFiles as $_engineFile) |
---|
| 502 | require $_engineFile; |
---|
| 503 | |
---|
[3061] | 504 | $processTime = (microtime(true) - $processTime); |
---|
| 505 | |
---|
[795] | 506 | unset($GLOBALS['workflow_env']); |
---|
| 507 | |
---|
| 508 | /* check if the developer wants to user the download mode */ |
---|
| 509 | if (isset($GLOBALS['workflow']['downloadMode']) && ($GLOBALS['workflow']['downloadMode'] == true)) |
---|
| 510 | $this->download_mode = true; |
---|
| 511 | |
---|
| 512 | if ($auto && (!$this->isChildInstance) && $activity->isInteractive() && (!empty($actualUser))) |
---|
| 513 | { |
---|
| 514 | $_SESSION['phpgw_info']['workflow']['user_groups'] = $actualUserGroups; |
---|
| 515 | $_SESSION['phpgw_info']['workflow']['account_id'] = $actualUser; |
---|
| 516 | $GLOBALS['phpgw_info']['user']['account_id'] = $actualUser; |
---|
| 517 | $GLOBALS['workflow']['wf_user_id'] = $actualUser; |
---|
| 518 | $GLOBALS['user'] = $actualUser; |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | //Now that the instance is ready and that user code has maybe change some things |
---|
| 522 | // we can catch some others usefull vars |
---|
| 523 | $this->instance_id = $instance->getInstanceId(); |
---|
| 524 | $this->instance_name = $instance->getName(); |
---|
| 525 | $this->instance_owner = $instance->getOwner(); |
---|
| 526 | $this->owner_name = $GLOBALS['phpgw']->accounts->id2name($this->instance_owner); |
---|
| 527 | if ($this->owner_name == '') |
---|
| 528 | { |
---|
| 529 | $this->owner_name = lang('Nobody'); |
---|
| 530 | } |
---|
| 531 | $GLOBALS['workflow']['wf_instance_id'] =& $this->instance_id; |
---|
| 532 | $GLOBALS['workflow']['wf_instance_name']=& $this->instance_name; |
---|
| 533 | $GLOBALS['workflow']['wf_instance_owner']=& $this->instance_owner; |
---|
| 534 | $GLOBALS['workflow']['wf_owner_name']=& $this->owner_name; |
---|
| 535 | |
---|
| 536 | //was template changed? |
---|
| 537 | if ($_template_name) |
---|
| 538 | { |
---|
| 539 | $this->_template_name = $_template_name; |
---|
| 540 | } |
---|
| 541 | else |
---|
| 542 | { |
---|
| 543 | $this->_template_name = $this->activity->getNormalizedName().'.tpl'; |
---|
| 544 | } |
---|
| 545 | |
---|
[3061] | 546 | $totalTime = (microtime(true) - $totalTime); |
---|
| 547 | |
---|
| 548 | $logTime = sprintf("GO [pid=%s,iid=%s,uid=%s,aid=%s] [eng=%ss,proc=%ss]", |
---|
| 549 | $this->process_id, |
---|
| 550 | $this->instance_id, |
---|
| 551 | $GLOBALS['user'], |
---|
| 552 | $this->activity_id, |
---|
| 553 | number_format(($totalTime - $processTime),3), |
---|
| 554 | number_format($processTime,3) ); |
---|
| 555 | |
---|
| 556 | $this->logger->debug($logTime); |
---|
| 557 | |
---|
[795] | 558 | // TODO: process instance comments |
---|
| 559 | $instructions = $this->runtime->handle_postUserCode(_DEBUG); |
---|
| 560 | switch($instructions['action']) |
---|
| 561 | { |
---|
| 562 | //interactive activity completed |
---|
| 563 | case 'completed': |
---|
| 564 | // re-retrieve instance data which could have been modified by an automatic activity |
---|
| 565 | $this->instance_id = $instance->getInstanceId(); |
---|
| 566 | $this->instance_name = $instance->getName(); |
---|
| 567 | $this->activityCompleteMessage = $instance->getActivityCompleteMessage(); |
---|
| 568 | |
---|
| 569 | if (!$auto) |
---|
| 570 | { |
---|
| 571 | $this->assignCommonVariables(); |
---|
| 572 | // and display completed template |
---|
| 573 | if ($GLOBALS['phpgw_info']['user']['preferences']['workflow']['show_activity_complete_page'] === '0') |
---|
| 574 | header('Location: workflow/index.php'); |
---|
| 575 | else |
---|
| 576 | $this->showCompletedPage(); |
---|
| 577 | } |
---|
| 578 | break; |
---|
| 579 | //interactive activity still in interactive mode |
---|
| 580 | case 'loop': |
---|
| 581 | if (!$auto) |
---|
| 582 | { |
---|
| 583 | $this->assignCommonVariables(); |
---|
| 584 | $this->showForm(); |
---|
| 585 | } |
---|
| 586 | break; |
---|
| 587 | //nothing more |
---|
| 588 | case 'leaving': |
---|
| 589 | if (!$auto) |
---|
| 590 | { |
---|
| 591 | $this->assignCommonVariables(); |
---|
| 592 | $this->showCancelledPage(); |
---|
| 593 | } |
---|
| 594 | break; |
---|
| 595 | //non-interactive activities, auto-mode |
---|
| 596 | case 'return': |
---|
| 597 | $result=Array(); |
---|
| 598 | $this->message[] = $this->GUI->get_error(false, _DEBUG); |
---|
| 599 | $this->message[] = $this->runtime->get_error(false, _DEBUG); |
---|
| 600 | //$this->message[] = $this->process->get_error(false, _DEBUG); |
---|
| 601 | $result =& $instructions['engine_info']; |
---|
| 602 | $this->message[] = $result['debug']; |
---|
| 603 | $result['debug'] = implode('<br />',array_filter($this->message)); |
---|
| 604 | return $result; |
---|
| 605 | break; |
---|
| 606 | default: |
---|
| 607 | return $this->runtime->fail(lang('unknown instruction from the workflow engine: %1', $instructions['action']), true, _DEBUG); |
---|
| 608 | break; |
---|
| 609 | } |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | /** |
---|
| 613 | * goajax |
---|
| 614 | * |
---|
| 615 | * @param int $activity_id |
---|
| 616 | * @param int $iid |
---|
| 617 | * @param bool $auto |
---|
| 618 | * @return array |
---|
| 619 | */ |
---|
| 620 | function goAjax($activity_id=0, $iid=0, $auto=0) |
---|
| 621 | { |
---|
[3061] | 622 | $totalTime = microtime(true); |
---|
| 623 | |
---|
[795] | 624 | $result=Array(); |
---|
| 625 | |
---|
| 626 | if ($iid) |
---|
| 627 | $_REQUEST['iid'] = $iid; |
---|
| 628 | $iid = $_REQUEST['iid']; |
---|
| 629 | |
---|
| 630 | //$activity_id is set when we are in auto mode. In interactive mode we get if from POST or GET |
---|
| 631 | if (!$activity_id) |
---|
| 632 | $activity_id = (int)get_var('activity_id', array('GET','POST'), 0); |
---|
| 633 | |
---|
| 634 | // load activity and instance |
---|
| 635 | if (!$activity_id) |
---|
| 636 | { |
---|
| 637 | $result['failure'] = $this->runtime->fail(lang('Cannot run unknown activity'), true, _DEBUG, $auto); |
---|
| 638 | return $result; |
---|
| 639 | } |
---|
| 640 | |
---|
| 641 | //initalising activity and instance objects inside the WfRuntime object |
---|
| 642 | if (!($this->runtime->loadRuntime($activity_id,$iid))) |
---|
| 643 | { |
---|
| 644 | $result['failure'] = $this->runtime->fail(lang('Cannot run the activity'), true, _DEBUG, $auto); |
---|
| 645 | return $result; |
---|
| 646 | } |
---|
| 647 | |
---|
| 648 | $activity =& $this->runtime->getActivity($activity_id, true, true); |
---|
| 649 | $this->activity =& $activity; |
---|
| 650 | // the instance is avaible with $instance or $this->instance |
---|
| 651 | // note that for standalone activities this instance can be an empty instance object, but false is a bad value |
---|
| 652 | // HERE IS A BIG POINT: we map the instance to a runtime object |
---|
| 653 | // user code will manipulate a stance, thinking it's an instance, but it is |
---|
| 654 | // in fact a WfRuntime object, mapping all instance functions |
---|
| 655 | $this->instance =& $this->runtime; |
---|
| 656 | $instance =& $this->instance; |
---|
| 657 | $GLOBALS['workflow']['wf_runtime'] =& $this->runtime; |
---|
| 658 | if (!($instance)) |
---|
| 659 | { |
---|
| 660 | $result['failure'] = $this->runtime->fail(lang('Cannot run the activity without instance'), true, _DEBUG, $auto); |
---|
| 661 | return $result; |
---|
| 662 | } |
---|
| 663 | $this->instance_id = $instance->getInstanceId(); |
---|
| 664 | |
---|
| 665 | // load process |
---|
| 666 | $this->process =& $this->runtime->getProcess(); |
---|
| 667 | if (!($this->process)) |
---|
| 668 | { |
---|
| 669 | $result['failure'] = $this->runtime->fail(lang('Cannot run the activity without her process').$instance, true, _DEBUG, $auto); |
---|
| 670 | return $result; |
---|
| 671 | } |
---|
| 672 | |
---|
| 673 | //set some global variables needed |
---|
| 674 | $GLOBALS['user'] = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
| 675 | |
---|
| 676 | //load role names, just an information |
---|
| 677 | $this->act_role_names = $activity->getActivityRoleNames(); |
---|
| 678 | |
---|
| 679 | //set some other usefull vars |
---|
| 680 | $this->activity_type = $activity->getType(); |
---|
| 681 | $this->process_id = $activity->getProcessId(); |
---|
| 682 | $this->activity_id = $activity_id; |
---|
| 683 | $this->process_name = $this->process->getName(); |
---|
| 684 | $this->process_version = $this->process->getVersion(); |
---|
| 685 | $this->activity_name = $activity->getName(); |
---|
| 686 | $this->user_name = $GLOBALS['phpgw']->accounts->id2name($GLOBALS['user']); |
---|
| 687 | $this->view_activity = $this->GUI->gui_get_process_view_activity($this->process_id); |
---|
| 688 | |
---|
| 689 | //we set them in $GLOBALS['workflow'] as well |
---|
| 690 | $GLOBALS['workflow']['wf_activity_type'] =& $this->activity_type; |
---|
| 691 | $GLOBALS['workflow']['wf_process_id'] =& $this->process_id; |
---|
| 692 | $GLOBALS['workflow']['wf_activity_id'] =& $this->activity_id; |
---|
| 693 | $GLOBALS['workflow']['wf_process_name'] =& $this->process_name; |
---|
| 694 | $GLOBALS['workflow']['wf_normalized_name'] = $this->process->getNormalizedName(); |
---|
| 695 | $GLOBALS['workflow']['wf_process_version'] =& $this->process_version; |
---|
| 696 | $GLOBALS['workflow']['wf_activity_name'] =& $this->activity_name; |
---|
| 697 | $GLOBALS['workflow']['wf_user_name'] =& $this->user_name; |
---|
| 698 | $GLOBALS['workflow']['wf_user_id'] =& $GLOBALS['user']; |
---|
| 699 | $GLOBALS['workflow']['wf_view_activity'] =& $this->view_activity; |
---|
| 700 | $GLOBALS['workflow']['wf_workflow_path'] = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'; |
---|
| 701 | $GLOBALS['workflow']['wf_resources_path'] = $GLOBALS['phpgw_info']['server']['webserver_url'] . SEP . 'workflow/redirect.php?pid=' . $this->process_id . '&file='; |
---|
[2372] | 702 | $GLOBALS['workflow']['wf_default_resources_path'] = Factory::getInstance('TemplateServer')->generateLink('processes'); |
---|
| 703 | $GLOBALS['workflow']['wf_workflow_resources_path'] = Factory::getInstance('TemplateServer')->generateLink(''); |
---|
[795] | 704 | $GLOBALS['workflow']['wf_activity_url'] = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'index.php?menuaction=workflow.'.get_class($this).'.go&activity_id='.$activity_id; |
---|
[2372] | 705 | $GLOBALS['workflow']['wf_user_cnname'] = Factory::getInstance('WorkflowLDAP')->getName($GLOBALS['user']); |
---|
[795] | 706 | $GLOBALS['workflow']['wf_back_link'] = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'.SEP.'index.php?start_tab=1'; |
---|
| 707 | $GLOBALS['workflow']['wf_js_path'] = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'.SEP.'js'.SEP.'jscode'; |
---|
| 708 | $GLOBALS['workflow']['wf_user_activities'] = $this->GUI->gui_list_user_activities($GLOBALS['user'], '0', '-1', 'ga.wf_name__ASC', '', '', false, true, true, true, ''); |
---|
| 709 | if ($iid) |
---|
| 710 | $GLOBALS['workflow']['wf_instance_url'] = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'index.php?menuaction=workflow.'.get_class($this).'.go&activity_id='.$activity_id."&iid=".$iid; |
---|
| 711 | else |
---|
| 712 | unset($GLOBALS['workflow']['wf_instance_url']); |
---|
| 713 | |
---|
| 714 | /* activate local functions */ |
---|
| 715 | require_once(PHPGW_SERVER_ROOT . SEP . 'workflow' . SEP . 'inc' . SEP . 'local' . SEP . 'functions' . SEP . 'local.functions.php'); |
---|
| 716 | |
---|
| 717 | //get configuration options with default values if no init was done before |
---|
| 718 | $myconf = array( |
---|
| 719 | 'execute_activities_in_debug_mode' => 0, |
---|
| 720 | 'execute_activities_using_secure_connection' => 0 |
---|
| 721 | ); |
---|
| 722 | //this will give use asked options and som others used by WfRuntime |
---|
| 723 | $this->conf =& $this->runtime->getConfigValues($myconf); |
---|
| 724 | |
---|
| 725 | // run the activity |
---|
| 726 | if ($this->conf['execute_activities_in_debug_mode']) |
---|
| 727 | { |
---|
| 728 | ini_set('display_errors',true); |
---|
| 729 | error_reporting(E_ALL & ~E_NOTICE); |
---|
| 730 | } |
---|
| 731 | |
---|
| 732 | /* BEGIN WORKFLOW MVC SETTINGS */ |
---|
[3061] | 733 | $env = array(); //create settings vector |
---|
| 734 | $env['dao'] =& Factory::newInstance('wf_db'); //data access object instance |
---|
[795] | 735 | $env['workflow'] =& $GLOBALS['workflow']; //workflow environment information |
---|
| 736 | $env['instance'] =& $instance; //process manager instance |
---|
| 737 | $env['activity'] =& $activity; //activity manager instance |
---|
[2372] | 738 | $security =& Factory::newInstance('SecurityUtils'); //input sanitizer class |
---|
[795] | 739 | $env['request'] =& $security->process($_REQUEST); //sanitizes input data from client |
---|
[2372] | 740 | $env['factory'] =& Factory::newInstance('ProcessWrapperFactory'); //instantiation controller class |
---|
[3061] | 741 | $env['natural'] =& Factory::newInstance('wf_natural'); //data access object instance for mainframe |
---|
[795] | 742 | /* END WORKFLOW MVC SETTINGS */ |
---|
| 743 | |
---|
| 744 | require_once(dirname(__FILE__) . SEP . 'nano' . SEP . 'JSON.php'); |
---|
| 745 | require_once(dirname(__FILE__) . SEP . 'nano' . SEP . 'NanoUtil.class.php'); |
---|
| 746 | require_once(dirname(__FILE__) . SEP . 'nano' . SEP . 'NanoJsonConverter.class.php'); |
---|
| 747 | require_once(dirname(__FILE__) . SEP . 'nano' . SEP . 'NanoRequest.class.php'); |
---|
| 748 | require_once(dirname(__FILE__) . SEP . 'nano' . SEP . 'NanoController.class.php'); |
---|
| 749 | |
---|
| 750 | /* activate the security policy */ |
---|
[2372] | 751 | Factory::getInstance('WorkflowSecurity')->enableSecurityPolicy(); |
---|
[795] | 752 | |
---|
[2372] | 753 | /** |
---|
| 754 | * here we are going to use our new Security static class. |
---|
| 755 | * From now, the factory frontend (static) will forward |
---|
| 756 | * the messages for the process factory instead of Workflow |
---|
| 757 | * factory. Note that this is the same comment as the previous |
---|
[3061] | 758 | * function... boooring.. |
---|
[2588] | 759 | */ |
---|
[2372] | 760 | Security::enable(); |
---|
| 761 | |
---|
[795] | 762 | $GLOBALS['workflow_env'] = &$env; |
---|
[2372] | 763 | $nc = &Factory::newInstance('NanoController'); |
---|
[795] | 764 | $nc->setClassPath(GALAXIA_PROCESSES . SEP . $this->process->getNormalizedName(). SEP . 'code'); |
---|
[3061] | 765 | |
---|
| 766 | $processTime = microtime(true); |
---|
[795] | 767 | $nc->iterateOverVirtualRequests(); |
---|
[3061] | 768 | $processTime = microtime(true) - $processTime; |
---|
| 769 | |
---|
[795] | 770 | $nc->outputResultData(); |
---|
| 771 | unset($GLOBALS['workflow_env']); |
---|
| 772 | |
---|
| 773 | if (!is_null($iid)) |
---|
| 774 | $instance->instance->sync(); |
---|
[3061] | 775 | |
---|
| 776 | $totalTime = microtime(true) - $totalTime; |
---|
| 777 | |
---|
| 778 | $logTime = sprintf("GOAJAX [pid=%s,iid=%s,uid=%s,aid=%s] [eng=%ss,proc=%ss]", |
---|
| 779 | $this->process_id, |
---|
| 780 | $this->instance_id, |
---|
| 781 | $GLOBALS['user'], |
---|
| 782 | $this->activity_id, |
---|
| 783 | number_format(($totalTime - $processTime),3), |
---|
| 784 | number_format($processTime,3) ); |
---|
| 785 | |
---|
| 786 | $this->logger->debug($logTime); |
---|
[795] | 787 | } |
---|
| 788 | |
---|
| 789 | /** |
---|
| 790 | * Create a child instance |
---|
| 791 | * |
---|
| 792 | * @param int $activityID |
---|
| 793 | * @param mixed $properties |
---|
| 794 | * @param string $user |
---|
| 795 | * @param bool $parentLock |
---|
| 796 | * @return int The instance ID of the just created instance |
---|
| 797 | * @access public |
---|
| 798 | */ |
---|
| 799 | function goChildInstance($activityID, $properties, $user, $parentLock) |
---|
| 800 | { |
---|
| 801 | $this->isChildInstance = true; |
---|
| 802 | $this->runtime->instance->isChildInstance = true; |
---|
| 803 | $this->runtime->instance->activityID = $activityID; |
---|
| 804 | $this->runtime->instance->parentLock = $parentLock; |
---|
| 805 | $this->runtime->instance->setProperties($properties); |
---|
| 806 | if ($user != '*') |
---|
| 807 | $this->runtime->setNextUser($user); |
---|
| 808 | |
---|
| 809 | /* run the selected activity */ |
---|
| 810 | ob_start(); |
---|
| 811 | $this->go($activityID, 0, true); |
---|
| 812 | ob_end_clean(); |
---|
| 813 | |
---|
| 814 | /* return the just created child instance */ |
---|
| 815 | return $this->runtime->instance_id; |
---|
| 816 | } |
---|
| 817 | |
---|
| 818 | /** |
---|
| 819 | * Show the page avaible when completing an activity |
---|
| 820 | * @return void |
---|
| 821 | * @access public |
---|
| 822 | */ |
---|
| 823 | function showCompletedPage() |
---|
| 824 | { |
---|
| 825 | $this->workflowSmarty->assign('activityEvent', 'completed'); |
---|
| 826 | $this->showAfterRunningPage(); |
---|
| 827 | } |
---|
| 828 | |
---|
| 829 | /** |
---|
| 830 | * Show the page avaible when leaving an activity |
---|
| 831 | * @return void |
---|
| 832 | * @access public |
---|
| 833 | */ |
---|
| 834 | function showCancelledPage() |
---|
| 835 | { |
---|
| 836 | $this->workflowSmarty->assign('activityEvent', 'cancelled'); |
---|
| 837 | $this->showAfterRunningPage(); |
---|
| 838 | } |
---|
| 839 | |
---|
| 840 | /** |
---|
| 841 | * Common code of pages showed after activity pages |
---|
| 842 | * @return void |
---|
| 843 | * @access public |
---|
| 844 | */ |
---|
| 845 | function showAfterRunningPage() |
---|
| 846 | { |
---|
| 847 | /* get the header/footer */ |
---|
| 848 | $this->assignHeader(); |
---|
| 849 | |
---|
| 850 | /* generate the activity list */ |
---|
| 851 | $processActivities = array_filter($GLOBALS['workflow']['wf_user_activities']['data'], create_function('$a', 'return ($a["wf_p_id"] == ' . $GLOBALS['workflow']['wf_process_id'] . ');')); |
---|
| 852 | $activityList = array(0 => '-- Selecione uma atividade --'); |
---|
| 853 | foreach ($processActivities as $processActivity) |
---|
| 854 | $activityList[$processActivity['wf_activity_id']] = $processActivity['wf_name']; |
---|
| 855 | |
---|
| 856 | /* assign some variables */ |
---|
| 857 | $this->workflowSmarty->assign('processName', $this->process_name); |
---|
| 858 | $this->workflowSmarty->assign('processVersion', $this->process_version); |
---|
| 859 | $this->workflowSmarty->assign('activityName', $this->activity_name); |
---|
| 860 | $this->workflowSmarty->assign('activityCompleteMessage', $this->activityCompleteMessage); |
---|
| 861 | $this->workflowSmarty->assign('activityBaseURL', $GLOBALS['phpgw_info']['server']['webserver_url']); |
---|
| 862 | $this->workflowSmarty->assign('activityList', $activityList); |
---|
| 863 | |
---|
| 864 | /* display the template */ |
---|
| 865 | $this->workflowSmarty->display('after_running.tpl'); |
---|
| 866 | } |
---|
| 867 | |
---|
| 868 | /** |
---|
| 869 | * Assign common information of interactive forms (e.g., error messages) |
---|
| 870 | * @return void |
---|
| 871 | * @access public |
---|
| 872 | */ |
---|
| 873 | function assignCommonVariables() |
---|
| 874 | { |
---|
| 875 | $this->message[] = $this->GUI->get_error(false, _DEBUG); |
---|
| 876 | $this->message[] = $this->runtime->get_error(false, _DEBUG); |
---|
| 877 | $activityErrors = array_filter(array_merge(explode('<br />', $this->message[0]), explode('<br />', $this->message[1]))); |
---|
| 878 | $this->workflowSmarty->assign('activityErrors', $activityErrors); |
---|
| 879 | } |
---|
| 880 | |
---|
| 881 | /** |
---|
| 882 | * Show the activity page (workflow template and activity template) |
---|
| 883 | * @return void |
---|
| 884 | * @access public |
---|
| 885 | */ |
---|
| 886 | function showForm() |
---|
| 887 | { |
---|
| 888 | /* define the header */ |
---|
| 889 | $this->assignHeader(); |
---|
| 890 | |
---|
| 891 | /* define the variables */ |
---|
| 892 | $activityOutput = $this->wf_template->fetch($this->_template_name); |
---|
| 893 | $actionURL = isset($GLOBALS['workflow']['wf_instance_url']) ? $GLOBALS['workflow']['wf_instance_url'] : $GLOBALS['workflow']['wf_activity_url']; |
---|
| 894 | $CSSLink = $this->get_css_link('run_activity', $this->print_mode); |
---|
| 895 | $CSSMedia = $this->print_mode ? 'print' : 'all'; |
---|
| 896 | |
---|
| 897 | /* assign the variables to smarty */ |
---|
| 898 | $this->workflowSmarty->assign('activityOutput', $activityOutput); |
---|
| 899 | $this->workflowSmarty->assign('actionURL', $actionURL); |
---|
| 900 | $this->workflowSmarty->assign('CSSLink', $CSSLink); |
---|
| 901 | $this->workflowSmarty->assign('CSSMedia', $CSSMedia); |
---|
| 902 | |
---|
| 903 | $this->workflowSmarty->display('run_activity.tpl'); |
---|
| 904 | unset($smarty); |
---|
| 905 | } |
---|
| 906 | |
---|
| 907 | /** |
---|
| 908 | * Define if the header, footer and navigation bar will be shown |
---|
| 909 | * @return void |
---|
| 910 | * @access public |
---|
| 911 | */ |
---|
| 912 | function assignHeader() |
---|
| 913 | { |
---|
| 914 | $headerConfig = 0; |
---|
[2072] | 915 | if (!$this->download_mode and !$this->print_mode) |
---|
[795] | 916 | { |
---|
| 917 | $headerConfig |= workflow_smarty::SHOW_HEADER | workflow_smarty::SHOW_FOOTER; |
---|
| 918 | if ($this->runtime->activity->child_name != 'View') |
---|
| 919 | $headerConfig |= workflow_smarty::SHOW_NAVIGATION_BAR; |
---|
| 920 | } |
---|
| 921 | |
---|
| 922 | $this->workflowSmarty->setHeader($headerConfig); |
---|
| 923 | $this->workflowSmarty->assign('header', $this->workflowSmarty->expressoHeader); |
---|
| 924 | $this->workflowSmarty->assign('footer', $this->workflowSmarty->expressoFooter); |
---|
| 925 | } |
---|
| 926 | } |
---|
| 927 | ?> |
---|