source: trunk/workflow/inc/class.workflow_processmanager.inc.php @ 7655

Revision 7655, 23.0 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Melhorias de performance no codigo do Expresso.

  • Property svn:executable set to *
Line 
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            $tree_count = count($this->tree[1]['children']);
393                        for($i=0;$i<$tree_count;++$i) {
394                          // Process attributes
395                          $z=$this->tree[1]['children'][$i];
396                          $name = trim($this->tree[$z]['name']);
397                         
398                          //config values
399                          if ($name=='configs') {
400                $tree_z_count = count($this->tree[$z]['children']);
401                                for($j=0;$j<$tree_z_count;++$j) {
402                                  $z2 = $this->tree[$z]['children'][$j];
403                                  // this is a config $name = $this->tree[$z2]['name'];
404                                  $aux = Array();
405                                  if($this->tree[$z2]['name']=='config') {
406                    $tree_z_count = count($this->tree[$z2]['children']);
407                                        for($k=0;$k<$tree_z_count;++$k) {
408                                          $z3 = $this->tree[$z2]['children'][$k];
409                                          $name = trim($this->tree[$z3]['name']);
410                                          $value= trim($this->tree[$z3]['data']);
411                                          $aux[$name]=$value;
412                                        }
413                                        $configs[]=$aux;
414                                  }
415                                }     
416                          }
417                          //activities
418                          elseif($name=='activities') {
419                $tree_z_count = count($this->tree[$z]['children']);
420                                for($j=0;$j<$tree_z_count;++$j) {
421                                  $z2 = $this->tree[$z]['children'][$j];
422                                  // this is an activity $name = $this->tree[$z2]['name'];
423                                  $aux = Array();
424                                  if($this->tree[$z2]['name']=='activity') {
425                    $tree_z2_count = count($this->tree[$z2]['children']);
426                                        for($k=0;$k<$tree_z2_count;++$k) {
427                                          $z3 = $this->tree[$z2]['children'][$k];
428                                          $name = trim($this->tree[$z3]['name']);
429                                          $value= trim($this->tree[$z3]['data']);
430                                          if($name=='roles') {
431                                                $roles=Array();
432                        $tree_z3_count = count($this->tree[$z3]['children']);
433                                                for($l=0;$l<$tree_z3_count;++$l) {
434                                                  $z4 = $this->tree[$z3]['children'][$l];
435                                                  $name = trim($this->tree[$z4]['name']);
436                                                  $data = trim($this->tree[$z4]['data']);
437                                                  $attribs = $this->tree[$z4]['attribs'];
438                                                  $readonly = false;
439                                                  if ( (isset($attribs['readonly'])) && ($attribs['readonly']))
440                                                  {
441                                                        //role in read-only
442                                                        $readonly = true;
443                                                  }
444                                                  $roles[]=array(
445                                                        'name'  => $data,
446                                                        'readonly'      => $readonly,
447                                                  );
448                                                }
449                                          }
450                                          elseif ($name=='agents')
451                                          {
452                                                $agents=Array();
453                        $tree_z3_count = count($this->tree[$z3]['children']);
454                                                for($l=0;$l<$tree_z3_count;++$l)
455                                                {
456                                                  $z4 = $this->tree[$z3]['children'][$l];
457                                                  //$name is agent
458                                                  $name = trim($this->tree[$z4]['name']);
459                                                  if ($name = 'agent')
460                                                  {
461                                                        $agent = array();
462                            $tree_z4_count = count($this->tree[$z4]['children']);
463                                                        for($m=0;$m<$tree_z4_count;++$m)
464                                                        {
465                                                          $z5 = $this->tree[$z4]['children'][$m];
466                                                          //$name is agent_type or agent_datas
467                                                          $name = trim($this->tree[$z5]['name']);
468                                                          // data will be the agent_type or an array for agent_datas
469                                                          $data = trim($this->tree[$z5]['data']);
470                                                          if ($name=='agent_type')
471                                                          {
472                                                                $agent['wf_agent_type']=$data;
473                                                          }
474                                                          elseif ($name=='agent_datas')
475                                                          {
476                                $tree_z5_count = count($this->tree[$z5]['children']);
477                                                                for($n=0;$n<$tree_z5_count;++$n)
478                                                                {
479                                                                  $z6 = $this->tree[$z5]['children'][$n];
480                                                                  //$name is agent_data $val is an array
481                                                                  $name = trim($this->tree[$z6]['name']);
482                                                                  $val = trim($this->tree[$z6]['data']);
483                                                                  if ($name=='agent_data')
484                                                                  {
485                                    $tree_z6_count = count($this->tree[$z6]['children']);
486                                                                        for($o=0;$o<$tree_z6_count;++$o)
487                                                                        {
488                                                                          $z7 = $this->tree[$z6]['children'][$o];
489                                                                          //$name is agent_data $val is 'name' or 'value'
490                                                                          $name = trim($this->tree[$z7]['name']);
491                                                                          $content = trim($this->tree[$z7]['data']);
492                                                                          //echo "<br>z7 name $name content: $content";
493                                                                          if ($name=='name')
494                                                                          {
495                                                                                $agent_data_name = $content;
496                                                                          }
497                                                                          elseif ($name=='value')
498                                                                          {
499                                                                                $agent_data_value =& $content;
500                                                                          }
501                                                                        }
502                                                                        //echo "<br>associate $agent_data_name to $agent_data_value <hr>";
503                                                                        $agent[$agent_data_name] = $agent_data_value;
504                                                                  }
505                                                                }
506                                                          }
507                                                        }
508                                                        $agents[]=$agent;
509                                                  }
510                                                }
511                                          } else {
512                                                $aux[$name]=$value;
513                                                //print("$name:$value<br/>");
514                                          }
515                                        }
516                                        $aux['agents']=$agents;
517                                        $aux['roles']=$roles;
518                                        $activities[]=$aux;
519                                  }
520                                }
521                          } elseif($name=='transitions') {
522                $tree_z_count = count($this->tree[$z]['children']);
523                                for($j=0;$j<$tree_z_count;++$j) {
524                                  $z2 = $this->tree[$z]['children'][$j];
525                                  // this is an activity $name = $this->tree[$z2]['name'];
526                                  $aux=Array();
527                                  if($this->tree[$z2]['name']=='transition') {
528                    $tree_z2_count = count($this->tree[$z2]['children']);
529                                        for($k=0;$k<$tree_z2_count;++$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                $tree_z_count = count($this->tree[$z]['children']);
542                                for($j=0;$j<$tree_z_count;++$j) {
543                                  $z2 = $this->tree[$z]['children'][$j];
544                                  // this is an activity $name = $this->tree[$z2]['name'];
545                                  $aux=Array();
546                                  if($this->tree[$z2]['name']=='include') {
547                    $tree_z2_count = count($this->tree[$z2]['children']);
548                                        for($k=0;$k<$tree_z2_count;++$k) {
549                                          $z3 = $this->tree[$z2]['children'][$k];
550                                          $name = trim($this->tree[$z3]['name']);
551                                          $value= trim($this->tree[$z3]['data']);
552                                          $aux[$name]=$value;
553                                        }
554                                  }
555                                  $includes[] = $aux;
556                                }
557                          } elseif($name=='templates') {
558                $tree_z_count = count($this->tree[$z]['children']);
559                                for($j=0;$j<$tree_z_count;++$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']=='template') {
564                    $tree_z2_count = count($this->tree[$z2]['children']);
565                                        for($k=0;$k<$tree_z2_count;++$k) {
566                                          $z3 = $this->tree[$z2]['children'][$k];
567                                          $name = trim($this->tree[$z3]['name']);
568                                          $value= trim($this->tree[$z3]['data']);
569                                          $aux[$name]=$value;
570                                        }
571                                  }
572                                  $templates[] = $aux;
573                                }
574                          } elseif($name=='resources') {
575                $tree_z_count = count($this->tree[$z]['children']);
576                                for($j=0;$j<$tree_z_count;++$j) {
577                                  $z2 = $this->tree[$z]['children'][$j];
578                                  // this is an activity $name = $this->tree[$z2]['name'];
579                                  $aux=Array();
580                                  if($this->tree[$z2]['name']=='resource') {
581                    $tree_z2_count = count($this->tree[$z2]['children']);
582                                        for($k=0;$k<$tree_z2_count;++$k) {
583                                          $z3 = $this->tree[$z2]['children'][$k];
584                                          $name = trim($this->tree[$z3]['name']);
585                                          $value= trim($this->tree[$z3]['data']);
586                                          $aux[$name]=$value;
587                                        }
588                                  }
589                                  $resources[] = $aux;
590                                }
591                          }
592                          elseif ($name == 'jobs'){
593                  $tree_z_count = count($this->tree[$z]['children']);
594                  for ($j = 0; $j < $tree_z_count; ++$j)
595                  {
596                    $job = array();
597                            $jobIndex = $this->tree[$z]['children'][$j];
598                    if($this->tree[$jobIndex]['name'] == 'job')
599                    {
600                      $tree_jobIndex_count = count($this->tree[$jobIndex]['children']);
601                      for ($k = 0; $k < $tree_jobIndex_count; ++$k)
602                      {
603                        $propertyIndex = $this->tree[$jobIndex]['children'][$k];
604                        $job[trim($this->tree[$propertyIndex]['name'])] = trim($this->tree[$propertyIndex]['data']);
605                      }
606                    }
607                    $jobs[] = $job;
608                  }
609                          }
610                          else {
611                                $value = trim($this->tree[$z]['data']);
612                                //print("$name is $value<br/>");
613                                $process[$name]=$value;
614                          }
615                        }
616
617                        $process['configs']             = $configs;
618                        $process['activities']  = $activities;
619                        $process['transitions'] = $transitions;
620                        $process['resources']   = $resources;
621                        $process['includes']    = $includes;
622                        $process['templates']   = $templates;
623                        $process['jobs']        = $jobs;
624
625                        return $process;
626                  }
627                 
628                /**
629                 * Creates a new process PHP data structure from its XML representation
630                 * unserial
631                 * @access public
632                 * @return void
633                 */
634                  function new_process_version($pId, $minor=true)
635                  {
636                         $new_id = parent::new_process_version($pId,$minor);
637
638                         //copy resource dir too
639                         $old_name = GALAXIA_PROCESSES . SEP . $this->_get_normalized_name($pId) . SEP . 'resources';
640                         $new_name = GALAXIA_PROCESSES . SEP . $this->_get_normalized_name($new_id) . SEP . 'resources';
641                         if (is_dir($old_name))
642                                $this->_rec_copy($old_name,$new_name);
643
644                         $this->workflow_acl->add_process_admins($new_id, array( $GLOBALS['phpgw_info']['user']['account_id'] ));
645
646                         return $new_id;
647                  }
648                /**
649                 * Remove process
650                 * @param int $pId process id
651                 * @access public
652                 * @return string
653                 */
654                  function remove_process($pId)
655                  {
656                        $result = parent::remove_process($pId);
657                        $this->workflow_acl->del_process($pId);
658                        return $result;
659                  }
660                /**
661                 * Replace_process
662                 *
663                 * @param int      $pid     process id
664                 * @param array    $vars
665                 * @param boolean  $create
666                 *   
667                 * @access public
668                 * @return int new id
669                 */
670                  function replace_process($pId, &$vars, $create = true)
671          {
672            $id = parent::replace_process($pId, $vars, $create);
673
674            if (!$pId)
675            {
676                                $this->workflow_acl->add_process_admins($id, array( $GLOBALS['phpgw_info']['user']['account_id'] ) );
677            }
678
679                        return $id;
680          }     
681        }
682?>
Note: See TracBrowser for help on using the repository browser.