Index: branches/2.2/workflow/inc/class.run_activity.inc.php
===================================================================
--- branches/2.2/workflow/inc/class.run_activity.inc.php	(revision 795)
+++ branches/2.2/workflow/inc/class.run_activity.inc.php	(revision 3167)
@@ -10,9 +10,8 @@
 	\**************************************************************************/
 
+	require_once(dirname(__FILE__) . SEP . 'common.inc.php'); 				 /* including common deifinitions */
 	require_once(dirname(__FILE__) . SEP . 'class.WorkflowUtils.inc.php'  ); /* superclass source code       */
 	require_once(dirname(__FILE__) . SEP . 'class.basecontroller.inc.php' ); /* module controller            */
 	require_once(dirname(__FILE__) . SEP . 'class.basemodel.inc.php'      ); /* module logic                 */
-	require_once(dirname(__FILE__) . SEP . 'class.process_factory.inc.php'); /* module process factory class */
-	require_once(dirname(__FILE__) . SEP . 'class.utils.security.php'     ); /* sanitizes input data         */
 
 	/**
@@ -169,5 +168,4 @@
 		var $agents = Array();
 
-		/* CELEPAR */
 		/**
 		 * @var object $smarty holds a Smarty instance
@@ -195,7 +193,15 @@
          */
 		var $isChildInstance = false;
-
+		/**
+		 * @var object Stores a 'workflow_smarty' object
+         * @access private
+         */
 		private $workflowSmarty = null;
-		/* CELEPAR */
+		/**
+		 * @var object Log Object
+         * @access private
+         */
+		private $logger = null;
+
 		/**
 		 * Constructor
@@ -206,14 +212,20 @@
 		{
 			parent::WorkflowUtils();
-			$this->runtime		= CreateObject('workflow.workflow_wfruntime');
+
+			/**
+			 * We should always use newInstance to instantiate
+			 * 'workflow_wfruntime'
+			 */
+			$this->runtime			= &Factory::newInstance('workflow_wfruntime');
 			$this->runtime->setDebug(_DEBUG);
-			//$this->base_activity	= CreateObject('workflow.workflow_baseactivity');
-			//$this->process		= CreateObject('workflow.workflow_process');
-			$this->GUI		= CreateObject('workflow.workflow_gui');
-			$this->categories 	= CreateObject('phpgwapi.categories');
-
-			$this->workflowSmarty = CreateObject('workflow.workflow_smarty', false);
+			$this->GUI				= &Factory::getInstance('workflow_gui');
+			$this->categories 		= &Factory::getInstance('categories');
+
+			$this->workflowSmarty 	= &Factory::getInstance('workflow_smarty', false);
+
+			// never configure a log of type "firebug" here. This will make goAjax stop running well =(
+			$this->logger 			= &Factory::getInstance('Logger', array('file'));
+
 			// TODO: open a new connection to the database under a different username to allow privilege handling on tables
-			/* CELEPAR */
 			unset($this->db);
 		}
