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

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

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

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