source: branches/2.2/workflow/inc/class.ui_adminactivities.inc.php @ 3167

Revision 3167, 40.2 KB checked in by viani, 14 years ago (diff)

Ticket #1135 - Merged r1990:3166 from /trunk/workflow into /branches/2.2/workflow

  • Property svn:executable set to *
Line 
1<?php
2
3require_once dirname(__FILE__) . SEP . 'class.WorkflowUtils.inc.php';
4require_once 'engine' . SEP . 'config.egw.inc.php';
5/**
6 * @package Workflow
7 * @license http://www.gnu.org/copyleft/gpl.html GPL
8 */
9class ui_adminactivities extends WorkflowUtils
10{
11        /**
12         * @var array $public_functions Array of public functions
13         * @access public
14         */
15        var $public_functions = array(
16                'form'                  => true,
17                'show_graph'    => true
18        );
19/**
20 * @var object $process_manager Process manager
21 * @access public
22 */
23        var $process_manager;           
24/**
25 * @var object $activity_manager
26 * @access public
27 */
28        var $activity_manager;
29/**
30 * @var object $role_manager
31 * @access public
32 */
33        var $role_manager;
34/**
35 * @var $where2
36 * @access public
37 */     
38        var $where2;
39        /**
40         * @var object $sort_mode2
41         * @access public
42         */     
43        var $sort_mode2;
44        /**
45         * @var array $agents agents handling
46         * @access public
47         */
48        var $agents=Array();
49        /**
50         * @var object $workflow_acl
51         * @access public
52         */
53        var $workflow_acl;
54        /**
55         * @var object $fs object for reading process folder 
56         * @access public
57         */
58        var $fs;
59        /**
60         * @var array  $invalidFiles invalid files list
61         * @access public
62         */
63        var $invalidFiles = array();     
64        /**
65         * Constructor da classe ui_adminactivities
66         *
67         * @access public
68         * @return void
69         */     
70        function ui_adminactivities()
71        {
72                parent::WorkflowUtils();
73
74                $this->workflow_acl = Factory::getInstance('workflow_acl');
75                $denyAccess = true;
76                if ($this->workflow_acl->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']))
77                {
78                        /* the user is an Expresso/Workflow admin */
79                        $denyAccess = false;
80                }
81                else
82                {
83                        if ($GLOBALS['phpgw']->acl->check('admin_workflow', 1, 'workflow'))
84                        {
85                                /* check if the user can admin the informed process */
86                                if ($this->wf_p_id != 0)
87                                        $denyAccess = !$this->workflow_acl->check_process_access($GLOBALS['phpgw_info']['user']['account_id'], $this->wf_p_id);
88                                else
89                                        $denyAccess = false;
90                        }
91                }
92
93                /* allow regular users to see the process graph */
94                if ($_GET['menuaction'] == "workflow.ui_adminactivities.show_graph")
95                        $denyAccess = false;
96
97                if ($denyAccess)
98                {
99                        $GLOBALS['phpgw']->common->phpgw_header();
100                        echo parse_navbar();
101                        echo lang('access not permitted');
102                        $GLOBALS['phpgw']->log->message('F-Abort, Unauthorized access to workflow.ui_adminprocesses');
103                        $GLOBALS['phpgw']->log->commit();
104                        $GLOBALS['phpgw']->common->phpgw_exit();
105                }
106
107                $this->process_manager  = Factory::getInstance('workflow_processmanager');
108                $this->activity_manager = Factory::getInstance('workflow_activitymanager');
109                $this->role_manager     = Factory::getInstance('workflow_rolemanager');
110                $this->fs = &Factory::newInstance('FsUtils'); /* gets instance */
111
112        }
113               
114        /**
115         * Build the form for Activities Administration
116         * @return void
117         * @access public
118         */
119        function form()
120        {
121                $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['workflow']['title'] . ' - ' . lang('Admin Process Activities');
122                $GLOBALS['phpgw']->common->phpgw_header();
123                echo parse_navbar();
124
125                $this->t->set_file('admin_activities', 'admin_activities.tpl');
126                $this->t->set_block('admin_activities', 'block_select_type', 'select_type');
127                $this->t->set_block('admin_activities', 'block_activity_roles', 'activity_roles');
128                $this->t->set_block('admin_activities', 'block_process_roles', 'process_roles');
129                $this->t->set_block('admin_activities', 'block_activity_agents', 'activity_agents');
130                $this->t->set_block('admin_activities', 'block_default_roles', 'default_roles');
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 = &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                $this->t->set_var(array(
522                        'default_user_option_checked_0' => ($activity_info['wf_default_user'][0] != 'p')? "checked='checked'": '',
523                        'default_user_option_checked_1' => ($activity_info['wf_default_user'][0] == 'p')? "checked='checked'": '',
524                ));
525
526                // fill process roles
527                foreach ($process_roles['data'] as $role)
528                {
529                        $this->t->set_var(array(
530                                'proc_roleId'   => $role['wf_role_id'],
531                                'proc_roleName' => $role['wf_name']
532                        ));
533                        $this->t->parse('process_roles', 'block_process_roles', True);
534                }
535
536                // fill process roles for activity default role
537                foreach ($process_roles['data'] as $role)
538                {
539                        $role_id = 'p' . $role['wf_role_id'];
540                        $this->t->set_var(array(
541                                'proc_roleId'                   => $role_id,
542                                'proc_role_selected'    => ($role_id == $activity_info['wf_default_user'])? 'selected="selected"' : '',
543                                'proc_roleName'                 => $role['wf_name']
544                        ));
545                        $this->t->parse('default_roles', 'block_default_roles', true);
546                }
547
548                // fill agents select
549                foreach ($agents_list as $agent)
550                {
551                        $this->t->set_var(array(
552                                'select_agentType'      => $agent['wf_agent_type']
553                        ));
554                        $this->t->parse('select_agents', 'block_select_agents', True);
555                }
556
557                // fill list of transitions table
558                $this->show_transitions_table($process_transitions);
559                $this->t->set_var('filter_type_value', $filter_type);
560                $this->t->set_var('filter_interactive_value', $filter_interactive);
561                $this->t->set_var('filter_autoroute_value', $filter_autoroute);
562                $this->t->set_var('find_value', $find);
563
564                // create graph
565                $this->activity_manager->build_process_graph($this->wf_p_id);
566
567                $this->translate_template('admin_activities');
568                $this->t->pparse('output', 'admin_activities');
569                $GLOBALS['phpgw']->common->phpgw_footer();
570        }
571        /**
572        * Show select filter type
573        * @param array $all_activity_types
574        * @param $filter_type
575        * @access public
576        * @return void
577        */
578        function show_select_filter_type($all_activity_types, $filter_type)
579        {
580                $this->t->set_block('admin_activities', 'block_select_filter_type', 'select_filter_type');
581                $this->t->set_var('selected_filter_type_all', (!($filter_type))? 'selected="selected"' : '');
582
583                foreach ($all_activity_types as $type)
584                {
585                        $this->t->set_var(array(
586                                'selected_filter_type'  => ($filter_type == $type)? 'selected="selected"' : '',
587                                'filter_type_name'      => lang($type),
588                                'filter_type_en_name'   => $type
589                        ));
590                        $this->t->parse('select_filter_type', 'block_select_filter_type', true);
591                }
592        }
593       
594        /**
595        * Show select filter type
596        * @param array $all_activity_types
597        * @param $filter_type
598        * @access public
599        * @return void
600        */
601        function show_select_filter_interactive($all_activity_interactive, $filter_interactive)
602        {
603                $this->t->set_block('admin_activities', 'block_select_filter_interactive', 'select_filter_interactive');
604                $this->t->set_var('selected_filter_interactive_all', (!($filter_interactive))? 'selected="selected"' : '');
605
606                foreach ($all_activity_interactive as $value=>$name)
607                {
608                        $this->t->set_var(array(
609                                'selected_filter_interactive'   => ($filter_interactive == $value)? 'selected="selected"' : '',
610                                'filter_interactive_name'               => $name,
611                                'filter_interactive_value'              => $value
612                        ));
613                        $this->t->parse('select_filter_interactive', 'block_select_filter_interactive', true);
614                }
615        }
616        /**
617        * Show select filter type
618        * @param array $all_activity_types
619        * @param $filter_type
620        * @access public
621        * @return void
622        */
623        function show_select_filter_autoroute($all_activity_autoroute, $filter_autoroute)
624        {
625                $this->t->set_block('admin_activities', 'block_select_filter_autoroute', 'select_filter_autoroute');
626                $this->t->set_var('selected_filter_autoroute_all', (!($filter_autoroute))? 'selected="selected"' : '');
627
628                foreach ($all_activity_autoroute as $value=>$name)
629                {
630                        $this->t->set_var(array(
631                                'selected_filter_autoroute'     => ($filter_autoroute == $value)? 'selected="selected"' : '',
632                                'filter_autoroute_name'         => $name,
633                                'filter_autoroute_value'                => $value
634                        ));
635                        $this->t->parse('select_filter_autoroute', 'block_select_filter_autoroute', true);
636                }
637        }
638       
639        /**
640        * Show select filter type
641        * @param array $all_activity_types
642        * @param $filter_type
643        * @access public
644        * @return void
645        */
646        function update_activities(&$process_activities, $activities_inter, $activities_route)
647        {
648                $num_activities = count($process_activities['data']);
649                for ($i=0; $i < $num_activities; $i++)
650                {
651                        $act_id = $process_activities['data'][$i]['wf_activity_id'];
652                        if ($process_activities['data'][$i]['wf_is_interactive'] == 'y' && !in_array($act_id, $activities_inter))
653                        {
654                                $process_activities['data'][$i]['wf_is_interactive'] = 'n';
655                                $this->activity_manager->set_interactivity($this->wf_p_id, $act_id, 'n');
656                        }
657                        if ($process_activities['data'][$i]['wf_is_interactive'] == 'n' && in_array($act_id, $activities_inter))
658                        {
659                                $process_activities['data'][$i]['wf_is_interactive'] = 'y';
660                                $this->activity_manager->set_interactivity($this->wf_p_id, $act_id, 'y');
661                        }
662                        if ($process_activities['data'][$i]['wf_is_autorouted'] == 'y' && !in_array($act_id, $activities_route))
663                        {
664                                $process_activities['data'][$i]['wf_is_autorouted'] = 'n';
665                                $this->activity_manager->set_autorouting($this->wf_p_id, $act_id, 'n');
666                        }
667                        if ($process_activities['data'][$i]['wf_is_autorouted'] == 'n' && in_array($act_id, $activities_route))
668                        {
669                                $process_activities['data'][$i]['wf_is_autorouted'] = 'y';
670                                $this->activity_manager->set_autorouting($this->wf_p_id, $act_id, 'y');
671                        }
672                }
673        }
674
675        /**
676         *  Add a role to the process
677         *  @param $rolename is the role name
678         *  @param $roledescription is the role description
679         *  @return int new role id
680         */
681        function add_process_role($rolename, $roledescription)
682        {
683                $vars = array(
684                        'wf_name'               => $rolename,
685                        'wf_description'        => $roledescription,
686                );
687                return $this->role_manager->replace_role($this->wf_p_id, 0, $vars);
688        }
689        /**
690         *  Search transitions activities
691         *  @param array $process_activities
692         *  @param int $act_id
693         *  @return int new role id
694         */
695        function search_transitions_act(&$process_activities, $act_id)
696        {
697                for ($i=0; $i < $process_activities['cant']; $i++)
698                {
699                        $id = $process_activities['data'][$i]['wf_activity_id'];
700                        $process_activities['data'][$i]['to'] = $this->activity_manager->transition_exists($this->wf_p_id, $act_id, $id)? 'y' : 'n';
701                        $process_activities['data'][$i]['from'] = $this->activity_manager->transition_exists($this->wf_p_id, $id, $act_id)? 'y' : 'n';
702                }
703        }
704        /**
705         *  Show process activities data
706         *  @param $rolename is the role name
707         *  @param $roledescription is the role description
708         *  @return int new role id
709         */
710        function show_process_activities($process_activities_data)
711        {
712                $this->t->set_block('admin_activities', 'block_process_activities', 'process_activities');
713                $this->t->set_var(array(
714                        'form_process_activities_action'=> $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminactivities.form'),
715                        'left_arrow'            => $this->nextmatchs->left('index.php', $this->start, $this->total),
716                        'right_arrow'           => $this->nextmatchs->right('index.php', $this->start, $this->total),
717                ));
718                $this->translate_template('block_process_activities');
719
720                $this->t->set_block('admin_activities', 'block_process_activities_header', 'process_activities_header');
721                $this->t->set_block('admin_activities', 'block_process_activities_footer', 'process_activities_footer');
722                if( is_array($process_activities_data) && count($process_activities_data) > 0 )
723                {
724                        $this->t->set_var(array(
725                                'header_name'           => $this->nextmatchs->show_sort_order($this->sort, 'wf_name', $this->order, 'index.php', lang('Name'), array('p_id'=>$this->wf_p_id)),
726                                'header_type'           => $this->nextmatchs->show_sort_order($this->sort, 'wf_type', $this->order, 'index.php', lang('Type'), array('p_id'=>$this->wf_p_id)),
727                                '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)),
728                                '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)),
729                                'header_default_user'   => lang('Default User')
730                        ));
731                        $this->translate_template('block_process_activities_header');
732                        $this->t->parse('process_activities_header', 'block_process_activities_header', True);
733                        $templateServer = &Factory::getInstance('TemplateServer');
734                        foreach ($process_activities_data as $activity)
735                        {
736                                if($activity['wf_default_user'] == '*' )
737                                {
738                                        $act_default_user = lang('None');
739                                }
740                                else if($activity['wf_default_user'] != '*')
741                                {
742                                        $act_default_user = $GLOBALS['phpgw']->accounts->id2name($activity['wf_default_user']);
743                                }
744                               
745                                $this->t->set_var(array(
746                                        'act_activity_id'       => $activity['wf_activity_id'],
747                                        'act_flowNum'           => $activity['wf_flow_num'],
748                                        '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']),
749                                        'act_name'                      => $activity['wf_name'],
750                                        'no_roles'                      => ($activity['wf_roles'] < 1)? '<small>('.lang('no roles').')</small>' : '',
751                                        'act_icon'                      => $this->act_icon($activity['wf_type'],$activity['wf_is_interactive']),
752                                        'act_inter_checked'     => ($activity['wf_is_interactive'] == 'y')? 'checked="checked"' : '',
753                                        'act_route_checked'     => ($activity['wf_is_autorouted'] == 'y')? 'checked="checked"' : '',
754                                        'act_default_user'      => $act_default_user,
755                                        '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']),
756                                        '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>' : '',
757                                        'img_code'              => $templateServer->generateImageLink('code.png'),
758                                        'color_line'            => $this->nextmatchs->alternate_row_color($tr_color),
759
760                                ));
761                                $this->t->parse('process_activities', 'block_process_activities', True);
762                        }
763                        $this->translate_template('block_process_activities_footer');
764                        $this->t->parse('process_activities_footer', 'block_process_activities_footer', True);
765                }
766                else
767                {
768                        $this->t->set_var('process_activities_header', '');
769                        $this->t->set_var('process_activities', '<tr><td colspan="7" align="center">'. lang('There are no processes with the current filter')  .'</td></tr>');
770                        $this->t->set_var('process_activities_footer', '');
771                }
772        }
773/**
774 * Show transitions table
775 * @var array $process_transition
776 * @access public
777 * @return void
778 */
779        function show_transitions_table($process_transitions)
780        {
781                $this->t->set_block('admin_activities', 'block_transitions_table', 'transitions_table');
782                $this->t->set_block('admin_activities', 'block_transitions_table_footer', 'transitions_table_footer');
783                $this->translate_template('block_transitions_table');
784                $this->translate_template('block_transitions_table_footer');
785
786                foreach ($process_transitions as $transition)
787                {
788                        $this->t->set_var(array(
789                                'trans_actFromId'       => $transition['wf_act_from_id'],
790                                'trans_actToId'         => $transition['wf_act_to_id'],
791                                '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']),
792                                'trans_actFromName'     => $transition['wf_act_from_name'],
793                                'trans_arrow'           => Factory::getInstance('TemplateServer')->generateImageLink('next.gif'),
794                                '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']),
795                                'trans_actToName'       => $transition['wf_act_to_name'],
796                                'color_line'            => $this->nextmatchs->alternate_row_color($tr_color),
797                        ));
798                        $this->t->parse('transitions_table', 'block_transitions_table', true);
799                }
800                if (!count($process_transitions))
801                {
802                        $this->t->set_var('transitions_table', '<tr><td colspan="2" align="center">'. lang('There are no transitions defined')  .'</td></tr>');
803                        $this->t->set_var('transitions_table_footer', '');
804                }
805                else
806                {
807                        $this->t->parse('transitions_table_footer', 'block_transitions_table_footer', true);
808                }
809        }
810
811        /**
812         * Build select box with all transitions activities
813         * @param string  $var_name             
814         * @param array   $process_activities_data array of process data
815         * @param boolean $multiple
816         * @param boolean $show_all show all list
817         * @param boolean $from_or_to
818         * @access public
819         * @return string html code with select box
820         */
821        function build_select_transition($var_name, $process_activities_data, $multiple=false,
822        $show_all=true, $from_or_to=false)
823        {
824                //echo "process_activities_data: <pre>";print_r($process_activities_data);echo "</pre>";
825                $select_str = "<select name='$var_name'" . (($multiple)? " multiple='multiple' size='5'" : "" ) . ">";
826                if ($show_all) $select_str .= '<option value="">'. lang('All') .'</option>';
827               
828                foreach ($process_activities_data as $activity)
829                {
830                        if ($from_or_to && isset($activity[$from_or_to]) && $activity[$from_or_to] == 'y')
831                        {
832                                $selected = 'selected="selected"';
833                        }
834                        else
835                        {
836                                $selected = '';
837                        }
838                        $select_str .= '<option value="'. $activity['wf_activity_id'] .'" '. $selected .'>'. $activity['wf_name'] .'</option>';
839                }
840                $select_str .= "</select>\n";
841                return $select_str;
842        }
843       
844        /**
845         * Build select box with all transitions activities filtered
846         * @param string  $var_name             
847         * @param array   $process_activities_data array of process data
848         * @param boolean $multiple
849         * @param boolean $show_all show all list
850         * @param boolean $from_or_to
851         * @access public
852         * @return string html code with select box
853         */     
854        function build_select_transition_filtered($var_name, $process_activities_data, $multiple=false, $show_all=true, $from=false)
855        {
856                $select_str = "<select name='$var_name'" . (($multiple)? " multiple='multiple' size='5'" : "" ) . ">";
857                if ($show_all) $select_str .= '<option value="">'. lang('All') .'</option>';
858               
859                if( is_array($process_activities_data) && count($process_activities_data) > 0 )
860                {
861                        foreach ($process_activities_data as $activity)
862                        {
863                                if ($from && $activity['wf_activity_id'] == $from )
864                                {
865                                        $selected = 'selected="selected"';
866                                }
867                                else
868                                {
869                                        $selected = '';
870                                }
871                                $select_str .= '<option value="'. $activity['wf_activity_id'] .'" '. $selected .'>'. $activity['wf_name'] .'</option>';
872                        }
873                }
874                $select_str .= "</select>\n";
875                return $select_str;
876        }
877
878        /**
879         * Save the edited activity.
880         *
881         * @param int $activity_id
882         * @param string $name
883         * @param string $description
884         * @param string $type
885         * @param string $default_user
886         * @param bool $is_interative
887         * @param bool $is_autorouted
888         * @return mixed Return the activity_id or false in case of error, $this->message is set in case of error
889         * @access public
890         */
891        function save_activity($activity_id, $name, $description, $type, $default_user, $is_interactive, $is_autorouted, $userole, $userole_ro, $useagent, $rolename, $menu_path)
892        {
893                $is_interactive = ($is_interactive == 'on') ? 'y' : 'n';
894                $is_autorouted = ($is_autorouted == 'on') ? 'y' : 'n';
895                $vars = array(
896                        'wf_name' => $name,
897                        'wf_description' => $description,
898                        'wf_activity_id' => $activity_id,
899                        'wf_is_interactive' => $is_interactive,
900                        'wf_is_autorouted' => $is_autorouted,
901                        'wf_default_user' => $default_user,
902                        'wf_type' => $type,
903                        'wf_menu_path' => $menu_path
904                );
905
906                if( strlen($name) > 0 )
907                {
908                        if ($this->activity_manager->activity_name_exists($this->wf_p_id, $name, $activity_id))
909                        {
910                                $this->message[] = ($name . ': '. lang('activity name already exists'));
911                                return false;
912                        }
913                }
914                else
915                {
916                        $this->message[] = lang('Enter an activity name');
917                        return false;
918                }
919
920                $activity_id = $this->activity_manager->replace_activity($this->wf_p_id, $activity_id, $vars);
921               
922                // assign role to activity
923                if ($userole)
924                {
925                        $this->activity_manager->add_activity_role($activity_id, $userole, ($userole_ro=='on'));
926                }
927               
928                // assign agent to activity
929                if ($useagent)
930                {
931                        $this->activity_manager->add_activity_agent($activity_id, $useagent);
932                }
933
934                //save agent configuration datas if any
935                if (isset($_POST['wf_agent']))
936                {
937                        $agents_conf =& $_POST['wf_agent'];
938                       
939                        //retrieve agents list
940                        $activity_agents =& $this->activity_manager->get_activity_agents($activity_id);
941                        //for all agents we create ui_agent object to handle admin agents displays and savings
942                        foreach ($activity_agents as $agent)
943                        {
944                                //create an empty temp ui_agent object
945                                $ui_agent =& createObject('workflow.ui_agent_'.$agent['wf_agent_type']);
946                                //build this object BUT without loading actual data
947                                //because we will save next values soon
948                                $ui_agent->load($agent['wf_agent_id'],false);
949                                //store it in an array
950                                $this->agents[$agent['wf_agent_type']] = $ui_agent;
951                                //delete the temp object
952                                unset($ui_agent);
953                        }
954                        // now we save the data obtained from the form in theses agents
955                        foreach ($agents_conf as $typeagent => $confarray)
956                        {
957                                $this->agents[$typeagent]->save($confarray);
958                        }
959                }
960
961                // add activity transitions
962                if (isset($_POST['add_tran_from']))
963                {
964                        foreach ($_POST['add_tran_from'] as $act_from)
965                        {
966                                $this->activity_manager->add_transition($this->wf_p_id, $act_from, $activity_id);
967                        }
968                }
969                if (isset($_POST['add_tran_to']))
970                {
971                        foreach ($_POST['add_tran_to'] as $act_to)
972                        {
973                                $this->activity_manager->add_transition($this->wf_p_id, $activity_id, $act_to);
974                        }
975                }
976                $this->activity_manager->validate_process_activities($this->wf_p_id);
977               
978               
979                return $activity_id;
980        }
981        /**
982         * Delete selected activities
983         * @param array $activities_ids
984         * @return bool true always
985         * @access public
986         */
987        function delete_activities($activities_ids)
988        {
989                foreach ($activities_ids as $act_id)
990                {
991                        $this->activity_manager->remove_activity($this->wf_p_id, $act_id);
992                }
993                return true;
994        }
995
996        function delete_transitions($transitions)
997        {
998                if( is_array($transitions) && count($transitions) > 0 ) {
999                        foreach (array_keys($transitions) as $transition)
1000                        {
1001                                $parts = explode('_', $transition);
1002                                $this->activity_manager->remove_transition($parts[0], $parts[1]);
1003                        }
1004                        $this->message[] = lang('Transitions removed successfully');
1005                }
1006                else
1007                {
1008                        $this->message[] = lang('Select a transition to remove');
1009                }
1010        }
1011        /**
1012         * Add a transition activity
1013         * @param int $from from activity
1014         * @param int $to   next activity
1015         * @return string Error or success message
1016         * @access public
1017         */
1018        function add_transition($from, $to)
1019        {
1020                if ($this->activity_manager->add_transition($this->wf_p_id, $from, $to))
1021                {
1022                        $this->activity_manager->validate_process_activities($this->wf_p_id);
1023                        return lang('New transition added');
1024                }
1025                $error_msg =  $this->activity_manager->get_error(false, _DEBUG);
1026                return lang("Couldn't add transition"). '; '. $error_msg[0];
1027        }
1028        /**
1029         * Show actual process graph
1030         * @access public
1031         */
1032        function show_graph()
1033        {
1034                $proc_info = $this->process_manager->get_process($this->wf_p_id);
1035                $image_name = $proc_info['wf_normalized_name'] . SEP . 'graph' . SEP . $proc_info['wf_normalized_name'] . '.png';
1036                $image = GALAXIA_PROCESSES . SEP . $image_name;
1037                if (file_exists($image))
1038                {
1039                        if (Factory::getInstance('BrowserInfo')->isOpera())
1040                                $maximumDimension = 1000000;
1041                        else
1042                                $maximumDimension = 2500;
1043
1044                        $dims = getimagesize($image);
1045                        list($originalWidth, $originalHeight) = $dims;
1046
1047                        /* the image must be resized */
1048                        if (max($originalWidth, $originalHeight) > $maximumDimension)
1049                        {
1050                                /* define the new width and height */
1051                                $newWidth = $newHeight = $maximumDimension;
1052                                if ($originalWidth > $originalHeight)
1053                                        $newHeight = $maximumDimension * ($originalHeight / $originalWidth);
1054                                else
1055                                        $newWidth = $maximumDimension * ($originalWidth / $originalHeight);
1056
1057                                /* create the new image and send to the browser */
1058                                $smallerImage = imagecreatetruecolor($newWidth, $newHeight);
1059                                imagecopyresampled($smallerImage, imagecreatefrompng($image), 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight);
1060                                header('content-disposition: inline; filename=' . $image_name);
1061                                header('content-type: ' . $dims['mime']);
1062                                imagepng($smallerImage);
1063                        }
1064                        else
1065                        {
1066                                header('content-disposition: inline; filename=' . $image_name);
1067                                header('content-type: ' . $dims['mime']);
1068                                header('content-length: ' . filesize($image));
1069                                readfile($image);
1070                        }
1071                }
1072                // if there is no graph, show "graph not found" message
1073                else
1074                {
1075                        header ('Content-type: image/png');
1076                        $text = 'GRAFICO NAO ENCONTRADO';
1077                        $font_size = 5;
1078                        $width = imagefontwidth($font_size) * strlen($text);
1079                        $height = imagefontheight($font_size);
1080                        $im = imagecreate($width, $height);
1081                        $text_color = imagecolorallocate($im, 0, 0, 0);         // black
1082                        $bg_color = imagecolorallocate($im, 255, 255, 255);     // white
1083                        imagefill($im, 0, 0, $bg_color);
1084                        imagestring($im, $font_size, 0, 0, $text, $text_color);
1085                        imagepng($im);
1086                        imagedestroy($im);
1087                }
1088        }
1089
1090        /**
1091         * Dislays the activity agents config rows
1092         * @return void
1093         * @access public
1094         */
1095        function display_agents_rows()
1096        {
1097                if (empty($this->agents))
1098                {
1099                        $this->t->set_var(array('agents_config_rows' => ''));
1100                }
1101                else
1102                {
1103                        $this->t->set_file('admin_agents', 'admin_agents.tpl');
1104                        foreach ($this->agents as $ui_agent)
1105                        {
1106                                //this is parsing the agent's admin template in the given template var
1107                                $ui_agent->showAdminActivityOptions('each_agent_rows');
1108                        }
1109                        $this->translate_template('admin_agents');
1110                        $this->t->parse('agents_config_rows', 'admin_agents');
1111                }
1112        }
1113}
1114?>
Note: See TracBrowser for help on using the repository browser.