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