@@ -232,4 +244,6 @@
 		function go($activity_id=0, $iid=0, $auto=0)
 		{
+			$totalTime = microtime(true);
+
 			$result=Array();
 
@@ -301,5 +315,5 @@
 			$this->process_version	= $this->process->getVersion();
 			$this->activity_name	= $activity->getName();
-			$this->user_name	= $GLOBALS['phpgw']->accounts->id2name($GLOBALS['user']);
+			$this->user_name   		= $GLOBALS['phpgw']->accounts->id2name($GLOBALS['user']);
 			$this->view_activity	= $this->GUI->gui_get_process_view_activity($this->process_id);
 
@@ -315,10 +329,11 @@
 			$GLOBALS['workflow']['wf_user_id']					=& $GLOBALS['user'];
 			$GLOBALS['workflow']['wf_view_activity']			=& $this->view_activity;
+			$GLOBALS['workflow']['wf_webserver_url'] 			= $GLOBALS['phpgw_info']['server']['webserver_url'];
 			$GLOBALS['workflow']['wf_workflow_path']			= $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow';
 			$GLOBALS['workflow']['wf_resources_path']			= $GLOBALS['phpgw_info']['server']['webserver_url'] . SEP . 'workflow/redirect.php?pid=' . $this->process_id . '&file=';
-			$GLOBALS['workflow']['wf_default_resources_path']	= $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateLink('processes');
-			$GLOBALS['workflow']['wf_workflow_resources_path']	= $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateLink('');
+			$GLOBALS['workflow']['wf_default_resources_path']	= Factory::getInstance('TemplateServer')->generateLink('processes');
+			$GLOBALS['workflow']['wf_workflow_resources_path']	= Factory::getInstance('TemplateServer')->generateLink('');
 			$GLOBALS['workflow']['wf_activity_url']				= $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'index.php?menuaction=workflow.'.get_class($this).'.go&activity_id='.$activity_id;
-			$GLOBALS['workflow']['wf_user_cnname']				= $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($GLOBALS['user']);
+			$GLOBALS['workflow']['wf_user_cnname']				= Factory::getInstance('WorkflowLDAP')->getName($GLOBALS['user']);
 			$GLOBALS['workflow']['wf_back_link']				= $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'.SEP.'index.php?start_tab=1';
 			$GLOBALS['workflow']['wf_js_path']					= $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'.SEP.'js'.SEP.'jscode';
@@ -330,5 +345,4 @@
 			$wf =& $GLOBALS['workflow'];
 
-			/* CELEPAR */
 			/* path to the local functions developed by Celepar */
 			$functions = PHPGW_SERVER_ROOT . SEP . 'workflow' . SEP . 'inc' . SEP . 'local' . SEP . 'functions' . SEP . 'local.functions.php';
@@ -336,5 +350,4 @@
 			/* activate local functions */
 			require_once($functions);
-			/* CELEPAR */
 
 			//get configuration options with default values if no init was done before
@@ -375,5 +388,5 @@
 
 				/* check some permissions */
-				if (($newUser == '*') || (!$this->runtime->checkUserRun($newUser)) || ($GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($newUser) === false))
+				if (($newUser == '*') || (!$this->runtime->checkUserRun($newUser)) || (Factory::getInstance('WorkflowLDAP')->getName($newUser) === false))
 				{
 					$_SESSION['phpgw_info']['workflow']['user_groups'] = $actualUserGroups;
@@ -385,5 +398,5 @@
 					return false;
 				}
-				$smarty = CreateObject('workflow.process_smarty');
+				$smarty = Factory::getInstance('process_smarty');
 			}
 
@@ -396,7 +409,5 @@
 				$this->download_mode = get_var('download_mode', array('POST','GET'), false);
 
-				/* #celepar# smarty code*/
-
-				$smarty = CreateObject('workflow.process_smarty');
+				$smarty = Factory::getInstance('process_smarty');
 
 				$smarty->template_dir  = GALAXIA_PROCESSES.SEP.$this->process->getNormalizedName().SEP.'code'.SEP.'templates';
@@ -418,5 +429,5 @@
 				$smarty->assign('wf_back_link',$GLOBALS['workflow']['wf_back_link']);
 				$smarty->assign('wf_activity_url',$GLOBALS['workflow']['wf_activity_url']);
-				
+
 				/* register the prefilter smarty plugin wf_default_template */
 				$smarty->load_filter('pre', 'wf_default_template');
@@ -430,23 +441,25 @@
 
 			/* BEGIN WORKFLOW MVC SETTINGS */
-			$env = array( );                                           //create settings vector
+			$env = array();                                            //create settings vector
 			$env['view']          =& $smarty;                          //view layer instance
 			$env['template_file'] =& $_template_name;                  //template file to be shown
-			$env['dao']           =& wf_create_object('wf_db');        //data access object instance
+			$env['dao']			  =& Factory::newInstance('wf_db');    //data access object instance
 			$env['workflow']      =& $GLOBALS['workflow'];             //workflow environment information
 			$env['instance']      =& $instance;                        //process manager instance
 			$env['activity']      =& $activity;                        //activity manager instance
-			$security             =& new SecurityUtils();              //input sanitizer class
+			$security             =& Factory::newInstance('SecurityUtils');              //input sanitizer class
 			$env['request']       =& $security->process($_REQUEST);    //sanitizes input data from client
