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

Revision 1710, 39.8 KB checked in by rufino, 14 years ago (diff)

Ticket #792 - Cria a possibilidade de ter um perfil padrão cada atividade no Workflow

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