source: trunk/workflow/inc/class.ui_adminactivities.inc.php @ 795

Revision 795, 39.0 KB checked in by viani, 15 years ago (diff)

Ticket #488 - Inclusão do módulo workflow no ramo trunk do repositório Expresso.

  • Property svn:executable set to *
Line 
1<?php
2
3require_once dirname(__FILE__) . SEP . 'class.WorkflowUtils.inc.php';
4require_once dirname(__FILE__) . SEP . 'class.fsutils.inc.php'; /* toolkit for filesystem handling */
5require_once 'engine' . SEP . 'config.egw.inc.php';
6/**
7 * @package Workflow
8 * @license http://www.gnu.org/copyleft/gpl.html GPL
9 */
10class ui_adminactivities extends WorkflowUtils
11{
12        /**
13         * @var array $public_functions Array of public functions
14         * @access public
15         */
16        var $public_functions = array(
17                'form'                  => true,
18                'show_graph'    => true
19        );
20/**
21 * @var object $process_manager Process manager
22 * @access public
23 */
24        var $process_manager;           
25/**
26 * @var object $activity_manager
27 * @access public
28 */
29        var $activity_manager;
30/**
31 * @var object $role_manager
32 * @access public
33 */
34        var $role_manager;
35/**
36 * @var $where2
37 * @access public
38 */     
39        var $where2;
40        /**
41         * @var object $sort_mode2
42         * @access public
43         */     
44        var $sort_mode2;
45        /**
46         * @var array $agents agents handling
47         * @access public
48         */
49        var $agents=Array();
50        /**
51         * @var object $workflow_acl
52         * @access public
53         */
54        var $workflow_acl;
55        /**
56         * @var object $fs object for reading process folder 
57         * @access public
58         */
59        var $fs;
60        /**
61         * @var array  $invalidFiles invalid files list
62         * @access public
63         */
64        var $invalidFiles = array();     
65        /**
66         * Constructor da classe ui_adminactivities
67         *
68         * @access public
69         * @return void
70         */     
71        function ui_adminactivities()
72        {
73                parent::WorkflowUtils();
74
75                $this->workflow_acl = CreateObject('workflow.workflow_acl');
76                $denyAccess = true;
77                if ($this->workflow_acl->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']))
78                {
79                        /* the user is an Expresso/Workflow admin */
80                        $denyAccess = false;
81                }
82                else
83                {
84                        if ($GLOBALS['phpgw']->acl->check('admin_workflow', 1, 'workflow'))
85                        {
86                                /* check if the user can admin the informed process */
87                                if ($this->wf_p_id != 0)
88                                        $denyAccess = !$this->workflow_acl->check_process_access($GLOBALS['phpgw_info']['user']['account_id'], $this->wf_p_id);
89                                else
90                                        $denyAccess = false;
91                        }
92                }
93
94                /* allow regular users to see the process graph */
95                if ($_GET['menuaction'] == "workflow.ui_adminactivities.show_graph")
96                        $denyAccess = false;
97
98                if ($denyAccess)
99                {
100                        $GLOBALS['phpgw']->common->phpgw_header();
101                        echo parse_navbar();
102                        echo lang('access not permitted');
103                        $GLOBALS['phpgw']->log->message('F-Abort, Unauthorized access to workflow.ui_adminprocesses');
104                        $GLOBALS['phpgw']->log->commit();
105                        $GLOBALS['phpgw']->common->phpgw_exit();
106                }
107
108                $this->process_manager  = CreateObject('workflow.workflow_processmanager');
109                $this->activity_manager = CreateObject('workflow.workflow_activitymanager');
110                $this->role_manager     = CreateObject('workflow.workflow_rolemanager');
111                $this->fs = new FsUtils(); /* gets instance */
112
113        }
114               
115        /**
116         * Build the form for Activities Administration
117         * @return void
118         * @access public
119         */
120        function form()
121        {
122                $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['workflow']['title'] . ' - ' . lang('Admin Process Activities');
123                $GLOBALS['phpgw']->common->phpgw_header();
124                echo parse_navbar();
125
126                $this->t->set_file('admin_activities', 'admin_activities.tpl');
127                $this->t->set_block('admin_activities', 'block_select_type', 'select_type');
128                $this->t->set_block('admin_activities', 'block_activity_roles', 'activity_roles');
129                $this->t->set_block('admin_activities', 'block_process_roles', 'process_roles');
130                $this->t->set_block('admin_activities', 'block_activity_agents', 'activity_agents');
131                $this->t->set_block('admin_activities', 'block_select_agents', 'select_agents');
132       
133                $proc_info =& $this->process_manager->get_process($this->wf_p_id);
134       
135                $activity_id            = (int)get_var('activity_id', 'any', 0);
136                $name                           = get_var('name', 'any', '');
137                                       
138                // TODO: not all variables below are still required.  clean up
139               
140                $description                    = get_var('description', 'any', '');
141                $type                                   = get_var('type', 'any', '');
142                $is_interactive                 = get_var('is_interactive', 'any', '');
143                $is_autorouted                  = get_var('is_autorouted', 'any', '');
144                $default_user                   = get_var('default_user', 'any', '');
145                $useagent                               = get_var('useagent', 'POST', '');
146                $where                                  = get_var('where', array('GET', 'POST'), '');
147                $this->where2                   = get_var('where2', 'any', '');
148                $find                                   = get_var('find', 'any', '');
149                $find2                                  = get_var('find2', 'any', '');
150                $this->sort_mode2               = get_var('sort_mode2', 'any', '');
151                $filter_trans_from              = get_var('filter_trans_from', 'any', '');
152                $this->order                    = get_var('order', 'GET', 'wf_flow_num');
153                $this->sort                             = get_var('sort', 'GET', 'asc');
154                $this->sort_mode                = $this->order . '__'. $this->sort;
155                $menu_path                              = get_var('menu_path', 'any', '');
156                //roles
157                $activity_role_ro               = get_var('activity_role_ro','POST', Array());
158                $activity_role_delete   = get_var('activity_role_delete','POST', Array());
159                $remove_roles                   = get_var('remove_roles', 'POST', false);
160                $rolename                               = get_var('rolename', 'POST', '');
161                $roledescription                = get_var('roledescription', 'POST', '');
162                $userole                                = get_var('userole', 'POST', '');
163                $userole_ro                             = get_var('userole_ro', 'POST', 'off');
164                $newrole_ro                             = get_var('newrole_ro', 'POST', 'off');
165
166
167                if (!$this->wf_p_id) die(lang('No process indicated'));
168
169                // *************************************   START OF OPERATIONS COMMANDED BY THIS SAME FORM ******************
170                // do we need to check validity? do it only if necessary, high load on database
171                $checkvalidity = false;
172
173                // add role to process roles
174                if( !(empty($rolename)) )
175                {
176                        $rolename = trim($rolename);
177                        if( strlen($rolename) > 0 )
178                        {
179                                //second parameter for read-only mode
180                                $newrole_id = $this->add_process_role($rolename, $roledescription);
181                                if ($newrole_id)
182                                {
183                                        $this->message[] = lang('Role added to process');
184                                        if ($activity_id)
185                                        {
186                                                $this->activity_manager->add_activity_role($activity_id, $newrole_id, ($newrole_ro=='on'));
187                                                $this->message[] = lang('Role added to activity');
188                                        }
189                                        $checkvalidity = true;
190                                }
191                        }
192                        else
193                        {
194                                $this->message[] = lang('Invalid role name');
195                        }
196                }
197
198                // remove activity role
199                if (!!($remove_roles) && $activity_id)
200                {
201                        foreach ($activity_role_delete as $role_id => $checked_on)
202                        {
203                                $this->activity_manager->remove_activity_role($activity_id, $role_id);
204                                $this->message[] = lang('Activity role #%1 removed', $role_id);
205                        }
206                        $this->message[] = $this->activity_manager->get_error(false, _DEBUG);
207                        $checkvalidity = true;
208                }
209
210                // remove activity agent
211                if (isset($_GET['remove_agent']) && $activity_id)
212                {
213                        $this->activity_manager->remove_activity_agent($activity_id, $_GET['remove_agent'],true);
214                        $this->message[] = lang('Activity agent removed');
215                        $this->message[] = $this->activity_manager->get_error(false, _DEBUG);
216                }
217
218                // TODO: activityname need to be valid.  Add a validity checking function?
219                // save activity
220                if (isset($_POST['save_act']))
221                {
222                        $activity_id = $this->save_activity($activity_id, $name, $description, $type, $default_user, $is_interactive, $is_autorouted, $userole, $userole_ro, $useagent, $rolename, $menu_path);
223                        if( $activity_id )
224                        {
225                                if ($newrole_id)
226                                {
227                                        $this->activity_manager->add_activity_role($activity_id, $newrole_id, ($newrole_ro=='on'));
228                                        $this->message[] = lang('Role added to activity');
229                                }
230                                $this->message[] = lang('Activity saved');
231                        }
232                        //no checkvalidity, this is done already in ActivityManager
233                }
234
235                // delete activity
236                if (isset($_POST['delete_act']))
237                {
238                        if( isset($_POST['activities']) )
239                        {
240                                if ($this->delete_activities(array_keys($_POST['activities']))) $this->message[] = lang('Deletion successful');
241                                $checkvalidity = true;
242                        }
243                }
244
245                // add transitions
246                if (isset($_POST['add_trans']))
247                {
248                        $this->message[] = $this->add_transition($_POST['wf_act_from_id'], $_POST['wf_act_to_id']);
249                        $checkvalidity = true;
250                }
251
252                // delete transitions
253                if (isset($_POST['delete_tran']))
254                {
255                        $this->delete_transitions($_POST['transition']);
256                        $checkvalidity = true;
257                }
258
259                // *************************************   END OF OPERATIONS COMMANDED BY THIS SAME FORM ******************
260
261                $expandTable = isset($_POST['new_activity']);
262                // retrieve activity info and its roles and agents
263                if (!$activity_id || isset($_POST['new_activity']))
264                {
265                        $activity_info = array(
266                                'wf_name'               => '',
267                                'wf_description'        => '',
268                                'wf_activity_id'        => 0,
269                                'wf_is_interactive'     => true,
270                                'wf_is_autorouted'      => false,
271                                'wf_default_user'       => '*',
272                                'wf_type'               => 'activity',
273                                'wf_menu_path'  => ''
274                        );
275                        $activity_roles = array();
276                        $activity_agents = array();
277                }
278                else
279                {
280                        $expandTable = true;
281                        $activity_info =& $this->activity_manager->get_activity($activity_id);
282                        $activity_roles =& $this->activity_manager->get_activity_roles($activity_id);
283                        $activity_agents =& $this->activity_manager->get_activity_agents($activity_id);
284                        //for all agents we create ui_agent object to handle admin agents displays
285                        //this array can be already done by the save_activity function, in this case
286                        // we will just actualize most of the records
287                        foreach ($activity_agents as $agent)
288                        {
289                                if (empty($this->agents[$agent['wf_agent_type']]))
290                                {
291                                        $ui_agent =& createObject('workflow.ui_agent_'.$agent['wf_agent_type']);
292                                        $ui_agent->load($agent['wf_agent_id']);
293                                        $this->agents[$agent['wf_agent_type']] = $ui_agent;
294                                        unset($ui_agent);
295                                }
296                                else
297                                {
298                                        $this->agents[$agent['wf_agent_type']]->load($agent['wf_agent_id']);
299                                }
300                        }
301                }
302
303                // fill type filter select box
304                $activity_types = array('start', 'end', 'activity', 'switch', 'split', 'join', 'standalone', 'view');
305                $filter_type = get_var('filter_type', 'any', '');
306                $this->show_select_filter_type($activity_types, $filter_type);
307               
308                $filter_interactive             = get_var('filter_interactive', 'any', '');
309                $activity_interactive = array('y' => lang('Interactive'), 'n'=>lang('Automatic'));
310                $this->show_select_filter_interactive($activity_interactive, $filter_interactive);
311               
312                $filter_autoroute               = get_var('filter_autoroute', 'any', '');
313                $activity_autoroute = array('y' => lang('Auto Routed'), 'n'=>lang('Manual'));
314                $this->show_select_filter_autoroute($activity_autoroute, $filter_autoroute);
315               
316                $where = '';
317                $wheres = array();
318                if( !($filter_type == '') )
319                {
320                                        $wheres[] = "wf_type = '" .$filter_type. "'";
321                }
322                if( !($filter_interactive == '') )
323                {
324                                        $wheres[] = "wf_is_interactive = '" .$filter_interactive. "'";
325                }
326                if( !($filter_autoroute == '') )
327                {
328                        $wheres[] = "wf_is_autorouted = '" .$filter_autoroute. "'";
329                }
330                if( count($wheres) > 0 )
331                {
332                        $where = implode(' and ', $wheres);
333                }
334               
335                if (empty($process_activities)) $process_activities =& $this->activity_manager->list_activities($this->wf_p_id, 0, -1, $this->sort_mode, $find, $where);
336                $all_transition_activities_from =& $this->activity_manager->get_transition_activities($this->wf_p_id, 'end');
337                $all_transition_activities_to =& $this->activity_manager->get_transition_activities($this->wf_p_id, 'start');
338                if ($activity_id) $this->search_transitions_act($process_activities, $activity_id);
339                $process_roles =& $this->role_manager->list_roles($this->wf_p_id, 0, -1, 'wf_name__asc', '');
340                $agents_list =& $this->process_manager->get_agents();
341                $all_process_transitions =& $this->activity_manager->get_process_transitions($this->wf_p_id);
342                $process_transitions =& $this->activity_manager->get_process_transitions($this->wf_p_id, $filter_trans_from);
343                $process_activities_with_transitions =& $this->activity_manager->get_process_activities_with_transitions($this->wf_p_id);
344
345                // update activities
346                if (isset($_POST['update_act']))
347                {
348                        if( is_array($process_activities['data']) && count($process_activities['data']) > 0 )
349                        {
350                                $this->update_activities($process_activities, array_keys($_POST['activity_inter']), array_keys($_POST['activity_route']));
351                                $this->message[] = lang('Activities updated');
352                        }
353                }
354
355                // activate process
356                if (isset($_GET['activate_proc']))
357                {
358                        $this->process_manager->activate_process($_GET['activate_proc']);
359                        $proc_info['wf_is_active'] = 'y';
360                }
361
362                // deactivate process
363                if (isset($_GET['deactivate_proc']))
364                {
365                        $this->process_manager->deactivate_process($_GET['deactivate_proc']);
366                        $proc_info['wf_is_active'] = 'n';
367                }
368
369                /* warning, heavy database load! */
370                /* check process validity and show errors if necessary */
371                if ($checkvalidity) $proc_info['wf_is_valid'] = $this->show_errors($this->activity_manager, $error_str);
372
373                // fill proc_bar
374                $this->t->set_var('proc_bar', $this->fill_proc_bar($proc_info));
375               
376                //collect some messages from used objects
377                $this->message[] = $this->activity_manager->get_error(false, _DEBUG);
378                $this->message[] = $this->process_manager->get_error(false, _DEBUG);
379                $this->message[] = $this->role_manager->get_error(false, _DEBUG);
380
381                $templateServer = &$GLOBALS['workflow']['factory']->getInstance('TemplateServer');
382
383                // fill the general variables of the template
384                $this->t->set_var(array(
385                        'message'                               => implode('<br>', array_filter($this->message)),
386                        'errors'                                => $error_str,
387                        'form_details_action'   => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form'),
388                        'form_list_transitions_action'  => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form'),
389                        'p_id'                                  => $this->wf_p_id,
390                        'where'                                 => $where,
391                        'where2'                                => $this->where2,
392                        'sort_mode'                             => $this->sort_mode,
393                        'sort_mode2'                    => $this->sort_mode2,
394                        'find'                          => $find,
395                        'find2'                         => $find2,
396                        'expandTable'                   => ($expandTable ? 'true' : 'false'),
397                        'activity_id'                   => $activity_info['wf_activity_id'],
398                        'new_act_href'                  => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form'),
399                        'name'                                  => $activity_info['wf_name'],
400                        'description'                   => $activity_info['wf_description'],
401                        'checked_interactive'   => ($activity_info['wf_is_interactive'])? 'checked="checked"' : '',
402                        'checked_autorouted'    => ($activity_info['wf_is_autorouted'])? 'checked="checked"' : '',
403                        'menu_path'                             => $activity_info['wf_menu_path'],
404                        'img_transition_auto'           => '<img src="'.$templateServer->generateImageLink('transition_interactive.gif') .'" alt="'. lang('transition mode') .'" />',
405                        'img_interactive'               => '<img src="'.$templateServer->generateImageLink('mini_interactive.gif') .'" alt="'. lang('interactivity') .'" />',
406                        'img_transition'                => '<img src="'.$templateServer->generateImageLink('transition.gif') .'" alt="'. lang('transitions') .'" />',
407                        'img_transition_add'            => '<img src="'.$templateServer->generateImageLink('transition_add.gif') .'" alt="'. lang('add transition') .'" />',
408                        'img_transition_delete'         => '<img src="'.$templateServer->generateImageLink('transition_remove.gif') .'" alt="'. lang('delete transition') .'" />',
409                        'add_trans_from'                => $this->build_select_transition('add_tran_from[]', $all_transition_activities_from['data'], true, false, 'from'),
410                        'add_trans_to'                  => $this->build_select_transition('add_tran_to[]', $all_transition_activities_to['data'], true, false, 'to'),
411                        'add_a_trans_from'              => $this->build_select_transition('wf_act_from_id', $all_transition_activities_from['data'], false, false),
412                        'add_a_trans_to'                => $this->build_select_transition('wf_act_to_id', $all_transition_activities_to['data'], false, false)
413                ));
414
415                if( $filter_trans_from ) {
416                        $this->t->set_var('filter_trans_from', $this->build_select_transition_filtered('filter_trans_from', $process_activities_with_transitions['data'], false, true, $filter_trans_from));
417                        $this->t->set_var('filter_trans_from_value', $filter_trans_from);
418                }
419                else {
420                        $this->t->set_var('filter_trans_from', $this->build_select_transition_filtered('filter_trans_from', $process_activities_with_transitions['data'], false, true, false));                         
421                        $this->t->set_var('filter_trans_from_value', '');
422                }
423
424                // show process activities table
425                $this->show_process_activities($process_activities['data']);
426
427               
428                foreach ($activity_types as $type)
429                {
430                        $this->t->set_var(array(
431                                'type_value'    => $type,
432                                'type_selected' => ($activity_info['wf_type'] == $type)? 'selected="selected"' : '',
433                                'type_name'             => $type
434                        ));
435                        $this->t->parse('select_type', 'block_select_type', true);
436                }
437
438                // fill activity roles
439                if (!$activity_roles)
440                {
441                        $this->t->set_var('activity_roles', '<tr><td colspan="3">'.lang('No roles asociated with this activity').'</td></tr>');
442                }
443                else
444                {
445                        foreach ($activity_roles as $role)
446                        {
447                                $this->t->set_var(array(
448                                        'act_role_name'         => $role['wf_name'],
449                                        'act_role_id'           => $role['wf_role_id'],
450                                        'act_role_ro_checked'   => ($role['wf_readonly'])? 'checked="checked"' : '',
451                                        'act_role_href'         => $GLOBALS['phpgw']->link('/index.php', array(
452                                                        'menuaction'    => 'workflow.ui_adminactivities.form',
453                                                        'where2'        => $where2,
454                                                        'sort_mode2'    => $sort_mode2,
455                                                        'find'          => $find,
456                                                        'where'         => $where,
457                                                        'activity_id'   => $activity_info['wf_activity_id'],
458                                                        'p_id'          => $this->wf_p_id,
459                                                        'remove_role'   => $role['wf_role_id'],
460                                        )),
461                                         'lang_delete'          => lang('delete'),
462                                ));
463                                $this->t->parse('activity_roles', 'block_activity_roles', True);
464                        }
465                       
466                }
467               
468                //general texts about roles
469                $this->t->set_var(array(
470                        'txt_read_only'                         => lang('read-only'),
471                        'txt_role_name'                         => lang('Role Name'),
472                        'txt_Remove_selected_roles'             => lang('remove selected roles'),
473                        'txt_Use_existing_roles'                => lang('Use existing roles'),
474                        )
475                );
476               
477                // fill activity agents
478                if (!$activity_agents)
479                {
480                        $this->t->set_var(array(
481                                'activity_agents'       => lang('No agents associated with this activity'),
482                                'agents_config_rows'    => '',
483                        ));
484                }
485                else
486                {
487                        foreach ($activity_agents as $agent)
488                        {
489                                $this->t->set_var(array(
490                                        'act_agent_type'        => $agent['wf_agent_type'],
491                                        'act_agent_href'        => $GLOBALS['phpgw']->link('/index.php', array(
492                                                'menuaction'    => 'workflow.ui_adminactivities.form',
493                                                'where2'        => $where2,
494                                                'sort_mode2'    => $sort_mode2,
495                                                'find'          => $find,
496                                                'where'         => $where,
497                                                'activity_id'   => $activity_info['wf_activity_id'],
498                                                'p_id'          => $this->wf_p_id,
499                                                'remove_agent'  => $agent['wf_agent_id'],
500                                        )),
501                                        'lang_delete'           => lang('delete'),
502                                ));
503                                $this->t->parse('activity_agents', 'block_activity_agents', True);
504                        }
505                }
506               
507                //display agents options
508                $this->display_agents_rows();
509
510                // if we have no default user
511                if ($activity_info['wf_default_user'] == '*')
512                        $wf_default_user_desc = '';
513                else
514                        $wf_default_user_desc = $GLOBALS['phpgw']->accounts->id2name($activity_info['wf_default_user'], 'account_lastname');
515
516                $this->t->set_var(array(
517                        'wf_default_user' => $activity_info['wf_default_user'],
518                        'wf_default_user_desc' => $wf_default_user_desc
519                ));
520
521                // fill process roles
522                foreach ($process_roles['data'] as $role)
523                {
524                        $this->t->set_var(array(
525                                'proc_roleId'   => $role['wf_role_id'],
526                                'proc_roleName' => $role['wf_name']
527                        ));
528                        $this->t->parse('process_roles', 'block_process_roles', True);
529                }
530               
531                // fill agents select
532                foreach ($agents_list as $agent)
533                {
534                        $this->t->set_var(array(
535                                'select_agentType'      => $agent['wf_agent_type']
536                        ));
537                        $this->t->parse('select_agents', 'block_select_agents', True);
538                }
539
540                // fill list of transitions table
541                $this->show_transitions_table($process_transitions);
542                $this->t->set_var('filter_type_value', $filter_type);
543                $this->t->set_var('filter_interactive_value', $filter_interactive);
544                $this->t->set_var('filter_autoroute_value', $filter_autoroute);
545                $this->t->set_var('find_value', $find);
546
547                // create graph
548                $this->activity_manager->build_process_graph($this->wf_p_id);
549
550                $this->translate_template('admin_activities');
551                $this->t->pparse('output', 'admin_activities');
552                $GLOBALS['phpgw']->common->phpgw_footer();
553        }
554        /**
555        * Show select filter type
556        * @param array $all_activity_types
557        * @param $filter_type
558        * @access public
559        * @return void
560        */
561        function show_select_filter_type($all_activity_types, $filter_type)
562        {
563                $this->t->set_block('admin_activities', 'block_select_filter_type', 'select_filter_type');
564                $this->t->set_var('selected_filter_type_all', (!($filter_type))? 'selected="selected"' : '');
565
566                foreach ($all_activity_types as $type)
567                {
568                        $this->t->set_var(array(
569                                'selected_filter_type'  => ($filter_type == $type)? 'selected="selected"' : '',
570                                'filter_type_name'      => lang($type),
571                                'filter_type_en_name'   => $type
572                        ));
573                        $this->t->parse('select_filter_type', 'block_select_filter_type', true);
574                }
575        }
576       
577        /**
578        * Show select filter type
579        * @param array $all_activity_types
580        * @param $filter_type
581        * @access public
582        * @return void
583        */
584        function show_select_filter_interactive($all_activity_interactive, $filter_interactive)
585        {
586                $this->t->set_block('admin_activities', 'block_select_filter_interactive', 'select_filter_interactive');
587                $this->t->set_var('selected_filter_interactive_all', (!($filter_interactive))? 'selected="selected"' : '');
588
589                foreach ($all_activity_interactive as $value=>$name)
590                {
591                        $this->t->set_var(array(
592                                'selected_filter_interactive'   => ($filter_interactive == $value)? 'selected="selected"' : '',
593                                'filter_interactive_name'               => $name,
594                                'filter_interactive_value'              => $value
595                        ));
596                        $this->t->parse('select_filter_interactive', 'block_select_filter_interactive', true);
597                }
598        }
599        /**
600        * Show select filter type
601        * @param array $all_activity_types
602        * @param $filter_type
603        * @access public
604        * @return void
605        */
606        function show_select_filter_autoroute($all_activity_autoroute, $filter_autoroute)
607        {
608                $this->t->set_block('admin_activities', 'block_select_filter_autoroute', 'select_filter_autoroute');
609                $this->t->set_var('selected_filter_autoroute_all', (!($filter_autoroute))? 'selected="selected"' : '');
610
611                foreach ($all_activity_autoroute as $value=>$name)
612                {
613                        $this->t->set_var(array(
614                                'selected_filter_autoroute'     => ($filter_autoroute == $value)? 'selected="selected"' : '',
615                                'filter_autoroute_name'         => $name,
616                                'filter_autoroute_value'                => $value
617                        ));
618                        $this->t->parse('select_filter_autoroute', 'block_select_filter_autoroute', true);
619                }
620        }
621       
622        /**
623        * Show select filter type
624        * @param array $all_activity_types
625        * @param $filter_type
626        * @access public
627        * @return void
628        */
629        function update_activities(&$process_activities, $activities_inter, $activities_route)
630        {
631                $num_activities = count($process_activities['data']);
632                for ($i=0; $i < $num_activities; $i++)
633                {
634                        $act_id = $process_activities['data'][$i]['wf_activity_id'];
635                        if ($process_activities['data'][$i]['wf_is_interactive'] == 'y' && !in_array($act_id, $activities_inter))
636                        {
637                                $process_activities['data'][$i]['wf_is_interactive'] = 'n';
638                                $this->activity_manager->set_interactivity($this->wf_p_id, $act_id, 'n');
639                        }
640                        if ($process_activities['data'][$i]['wf_is_interactive'] == 'n' && in_array($act_id, $activities_inter))
641                        {
642                                $process_activities['data'][$i]['wf_is_interactive'] = 'y';
643                                $this->activity_manager->set_interactivity($this->wf_p_id, $act_id, 'y');
644                        }
645                        if ($process_activities['data'][$i]['wf_is_autorouted'] == 'y' && !in_array($act_id, $activities_route))
646                        {
647                                $process_activities['data'][$i]['wf_is_autorouted'] = 'n';
648                                $this->activity_manager->set_autorouting($this->wf_p_id, $act_id, 'n');
649                        }
650                        if ($process_activities['data'][$i]['wf_is_autorouted'] == 'n' && in_array($act_id, $activities_route))
651                        {
652                                $process_activities['data'][$i]['wf_is_autorouted'] = 'y';
653                                $this->activity_manager->set_autorouting($this->wf_p_id, $act_id, 'y');
654                        }
655                }
656        }
657
658        /**
659         *  Add a role to the process
660         *  @param $rolename is the role name
661         *  @param $roledescription is the role description
662         *  @return int new role id
663         */
664        function add_process_role($rolename, $roledescription)
665        {
666                $vars = array(
667                        'wf_name'               => $rolename,
668                        'wf_description'        => $roledescription,
669                );
670                return $this->role_manager->replace_role($this->wf_p_id, 0, $vars);
671        }
672        /**
673         *  Search transitions activities
674         *  @param array $process_activities
675         *  @param int $act_id
676         *  @return int new role id
677         */
678        function search_transitions_act(&$process_activities, $act_id)
679        {
680                for ($i=0; $i < $process_activities['cant']; $i++)
681                {
682                        $id = $process_activities['data'][$i]['wf_activity_id'];
683                        $process_activities['data'][$i]['to'] = $this->activity_manager->transition_exists($this->wf_p_id, $act_id, $id)? 'y' : 'n';
684                        $process_activities['data'][$i]['from'] = $this->activity_manager->transition_exists($this->wf_p_id, $id, $act_id)? 'y' : 'n';
685                }
686        }
687        /**
688         *  Show process activities data
689         *  @param $rolename is the role name
690         *  @param $roledescription is the role description
691         *  @return int new role id
692         */
693        function show_process_activities($process_activities_data)
694        {
695                $this->t->set_block('admin_activities', 'block_process_activities', 'process_activities');
696                $this->t->set_var(array(
697                        'form_process_activities_action'=> $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form'),
698                        'left_arrow'            => $this->nextmatchs->left('index.php', $this->start, $this->total),
699                        'right_arrow'           => $this->nextmatchs->right('index.php', $this->start, $this->total),
700                ));
701                $this->translate_template('block_process_activities');
702
703                $this->t->set_block('admin_activities', 'block_process_activities_header', 'process_activities_header');
704                $this->t->set_block('admin_activities', 'block_process_activities_footer', 'process_activities_footer');
705                if( is_array($process_activities_data) && count($process_activities_data) > 0 )
706                {
707                        $this->t->set_var(array(
708                                'header_name'           => $this->nextmatchs->show_sort_order($this->sort, 'wf_name', $this->order, 'index.php', lang('Name'), array('p_id'=>$this->wf_p_id)),
709                                'header_type'           => $this->nextmatchs->show_sort_order($this->sort, 'wf_type', $this->order, 'index.php', lang('Type'), array('p_id'=>$this->wf_p_id)),
710                                'header_interactive'    => $this->nextmatchs->show_sort_order($this->sort, 'wf_is_interactive', $this->order, 'index.php', lang('Interactive'),  array('p_id'=>$this->wf_p_id)),
711                                'header_route'          => $this->nextmatchs->show_sort_order($this->sort, 'wf_is_autorouted', $this->order, 'index.php', lang('Auto routed'),  array('p_id'=>$this->wf_p_id)),
712                                'header_default_user'   => lang('Default User')
713                        ));
714                        $this->translate_template('block_process_activities_header');
715                        $this->t->parse('process_activities_header', 'block_process_activities_header', True);
716                        $templateServer = &$GLOBALS['workflow']['factory']->getInstance('TemplateServer');
717                        foreach ($process_activities_data as $activity)
718                        {
719                                if($activity['wf_default_user'] == '*' )
720                                {
721                                        $act_default_user = lang('None');
722                                }
723                                else if($activity['wf_default_user'] != '*')
724                                {
725                                        $act_default_user = $GLOBALS['phpgw']->accounts->id2name($activity['wf_default_user']);
726                                }
727                               
728                                $this->t->set_var(array(
729                                        'act_activity_id'       => $activity['wf_activity_id'],
730                                        'act_flowNum'           => $activity['wf_flow_num'],
731                                        'act_href'                      => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form&where2='. $where2 .'&sort_mode2='. $sort_mode2 .'&p_id='. $this->wf_p_id .'&find='. $find .'&where='. $where .'&sort_mode='. $this->sort_mode .'&activity_id='. $activity['wf_activity_id']),
732                                        'act_name'                      => $activity['wf_name'],
733                                        'no_roles'                      => ($activity['wf_roles'] < 1)? '<small>('.lang('no roles').')</small>' : '',
734                                        'act_icon'                      => $this->act_icon($activity['wf_type'],$activity['wf_is_interactive']),
735                                        'act_inter_checked'     => ($activity['wf_is_interactive'] == 'y')? 'checked="checked"' : '',
736                                        'act_route_checked'     => ($activity['wf_is_autorouted'] == 'y')? 'checked="checked"' : '',
737                                        'act_default_user'      => $act_default_user,
738                                        'act_href_edit'         => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminsource.form&p_id='. $this->wf_p_id .'&activity_id='. $activity['wf_activity_id']),
739                                        'act_template'          => ($activity['wf_is_interactive'] == 'y')? '<a href="'. $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminsource.form&p_id='. $this->wf_p_id .'&activity_id='. $activity['wf_activity_id'] .'&template=1') .'"><img src="'. $templateServer->generateImageLink('template.png') .'" alt="' .lang('template') .'" title="' . lang('template') .'" /></a>' : '',
740                                        'img_code'              => $templateServer->generateImageLink('code.png'),
741                                        'color_line'            => $this->nextmatchs->alternate_row_color($tr_color),
742
743                                ));
744                                $this->t->parse('process_activities', 'block_process_activities', True);
745                        }
746                        $this->translate_template('block_process_activities_footer');
747                        $this->t->parse('process_activities_footer', 'block_process_activities_footer', True);
748                }
749                else
750                {
751                        $this->t->set_var('process_activities_header', '');
752                        $this->t->set_var('process_activities', '<tr><td colspan="7" align="center">'. lang('There are no processes with the current filter')  .'</td></tr>');
753                        $this->t->set_var('process_activities_footer', '');
754                }
755        }
756/**
757 * Show transitions table
758 * @var array $process_transition
759 * @access public
760 * @return void
761 */
762        function show_transitions_table($process_transitions)
763        {
764                $this->t->set_block('admin_activities', 'block_transitions_table', 'transitions_table');
765                $this->t->set_block('admin_activities', 'block_transitions_table_footer', 'transitions_table_footer');
766                $this->translate_template('block_transitions_table');
767                $this->translate_template('block_transitions_table_footer');
768
769                foreach ($process_transitions as $transition)
770                {
771                        $this->t->set_var(array(
772                                'trans_actFromId'       => $transition['wf_act_from_id'],
773                                'trans_actToId'         => $transition['wf_act_to_id'],
774                                'trans_href_from'       => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form&where2='. $where2 .'&sort_mode2='. $sort_mode2 .'&p_id='. $this->wf_p_id .'&find='. $find .'&where='. $where .'&sort_mode='. $this->sort_mode .'&activity_id='. $transition['wf_act_from_id']),
775                                'trans_actFromName'     => $transition['wf_act_from_name'],
776                                'trans_arrow'           => $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateImageLink('next.gif'),
777                                'trans_href_to'         => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form&where2='. $where2 .'&sort_mode2='. $sort_mode2 .'&p_id='. $this->wf_p_id .'&find='. $find .'&where='. $where .'&sort_mode='. $this->sort_mode .'&activity_id='. $transition['wf_act_to_id']),
778                                'trans_actToName'       => $transition['wf_act_to_name'],
779                                'color_line'            => $this->nextmatchs->alternate_row_color($tr_color),
780                        ));
781                        $this->t->parse('transitions_table', 'block_transitions_table', true);
782                }
783                if (!count($process_transitions))
784                {
785                        $this->t->set_var('transitions_table', '<tr><td colspan="2" align="center">'. lang('There are no transitions defined')  .'</td></tr>');
786                        $this->t->set_var('transitions_table_footer', '');
787                }
788                else
789                {
790                        $this->t->parse('transitions_table_footer', 'block_transitions_table_footer', true);
791                }
792        }
793
794        /**
795         * Build select box with all transitions activities
796         * @param string  $var_name             
797         * @param array   $process_activities_data array of process data
798         * @param boolean $multiple
799         * @param boolean $show_all show all list
800         * @param boolean $from_or_to
801         * @access public
802         * @return string html code with select box
803         */
804        function build_select_transition($var_name, $process_activities_data, $multiple=false,
805        $show_all=true, $from_or_to=false)
806        {
807                //echo "process_activities_data: <pre>";print_r($process_activities_data);echo "</pre>";
808                $select_str = "<select name='$var_name'" . (($multiple)? " multiple='multiple' size='5'" : "" ) . ">";
809                if ($show_all) $select_str .= '<option value="">'. lang('All') .'</option>';
810               
811                foreach ($process_activities_data as $activity)
812                {
813                        if ($from_or_to && isset($activity[$from_or_to]) && $activity[$from_or_to] == 'y')
814                        {
815                                $selected = 'selected="selected"';
816                        }
817                        else
818                        {
819                                $selected = '';
820                        }
821                        $select_str .= '<option value="'. $activity['wf_activity_id'] .'" '. $selected .'>'. $activity['wf_name'] .'</option>';
822                }
823                $select_str .= "</select>\n";
824                return $select_str;
825        }
826       
827        /**
828         * Build select box with all transitions activities filtered
829         * @param string  $var_name             
830         * @param array   $process_activities_data array of process data
831         * @param boolean $multiple
832         * @param boolean $show_all show all list
833         * @param boolean $from_or_to
834         * @access public
835         * @return string html code with select box
836         */     
837        function build_select_transition_filtered($var_name, $process_activities_data, $multiple=false, $show_all=true, $from=false)
838        {
839                $select_str = "<select name='$var_name'" . (($multiple)? " multiple='multiple' size='5'" : "" ) . ">";
840                if ($show_all) $select_str .= '<option value="">'. lang('All') .'</option>';
841               
842                if( is_array($process_activities_data) && count($process_activities_data) > 0 )
843                {
844                        foreach ($process_activities_data as $activity)
845                        {
846                                if ($from && $activity['wf_activity_id'] == $from )
847                                {
848                                        $selected = 'selected="selected"';
849                                }
850                                else
851                                {
852                                        $selected = '';
853                                }
854                                $select_str .= '<option value="'. $activity['wf_activity_id'] .'" '. $selected .'>'. $activity['wf_name'] .'</option>';
855                        }
856                }
857                $select_str .= "</select>\n";
858                return $select_str;
859        }
860
861        /**
862         * Save the edited activity.
863         *
864         * @param int $activity_id
865         * @param string $name
866         * @param string $description
867         * @param string $type
868         * @param string $default_user
869         * @param bool $is_interative
870         * @param bool $is_autorouted
871         * @return mixed Return the activity_id or false in case of error, $this->message is set in case of error
872         * @access public
873         */
874        function save_activity($activity_id, $name, $description, $type, $default_user, $is_interactive, $is_autorouted, $userole, $userole_ro, $useagent, $rolename, $menu_path)
875        {
876                $is_interactive = ($is_interactive == 'on') ? 'y' : 'n';
877                $is_autorouted = ($is_autorouted == 'on') ? 'y' : 'n';
878                $vars = array(
879                        'wf_name' => $name,
880                        'wf_description' => $description,
881                        'wf_activity_id' => $activity_id,
882                        'wf_is_interactive' => $is_interactive,
883                        'wf_is_autorouted' => $is_autorouted,
884                        'wf_default_user' => $default_user,
885                        'wf_type' => $type,
886                        'wf_menu_path' => $menu_path
887                );
888
889                if( strlen($name) > 0 )
890                {
891                        if ($this->activity_manager->activity_name_exists($this->wf_p_id, $name, $activity_id))
892                        {
893                                $this->message[] = ($name . ': '. lang('activity name already exists'));
894                                return false;
895                        }
896                }
897                else
898                {
899                        $this->message[] = lang('Enter an activity name');
900                        return false;
901                }
902
903                $activity_id = $this->activity_manager->replace_activity($this->wf_p_id, $activity_id, $vars);
904               
905                // assign role to activity
906                if ($userole)
907                {
908                        $this->activity_manager->add_activity_role($activity_id, $userole, ($userole_ro=='on'));
909                }
910               
911                // assign agent to activity
912                if ($useagent)
913                {
914                        $this->activity_manager->add_activity_agent($activity_id, $useagent);
915                }
916
917                //save agent configuration datas if any
918                if (isset($_POST['wf_agent']))
919                {
920                        $agents_conf =& $_POST['wf_agent'];
921                       
922                        //retrieve agents list
923                        $activity_agents =& $this->activity_manager->get_activity_agents($activity_id);
924                        //for all agents we create ui_agent object to handle admin agents displays and savings
925                        foreach ($activity_agents as $agent)
926                        {
927                                //create an empty temp ui_agent object
928                                $ui_agent =& createObject('workflow.ui_agent_'.$agent['wf_agent_type']);
929                                //build this object BUT without loading actual data
930                                //because we will save next values soon
931                                $ui_agent->load($agent['wf_agent_id'],false);
932                                //store it in an array
933                                $this->agents[$agent['wf_agent_type']] = $ui_agent;
934                                //delete the temp object
935                                unset($ui_agent);
936                        }
937                        // now we save the data obtained from the form in theses agents
938                        foreach ($agents_conf as $typeagent => $confarray)
939                        {
940                                $this->agents[$typeagent]->save($confarray);
941                        }
942                }
943
944                // add activity transitions
945                if (isset($_POST['add_tran_from']))
946                {
947                        foreach ($_POST['add_tran_from'] as $act_from)
948                        {
949                                $this->activity_manager->add_transition($this->wf_p_id, $act_from, $activity_id);
950                        }
951                }
952                if (isset($_POST['add_tran_to']))
953                {
954                        foreach ($_POST['add_tran_to'] as $act_to)
955                        {
956                                $this->activity_manager->add_transition($this->wf_p_id, $activity_id, $act_to);
957                        }
958                }
959                $this->activity_manager->validate_process_activities($this->wf_p_id);
960               
961               
962                return $activity_id;
963        }
964        /**
965         * Delete selected activities
966         * @param array $activities_ids
967         * @return bool true always
968         * @access public
969         */
970        function delete_activities($activities_ids)
971        {
972                foreach ($activities_ids as $act_id)
973                {
974                        $this->activity_manager->remove_activity($this->wf_p_id, $act_id);
975                }
976                return true;
977        }
978
979        function delete_transitions($transitions)
980        {
981                if( is_array($transitions) && count($transitions) > 0 ) {
982                        foreach (array_keys($transitions) as $transition)
983                        {
984                                $parts = explode('_', $transition);
985                                $this->activity_manager->remove_transition($parts[0], $parts[1]);
986                        }
987                        $this->message[] = lang('Transitions removed successfully');
988                }
989                else
990                {
991                        $this->message[] = lang('Select a transition to remove');
992                }
993        }
994        /**
995         * Add a transition activity
996         * @param int $from from activity
997         * @param int $to   next activity
998         * @return string Error or success message
999         * @access public
1000         */
1001        function add_transition($from, $to)
1002        {
1003                if ($this->activity_manager->add_transition($this->wf_p_id, $from, $to))
1004                {
1005                        $this->activity_manager->validate_process_activities($this->wf_p_id);
1006                        return lang('New transition added');
1007                }
1008                $error_msg =  $this->activity_manager->get_error(false, _DEBUG);
1009                return lang("Couldn't add transition"). '; '. $error_msg[0];
1010        }
1011        /**
1012         * Show actual process graph
1013         * @access public
1014         */
1015        function show_graph()
1016        {
1017                $proc_info = $this->process_manager->get_process($this->wf_p_id);
1018                $image_name = $proc_info['wf_normalized_name'] . SEP . 'graph' . SEP . $proc_info['wf_normalized_name'] . '.png';
1019                $image = GALAXIA_PROCESSES . SEP . $image_name;
1020                if ($GLOBALS['workflow']['factory']->getInstance('BrowserInfo')->isOpera())
1021                        $maximumDimension = 1000000;
1022                else
1023                        $maximumDimension = 2500;
1024
1025                $dims = getimagesize($image);
1026                list($originalWidth, $originalHeight) = $dims;
1027
1028                /* the image must be resized */
1029                if (max($originalWidth, $originalHeight) > $maximumDimension)
1030                {
1031                        /* define the new width and height */
1032                        $newWidth = $newHeight = $maximumDimension;
1033                        if ($originalWidth > $originalHeight)
1034                                $newHeight = $maximumDimension * ($originalHeight / $originalWidth);
1035                        else
1036                                $newWidth = $maximumDimension * ($originalWidth / $originalHeight);
1037
1038                        /* create the new image and send to the browser */
1039                        $smallerImage = imagecreatetruecolor($newWidth, $newHeight);
1040                        imagecopyresampled($smallerImage, imagecreatefrompng($image), 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight);
1041                        header('content-disposition: inline; filename=' . $image_name);
1042                        header('content-type: ' . $dims['mime']);
1043                        imagepng($smallerImage);
1044                }
1045                else
1046                {
1047                        header('content-disposition: inline; filename=' . $image_name);
1048                        header('content-type: ' . $dims['mime']);
1049                        header('content-length: ' . filesize($image));
1050                        readfile($image);
1051                }
1052        }
1053       
1054        /**
1055         * Dislays the activity agents config rows
1056         * @return void
1057         * @access public
1058         */
1059        function display_agents_rows()
1060        {
1061                if (empty($this->agents))
1062                {
1063                        $this->t->set_var(array('agents_config_rows' => ''));
1064                }
1065                else
1066                {
1067                        $this->t->set_file('admin_agents', 'admin_agents.tpl');
1068                        foreach ($this->agents as $ui_agent)
1069                        {
1070                                //this is parsing the agent's admin template in the given template var
1071                                $ui_agent->showAdminActivityOptions('each_agent_rows');
1072                        }
1073                        $this->translate_template('admin_agents');
1074                                                                                                $this->t->parse('agents_config_rows', 'admin_agents');
1075                }
1076        }
1077}
1078?>
Note: See TracBrowser for help on using the repository browser.