-			$env['factory']       =& new ProcessFactory();             //instantiation controller class
-			$env['natural']		  =& wf_create_object('wf_natural');   //data access object instance for mainframe
+			$env['factory']       =& Factory::getInstance('ProcessWrapperFactory');  //instantiation controller class
+			$env['natural']		  =& Factory::newInstance('wf_natural');   //data access object instance for mainframe
 			/* END WORKFLOW MVC SETTINGS */
 
 			$GLOBALS['workflow_env'] = &$env;
-			//echo "<br><br><br><br><br>Including $source <br>In request: <pre>";print_r($_REQUEST);echo "</pre>";
-			//[__leave_activity] is setted if needed in the xxx_pre code or by the user in his code
-			// HERE the user code is 'executed'. Note that we do not use include_once or require_once because
-			//it could the same code several times with automatic activities looping in the graph and it still
-			//need to be executed
+
+			/**
+			 * [__leave_activity] is setted if needed in the xxx_pre code or by the user in his code
+			 * HERE the user code is 'executed'. Note that we do not use include_once or require_once because
+			 * it could the same code several times with automatic activities looping in the graph and it still
+			 * need to be executed
+			 */
 			$_engineProcessCodeDirectory = GALAXIA_PROCESSES . SEP . $this->process->getNormalizedName(). SEP . 'code';
 			$_engineCompilerDirectory = GALAXIA_LIBRARY . SEP . 'compiler';
@@ -471,9 +484,21 @@
 
 			/* activate the security policy */
-			$GLOBALS['workflow']['factory']->getInstance('WorkflowSecurity')->enableSecurityPolicy();
+			Factory::getInstance('WorkflowSecurity')->enableSecurityPolicy();
+
+			/**
+			 * Here we are going to use our new Security static class.
+			 * From now, the factory frontend (static) will forward
+			 * the messages for the process factory instead of Workflow
+			 * factory.
+			*/
+			Security::enable();
 
 			/* include the files */
+			$processTime = microtime(true);
+
 			foreach ($_engineFiles as $_engineFile)
-				require $_engineFile;
+				require_once $_engineFile;
+
+			$processTime = (microtime(true) - $processTime);
 
 			unset($GLOBALS['workflow_env']);
@@ -517,6 +542,17 @@
 			}
 
+			$totalTime = (microtime(true) - $totalTime);
+
+			$logTime = sprintf("GO [pid=%s,iid=%s,uid=%s,aid=%s] [eng=%ss,proc=%ss]",
+								$this->process_id,
+								$this->instance_id,
+								$GLOBALS['user'],
+								$this->activity_id,
+								number_format(($totalTime - $processTime),3),
+								number_format($processTime,3) );
+
+			$this->logger->debug($logTime);
+
 			// TODO: process instance comments
-
 			$instructions = $this->runtime->handle_postUserCode(_DEBUG);
 			switch($instructions['action'])
