[795] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /** |
---|
| 4 | * Configuration of the Galaxia Workflow Engine for E-Groupware |
---|
| 5 | * @package Galaxia |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | // Common prefix used for all database table names, e.g. galaxia_ |
---|
| 9 | if (!defined('GALAXIA_TABLE_PREFIX')) { |
---|
| 10 | define('GALAXIA_TABLE_PREFIX', 'egw_wf_'); |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | // Directory containing the Galaxia library, e.g. this directory |
---|
| 14 | if (!defined('GALAXIA_LIBRARY')) { |
---|
| 15 | define('GALAXIA_LIBRARY', dirname(__FILE__)); |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | // Specify how error messages should be shown |
---|
| 19 | if (!function_exists('galaxia_show_error')) { |
---|
| 20 | /** |
---|
| 21 | * Show error messages from the engine |
---|
| 22 | * @param $msg is the message to show |
---|
| 23 | * @param $dying is true by default and will launch a terminal die command |
---|
| 24 | * @param $log is trru by default and will emit a PHP WARNING if set to true |
---|
| 25 | * if not set to false. |
---|
| 26 | */ |
---|
| 27 | function galaxia_show_error($msg, $dying = true, $log=true) |
---|
| 28 | { |
---|
| 29 | $final_message = str_replace(htmlspecialchars('<br />'), '<br />', htmlspecialchars("Galaxia Workflow Error: $msg")); |
---|
| 30 | if ($log) |
---|
| 31 | { |
---|
| 32 | trigger_error($final_message, E_USER_WARNING); |
---|
| 33 | } |
---|
| 34 | if ($dying) |
---|
| 35 | { |
---|
| 36 | die($final_message); |
---|
| 37 | } |
---|
| 38 | else |
---|
| 39 | { |
---|
| 40 | echo("<br>$final_message"); |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | // filesystem Operations |
---|
| 47 | $GLOBALS['phpgw']->vfs = createobject('phpgwapi.vfs'); |
---|
| 48 | |
---|
| 49 | // check if basedir exists |
---|
| 50 | $test=$GLOBALS['phpgw']->vfs->get_real_info(array('string' => '/', 'relatives' => array(RELATIVE_NONE), 'relative' => False)); |
---|
| 51 | if($test[mime_type]!='Directory') |
---|
| 52 | { |
---|
| 53 | galaxia_show_error(lang('Base directory does not exist, please ask adminstrator to check the global configuration'),false, true); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | // check if /workflow exists |
---|
| 57 | $test = @$GLOBALS['phpgw']->vfs->get_real_info(array('string' => '/workflow', 'relatives' => array(RELATIVE_NONE), 'relative' => False)); |
---|
| 58 | if($test[mime_type]!='Directory') |
---|
| 59 | { |
---|
| 60 | // if not, create it |
---|
| 61 | $GLOBALS['phpgw']->vfs->override_acl = 1; |
---|
| 62 | $GLOBALS['phpgw']->vfs->mkdir(array( |
---|
| 63 | 'string' => '/workflow', |
---|
| 64 | 'relatives' => array(RELATIVE_NONE) |
---|
| 65 | )); |
---|
| 66 | $GLOBALS['phpgw']->vfs->override_acl = 0; |
---|
| 67 | |
---|
| 68 | // test one more time |
---|
| 69 | $test = $GLOBALS['phpgw']->vfs->get_real_info(array('string' => '/workflow', 'relatives' => array(RELATIVE_NONE), 'relative' => False)); |
---|
| 70 | if($test[mime_type]!='Directory') |
---|
| 71 | { |
---|
| 72 | galaxia_show_error(lang('/workflow directory does not exist and could not be created, please ask adminstrator to check the global configuration'), false, true); |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | // Directory where the Galaxia processes will be stored, e.g. /workflow on the vfs |
---|
| 77 | if (!defined('GALAXIA_PROCESSES')) |
---|
| 78 | { |
---|
| 79 | // Note: this directory must be writeable by the webserver ! |
---|
| 80 | define('GALAXIA_PROCESSES', $GLOBALS['phpgw']->vfs->basedir.SEP.'workflow'); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | // Directory where a *copy* of the Galaxia activity templates will be stored, e.g. templates |
---|
| 84 | // Define as '' if you don't want to copy templates elsewhere |
---|
| 85 | if (!defined('GALAXIA_TEMPLATES')) { |
---|
| 86 | // Note: this directory must be writeable by the webserver ! |
---|
| 87 | define('GALAXIA_TEMPLATES', ''); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | // Default header to be added to new activity templates |
---|
| 91 | if (!defined('GALAXIA_TEMPLATE_HEADER')) { |
---|
| 92 | define('GALAXIA_TEMPLATE_HEADER', ''); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | // File where the ProcessManager logs for Galaxia will be saved, e.g. lib/Galaxia/log/pm.log |
---|
| 96 | // Define as '' if you don't want to use logging |
---|
| 97 | if (!defined('GALAXIA_LOGFILE')) { |
---|
| 98 | // Note: this file must be writeable by the webserver ! |
---|
| 99 | //define('GALAXIA_LOGFILE', GALAXIA_LIBRARY . '/log/pm.log'); |
---|
| 100 | define('GALAXIA_LOGFILE', $GLOBALS['phpgw']->vfs->basedir.SEP.'workflow'.SEP.'galaxia.log'); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | // Directory containing the GraphViz 'dot' and 'neato' programs, in case |
---|
| 104 | // your webserver can't find them via its PATH environment variable |
---|
| 105 | if (!defined('GRAPHVIZ_BIN_DIR')) { |
---|
| 106 | define('GRAPHVIZ_BIN_DIR', ''); |
---|
| 107 | //define('GRAPHVIZ_BIN_DIR', 'd:/wintools/ATT/GraphViz/bin'); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | if (!function_exists('tra')) |
---|
| 111 | { |
---|
| 112 | // language function |
---|
| 113 | function tra($msg, $m1='', $m2='', $m3='', $m4='') |
---|
| 114 | { |
---|
| 115 | return lang($msg, $m1, $m2, $m3, $m4); |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | //define the list of agents avaible with your Galaxia installation |
---|
| 121 | if (!function_exists('galaxia_get_agents_list')) |
---|
| 122 | { |
---|
| 123 | /** |
---|
| 124 | * * This function list the agents avaible with your galaxia installation. The name of an agent |
---|
| 125 | * * is his unique identifier, the priority is an execution order priority |
---|
| 126 | * * @return an associative array of agents description, each row is an agent description |
---|
| 127 | * * containing a 'wf_agent_type' key and a 'wf_agent_priority' key |
---|
| 128 | */ |
---|
| 129 | function galaxia_get_agents_list() |
---|
| 130 | { |
---|
| 131 | $res = array( |
---|
| 132 | array( |
---|
| 133 | 'wf_agent_type' => 'mail_smtp', |
---|
| 134 | 'wf_agent_priority' => 1, |
---|
| 135 | ) |
---|
| 136 | ); |
---|
| 137 | return $res; |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | if (!function_exists('galaxia_user_can_admin_process')) |
---|
| 144 | { |
---|
| 145 | //! Specify if the user has special admin rights on processes |
---|
| 146 | /** |
---|
| 147 | * * @return true if the actual user has access to the processes administration. |
---|
| 148 | * * ie. he can edit/activate/deactivate/create/destroy processes and activities |
---|
| 149 | * * warning: dangerous rights, this user can do whatever PHP can do... |
---|
| 150 | */ |
---|
| 151 | function galaxia_user_can_admin_process() |
---|
| 152 | { |
---|
[3167] | 153 | return (Factory::getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']) || $GLOBALS['phpgw']->acl->check('admin_workflow', 1, 'workflow')); |
---|
[795] | 154 | } |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | if (!function_exists('galaxia_user_can_admin_instance')) |
---|
| 158 | { |
---|
| 159 | //! Specify if the user has special admin rights on instances |
---|
| 160 | /** |
---|
| 161 | * * @return true if the actual user has access to the instance administration |
---|
| 162 | * * ie. he can edit and modify all properties, members, assigned users of an instance whatever the state of the instance is |
---|
| 163 | * * warning: this is clearly an administrator right |
---|
| 164 | */ |
---|
| 165 | function galaxia_user_can_admin_instance() |
---|
| 166 | { |
---|
[3167] | 167 | return (Factory::getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']) || $GLOBALS['phpgw']->acl->check('admin_instance_workflow', 1, 'workflow')); |
---|
[795] | 168 | } |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | if (!function_exists('galaxia_user_can_clean_instances')) |
---|
| 173 | { |
---|
| 174 | //! Specify if the user has special cleanup rights on ALL instances |
---|
| 175 | /** |
---|
| 176 | * * @return true if the actual user is granted access to the 'clean instances' and 'clean all instances for a process' functions |
---|
| 177 | * * warning: theses are dangerous functions! |
---|
| 178 | */ |
---|
| 179 | function galaxia_user_can_clean_instances() |
---|
| 180 | { |
---|
[3167] | 181 | return (Factory::getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']) || $GLOBALS['phpgw']->acl->check('cleanup_workflow', 1, 'workflow')); |
---|
[795] | 182 | } |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | if (!function_exists('galaxia_user_can_clean_aborted_instances')) |
---|
| 186 | { |
---|
| 187 | //! Specify if the actual user has special cleanup rights on aborted instances |
---|
| 188 | /** |
---|
| 189 | * * @return true if the user is granted access to the 'clean aborted instances' functions |
---|
| 190 | */ |
---|
| 191 | function galaxia_user_can_clean_aborted_instances() |
---|
| 192 | { |
---|
[3167] | 193 | return (Factory::getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']) || $GLOBALS['phpgw']->acl->check('cleanup_aborted_workflow', 1, 'workflow')); |
---|
[795] | 194 | } |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | if (!function_exists('galaxia_user_can_monitor')) |
---|
| 198 | { |
---|
| 199 | //! Specify if the user has special monitors rights |
---|
| 200 | /** |
---|
| 201 | * * @return true if the actual user has access to the monitor screens (this is not sufficient for cleanup access) |
---|
| 202 | */ |
---|
| 203 | function galaxia_user_can_monitor() |
---|
| 204 | { |
---|
[3167] | 205 | return (Factory::getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']) || $GLOBALS['phpgw']->acl->check('monitor_workflow', 1, 'workflow')); |
---|
[795] | 206 | } |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | if (!function_exists('galaxia_retrieve_user_groups')) |
---|
| 210 | { |
---|
| 211 | /*! |
---|
| 212 | * Specify how to retrieve an array containing all groups id for a given user |
---|
| 213 | * if the user is in no group this function should return false |
---|
| 214 | * @param $user is the current user id |
---|
| 215 | * @return an arry of integers, the groups ids the user is member of, or false if the user is not |
---|
| 216 | * the member of any group |
---|
| 217 | */ |
---|
| 218 | function galaxia_retrieve_user_groups($user = 0) |
---|
| 219 | { |
---|
| 220 | if ($user == '') |
---|
| 221 | $user = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
| 222 | |
---|
[3167] | 223 | $memberships = Factory::getInstance('WorkflowLDAP')->getUserGroups($user); |
---|
[795] | 224 | |
---|
| 225 | if ($memberships === false) |
---|
| 226 | return false; |
---|
| 227 | |
---|
| 228 | if (count($memberships) == 0) |
---|
| 229 | return false; |
---|
| 230 | |
---|
| 231 | return $memberships; |
---|
| 232 | } |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | |
---|
| 236 | if (!function_exists('galaxia_retrieve_group_users')) |
---|
| 237 | { |
---|
| 238 | //! Specify how to retrieve an array containing all users id for a given group id |
---|
| 239 | /** |
---|
| 240 | * * @param $group the group id |
---|
| 241 | * * @param $add_names false by default, if true we add user names in the result |
---|
| 242 | * * return an array with all users id or an associative array with names associated with ids if $add_names is true |
---|
| 243 | */ |
---|
| 244 | function galaxia_retrieve_group_users($group, $add_names = false) |
---|
| 245 | { |
---|
| 246 | /* get information regarding the members of the group */ |
---|
[3167] | 247 | $members = &Factory::getInstance('WorkflowLDAP')->getGroupUsers($group); |
---|
[795] | 248 | |
---|
| 249 | /* checl for error in the LDAP query */ |
---|
| 250 | if ($members === false) |
---|
| 251 | return false; |
---|
| 252 | |
---|
| 253 | /* format the output as requested */ |
---|
| 254 | $group_users = array(); |
---|
| 255 | foreach($members as $member) |
---|
| 256 | if ($add_names) |
---|
| 257 | $group_users[$member['account_id']] = $member['account_name']; |
---|
| 258 | else |
---|
| 259 | $group_users[] = $member['account_id']; |
---|
| 260 | |
---|
| 261 | return $group_users; |
---|
| 262 | } |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | if (!function_exists('galaxia_retrieve_running_user')) |
---|
| 266 | { |
---|
| 267 | //! returns the actual user running this PHP code |
---|
| 268 | /** |
---|
| 269 | * * @return the user id of the actual running user. |
---|
| 270 | */ |
---|
| 271 | function galaxia_retrieve_running_user() |
---|
| 272 | { |
---|
| 273 | return ($GLOBALS['phpgw_info']['user']['account_id']); |
---|
| 274 | } |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | |
---|
| 278 | if (!function_exists('galaxia_retrieve_name')) |
---|
| 279 | { |
---|
| 280 | //! Specify how to retrieve the name of an user with is Id |
---|
| 281 | /** |
---|
| 282 | * * @param $user the user or group id |
---|
| 283 | * * return the name of the user |
---|
| 284 | */ |
---|
| 285 | function galaxia_retrieve_name($user) |
---|
| 286 | { |
---|
| 287 | $username = $GLOBALS['phpgw']->accounts->id2name($user); |
---|
| 288 | return $username; |
---|
| 289 | } |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | // Specify how to execute a non-interactive activity (for use in src/API/Instance.php) |
---|
| 293 | if (!function_exists('galaxia_execute_activity')) { |
---|
| 294 | /** |
---|
| 295 | * * This function will execute automatic (non-interactive) activities for the engine |
---|
| 296 | * * @param $activityId (default 0) is the activity_id it should run |
---|
| 297 | * * @param $iid (default 0) is the instance id it should run for |
---|
| 298 | * * @param $auto is true by default |
---|
| 299 | * * @return AN ARRAY, or at least true or false. This array can contain : |
---|
| 300 | * * a key 'failure' with an error string the engine will retrieve in instance error messages in case of |
---|
| 301 | * failure (this will mark your execution as Bad), |
---|
| 302 | * * a key 'debug' with a debug string the engine will retrieve in instance error messages, |
---|
| 303 | */ |
---|
| 304 | function galaxia_execute_activity($activityId = 0, $iid = 0, $auto = 1) |
---|
| 305 | { |
---|
| 306 | // This way we create a new run_activity instance for the next activity |
---|
[3167] | 307 | $run_activity = Factory::getInstance('run_activity'); |
---|
[795] | 308 | $data = $run_activity->go($activityId, $iid, $auto); |
---|
| 309 | return $data; |
---|
| 310 | } |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | /* |
---|
| 314 | Specify how to obtain stored config values |
---|
| 315 | Parameter: an array containing pairs of (variables_names => default values) |
---|
| 316 | For an unknown variable name it will return default_value and this |
---|
| 317 | default value will be the NEW STORED value. If no default value is |
---|
| 318 | given we assume it's a false. |
---|
| 319 | WARNING: you should cast your result if you bet its' an integer |
---|
| 320 | as it is maybe stored as a string. But 1 and 0 special values are |
---|
| 321 | handled correctly as ints (bools). |
---|
| 322 | */ |
---|
| 323 | if (!function_exists('galaxia_get_config_values')) |
---|
| 324 | { |
---|
| 325 | function galaxia_get_config_values($parameters=array()) |
---|
| 326 | { |
---|
[3167] | 327 | $config = Factory::getInstance('config'); |
---|
[795] | 328 | $config->read_repository(); |
---|
| 329 | |
---|
| 330 | $result_array = array(); |
---|
| 331 | foreach ($parameters as $config_var => $default_value) |
---|
| 332 | { |
---|
| 333 | $config_value = $config->config_data[$config_var]; |
---|
| 334 | if(isset($config_value)) |
---|
| 335 | { //we add something in the config store, we take it |
---|
| 336 | if ($config_value=='False') |
---|
| 337 | { |
---|
| 338 | $result_array[$config_var]=0; |
---|
| 339 | } |
---|
| 340 | elseif ($config_value=='True') |
---|
| 341 | { |
---|
| 342 | $result_array[$config_var]=1; |
---|
| 343 | } |
---|
| 344 | else |
---|
| 345 | { |
---|
| 346 | $result_array[$config_var] = $config_value; |
---|
| 347 | } |
---|
| 348 | } |
---|
| 349 | else |
---|
| 350 | { |
---|
| 351 | //we had no value stored yet, so we store it now |
---|
| 352 | //boolean warning: egw'config class is not storing false values if it is 0 |
---|
| 353 | //we have to map theses int... |
---|
| 354 | $stored_value= (string)$default_value; |
---|
| 355 | if ($stored_value=='1') |
---|
| 356 | { |
---|
| 357 | $stored_value='True'; |
---|
| 358 | } |
---|
| 359 | elseif ($stored_value=='0') |
---|
| 360 | { |
---|
| 361 | $stored_value='False'; |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | $config->value($config_var,$stored_value); |
---|
| 365 | $config->save_repository(); |
---|
| 366 | // take the not casted variable |
---|
| 367 | $result_array[$config_var] = $default_value; |
---|
| 368 | } |
---|
| 369 | } |
---|
| 370 | unset($config); |
---|
| 371 | return $result_array; |
---|
| 372 | } |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | ?> |
---|