source: sandbox/workflow/branches/609/inc/class.run_activity.inc.php @ 2234

Revision 2234, 33.6 KB checked in by pedroerp, 14 years ago (diff)

Ticket #609 - Removendo factories antigas do módulo workflow.

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