@@ -582,4 +618,6 @@
 		function goAjax($activity_id=0, $iid=0, $auto=0)
 		{
+			$totalTime = microtime(true);
+
 			$result=Array();
 
@@ -660,8 +698,8 @@
 			$GLOBALS['workflow']['wf_workflow_path']			= $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow';
 			$GLOBALS['workflow']['wf_resources_path']			= $GLOBALS['phpgw_info']['server']['webserver_url'] . SEP . 'workflow/redirect.php?pid=' . $this->process_id . '&file=';
-			$GLOBALS['workflow']['wf_default_resources_path']	= $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateLink('processes');
-			$GLOBALS['workflow']['wf_workflow_resources_path']	= $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateLink('');
+			$GLOBALS['workflow']['wf_default_resources_path']	= Factory::getInstance('TemplateServer')->generateLink('processes');
+			$GLOBALS['workflow']['wf_workflow_resources_path']	= Factory::getInstance('TemplateServer')->generateLink('');
 			$GLOBALS['workflow']['wf_activity_url']				= $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'index.php?menuaction=workflow.'.get_class($this).'.go&activity_id='.$activity_id;
-			$GLOBALS['workflow']['wf_user_cnname']				= $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($GLOBALS['user']);
+			$GLOBALS['workflow']['wf_user_cnname']				= Factory::getInstance('WorkflowLDAP')->getName($GLOBALS['user']);
 			$GLOBALS['workflow']['wf_back_link']				= $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'.SEP.'index.php?start_tab=1';
 			$GLOBALS['workflow']['wf_js_path']					= $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'.SEP.'js'.SEP.'jscode';
@@ -672,8 +710,6 @@
 				unset($GLOBALS['workflow']['wf_instance_url']);
 
-			/* CELEPAR */
 			/* activate local functions */
 			require_once(PHPGW_SERVER_ROOT . SEP . 'workflow' . SEP . 'inc' . SEP . 'local' . SEP . 'functions' . SEP . 'local.functions.php');
-			/* CELEPAR */
 
 			//get configuration options with default values if no init was done before
@@ -693,13 +729,13 @@
 
 			/* BEGIN WORKFLOW MVC SETTINGS */
-			$env = array( );                                           //create settings vector
-			$env['dao']           =& wf_create_object('wf_db');        //data access object instance
+			$env = array();                                            //create settings vector
+			$env['dao']			  =& Factory::newInstance('wf_db');    //data access object instance
 			$env['workflow']      =& $GLOBALS['workflow'];             //workflow environment information
 			$env['instance']      =& $instance;                        //process manager instance
 			$env['activity']      =& $activity;                        //activity manager instance
-			$security             =& new SecurityUtils();              //input sanitizer class
+			$security             =& Factory::newInstance('SecurityUtils'); //input sanitizer class
 			$env['request']       =& $security->process($_REQUEST); //sanitizes input data from client
-			$env['factory']       =& new ProcessFactory();			   //instantiation controller class
-			$env['natural']		  =& wf_create_object('wf_natural');   //data access object instance for mainframe
+			$env['factory']       =& Factory::newInstance('ProcessWrapperFactory');  //instantiation controller class
+			$env['natural']		  =& Factory::newInstance('wf_natural');   //data access object instance for mainframe
 			/* END WORKFLOW MVC SETTINGS */
 
@@ -711,10 +747,23 @@
 
 			/* activate the security policy */
-			$GLOBALS['workflow']['factory']->getInstance('WorkflowSecurity')->enableSecurityPolicy();
+			Factory::getInstance('WorkflowSecurity')->enableSecurityPolicy();
+
+			/**
+			 * here we are going to use our new Security static class.
+			 * From now, the factory frontend (static) will forward
+			 * the messages for the process factory instead of Workflow
+			 * factory. Note that this is the same comment as the previous
+			 * function... boooring..
+			 */
+			Security::enable();
 
 			$GLOBALS['workflow_env'] = &$env;
-			$nc = new NanoController();
+			$nc = &Factory::newInstance('NanoController');
 			$nc->setClassPath(GALAXIA_PROCESSES . SEP . $this->process->getNormalizedName(). SEP . 'code');
+
+			$processTime = microtime(true);
 			$nc->iterateOverVirtualRequests();
+			$processTime = microtime(true) - $processTime;
+
 			$nc->outputResultData();
 			unset($GLOBALS['workflow_env']);
@@ -722,4 +771,16 @@
 			if (!is_null($iid))
 				$instance->instance->sync();
+
+			$totalTime = microtime(true) - $totalTime;
+
+			$logTime = sprintf("GOAJAX [pid=%s,iid=%s,uid=%s,aid=%s] [eng=%ss,proc=%ss]",
+								$this->process_id,
+								$this->instance_id,
+								$GLOBALS['user'],
+								$this->activity_id,
+								number_format(($totalTime - $processTime),3),
+								number_format($processTime,3) );
+
+			$this->logger->debug($logTime);
 		}
 
@@ -850,5 +911,5 @@
 		{
 			$headerConfig = 0;
-			if (!$this->download_mode)
+			if (!$this->download_mode and !$this->print_mode)
 			{
 				$headerConfig |= workflow_smarty::SHOW_HEADER | workflow_smarty::SHOW_FOOTER;
