source: trunk/workflow/inc/class.ui_adminprocesses.inc.php @ 989

Revision 989, 24.9 KB checked in by viani, 15 years ago (diff)

Ticket #547 - Uniformizar as Opcoes de Administracao no Workflow

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