diff --git a/phpgwapi/inc/galaxia_workflow/compiler/_shared_pos.php b/phpgwapi/inc/galaxia_workflow/compiler/_shared_pos.php deleted file mode 100644 index 1f90d01d56..0000000000 --- a/phpgwapi/inc/galaxia_workflow/compiler/_shared_pos.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/phpgwapi/inc/galaxia_workflow/compiler/_shared_pre.php b/phpgwapi/inc/galaxia_workflow/compiler/_shared_pre.php deleted file mode 100644 index 04081ca7c1..0000000000 --- a/phpgwapi/inc/galaxia_workflow/compiler/_shared_pre.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/phpgwapi/inc/galaxia_workflow/compiler/activity_pos.php b/phpgwapi/inc/galaxia_workflow/compiler/activity_pos.php deleted file mode 100644 index 7f335b1908..0000000000 --- a/phpgwapi/inc/galaxia_workflow/compiler/activity_pos.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/phpgwapi/inc/galaxia_workflow/compiler/activity_pre.php b/phpgwapi/inc/galaxia_workflow/compiler/activity_pre.php deleted file mode 100644 index 4d28ef07b5..0000000000 --- a/phpgwapi/inc/galaxia_workflow/compiler/activity_pre.php +++ /dev/null @@ -1,23 +0,0 @@ -instanceId)) { - // This activity needs an instance to be passed to - // be started, so get the instance into $instance. - if(isset($_REQUEST['iid'])) { - $instance->getInstance($_REQUEST['iid']); - } else { - // defined in lib/Galaxia/config.php - galaxia_show_error(lang("No instance indicated")); - die; - } -} -// Set the current user for this activity -if(isset($GLOBALS['user']) && ($activity->isInteractive()) && !empty($instance->instanceId) && !empty($activity_id)) { - if (!$instance->setActivityUser($activity_id,$GLOBALS['user'])){ - galaxia_show_error(lang("You do not have the right to run this activity anymore, maybe a concurrent access problem, refresh your datas.")); - die; - } -} - -?> diff --git a/phpgwapi/inc/galaxia_workflow/compiler/end_pos.php b/phpgwapi/inc/galaxia_workflow/compiler/end_pos.php deleted file mode 100644 index 3d74f3cde9..0000000000 --- a/phpgwapi/inc/galaxia_workflow/compiler/end_pos.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/phpgwapi/inc/galaxia_workflow/compiler/end_pre.php b/phpgwapi/inc/galaxia_workflow/compiler/end_pre.php deleted file mode 100644 index 202de3e15a..0000000000 --- a/phpgwapi/inc/galaxia_workflow/compiler/end_pre.php +++ /dev/null @@ -1,23 +0,0 @@ -instanceId)) { - // This activity needs an instance to be passed to - // be started, so get the instance into $instance. - if(isset($_REQUEST['iid'])) { - $instance->getInstance($_REQUEST['iid']); - } else { - // defined in lib/Galaxia/config.php - galaxia_show_error(lang("No instance indicated")); - die; - } -} -// Set the current user for this activity -if(isset($GLOBALS['user']) && ($activity->isInteractive()) && !empty($instance->instanceId) && !empty($activity_id)) { - if (!$instance->setActivityUser($activity_id,$GLOBALS['user'])){ - galaxia_show_error(lang("You do not have the right to run this activity anymore, maybe a concurrent access problem, refresh your datas.")); - die; - } -} - -?> diff --git a/phpgwapi/inc/galaxia_workflow/compiler/join_pos.php b/phpgwapi/inc/galaxia_workflow/compiler/join_pos.php deleted file mode 100644 index 36c6aca604..0000000000 --- a/phpgwapi/inc/galaxia_workflow/compiler/join_pos.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/phpgwapi/inc/galaxia_workflow/compiler/join_pre.php b/phpgwapi/inc/galaxia_workflow/compiler/join_pre.php deleted file mode 100644 index 261917ef0a..0000000000 --- a/phpgwapi/inc/galaxia_workflow/compiler/join_pre.php +++ /dev/null @@ -1,23 +0,0 @@ -instanceId)) { - // This activity needs an instance to be passed to - // be started, so get the instance into $instance. - if(isset($_REQUEST['iid'])) { - $instance->getInstance($_REQUEST['iid']); - } else { - // defined in lib/Galaxia/config.php - galaxia_show_error(lang("No instance indicated")); - die; - } -} -// Set the current user for this activity -if(isset($GLOBALS['user']) && ($activity->isInteractive()) && !empty($instance->instanceId) && !empty($activity_id)) { - if (!$instance->setActivityUser($activity_id,$GLOBALS['user'])){ - galaxia_show_error(lang("You do not have the right to run this activity anymore, maybe a concurrent access problem, refresh your datas.")); - die; - } -} - -?> diff --git a/phpgwapi/inc/galaxia_workflow/compiler/split_pos.php b/phpgwapi/inc/galaxia_workflow/compiler/split_pos.php deleted file mode 100644 index 3c77cb39d4..0000000000 --- a/phpgwapi/inc/galaxia_workflow/compiler/split_pos.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/phpgwapi/inc/galaxia_workflow/compiler/split_pre.php b/phpgwapi/inc/galaxia_workflow/compiler/split_pre.php deleted file mode 100644 index 7dd833b0c3..0000000000 --- a/phpgwapi/inc/galaxia_workflow/compiler/split_pre.php +++ /dev/null @@ -1,22 +0,0 @@ -instanceId)) { - // This activity needs an instance to be passed to - // be started, so get the instance into $instance. - if(isset($_REQUEST['iid'])) { - $instance->getInstance($_REQUEST['iid']); - } else { - // defined in lib/Galaxia/config.php - galaxia_show_error(lang("No instance indicated")); - die; - } -} -// Set the current user for this activity -if(isset($GLOBALS['user']) && ($activity->isInteractive()) && !empty($instance->instanceId) && !empty($activity_id)) { - if (!$instance->setActivityUser($activity_id,$GLOBALS['user'])){ - galaxia_show_error(lang("You do not have the right to run this activity anymore, maybe a concurrent access problem, refresh your datas.")); - die; - } -} -?> diff --git a/phpgwapi/inc/galaxia_workflow/compiler/standalone_pos.php b/phpgwapi/inc/galaxia_workflow/compiler/standalone_pos.php deleted file mode 100644 index 8041380a7d..0000000000 --- a/phpgwapi/inc/galaxia_workflow/compiler/standalone_pos.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/phpgwapi/inc/galaxia_workflow/compiler/standalone_pre.php b/phpgwapi/inc/galaxia_workflow/compiler/standalone_pre.php deleted file mode 100644 index 69859b9297..0000000000 --- a/phpgwapi/inc/galaxia_workflow/compiler/standalone_pre.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/phpgwapi/inc/galaxia_workflow/compiler/start_pos.php b/phpgwapi/inc/galaxia_workflow/compiler/start_pos.php deleted file mode 100644 index 424ce308ad..0000000000 --- a/phpgwapi/inc/galaxia_workflow/compiler/start_pos.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/phpgwapi/inc/galaxia_workflow/compiler/start_pre.php b/phpgwapi/inc/galaxia_workflow/compiler/start_pre.php deleted file mode 100644 index f76a04a1d5..0000000000 --- a/phpgwapi/inc/galaxia_workflow/compiler/start_pre.php +++ /dev/null @@ -1,11 +0,0 @@ -instanceId) && isset($_REQUEST['iid'])) { - // in case we're looping back to a start activity, we need to retrieve the instance - $instance->getInstance($_REQUEST['iid']); -} else { - // otherwise we'll create an instance when this activity is completed -} - -?> diff --git a/phpgwapi/inc/galaxia_workflow/compiler/switch_pos.php b/phpgwapi/inc/galaxia_workflow/compiler/switch_pos.php deleted file mode 100644 index da816dc1f7..0000000000 --- a/phpgwapi/inc/galaxia_workflow/compiler/switch_pos.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/phpgwapi/inc/galaxia_workflow/compiler/switch_pre.php b/phpgwapi/inc/galaxia_workflow/compiler/switch_pre.php deleted file mode 100644 index b8df5096b3..0000000000 --- a/phpgwapi/inc/galaxia_workflow/compiler/switch_pre.php +++ /dev/null @@ -1,23 +0,0 @@ -instanceId)) { - // This activity needs an instance to be passed to - // be started, so get the instance into $instance. - if(isset($_REQUEST['iid'])) { - $instance->getInstance($_REQUEST['iid']); - } else { - // defined in lib/Galaxia/config.php - galaxia_show_error(lang("No instance indicated")); - die; - } -} -// Set the current user for this activity -if(isset($GLOBALS['user']) && ($activity->isInteractive()) && !empty($instance->instanceId) && !empty($activity_id)) { - if (!$instance->setActivityUser($activity_id,$GLOBALS['user'])){ - galaxia_show_error(lang("You do not have the right to run this activity anymore, maybe a concurrent access problem, refresh your datas.")); - die; - } -} - -?> diff --git a/phpgwapi/inc/galaxia_workflow/config.egw.inc.php b/phpgwapi/inc/galaxia_workflow/config.egw.inc.php deleted file mode 100644 index 90e6181aa7..0000000000 --- a/phpgwapi/inc/galaxia_workflow/config.egw.inc.php +++ /dev/null @@ -1,125 +0,0 @@ -vfs = createobject('phpgwapi.vfs'); - -// check if basedir exists -$test=$GLOBALS['phpgw']->vfs->get_real_info(array('string' => '/', 'relatives' => array(RELATIVE_NONE), 'relative' => False)); -if($test[mime_type]!='Directory') -{ - die(lang('Base directory does not exist, please ask adminstrator to check the global configuration')); -} - -// check if /workflow exists -$test = @$GLOBALS['phpgw']->vfs->get_real_info(array('string' => '/workflow', 'relatives' => array(RELATIVE_NONE), 'relative' => False)); -if($test[mime_type]!='Directory') -{ - // if not, create it - $GLOBALS['phpgw']->vfs->override_acl = 1; - $GLOBALS['phpgw']->vfs->mkdir(array( - 'string' => '/workflow', - 'relatives' => array(RELATIVE_NONE) - )); - $GLOBALS['phpgw']->vfs->override_acl = 0; - - // test one more time - $test = $GLOBALS['phpgw']->vfs->get_real_info(array('string' => '/workflow', 'relatives' => array(RELATIVE_NONE), 'relative' => False)); - if($test[mime_type]!='Directory') - { - die(lang('/workflow directory does not exist and could not be created, please ask adminstrator to check the global configuration')); - } -} - -// Directory where the Galaxia processes will be stored, e.g. lib/Galaxia/processes -if (!defined('GALAXIA_PROCESSES')) -{ - // Note: this directory must be writeable by the webserver ! - define('GALAXIA_PROCESSES', $GLOBALS['phpgw']->vfs->basedir.SEP.'workflow'); -} - -// Directory where a *copy* of the Galaxia activity templates will be stored, e.g. templates -// Define as '' if you don't want to copy templates elsewhere -if (!defined('GALAXIA_TEMPLATES')) { - // Note: this directory must be writeable by the webserver ! - define('GALAXIA_TEMPLATES', ''); -} - -// Default header to be added to new activity templates -if (!defined('GALAXIA_TEMPLATE_HEADER')) { - define('GALAXIA_TEMPLATE_HEADER', ''); -} - -// File where the ProcessManager logs for Galaxia will be saved, e.g. lib/Galaxia/log/pm.log -// Define as '' if you don't want to use logging -if (!defined('GALAXIA_LOGFILE')) { - // Note: this file must be writeable by the webserver ! - //define('GALAXIA_LOGFILE', GALAXIA_LIBRARY . '/log/pm.log'); - define('GALAXIA_LOGFILE', ''); -} - -// Directory containing the GraphViz 'dot' and 'neato' programs, in case -// your webserver can't find them via its PATH environment variable -if (!defined('GRAPHVIZ_BIN_DIR')) { - define('GRAPHVIZ_BIN_DIR', ''); - //define('GRAPHVIZ_BIN_DIR', 'd:/wintools/ATT/GraphViz/bin'); -} - -// language function -function tra($msg, $m1='', $m2='', $m3='', $m4='') -{ - return lang($msg, $m1, $m2, $m3, $m4); -} - -// Specify how error messages should be shown -if (!function_exists('galaxia_show_error')) { - function galaxia_show_error($msg) - { - die("Error: $msg"); - } -} - -// Specify how to execute a non-interactive activity (for use in src/API/Instance.php) -if (!function_exists('galaxia_execute_activity')) { - function galaxia_execute_activity($activityId = 0, $iid = 0, $auto = 1) - { - // Now execute the code for the activity but we are in a method! - // so just use an fopen with http mode - -/* $parsed = parse_url($_SERVER["REQUEST_URI"]); - $URI = 'http'.((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) ? 's' : '').'://'.$_SERVER['HTTP_HOST'].$parsed["path"]; - $parts = explode('/',$URI); - $parts[count($parts)-1] = "index.php?sessionid=".SID."&menuaction=workflow.run_activity&activityId=$activityId&iid=$iid&auto=$auto"; - $URI = implode('/',$parts); - - $fp = fopen($URI,"r"); - $data = ''; - if (!$fp) { - trigger_error(tra("Fatal error: cannot execute automatic activity $activityId"),E_USER_WARNING); - die; - } - while (!feof($fp)) { - $data.=fread($fp,8192); - } - fclose($fp); - -*/ - $run_activity = CreateObject('workflow.run_activity.go'); - $data = $run_activity->go($activityId, $iid, $auto); - } -} - -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/API/BaseActivity.php b/phpgwapi/inc/galaxia_workflow/src/API/BaseActivity.php deleted file mode 100644 index 3d1dc92219..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/API/BaseActivity.php +++ /dev/null @@ -1,218 +0,0 @@ -db=$db; - } - - function BaseActivity($db) - { - $this->db=$db; - $this->type='base'; - } - - - /*! - Factory method returning an activity of the desired type - loading the information from the database. - */ - function getActivity($activityId) - { - $query = "select * from `".GALAXIA_TABLE_PREFIX."activities` where `wf_activity_id`=?"; - $result = $this->query($query,array($activityId)); - if(!$result->numRows()) return false; - $res = $result->fetchRow(); - switch($res['wf_type']) { - case 'start': - $act = new Start($this->db); - break; - case 'end': - $act = new End($this->db); - break; - case 'join': - $act = new Join($this->db); - break; - case 'split': - $act = new Split($this->db); - break; - case 'standalone': - $act = new Standalone($this->db); - break; - case 'switch': - $act = new SwitchActivity($this->db); - break; - case 'activity': - $act = new Activity($this->db); - break; - default: - trigger_error('Unknown activity type:'.$res['wf_type'],E_USER_WARNING); - } - - $act->setName($res['wf_name']); - $act->setProcessId($res['wf_p_id']); - $act->setNormalizedName($res['wf_normalized_name']); - $act->setDescription($res['wf_description']); - $act->setIsInteractive($res['wf_is_interactive']); - $act->setIsAutoRouted($res['wf_is_autorouted']); - $act->setActivityId($res['wf_activity_id']); - $act->setType($res['wf_type']); - - //Now get forward transitions - - //Now get backward transitions - - //Now get roles - $query = "select `wf_role_id` from `".GALAXIA_TABLE_PREFIX."activity_roles` where `wf_activity_id`=?"; - $result=$this->query($query,array($res['wf_activity_id'])); - while($res = $result->fetchRow()) { - $this->roles[] = $res['wf_role_id']; - } - $act->setRoles($this->roles); - return $act; - } - - /*! Returns an Array of roleIds for the given user */ - function getUserRoles($user) { - $query = "select `wf_role_id` from `".GALAXIA_TABLE_PREFIX."user_roles` where `wf_user`=?"; - $result=$this->query($query,array($user)); - $ret = Array(); - while($res = $result->fetchRow()) { - $ret[] = $res['wf_role_id']; - } - return $ret; - } - - /*! Returns an Array of asociative arrays with roleId and name - for the given user */ - function getActivityRoleNames() { - $aid = $this->activityId; - $query = "select gr.`wf_role_id`, `wf_name` from `".GALAXIA_TABLE_PREFIX."activity_roles` gar, `".GALAXIA_TABLE_PREFIX."roles` gr where gar.`wf_role_id`=gr.`wf_role_id` and gar.`wf_activity_id`=?"; - $result=$this->query($query,array($aid)); - $ret = Array(); - while($res = $result->fetchRow()) { - $ret[] = $res; - } - return $ret; - } - - /*! Returns the normalized name for the activity */ - function getNormalizedName() { - return $this->normalizedName; - } - - /*! Sets normalized name for the activity */ - function setNormalizedName($name) { - $this->normalizedName=$name; - } - - /*! Sets the name for the activity */ - function setName($name) { - $this->name=$name; - } - - /*! Gets the activity name */ - function getName() { - return $this->name; - } - - /*! Sets the activity description */ - function setDescription($desc) { - $this->description=$desc; - } - - /*! Gets the activity description */ - function getDescription() { - return $this->description; - } - - /*! Sets the type for the activity - this does NOT allow you to change the actual type */ - function setType($type) { - $this->type=$type; - } - - /*! Gets the activity type */ - function getType() { - return $this->type; - } - - /*! Sets if the activity is interactive */ - function setIsInteractive($is) { - $this->isInteractive=$is; - } - - /*! Returns if the activity is interactive */ - function isInteractive() { - return $this->isInteractive == 'y'; - } - - /*! Sets if the activity is auto-routed */ - function setIsAutoRouted($is) { - $this->isAutoRouted = $is; - } - - /*! Gets if the activity is auto routed */ - function isAutoRouted() { - return $this->isAutoRouted == 'y'; - } - - /*! Sets the processId for this activity */ - function setProcessId($pid) { - $this->pId=$pid; - } - - /*! Gets the processId for this activity*/ - function getProcessId() { - return $this->pId; - } - - /*! Gets the activityId */ - function getActivityId() { - return $this->activityId; - } - - /*! Sets the activityId */ - function setActivityId($id) { - $this->activityId=$id; - } - - /*! Gets array with roleIds asociated to this activity */ - function getRoles() { - return $this->roles; - } - - /*! Sets roles for this activities, shoule receive an - array of roleIds */ - function setRoles($roles) { - $this->roles = $roles; - } - - /*! Checks if a user has a certain role (by name) for this activity, - e.g. $isadmin = $activity->checkUserRole($user,'admin'); */ - function checkUserRole($user,$rolename) { - $aid = $this->activityId; - return $this->getOne("select count(*) from `".GALAXIA_TABLE_PREFIX."activity_roles` gar, `".GALAXIA_TABLE_PREFIX."user_roles` gur, `".GALAXIA_TABLE_PREFIX."roles` gr where gar.`wf_role_id`=gr.`roleId` and gur.`wf_role_id`=gr.`roleId` and gar.`wf_activity_id`=? and gur.`wf_user`=? and gr.`wf_name`=?",array($aid, $user, $rolename)); - } - -} -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/API/Instance.php b/phpgwapi/inc/galaxia_workflow/src/API/Instance.php deleted file mode 100644 index 89496899a4..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/API/Instance.php +++ /dev/null @@ -1,673 +0,0 @@ -db = $db; - } - - /*! - Method used to load an instance data from the database. - */ - function getInstance($instanceId) { - // Get the instance data - $query = "select * from `".GALAXIA_TABLE_PREFIX."instances` where `wf_instance_id`=?"; - $result = $this->query($query,array((int)$instanceId)); - if(!$result->numRows()) return false; - $res = $result->fetchRow(); - - //Populate - $this->properties = unserialize($res['wf_properties']); - $this->status = $res['wf_status']; - $this->pId = $res['wf_p_id']; - $this->instanceId = $res['wf_instance_id']; - $this->owner = $res['wf_owner']; - $this->started = $res['wf_started']; - $this->ended = $res['wf_ended']; - $this->nextActivity = $res['wf_next_activity']; - $this->nextUser = $res['wf_next_user']; - // Get the activities where the instance is (ids only is ok) - $query = "select * from `".GALAXIA_TABLE_PREFIX."instance_activities` where `wf_instance_id`=?"; - $result = $this->query($query,array((int)$instanceId)); - while($res = $result->fetchRow()) { - $this->activities[]=$res; - } - } - - /*! - Sets the next activity to be executed, if the current activity is - a switch activity the complete() method will use the activity setted - in this method as the next activity for the instance. - Note that this method receives an activity name as argument. (Not an Id) - */ - function setNextActivity($actname) { - $pId = $this->pId; - $actname=trim($actname); - $aid = $this->getOne("select `wf_activity_id` from `".GALAXIA_TABLE_PREFIX."activities` where `wf_p_id`=? and `wf_name`=?",array($pId,$actname)); - if(!$this->getOne("select count(*) from `".GALAXIA_TABLE_PREFIX."activities` where `wf_activity_id`=? and `wf_p_id`=?",array($aid,$pId))) { - trigger_error(tra('Fatal error: setting next activity to an unexisting activity'),E_USER_WARNING); - } - $this->nextActivity=$aid; - $query = "update `".GALAXIA_TABLE_PREFIX."instances` set `wf_next_activity`=? where `wf_instance_id`=?"; - $this->query($query,array((int)$aid,(int)$this->instanceId)); - } - - /*! - This method can be used to set the user that must perform the next - activity of the process. this effectively "assigns" the instance to - some user. - */ - function setNextUser($user) { - $pId = $this->pId; - $this->nextUser = $user; - $query = "update `".GALAXIA_TABLE_PREFIX."instances` set `wf_next_user`=? where `wf_instance_id`=?"; - $this->query($query,array($user,(int)$this->instanceId)); - } - - /*! - \private - Creates a new instance. - This method is called in start activities when the activity is completed - to create a new instance representing the started process. - */ - function _createNewInstance($activityId,$user) { - // Creates a new instance setting up started,ended,user - // and status - $pid = $this->getOne("select `wf_p_id` from `".GALAXIA_TABLE_PREFIX."activities` where `wf_activity_id`=?",array((int)$activityId)); - $this->status = 'active'; - $this->nextActivity = 0; - $this->setNextUser(''); - $this->pId = $pid; - $now = date("U"); - $this->started=$now; - $this->owner = $user; - $props=serialize($this->properties); - $query = "insert into `".GALAXIA_TABLE_PREFIX."instances`(`wf_started`,`wf_ended`,`wf_status`,`wf_p_id`,`wf_owner`,`wf_properties`) values(?,?,?,?,?,?)"; - $this->query($query,array($now,0,'active',$pid,$user,$props)); - $this->instanceId = $this->getOne("select max(`wf_instance_id`) from `".GALAXIA_TABLE_PREFIX."instances` where `wf_started`=? and `wf_owner`=?",array((int)$now,$user)); - $iid=$this->instanceId; - - // Now update the properties! - $props = serialize($this->properties); - $query = "update `".GALAXIA_TABLE_PREFIX."instances` set `wf_properties`=? where `wf_instance_id`=?"; - $this->query($query,array($props,(int)$iid)); - - // Then add in ".GALAXIA_TABLE_PREFIX."instance_activities an entry for the - // activity the user and status running and started now - $query = "insert into `".GALAXIA_TABLE_PREFIX."instance_activities`(`wf_instance_id`,`wf_activity_id`,`wf_user`,`wf_started`,`wf_status`) values(?,?,?,?,?)"; - $this->query($query,array((int)$iid,(int)$activityId,$user,(int)$now,'running')); - } - - /*! - Sets a property in this instance. This method is used in activities to - set instance properties. Instance properties are inemdiately serialized. - */ - function set($name,$value) { - $this->properties[$name] = $value; - $props = serialize($this->properties); - $query = "update `".GALAXIA_TABLE_PREFIX."instances` set `wf_properties`=? where `wf_instance_id`=?"; - $this->query($query,array($props,$this->instanceId)); - } - - /*! - Gets the value of an instance property. - */ - function get($name) { - if(isset($this->properties[$name])) { - return $this->properties[$name]; - } else { - return false; - } - } - - /*! - Returns an array of asocs describing the activities where the instance - is present, can be more than one activity if the instance was "splitted" - */ - function getActivities() { - return $this->activities; - } - - /*! - Gets the instance status can be - 'completed', 'active', 'aborted' or 'exception' - */ - function getStatus() { - return $this->status; - } - - /*! - Sets the instance status , the value can be: - 'completed', 'active', 'aborted' or 'exception' - */ - function setStatus($status) { - $this->status = $status; - // and update the database - $query = "update `".GALAXIA_TABLE_PREFIX."instances` set `wf_status`=? where `wf_instance_id`=?"; - $this->query($query,array($status,(int)$this->instanceId)); - } - - /*! - Returns the instanceId - */ - function getInstanceId() { - return $this->instanceId; - } - - /*! - Returns the processId for this instance - */ - function getProcessId() { - return $this->pId; - } - - /*! - Returns the user that created the instance - */ - function getOwner() { - return $this->owner; - } - - /*! - Sets the instance creator user - */ - function setOwner($user) { - $this->owner = $user; - // save database - $query = "update `".GALAXIA_TABLE_PREFIX."instances` set `wf_owner`=? where `wf_instance_id`=?"; - $this->query($query,array($this->owner,(int)$this->instanceId)); - } - - /*! - Sets the user that must execute the activity indicated by the activityId. - Note that the instance MUST be present in the activity to set the user, - you can't program who will execute an activity. - - egw: if the user we set is not * verification is done before the update - that the instance has no user setted (or the same one) - return false if it was impossible to set the user, it can be because the - activity is not avaible anymore for this instance or because another user - is already there. - */ - function setActivityUser($activityId,$theuser) { - if(empty($theuser)) $theuser='*'; - $found = false; - for($i=0;$iactivities);$i++) { - if($this->activities[$i]['wf_activity_id']==$activityId) { - $found = true; - $query = "update `".GALAXIA_TABLE_PREFIX."instance_activities` set `wf_user`=? where `wf_activity_id`=? and `wf_instance_id`=?"; - $bindvars = array($theuser,(int)$activityId,(int)$this->instanceId); - if(!($theuser=='*')) { - $query.= "and (`wf_user`=? or `wf_user`=?)"; - $bindvars[]= $theuser; - $bindvars[]= '*'; - } - $this->query($query,$bindvars); - if(!$this->db->Affected_Rows()) return false; - $this->activities[$i]['wf_user']=$theuser; - } - } - return $found; - } - - /*! - Returns the user that must execute or is already executing an activity - wherethis instance is present. - */ - function getActivityUser($activityId) { - for($i=0;$iactivities);$i++) { - if($this->activities[$i]['wf_activity_id']==$activityId) { - return $this->activities[$i]['wf_user']; - } - } - return false; - } - - /*! - Sets the status of the instance in some activity, can be - 'running' or 'completed' - */ - function setActivityStatus($activityId,$status) { - for($i=0;$iactivities);$i++) { - if($this->activities[$i]['wf_activity_id']==$activityId) { - $this->activities[$i]['wf_status']=$status; - $query = "update `".GALAXIA_TABLE_PREFIX."instance_activities` set `wf_status`=? where `wf_activity_id`=? and `wf_instance_id`=?"; - $this->query($query,array($status,(int)$activityId,(int)$this->instanceId)); - } - } - } - - - /*! - Gets the status of the instance in some activity, can be - 'running' or 'completed' - */ - function getActivityStatus($activityId) { - for($i=0;$iactivities);$i++) { - if($this->activities[$i]['wf_activity_id']==$activityId) { - return $this->activities[$i]['wf_status']; - } - } - return false; - } - - /*! - Resets the start time of the activity indicated to the current time. - */ - function setActivityStarted($activityId) { - $now = date("U"); - for($i=0;$iactivities);$i++) { - if($this->activities[$i]['wf_activity_id']==$activityId) { - $this->activities[$i]['wf_started']=$now; - $query = "update `".GALAXIA_TABLE_PREFIX."instance_activities` set `wf_started`=? where `wf_activity_id`=? and `wf_instance_id`=?"; - $this->query($query,array($now,(int)$activityId,(int)$this->instanceId)); - } - } - } - - /*! - Gets the Unix timstamp of the starting time for the given activity. - */ - function getActivityStarted($activityId) { - for($i=0;$iactivities);$i++) { - if($this->activities[$i]['wf_activity_id']==$activityId) { - return $this->activities[$i]['wf_started']; - } - } - return false; - } - - /*! - \private - Gets an activity from the list of activities of the instance - */ - function _get_instance_activity($activityId) { - for($i=0;$iactivities);$i++) { - if($this->activities[$i]['wf_activity_id']==$activityId) { - return $this->activities[$i]; - } - } - return false; - } - - /*! - Sets the time where the instance was started. - */ - function setStarted($time) { - $this->started=$time; - $query = "update `".GALAXIA_TABLE_PREFIX."instances` set `wf_started`=? where `wf_instance_id`=?"; - $this->query($query,array((int)$time,(int)$this->instanceId)); - } - - /*! - Gets the time where the instance was started (Unix timestamp) - */ - function getStarted() { - return $this->started; - } - - /*! - Sets the end time of the instance (when the process was completed) - */ - function setEnded($time) { - $this->ended=$time; - $query = "update `".GALAXIA_TABLE_PREFIX."instances` set `wf_ended`=? where `wf_instance_id`=?"; - $this->query($query,array((int)$time,(int)$this->instanceId)); - } - - /*! - Gets the end time of the instance (when the process was completed) - */ - function getEnded() { - return $this->ended; - } - - /*! - Completes an activity, normally from any activity you should call this - function without arguments. - The arguments are explained just in case. - $activityId is the activity that is being completed, when this is not - passed the engine takes it from the $_REQUEST array,all activities - are executed passing the activityId in the URI. - $force indicates that the instance must be routed no matter if the - activity is auto-routing or not. This is used when "sending" an - instance from a non-auto-routed activity to the next activity. - $addworkitem indicates if a workitem should be added for the completed - activity. - YOU MUST NOT CALL complete() for non-interactive activities since - the engine does automatically complete automatic activities after - executing them. - */ - function complete($activityId=0,$force=false,$addworkitem=true) { - global $user; - global $__activity_completed; - - $__activity_completed = true; - - if(empty($user)) {$theuser='*';} else {$theuser=$user;} - - if($activityId==0) { - $activityId=$_REQUEST['activity_id']; - } - - // If we are completing a start activity then the instance must - // be created first! - $type = $this->getOne("select `wf_type` from `".GALAXIA_TABLE_PREFIX."activities` where `wf_activity_id`=?",array((int)$activityId)); - if($type=='start') { - $this->_createNewInstance((int)$activityId,$theuser); - } - - // Now set ended - $now = date("U"); - $query = "update `".GALAXIA_TABLE_PREFIX."instance_activities` set `wf_ended`=? where `wf_activity_id`=? and `wf_instance_id`=?"; - $this->query($query,array((int)$now,(int)$activityId,(int)$this->instanceId)); - //Add a workitem to the instance - $iid = $this->instanceId; - if($addworkitem) { - $max = $this->getOne("select max(`wf_order_id`) from `".GALAXIA_TABLE_PREFIX."workitems` where `wf_instance_id`=?",array((int)$iid)); - if(!$max) { - $max=1; - } else { - $max++; - } - $act = $this->_get_instance_activity($activityId); - if(!$act) { - //Then this is a start activity ending - $started = $this->getStarted(); - $putuser = $this->getOwner(); - } else { - $started=$act['wf_started']; - $putuser = $act['wf_user']; - } - $ended = date("U"); - $properties = serialize($this->properties); - $query="insert into `".GALAXIA_TABLE_PREFIX."workitems`(`wf_instance_id`,`wf_order_id`,`wf_activity_id`,`wf_started`,`wf_ended`,`wf_properties`,`wf_user`) values(?,?,?,?,?,?,?)"; - $this->query($query,array((int)$iid,(int)$max,(int)$activityId,(int)$started,(int)$ended,$properties,$putuser)); - } - - //Set the status for the instance-activity to completed - $this->setActivityStatus($activityId,'completed'); - - //If this and end actt then terminate the instance - if($type=='end') { - $this->terminate(); - return; - } - - //If the activity ending is autorouted then send to the - //activity - if ($type != 'end') { - if (($force) || ($this->getOne("select `wf_is_autorouted` from `".GALAXIA_TABLE_PREFIX."activities` where `wf_activity_id`=?",array($activityId)) == 'y')) { - // Now determine where to send the instance - $query = "select `wf_act_to_id` from `".GALAXIA_TABLE_PREFIX."transitions` where `wf_act_from_id`=?"; - $result = $this->query($query,array((int)$activityId)); - $candidates = Array(); - while ($res = $result->fetchRow()) { - $candidates[] = $res['wf_act_to_id']; - } - if($type == 'split') { - $erase_from = false; - $num_candidates = count($candidates); - $i = 1; - foreach ($candidates as $cand) { - // only erase split activity in instance when all the activities comming from the split have been set up - if ($i == $num_candidates) $erase_from = true; - $this->sendTo($activityId,$cand,$erase_from); - $i++; - } - } elseif($type == 'switch') { - if (in_array($this->nextActivity,$candidates)) { - $this->sendTo((int)$activityId,(int)$this->nextActivity); - } else { - trigger_error(tra('Fatal error: nextActivity does not match any candidate in autorouting switch activity'),E_USER_WARNING); - } - } else { - if (count($candidates)>1) { - trigger_error(tra('Fatal error: non-deterministic decision for autorouting activity'),E_USER_WARNING); - } else { - $this->sendTo((int)$activityId,(int)$candidates[0]); - } - } - } - } - } - - /*! - Aborts an activity and terminates the whole instance. We still create a workitem to keep track - of where in the process the instance was aborted - */ - function abort($activityId=0,$theuser = '',$addworkitem=true) { - if(empty($theuser)) { - global $user; - if (empty($user)) {$theuser='*';} else {$theuser=$user;} - } - - if($activityId==0) { - $activityId=$_REQUEST['wf_activity_id']; - } - - // If we are completing a start activity then the instance must - // be created first! - $type = $this->getOne("select `wf_type` from `".GALAXIA_TABLE_PREFIX."activities` where `wf_activity_id`=?",array((int)$activityId)); - if($type=='start') { - $this->_createNewInstance((int)$activityId,$theuser); - } - - // Now set ended - $now = date("U"); - $query = "update `".GALAXIA_TABLE_PREFIX."instance_activities` set `wf_ended`=? where `wf_activity_id`=? and `wf_instance_id`=?"; - $this->query($query,array((int)$now,(int)$activityId,(int)$this->instanceId)); - - //Add a workitem to the instance - $iid = $this->instanceId; - if($addworkitem) { - $max = $this->getOne("select max(`wf_order_id`) from `".GALAXIA_TABLE_PREFIX."workitems` where `wf_instance_id`=?",array((int)$iid)); - if(!$max) { - $max=1; - } else { - $max++; - } - $act = $this->_get_instance_activity($activityId); - if(!$act) { - //Then this is a start activity ending - $started = $this->getStarted(); - $putuser = $this->getOwner(); - } else { - $started=$act['wf_started']; - $putuser = $act['wf_user']; - } - $ended = date("U"); - $properties = serialize($this->properties); - $query="insert into `".GALAXIA_TABLE_PREFIX."workitems`(`wf_instance_id`,`wf_order_id`,`wf_activity_id`,`wf_started`,`wf_ended`,`wf_properties`,`wf_user`) values(?,?,?,?,?,?,?)"; - $this->query($query,array((int)$iid,(int)$max,(int)$activityId,(int)$started,(int)$ended,$properties,$putuser)); - } - - //Set the status for the instance-activity to aborted -// TODO: support 'aborted' if we keep activities after termination some day - //$this->setActivityStatus($activityId,'aborted'); - - // terminate the instance with status 'aborted' - $this->terminate('aborted'); - } - - /*! - Terminates the instance marking the instance and the process - as completed. This is the end of a process. - Normally you should not call this method since it is automatically - called when an end activity is completed. - */ - function terminate($status = 'completed') { - //Set the status of the instance to completed - $now = date("U"); - $query = "update `".GALAXIA_TABLE_PREFIX."instances` set `wf_status`=?, `wf_ended`=? where `wf_instance_id`=?"; - $this->query($query,array($status,(int)$now,(int)$this->instanceId)); - $query = "delete from `".GALAXIA_TABLE_PREFIX."instance_activities` where `wf_instance_id`=?"; - $this->query($query,array((int)$this->instanceId)); - $this->status = $status; - $this->activities = Array(); - } - - - /*! - Sends the instance from some activity to another activity. - You should not call this method unless you know very very well what - you are doing. - */ - function sendTo($from,$activityId,$erase_from=true) { - //1: if we are in a join check - //if this instance is also in - //other activity if so do - //nothing - $type = $this->getOne("select `wf_type` from `".GALAXIA_TABLE_PREFIX."activities` where `wf_activity_id`=?",array((int)$activityId)); - - // Verify the existance of a transition - if(!$this->getOne("select count(*) from `".GALAXIA_TABLE_PREFIX."transitions` where `wf_act_from_id`=? and `wf_act_to_id`=?",array($from,(int)$activityId))) { - trigger_error(tra('Fatal error: trying to send an instance to an activity but no transition found'),E_USER_WARNING); - } - - //try to determine the user or * - //Use the nextUser - if($this->nextUser) { - $putuser = $this->nextUser; - } else { - $candidates = Array(); - $query = "select `wf_role_id` from `".GALAXIA_TABLE_PREFIX."activity_roles` where `wf_activity_id`=?"; - $result = $this->query($query,array((int)$activityId)); - while ($res = $result->fetchRow()) { - $roleId = $res['wf_role_id']; - $query2 = "select `wf_user` from `".GALAXIA_TABLE_PREFIX."user_roles` where `wf_role_id`=?"; - $result2 = $this->query($query2,array((int)$roleId)); - while ($res2 = $result2->fetchRow()) { - $candidates[] = $res2['wf_user']; - } - } - if(count($candidates) == 1) { - $putuser = $candidates[0]; - } else { - $putuser = '*'; - } - } - //update the instance_activities table - //if not splitting delete first - //please update started,status,user - if($erase_from) { - $query = "delete from `".GALAXIA_TABLE_PREFIX."instance_activities` where `wf_instance_id`=? and `wf_activity_id`=?"; - $this->query($query,array((int)$this->instanceId,$from)); - } - - if ($type == 'join') { - if (count($this->activities)>1) { - // This instance will have to wait! - return; - } - } - - $now = date("U"); - $iid = $this->instanceId; - $query="delete from `".GALAXIA_TABLE_PREFIX."instance_activities` where `wf_instance_id`=? and `wf_activity_id`=?"; - $this->query($query,array((int)$iid,(int)$activityId)); - $query="insert into `".GALAXIA_TABLE_PREFIX."instance_activities`(`wf_instance_id`,`wf_activity_id`,`wf_user`,`wf_status`,`wf_started`) values(?,?,?,?,?)"; - $this->query($query,array((int)$iid,(int)$activityId,$putuser,'running',(int)$now)); - - //we are now in a new activity - $this->activities=Array(); - $query = "select * from `".GALAXIA_TABLE_PREFIX."instance_activities` where `wf_instance_id`=?"; - $result = $this->query($query,array((int)$iid)); - while ($res = $result->fetchRow()) { - $this->activities[]=$res; - } - - //if the activity is not interactive then - //execute the code for the activity and - //complete the activity - $isInteractive = $this->getOne("select `wf_is_interactive` from `".GALAXIA_TABLE_PREFIX."activities` where `wf_activity_id`=?",array((int)$activityId)); - if ($isInteractive=='n') { - - // Now execute the code for the activity (function defined in lib/Galaxia/config.php) - galaxia_execute_activity($activityId, $iid , 1); - - // Reload in case the activity did some change - $this->getInstance($this->instanceId); - $this->complete($activityId); - } - } - - /*! - Gets a comment for this instance - */ - function get_instance_comment($cId) { - $iid = $this->instanceId; - $query = "select * from `".GALAXIA_TABLE_PREFIX."instance_comments` where `wf_instance_id`=? and `wf_c_id`=?"; - $result = $this->query($query,array((int)$iid,(int)$cId)); - $res = $result->fetchRow(); - return $res; - } - - /*! - Inserts or updates an instance comment - */ - function replace_instance_comment($cId, $activityId, $activity, $user, $title, $comment) { - if (!$user) { - $user = 'Anonymous'; - } - $iid = $this->instanceId; - if ($cId) { - $query = "update `".GALAXIA_TABLE_PREFIX."instance_comments` set `wf_title`=?,`wf_comment`=? where `wf_instance_id`=? and `wf_c_id`=?"; - $this->query($query,array($title,$comment,(int)$iid,(int)$cId)); - } else { - $hash = md5($title.$comment); - if ($this->getOne("select count(*) from `".GALAXIA_TABLE_PREFIX."instance_comments` where `wf_instance_id`=? and `wf_hash`=?",array($iid,$hash))) { - return false; - } - $now = date("U"); - $query ="insert into `".GALAXIA_TABLE_PREFIX."instance_comments`(`wf_instance_id`,`wf_user`,`wf_activity_id`,`wf_activity`,`wf_title`,`wf_comment`,`wf_timestamp`,`wf_hash`) values(?,?,?,?,?,?,?,?)"; - $this->query($query,array((int)$iid,$user,(int)$activityId,$activity,$title,$comment,(int)$now,$hash)); - } - } - - /*! - Removes an instance comment - */ - function remove_instance_comment($cId) { - $iid = $this->instanceId; - $query = "delete from `".GALAXIA_TABLE_PREFIX."instance_comments` where `wf_c_id`=? and `wf_instance_id`=?"; - $this->query($query,array((int)$cId,(int)$iid)); - } - - /*! - Lists instance comments - */ - function get_instance_comments() { - $iid = $this->instanceId; - $query = "select * from `".GALAXIA_TABLE_PREFIX."instance_comments` where `wf_instance_id`=? order by ".$this->convert_sortmode("timestamp_desc"); - $result = $this->query($query,array((int)$iid)); - $ret = Array(); - while($res = $result->fetchRow()) { - $ret[] = $res; - } - return $ret; - } - -} -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/API/Process.php b/phpgwapi/inc/galaxia_workflow/src/API/Process.php deleted file mode 100644 index a8e84812f1..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/API/Process.php +++ /dev/null @@ -1,76 +0,0 @@ -db=$db; - } - - /*! - Loads a process form the database - */ - function getProcess($pId) { - $query = "select * from `".GALAXIA_TABLE_PREFIX."processes` where `wf_p_id`=?"; - $result = $this->query($query,array($pId)); - if(!$result->numRows()) return false; - $res = $result->fetchRow(); - $this->name = $res['wf_name']; - $this->description = $res['wf_description']; - $this->normalizedName = $res['wf_normalized_name']; - $this->version = $res['wf_version']; - $this->pId = $res['wf_p_id']; - } - - /*! - Gets the normalized name of the process - */ - function getNormalizedName() { - return $this->normalizedName; - } - - /*! - Gets the process name - */ - function getName() { - return $this->name; - } - - /*! - Gets the process version - */ - function getVersion() { - return $this->version; - } - - /*! - Gets information about an activity in this process by name, - e.g. $actinfo = $process->getActivityByName('Approve CD Request'); - if ($actinfo) { - $some_url = 'tiki-g-run_activity.php?activityId=' . $actinfo['activityId']; - } - */ - function getActivityByName($actname) { - // Get the activity data - $query = "select * from `".GALAXIA_TABLE_PREFIX."activities` where `wf_p_id`=? and `wf_name`=?"; - $pId = $this->pId; - $result = $this->query($query,array($pId,$actname)); - if(!$result->numRows()) return false; - $res = $result->fetchRow(); - return $res; - } - -} - -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/API/Role.php b/phpgwapi/inc/galaxia_workflow/src/API/Role.php deleted file mode 100644 index ca21adf8a1..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/API/Role.php +++ /dev/null @@ -1,12 +0,0 @@ - diff --git a/phpgwapi/inc/galaxia_workflow/src/API/Workitem.php b/phpgwapi/inc/galaxia_workflow/src/API/Workitem.php deleted file mode 100644 index 532931e9db..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/API/Workitem.php +++ /dev/null @@ -1,16 +0,0 @@ - diff --git a/phpgwapi/inc/galaxia_workflow/src/API/activities/Activity.php b/phpgwapi/inc/galaxia_workflow/src/API/activities/Activity.php deleted file mode 100644 index 7b922a28e0..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/API/activities/Activity.php +++ /dev/null @@ -1,14 +0,0 @@ -setDb($db); - } -} -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/API/activities/End.php b/phpgwapi/inc/galaxia_workflow/src/API/activities/End.php deleted file mode 100644 index 019b5e4bf8..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/API/activities/End.php +++ /dev/null @@ -1,14 +0,0 @@ -setDb($db); - } -} -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/API/activities/Join.php b/phpgwapi/inc/galaxia_workflow/src/API/activities/Join.php deleted file mode 100644 index 85489521db..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/API/activities/Join.php +++ /dev/null @@ -1,14 +0,0 @@ -setDb($db); - } -} -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/API/activities/Split.php b/phpgwapi/inc/galaxia_workflow/src/API/activities/Split.php deleted file mode 100644 index b6cd472904..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/API/activities/Split.php +++ /dev/null @@ -1,14 +0,0 @@ -setDb($db); - } -} -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/API/activities/Standalone.php b/phpgwapi/inc/galaxia_workflow/src/API/activities/Standalone.php deleted file mode 100644 index 030847feaa..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/API/activities/Standalone.php +++ /dev/null @@ -1,14 +0,0 @@ -setDb($db); - } -} -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/API/activities/Start.php b/phpgwapi/inc/galaxia_workflow/src/API/activities/Start.php deleted file mode 100644 index a501d29f1e..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/API/activities/Start.php +++ /dev/null @@ -1,14 +0,0 @@ -setDb($db); - } -} -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/API/activities/SwitchActivity.php b/phpgwapi/inc/galaxia_workflow/src/API/activities/SwitchActivity.php deleted file mode 100644 index 9218d45535..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/API/activities/SwitchActivity.php +++ /dev/null @@ -1,14 +0,0 @@ -setDb($db); - } -} -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/GUI/GUI.php b/phpgwapi/inc/galaxia_workflow/src/GUI/GUI.php deleted file mode 100644 index 10fd9fa610..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/GUI/GUI.php +++ /dev/null @@ -1,316 +0,0 @@ -convert_sortmode($sort_mode); - $sort_mode = str_replace("__"," ",$sort_mode); - - $mid = "where gp.wf_is_active=? and gur.wf_user=?"; - $bindvars = array('y',$user); - if($find) { - $findesc = '%'.$find.'%'; - $mid .= " and ((gp.wf_name like ?) or (gp.wf_description like ?))"; - $bindvars[] = $findesc; - $bindvars[] = $findesc; - } - if($where) { - $mid.= " and ($where) "; - } - - $query = "select distinct(gp.wf_p_id), - gp.wf_is_active, - gp.wf_name as wf_procname, - gp.wf_normalized_name as normalized_name, - gp.wf_version as wf_version, - gp.wf_version as version - from ".GALAXIA_TABLE_PREFIX."processes gp - INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.wf_p_id=ga.wf_p_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.wf_activity_id=ga.wf_activity_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.wf_role_id=gar.wf_role_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gr.wf_role_id - $mid order by $sort_mode"; - $query_cant = "select count(distinct(gp.wf_p_id)) - from ".GALAXIA_TABLE_PREFIX."processes gp - INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.wf_p_id=ga.wf_p_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.wf_activity_id=ga.wf_activity_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.wf_role_id=gar.wf_role_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gr.wf_role_id - $mid"; - $result = $this->query($query,$bindvars,$maxRecords,$offset); - $cant = $this->getOne($query_cant,$bindvars); - $ret = Array(); - while($res = $result->fetchRow()) { - // Get instances per activity - $pId=$res['wf_p_id']; - $res['wf_activities']=$this->getOne("select count(distinct(ga.wf_activity_id)) - from ".GALAXIA_TABLE_PREFIX."processes gp - INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.wf_p_id=ga.wf_p_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.wf_activity_id=ga.wf_activity_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.wf_role_id=gar.wf_role_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gr.wf_role_id - where gp.wf_p_id=? and gur.wf_user=?", - array($pId,$user)); - $res['wf_instances']=$this->getOne("select count(distinct(gi.wf_instance_id)) - from ".GALAXIA_TABLE_PREFIX."instances gi - INNER JOIN ".GALAXIA_TABLE_PREFIX."instance_activities gia ON gi.wf_instance_id=gia.wf_instance_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gia.wf_activity_id=gar.wf_activity_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gar.wf_role_id=gur.wf_role_id - where gi.wf_p_id=? and ((gia.wf_user=?) or (gia.wf_user=? and gur.wf_user=?))", - array($pId,$user,'*',$user)); - $ret[] = $res; - } - $retval = Array(); - $retval["data"] = $ret; - $retval["cant"] = $cant; - return $retval; - } - - - function gui_list_user_activities($user,$offset,$maxRecords,$sort_mode,$find,$where='') - { - // FIXME: this doesn't support multiple sort criteria - //$sort_mode = $this->convert_sortmode($sort_mode); - $sort_mode = str_replace("__"," ",$sort_mode); - - $mid = "where gp.wf_is_active=? and gur.wf_user=?"; - $bindvars = array('y',$user); - if($find) { - $findesc = '%'.$find.'%'; - $mid .= " and ((ga.wf_name like ?) or (ga.wf_description like ?))"; - $bindvars[] = $findesc; - $bindvars[] = $findesc; - } - if($where) { - $mid.= " and ($where) "; - } - - $query = "select distinct(ga.wf_activity_id), - ga.wf_name, - ga.wf_type, - gp.wf_name as wf_procname, - ga.wf_is_interactive, - ga.wf_is_autorouted, - ga.wf_activity_id, - gp.wf_version as wf_version, - gp.wf_p_id, - gp.wf_is_active - from ".GALAXIA_TABLE_PREFIX."processes gp - INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.wf_p_id=ga.wf_p_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.wf_activity_id=ga.wf_activity_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.wf_role_id=gar.wf_role_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gr.wf_role_id - $mid order by $sort_mode"; - $query_cant = "select count(distinct(ga.wf_activity_id)) - from ".GALAXIA_TABLE_PREFIX."processes gp - INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gp.wf_p_id=ga.wf_p_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.wf_activity_id=ga.wf_activity_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."roles gr ON gr.wf_role_id=gar.wf_role_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gr.wf_role_id - $mid"; - $result = $this->query($query,$bindvars,$maxRecords,$offset); - $cant = $this->getOne($query_cant,$bindvars); - $ret = Array(); - while($res = $result->fetchRow()) { - // Get instances per activity - $res['wf_instances']=$this->getOne("select count(distinct(gi.wf_instance_id)) - from ".GALAXIA_TABLE_PREFIX."instances gi - INNER JOIN ".GALAXIA_TABLE_PREFIX."instance_activities gia ON gi.wf_instance_id=gia.wf_instance_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gia.wf_activity_id=gar.wf_activity_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gar.wf_role_id=gur.wf_role_id - where gia.wf_activity_id=? and ((gia.wf_user=?) or (gia.wf_user=? and gur.wf_user=?))", - array($res['wf_activity_id'],$user,'*',$user)); - $ret[] = $res; - } - $retval = Array(); - $retval["data"] = $ret; - $retval["cant"] = $cant; - return $retval; - } - - - function gui_list_user_instances($user,$offset,$maxRecords,$sort_mode,$find,$where='') - { - // FIXME: this doesn't support multiple sort criteria - //$sort_mode = $this->convert_sortmode($sort_mode); - $sort_mode = str_replace("__"," ",$sort_mode); - - $mid = "where (gia.wf_user=? or (gia.wf_user=? and gur.wf_user=?))"; - $bindvars = array($user,'*',$user); - if($find) { - $findesc = '%'.$find.'%'; - $mid .= " and ((ga.wf_name like ?) or (ga.wf_description like ?))"; - $bindvars[] = $findesc; - $bindvars[] = $findesc; - } - if($where) { - $mid.= " and ($where) "; - } - - $query = "select distinct(gi.wf_instance_id), - gi.wf_started, - gi.wf_owner, - gia.wf_user, - gi.wf_status, - gia.wf_status as wf_act_status, - ga.wf_name, - ga.wf_type, - gp.wf_name as wf_procname, - ga.wf_is_interactive, - ga.wf_is_autorouted, - ga.wf_activity_id, - gp.wf_version as wf_version, - gp.wf_p_id - from ".GALAXIA_TABLE_PREFIX."instances gi - INNER JOIN ".GALAXIA_TABLE_PREFIX."instance_activities gia ON gi.wf_instance_id=gia.wf_instance_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gia.wf_activity_id = ga.wf_activity_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gia.wf_activity_id=gar.wf_activity_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gar.wf_role_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."processes gp ON gp.wf_p_id=ga.wf_p_id - $mid order by $sort_mode"; - $query_cant = "select count(distinct(gi.wf_instance_id)) - from ".GALAXIA_TABLE_PREFIX."instances gi - INNER JOIN ".GALAXIA_TABLE_PREFIX."instance_activities gia ON gi.wf_instance_id=gia.wf_instance_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."activities ga ON gia.wf_activity_id = ga.wf_activity_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gia.wf_activity_id=gar.wf_activity_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gur.wf_role_id=gar.wf_role_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."processes gp ON gp.wf_p_id=ga.wf_p_id - $mid"; - $result = $this->query($query,$bindvars,$maxRecords,$offset); - $cant = $this->getOne($query_cant,$bindvars); - $ret = Array(); - while($res = $result->fetchRow()) { - // Get instances per activity - $ret[] = $res; - } - $retval = Array(); - $retval["data"] = $ret; - $retval["cant"] = $cant; - return $retval; - } - - /*! - Abort an instance - this terminates the instance with status 'aborted', and removes all running activities - */ - function gui_abort_instance($user,$activityId,$instanceId) - { - // Users can only abort instances they're currently running, or instances that they're the owner of - if(!$this->getOne("select count(*) - from ".GALAXIA_TABLE_PREFIX."instance_activities gia, ".GALAXIA_TABLE_PREFIX."instances gi - where gia.wf_instance_id=gi.wf_instance_id and wf_activity_id=? and gia.wf_instance_id=? and (wf_user=? or wf_owner=?)", - array($activityId,$instanceId,$user,$user))) - return false; - include_once(GALAXIA_LIBRARY.'/src/API/Instance.php'); - $instance = new Instance($this->db); - $instance->getInstance($instanceId); - if (!empty($instance->instanceId)) { - $instance->abort($activityId,$user); - } - unset($instance); - } - - /*! - Exception handling for an instance - this sets the instance status to 'exception', but keeps all running activities. - The instance can be resumed afterwards via gui_resume_instance(). - */ - function gui_exception_instance($user,$activityId,$instanceId) - { - // Users can only do exception handling for instances they're currently running, or instances that they're the owner of - if(!$this->getOne("select count(*) - from ".GALAXIA_TABLE_PREFIX."instance_activities gia, ".GALAXIA_TABLE_PREFIX."instances gi - where gia.wf_instance_id=gi.wf_instance_id and wf_activity_id=? and gia.wf_instance_id=? and (wf_user=? or wf_owner=?)", - array($activityId,$instanceId,$user,$user))) - return false; - $query = "update ".GALAXIA_TABLE_PREFIX."instances - set wf_status=? - where wf_instance_id=?"; - $this->query($query, array('exception',$instanceId)); - } - - /*! - Resume an instance - this sets the instance status from 'exception' back to 'active' - */ - function gui_resume_instance($user,$activityId,$instanceId) - { - // Users can only resume instances they're currently running, or instances that they're the owner of - if(!$this->getOne("select count(*) - from ".GALAXIA_TABLE_PREFIX."instance_activities gia, ".GALAXIA_TABLE_PREFIX."instances gi - where gia.wf_instance_id=gi.wf_instance_id and wf_activity_id=? and gia.wf_instance_id=? and (wf_user=? or wf_owner=?)", - array($activityId,$instanceId,$user,$user))) - return false; - $query = "update ".GALAXIA_TABLE_PREFIX."instances - set wf_status=? - where wf_instance_id=?"; - $this->query($query, array('active',$instanceId)); - } - - - function gui_send_instance($user,$activityId,$instanceId) - { - if(! - ($this->getOne("select count(*) - from ".GALAXIA_TABLE_PREFIX."instance_activities - where wf_activity_id=? and wf_instance_id=? and wf_user=?", - array($activityId,$instanceId,$user))) - || - ($this->getOne("select count(*) - from ".GALAXIA_TABLE_PREFIX."instance_activities gia - INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.wf_activity_id=gia.wf_activity_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gar.wf_role_id=gur.wf_role_id - where gia.wf_instance_id=? and gia.wf_activity_id=? and gia.wf_user=? and gur.wf_user=?", - array($instanceId,$activityId,'*',$user))) - ) return false; - include_once(GALAXIA_LIBRARY.'/src/API/Instance.php'); - $instance = new Instance($this->db); - $instance->getInstance($instanceId); - $instance->complete($activityId,true,false); - unset($instance); - } - - function gui_release_instance($user,$activityId,$instanceId) - { - if(!$this->getOne("select count(*) - from ".GALAXIA_TABLE_PREFIX."instance_activities - where wf_activity_id=? and wf_instance_id=? and wf_user=?", - array($activityId,$instanceId,$user))) return false; - $query = "update ".GALAXIA_TABLE_PREFIX."instance_activities - set wf_user=? - where wf_instance_id=? and wf_activity_id=?"; - $this->query($query, array('*',$instanceId,$activityId)); - } - - function gui_grab_instance($user,$activityId,$instanceId) - { - // Grab only if roles are ok - if(!$this->getOne("select count(*) - from ".GALAXIA_TABLE_PREFIX."instance_activities gia - INNER JOIN ".GALAXIA_TABLE_PREFIX."activity_roles gar ON gar.wf_activity_id=gia.wf_activity_id - INNER JOIN ".GALAXIA_TABLE_PREFIX."user_roles gur ON gar.wf_role_id=gur.wf_role_id - where gia.wf_instance_id=? and gia.wf_activity_id=? and gia.wf_user=? and gur.wf_user=?", - array($instanceId,$activityId,'*',$user))) return false; - $query = "update ".GALAXIA_TABLE_PREFIX."instance_activities - set wf_user=? - where wf_instance_id=? and wf_activity_id=?"; - $this->query($query, array($user,$instanceId,$activityId)); - } -} -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/Observers/Logger.php b/phpgwapi/inc/galaxia_workflow/src/Observers/Logger.php deleted file mode 100644 index 74ccb55535..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/Observers/Logger.php +++ /dev/null @@ -1,33 +0,0 @@ -_filename = $filename; - $fp = fopen($this->_filename,"a"); - if(!$fp) { - trigger_error("Logger cannot append to log file: ".$this->filename,E_USER_WARNING); - } - if($fp) { - fclose($fp); - } - - } - - function notify($event,$msg) { - // Add a line to the log file. - $fp = fopen($this->_filename,"a"); - $date = date("[d/m/Y h:i:s]"); - $msg=trim($msg); - fputs($fp,$date." ".$msg."\n"); - fclose($fp); - } -} -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/ProcessManager/ActivityManager.php b/phpgwapi/inc/galaxia_workflow/src/ProcessManager/ActivityManager.php deleted file mode 100644 index b565b1bab2..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/ProcessManager/ActivityManager.php +++ /dev/null @@ -1,870 +0,0 @@ -db = $db; - } - - function get_error() { - return $this->error; - } - - /*! - Asociates an activity with a role - */ - function add_activity_role($activityId, $roleId) { - $query = "delete from `".GALAXIA_TABLE_PREFIX."activity_roles` where `wf_activity_id`=? and `wf_role_id`=?"; - $this->query($query,array($activityId, $roleId)); - $query = "insert into `".GALAXIA_TABLE_PREFIX."activity_roles`(`wf_activity_id`,`wf_role_id`) values(?,?)"; - $this->query($query,array($activityId, $roleId)); - } - - /*! - Gets the roles asociated to an activity - */ - function get_activity_roles($activityId) { - $query = "select wf_activity_id,roles.wf_role_id,roles.wf_name - from ".GALAXIA_TABLE_PREFIX."activity_roles gar, ".GALAXIA_TABLE_PREFIX."roles roles - where roles.wf_role_id = gar.wf_role_id and wf_activity_id=?"; - $result = $this->query($query,array($activityId)); - $ret = Array(); - while($res = $result->fetchRow()) { - $ret[] = $res; - } - return $ret; - } - - /*! - Removes a role from an activity - */ - function remove_activity_role($activityId, $roleId) - { - $query = "delete from ".GALAXIA_TABLE_PREFIX."activity_roles - where wf_activity_id=$activityId and wf_role_id=$roleId"; - $this->query($query); - } - - /*! - Checks if a transition exists - */ - function transition_exists($pid,$actFromId,$actToId) - { - return($this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."transitions where wf_p_id=$pid and wf_act_from_id=$actFromId and wf_act_to_id=$actToId")); - } - - /*! - Adds a transition - */ - function add_transition($pId, $actFromId, $actToId) - { - // No circular transitions allowed - if($actFromId == $actToId) { - $this->error= tra('No circular transitions allowed.'); - return false; - } - - // Rule: if act is not spl-x or spl-a it can't have more than - // 1 outbound transition. - $a1 = $this->get_activity($pId, $actFromId); - $a2 = $this->get_activity($pId, $actToId); - if(!$a1 || !$a2) { - $this->error = tra('No activites'); - return false; - } - if($a1['wf_type'] != 'switch' && $a1['wf_type'] != 'split') { - if($this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."transitions where wf_act_from_id=$actFromId")) { - $this->error = tra('Cannot add transition only split activities can have more than one outbound transition'); - return false; - } - } - - // Rule: if act is standalone no transitions allowed - if($a1['wf_type'] == 'standalone' || $a2['wf_type']=='standalone') { - $this->error= tra('No transitions allowed for standalone activities'); - return false; - } - // No inbound to start - if($a2['wf_type'] == 'start') { - $this->error= tra('No inbound for start activity'); - return false; - } - // No outbound from end - if($a1['wf_type'] == 'end') { - $this->error= tra('No outbound for end activity'); - return false; - } - - - $query = "delete from `".GALAXIA_TABLE_PREFIX."transitions` where `wf_act_from_id`=? and `wf_act_to_id`=?"; - $this->query($query,array($actFromId, $actToId)); - $query = "insert into `".GALAXIA_TABLE_PREFIX."transitions`(`wf_p_id`,`wf_act_from_id`,`wf_act_to_id`) values(?,?,?)"; - $this->query($query,array($pId, $actFromId, $actToId)); - - return true; - } - - /*! - Removes a transition - */ - function remove_transition($actFromId, $actToId) - { - $query = "delete from ".GALAXIA_TABLE_PREFIX."transitions where wf_act_from_id=$actFromId and wf_act_to_id=$actToId"; - $this->query($query); - return true; - } - - /*! - Removes all the activity transitions - */ - function remove_activity_transitions($pId, $aid) - { - $query = "delete from ".GALAXIA_TABLE_PREFIX."transitions where wf_p_id=$pId and (wf_act_from_id=$aid or wf_act_to_id=$aid)"; - $this->query($query); - } - - - /*! - Returns all the transitions for a process - */ - function get_process_transitions($pId,$actid=0) - { - if(!$actid) { - $query = "select a1.wf_name as wf_act_from_name, a2.wf_name as wf_act_to_name, wf_act_from_id, wf_act_to_id from ".GALAXIA_TABLE_PREFIX."transitions gt,".GALAXIA_TABLE_PREFIX."activities a1, ".GALAXIA_TABLE_PREFIX."activities a2 where gt.wf_act_from_id = a1.wf_activity_id and gt.wf_act_to_id = a2.wf_activity_id and gt.wf_p_id = $pId"; - } else { - $query = "select a1.wf_name as wf_act_from_name, a2.wf_name as wf_act_to_name, wf_act_from_id, wf_act_to_id from ".GALAXIA_TABLE_PREFIX."transitions gt,".GALAXIA_TABLE_PREFIX."activities a1, ".GALAXIA_TABLE_PREFIX."activities a2 where gt.wf_act_from_id = a1.wf_activity_id and gt.wf_act_to_id = a2.wf_activity_id and gt.wf_p_id = $pId and (wf_act_from_id = $actid)"; - } - $result = $this->query($query); - $ret = Array(); - while($res = $result->fetchRow()) { - $ret[] = $res; - } - return $ret; - } - - /*! - Indicates if an activity is autoRouted - */ - function activity_is_auto_routed($actid) - { - return($this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."activities where wf_activity_id=$actid and wf_is_autorouted='y'")); - } - - /*! - Returns all the activities for a process as - an array - */ - function get_process_activities($pId) - { - $query = "select * from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$pId"; - $result = $this->query($query); - $ret = Array(); - while($res = $result->fetchRow()) { - $ret[] = $res; - } - return $ret; - } - - /*! - Builds the graph - */ - //\todo build the real graph - function build_process_graph($pId) - { - $attributes = Array( - - ); - $graph = new Process_GraphViz(true,$attributes); - $pm = new ProcessManager($this->db); - $name = $pm->_get_normalized_name($pId); - $graph->set_pid($name); - - // Nodes are process activities so get - // the activities and add nodes as needed - $nodes = $this->get_process_activities($pId); - - foreach($nodes as $node) - { - if($node['wf_is_interactive']=='y') { - $color='blue'; - } else { - $color='black'; - } - $auto[$node['wf_name']] = $node['wf_is_autorouted']; - $graph->addNode($node['wf_name'],array('URL'=>"foourl?wf_activity_id=".$node['wf_activity_id'], - 'label'=>$node['wf_name'], - 'shape' => $this->_get_activity_shape($node['wf_type']), - 'color' => $color - - ) - ); - } - - // Now add edges, edges are transitions, - // get the transitions and add the edges - $edges = $this->get_process_transitions($pId); - foreach($edges as $edge) - { - if($auto[$edge['wf_actwf_from_name']] == 'y') { - $color = 'red'; - } else { - $color = 'black'; - } - $graph->addEdge(array($edge['wf_act_from_name'] => $edge['wf_act_to_name']), array('color'=>$color)); - } - - - // Save the map image and the image graph - $graph->image_and_map(); - unset($graph); - return true; - } - - - /*! - Validates if a process can be activated checking the - process activities and transitions the rules are: - 0) No circular activities - 1) Must have only one a start and end activity - 2) End must be reachable from start - 3) Interactive activities must have a role assigned - 4) Roles should be mapped - 5) Standalone activities cannot have transitions - 6) Non intractive activities non-auto routed must have some role - so the user can "send" the activity - 7) start activities must be autorouted and interactive - */ - function validate_process_activities($pId) - { - $errors = Array(); - // Pre rule no cricular activities - $cant = $this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."transitions where wf_p_id=$pId and wf_act_from_id=wf_act_to_id"); - if($cant) { - $errors[] = tra('Circular reference found some activity has a transition leading to itself'); - } - - // Rule 1 must have exactly one start and end activity - $cant = $this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$pId and wf_type='start'"); - if($cant < 1) { - $errors[] = tra('Process does not have a start activity'); - } - $cant = $this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$pId and wf_type='end'"); - if($cant != 1) { - $errors[] = tra('Process does not have exactly one end activity'); - } - - // Rule 2 end must be reachable from start - // and Rule 7 start activities must be autorouted and interactive - $nodes = Array(); - $endId = $this->getOne("select wf_activity_id from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$pId and wf_type='end'"); - $aux['id']=$endId; - $aux['visited']=false; - $nodes[] = $aux; - - $query = "select wf_is_autorouted,wf_is_interactive,wf_activity_id from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$pId and wf_type='start'"; - $result = $this->query($query); - while($res = $result->fetchRow()) { - $start_node['id'] = $res['wf_activity_id']; - if(!($res['wf_is_interactive'] == 'y')) { - $errors[] = tra('start activities must be interactive'); - } - if(!($res['wf_is_autorouted'] == 'y')) { - $errors[] = tra('start activities must be autorouted'); - } - } - $start_node['visited']=true; - - while($this->_list_has_unvisited_nodes($nodes) && !$this->_node_in_list($start_node,$nodes)) { - for($i=0;$iquery($query); - while($res = $result->fetchRow()) { - $aid = $res['wf_activity_id']; - if($res['wf_is_interactive'] == 'y') { - $cant = $this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."activity_roles where wf_activity_id=".$res['wf_activity_id']); - if(!$cant) { - $errors[] = tra('Activity %1 is interactive but has no role assigned', $res['wf_name']); - } - } else { - if( $res['wf_type'] != 'end' && $res['wf_is_autorouted'] == 'n') { - $cant = $this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."activity_roles where wf_activity_id=".$res['wf_activity_id']); - if(!$cant) { - $errors[] = tra('Activity %1 is non-interactive and non-autorouted but has no role assigned', $res['wf_name']); - } - } - } - if($res['wf_type']=='standalone') { - if($this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."transitions where wf_act_from_id=$aid or wf_act_to_id=$aid")) { - $errors[] = tra('Activity %1 is standalone but has transitions', $res['wf_name']); - } - } - - } - - - //Rule4: roles should be mapped - $query = "select * from ".GALAXIA_TABLE_PREFIX."roles where wf_p_id = $pId"; - $result = $this->query($query); - while($res = $result->fetchRow()) { - $cant = $this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."user_roles where wf_role_id=".$res['wf_role_id']); - if(!$cant) { - $errors[] = tra('Role %1 is not mapped', $res['wf_name']); - } - } - - - // End of rules - - // Validate process sources - $serrors=$this->validate_process_sources($pId); - $errors = array_merge($errors,$serrors); - - $this->error = $errors; - - - - $isValid = (count($errors)==0) ? 'y' : 'n'; - - $query = "update ".GALAXIA_TABLE_PREFIX."processes set wf_is_valid='$isValid' where wf_p_id=$pId"; - $this->query($query); - - $this->_label_nodes($pId); - - return ($isValid=='y'); - - - } - - /*! - Validate process sources - Rules: - 1) Interactive activities (non-standalone) must use complete() - 2) Standalone activities must not use $instance - 3) Switch activities must use setNextActivity - 4) Non-interactive activities cannot use complete() - */ - function validate_process_sources($pid) - { - $errors=Array(); - $wf_procname= $this->getOne("select wf_normalized_name from ".GALAXIA_TABLE_PREFIX."processes where wf_p_id=$pid"); - - $query = "select * from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$pid"; - $result = $this->query($query); - while($res = $result->fetchRow()) { - $actname = $res['wf_normalized_name']; - $source = GALAXIA_PROCESSES."/$wf_procname/code/activities/$actname".'.php'; - if (!file_exists($source)) { - continue; - } - $fp = fopen($source,'r'); - $data=''; - while(!feof($fp)) { - $data.=fread($fp,8192); - } - fclose($fp); - if($res['wf_type']=='standalone') { - if(strstr($data,'$instance')) { - $errors[] = tra('Activity %1 is standalone and is using the $instance object', $res['wf_name']); - } - } else { - if($res['wf_is_interactive']=='y') { - if(!strstr($data,'$instance->complete()')) { - $errors[] = tra('Activity %1 is interactive so it must use the $instance->complete() method', $res['wf_name']); - } - } else { - if(strstr($data,'$instance->complete()')) { - $errors[] = tra('Activity %1 is non-interactive so it must not use the $instance->complete() method', $res['wf_name']); - } - } - if($res['wf_type']=='switch') { - if(!strstr($data,'$instance->setNextActivity(')) { - $errors[] = tra('Activity %1 is switch so it must use $instance->setNextActivity($actname) method', $res['wf_name']); - } - } - } - } - return $errors; - } - - /*! - Indicates if an activity with the same name exists - */ - function activity_name_exists($pId,$name) - { - $name = addslashes($this->_normalize_name($name)); - return $this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$pId and wf_normalized_name='$name'"); - } - - - /*! - Gets a activity fields are returned as an asociative array - */ - function get_activity($pId, $activityId) - { - $query = "select * from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$pId and wf_activity_id=$activityId"; - $result = $this->query($query); - $res = $result->fetchRow(); - return $res; - } - - /*! - Lists activities at a per-process level - */ - function list_activities($pId,$offset,$maxRecords,$sort_mode,$find,$where='') - { - $sort_mode = str_replace("__"," ",$sort_mode); - if($find) { - $findesc = '%'.$find.'%'; - $mid=" where wf_p_id=? and ((wf_name like ?) or (wf_description like ?))"; - $bindvars = array($pId,$findesc,$findesc); - } else { - $mid=" where wf_p_id=? "; - $bindvars = array($pId); - } - if($where) { - $mid.= " and ($where) "; - } - $query = "select * from ".GALAXIA_TABLE_PREFIX."activities $mid order by $sort_mode"; - $query_cant = "select count(*) from ".GALAXIA_TABLE_PREFIX."activities $mid"; - $result = $this->query($query,$bindvars,$maxRecords,$offset); - $cant = $this->getOne($query_cant,$bindvars); - $ret = Array(); - while($res = $result->fetchRow()) { - $res['wf_roles'] = $this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."activity_roles where wf_activity_id=?",array($res['wf_activity_id'])); - $ret[] = $res; - } - $retval = Array(); - $retval["data"] = $ret; - $retval["cant"] = $cant; - return $retval; - } - - - - /*! - Removes a activity. - */ - function remove_activity($pId, $activityId) - { - $pm = new ProcessManager($this->db); - $proc_info = $pm->get_process($pId); - $actname = $this->_get_normalized_name($activityId); - $query = "delete from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$pId and wf_activity_id=$activityId"; - $this->query($query); - $query = "select wf_act_from_id,wf_act_to_id from ".GALAXIA_TABLE_PREFIX."transitions where wf_act_from_id=$activityId or wf_act_to_id=$activityId"; - $result = $this->query($query); - while($res = $result->fetchRow()) { - $this->remove_transition($res['wf_act_from_id'], $res['wf_act_to_id']); - } - $query = "delete from ".GALAXIA_TABLE_PREFIX."activity_roles where wf_activity_id=$activityId"; - $this->query($query); - // And we have to remove the user and compiled files - // for this activity - $wf_procname = $proc_info['wf_normalized_name']; - unlink(GALAXIA_PROCESSES."/$wf_procname/code/activities/$actname".'.php'); - if (file_exists(GALAXIA_PROCESSES."/$wf_procname/code/templates/$actname".'.tpl')) { - @unlink(GALAXIA_PROCESSES."/$wf_procname/code/templates/$actname".'.tpl'); - } - unlink(GALAXIA_PROCESSES."/$wf_procname/compiled/$actname".'.php'); - return true; - } - - /*! - Updates or inserts a new activity in the database, $vars is an asociative - array containing the fields to update or to insert as needed. - $pId is the processId - $activityId is the activityId - */ - function replace_activity($pId, $activityId, $vars, $create_files=true) - { - $TABLE_NAME = GALAXIA_TABLE_PREFIX."activities"; - $now = date("U"); - $vars['wf_last_modif']=$now; - $vars['wf_p_id']=$pId; - $vars['wf_normalized_name'] = $this->_normalize_name($vars['wf_name']); - - $pm = new ProcessManager($this->db); - $proc_info = $pm->get_process($pId); - - - foreach($vars as $key=>$value) - { - $vars[$key]=addslashes($value); - } - - if($activityId) { - $oldname = $this->_get_normalized_name($activityId); - // update mode - $first = true; - $query ="update $TABLE_NAME set"; - foreach($vars as $key=>$value) { - if(!$first) $query.= ','; - if(!is_numeric($value)) $value="'".$value."'"; - $query.= " $key=$value "; - $first = false; - } - $query .= " where wf_p_id=$pId and wf_activity_id=$activityId "; - $this->query($query); - - $newname = $vars['wf_normalized_name']; - // if the activity is changing name then we - // should rename the user_file for the activity - // remove the old compiled file and recompile - // the activity - - $user_file_old = GALAXIA_PROCESSES.'/'.$proc_info['wf_normalized_name'].'/code/activities/'.$oldname.'.php'; - $user_file_new = GALAXIA_PROCESSES.'/'.$proc_info['wf_normalized_name'].'/code/activities/'.$newname.'.php'; - rename($user_file_old, $user_file_new); - - $user_file_old = GALAXIA_PROCESSES.'/'.$proc_info['wf_normalized_name'].'/code/templates/'.$oldname.'.tpl'; - $user_file_new = GALAXIA_PROCESSES.'/'.$proc_info['wf_normalized_name'].'/code/templates/'.$newname.'.tpl'; - if ($user_file_old != $user_file_new) { - @rename($user_file_old, $user_file_new); - } - - - $compiled_file = GALAXIA_PROCESSES.'/'.$proc_info['wf_normalized_name'].'/compiled/'.$oldname.'.php'; - unlink($compiled_file); - $this->compile_activity($pId,$activityId); - - - } else { - - // When inserting activity names can't be duplicated - if($this->activity_name_exists($pId, $vars['wf_name'])) { - return false; - } - unset($vars['wf_activity_id']); - // insert mode - $first = true; - $query = "insert into $TABLE_NAME("; - foreach(array_keys($vars) as $key) { - if(!$first) $query.= ','; - $query.= "$key"; - $first = false; - } - $query .=") values("; - $first = true; - foreach(array_values($vars) as $value) { - if(!$first) $query.= ','; - if(!is_numeric($value)) $value="'".$value."'"; - $query.= "$value"; - $first = false; - } - $query .=")"; - $this->query($query); - $activityId = $this->getOne("select max(wf_activity_id) from $TABLE_NAME where wf_p_id=$pId and wf_last_modif=$now"); - $ret = $activityId; - if(!$activityId) { - print("select max(wf_activity_id) from $TABLE_NAME where wf_p_id=$pId and wf_last_modif=$now"); - die; - } - // Should create the code file - if ($create_files) { - $wf_procname = $proc_info["wf_normalized_name"]; - $fw = fopen(GALAXIA_PROCESSES."/$wf_procname/code/activities/".$vars['wf_normalized_name'].'.php','w'); - fwrite($fw,'<'.'?'.'php'."\n".'?'.'>'); - fclose($fw); - - if($vars['wf_is_interactive']=='y') { - $fw = fopen(GALAXIA_PROCESSES."/$wf_procname/code/templates/".$vars['wf_normalized_name'].'.tpl','w'); - if (defined('GALAXIA_TEMPLATE_HEADER') && GALAXIA_TEMPLATE_HEADER) { - fwrite($fw,GALAXIA_TEMPLATE_HEADER . "\n"); - } - fclose($fw); - } - } - - $this->compile_activity($pId,$activityId); - - } - // Get the id - return $activityId; - } - - /*! - Sets if an activity is interactive or not - */ - function set_interactivity($pId, $actid, $value) - { - $query = "update ".GALAXIA_TABLE_PREFIX."activities set wf_is_interactive='$value' where wf_p_id=$pId and wf_activity_id=$actid"; - $this->query($query); - // If template does not exist then create template - $this->compile_activity($pId,$actid); - } - - /*! - Sets if an activity is auto routed or not - */ - function set_autorouting($pId, $actid, $value) - { - $query = "update ".GALAXIA_TABLE_PREFIX."activities set wf_is_autorouted='$value' where wf_p_id=$pId and wf_activity_id=$actid"; - $this->query($query); - } - - - /*! - Compiles activity - */ - function compile_activity($pId, $activityId) - { - $act_info = $this->get_activity($pId,$activityId); - $actname = $act_info['wf_normalized_name']; - $pm = new ProcessManager($this->db); - $proc_info = $pm->get_process($pId); - $compiled_file = GALAXIA_PROCESSES.'/'.$proc_info['wf_normalized_name'].'/compiled/'.$act_info['wf_normalized_name'].'.php'; - $template_file = GALAXIA_PROCESSES.'/'.$proc_info['wf_normalized_name'].'/code/templates/'.$actname.'.tpl'; - $user_file = GALAXIA_PROCESSES.'/'.$proc_info['wf_normalized_name'].'/code/activities/'.$actname.'.php'; - $pre_file = GALAXIA_LIBRARY.'/compiler/'.$act_info['wf_type'].'_pre.php'; - $pos_file = GALAXIA_LIBRARY.'/compiler/'.$act_info['wf_type'].'_pos.php'; - $fw = fopen($compiled_file,"wb"); - - // First of all add an include to to the shared code - $shared_file = GALAXIA_PROCESSES.'/'.$proc_info['wf_normalized_name'].'/code/shared.php'; - - fwrite($fw, '<'."?php include_once('$shared_file'); ?".'>'."\n"); - - // Before pre shared - $fp = fopen(GALAXIA_LIBRARY.'/compiler/_shared_pre.php',"rb"); - while (!feof($fp)) { - $data = fread($fp, 4096); - fwrite($fw,$data); - } - fclose($fp); - - // Now get pre and pos files for the activity - $fp = fopen($pre_file,"rb"); - while (!feof($fp)) { - $data = fread($fp, 4096); - fwrite($fw,$data); - } - fclose($fp); - - // Get the user data for the activity - $fp = fopen($user_file,"rb"); - while (!feof($fp)) { - $data = fread($fp, 4096); - fwrite($fw,$data); - } - fclose($fp); - - // Get pos and write - $fp = fopen($pos_file,"rb"); - while (!feof($fp)) { - $data = fread($fp, 4096); - fwrite($fw,$data); - } - fclose($fp); - - // Shared pos - $fp = fopen(GALAXIA_LIBRARY.'/compiler/_shared_pos.php',"rb"); - while (!feof($fp)) { - $data = fread($fp, 4096); - fwrite($fw,$data); - } - fclose($fp); - - fclose($fw); - - //Copy the templates - - if($act_info['wf_is_interactive']=='y' && !file_exists($template_file)) { - $fw = fopen($template_file,'w'); - if (defined('GALAXIA_TEMPLATE_HEADER') && GALAXIA_TEMPLATE_HEADER) { - fwrite($fw,GALAXIA_TEMPLATE_HEADER . "\n"); - } - fclose($fw); - } - if($act_info['wf_is_interactive']!='y' && file_exists($template_file)) { - @unlink($template_file); - if (GALAXIA_TEMPLATES && file_exists(GALAXIA_TEMPLATES.'/'.$proc_info['wf_normalized_name']."/$actname.tpl")) { - @unlink(GALAXIA_TEMPLATES.'/'.$proc_info['wf_normalized_name']."/$actname.tpl"); - } - } - if (GALAXIA_TEMPLATES && file_exists($template_file)) { - @copy($template_file,GALAXIA_TEMPLATES.'/'.$proc_info['wf_normalized_name']."/$actname.tpl"); - } - } - - /*! - \private - Returns activity id by pid,name (activity names are unique) - */ - function _get_activity_id_by_name($pid,$name) - { - $name = addslashes($name); - if($this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$pid and wf_name='$name'")) { - return($this->getOne("select wf_activity_id from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$pid and wf_name='$name'")); - } else { - return ''; - } - } - - /*! - \private Returns the activity shape - */ - function _get_activity_shape($type) - { - switch($type) { - case "start": - return "circle"; - case "end": - return "doublecircle"; - case "activity": - return "box"; - case "split": - return "triangle"; - case "switch": - return "diamond"; - case "join": - return "invtriangle"; - case "standalone": - return "hexagon"; - default: - return "egg"; - - } - - } - - - /*! - \private Returns true if a list contains unvisited nodes - list members are asoc arrays containing id and visited - */ - function _list_has_unvisited_nodes($list) - { - foreach($list as $node) { - if(!$node['visited']) return true; - } - return false; - } - - /*! - \private Returns true if a node is in a list - list members are asoc arrays containing id and visited - */ - function _node_in_list($node,$list) - { - foreach($list as $a_node) { - if($node['id'] == $a_node['id']) return true; - } - return false; - } - - /*! - \private - Normalizes an activity name - */ - function _normalize_name($name) - { - $name = str_replace(" ","_",$name); - $name = preg_replace("/[^A-Za-z_]/",'',$name); - return $name; - } - - /*! - \private - Returns normalized name of an activity - */ - function _get_normalized_name($activityId) - { - return $this->getOne("select wf_normalized_name from ".GALAXIA_TABLE_PREFIX."activities where wf_activity_id=$activityId"); - } - - /*! - \private - Labels nodes - */ - function _label_nodes($pId) - { - - - ///an empty list of nodes starts the process - $nodes = Array(); - // the end activity id - $endId = $this->getOne("select wf_activity_id from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$pId and wf_type='end'"); - // and the number of total nodes (=activities) - $cant = $this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$pId"); - $nodes[] = $endId; - $label = $cant; - $num = $cant; - - $query = "update ".GALAXIA_TABLE_PREFIX."activities set wf_flow_num=$cant+1 where wf_p_id=$pId"; - $this->query($query); - - $seen = array(); - while(count($nodes)) { - $newnodes = Array(); - foreach($nodes as $node) { - // avoid endless loops - if (isset($seen[$node])) continue; - $seen[$node] = 1; - $query = "update ".GALAXIA_TABLE_PREFIX."activities set wf_flow_num=$num where wf_activity_id=$node"; - $this->query($query); - $query = "select wf_act_from_id from ".GALAXIA_TABLE_PREFIX."transitions where wf_act_to_id=".$node; - $result = $this->query($query); - $ret = Array(); - while($res = $result->fetchRow()) { - $newnodes[] = $res['wf_act_from_id']; - } - } - $num--; - $nodes=Array(); - $nodes=$newnodes; - - } - - $min = $this->getOne("select min(wf_flow_num) from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$pId"); - $query = "update ".GALAXIA_TABLE_PREFIX."activities set wf_flow_num=wf_flow_num-$min where wf_p_id=$pId"; - $this->query($query); - - //$query = "update ".GALAXIA_TABLE_PREFIX."activities set flowNum=0 where flowNum=$cant+1"; - //$this->query($query); - } - -} - - -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/ProcessManager/BaseManager.php b/phpgwapi/inc/galaxia_workflow/src/ProcessManager/BaseManager.php deleted file mode 100644 index c17d618f5f..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/ProcessManager/BaseManager.php +++ /dev/null @@ -1,22 +0,0 @@ -db = $db; - } - -} //end of class - -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/ProcessManager/GraphViz.php b/phpgwapi/inc/galaxia_workflow/src/ProcessManager/GraphViz.php deleted file mode 100644 index 7a4479a7bc..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/ProcessManager/GraphViz.php +++ /dev/null @@ -1,465 +0,0 @@ - and | -// | Dr. Volker Göbbels . | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 3.00 of the PHP License, | -// | that is available at http://www.php.net/license/3_0.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// -// $Id$ -// - -/** -* PEAR::Image_GraphViz -* -* Purpose -* -* Allows for the creation of and the work with directed -* and undirected graphs and their visualization with -* AT&T's GraphViz tools. These can be found at -* http://www.research.att.com/sw/tools/graphviz/ -* -* Example -* -* require_once 'Image/GraphViz.php'; -* $graph = new Image_GraphViz(); -* -* $graph->addNode('Node1', array('URL' => 'http://link1', -* 'label' => 'This is a label', -* 'shape' => 'box' -* ) -* ); -* $graph->addNode('Node2', array('URL' => 'http://link2', -* 'fontsize' => '14' -* ) -* ); -* $graph->addNode('Node3', array('URL' => 'http://link3', -* 'fontsize' => '20' -* ) -* ); -* -* $graph->addEdge(array('Node1' => 'Node2'), array('label' => 'Edge Label')); -* $graph->addEdge(array('Node1' => 'Node2'), array('color' => 'red')); -* -* $graph->image(); -* -* @author Sebastian Bergmann -* Dr. Volker Göbbels -* @package Image -*/ -class Process_GraphViz { - /** - * Path to GraphViz/dot command - * - * @var string - */ - var $dotCommand = 'dot'; - - var $pid; - - /** - * Path to GraphViz/neato command - * - * @var string - */ - var $neatoCommand = 'neato'; - - /** - * Representation of the graph - * - * @var array - */ - var $graph; - - /** - * Constructor - * - * @param boolean Directed (true) or undirected (false) graph. - * @param array Attributes of the graph - * @access public - */ - function Process_GraphViz($directed = true, $attributes = array()) { - $this->setDirected($directed); - $this->setAttributes($attributes); - if (defined('GRAPHVIZ_BIN_DIR') && GRAPHVIZ_BIN_DIR) { - $this->dotCommand = GRAPHVIZ_BIN_DIR.'/'.$this->dotCommand; - $this->neatoCommand = GRAPHVIZ_BIN_DIR.'/'.$this->neatoCommand; - } - } - - function set_pid($pid) - { - $this->pid = $pid; - } - - /** - * Output image of the graph in a given format. - * - * @param string Format of the output image. - * This may be one of the formats supported by GraphViz. - * @access public - */ - function image($format = 'png') { - if ($file = $this->saveParsedGraph()) { - $outputfile = $file . '.' . $format; - $outputfile2 = $file . '.' . 'map'; - $command = $this->graph['directed'] ? $this->dotCommand : $this->neatoCommand; - $command .= " -T$format -o$outputfile $file"; - - @`$command`; - $command = $this->dotCommand; - $command.= " -Tcmap -o$outputfile2 $file"; - @`$command`; - $fr = fopen($outputfile2,"r"); - $map = fread($fr,filesize($outputfile2)); - fclose($fr); - @unlink($file); - - switch ($format) { - case 'gif': - case 'jpg': - case 'png': - case 'svg': - case 'wbmp': { - header('Content-Type: image/' . $format); - } - break; - - case 'pdf': { - header('Content-Type: application/pdf'); - } - break; - } - - header('Content-Length: ' . filesize($outputfile)); - - $fp = fopen($outputfile, 'rb'); - - if ($fp) { - echo fread($fp, filesize($outputfile)); - fclose($fp); - @unlink($outputfile); - } - @unlink($outputfile2); - return $map; - } - } - - function image_and_map($format = 'png') { - if ($file = $this->saveParsedGraph()) { - $outputfile = $file . '.' . $format; - $outputfile2 = $file . '.' . 'map'; - if(!isset($this->graph['directed'])) $this->graph['directed']=true; - $command = $this->graph['directed'] ? $this->dotCommand : $this->neatoCommand; - $command .= " -T$format -o $outputfile $file"; - @`$command`; - - $command = $this->dotCommand; - $command.= " -Tcmap -o $outputfile2 $file"; - @`$command`; - @unlink($file); - return true; - } - } - - - function map() { - if ($file = $this->saveParsedGraph()) { - - $outputfile2 = $file . '.' . 'map'; - - $command = $this->dotCommand; - $command.= " -Tcmap -o$outputfile2 $file"; - @`$command`; - $fr = fopen($outputfile2,"r"); - $map = fread($fr,filesize($outputfile2)); - fclose($fr); - - @unlink($outputfile2); - @unlink($file); - return $map; - } - } - - /** - * Add a cluster to the graph. - * - * @param string ID. - * @param array Title. - * @access public - */ - function addCluster($id, $title) { - $this->graph['clusters'][$id] = $title; - } - - /** - * Add a note to the graph. - * - * @param string Name of the node. - * @param array Attributes of the node. - * @param string Group of the node. - * @access public - */ - function addNode($name, $attributes = array(), $group = 'default') { - $this->graph['nodes'][$group][$name] = $attributes; - } - - /** - * Remove a node from the graph. - * - * @param Name of the node to be removed. - * @access public - */ - function removeNode($name, $group = 'default') { - if (isset($this->graph['nodes'][$group][$name])) { - unset($this->graph['nodes'][$group][$name]); - } - } - - /** - * Add an edge to the graph. - * - * @param array Start and End node of the edge. - * @param array Attributes of the edge. - * @access public - */ - function addEdge($edge, $attributes = array()) { - if (is_array($edge)) { - $from = key($edge); - $to = $edge[$from]; - $id = $from . '_' . $to; - - if (!isset($this->graph['edges'][$id])) { - $this->graph['edges'][$id] = $edge; - } else { - $this->graph['edges'][$id] = array_merge( - $this->graph['edges'][$id], - $edge - ); - } - - if (is_array($attributes)) { - if (!isset($this->graph['edgeAttributes'][$id])) { - $this->graph['edgeAttributes'][$id] = $attributes; - } else { - $this->graph['edgeAttributes'][$id] = array_merge( - $this->graph['edgeAttributes'][$id], - $attributes - ); - } - } - } - } - - /** - * Remove an edge from the graph. - * - * @param array Start and End node of the edge to be removed. - * @access public - */ - function removeEdge($edge) { - if (is_array($edge)) { - $from = key($edge); - $to = $edge[$from]; - $id = $from . '_' . $to; - - if (isset($this->graph['edges'][$id])) { - unset($this->graph['edges'][$id]); - } - - if (isset($this->graph['edgeAttributes'][$id])) { - unset($this->graph['edgeAttributes'][$id]); - } - } - } - - /** - * Add attributes to the graph. - * - * @param array Attributes to be added to the graph. - * @access public - */ - function addAttributes($attributes) { - if (is_array($attributes)) { - $this->graph['attributes'] = array_merge( - $this->graph['attributes'], - $attributes - ); - } - } - - /** - * Set attributes of the graph. - * - * @param array Attributes to be set for the graph. - * @access public - */ - function setAttributes($attributes) { - if (is_array($attributes)) { - $this->graph['attributes'] = $attributes; - } - } - - /** - * Set directed/undirected flag for the graph. - * - * @param boolean Directed (true) or undirected (false) graph. - * @access public - */ - function setDirected($directed) { - if (is_bool($directed)) { - $this->graph['directed'] = $directed; - } - } - - /** - * Load graph from file. - * - * @param string File to load graph from. - * @access public - */ - function load($file) { - if ($serialized_graph = implode('', @file($file))) { - $this->graph = unserialize($serialized_graph); - } - } - - /** - * Save graph to file. - * - * @param string File to save the graph to. - * @return mixed File the graph was saved to, false on failure. - * @access public - */ - function save($file = '') { - $serialized_graph = serialize($this->graph); - - if (empty($file)) { - $file = tempnam('temp', 'graph_'); - } - - if ($fp = @fopen($file, 'w')) { - @fputs($fp, $serialized_graph); - @fclose($fp); - - return $file; - } - - return false; - } - - /** - * Parse the graph into GraphViz markup. - * - * @return string GraphViz markup - * @access public - */ - function parse() { - $parsedGraph = "digraph G {\n"; - - if (isset($this->graph['attributes'])) { - foreach ($this->graph['attributes'] as $key => $value) { - $attributeList[] = $key . '="' . $value . '"'; - } - - if (!empty($attributeList)) { - $parsedGraph .= implode(',', $attributeList) . ";\n"; - } - } - - if (isset($this->graph['nodes'])) { - foreach($this->graph['nodes'] as $group => $nodes) { - if ($group != 'default') { - $parsedGraph .= sprintf( - "subgraph \"cluster_%s\" {\nlabel=\"%s\";\n", - - $group, - isset($this->graph['clusters'][$group]) ? $this->graph['clusters'][$group] : '' - ); - } - - foreach($nodes as $node => $attributes) { - unset($attributeList); - - foreach($attributes as $key => $value) { - $attributeList[] = $key . '="' . $value . '"'; - } - - if (!empty($attributeList)) { - $parsedGraph .= sprintf( - "\"%s\" [ %s ];\n", - addslashes(stripslashes($node)), - implode(',', $attributeList) - ); - } - } - - if ($group != 'default') { - $parsedGraph .= "}\n"; - } - } - } - - if (isset($this->graph['edges'])) { - foreach($this->graph['edges'] as $label => $node) { - unset($attributeList); - - $from = key($node); - $to = $node[$from]; - - foreach($this->graph['edgeAttributes'][$label] as $key => $value) { - $attributeList[] = $key . '="' . $value . '"'; - } - - $parsedGraph .= sprintf( - '"%s" -> "%s"', - addslashes(stripslashes($from)), - addslashes(stripslashes($to)) - ); - - if (!empty($attributeList)) { - $parsedGraph .= sprintf( - ' [ %s ]', - implode(',', $attributeList) - ); - } - - $parsedGraph .= ";\n"; - } - } - - return $parsedGraph . "}\n"; - } - - /** - * Save GraphViz markup to file. - * - * @param string File to write the GraphViz markup to. - * @return mixed File to which the GraphViz markup was - * written, false on failure. - * @access public - */ - function saveParsedGraph($file = '') { - $parsedGraph = $this->parse(); - if (!empty($parsedGraph)) { - - $file = GALAXIA_PROCESSES.'/'.$this->pid.'/graph/'.$this->pid; - if ($fp = @fopen($file, 'w')) { - @fputs($fp, $parsedGraph); - @fclose($fp); - - return $file; - } - } - - return false; - } -} -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/ProcessManager/InstanceManager.php b/phpgwapi/inc/galaxia_workflow/src/ProcessManager/InstanceManager.php deleted file mode 100644 index 7d2b48e1e1..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/ProcessManager/InstanceManager.php +++ /dev/null @@ -1,86 +0,0 @@ -db = $db; - } - - function get_instance_activities($iid) - { - $query = "select ga.wf_type,ga.wf_is_interactive,ga.wf_is_autorouted,gi.wf_p_id,ga.wf_activity_id,ga.wf_name,gi.wf_instance_id,gi.wf_status,gia.wf_activity_id,gia.wf_user,gi.wf_started,gia.wf_status as wf_act_status from ".GALAXIA_TABLE_PREFIX."activities ga,".GALAXIA_TABLE_PREFIX."instances gi,".GALAXIA_TABLE_PREFIX."instance_activities gia where ga.wf_activity_id=gia.wf_activity_id and gi.wf_instance_id=gia.wf_instance_id and gi.wf_instance_id=$iid"; - $result = $this->query($query); - $ret = Array(); - while($res = $result->fetchRow()) { - // Number of active instances - $ret[] = $res; - } - return $ret; - } - - function get_instance($iid) - { - $query = "select * from ".GALAXIA_TABLE_PREFIX."instances gi where wf_instance_id=$iid"; - $result = $this->query($query); - $res = $result->fetchRow(); - $res['wf_workitems']=$this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."workitems where wf_instance_id=$iid"); - return $res; - } - - function get_instance_properties($iid) - { - $prop = unserialize($this->getOne("select wf_properties from ".GALAXIA_TABLE_PREFIX."instances gi where wf_instance_id=$iid")); - return $prop; - } - - function set_instance_properties($iid,&$prop) - { - $props = addslashes(serialize($prop)); - $query = "update ".GALAXIA_TABLE_PREFIX."instances set wf_properties='$props' where wf_instance_id=$iid"; - $this->query($query); - } - - function set_instance_owner($iid,$owner) - { - $query = "update ".GALAXIA_TABLE_PREFIX."instances set wf_owner='$owner' where wf_instance_id=$iid"; - $this->query($query); - } - - function set_instance_status($iid,$status) - { - $query = "update ".GALAXIA_TABLE_PREFIX."instances set wf_status='$status' where wf_instance_id=$iid"; - $this->query($query); - } - - function set_instance_destination($iid,$activityId) - { - $query = "delete from ".GALAXIA_TABLE_PREFIX."instance_activities where wf_instance_id=$iid"; - $this->query($query); - $query = "insert into ".GALAXIA_TABLE_PREFIX."instance_activities(wf_instance_id,wf_activity_id,wf_user,wf_status) - values($iid,$activityId,'*','running')"; - $this->query($query); - } - - function set_instance_user($iid,$activityId,$user) - { - $query = "update ".GALAXIA_TABLE_PREFIX."instance_activities set wf_user='$user', wf_status='running' where wf_instance_id=$iid and wf_activity_id=$activityId"; - $this->query($query); - } - -} - -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/ProcessManager/ProcessManager.php b/phpgwapi/inc/galaxia_workflow/src/ProcessManager/ProcessManager.php deleted file mode 100644 index bdfdf30d07..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/ProcessManager/ProcessManager.php +++ /dev/null @@ -1,727 +0,0 @@ -db = $db; - } - - /*! - Sets a process as active - */ - function activate_process($pId) - { - $query = "update ".GALAXIA_TABLE_PREFIX."processes set wf_is_active='y' where wf_p_id=$pId"; - $this->query($query); - $msg = sprintf(tra('Process %d has been activated'),$pId); - $this->notify_all(3,$msg); - } - - /*! - De-activates a process - */ - function deactivate_process($pId) - { - $query = "update ".GALAXIA_TABLE_PREFIX."processes set wf_is_active='n' where wf_p_id=$pId"; - $this->query($query); - $msg = sprintf(tra('Process %d has been deactivated'),$pId); - $this->notify_all(3,$msg); - } - - /*! - Creates an XML representation of a process. - */ - function serialize_process($pId) - { - // - $out = ''."\n"; - $proc_info = $this->get_process($pId); - $wf_procname = $proc_info['wf_normalized_name']; - $out.= ' '.htmlspecialchars($proc_info['wf_name']).''."\n"; - $out.= ' '.htmlspecialchars($proc_info['wf_is_valid']).''."\n"; - $out.= ' '.htmlspecialchars($proc_info['wf_version']).''."\n"; - $out.= ' '.htmlspecialchars($proc_info['wf_is_active']).''."\n"; - $out.=' '.htmlspecialchars($proc_info['wf_description']).''."\n"; - $out.= ' '.date("d/m/Y [h:i:s]",$proc_info['wf_last_modif']).''."\n"; - $out.= ' '."\n"; - // Now loop over activities - $query = "select * from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$pId"; - $result = $this->query($query); - $out.=' '."\n"; - $am = new ActivityManager($this->db); - while($res = $result->fetchRow()) { - $name = $res['wf_normalized_name']; - $out.=' '."\n"; - $out.=' '.htmlspecialchars($res['wf_name']).''."\n"; - $out.=' '.htmlspecialchars($res['wf_type']).''."\n"; - $out.=' '.htmlspecialchars($res['wf_description']).''."\n"; - $out.=' '.date("d/m/Y [h:i:s]",$res['wf_last_modif']).''."\n"; - $out.=' '.$res['wf_is_interactive'].''."\n"; - $out.=' '.$res['wf_is_autorouted'].''."\n"; - $out.=' '."\n"; - - $roles = $am->get_activity_roles($res['wf_activity_id']); - foreach($roles as $role) { - $out.=' '.htmlspecialchars($role['wf_name']).''."\n"; - } - $out.=' '."\n"; - $out.=' '; - if($res['wf_is_interactive']=='y') { - $out.=' '; - } - $out.=' '."\n"; - } - $out.=' '."\n"; - $out.=' '."\n"; - $transitions = $am->get_process_transitions($pId); - foreach($transitions as $tran) { - $out.=' '."\n"; - $out.=' '.htmlspecialchars($tran['wf_act_from_name']).''."\n"; - $out.=' '.htmlspecialchars($tran['wf_act_to_name']).''."\n"; - $out.=' '."\n"; - } - $out.=' '."\n"; - $out.= ''."\n"; - //$fp = fopen(GALAXIA_PROCESSES."/$wf_procname/$wf_procname.xml","w"); - //fwrite($fp,$out); - //fclose($fp); - return $out; - } - - /*! - Creates a process PHP data structure from its XML - representation - */ - function unserialize_process($xml) - { - // Create SAX parser assign this object as base for handlers - // handlers are private methods defined below. - // keep contexts and parse - $this->parser = xml_parser_create(); - xml_parser_set_option($this->parser,XML_OPTION_CASE_FOLDING,0); - xml_set_object($this->parser, $this); - xml_set_element_handler($this->parser, "_start_element_handler", "_end_element_handler"); - xml_set_character_data_handler($this->parser, "_data_handler"); - $aux=Array( - 'name'=>'root', - 'children'=>Array(), - 'parent' => 0, - 'data'=>'' - ); - $this->tree[0]=$aux; - $this->current=0; - if (!xml_parse($this->parser, $xml, true)) { - $error = sprintf("XML error: %s at line %d", - xml_error_string(xml_get_error_code($this->parser)), - xml_get_current_line_number($this->parser)); - trigger_error($error,E_USER_WARNING); - } - xml_parser_free($this->parser); - // Now that we have the tree we can do interesting things - //print_r($this->tree); - $process=Array(); - $activities=Array(); - $transitions=Array(); - for($i=0;$itree[1]['children']);$i++) { - // Process attributes - $z=$this->tree[1]['children'][$i]; - $name = trim($this->tree[$z]['name']); - if($name=='activities') { - for($j=0;$jtree[$z]['children']);$j++) { - $z2 = $this->tree[$z]['children'][$j]; - // this is an activity $name = $this->tree[$z2]['name']; - if($this->tree[$z2]['name']=='activity') { - for($k=0;$ktree[$z2]['children']);$k++) { - $z3 = $this->tree[$z2]['children'][$k]; - $name = trim($this->tree[$z3]['name']); - $value= trim($this->tree[$z3]['data']); - if($name=='roles') { - $roles=Array(); - for($l=0;$ltree[$z3]['children']);$l++) { - $z4 = $this->tree[$z3]['children'][$l]; - $name = trim($this->tree[$z4]['name']); - $data = trim($this->tree[$z4]['data']); - $roles[]=$data; - } - } else { - $aux[$name]=$value; - //print("$name:$value
"); - } - } - $aux['roles']=$roles; - $activities[]=$aux; - } - } - } elseif($name=='transitions') { - for($j=0;$jtree[$z]['children']);$j++) { - $z2 = $this->tree[$z]['children'][$j]; - // this is an activity $name = $this->tree[$z2]['name']; - if($this->tree[$z2]['name']=='transition') { - for($k=0;$ktree[$z2]['children']);$k++) { - $z3 = $this->tree[$z2]['children'][$k]; - $name = trim($this->tree[$z3]['name']); - $value= trim($this->tree[$z3]['data']); - if($name == 'from' || $name == 'to') { - $aux[$name]=$value; - } - } - } - $transitions[] = $aux; - } - } else { - $value = trim($this->tree[$z]['data']); - //print("$name is $value
"); - $process[$name]=$value; - } - } - $process['activities']=$activities; - $process['transitions']=$transitions; - return $process; - } - - /*! - Creates a process from the process data structure, if you want to - convert an XML to a process then use first unserialize_process - and then this method. - */ - function import_process($data) - { - //Now the show begins - $am = new ActivityManager($this->db); - $rm = new RoleManager($this->db); - // First create the process - $vars = Array( - 'name' => $data['name'], - 'version' => $data['version'], - 'description' => $data['description'], - 'lastModif' => $data['lastModif'], - 'isActive' => $data['isActive'], - 'isValid' => $data['isValid'] - ); - $pid = $this->replace_process(0,$vars,false); - //Put the shared code - $proc_info = $this->get_process($pid); - $wf_procname = $proc_info['wf_normalized_name']; - $fp = fopen(GALAXIA_PROCESSES.SEP."$wf_procname".SEP."code".SEP."shared.php","w"); - fwrite($fp,$data['sharedCode']); - fclose($fp); - $actids = Array(); - // Foreach activity create activities - foreach($data['activities'] as $activity) { - $vars = Array( - 'name' => $activity['wf_name'], - 'description' => $activity['wf_description'], - 'type' => $activity['wf_type'], - 'lastModif' => $activity['wf_lastModif'], - 'isInteractive' => $activity['wf_is_interactive'], - 'isAutoRouted' => $activity['wf_is_autorouted'] - ); - $actname=$am->_normalize_name($activity['wf_name']); - - $actid = $am->replace_activity($pid,0,$vars); - $fp = fopen(GALAXIA_PROCESSES.SEP."$wf_procname".SEP."code".SEP."activities".SEP."$actname".'.php',"w"); - fwrite($fp,$activity['code']); - fclose($fp); - if($activity['isInteractive']=='y') { - $fp = fopen(GALAXIA_PROCESSES.SEP."$wf_procname".SEP."code".SEP."templates".SEP."$actname".'.tpl',"w"); - fwrite($fp,$activity['template']); - fclose($fp); - } - $actids[$activity['name']] = $am->_get_activity_id_by_name($pid,$activity['wf_name']); - $actname = $am->_normalize_name($activity['wf_name']); - $now = date("U"); - - foreach($activity['wf_roles'] as $role) { - $vars = Array( - 'name' => $role, - 'description' => $role, - 'lastModif' => $now, - ); - if(!$rm->role_name_exists($pid,$role)) { - $rid=$rm->replace_role($pid,0,$vars); - } else { - $rid = $rm->get_role_id($pid,$role); - } - if($actid && $rid) { - $am->add_activity_role($actid,$rid); - } - } - } - foreach($data['transitions'] as $tran) { - $am->add_transition($pid,$actids[$tran['from']],$actids[$tran['to']]); - } - // FIXME: recompile activities seems to be needed here - foreach ($actids as $name => $actid) { - $am->compile_activity($pid,$actid); - } - // create a graph for the new process - $am->build_process_graph($pid); - unset($am); - unset($rm); - $msg = sprintf(tra('Process %s %s imported'),$proc_info['wf_name'],$proc_info['wf_version']); - $this->notify_all(2,$msg); - } - - /*! - Creates a new process based on an existing process - changing the process version. By default the process - is created as an unactive process and the version is - by default a minor version of the process. - */ - ///\todo copy process activities and so - function new_process_version($pId, $minor=true) - { - $oldpid = $pId; - $proc_info = $this->get_process($pId); - $name = $proc_info['wf_name']; - if(!$proc_info) return false; - - // Now update the version - $version = $this->_new_version($proc_info['wf_version'],$minor); - while($this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."processes where wf_name='$name' and wf_version='$version'")) { - $version = $this->_new_version($version,$minor); - } - // Make new versions unactive - $proc_info['wf_version'] = $version; - $proc_info['wf_is_active'] = 'n'; - // create a new process, but don't create start/end activities - $pid = $this->replace_process(0, $proc_info, false); - - //Since we are copying a process we should copy - //the old directory structure to the new directory - $oldname = $proc_info['wf_normalized_name']; - $newname = $this->_get_normalized_name($pid); - $this->_rec_copy(GALAXIA_PROCESSES.SEP."$oldname".SEP.'code',GALAXIA_PROCESSES.SEP."$newname".SEP.'code'); - - // And here copy all the activities & so - $am = new ActivityManager($this->db); - $query = "select * from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$oldpid"; - $result = $this->query($query); - $newaid = array(); - while($res = $result->fetchRow()) { - $oldaid = $res['wf_activity_id']; - $newaid[$oldaid] = $am->replace_activity($pid,0,$res, false); - } - // create transitions - $query = "select * from ".GALAXIA_TABLE_PREFIX."transitions where wf_p_id=$oldpid"; - $result = $this->query($query); - - while($res = $result->fetchRow()) { - if (empty($newaid[$res['wf_act_from_id']]) || empty($newaid[$res['wf_act_to_id']])) { - continue; - } - $am->add_transition($pid,$newaid[$res['wf_act_from_id']],$newaid[$res['wf_act_to_id']]); - } - // create roles - $rm = new RoleManager($this->db); - $query = "select * from ".GALAXIA_TABLE_PREFIX."roles where wf_p_id=$oldpid"; - $result = $this->query($query); - $newrid = array(); - while($res = $result->fetchRow()) { - if(!$rm->role_name_exists($pid,$res['wf_name'])) { - $rid=$rm->replace_role($pid,0,$res); - } else { - $rid = $rm->get_role_id($pid,$res['wf_name']); - } - $newrid[$res['wf_role_id']] = $rid; - } - // map users to roles - if (count($newrid) > 0) { - $query = "select * from ".GALAXIA_TABLE_PREFIX."user_roles where wf_p_id=$oldpid"; - $result = $this->query($query); - while($res = $result->fetchRow()) { - if (empty($newrid[$res['wf_role_id']])) { - continue; - } - $rm->map_user_to_role($pid,$res['wf_user'],$newrid[$res['wf_role_id']]); - } - } - // add roles to activities - if (count($newaid) > 0 && count($newrid ) > 0) { - $query = "select * from ".GALAXIA_TABLE_PREFIX."activity_roles where wf_activity_id in (" . join(', ',array_keys($newaid)) . ")"; - $result = $this->query($query); - while($res = $result->fetchRow()) { - if (empty($newaid[$res['wf_activity_id']]) || empty($newrid[$res['wf_role_id']])) { - continue; - } - $am->add_activity_role($newaid[$res['wf_activity_id']],$newrid[$res['wf_role_id']]); - } - } - - // create a graph for the new process - $am->build_process_graph($pid); - return $pid; - } - - /*! - This function can be used to check if a process name exists, note that - this is NOT used by replace_process since that function can be used to - create new versions of an existing process. The application must use this - method to ensure that processes have unique names. - */ - function process_name_exists($name,$version) - { - $name = addslashes($this->_normalize_name($name,$version)); - return $this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."processes where wf_normalized_name='$name'"); - } - - - /*! - Gets a process by pId. Fields are returned as an asociative array - */ - function get_process($pId) - { - $query = "select * from ".GALAXIA_TABLE_PREFIX."processes where wf_p_id=$pId"; - $result = $this->query($query); - if(!$result->numRows()) return false; - $res = $result->fetchRow(); - return $res; - } - - /*! - Lists processes (all processes) - */ - function list_processes($offset,$maxRecords,$sort_mode,$find,$where='') - { - $sort_mode = $this->convert_sortmode($sort_mode); - if($find) { - $findesc = '%'.$find.'%'; - $mid=" where ((wf_name like ?) or (wf_description like ?))"; - $bindvars = array($findesc,$findesc); - } else { - $mid=""; - $bindvars = array(); - } - if($where) { - if($mid) { - $mid.= " and ($where) "; - } else { - $mid.= " where ($where) "; - } - } - $query = "select * from ".GALAXIA_TABLE_PREFIX."processes $mid order by $sort_mode"; - $query_cant = "select count(*) from ".GALAXIA_TABLE_PREFIX."processes $mid"; - $result = $this->query($query,$bindvars,$maxRecords,$offset); - $cant = $this->getOne($query_cant,$bindvars); - $ret = Array(); - while($res = $result->fetchRow()) { - $ret[] = $res; - } - $retval = Array(); - $retval["data"] = $ret; - $retval["cant"] = $cant; - return $retval; - } - - /*! - Marks a process as an invalid process - */ - function invalidate_process($pid) - { - $query = "update ".GALAXIA_TABLE_PREFIX."processes set wf_is_valid='n' where wf_p_id=$pid"; - $this->query($query); - } - - /*! - Removes a process by pId - */ - function remove_process($pId) - { - $this->deactivate_process($pId); - $name = $this->_get_normalized_name($pId); - $aM = new ActivityManager($this->db); - // Remove process activities - $query = "select wf_activity_id from ".GALAXIA_TABLE_PREFIX."activities where wf_p_id=$pId"; - $result = $this->query($query); - while($res = $result->fetchRow()) { - $aM->remove_activity($pId,$res['wf_activity_id']); - } - - // Remove process roles - $query = "delete from ".GALAXIA_TABLE_PREFIX."roles where wf_p_id=$pId"; - $this->query($query); - $query = "delete from ".GALAXIA_TABLE_PREFIX."user_roles where wf_p_id=$pId"; - $this->query($query); - - // Remove process instances - $query = "delete from ".GALAXIA_TABLE_PREFIX."instances where wf_p_id=$pId"; - $this->query($query); - - // Remove the directory structure - if (!empty($name) && is_dir(GALAXIA_PROCESSES.SEP."$name")) { - $this->_remove_directory(GALAXIA_PROCESSES.SEP."$name",true); - } - if (GALAXIA_TEMPLATES && !empty($name) && is_dir(GALAXIA_TEMPLATES.SEP."$name")) { - $this->_remove_directory(GALAXIA_TEMPLATES.SEP."$name",true); - } - // And finally remove the proc - $query = "delete from ".GALAXIA_TABLE_PREFIX."processes where wf_p_id=$pId"; - $this->query($query); - $msg = sprintf(tra('Process %s removed'),$name); - $this->notify_all(5,$msg); - - return true; - } - - /*! - Updates or inserts a new process in the database, $vars is an asociative - array containing the fields to update or to insert as needed. - $pId is the processId - */ - function replace_process($pId, $vars, $create = true) - { - $TABLE_NAME = GALAXIA_TABLE_PREFIX."processes"; - $now = date("U"); - $vars['wf_last_modif']=$now; - $vars['wf_normalized_name'] = $this->_normalize_name($vars['wf_name'],$vars['wf_version']); - foreach($vars as $key=>$value) - { - $vars[$key]=addslashes($value); - } - - if($pId) { - // update mode - $old_proc = $this->get_process($pId); - $first = true; - $query ="update $TABLE_NAME set"; - foreach($vars as $key=>$value) { - if(!$first) $query.= ','; - if(!is_numeric($value)||strstr($value,'.')) $value="'".$value."'"; - $query.= " $key=$value "; - $first = false; - } - $query .= " where wf_p_id=$pId "; - $this->query($query); - // Note that if the name is being changed then - // the directory has to be renamed! - $oldname = $old_proc['wf_normalized_name']; - $newname = $vars['wf_normalized_name']; - if ($newname != $oldname) { - rename(GALAXIA_PROCESSES.SEP."$oldname",GALAXIA_PROCESSES.SEP."$newname"); - } - $msg = sprintf(tra('Process %s has been updated'),$vars['wf_name']); - $this->notify_all(3,$msg); - } else { - unset($vars['wf_p_id']); - // insert mode - $name = $this->_normalize_name($vars['wf_name'],$vars['wf_version']); - $this->_create_directory_structure($name); - $first = true; - $query = "insert into $TABLE_NAME("; - foreach(array_keys($vars) as $key) { - if(!$first) $query.= ','; - $query.= "$key"; - $first = false; - } - $query .=") values("; - $first = true; - foreach(array_values($vars) as $value) { - if(!$first) $query.= ','; - if(!is_numeric($value)||strstr($value,'.')) $value="'".$value."'"; - $query.= "$value"; - $first = false; - } - $query .=")"; - $this->query($query); - $pId = $this->getOne("select max(wf_p_id) from $TABLE_NAME where wf_last_modif=$now"); - // Now automatically add a start and end activity - // unless importing ($create = false) - if($create) { - $aM= new ActivityManager($this->db); - $vars1 = Array( - 'wf_name' => 'start', - 'wf_description' => 'default start activity', - 'wf_type' => 'start', - 'wf_is_interactive' => 'y', - 'wf_is_autorouted' => 'y' - ); - $vars2 = Array( - 'wf_name' => 'end', - 'wf_description' => 'default end activity', - 'wf_type' => 'end', - 'wf_is_interactive' => 'n', - 'wf_is_autorouted' => 'y' - ); - - $aM->replace_activity($pId,0,$vars1); - $aM->replace_activity($pId,0,$vars2); - } - $msg = sprintf(tra('Process %s has been created'),$vars['wf_name']); - $this->notify_all(4,$msg); - } - // Get the id - return $pId; - } - - /*! - \private - Gets the normalized name of a process by pid - */ - function _get_normalized_name($pId) - { - $info = $this->get_process($pId); - return $info['wf_normalized_name']; - } - - /*! - \private - Normalizes a process name - */ - function _normalize_name($name, $version) - { - $name = $name.'_'.$version; - $name = str_replace(" ","_",$name); - $name = preg_replace("/[^0-9A-Za-z\_]/",'',$name); - return $name; - } - - /*! - \private - Generates a new minor version number - */ - function _new_version($version,$minor=true) - { - $parts = explode('.',$version); - if($minor) { - $parts[count($parts)-1]++; - } else { - $parts[0]++; - for ($i = 1; $i < count($parts); $i++) { - $parts[$i] = 0; - } - } - return implode('.',$parts); - } - - /*! - \private - Creates directory structure for process - */ - function _create_directory_structure($name) - { - // Create in processes a directory with this name - mkdir(GALAXIA_PROCESSES.SEP."$name",0770); - mkdir(GALAXIA_PROCESSES.SEP."$name".SEP."graph",0770); - mkdir(GALAXIA_PROCESSES.SEP."$name".SEP."code",0770); - mkdir(GALAXIA_PROCESSES.SEP."$name".SEP."compiled",0770); - mkdir(GALAXIA_PROCESSES.SEP."$name".SEP."code".SEP."activities",0770); - mkdir(GALAXIA_PROCESSES.SEP."$name".SEP."code".SEP."templates",0770); - if (GALAXIA_TEMPLATES) { - mkdir(GALAXIA_TEMPLATES.SEP."$name",0770); - } - // Create shared file - $fp = fopen(GALAXIA_PROCESSES.SEP."$name".SEP."code".SEP."shared.php","w"); - fwrite($fp,'<'.'?'.'php'."\n".'?'.'>'); - fclose($fp); - } - - /*! - \private - Removes a directory recursively - */ - function _remove_directory($dir,$rec=false) - { - // Prevent a disaster - if(trim($dir) == SEP || trim($dir)=='.' || trim($dir)=='templates' || trim($dir)=='templates'.SEP) return false; - $h = opendir($dir); - while(($file = readdir($h)) != false) { - if(is_file($dir.SEP.$file)) { - @unlink($dir.SEP.$file); - } else { - if($rec && $file != '.' && $file != '..') { - $this->_remove_directory($dir.SEP.$file, true); - } - } - } - closedir($h); - @rmdir($dir); - @unlink($dir); - } - - function _rec_copy($dir1,$dir2) - { - @mkdir($dir2,0777); - $h = opendir($dir1); - while(($file = readdir($h)) !== false) { - if(is_file($dir1.SEP.$file)) { - copy($dir1.SEP.$file,$dir2.SEP.$file); - } else { - if($file != '.' && $file != '..') { - $this->_rec_copy($dir1.SEP.$file, $dir2.SEP.$file); - } - } - } - closedir($h); - } - - function _start_element_handler($parser,$element,$attribs) - { - $aux=Array('name'=>$element, - 'data'=>'', - 'parent' => $this->current, - 'children'=>Array()); - $i = count($this->tree); - $this->tree[$i] = $aux; - - $this->tree[$this->current]['children'][]=$i; - $this->current=$i; - } - - - function _end_element_handler($parser,$element) - { - //when a tag ends put text - $this->tree[$this->current]['data']=$this->buffer; - $this->buffer=''; - $this->current=$this->tree[$this->current]['parent']; - } - - - function _data_handler($parser,$data) - { - $this->buffer.=$data; - } - -} - - -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/ProcessManager/RoleManager.php b/phpgwapi/inc/galaxia_workflow/src/ProcessManager/RoleManager.php deleted file mode 100644 index 231c06fe87..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/ProcessManager/RoleManager.php +++ /dev/null @@ -1,213 +0,0 @@ -db = $db; - } - - function get_role_id($pid,$name) - { - $name = addslashes($name); - return ($this->getOne("select wf_role_id from ".GALAXIA_TABLE_PREFIX."roles where wf_name='$name' and wf_p_id=$pid")); - } - - /*! - Gets a role fields are returned as an asociative array - */ - function get_role($pId, $roleId) - { - $query = "select * from `".GALAXIA_TABLE_PREFIX."roles` where `wf_p_id`=? and `wf_role_id`=?"; - $result = $this->query($query,array($pId, $roleId)); - $res = $result->fetchRow(); - return $res; - } - - /*! - Indicates if a role exists - */ - function role_name_exists($pid,$name) - { - $name = addslashes($name); - return ($this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."roles where wf_p_id=$pid and wf_name='$name'")); - } - - /*! - Maps a user to a role - */ - function map_user_to_role($pId,$user,$roleId) - { - $query = "delete from `".GALAXIA_TABLE_PREFIX."user_roles` where `wf_role_id`=? and `wf_user`=?"; - $this->query($query,array($roleId, $user)); - $query = "insert into `".GALAXIA_TABLE_PREFIX."user_roles`(`wf_p_id`, `wf_user`, `wf_role_id`) values(?,?,?)"; - $this->query($query,array($pId,$user,$roleId)); - } - - /*! - Removes a mapping - */ - function remove_mapping($user,$roleId) - { - $query = "delete from `".GALAXIA_TABLE_PREFIX."user_roles` where `wf_user`=? and `wf_role_id`=?"; - $this->query($query,array($user, $roleId)); - } - - /*! - List mappings - */ - function list_mappings($pId,$offset,$maxRecords,$sort_mode,$find) { - $sort_mode = $this->convert_sortmode($sort_mode); - if($find) { - // no more quoting here - this is done in bind vars already - $findesc = '%'.$find.'%'; - $query = "select `wf_name`,`gr`.`wf_role_id`,`wf_user` from `".GALAXIA_TABLE_PREFIX."roles` gr, `".GALAXIA_TABLE_PREFIX."user_roles` gur where `gr`.`wf_role_id`=`gur`.`wf_role_id` and `gur`.`wf_p_id`=? and ((`wf_name` like ?) or (`wf_user` like ?) or (`wf_description` like ?)) order by $sort_mode"; - $result = $this->query($query,array($pId,$findesc,$findesc,$findesc), $maxRecords, $offset); - $query_cant = "select count(*) from `".GALAXIA_TABLE_PREFIX."roles` gr, `".GALAXIA_TABLE_PREFIX."user_roles` gur where `gr`.`wf_role_id`=`gur`.`wf_role_id` and `gur`.`wf_p_id`=? and ((`wf_name` like ?) or (`wf_user` like ?) or (`wf_description` like ?))"; - $cant = $this->getOne($query_cant,array($pId,$findesc,$findesc,$findesc)); - } else { - $query = "select `wf_name`,`gr`.`wf_role_id`,`wf_user` from `".GALAXIA_TABLE_PREFIX."roles` gr, `".GALAXIA_TABLE_PREFIX."user_roles` gur where `gr`.`wf_role_id`=`gur`.`wf_role_id` and `gur`.`wf_p_id`=? order by $sort_mode"; - $result = $this->query($query,array($pId), $maxRecords, $offset); - $query_cant = "select count(*) from `".GALAXIA_TABLE_PREFIX."roles` gr, `".GALAXIA_TABLE_PREFIX."user_roles` gur where `gr`.`wf_role_id`=`gur`.`wf_role_id` and `gur`.`wf_p_id`=?"; - $cant = $this->getOne($query_cant,array($pId)); - } - $ret = Array(); - while($res = $result->fetchRow()) { - $ret[] = $res; - } - $retval = Array(); - $retval["data"] = $ret; - $retval["cant"] = $cant; - return $retval; - } - - /*! - Lists roles at a per-process level - */ - function list_roles($pId,$offset,$maxRecords,$sort_mode,$find,$where='') - { - $sort_mode = $this->convert_sortmode($sort_mode); - if($find) { - // no more quoting here - this is done in bind vars already - $findesc = '%'.$find.'%'; - $mid=" where wf_p_id=? and ((wf_name like ?) or (wf_description like ?))"; - $bindvars = array($pId,$findesc,$findesc); - } else { - $mid=" where wf_p_id=? "; - $bindvars = array($pId); - } - if($where) { - $mid.= " and ($where) "; - } - $query = "select * from ".GALAXIA_TABLE_PREFIX."roles $mid order by $sort_mode"; - $query_cant = "select count(*) from ".GALAXIA_TABLE_PREFIX."roles $mid"; - $result = $this->query($query,$bindvars,$maxRecords,$offset); - $cant = $this->getOne($query_cant,$bindvars); - $ret = Array(); - while($res = $result->fetchRow()) { - $ret[] = $res; - } - $retval = Array(); - $retval["data"] = $ret; - $retval["cant"] = $cant; - return $retval; - } - - - - /*! - Removes a role. - */ - function remove_role($pId, $roleId) - { - $query = "delete from `".GALAXIA_TABLE_PREFIX."roles` where `wf_p_id`=? and `wf_role_id`=?"; - $this->query($query,array($pId, $roleId)); - $query = "delete from `".GALAXIA_TABLE_PREFIX."activity_roles` where `wf_role_id`=?"; - $this->query($query,array($roleId)); - $query = "delete from `".GALAXIA_TABLE_PREFIX."user_roles` where `wf_role_id`=?"; - $this->query($query,array($roleId)); - } - - /*! - Updates or inserts a new role in the database, $vars is an asociative - array containing the fields to update or to insert as needed. - $pId is the processId - $roleId is the roleId - */ - function replace_role($pId, $roleId, $vars) - { - $TABLE_NAME = GALAXIA_TABLE_PREFIX."roles"; - $now = date("U"); - $vars['wf_last_modif']=$now; - $vars['wf_p_id']=$pId; - - foreach($vars as $key=>$value) - { - $vars[$key]=addslashes($value); - } - - if($roleId) { - // update mode - $first = true; - $query ="update $TABLE_NAME set"; - foreach($vars as $key=>$value) { - if(!$first) $query.= ','; - if(!is_numeric($value)) $value="'".$value."'"; - $query.= " $key=$value "; - $first = false; - } - $query .= " where wf_p_id=$pId and wf_role_id=$roleId "; - $this->query($query); - } else { - $name = $vars['wf_name']; - if ($this->getOne("select count(*) from ".GALAXIA_TABLE_PREFIX."roles where wf_p_id=$pId and wf_name='$name'")) { - return false; - } - unset($vars['wf_role_id']); - // insert mode - $first = true; - $query = "insert into $TABLE_NAME("; - foreach(array_keys($vars) as $key) { - if(!$first) $query.= ','; - $query.= "$key"; - $first = false; - } - $query .=") values("; - $first = true; - foreach(array_values($vars) as $value) { - if(!$first) $query.= ','; - if(!is_numeric($value)) $value="'".$value."'"; - $query.= "$value"; - $first = false; - } - $query .=")"; - $this->query($query); - $roleId = $this->getOne("select max(wf_role_id) from $TABLE_NAME where wf_p_id=$pId and wf_last_modif=$now"); - } - // Get the id - return $roleId; - } -} - -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/ProcessMonitor/ProcessMonitor.php b/phpgwapi/inc/galaxia_workflow/src/ProcessMonitor/ProcessMonitor.php deleted file mode 100644 index 856c809754..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/ProcessMonitor/ProcessMonitor.php +++ /dev/null @@ -1,390 +0,0 @@ -getOne("select count(*) from `".GALAXIA_TABLE_PREFIX."processes` where `wf_is_active`=?",array('y')); - $res['processes'] = $this->getOne("select count(*) from `".GALAXIA_TABLE_PREFIX."processes`"); - $result = $this->query("select distinct(`wf_p_id`) from `".GALAXIA_TABLE_PREFIX."instances` where `wf_status`=?",array('active')); - $res['running_processes'] = $result->numRows(); - // get the number of instances per status - $query = "select wf_status, count(*) as num_instances from ".GALAXIA_TABLE_PREFIX."instances group by wf_status"; - $result = $this->query($query); - $status = array(); - while($info = $result->fetchRow()) { - $status[$info['wf_status']] = $info['wf_num_instances']; - } - $res['active_instances'] = isset($status['active']) ? $status['active'] : 0; - $res['completed_instances'] = isset($status['completed']) ? $status['completed'] : 0; - $res['exception_instances'] = isset($status['exception']) ? $status['exception'] : 0; - $res['aborted_instances'] = isset($status['aborted']) ? $status['aborted'] : 0; - return $res; - } - - function update_instance_status($iid,$status) { - $query = "update `".GALAXIA_TABLE_PREFIX."instances` set `wf_status`=? where `wf_instance_id`=?"; - $this->query($query,array($status,$iid)); - } - - function update_instance_activity_status($iid,$activityId,$status) { - $query = "update `".GALAXIA_TABLE_PREFIX."instance_activities` set `wf_status`=? where `wf_instance_id`=? and `wf_activity_id`=?"; - $this->query($query,array($status,$iid,$activityId)); - } - - function remove_instance($iid) { - $query = "delete from `".GALAXIA_TABLE_PREFIX."workitems` where `wf_instance_id`=?"; - $this->query($query,array($iid)); - $query = "delete from `".GALAXIA_TABLE_PREFIX."instance_activities` where `wf_instance_id`=?"; - $this->query($query,array($iid)); - $query = "delete from `".GALAXIA_TABLE_PREFIX."instances` where `wf_instance_id`=?"; - $this->query($query,array($iid)); - } - - function remove_aborted() { - $query="select `wf_instance_id` from `".GALAXIA_TABLE_PREFIX."instances` where `wf_status`=?"; - $result = $this->query($query,array('aborted')); - while($res = $result->fetchRow()) { - $iid = $res['wf_instance_id']; - $query = "delete from `".GALAXIA_TABLE_PREFIX."instance_activities` where `wf_instance_id`=?"; - $this->query($query,array($iid)); - $query = "delete from `".GALAXIA_TABLE_PREFIX."workitems` where `wf_instance_id`=?"; - $this->query($query,array($iid)); - } - $query = "delete from `".GALAXIA_TABLE_PREFIX."instances` where `wf_status`=?"; - $this->query($query,array('aborted')); - } - - function remove_all($pId) { - $query="select `wf_instance_id` from `".GALAXIA_TABLE_PREFIX."instances` where `wf_p_id`=?"; - $result = $this->query($query,array($pId)); - while($res = $result->fetchRow()) { - $iid = $res['wf_instance_id']; - $query = "delete from `".GALAXIA_TABLE_PREFIX."instance_activities` where `wf_instance_id`=?"; - $this->query($query,array($iid)); - $query = "delete from `".GALAXIA_TABLE_PREFIX."workitems` where `wf_instance_id`=?"; - $this->query($query,array($iid)); - } - $query = "delete from `".GALAXIA_TABLE_PREFIX."instances` where `wf_p_id`=?"; - $this->query($query,array($pId)); - } - - - function monitor_list_processes($offset,$maxRecords,$sort_mode,$find,$where='') { - $sort_mode = $this->convert_sortmode($sort_mode); - if($find) { - $findesc = '%'.$find.'%'; - $mid=" where ((wf_name like ?) or (wf_description like ?))"; - $bindvars = array($findesc,$findesc); - } else { - $mid=""; - $bindvars = array(); - } - if($where) { - if($mid) { - $mid.= " and ($where) "; - } else { - $mid.= " where ($where) "; - } - } - // get the requested processes - $query = "select * from ".GALAXIA_TABLE_PREFIX."processes $mid order by $sort_mode"; - $query_cant = "select count(*) from ".GALAXIA_TABLE_PREFIX."processes $mid"; - $result = $this->query($query,$bindvars,$maxRecords,$offset); - $cant = $this->getOne($query_cant,$bindvars); - $ret = Array(); - while($res = $result->fetchRow()) { - $pId = $res['wf_p_id']; - // Number of active instances - $res['active_instances'] = 0; - // Number of exception instances - $res['exception_instances'] = 0; - // Number of completed instances - $res['completed_instances'] = 0; - // Number of aborted instances - $res['aborted_instances'] = 0; - $res['all_instances'] = 0; - // Number of activities - $res['activities'] = 0; - $ret[$pId] = $res; - } - if (count($ret) < 1) { - $retval = Array(); - $retval["data"] = $ret; - $retval["cant"] = $cant; - return $retval; - } - // get number of instances and timing statistics per process and status - $query = "select wf_p_id, wf_status, count(*) as num_instances, - min(wf_ended - wf_started) as min_time, avg(wf_ended - wf_started) as avg_time, max(wf_ended - wf_started) as max_time - from ".GALAXIA_TABLE_PREFIX."instances where wf_p_id in (" . join(', ', array_keys($ret)) . ") group by wf_p_id, wf_status"; - $result = $this->query($query); - while($res = $result->fetchRow()) { - $pId = $res['wf_p_id']; - if (!isset($ret[$pId])) continue; - switch ($res['wf_status']) { - case 'active': - $ret[$pId]['active_instances'] = $res['num_instances']; - $ret[$pId]['all_instances'] += $res['num_instances']; - break; - case 'completed': - $ret[$pId]['completed_instances'] = $res['num_instances']; - $ret[$pId]['all_instances'] += $res['num_instances']; - $ret[$pId]['duration'] = array('min' => $res['min_time'], 'avg' => $res['avg_time'], 'max' => $res['max_time']); - break; - case 'exception': - $ret[$pId]['exception_instances'] = $res['num_instances']; - $ret[$pId]['all_instances'] += $res['num_instances']; - break; - case 'aborted': - $ret[$pId]['aborted_instances'] = $res['num_instances']; - $ret[$pId]['all_instances'] += $res['num_instances']; - break; - } - } - // get number of activities per process - $query = "select wf_p_id, count(*) as num_activities - from ".GALAXIA_TABLE_PREFIX."activities - where wf_p_id in (" . join(', ', array_keys($ret)) . ") - group by wf_p_id"; - $result = $this->query($query); - while($res = $result->fetchRow()) { - $pId = $res['wf_p_id']; - if (!isset($ret[$pId])) continue; - $ret[$pId]['wf_activities'] = $res['num_activities']; - } - $retval = Array(); - $retval["data"] = $ret; - $retval["cant"] = $cant; - return $retval; - } - - function monitor_list_activities($offset,$maxRecords,$sort_mode,$find,$where='') { - $sort_mode = $this->convert_sortmode($sort_mode); - if($find) { - $findesc = '%'.$find.'%'; - $mid=" where ((ga.wf_name like ?) or (ga.wf_description like ?))"; - $bindvars = array($findesc,$findesc); - } else { - $mid=""; - $bindvars = array(); - } - if($where) { - $where = preg_replace('/pId/', 'ga.wf_p_id', $where); - if($mid) { - $mid.= " and ($where) "; - } else { - $mid.= " where ($where) "; - } - } - $query = "select gp.`wf_name` as `wf_procname`, gp.`wf_version`, ga.* - from ".GALAXIA_TABLE_PREFIX."activities ga - left join ".GALAXIA_TABLE_PREFIX."processes gp on gp.wf_p_id=ga.wf_p_id - $mid order by $sort_mode"; - $query_cant = "select count(*) from ".GALAXIA_TABLE_PREFIX."activities ga $mid"; - $result = $this->query($query,$bindvars,$maxRecords,$offset); - $cant = $this->getOne($query_cant,$bindvars); - $ret = Array(); - while($res = $result->fetchRow()) { - // Number of active instances - $aid = $res['wf_activity_id']; - $res['active_instances']=$this->getOne("select count(gi.wf_instance_id) from ".GALAXIA_TABLE_PREFIX."instances gi,".GALAXIA_TABLE_PREFIX."instance_activities gia where gi.wf_instance_id=gia.wf_instance_id and gia.wf_activity_id=$aid and gi.wf_status='active' and wf_p_id=".$res['wf_p_id']); - // activities of completed instances are all removed from the instance_activities table for some reason, so we need to look at workitems - $res['completed_instances']=$this->getOne("select count(distinct gi.wf_instance_id) from ".GALAXIA_TABLE_PREFIX."instances gi,".GALAXIA_TABLE_PREFIX."workitems gw where gi.wf_instance_id=gw.wf_instance_id and gw.wf_activity_id=$aid and gi.wf_status='completed' and wf_p_id=".$res['wf_p_id']); - // activities of aborted instances are all removed from the instance_activities table for some reason, so we need to look at workitems - $res['aborted_instances']=$this->getOne("select count(distinct gi.wf_instance_id) from ".GALAXIA_TABLE_PREFIX."instances gi,".GALAXIA_TABLE_PREFIX."workitems gw where gi.wf_instance_id=gw.wf_instance_id and gw.wf_activity_id=$aid and gi.wf_status='aborted' and wf_p_id=".$res['wf_p_id']); - $res['exception_instances']=$this->getOne("select count(gi.wf_instance_id) from ".GALAXIA_TABLE_PREFIX."instances gi,".GALAXIA_TABLE_PREFIX."instance_activities gia where gi.wf_instance_id=gia.wf_instance_id and gia.wf_activity_id=$aid and gi.wf_status='exception' and wf_p_id=".$res['wf_p_id']); - $res['act_running_instances']=$this->getOne("select count(gi.wf_instance_id) from ".GALAXIA_TABLE_PREFIX."instances gi,".GALAXIA_TABLE_PREFIX."instance_activities gia where gi.wf_instance_id=gia.wf_instance_id and gia.wf_activity_id=$aid and gia.wf_status='running' and wf_p_id=".$res['wf_p_id']); - // completed activities are removed from the instance_activities table unless they're part of a split for some reason, so this won't work - // $res['act_completed_instances']=$this->getOne("select count(gi.wf_instance_id) from ".GALAXIA_TABLE_PREFIX."instances gi,".GALAXIA_TABLE_PREFIX."instance_activities gia where gi.wf_instance_id=gia.wf_instance_id and gia.activityId=$aid and gia.status='completed' and pId=".$res['pId']); - $res['act_completed_instances'] = 0; - $ret[$aid] = $res; - } - if (count($ret) < 1) { - $retval = Array(); - $retval["data"] = $ret; - $retval["cant"] = $cant; - return $retval; - } - $query = "select wf_activity_id, count(distinct wf_instance_id) as num_instances, min(wf_ended - wf_started) as min_time, avg(wf_ended - wf_started) as avg_time, max(wf_ended - wf_started) as max_time - from ".GALAXIA_TABLE_PREFIX."workitems - where wf_activity_id in (" . join(', ', array_keys($ret)) . ") - group by wf_activity_id"; - $result = $this->query($query); - while($res = $result->fetchRow()) { - // Number of active instances - $aid = $res['wf_activity_id']; - if (!isset($ret[$aid])) continue; - $ret[$aid]['act_completed_instances'] = $res['num_instances'] - $ret[$aid]['aborted_instances']; - $ret[$aid]['duration'] = array('min' => $res['min_time'], 'avg' => $res['avg_time'], 'max' => $res['max_time']); - } - $retval = Array(); - $retval["data"] = $ret; - $retval["cant"] = $cant; - return $retval; - } - - function monitor_list_instances($offset,$maxRecords,$sort_mode,$find,$where='',$wherevars='') { - if($find) { - $findesc = $this->qstr('%'.$find.'%'); - $mid=" where (`wf_properties` like $findesc)"; - } else { - $mid=""; - } - if($where) { - if($mid) { - $mid.= " and ($where) "; - } else { - $mid.= " where ($where) "; - } - } - - $query = "select gp.`wf_p_id`, ga.`wf_is_interactive`, gi.`wf_owner`, gp.`wf_name` as `wf_procname`, gp.`wf_version`, ga.`wf_type`,"; - $query.= " ga.`wf_activity_id`, ga.`wf_name`, gi.`wf_instance_id`, gi.`wf_status`, gia.`wf_activity_id`, gia.`wf_user`, gi.`wf_started`, gi.`wf_ended`, gia.`wf_status` as wf_act_status "; - $query.=" from `".GALAXIA_TABLE_PREFIX."instances` gi LEFT JOIN `".GALAXIA_TABLE_PREFIX."instance_activities` gia ON gi.`wf_instance_id`=gia.`wf_instance_id` "; - $query.= "LEFT JOIN `".GALAXIA_TABLE_PREFIX."activities` ga ON gia.`wf_activity_id` = ga.`wf_activity_id` "; - $query.= "LEFT JOIN `".GALAXIA_TABLE_PREFIX."processes` gp ON gp.`wf_p_id`=gi.`wf_p_id` $mid order by ".$this->convert_sortmode($sort_mode); - - $query_cant = "select count(*) from `".GALAXIA_TABLE_PREFIX."instances` gi LEFT JOIN `".GALAXIA_TABLE_PREFIX."instance_activities` gia ON gi.`wf_instance_id`=gia.`wf_instance_id` "; - $query_cant.= "LEFT JOIN `".GALAXIA_TABLE_PREFIX."activities` ga ON gia.`wf_activity_id` = ga.`wf_activity_id` LEFT JOIN `".GALAXIA_TABLE_PREFIX."processes` gp ON gp.`wf_p_id`=gi.`wf_p_id` $mid"; - $result = $this->query($query,$wherevars,$maxRecords,$offset); - $cant = $this->getOne($query_cant,$wherevars); - $ret = Array(); - while($res = $result->fetchRow()) { - $iid = $res['wf_instance_id']; - $res['workitems']=$this->getOne("select count(*) from `".GALAXIA_TABLE_PREFIX."workitems` where `wf_instance_id`=?",array($iid)); - $ret[$iid] = $res; - } - $retval = Array(); - $retval["data"] = $ret; - $retval["cant"] = $cant; - return $retval; - } - - - function monitor_list_all_processes($sort_mode = 'wf_name_asc', $where = '') { - if (!empty($where)) { - $where = " where ($where) "; - } - $query = "select `wf_name`,`wf_version`,`wf_p_id` from `".GALAXIA_TABLE_PREFIX."processes` $where order by ".$this->convert_sortmode($sort_mode); - $result = $this->query($query); - $ret = Array(); - while($res = $result->fetchRow()) { - $pId = $res['wf_p_id']; - $ret[$pId] = $res; - } - return $ret; - } - - function monitor_list_all_activities($sort_mode = 'wf_name_asc', $where = '') { - if (!empty($where)) { - $where = " where ($where) "; - } - $query = "select `wf_name`,`wf_activity_id` from `".GALAXIA_TABLE_PREFIX."activities` $where order by ".$this->convert_sortmode($sort_mode); - $result = $this->query($query); - $ret = Array(); - while($res = $result->fetchRow()) { - $aid = $res['wf_activity_id']; - $ret[$aid] = $res; - } - return $ret; - } - - function monitor_list_statuses() { - $query = "select distinct(`wf_status`) from `".GALAXIA_TABLE_PREFIX."instances`"; - $result = $this->query($query); - $ret = Array(); - while($res = $result->fetchRow()) { - $ret[] = $res['wf_status']; - } - return $ret; - } - - function monitor_list_users() { - $query = "select distinct(`wf_user`) from `".GALAXIA_TABLE_PREFIX."instance_activities`"; - $result = $this->query($query); - $ret = Array(); - while($res = $result->fetchRow()) { - $ret[] = $res['wf_user']; - } - return $ret; - } - - function monitor_list_wi_users() { - $query = "select distinct(`wf_user`) from `".GALAXIA_TABLE_PREFIX."workitems`"; - $result = $this->query($query); - $ret = Array(); - while($res = $result->fetchRow()) { - $ret[] = $res['wf_user']; - } - return $ret; - } - - - function monitor_list_owners() { - $query = "select distinct(`wf_owner`) from `".GALAXIA_TABLE_PREFIX."instances`"; - $result = $this->query($query); - $ret = Array(); - while($res = $result->fetchRow()) { - $ret[] = $res['wf_owner']; - } - return $ret; - } - - - function monitor_list_activity_types() { - $query = "select distinct(`wf_type`) from `".GALAXIA_TABLE_PREFIX."activities`"; - $result = $this->query($query); - $ret = Array(); - while($res = $result->fetchRow()) { - $ret[] = $res['wf_type']; - } - return $ret; - } - - function monitor_get_workitem($itemId) { - $query = "select gw.`wf_order_id`,ga.`wf_name`,ga.`wf_type`,ga.`wf_is_interactive`,gp.`wf_name` as `wf_wf_procname`,gp.`wf_version`,"; - $query.= "gw.`wf_item_id`,gw.`wf_properties`,gw.`wf_user`,`wf_started`,`wf_ended`-`wf_started` as wf_duration "; - $query.= "from `".GALAXIA_TABLE_PREFIX."workitems` gw,`".GALAXIA_TABLE_PREFIX."activities` ga,`".GALAXIA_TABLE_PREFIX."processes` gp where ga.`wf_activity_id`=gw.`wf_activity_id` and ga.`wf_p_id`=gp.`wf_p_id` and `wf_item_id`=?"; - $result = $this->query($query, array($itemId)); - $res = $result->fetchRow(); - $res['wf_properties'] = unserialize($res['wf_properties']); - return $res; - } - - // List workitems per instance, remove workitem, update_workitem - function monitor_list_workitems($offset,$maxRecords,$sort_mode,$find,$where='',$wherevars=array()) { - $mid = ''; - if ($where) { - $mid.= " and ($where) "; - } - if($find) { - $findesc = $this->qstr('%'.$find.'%'); - $mid.=" and (`wf_properties` like $findesc)"; - } -// TODO: retrieve instance status as well - $query = "select `wf_item_id`,`wf_ended`-`wf_started` as wf_duration,ga.`wf_is_interactive`, ga.`wf_type`,gp.`wf_name` as wf_procname,gp.`wf_version`,ga.`wf_name` as wf_act_name,"; - $query.= "ga.`wf_activity_id`,`wf_instance_id`,`wf_order_id`,`wf_properties`,`wf_started`,`wf_ended`,`wf_user` from `".GALAXIA_TABLE_PREFIX."workitems` gw,`".GALAXIA_TABLE_PREFIX."activities` ga,`".GALAXIA_TABLE_PREFIX."processes` gp "; - $query.= "where gw.`wf_activity_id`=ga.`wf_activity_id` and ga.`wf_p_id`=gp.`wf_p_id` $mid order by gp.`wf_p_id` desc,".$this->convert_sortmode($sort_mode); - $query_cant = "select count(*) from `".GALAXIA_TABLE_PREFIX."workitems` gw,`".GALAXIA_TABLE_PREFIX."activities` ga,`".GALAXIA_TABLE_PREFIX."processes` gp where gw.`wf_activity_id`=ga.`wf_activity_id` and ga.`wf_p_id`=gp.`wf_p_id` $mid"; - $result = $this->query($query,$wherevars,$maxRecords,$offset); - $cant = $this->getOne($query_cant,$wherevars); - $ret = Array(); - while($res = $result->fetchRow()) { - $itemId = $res['wf_item_id']; - $ret[$itemId] = $res; - } - $retval = Array(); - $retval["data"] = $ret; - $retval["cant"] = $cant; - return $retval; - } - - -} -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/common/Base.php b/phpgwapi/inc/galaxia_workflow/src/common/Base.php deleted file mode 100644 index 63d9bf1095..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/common/Base.php +++ /dev/null @@ -1,119 +0,0 @@ -db = $db; - } - - // copied from tikilib.php - function query($query, $values = null, $numrows = -1, $offset = -1, $reporterrors = true) { - $this->convert_query($query); - - // Galaxia needs to be call ADOdb in associative mode - $this->db->SetFetchMode(ADODB_FETCH_ASSOC); - - if ($numrows == -1 && $offset == -1) - $result = $this->db->Execute($query, $values); - else - $result = $this->db->SelectLimit($query, $numrows, $offset, $values); - if (!$result && $reporterrors) - $this->sql_error($query, $values, $result); - $this->num_queries++; - return $result; - } - - function getOne($query, $values = null, $reporterrors = true) { - $this->convert_query($query); - $result = $this->db->SelectLimit($query, 1, 0, $values); - if (!$result && $reporterrors) - $this->sql_error($query, $values, $result); - - $res = $result->fetchRow(); - $this->num_queries++; - if ($res === false) - return (NULL); //simulate pears behaviour - list($key, $value) = each($res); - return $value; - } - - function sql_error($query, $values, $result) { - global $ADODB_LASTDB; - - trigger_error($ADODB_LASTDB . " error: " . $this->db->ErrorMsg(). " in query:
" . $query . "
", E_USER_WARNING); - // only for debugging. - print_r($values); - //echo "
"; - die; - } - - // functions to support DB abstraction - function convert_query(&$query) { - global $ADODB_LASTDB; - - switch ($ADODB_LASTDB) { - case "oci8": - $query = preg_replace("/`/", "\"", $query); - // convert bind variables - adodb does not do that - $qe = explode("?", $query); - $query = ''; - for ($i = 0; $i < sizeof($qe) - 1; $i++) { - $query .= $qe[$i] . ":" . $i; - } - $query .= $qe[$i]; - break; - case "postgres7": - case "sybase": - $query = preg_replace("/`/", "\"", $query); - break; - } - } - - function convert_sortmode($sort_mode) { - global $ADODB_LASTDB; - - $sort_mode = str_replace("__", "` ", $sort_mode); - $sort_mode = "`" . $sort_mode; - return $sort_mode; - } - - function convert_binary() { - global $ADODB_LASTDB; - - switch ($ADODB_LASTDB) { - case "pgsql72": - case "oci8": - case "postgres7": - return; - break; - case "mysql3": - case "mysql": - return "binary"; - break; - } - } - - function qstr($string, $quoted = null) - { - if (!isset($quoted)) { - $quoted = get_magic_quotes_gpc(); - } - return $this->db->qstr($string,$quoted); - } - -} //end of class - -?> diff --git a/phpgwapi/inc/galaxia_workflow/src/common/Observable.php b/phpgwapi/inc/galaxia_workflow/src/common/Observable.php deleted file mode 100644 index d2ad99a8f9..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/common/Observable.php +++ /dev/null @@ -1,81 +0,0 @@ -_observerId = uniqid(rand()); - $this->_observers[$event][$obj->_observerId] = &$obj; - } - - /*! - Attaches an object to the class listening for any event. - The object will be notified when any event occurs in the derived class. - */ - function attach_all(&$obj) - { - if (!is_object($obj)) { - return false; - } - $obj->_observerId = uniqid(rand()); - $this->_observers['all'][$obj->_observerId] = &$obj; - } - - /*! - Detaches an observer from the class. - */ - function dettach(&$obj) - { - if (isset($this->_observers[$obj->_observerId])) { - unset($this->_observers[$obj->_observerId]); - } - } - - /*! - \protected - Method used to notify objects of an event. This is called in the - methods of the derived class that want to notify some event. - */ - function notify_all($event, $msg) - { - //reset($this->_observers[$event]); - if(isset($this->_observers[$event])) { - foreach ($this->_observers[$event] as $observer) { - $observer->notify($event,$msg); - } - } - if(isset($this->_observers['all'])) { - foreach ($this->_observers['all'] as $observer) { - $observer->notify($event,$msg); - } - } - - } - -} -?> \ No newline at end of file diff --git a/phpgwapi/inc/galaxia_workflow/src/common/Observer.php b/phpgwapi/inc/galaxia_workflow/src/common/Observer.php deleted file mode 100644 index 8ac67d7d89..0000000000 --- a/phpgwapi/inc/galaxia_workflow/src/common/Observer.php +++ /dev/null @@ -1,27 +0,0 @@ -attach('moo',$log); //Now $log observers 'moo' events in $foo class - // of - $foo->attach_all($log); // Same but all events are listened -*/ - -class Observer { - ///This will be assigned by an observable object when attaching. - var $_observerId=''; - - function notify($event, $msg) { - // do something... - } -} -?>