1 | <?php |
---|
2 | require_once 'common.inc.php'; |
---|
3 | // include galaxia's configuration tailored to egroupware |
---|
4 | require_once('engine/config.egw.inc.php'); |
---|
5 | |
---|
6 | require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ProcessManager.php'); |
---|
7 | require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'RoleManager.php'); |
---|
8 | require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ActivityManager.php'); |
---|
9 | require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'API' . SEP . 'Process.php'); |
---|
10 | /** |
---|
11 | * @package Workflow |
---|
12 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
13 | */ |
---|
14 | class workflow_processmanager extends ProcessManager |
---|
15 | { |
---|
16 | /** |
---|
17 | * @var array $workflow_acl |
---|
18 | * @access public |
---|
19 | */ |
---|
20 | var $workflow_acl; |
---|
21 | /** |
---|
22 | * @var array $not_export_attributes |
---|
23 | * @access public |
---|
24 | */ |
---|
25 | var $not_export_attributes = array( |
---|
26 | 'database_user', |
---|
27 | 'database_password' |
---|
28 | ); |
---|
29 | /** |
---|
30 | * Constructor |
---|
31 | * @access public |
---|
32 | * @return object |
---|
33 | */ |
---|
34 | function workflow_processmanager() |
---|
35 | { |
---|
36 | parent::ProcessManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID); |
---|
37 | $this->workflow_acl = CreateObject('workflow.workflow_acl'); |
---|
38 | |
---|
39 | /* allow regular users to see the process graph */ |
---|
40 | if ($_GET['menuaction'] == "workflow.ui_adminactivities.show_graph") |
---|
41 | return; |
---|
42 | |
---|
43 | if (isset($_GET['p_id'])) |
---|
44 | { |
---|
45 | if (!($this->workflow_acl->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']) || $this->workflow_acl->check_process_access($GLOBALS['phpgw_info']['user']['account_id'], (int) $_GET['p_id']))) |
---|
46 | { |
---|
47 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
48 | echo parse_navbar(); |
---|
49 | echo lang('access not permitted'); |
---|
50 | $GLOBALS['phpgw']->log->message('F-Abort, Unauthorized access to workflow.ui_adminprocesses'); |
---|
51 | $GLOBALS['phpgw']->log->commit(); |
---|
52 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
53 | } |
---|
54 | } |
---|
55 | } |
---|
56 | /** |
---|
57 | * Import process data |
---|
58 | * @param $data |
---|
59 | * @access public |
---|
60 | * @return bool |
---|
61 | */ |
---|
62 | function import_process(&$data) |
---|
63 | { |
---|
64 | if (!(isset($this->activity_manager))) $this->activity_manager = new ActivityManager($this->db); |
---|
65 | |
---|
66 | if (parent::import_process($data)) |
---|
67 | { |
---|
68 | $proc_name = $this->_normalize_name($data['name'],$data['version']); |
---|
69 | foreach($data['templates'] as $tpl) |
---|
70 | { |
---|
71 | $full_fname = GALAXIA_PROCESSES.SEP.$proc_name.SEP.'code'.SEP.'templates'.SEP.$tpl['name']; |
---|
72 | if (file_exists($full_fname)) unlink($full_fname); |
---|
73 | |
---|
74 | $fp = fopen($full_fname,"w"); |
---|
75 | fwrite($fp, $tpl['code']); |
---|
76 | fclose($fp); |
---|
77 | } |
---|
78 | |
---|
79 | foreach($data['includes'] as $inc) |
---|
80 | { |
---|
81 | $full_fname = GALAXIA_PROCESSES.SEP.$proc_name.SEP.'code'.SEP.$inc['name']; |
---|
82 | if (file_exists($full_fname)) unlink($full_fname); |
---|
83 | |
---|
84 | $fp = fopen($full_fname,"w"); |
---|
85 | fwrite($fp, $inc['code']); |
---|
86 | fclose($fp); |
---|
87 | } |
---|
88 | |
---|
89 | //create resource dir if needed |
---|
90 | $resource_dir = GALAXIA_PROCESSES . SEP . $proc_name . SEP . 'resources'; |
---|
91 | if (count($data['resources'])) |
---|
92 | if (!is_dir($resource_dir)) |
---|
93 | mkdir($resource_dir, 0770); |
---|
94 | |
---|
95 | if (is_array($data['resources'])) |
---|
96 | { |
---|
97 | foreach($data['resources'] as $res) |
---|
98 | { |
---|
99 | $full_fname = $resource_dir . SEP . $res['name']; |
---|
100 | if (file_exists($full_fname)) unlink($full_fname); |
---|
101 | $fp = fopen($full_fname,"w"); |
---|
102 | fwrite($fp, base64_decode($res['bindata'])); |
---|
103 | fclose($fp); |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | return true; |
---|
108 | } else { |
---|
109 | return false; |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | /** |
---|
114 | * Creates an XML representation of a process. |
---|
115 | * Original from ProcessManager Class |
---|
116 | * Modified to support includes, resources and variable templates |
---|
117 | * @param $pId process id |
---|
118 | * @access public |
---|
119 | * @return void |
---|
120 | */ |
---|
121 | function serialize_process($pId) |
---|
122 | { |
---|
123 | if (!(isset($this->activity_manager))) $this->activity_manager = new ActivityManager($this->db); |
---|
124 | if (!isset($this->jobManager)) |
---|
125 | $this->jobManager = new JobManager($this->db); |
---|
126 | |
---|
127 | //if (!(isset($this->activity_manager))) $this->activity_manager = new ActivityManager($this->db); |
---|
128 | // <process> |
---|
129 | $out = '<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n"; |
---|
130 | $out.= '<process>'."\n"; |
---|
131 | //we retrieve config values with the others process data |
---|
132 | $proc_info =& $this->get_process($pId, true); |
---|
133 | $wf_procname = $proc_info['wf_normalized_name']; |
---|
134 | $out.= ' <name>'.htmlspecialchars($proc_info['wf_name']).'</name>'."\n"; |
---|
135 | $out.= ' <isValid>'.htmlspecialchars($proc_info['wf_is_valid']).'</isValid>'."\n"; |
---|
136 | $out.= ' <version>'.htmlspecialchars($proc_info['wf_version']).'</version>'."\n"; |
---|
137 | $out.= ' <isActive>'.htmlspecialchars($proc_info['wf_is_active']).'</isActive>'."\n"; |
---|
138 | $out.=' <description>'.htmlspecialchars($proc_info['wf_description']).'</description>'."\n"; |
---|
139 | $out.= ' <lastModif>'.date("d/m/Y [h:i:s]",$proc_info['wf_last_modif']).'</lastModif>'."\n"; |
---|
140 | |
---|
141 | //Shared code |
---|
142 | $out.= ' <sharedCode><![CDATA['; |
---|
143 | $fp=fopen(GALAXIA_PROCESSES.SEP."$wf_procname".SEP."code".SEP."shared.php","r"); |
---|
144 | while(!feof($fp)) { |
---|
145 | $line=fread($fp,8192); |
---|
146 | $out.=$line; |
---|
147 | } |
---|
148 | fclose($fp); |
---|
149 | $out.= ' ]]></sharedCode>'."\n"; |
---|
150 | |
---|
151 | //Loop on config values |
---|
152 | $out.=' <configs>'."\n"; |
---|
153 | foreach($proc_info['config'] as $res) { |
---|
154 | $name = $res['wf_config_name']; |
---|
155 | $value_int = $res['wf_config_value_int']; |
---|
156 | $value = $res['wf_config_value']; |
---|
157 | if (array_search($name,$this->not_export_attributes) === false) |
---|
158 | { |
---|
159 | $out.=' <config>'."\n"; |
---|
160 | $out.=' <wf_config_name>'.htmlspecialchars($name).'</wf_config_name>'."\n"; |
---|
161 | $out.=' <wf_config_value>'.htmlspecialchars($value).'</wf_config_value>'."\n"; |
---|
162 | $out.=' <wf_config_value_int>'.htmlspecialchars($value_int).'</wf_config_value_int>'."\n"; |
---|
163 | $out.=' </config>'."\n"; |
---|
164 | } |
---|
165 | } |
---|
166 | $out.=' </configs>'."\n"; |
---|
167 | |
---|
168 | // Now loop over activities |
---|
169 | |
---|
170 | $act_list = $this->activity_manager->list_activities($pId, 0, -1, 'wf_name__asc', '','',false); |
---|
171 | $out.=' <activities>'."\n"; |
---|
172 | foreach($act_list['data'] as $res) { |
---|
173 | $name = $res['wf_normalized_name']; |
---|
174 | $out.=' <activity>'."\n"; |
---|
175 | $out.=' <name>'.htmlspecialchars($res['wf_name']).'</name>'."\n"; |
---|
176 | $out.=' <type>'.htmlspecialchars($res['wf_type']).'</type>'."\n"; |
---|
177 | $out.=' <description>'.htmlspecialchars($res['wf_description']).'</description>'."\n"; |
---|
178 | $out.=' <menuPath>'.htmlspecialchars($res['wf_menu_path']).'</menuPath>'."\n"; |
---|
179 | $out.=' <lastModif>'.date("d/m/Y [h:i:s]",$res['wf_last_modif']).'</lastModif>'."\n"; |
---|
180 | $out.=' <isInteractive>'.$res['wf_is_interactive'].'</isInteractive>'."\n"; |
---|
181 | $out.=' <isAutoRouted>'.$res['wf_is_autorouted'].'</isAutoRouted>'."\n"; |
---|
182 | $out.=' <roles>'."\n"; |
---|
183 | //loop on activity roles |
---|
184 | $actid = $res['wf_activity_id']; |
---|
185 | $roles =& $this->activity_manager->get_activity_roles($actid); |
---|
186 | foreach($roles as $role) { |
---|
187 | if ($role['wf_readonly']) |
---|
188 | { |
---|
189 | $out.=' <role readonly="true">'.htmlspecialchars($role['wf_name']).'</role>'."\n"; |
---|
190 | } |
---|
191 | else |
---|
192 | { |
---|
193 | $out.=' <role>'.htmlspecialchars($role['wf_name']).'</role>'."\n"; |
---|
194 | } |
---|
195 | } |
---|
196 | $out.=' </roles>'."\n"; |
---|
197 | $out.=' <agents>'."\n"; |
---|
198 | //loop on activity agents |
---|
199 | $agents =& $this->activity_manager->get_activity_agents($actid); |
---|
200 | foreach($agents as $agent) { |
---|
201 | $out.=' <agent>'."\n"; |
---|
202 | $out.=' <agent_type>'.htmlspecialchars($agent['wf_agent_type']).'</agent_type>'."\n"; |
---|
203 | //loop on agent datas |
---|
204 | $agent_data =& $this->activity_manager->get_activity_agent_data($actid,$agent['wf_agent_type']); |
---|
205 | $out.=' <agent_datas>'."\n"; |
---|
206 | foreach($agent_data as $key => $value) |
---|
207 | { |
---|
208 | if (!($key=='wf_agent_id')) |
---|
209 | { |
---|
210 | $out.=' <agent_data>'."\n"; |
---|
211 | $out.=' <name>'.htmlspecialchars($key).'</name>'."\n"; |
---|
212 | $out.=' <value>'.htmlspecialchars($value).'</value>'."\n"; |
---|
213 | $out.=' </agent_data>'."\n"; |
---|
214 | } |
---|
215 | } |
---|
216 | $out.=' </agent_datas>'."\n"; |
---|
217 | $out.=' </agent>'."\n"; |
---|
218 | } |
---|
219 | $out.=' </agents>'."\n"; |
---|
220 | |
---|
221 | //the code |
---|
222 | $out.=' <code><![CDATA['; |
---|
223 | $fp=fopen(GALAXIA_PROCESSES.SEP."$wf_procname".SEP."code".SEP."activities".SEP."$name.php","r"); |
---|
224 | while(!feof($fp)) { |
---|
225 | $line=fread($fp,8192); |
---|
226 | $out.=$line; |
---|
227 | } |
---|
228 | fclose($fp); |
---|
229 | $out.=' ]]></code>'; |
---|
230 | if($res['wf_is_interactive']=='y') { |
---|
231 | $out.=' <template><![CDATA['; |
---|
232 | $fp=fopen(GALAXIA_PROCESSES.SEP."$wf_procname".SEP."code".SEP."templates".SEP."$name.tpl","r"); |
---|
233 | //while(!feof($fp)) { |
---|
234 | // $line=fread($fp,8192); |
---|
235 | $out.=''; //all templatess will be exported in another section |
---|
236 | //} |
---|
237 | fclose($fp); |
---|
238 | $out.=' ]]></template>'; |
---|
239 | } |
---|
240 | $out.=' </activity>'."\n"; |
---|
241 | } |
---|
242 | $out.=' </activities>'."\n"; |
---|
243 | |
---|
244 | //export all templates |
---|
245 | $base_path = GALAXIA_PROCESSES.SEP.$wf_procname.SEP.'code'.SEP.'templates'; |
---|
246 | $handle = opendir($base_path); |
---|
247 | $out.=' <templates>'."\n"; |
---|
248 | while (false !== ($name = readdir($handle))) |
---|
249 | { |
---|
250 | if (is_dir($base_path.SEP.$name)) |
---|
251 | continue; |
---|
252 | if (substr($name, -4) != ".tpl") |
---|
253 | continue; |
---|
254 | $out.=' <template>'."\n"; |
---|
255 | $out.=' <name>'.htmlspecialchars($name).'</name>'."\n"; |
---|
256 | //the code |
---|
257 | $out.=' <code><![CDATA['; |
---|
258 | $fp=fopen($base_path.SEP.$name,'r'); |
---|
259 | while(!feof($fp)) { |
---|
260 | $line=fread($fp,8192); |
---|
261 | $out.=$line; |
---|
262 | } |
---|
263 | fclose($fp); |
---|
264 | $out.=' ]]></code>'; |
---|
265 | $out.=' </template>'."\n"; |
---|
266 | } |
---|
267 | $out.=' </templates>'."\n"; |
---|
268 | |
---|
269 | //export all includes |
---|
270 | $base_path = GALAXIA_PROCESSES.SEP.$wf_procname.SEP.'code'; |
---|
271 | $handle = opendir($base_path); |
---|
272 | $out.=' <includes>'."\n"; |
---|
273 | while (false !== ($name = readdir($handle))) |
---|
274 | { |
---|
275 | if (is_dir($base_path.SEP.$name)) /* ignore directories */ |
---|
276 | continue; |
---|
277 | if ($name == 'shared.php') /* shared.php was saved before */ |
---|
278 | continue; |
---|
279 | if (substr($name, -4) != ".php") |
---|
280 | continue; |
---|
281 | $out.=' <include>'."\n"; |
---|
282 | $out.=' <name>'.htmlspecialchars($name).'</name>'."\n"; |
---|
283 | //the code |
---|
284 | $out.=' <code><![CDATA['; |
---|
285 | $fp=fopen($base_path.SEP.$name,'r'); |
---|
286 | while(!feof($fp)) |
---|
287 | { |
---|
288 | $line=fread($fp,8192); |
---|
289 | $out.=$line; |
---|
290 | } |
---|
291 | fclose($fp); |
---|
292 | $out.=' ]]></code>'; |
---|
293 | $out.=' </include>'."\n"; |
---|
294 | } |
---|
295 | $out.=' </includes>'."\n"; |
---|
296 | |
---|
297 | $jobList = $this->jobManager->getJobsByProcessID($pId); |
---|
298 | $out .= " <jobs>\n"; |
---|
299 | foreach ($jobList as $job) |
---|
300 | { |
---|
301 | $out .= " <job>\n"; |
---|
302 | $out .= " <name>" . htmlspecialchars($job['name']) . "</name>\n"; |
---|
303 | $out .= " <description>" . htmlspecialchars($job['description']) . "</description>\n"; |
---|
304 | $out .= " <timeStart>" . htmlspecialchars($job['time_start']) . "</timeStart>\n"; |
---|
305 | $out .= " <intervalValue>" . htmlspecialchars($job['interval_value']) . "</intervalValue>\n"; |
---|
306 | $out .= " <intervalUnity>" . htmlspecialchars($job['interval_unity']) . "</intervalUnity>\n"; |
---|
307 | $out .= " <dateType>" . htmlspecialchars($job['date_type']) . "</dateType>\n"; |
---|
308 | $out .= " <weekDays>" . htmlspecialchars($job['week_days']) . "</weekDays>\n"; |
---|
309 | $out .= " <monthOffset>" . htmlspecialchars($job['month_offset']) . "</monthOffset>\n"; |
---|
310 | $out .= " <active>f</active>\n"; |
---|
311 | $out .= " <fileContents><![CDATA[" . file_get_contents($this->jobManager->getJobFile($job['job_id'])) . "]]></fileContents>\n"; |
---|
312 | $out .= " </job>\n"; |
---|
313 | } |
---|
314 | $out .= " </jobs>\n"; |
---|
315 | |
---|
316 | //export all resources |
---|
317 | $base_path = GALAXIA_PROCESSES . SEP . $wf_procname . SEP . 'resources'; |
---|
318 | $handle = opendir($base_path); |
---|
319 | $out.=' <resources>'."\n"; |
---|
320 | while (false !== ($name = readdir($handle))) |
---|
321 | { |
---|
322 | if (is_dir($base_path.SEP.$name)) |
---|
323 | continue; |
---|
324 | if (substr($name, -4) == ".swp") |
---|
325 | continue; |
---|
326 | $out.=' <resource>'."\n"; |
---|
327 | $out.=' <name>'.htmlspecialchars($name).'</name>'."\n"; |
---|
328 | //the code |
---|
329 | $out.=' <bindata><![CDATA['; |
---|
330 | $fp=fopen($base_path.SEP.$name,'r'); |
---|
331 | //while(!feof($fp)) { |
---|
332 | $line=fread($fp,filesize($base_path.SEP.$name)); |
---|
333 | $out.=chunk_split(base64_encode($line)); |
---|
334 | //} |
---|
335 | fclose($fp); |
---|
336 | $out.=' ]]></bindata>'; |
---|
337 | $out.=' </resource>'."\n"; |
---|
338 | } |
---|
339 | $out.=' </resources>'."\n"; |
---|
340 | |
---|
341 | |
---|
342 | $out.=' <transitions>'."\n"; |
---|
343 | //loop on transitions |
---|
344 | $transitions = $this->activity_manager->get_process_transitions($pId); |
---|
345 | foreach($transitions as $tran) { |
---|
346 | $out.=' <transition>'."\n"; |
---|
347 | $out.=' <from>'.htmlspecialchars($tran['wf_act_from_name']).'</from>'."\n"; |
---|
348 | $out.=' <to>'.htmlspecialchars($tran['wf_act_to_name']).'</to>'."\n"; |
---|
349 | $out.=' </transition>'."\n"; |
---|
350 | } |
---|
351 | $out.=' </transitions>'."\n"; |
---|
352 | $out.= '</process>'."\n"; |
---|
353 | |
---|
354 | //$fp = fopen(GALAXIA_PROCESSES."/$wf_procname/$wf_procname.xml","w"); |
---|
355 | //fwrite($fp,$out); |
---|
356 | //fclose($fp); |
---|
357 | return $out; |
---|
358 | } |
---|
359 | |
---|
360 | /** |
---|
361 | * Creates a process PHP data structure from its XML representation |
---|
362 | * |
---|
363 | * Unserialize process data |
---|
364 | * @access public |
---|
365 | * @return void |
---|
366 | */ |
---|
367 | function unserialize_process(&$xml) |
---|
368 | { |
---|
369 | // Create SAX parser assign this object as base for handlers |
---|
370 | // handlers are private methods defined below. |
---|
371 | // keep contexts and parse |
---|
372 | $this->parser = xml_parser_create("ISO-8859-1"); |
---|
373 | xml_parser_set_option($this->parser,XML_OPTION_CASE_FOLDING,0); |
---|
374 | //xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE, 1); |
---|
375 | xml_set_object($this->parser, $this); |
---|
376 | xml_set_element_handler($this->parser, '_start_element_handler', '_end_element_handler'); |
---|
377 | xml_set_character_data_handler($this->parser, '_data_handler'); |
---|
378 | |
---|
379 | $aux=Array( |
---|
380 | 'name'=>'root', |
---|
381 | 'children'=>Array(), |
---|
382 | 'parent' => 0, |
---|
383 | 'data'=>'', |
---|
384 | 'attribs' => Array(), |
---|
385 | ); |
---|
386 | |
---|
387 | $this->tree[0]=$aux; |
---|
388 | $this->current=0; |
---|
389 | |
---|
390 | if (!xml_parse($this->parser, $xml, true)) { |
---|
391 | $error = sprintf("XML error: %s at line %d", |
---|
392 | xml_error_string(xml_get_error_code($this->parser)), |
---|
393 | xml_get_current_line_number($this->parser)); |
---|
394 | trigger_error($error,E_USER_WARNING); |
---|
395 | $this->error[] = $error; |
---|
396 | } |
---|
397 | xml_parser_free($this->parser); |
---|
398 | // Now that we have the tree we can do interesting things |
---|
399 | |
---|
400 | $process=Array(); |
---|
401 | $activities=Array(); |
---|
402 | $transitions=Array(); |
---|
403 | $jobs = array(); |
---|
404 | for($i=0;$i<count($this->tree[1]['children']);$i++) { |
---|
405 | // Process attributes |
---|
406 | $z=$this->tree[1]['children'][$i]; |
---|
407 | $name = trim($this->tree[$z]['name']); |
---|
408 | |
---|
409 | //config values |
---|
410 | if ($name=='configs') { |
---|
411 | for($j=0;$j<count($this->tree[$z]['children']);$j++) { |
---|
412 | $z2 = $this->tree[$z]['children'][$j]; |
---|
413 | // this is a config $name = $this->tree[$z2]['name']; |
---|
414 | $aux = Array(); |
---|
415 | if($this->tree[$z2]['name']=='config') { |
---|
416 | for($k=0;$k<count($this->tree[$z2]['children']);$k++) { |
---|
417 | $z3 = $this->tree[$z2]['children'][$k]; |
---|
418 | $name = trim($this->tree[$z3]['name']); |
---|
419 | $value= trim($this->tree[$z3]['data']); |
---|
420 | $aux[$name]=$value; |
---|
421 | } |
---|
422 | $configs[]=$aux; |
---|
423 | } |
---|
424 | } |
---|
425 | } |
---|
426 | //activities |
---|
427 | elseif($name=='activities') { |
---|
428 | for($j=0;$j<count($this->tree[$z]['children']);$j++) { |
---|
429 | $z2 = $this->tree[$z]['children'][$j]; |
---|
430 | // this is an activity $name = $this->tree[$z2]['name']; |
---|
431 | $aux = Array(); |
---|
432 | if($this->tree[$z2]['name']=='activity') { |
---|
433 | for($k=0;$k<count($this->tree[$z2]['children']);$k++) { |
---|
434 | $z3 = $this->tree[$z2]['children'][$k]; |
---|
435 | $name = trim($this->tree[$z3]['name']); |
---|
436 | $value= trim($this->tree[$z3]['data']); |
---|
437 | if($name=='roles') { |
---|
438 | $roles=Array(); |
---|
439 | for($l=0;$l<count($this->tree[$z3]['children']);$l++) { |
---|
440 | $z4 = $this->tree[$z3]['children'][$l]; |
---|
441 | $name = trim($this->tree[$z4]['name']); |
---|
442 | $data = trim($this->tree[$z4]['data']); |
---|
443 | $attribs = $this->tree[$z4]['attribs']; |
---|
444 | $readonly = false; |
---|
445 | if ( (isset($attribs['readonly'])) && ($attribs['readonly'])) |
---|
446 | { |
---|
447 | //role in read-only |
---|
448 | $readonly = true; |
---|
449 | } |
---|
450 | $roles[]=array( |
---|
451 | 'name' => $data, |
---|
452 | 'readonly' => $readonly, |
---|
453 | ); |
---|
454 | } |
---|
455 | } |
---|
456 | elseif ($name=='agents') |
---|
457 | { |
---|
458 | $agents=Array(); |
---|
459 | for($l=0;$l<count($this->tree[$z3]['children']);$l++) |
---|
460 | { |
---|
461 | $z4 = $this->tree[$z3]['children'][$l]; |
---|
462 | //$name is agent |
---|
463 | $name = trim($this->tree[$z4]['name']); |
---|
464 | if ($name = 'agent') |
---|
465 | { |
---|
466 | $agent = array(); |
---|
467 | for($m=0;$m<count($this->tree[$z4]['children']);$m++) |
---|
468 | { |
---|
469 | $z5 = $this->tree[$z4]['children'][$m]; |
---|
470 | //$name is agent_type or agent_datas |
---|
471 | $name = trim($this->tree[$z5]['name']); |
---|
472 | // data will be the agent_type or an array for agent_datas |
---|
473 | $data = trim($this->tree[$z5]['data']); |
---|
474 | if ($name=='agent_type') |
---|
475 | { |
---|
476 | $agent['wf_agent_type']=$data; |
---|
477 | } |
---|
478 | elseif ($name=='agent_datas') |
---|
479 | { |
---|
480 | for($n=0;$n<count($this->tree[$z5]['children']);$n++) |
---|
481 | { |
---|
482 | $z6 = $this->tree[$z5]['children'][$n]; |
---|
483 | //$name is agent_data $val is an array |
---|
484 | $name = trim($this->tree[$z6]['name']); |
---|
485 | $val = trim($this->tree[$z6]['data']); |
---|
486 | if ($name=='agent_data') |
---|
487 | { |
---|
488 | for($o=0;$o<count($this->tree[$z6]['children']);$o++) |
---|
489 | { |
---|
490 | $z7 = $this->tree[$z6]['children'][$o]; |
---|
491 | //$name is agent_data $val is 'name' or 'value' |
---|
492 | $name = trim($this->tree[$z7]['name']); |
---|
493 | $content = trim($this->tree[$z7]['data']); |
---|
494 | //echo "<br>z7 name $name content: $content"; |
---|
495 | if ($name=='name') |
---|
496 | { |
---|
497 | $agent_data_name = $content; |
---|
498 | } |
---|
499 | elseif ($name=='value') |
---|
500 | { |
---|
501 | $agent_data_value =& $content; |
---|
502 | } |
---|
503 | } |
---|
504 | //echo "<br>associate $agent_data_name to $agent_data_value <hr>"; |
---|
505 | $agent[$agent_data_name] = $agent_data_value; |
---|
506 | } |
---|
507 | } |
---|
508 | } |
---|
509 | } |
---|
510 | $agents[]=$agent; |
---|
511 | } |
---|
512 | } |
---|
513 | } else { |
---|
514 | $aux[$name]=$value; |
---|
515 | //print("$name:$value<br/>"); |
---|
516 | } |
---|
517 | } |
---|
518 | $aux['agents']=$agents; |
---|
519 | $aux['roles']=$roles; |
---|
520 | $activities[]=$aux; |
---|
521 | } |
---|
522 | } |
---|
523 | } elseif($name=='transitions') { |
---|
524 | for($j=0;$j<count($this->tree[$z]['children']);$j++) { |
---|
525 | $z2 = $this->tree[$z]['children'][$j]; |
---|
526 | // this is an activity $name = $this->tree[$z2]['name']; |
---|
527 | $aux=Array(); |
---|
528 | if($this->tree[$z2]['name']=='transition') { |
---|
529 | for($k=0;$k<count($this->tree[$z2]['children']);$k++) { |
---|
530 | $z3 = $this->tree[$z2]['children'][$k]; |
---|
531 | $name = trim($this->tree[$z3]['name']); |
---|
532 | $value= trim($this->tree[$z3]['data']); |
---|
533 | if($name == 'from' || $name == 'to') { |
---|
534 | $aux[$name]=$value; |
---|
535 | } |
---|
536 | } |
---|
537 | } |
---|
538 | $transitions[] = $aux; |
---|
539 | } |
---|
540 | } elseif($name=='includes') { |
---|
541 | for($j=0;$j<count($this->tree[$z]['children']);$j++) { |
---|
542 | $z2 = $this->tree[$z]['children'][$j]; |
---|
543 | // this is an activity $name = $this->tree[$z2]['name']; |
---|
544 | $aux=Array(); |
---|
545 | if($this->tree[$z2]['name']=='include') { |
---|
546 | for($k=0;$k<count($this->tree[$z2]['children']);$k++) { |
---|
547 | $z3 = $this->tree[$z2]['children'][$k]; |
---|
548 | $name = trim($this->tree[$z3]['name']); |
---|
549 | $value= trim($this->tree[$z3]['data']); |
---|
550 | $aux[$name]=$value; |
---|
551 | } |
---|
552 | } |
---|
553 | $includes[] = $aux; |
---|
554 | } |
---|
555 | } elseif($name=='templates') { |
---|
556 | for($j=0;$j<count($this->tree[$z]['children']);$j++) { |
---|
557 | $z2 = $this->tree[$z]['children'][$j]; |
---|
558 | // this is an activity $name = $this->tree[$z2]['name']; |
---|
559 | $aux=Array(); |
---|
560 | if($this->tree[$z2]['name']=='template') { |
---|
561 | for($k=0;$k<count($this->tree[$z2]['children']);$k++) { |
---|
562 | $z3 = $this->tree[$z2]['children'][$k]; |
---|
563 | $name = trim($this->tree[$z3]['name']); |
---|
564 | $value= trim($this->tree[$z3]['data']); |
---|
565 | $aux[$name]=$value; |
---|
566 | } |
---|
567 | } |
---|
568 | $templates[] = $aux; |
---|
569 | } |
---|
570 | } elseif($name=='resources') { |
---|
571 | for($j=0;$j<count($this->tree[$z]['children']);$j++) { |
---|
572 | $z2 = $this->tree[$z]['children'][$j]; |
---|
573 | // this is an activity $name = $this->tree[$z2]['name']; |
---|
574 | $aux=Array(); |
---|
575 | if($this->tree[$z2]['name']=='resource') { |
---|
576 | for($k=0;$k<count($this->tree[$z2]['children']);$k++) { |
---|
577 | $z3 = $this->tree[$z2]['children'][$k]; |
---|
578 | $name = trim($this->tree[$z3]['name']); |
---|
579 | $value= trim($this->tree[$z3]['data']); |
---|
580 | $aux[$name]=$value; |
---|
581 | } |
---|
582 | } |
---|
583 | $resources[] = $aux; |
---|
584 | } |
---|
585 | } |
---|
586 | elseif ($name == 'jobs') |
---|
587 | { |
---|
588 | for ($j = 0; $j < count($this->tree[$z]['children']); $j++) |
---|
589 | { |
---|
590 | $job = array(); |
---|
591 | $jobIndex = $this->tree[$z]['children'][$j]; |
---|
592 | if($this->tree[$jobIndex]['name'] == 'job') |
---|
593 | { |
---|
594 | for ($k = 0; $k < count($this->tree[$jobIndex]['children']); $k++) |
---|
595 | { |
---|
596 | $propertyIndex = $this->tree[$jobIndex]['children'][$k]; |
---|
597 | $job[trim($this->tree[$propertyIndex]['name'])] = trim($this->tree[$propertyIndex]['data']); |
---|
598 | } |
---|
599 | } |
---|
600 | $jobs[] = $job; |
---|
601 | } |
---|
602 | } |
---|
603 | else { |
---|
604 | $value = trim($this->tree[$z]['data']); |
---|
605 | //print("$name is $value<br/>"); |
---|
606 | $process[$name]=$value; |
---|
607 | } |
---|
608 | } |
---|
609 | |
---|
610 | $process['configs'] = $configs; |
---|
611 | $process['activities'] = $activities; |
---|
612 | $process['transitions'] = $transitions; |
---|
613 | $process['resources'] = $resources; |
---|
614 | $process['includes'] = $includes; |
---|
615 | $process['templates'] = $templates; |
---|
616 | $process['jobs'] = $jobs; |
---|
617 | |
---|
618 | return $process; |
---|
619 | } |
---|
620 | |
---|
621 | /** |
---|
622 | * Creates a new process PHP data structure from its XML representation |
---|
623 | * unserial |
---|
624 | * @access public |
---|
625 | * @return void |
---|
626 | */ |
---|
627 | function new_process_version($pId, $minor=true) |
---|
628 | { |
---|
629 | $new_id = parent::new_process_version($pId,$minor); |
---|
630 | |
---|
631 | //copy resource dir too |
---|
632 | $old_name = GALAXIA_PROCESSES . SEP . $this->_get_normalized_name($pId) . SEP . 'resources'; |
---|
633 | $new_name = GALAXIA_PROCESSES . SEP . $this->_get_normalized_name($new_id) . SEP . 'resources'; |
---|
634 | if (is_dir($old_name)) |
---|
635 | $this->_rec_copy($old_name,$new_name); |
---|
636 | |
---|
637 | $this->workflow_acl->add_process_admins($new_id, array( $GLOBALS['phpgw_info']['user']['account_id'] )); |
---|
638 | |
---|
639 | return $new_id; |
---|
640 | } |
---|
641 | /** |
---|
642 | * Remove process |
---|
643 | * @param int $pId process id |
---|
644 | * @access public |
---|
645 | * @return string |
---|
646 | */ |
---|
647 | function remove_process($pId) |
---|
648 | { |
---|
649 | $result = parent::remove_process($pId); |
---|
650 | $this->workflow_acl->del_process($pId); |
---|
651 | return $result; |
---|
652 | } |
---|
653 | /** |
---|
654 | * Replace_process |
---|
655 | * |
---|
656 | * @param int $pid process id |
---|
657 | * @param array $vars |
---|
658 | * @param boolean $create |
---|
659 | * |
---|
660 | * @access public |
---|
661 | * @return int new id |
---|
662 | */ |
---|
663 | function replace_process($pId, &$vars, $create = true) |
---|
664 | { |
---|
665 | $id = parent::replace_process($pId, $vars, $create); |
---|
666 | |
---|
667 | if (!$pId) |
---|
668 | { |
---|
669 | $this->workflow_acl->add_process_admins($id, array( $GLOBALS['phpgw_info']['user']['account_id'] ) ); |
---|
670 | } |
---|
671 | |
---|
672 | return $id; |
---|
673 | } |
---|
674 | } |
---|
675 | ?> |
---|