source: sandbox/workflow/trunk/inc/class.workflow_processmanager.inc.php @ 2372

Revision 2372, 22.2 KB checked in by pedroerp, 14 years ago (diff)

Ticket #609 - Merged 2197:2356 /sandbox/workflow/branches/609/ em /sandbox/workflow/trunk.

  • 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                          if($res['wf_is_interactive']=='y') {
229                                $out.='      <template><![CDATA[';
230                                $fp=fopen(GALAXIA_PROCESSES.SEP."$wf_procname".SEP."code".SEP."templates".SEP."$name.tpl","r");
231                                //while(!feof($fp)) {
232                                //      $line=fread($fp,8192);
233                                        $out.=''; //all templatess will be exported in another section
234                                //}
235                                fclose($fp);
236                                $out.='      ]]></template>';
237                          }
238                          $out.='    </activity>'."\n";   
239                        }
240                        $out.='  </activities>'."\n";
241                       
242                        //export all templates
243                        $base_path = GALAXIA_PROCESSES.SEP.$wf_procname.SEP.'code'.SEP.'templates';     
244                        $handle = opendir($base_path);
245                        $out.='  <templates>'."\n";
246                        while (false !== ($name = readdir($handle)))
247                        {
248                                if (is_dir($base_path.SEP.$name))
249                                        continue;
250                                if (substr($name, -4) != ".tpl")
251                                        continue;
252                                $out.='    <template>'."\n";
253                                $out.='      <name>'.htmlspecialchars($name).'</name>'."\n";
254                                //the code
255                                $out.='      <code><![CDATA[';
256                                $fp=fopen($base_path.SEP.$name,'r');
257                                while(!feof($fp)) {
258                                        $line=fread($fp,8192);
259                                        $out.=$line;
260                                }
261                                fclose($fp);
262                                $out.='      ]]></code>';
263                                $out.='    </template>'."\n";   
264                        }
265                        $out.='  </templates>'."\n";
266
267                        //export all includes
268                        $base_path = GALAXIA_PROCESSES.SEP.$wf_procname.SEP.'code';     
269                        $handle = opendir($base_path);
270                        $out.='  <includes>'."\n";
271                        while (false !== ($name = readdir($handle)))
272                        {
273                                if (is_dir($base_path.SEP.$name)) /* ignore directories */
274                                        continue;
275                                if ($name == 'shared.php') /* shared.php was saved before */
276                                        continue;
277                                if (substr($name, -4) != ".php")
278                                        continue;
279                                $out.='    <include>'."\n";
280                                $out.='      <name>'.htmlspecialchars($name).'</name>'."\n";
281                                //the code
282                                $out.='      <code><![CDATA[';
283                                $fp=fopen($base_path.SEP.$name,'r');
284                                while(!feof($fp))
285                                {
286                                        $line=fread($fp,8192);
287                                        $out.=$line;
288                                }
289                                fclose($fp);
290                                $out.='      ]]></code>';
291                                $out.='    </include>'."\n";   
292                        }
293                        $out.='  </includes>'."\n";
294
295                        $jobList = $this->jobManager->getJobsByProcessID($pId);
296                        $out .= "  <jobs>\n";
297                        foreach ($jobList as $job)
298                        {
299                                $out .= "    <job>\n";
300                                $out .= "      <name>" . htmlspecialchars($job['name']) . "</name>\n";
301                                $out .= "      <description>" . htmlspecialchars($job['description']) . "</description>\n";
302                                $out .= "      <timeStart>" . htmlspecialchars($job['time_start']) . "</timeStart>\n";
303                                $out .= "      <intervalValue>" . htmlspecialchars($job['interval_value']) . "</intervalValue>\n";
304                                $out .= "      <intervalUnity>" . htmlspecialchars($job['interval_unity']) . "</intervalUnity>\n";
305                                $out .= "      <dateType>" . htmlspecialchars($job['date_type']) . "</dateType>\n";
306                                $out .= "      <weekDays>" . htmlspecialchars($job['week_days']) . "</weekDays>\n";
307                                $out .= "      <monthOffset>" . htmlspecialchars($job['month_offset']) . "</monthOffset>\n";
308                                $out .= "      <active>f</active>\n";
309                                $out .= "      <fileContents><![CDATA[" . file_get_contents($this->jobManager->getJobFile($job['job_id'])) . "]]></fileContents>\n";
310                                $out .= "    </job>\n";
311                        }
312                        $out .= "  </jobs>\n";
313
314                        //export all resources
315                        $base_path = GALAXIA_PROCESSES . SEP . $wf_procname . SEP . 'resources';
316                        $handle = opendir($base_path);
317                        $out.='  <resources>'."\n";
318                        while (false !== ($name = readdir($handle)))
319                        {
320                                if (is_dir($base_path.SEP.$name))
321                                        continue;
322                                if (substr($name, -4) == ".swp")
323                                        continue;
324                                $out.='    <resource>'."\n";
325                                $out.='      <name>'.htmlspecialchars($name).'</name>'."\n";
326                                //the code
327                                $out.='      <bindata><![CDATA[';
328                                $fp=fopen($base_path.SEP.$name,'r');
329                                //while(!feof($fp)) {
330                                $line=fread($fp,filesize($base_path.SEP.$name));
331                                $out.=chunk_split(base64_encode($line));
332                                //}
333                                fclose($fp);
334                                $out.=' ]]></bindata>';
335                                $out.='    </resource>'."\n";
336                        }
337                        $out.='  </resources>'."\n";
338
339
340                        $out.='  <transitions>'."\n";
341                        //loop on transitions
342                        $transitions = $this->activity_manager->get_process_transitions($pId);
343                        foreach($transitions as $tran) {
344                          $out.='     <transition>'."\n";
345                          $out.='       <from>'.htmlspecialchars($tran['wf_act_from_name']).'</from>'."\n";
346                          $out.='       <to>'.htmlspecialchars($tran['wf_act_to_name']).'</to>'."\n";
347                          $out.='     </transition>'."\n";
348                        }     
349                        $out.='  </transitions>'."\n";
350                        $out.= '</process>'."\n";
351                       
352                        //$fp = fopen(GALAXIA_PROCESSES."/$wf_procname/$wf_procname.xml","w");
353                        //fwrite($fp,$out);
354                        //fclose($fp);
355                        return $out;
356                }
357
358                /**
359                 * Creates  a process PHP data structure from its XML representation
360                 *
361                 * Unserialize process data 
362                 * @access public
363                 * @return void
364                 */
365                function unserialize_process(&$xml)
366                {
367                        // Create SAX parser assign this object as base for handlers
368                        // handlers are private methods defined below.
369                        // keep contexts and parse
370                        $this->parser = xml_parser_create("ISO-8859-1");
371                        xml_parser_set_option($this->parser,XML_OPTION_CASE_FOLDING,0);
372                        //xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE, 1);
373                        xml_set_object($this->parser, $this);
374                        xml_set_element_handler($this->parser, '_start_element_handler', '_end_element_handler');
375                        xml_set_character_data_handler($this->parser, '_data_handler');
376                         
377                        $aux=Array(
378                          'name'=>'root',
379                          'children'=>Array(),
380                          'parent' => 0,
381                          'data'=>'',
382                          'attribs'     => Array(),
383                        );
384                       
385                        $this->tree[0]=$aux;
386                        $this->current=0;
387                       
388                        if (!xml_parse($this->parser, $xml, true)) {
389                           $error = sprintf("XML error: %s at line %d",
390                                                        xml_error_string(xml_get_error_code($this->parser)),
391                                                        xml_get_current_line_number($this->parser));
392                           trigger_error($error,E_USER_WARNING);
393                           $this->error[] = $error;
394                        }
395                        xml_parser_free($this->parser);   
396                        // Now that we have the tree we can do interesting things
397                       
398                        $process=Array();
399                        $activities=Array();
400                        $transitions=Array();
401                        $jobs = array();
402                        for($i=0;$i<count($this->tree[1]['children']);$i++) {
403                          // Process attributes
404                          $z=$this->tree[1]['children'][$i];
405                          $name = trim($this->tree[$z]['name']);
406                         
407                          //config values
408                          if ($name=='configs') {
409                                for($j=0;$j<count($this->tree[$z]['children']);$j++) {
410                                  $z2 = $this->tree[$z]['children'][$j];
411                                  // this is a config $name = $this->tree[$z2]['name'];
412                                  $aux = Array();
413                                  if($this->tree[$z2]['name']=='config') {
414                                        for($k=0;$k<count($this->tree[$z2]['children']);$k++) {
415                                          $z3 = $this->tree[$z2]['children'][$k];
416                                          $name = trim($this->tree[$z3]['name']);
417                                          $value= trim($this->tree[$z3]['data']);
418                                          $aux[$name]=$value;
419                                        }
420                                        $configs[]=$aux;
421                                  }
422                                }     
423                          }
424                          //activities
425                          elseif($name=='activities') {
426                                for($j=0;$j<count($this->tree[$z]['children']);$j++) {
427                                  $z2 = $this->tree[$z]['children'][$j];
428                                  // this is an activity $name = $this->tree[$z2]['name'];
429                                  $aux = Array();
430                                  if($this->tree[$z2]['name']=='activity') {
431                                        for($k=0;$k<count($this->tree[$z2]['children']);$k++) {
432                                          $z3 = $this->tree[$z2]['children'][$k];
433                                          $name = trim($this->tree[$z3]['name']);
434                                          $value= trim($this->tree[$z3]['data']);
435                                          if($name=='roles') {
436                                                $roles=Array();
437                                                for($l=0;$l<count($this->tree[$z3]['children']);$l++) {
438                                                  $z4 = $this->tree[$z3]['children'][$l];
439                                                  $name = trim($this->tree[$z4]['name']);
440                                                  $data = trim($this->tree[$z4]['data']);
441                                                  $attribs = $this->tree[$z4]['attribs'];
442                                                  $readonly = false;
443                                                  if ( (isset($attribs['readonly'])) && ($attribs['readonly']))
444                                                  {
445                                                        //role in read-only
446                                                        $readonly = true;
447                                                  }
448                                                  $roles[]=array(
449                                                        'name'  => $data,
450                                                        'readonly'      => $readonly,
451                                                  );
452                                                }
453                                          }
454                                          elseif ($name=='agents')
455                                          {
456                                                $agents=Array();
457                                                for($l=0;$l<count($this->tree[$z3]['children']);$l++)
458                                                {
459                                                  $z4 = $this->tree[$z3]['children'][$l];
460                                                  //$name is agent
461                                                  $name = trim($this->tree[$z4]['name']);
462                                                  if ($name = 'agent')
463                                                  {
464                                                        $agent = array();
465                                                        for($m=0;$m<count($this->tree[$z4]['children']);$m++)
466                                                        {
467                                                          $z5 = $this->tree[$z4]['children'][$m];
468                                                          //$name is agent_type or agent_datas
469                                                          $name = trim($this->tree[$z5]['name']);
470                                                          // data will be the agent_type or an array for agent_datas
471                                                          $data = trim($this->tree[$z5]['data']);
472                                                          if ($name=='agent_type')
473                                                          {
474                                                                $agent['wf_agent_type']=$data;
475                                                          }
476                                                          elseif ($name=='agent_datas')
477                                                          {
478                                                                for($n=0;$n<count($this->tree[$z5]['children']);$n++)
479                                                                {
480                                                                  $z6 = $this->tree[$z5]['children'][$n];
481                                                                  //$name is agent_data $val is an array
482                                                                  $name = trim($this->tree[$z6]['name']);
483                                                                  $val = trim($this->tree[$z6]['data']);
484                                                                  if ($name=='agent_data')
485                                                                  {
486                                                                        for($o=0;$o<count($this->tree[$z6]['children']);$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                                for($j=0;$j<count($this->tree[$z]['children']);$j++) {
523                                  $z2 = $this->tree[$z]['children'][$j];
524                                  // this is an activity $name = $this->tree[$z2]['name'];
525                                  $aux=Array();
526                                  if($this->tree[$z2]['name']=='transition') {
527                                        for($k=0;$k<count($this->tree[$z2]['children']);$k++) {
528                                          $z3 = $this->tree[$z2]['children'][$k];
529                                          $name = trim($this->tree[$z3]['name']);
530                                          $value= trim($this->tree[$z3]['data']);
531                                          if($name == 'from' || $name == 'to') {
532                                                $aux[$name]=$value;
533                                          }
534                                        }
535                                  }
536                                  $transitions[] = $aux;
537                                }
538                          } elseif($name=='includes') {
539                                for($j=0;$j<count($this->tree[$z]['children']);$j++) {
540                                  $z2 = $this->tree[$z]['children'][$j];
541                                  // this is an activity $name = $this->tree[$z2]['name'];
542                                  $aux=Array();
543                                  if($this->tree[$z2]['name']=='include') {
544                                        for($k=0;$k<count($this->tree[$z2]['children']);$k++) {
545                                          $z3 = $this->tree[$z2]['children'][$k];
546                                          $name = trim($this->tree[$z3]['name']);
547                                          $value= trim($this->tree[$z3]['data']);
548                                          $aux[$name]=$value;
549                                        }
550                                  }
551                                  $includes[] = $aux;
552                                }
553                          } elseif($name=='templates') {
554                                for($j=0;$j<count($this->tree[$z]['children']);$j++) {
555                                  $z2 = $this->tree[$z]['children'][$j];
556                                  // this is an activity $name = $this->tree[$z2]['name'];
557                                  $aux=Array();
558                                  if($this->tree[$z2]['name']=='template') {
559                                        for($k=0;$k<count($this->tree[$z2]['children']);$k++) {
560                                          $z3 = $this->tree[$z2]['children'][$k];
561                                          $name = trim($this->tree[$z3]['name']);
562                                          $value= trim($this->tree[$z3]['data']);
563                                          $aux[$name]=$value;
564                                        }
565                                  }
566                                  $templates[] = $aux;
567                                }
568                          } elseif($name=='resources') {
569                                for($j=0;$j<count($this->tree[$z]['children']);$j++) {
570                                  $z2 = $this->tree[$z]['children'][$j];
571                                  // this is an activity $name = $this->tree[$z2]['name'];
572                                  $aux=Array();
573                                  if($this->tree[$z2]['name']=='resource') {
574                                        for($k=0;$k<count($this->tree[$z2]['children']);$k++) {
575                                          $z3 = $this->tree[$z2]['children'][$k];
576                                          $name = trim($this->tree[$z3]['name']);
577                                          $value= trim($this->tree[$z3]['data']);
578                                          $aux[$name]=$value;
579                                        }
580                                  }
581                                  $resources[] = $aux;
582                                }
583                          }
584                          elseif ($name == 'jobs')
585                          {
586          for ($j = 0; $j < count($this->tree[$z]['children']); $j++)
587          {
588            $job = array();
589                                    $jobIndex = $this->tree[$z]['children'][$j];
590            if($this->tree[$jobIndex]['name'] == 'job')
591            {
592              for ($k = 0; $k < count($this->tree[$jobIndex]['children']); $k++)
593              {
594                $propertyIndex = $this->tree[$jobIndex]['children'][$k];
595                $job[trim($this->tree[$propertyIndex]['name'])] = trim($this->tree[$propertyIndex]['data']);
596              }
597            }
598            $jobs[] = $job;
599          }
600                          }
601                          else {
602                                $value = trim($this->tree[$z]['data']);
603                                //print("$name is $value<br/>");
604                                $process[$name]=$value;
605                          }
606                        }
607
608                        $process['configs']             = $configs;
609                        $process['activities']  = $activities;
610                        $process['transitions'] = $transitions;
611                        $process['resources']   = $resources;
612                        $process['includes']    = $includes;
613                        $process['templates']   = $templates;
614                        $process['jobs']        = $jobs;
615
616                        return $process;
617                  }
618                 
619                /**
620                 * Creates a new process PHP data structure from its XML representation
621                 * unserial
622                 * @access public
623                 * @return void
624                 */
625                  function new_process_version($pId, $minor=true)
626                  {
627                         $new_id = parent::new_process_version($pId,$minor);
628
629                         //copy resource dir too
630                         $old_name = GALAXIA_PROCESSES . SEP . $this->_get_normalized_name($pId) . SEP . 'resources';
631                         $new_name = GALAXIA_PROCESSES . SEP . $this->_get_normalized_name($new_id) . SEP . 'resources';
632                         if (is_dir($old_name))
633                                $this->_rec_copy($old_name,$new_name);
634
635                         $this->workflow_acl->add_process_admins($new_id, array( $GLOBALS['phpgw_info']['user']['account_id'] ));
636
637                         return $new_id;
638                  }
639                /**
640                 * Remove process
641                 * @param int $pId process id
642                 * @access public
643                 * @return string
644                 */
645                  function remove_process($pId)
646                  {
647                        $result = parent::remove_process($pId);
648                        $this->workflow_acl->del_process($pId);
649                        return $result;
650                  }
651                /**
652                 * Replace_process
653                 *
654                 * @param int      $pid     process id
655                 * @param array    $vars
656                 * @param boolean  $create
657                 *   
658                 * @access public
659                 * @return int new id
660                 */
661                  function replace_process($pId, &$vars, $create = true)
662          {
663            $id = parent::replace_process($pId, $vars, $create);
664
665            if (!$pId)
666            {
667                                $this->workflow_acl->add_process_admins($id, array( $GLOBALS['phpgw_info']['user']['account_id'] ) );
668            }
669
670                        return $id;
671          }     
672        }
673?>
Note: See TracBrowser for help on using the repository browser.