source: companies/serpro/workflow/inc/class.ui_adminprocesses.inc.php @ 903

Revision 903, 25.3 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

Line 
1<?php
2require_once(dirname(__FILE__) . SEP . 'class.bo_workflow_forms.inc.php');
3require_once('engine' . SEP . 'config.egw.inc.php');
4/**
5 * @package Workflow
6 * @license http://www.gnu.org/copyleft/gpl.html GPL
7 */
8class ui_adminprocesses extends bo_workflow_forms
9{
10        /**
11         * @var array $public_functions public functions
12         * @access public
13         */
14        var $public_functions = array(
15                'form'  => true,
16        );
17        /**
18         * @var object $process_manager
19         * @access public
20         */
21        var $process_manager;
22       
23        /**
24         * @var object $activity_manager
25         * @access public
26         */
27        var $activity_manager;
28       
29        /**
30         * @var bool $filter_active
31         * @access public
32         */
33        var $filter_active;
34       
35        /**
36         * @var array $process_config
37         * @access public
38         */
39        var $process_config=array();
40       
41        /**
42         * @var array $workflow_acl
43         * @access public
44         */
45        var $workflow_acl;
46
47        /**
48         * Contructor
49         * @access public
50         * @return object
51         */
52        function ui_adminprocesses()
53        {
54                parent::bo_workflow_forms('admin_processes');
55
56                $this->workflow_acl = CreateObject('workflow.workflow_acl');
57                $denyAccess = true;
58                if ($this->workflow_acl->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']))
59                {
60                        /* the user is an Expresso/Workflow admin */
61                        $denyAccess = false;
62                }
63                else
64                {
65                        if ($GLOBALS['phpgw']->acl->check('admin_workflow', 1, 'workflow'))
66                        {
67                                /* check if the user can admin the informed process */
68                                if ($this->wf_p_id != 0)
69                                        $denyAccess = !$this->workflow_acl->check_process_access($GLOBALS['phpgw_info']['user']['account_id'], $this->wf_p_id);
70                                else
71                                        $denyAccess = false;
72                        }
73                }
74
75                if ($denyAccess)
76                {
77                        $GLOBALS['phpgw']->common->phpgw_header();
78                        echo parse_navbar();
79                        echo lang('access not permitted');
80                        $GLOBALS['phpgw']->log->message('F-Abort, Unauthorized access to workflow.ui_adminprocesses');
81                        $GLOBALS['phpgw']->log->commit();
82                        $GLOBALS['phpgw']->common->phpgw_exit();
83                }
84
85                $this->process_manager  = CreateObject('workflow.workflow_processmanager');
86                $this->activity_manager = CreateObject('workflow.workflow_activitymanager');
87               
88                $this->form_action = $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminprocesses.form');
89        }
90
91        /**
92        * Shows and processes process form
93        * Fields in the database are in the form 'wf_field', whereas in the form just 'field'
94        *
95        * @author       Alejandro Pedraza, Regis Leroy, Michael Bartz
96        * @access       public
97        */
98        function form()
99        {
100                //$GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['workflow']['title'] . ' - ' . lang('Admin Processes');
101                //$GLOBALS['phpgw']->common->phpgw_header();
102                //echo parse_navbar();
103                //$this->t->set_file('admin_processes', 'admin_processes.tpl');
104                $this->t->set_block('admin_processes', 'block_items', 'items');
105
106                $name                   = get_var('name', 'POST', '');
107                $description            = get_var('description', 'POST', '');
108                $version                = get_var('version', 'POST', '');
109                $is_active              = get_var('isActive', 'POST', '');
110                $filter                 = get_var('filter', 'any', '');
111                $this->filter_active    = get_var('filter_active', 'any', '');
112                $newminor               = get_var('newminor', 'GET', 0);
113                $newmajor               = get_var('newmajor', 'GET', 0);
114                //overwrite default sort order
115                $this->order            = get_var('order', 'any', 'wf_name');
116                $this->sort             = get_var('sort', 'any', 'asc');
117                $this->sort_mode        = $this->order . '__'. $this->sort;
118                //retrieve config_values POSTed by the form
119
120                // filtering options
121                $where_str = '';
122                $wheres = array();
123
124                if ($this->filter_active)
125                {
126                        $wheres[] = " wf_is_active='". $this->filter_active ."'";
127                }
128
129                if (!$GLOBALS['workflow']['factory']->getInstance('workflow_acl')->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']))
130                {
131                        $proc_ids = $this->workflow_acl->get_granted_processes($GLOBALS['phpgw_info']['user']['account_id']);
132                        if (count($proc_ids))
133                        {
134                                $wheres[] = ' wf_p_id in ('. implode(',',$proc_ids) .') ';
135                        }
136                        else
137                        {
138                                $wheres[] = ' wf_p_id = -1 ';
139                        }
140                }
141               
142                $where_str = implode('and', $wheres);
143
144                $this->link_data = array(
145                        'filter_active' => $this->filter_active,
146                        'search_str'    => $this->search_str,
147                        'offset'        => $this->offset,
148                        'start'         => $this->start,
149                );
150
151                // we set an array with all config values and titles we know
152                // this will serve to show config values and to save them
153                $known_config_items= array(
154                                        'Running activities options'                                    => 'title',
155                                        'auto-release_on_leaving_activity'                              => 'yesno',
156                                        'execute_activities_in_debug_mode'                              => 'yesno',
157                                        'execute_activities_using_secure_connection'    => 'yesno',
158                                        'Graphic options'                                                               => 'title',
159                                        'draw_roles'                                                                    => 'yesno',
160                                        'font_size'                                                                             => 'text',                                             
161                                        'Actions Right Options '                                                => 'title',
162                                        'ownership_give_abort_right'                                => 'yesno',
163                                        'ownership_give_exception_right'                            => 'yesno',
164                                        'ownership_give_release_right'                              => 'yesno',
165                                        'role_give_abort_right'                                     => 'yesno',
166                                        'role_give_release_right'                                   => 'yesno',
167                                        'role_give_exception_right'                                 => 'yesno',
168                                        'disable_advanced_actions'                                  => 'yesno',
169                                        'Database Options'                                                              => 'title',
170                                        'database_name'                                                                 => 'text',
171                                        'database_user'                                                                 => 'text',
172                                        'database_password'                                                             => 'password',
173                                        'View Options'                                                                  => 'title',                                     
174                                        'iframe_view_height'                                                    => 'text'
175                );
176                //we add agents options
177                //mail_smtp
178                $bo_agent = CreateObject('workflow.bo_agent_mail_smtp');
179                $known_config_items = $known_config_items + $bo_agent->listProcessConfigurationFields();       
180               
181               
182                //do we need to check validity, warning high load on database
183                $checkvalidity=false;
184               
185                if( isset($_POST['upload']))
186                {
187                        if ($_FILES['userfile1']['size'] == 0)
188                        {
189                                die("Bad upload!");
190                        }
191                       
192                        if ($_FILES['userfile1']['type'] != "text/xml") { die("Invalid file format!"); }                               
193                        //if ($_FILES['userfile1']['type'] != "text/xml" && $_FILES['file']['type'] != "image/jpeg" && $_FILES['file']['type'] != "image/pjpeg") { die("Invalid file format!"); }                               
194                        $fh = fopen ($_FILES['userfile1']['tmp_name'], "r") or die("Could not open file");
195
196                        // read file
197                        $date = '';
198                        while (!feof($fh))
199                        {
200                                 $data .= fgets($fh);
201                                 //echo $data;
202                        }
203                        // close file
204                        fclose ($fh);
205
206                        $process_data =& $this->process_manager->unserialize_process($data);
207                        if ($_POST['customImport'] == 'on')
208                        {
209                                if (!empty($_POST['newName']))
210                                        $process_data['name'] = $_POST['newName'];
211                                if (!empty($_POST['newVersion']))
212                                        $process_data['version'] = $_POST['newVersion'];
213                        }
214
215                        //_debug_array($process_data);
216                        if ($this->process_manager->import_process($process_data))
217                        {
218                                $this->message[] = lang('Import successfull');
219                        }
220                        else
221                        {
222                                $this->message[] = lang('Import aborted');
223                        }
224                }
225                // delete processes
226                if (isset($_POST['delete']))
227                {
228                        $this->delete_processes(array_keys($_POST['process']));
229                        $this->message[] = lang('Deletion successful');
230                }
231
232
233                // save new process
234                // or save modifs
235                if (isset($_POST['save']))
236                {
237                        //retrieve config_values POSTed by the form
238                        $config_yesno           =& get_var('config_yesno', 'POST', array());
239                        $config_value           =& get_var('config_value', 'POST', array());
240                        $config_use_default     =& get_var('config_use_default', 'POST', array());
241                        $global_config_array = array(
242                                'known_items'   => &$known_config_items,
243                                'yesno'         => &$config_yesno,
244                                'value'         => &$config_value,
245                                'default'       => &$config_use_default,
246                        );
247                        $this->wf_p_id = $this->save_process($name, $version, $description, $is_active,$global_config_array);
248                        //no need for $checkvalidity because this is done by the ProcessManager
249                }
250
251                // new minor
252                if ($newminor)
253                {
254                        if (!($this->process_manager->new_process_version($newminor)))
255                        {
256                                $this->message[] = lang('something was wrong while creating the new minor version');
257                        }
258                        else
259                        {
260                                $this->message[] = lang('new minor version created');
261                        }
262                       
263                }
264
265                // new major
266                if ($newmajor)
267                {
268                        if (!($this->process_manager->new_process_version($newmajor, false)))
269                        {
270                                $this->message[] = lang('something was wrong while creating the new major version');
271                        }
272                        else
273                        {
274                                $this->message[] = lang('new major version created');
275                        }
276
277                }
278
279                // retrieve current process
280                if ($this->wf_p_id)
281                {
282                        $proc_info = $this->process_manager->get_process($this->wf_p_id);
283                        $this->t->set_var('proc_bar', $this->fill_proc_bar($proc_info));
284                        //retrieve config values
285                        $this->process_config =& $this->process_manager->getConfigValues($this->wf_p_id);
286                }
287                else
288                {
289                        $proc_info = array(
290                                'wf_name'               => '',
291                                'wf_description'        => '',
292                                'wf_version'            => '1.0',
293                                'wf_is_active'          => 'n',
294                                'wf_p_id'               => 0
295                        );
296                        $this->t->set_var('proc_bar', '');
297                        $this->process_config = array();
298                }
299
300                // show list of processes
301                $items = &$this->process_manager->list_processes($this->start, $this->offset, $this->sort_mode, $search_str, $where_str);
302                //echo "list of processes: <pre>";print_r($items);echo "</pre>";
303                $this->show_list_processes($items['data'], $items['cant']);
304
305                if ($this->wf_p_id)
306                {
307                        // check process validity and show errors if necessary
308                        if ($checkvalidity) $proc_info['wf_is_valid'] = $this->show_errors($this->activity_manager, $error_str);
309                }
310               
311                //collect some messages from used objects
312                $this->message[] = $this->activity_manager->get_error(false, _DEBUG);
313                $this->message[] = $this->process_manager->get_error(false, _DEBUG);
314
315                // show current process
316                $this->t->set_var(array(
317                        'errors'                => $error_str,
318                        'txt_Process_Name'      => lang('Process Name'),
319                        'link_new'              => $GLOBALS['phpgw']->link('/index.php', array_merge( array(
320                                                        'menuaction'    => $this->form_action,
321                                                        'p_id'          => 0,), $this->link_data)
322                                                        ),
323                        'p_id'                  => $proc_info['wf_p_id'],
324                        'name'                  => $proc_info['wf_name'],
325                        'version'               => $proc_info['wf_version'],
326                        'description'           => $proc_info['wf_description'],
327                        'is_active'             => ($proc_info['wf_is_active'] == 'y')? 'checked="checked"' : '',
328                        'btn_update_create'     => ($this->wf_p_id)? lang('update') : lang('create'),
329                        'list_processes'        => lang('List of processes'),
330                ));
331                // show process config values
332                $this->show_process_config($known_config_items);
333               
334                $this->fill_form_variables();
335                $this->finish();
336        }
337        /**
338         * Delete processes
339         * @param array $process_ids
340         * @access public
341         * @return void
342         */
343        function delete_processes($process_ids)
344        {
345                foreach ($process_ids as $process_id)
346                {
347                        $this->process_manager->remove_process($process_id);
348                }
349        }
350       
351        /**
352         * Show the list of process configuration options
353         * Use the process_config array member which should be already setted. Show a table with a line for each config
354         * value containing [Yes-No/value/select | default] choices.
355         * @param array $known_config_itemns The parameter is an array containing all known config items and is used to show all config items, as only
356         * the ones changed for this process are stored in process_config.You should give this function all config_names avaible at process level associated with type which
357         * is 'yesno' or 'text' or an associative array with key 'select' containing an array of the select values
358         * to show (array: key => value) ==> (select: name => value)
359         * You can add titles by giving the title in the config_name and 'title' as type.
360         *
361         * @return void
362         * @access public
363         */
364        function show_process_config(&$known_config_items)
365        {
366                $siteconfiglink = '<a href="'.$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiconfig.index&appname=workflow')
367                        .'">'.lang('Workflow Site Configuration').'</a>';
368                $this->t->set_var(array(
369                        'txt_consult_site_config_with_link' => lang ('Consult %1 to get the default values:',$siteconfiglink),
370                ));
371               
372                $this->t->set_block('admin_processes', 'block_config_table_empty', 'config_table_empty');
373                $this->t->set_block('admin_processes', 'block_config_table_title', 'config_table_title');
374                $this->t->set_block('admin_processes', 'block_config_table_yesno', 'config_table_yesno');
375                $this->t->set_block('admin_processes', 'block_config_table_text', 'config_table_text');
376                $this->t->set_block('admin_processes', 'block_config_table_password', 'config_table_password');
377                $this->t->set_block('admin_processes', 'block_config_table_select_option', 'config_table_select_option');
378                $this->t->set_block('admin_processes', 'block_config_table_select', 'config_table_select');
379                $this->translate_template('block_config_table_title');
380                $this->translate_template('block_config_table_yesno');
381                $this->translate_template('block_config_table_text');
382                $this->translate_template('block_config_table_password');
383                $this->translate_template('block_config_table_empty');
384                $this->translate_template('block_config_table_select');
385                                                       
386                                        if (!(is_array($known_config_items)) || !count($known_config_items))
387                {
388                        $this->t->set_var(array(
389                                'config_empty' => lang('There are no config value defined'),
390                                'config_table_title' => '',
391                                'config_table_yesno' => '',
392                                'config_table_text' => '',
393                                'config_table_password' => '',
394                                'config_table_select' => '',
395                        ));
396                       
397                        $this->t->parse('config_table_empty', 'block_config_table_empty', true);
398                }
399                else
400                {
401                        //we wont need the 'empty config' row
402                        $this->t->set_var(array('config_table_empty'=> ''));
403                        //we prepare the global table rows
404                        $this->t->set_block('admin_processes', 'block_config_table', 'config_table');
405                        $this->translate_template('block_config_table');
406                        // we parse the config items we knows
407                        foreach ($known_config_items as $config_name => $config_type)
408                        {
409                                // now rows can be of different types
410                                if (is_array($config_type))
411                                {//we have a select
412                                        $this->t->set_var(array(
413                                                                                                                                                                        'config_name'                   => $config_name,
414                                                                                                                                                                        'config_name_trad'              => lang(str_replace('_',' ',$config_name)),
415                                                                                                                                                                        'color_line'                    => $this->nextmatchs->alternate_row_color($tr_color),
416                                                                                                                                                                        'config_table_title'            => '',
417                                                'config_table_text'             => '',
418                                                'config_table_password'         => '',
419                                                'config_table_yesno'            => '',
420                                        ));
421                                        unset($row_value);
422                                        $row_value = $this->process_config[$config_name];
423                                        if (!(isset($row_value)))
424                                        {
425                                                $this->t->set_var(array(
426                                                                                                                                                                                'config_default_selected'       => 'selected',
427                                                                                                                                                                                'config_table_select_option'    => '',
428                                                ));
429                                        }
430                                        else
431                                        {
432                                                $this->t->set_var(array('config_default_selected' => ''));
433                                        }
434                                        foreach($config_type as $key => $value)
435                                        {
436                                                $this->t->set_var(array(
437                                                                                                                                                                                 'config_option_name'           => $value,
438                                                                                                                                                                                 'config_option_value'          => $key,
439                                                                                                                                                                                 'config_option_selected'       => ($key == $row_value)? 'selected' : '',
440                                                ));//DEBUG TODO selected value?
441                                                $this->t->parse('config_table_select_option','block_config_table_select_option',true);
442                                        }
443                                        $this->t->parse('config_table_select', 'block_config_table_select', false);
444                                }
445                                elseif ($config_type=='title')
446                                {
447                                        $this->t->set_var(array(
448                                                                                                                                                                        'config_name_trad'      => lang(str_replace('_',' ',$config_name)),
449                                                                                                                                                                        'color_line'            => '#D3DCE3',
450                                                                                                                                                                        'config_table_text'     => '',
451                                                                                                                                                                        'config_table_password'         => '',
452                                                                                                                                                                        'config_table_yesno'    => '',
453                                                                                                                                        ));
454                                                                                                                                        $this->t->parse('config_table_title', 'block_config_table_title', false);
455                                }
456
457                                else
458                                {
459                                        // if not title or select our row can be a text value or a Yes/No/Default value
460                                        $this->t->set_var(array(
461                                                                                                                                                                        'config_name'                   => $config_name,
462                                                                                                                                                                        'config_name_trad'              => lang(str_replace('_',' ',$config_name)),
463                                                                                                                                                                        'color_line'                    => $this->nextmatchs->alternate_row_color($tr_color),
464                                                                                                                                                                        'config_table_title'            => '',
465                                                                                                                                                                        'config_table_select'           => '',
466                                        ));
467                                        unset($row_value);
468                                        $row_value = $this->process_config[$config_name];
469                                        if ($config_type=='text')
470                                        {
471                                                if (isset($row_value))
472                                                {
473                                                        $this->t->set_var(array(
474                                                                'config_value'                  => $row_value,
475                                                                'config_use_default_checked'    => '',
476                                                                'txt_Use_Default'               => lang('Use Default'),
477                                                                'config_table_password' => '',
478                                                                                                                                                                                        'config_table_yesno'            => '',
479                                                        ));
480                                                }
481                                                else
482                                                {
483                                                        $this->t->set_var(array(
484                                                                'config_value'                  => '',
485                                                                'config_use_default_checked'    => 'checked',
486                                                                'txt_Use_Default'               => lang('Use Default'),
487                                                                'config_table_password' => '',
488                                                                                                                                                                                        'config_table_yesno'            => '',
489                                                        ));
490                                                }
491                                                $this->t->parse('config_table_text', 'block_config_table_text', false);
492                                        }
493                                        elseif ($config_type=='password')
494                                        {
495                                                $config = array(
496                                                        'config_table_text' => '',
497                                                        'config_value' => '',
498                                                        'config_use_default_checked' => 'checked',
499                                                        'txt_Use_Default' => lang('Use Default'),
500                                                        'config_table_yesno' => ''
501                                                );
502                                                if (isset($row_value))
503                                                {
504                                                        $config['config_value'] =$row_value;
505                                                        $config['config_use_default_checked'] = '';
506                                                }
507                                                $this->t->set_var($config);
508                                                $this->t->parse('config_table_password', 'block_config_table_password', false);
509                                        }
510                                        elseif ($config_type=='yesno')
511                                        {
512                                                if (isset($row_value))
513                                                {
514                                                        $this->t->set_var(array(
515                                                                                                                                                                                        'config_table_text'             => '',
516                                                                                                                                                                                        'config_table_password' => '',
517                                                                                                                                                                                        'config_default_selected'       => '',
518                                                                                                                                                                                        'config_yes_selected'           => ($row_value==1)? 'selected':'',
519                                                                                                                                                                                        'config_no_selected'            => ($row_value==1)? '':'selected',
520                                                        ));
521                                                }
522                                                else
523                                                {
524                                                        $this->t->set_var(array(
525                                                                                                                                                                                        'config_table_text'             => '',
526                                                                                                                                                                                        'config_table_password' => '',
527                                                                                                                                                                                        'config_default_selected'       => 'selected',
528                                                                                                                                                                                        'config_yes_selected'           => '',
529                                                                                                                                                                                        'config_no_selected'            => '',
530                                                        ));
531                                                }
532                                                $this->t->parse('config_table_yesno', 'block_config_table_yesno', false);
533                                        }
534                                }
535                                $this->t->parse('config_table','block_config_table',true);
536                        }
537                }
538        }
539        /**
540         * Show list of processes
541         * @param $items
542         * @param int $total_number
543         * @access public
544         * @return void
545         */
546        function show_list_processes(&$items, $total_number)
547        {
548                $header_array = array(
549                        'wf_name'               => lang('Process'),
550                        'wf_version'    => lang('Version'),
551                        'wf_is_active'  => lang('Active'),
552                        'wf_is_valid'   => lang('Valid'),
553                );
554                $this->fill_nextmatchs($header_array,$total_number);
555               
556                // filter_active, "", y or n
557                $this->t->set_var(array(
558                                'filter_active_selected_all'    => ($this->filter_active=='')? 'selected':'',
559                                'filter_active_selected_y'      => ($this->filter_active=='y')? 'selected':'',
560                                'filter_active_selected_n'      => ($this->filter_active=='n')? 'selected':'',
561                ));
562                $get_link = array(
563                        'menuaction'    => 'workflow.ui_'. $this->class_name .'.form',
564                        'search_str'    => $this->search_str,
565                        'start'         => $this->start,
566                        'sort'          => $this->sort,
567                        'order'         => $this->order,
568                );
569                $get_link = array_merge($get_link, $this->link_data);
570                foreach ($items as $item)
571                {
572                        if ($item['wf_is_valid'] == 'y')
573                        {
574                                $dot = 'green';
575                                $alt = lang('Valid Process');
576                        }
577                        else
578                        {
579                                $dot = 'red';
580                                $alt = lang('Invalid Process');
581                        }
582                       
583                        $myp_id = $item['wf_p_id'];
584                        $templateServer = &$GLOBALS['workflow']['factory']->getInstance('TemplateServer');
585                        $this->t->set_var(array(
586                                'item_wf_p_id'          => $myp_id,
587                                'href_item_name'        => $GLOBALS['phpgw']->link('/index.php', array_merge($get_link,array('p_id' => $myp_id))),
588                                'item_name'                     => $item['wf_name'],
589                                'item_version'          => $item['wf_version'],
590                                'img_active'            => ($item['wf_is_active'] == 'y')? '<img src="'. $templateServer->generateImageLink('refresh2.gif') .'" alt="'. lang('active') .'" title="'. lang('active') .'" />' : '',
591                                'img_valid'                     => '<img src="'. $templateServer->generateImageLink($dot.'_dot.gif') .'" alt="'. $alt .'" title="'. $alt .'" />',
592                                'href_item_minor'       => $GLOBALS['phpgw']->link('/index.php', array_merge($get_link,array('newminor' => $myp_id))),
593                                'img_new'                       => $GLOBALS['phpgw']->common->image('workflow', 'new'),
594                                'href_item_major'       => $GLOBALS['phpgw']->link('/index.php', array_merge($get_link,array('newmajor' => $myp_id))),
595                                'href_item_activities'  => $GLOBALS['phpgw']->link('/index.php', array(
596                                                                'menuaction'    => 'workflow.ui_adminactivities.form',
597                                                                'p_id'          => $myp_id)),
598                                'img_activities'        => $templateServer->generateImageLink('Activity.gif'),
599                                'href_item_code'        => $GLOBALS['phpgw']->link('/index.php', array(
600                                                                'menuaction'    => 'workflow.ui_adminsource.form',
601                                                                'p_id'          => $myp_id)),
602                                'img_code'              => $templateServer->generateImageLink('code.png'),
603                                'href_item_save'        => $GLOBALS['phpgw']->link('/index.php', array(
604                                                                'menuaction'    => 'workflow.WorkflowUtils.export',
605                                                                'p_id'          => $myp_id)),
606                                'img_save'              => $templateServer->generateImageLink('save.png'),
607                                'href_item_roles'       => $GLOBALS['phpgw']->link('/index.php', array(
608                                                                'menuaction'    => 'workflow.ui_adminroles.form',
609                                                                'p_id'          => $myp_id)),
610                                'img_roles'             => $templateServer->generateImageLink('roles.png'),
611                                'href_item_jobs'        => $GLOBALS['phpgw']->link('/index.php', array(
612                                                                'menuaction'    => 'workflow.ui_adminjobs.form',
613                                                                'p_id'          => $myp_id)),
614                                'img_jobs'              => $templateServer->generateImageLink('clock.png'),
615                                'color_line'            => $this->nextmatchs->alternate_row_color($tr_color),
616                        ));
617                        $this->t->parse('items', 'block_items', True);
618                }
619                if (!count($items)) $this->t->set_var('items', '<tr><td colspan="5" align="center">'. lang('There are no processes defined')  .'</td></tr>');
620                $this->translate_template('block_items');
621        }
622       
623        /**
624         * Save or update the current process
625         * @param string $name name of process
626         * @param int $version version of process
627         * @param bool $is_active
628         * @param array $config_data
629         * @return int process id
630         * @access public
631         */
632        function save_process($name, $version, $description, $is_active, &$config_data)
633        {
634                if (($this->wf_p_id == 0) && $this->process_manager->process_name_exists($name, $version))
635                {
636                        $this->message[] = lang('Process name already exists');
637                        return false;
638                }
639                else
640                {
641                        /* prevent a process to overwrite an existing one */
642                        if ($this->wf_p_id != 0)
643                        {
644                                $processInfo = $this->process_manager->get_process($this->wf_p_id);
645                                if (($this->process_manager->_normalize_name($name, $version) != $processInfo['wf_normalized_name']) && $this->process_manager->process_name_exists($name, $version))
646                                {
647                                        $this->message[] = lang('Process name already exists');
648                                        return false;
649                                }
650                        }
651
652                        $proc_info = array(
653                                'wf_name'               => $name,
654                                'wf_description'        => $description,
655                                'wf_version'            => $version,
656                                'wf_is_active'          => ($is_active == 'on')? 'y' : 'n'
657                        );
658                        $this->wf_p_id = $this->process_manager->replace_process($this->wf_p_id, $proc_info);
659                        $this->save_config($config_data);
660                        $valid = $this->activity_manager->validate_process_activities($this->wf_p_id);
661                        if (!$valid)
662                        {
663                                $this->process_manager->deactivate_process($this->wf_p_id);
664                        }
665                        $this->message[] = lang('Process saved');
666                        return $this->wf_p_id;
667                }
668        }
669       
670       
671        /**
672         * Save the configuration values for the current process
673         * This function use the list of known configuration items to parse POSTed config values
674         * Theses values are passed to the process->SetConfigValues which know well what to do with
675         * them.
676         * @param array $global_config_data Global config
677         * @return void
678         * @access public
679         */
680        function save_config(&$global_config_data)
681        {
682                $known_config_items     =& $global_config_data['known_items'];
683                $config_yesno           =& $global_config_data['yesno'];       
684                $config_value           =& $global_config_data['value'];
685                $config_use_default     =& $global_config_data['default'];                     
686                $array_config = array();
687                foreach ($known_config_items as $config_name => $config_type)
688                {
689                        if (is_array($config_type))
690                        {//case of a select
691                                if (isset($config_use_default[$config_name]))
692                                {
693                                        $user_post_value = $config_value[$config_name];
694                                        if ($user_post_value == 'default')
695                                        {
696                                                //user ask for default
697                                                $array_config[$config_name]=array('int' => -1);
698                                        }
699                                        elseif (is_numeric($user_post_value))
700                                        {
701                                                $array_config[$config_name]=array('int' => $user_post_value);
702                                        }
703                                        else
704                                        {
705                                                $array_config[$config_name]=array('text' => $user_post_value);
706                                        }
707                                }
708                        }
709                        if (!($config_type=='title')) //we do not need titles
710                        {
711                                if ($config_type=='yesno')
712                                {
713                                        if (isset($config_yesno[$config_name]))
714                                        {
715                                                $user_post_value = $config_yesno[$config_name];
716                                                if ($user_post_value == 'default')
717                                                {
718                                                        //user ask for default
719                                                        $array_config[$config_name]=array('int' => -1);
720                                                }
721                                                elseif ($user_post_value == 'yes')
722                                                {
723                                                        $array_config[$config_name]=array('int' => 1);
724                                                }
725                                                else //no
726                                                {
727                                                        $array_config[$config_name]=array('int' => 0);
728                                                }
729                                        }
730                                }
731                                else // text config type
732                                {
733                                        if (isset($config_use_default[$config_name]))
734                                        {
735                                                //user ask for default
736                                                $array_config[$config_name]=array('int' => -1);
737                                        }
738                                        elseif (isset($config_value[$config_name]))
739                                        {
740                                                $user_post_value = $config_value[$config_name];
741                                                if (is_numeric($user_post_value))
742                                                {
743                                                        $array_config[$config_name]=array('int' => $user_post_value);
744                                                }
745                                                else
746                                                {
747                                                        $array_config[$config_name]=array('text' => $user_post_value);
748                                                }                                               
749                                        }
750                                }
751                        }
752               
753                } // end foreach                                       
754                $this->process_manager->setConfigValues($this->wf_p_id,$array_config);
755        }// end function
756}
757?>
Note: See TracBrowser for help on using the repository browser.