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

Revision 3000, 22.2 KB checked in by viani, 14 years ago (diff)

Ticket #1131 - Modificada a exportacao de processos de workflow para desobrigar templates com o nome de atividades

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