source: sandbox/workflow/branches/993/inc/class.ui_adminroles.inc.php @ 2492

Revision 2492, 10.5 KB checked in by pedroerp, 14 years ago (diff)

Ticket #993 - Trocando acessos à GLOBALS por acessos à Settings.

  • Property svn:executable set to *
Line 
1<?php
2require_once(dirname(__FILE__) . SEP . 'class.WorkflowUtils.inc.php');
3require_once('engine' . SEP . 'config.egw.inc.php');
4/**
5 * @package Workflow
6 * @license http://www.gnu.org/copyleft/gpl.html GPL
7 */
8class ui_adminroles extends WorkflowUtils
9{
10        /**
11         * @var array $public_functions public functions
12         * @access public
13         */
14        var $public_functions = array(
15                'form'  => true
16        );
17
18        /**
19         * @var object $process_manager Process manager object
20         * @access public
21         */
22        var $process_manager;
23        /**
24         * @var object $activity_manager Activity manager object
25         * @access public
26         */
27        var $activity_manager;
28
29        /**
30         * @var array $workflow_acl
31         * @access public
32         */
33        var $workflow_acl;
34
35        /**
36         * Constructor
37         * @access public
38         * @return object
39         */
40        function ui_adminroles()
41        {
42                parent::WorkflowUtils();
43
44                $this->workflow_acl = Factory::getInstance('workflow_acl');
45                $denyAccess = true;
46                if ($this->workflow_acl->checkWorkflowAdmin(Settings::get('expresso', 'user', 'account_id')))
47                {
48                        /* the user is an Expresso/Workflow admin */
49                        $denyAccess = false;
50                }
51                else
52                {
53                        if ($GLOBALS['phpgw']->acl->check('admin_workflow', 1, 'workflow'))
54                        {
55                                /* check if the user can admin the informed process */
56                                if ($this->wf_p_id != 0)
57                                        $denyAccess = !$this->workflow_acl->check_process_access(Settings::get('expresso', 'user', 'account_id'), $this->wf_p_id);
58                                else
59                                        $denyAccess = false;
60                        }
61                }
62
63                if ($denyAccess)
64                {
65                        $GLOBALS['phpgw']->common->phpgw_header();
66                        echo parse_navbar();
67                        echo lang('access not permitted');
68                        $GLOBALS['phpgw']->log->message('F-Abort, Unauthorized access to workflow.ui_adminprocesses');
69                        $GLOBALS['phpgw']->log->commit();
70                        $GLOBALS['phpgw']->common->phpgw_exit();
71                }
72
73                $this->process_manager  = Factory::getInstance('workflow_processmanager');
74                $this->activity_manager = Factory::getInstance('workflow_activitymanager');
75                $this->role_manager     = Factory::getInstance('workflow_rolemanager');
76                $this->form_action = $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminroles.form');
77               
78        }
79        /**
80         * Show the adminroles form
81         * @access public
82         * @return void
83         */
84        function form()
85        {
86                $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['workflow']['title'] . ' - ' . lang('Admin Process Roles');
87                $GLOBALS['phpgw']->common->phpgw_header();
88                echo parse_navbar();
89
90                $this->t->set_file('admin_roles', 'admin_roles.tpl');
91
92                $this->order            = get_var('order', 'GET', 'wf_name');
93                $this->sort                     = get_var('sort', 'GET', 'asc');
94                $this->sort_mode        = $this->order . '__'. $this->sort;
95                $sort_mode2                     = get_var('sort_mode2', 'any', 'wf_name__asc');
96                $role_id                                = (int)get_var('role_id', 'any', 0);
97
98                if (!$this->wf_p_id) die(lang('No process indicated'));
99               
100                //do we need to check validity, warning high load on database
101                $checkvalidity=false;
102
103                // save new role
104                if (isset($_POST['save']))
105                {
106                        $this->save_role($role_id, $_POST['name'], $_POST['description']);
107                        $checkvalidity = true;
108                }
109
110                // save new mapping
111                if (isset($_POST['save_map']))
112                {
113                        $this->save_mapping($_POST['user'], $_POST['role']);
114                        $this->message[] = lang('New mapping added');
115                        $checkvalidity = true;
116                }
117
118                // delete roles
119                if (isset($_POST['delete_roles']))
120                {
121                        $this->delete_roles(array_keys($_POST['role']));
122                        $checkvalidity = true;
123                }
124               
125                // delete mappings
126                if (isset($_POST['delete_map']))
127                {
128                        $this->delete_maps(array_keys($_POST['map']));
129                }
130
131                // retrieve process info
132                $proc_info = $this->process_manager->get_process($this->wf_p_id);
133
134                // check process validity and show errors if necessary
135                if ($checkvalidity) $proc_info['isValid'] = $this->show_errors($this->activity_manager, $error_str);
136
137                // fill proc_bar
138                $this->t->set_var('proc_bar', $this->fill_proc_bar($proc_info));
139               
140                // retrieve role info
141                if ($role_id || isset($_POST['new_role']))
142                {
143                        $role_info = $this->role_manager->get_role($this->wf_p_id, $_GET['role_id']);
144                }
145                else
146                {
147                        $role_info = array(
148                                'name'                  => '',
149                                'description'   => '',
150                                'role_id'               => 0
151                        );
152                }
153
154                // retrieve all roles info
155                $all_roles = $this->role_manager->list_roles($this->wf_p_id, 0, -1, 'wf_name__asc', '');
156                //echo "all_roles: <pre>";print_r($all_roles);echo "</pre>";
157               
158                //collect some messages from used objects
159                $this->message[] = $this->activity_manager->get_error(false, _DEBUG);
160                $this->message[] = $this->process_manager->get_error(false, _DEBUG);
161                $this->message[] = $this->role_manager->get_error(false, _DEBUG);
162
163
164                // fill the general varibles of the template
165                $this->t->set_var(array(
166                        'message'                               => implode('<br>', array_filter($this->message)),
167                        'errors'                                => $error_str,
168                        'form_action_adminroles'        => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminroles.form'),
169                        'role_info_role_id'             => $role_info['wf_role_id'],
170                        'role_info_name'                => $role_info['wf_name'],
171                        'role_info_description' => $role_info['wf_description'],
172                        'p_id'                                  => $this->wf_p_id,
173                        'start'                                 => $this->start,
174                ));
175
176                $this->show_process_roles_list($all_roles['data']);
177
178                // build users and roles multiple select boxes
179                $this->show_users_roles_selects($all_roles['data']);
180
181                // retrieve and show mappings
182                $this->show_mappings();
183
184                $this->translate_template('admin_roles');
185                $this->t->pparse('output', 'admin_roles');
186                $GLOBALS['phpgw']->common->phpgw_footer();
187        }
188        /**
189         * Save role
190         * @param int $role_id role identifier
191         * @param string $name role name
192         * @param string $description role description
193         * @access public
194         * @return void
195         */
196        function save_role($role_id, $name, $description)
197        {
198                $vars = array(
199                        'wf_name'                       => $name,
200                        'wf_description'        => $description,
201                );
202                if ($this->role_manager->replace_role($this->wf_p_id, $role_id, $vars))
203                {
204                        $this->message[] = lang('Role saved');
205                }
206                else
207                {
208                        $this->message[] = lang('Role not saved (maybe a name collision)');
209                }
210               
211        }
212        /**
213         * Delet selected roles
214         * @param array $roles_ids
215         * @access public
216         * @return void
217         */
218        function delete_roles($roles_ids)
219        {
220                foreach ($roles_ids as $role_id)
221                {
222                        $this->role_manager->remove_role($this->wf_p_id, $role_id);
223                }
224                $this->message[] = lang('Roles deleted');
225        }
226        /**
227         * Delete mappings
228         * @param array $mappings
229         * @return void
230         * @access public
231         */
232        function delete_maps($mappings)
233        {
234                                        foreach($mappings as $map)
235                                        {
236                                                                 $pos = strpos($map,":::");
237                                                                 $user=substr($map,0,$pos);
238                                                                 $role_id=substr($map,$pos+3);
239                                                                 $this->role_manager->remove_mapping($user,$role_id);
240                                        }
241                $this->message[] = lang('Mappings deleted');
242        }
243        /**
244         * Show mappings
245         * @return void
246         * @access public
247         */
248        function show_mappings()
249        {
250                $this->t->set_block('admin_roles', 'block_list_mappings', 'list_mappings');
251                $mappings = $this->role_manager->list_mappings($this->wf_p_id, $this->start, -1, $this->sort_mode, '');
252                //echo "mappings: <pre>";print_r($mappings);echo "</pre>";
253                if (!count($mappings['data'])) {
254                        $this->t->set_var('list_mappings', '<tr><td colspan="3" align="center">'. lang('There are no mappings defined for this process')  .'</td></tr>');
255                }
256                else {
257                        /* load the LDAP information */
258                        $cachedLDAP = Factory::getInstance('CachedLDAP');
259                        $tmpLDAP = &Factory::getInstance('WorkflowLDAP');
260                        $userContext  = $tmpLDAP->getUserContext();
261                        $groupContext = $tmpLDAP->getGroupContext();
262
263                        foreach ($mappings['data'] as $mapping)
264                        {
265                                if ($mapping['wf_account_type'] == 'g') {
266                                        $sri = ldap_search(Factory::getInstance('WorkflowObjects')->getLDAP(),
267                                                                        $groupContext,
268                                                                        '(&(gidnumber=' . (int)$mapping['wf_user'] . ')(phpgwAccountType=g))');
269
270                                        $allValues = ldap_get_entries(Factory::getInstance('WorkflowObjects')->getLDAP(), $sri);
271
272                                        $cname = $GLOBALS['phpgw']->translation->convert($allValues[0]['cn'][0],'utf-8');
273                                        $glabel = '[' . lang('Group') . ']';
274                                }
275                                else {
276                                        $entry = $cachedLDAP->getEntryByID($mapping['wf_user']);
277                                        $cname = $GLOBALS['phpgw']->translation->convert($entry['cn'],'utf-8');
278                                        $glabel = "";
279                                        if (is_null($entry['last_update']))
280                                                $glabel = '<font color="red">(excluído)</font>';
281                                }
282
283                                $this->t->set_var(array(
284                                        'map_user_id'   => $mapping['wf_user'],
285                                        'map_role_id'   => $mapping['wf_role_id'],
286                                        'map_role_name' => $mapping['wf_name'],
287                                        'map_user_name' => $cname . ' ' . $glabel,
288                                ));
289                                $this->t->parse('list_mappings', 'block_list_mappings', true);
290                        }
291                }
292        }
293        /**
294         * Save mapping
295         * @param array users list of users
296         * @param array $roles list of roles
297         * @access public
298         * @return void
299         */
300        function save_mapping($users, $roles)
301        {
302                foreach ($users as $user)
303                {
304                        $account_type   = $user{0};
305                        $user           = substr($user, 1);
306                        foreach ($roles as $role)
307                        {
308                                $this->role_manager->map_user_to_role($this->wf_p_id, $user, $role, $account_type);
309                        }
310                }
311        }
312        /**
313         * Show users roles selects
314         * @param string $all_roles_data
315         * @return
316         */
317        function show_users_roles_selects($all_roles_data)
318        {
319                $templateServer = &Factory::getInstance('TemplateServer');
320                $imgaddusers = $templateServer->generateImageLink('add_group.png');
321                $imgdelusers = $templateServer->generateImageLink('delete_group.png');
322
323                $this->t->set_var(array(
324                        'src_img_add_users' => $imgaddusers,
325                        'src_img_del_users' => $imgdelusers
326                ));
327
328                $this->t->set_block('admin_roles', 'block_select_roles', 'select_roles');
329                foreach ($all_roles_data as $role)
330                {
331                        $this->t->set_var(array(
332                                'select_role_id'        => $role['wf_role_id'],
333                                'select_role_name'      => $role['wf_name']
334                        ));
335                        $this->t->parse('select_roles', 'block_select_roles', true);
336                }
337        }
338        /**
339         * Show process roles list
340         * @param array $all_roles_data
341         * @return void
342         */
343        function show_process_roles_list($all_roles_data)
344        {
345                $this->t->set_block('admin_roles', 'block_process_roles_list', 'process_roles_list');
346                $this->translate_template('block_process_roles_list');
347
348                foreach ($all_roles_data as $role)
349                {
350                        $this->t->set_var(array(
351                                'all_roles_role_id'             => $role['wf_role_id'],
352                                'all_roles_href'                => $GLOBALS['phpgw']->link('/index.php', 'menuaction=workflow.ui_adminroles.form&sort_mode='. $this->sort_mode .'&start='. $this->start .'&find='. $find .'&p_id='. $this->wf_p_id .'&sort_mode2='. $sort_mode2 .'&role_id='. $role['wf_role_id']),
353                                'all_roles_name'                => $role['wf_name'],
354                                'all_roles_description' => $role['wf_description'],
355                                'color_line'                    => $this->nextmatchs->alternate_row_color($tr_color),
356                        ));
357                        $this->t->parse('process_roles_list', 'block_process_roles_list', true);
358                }
359                if (!count($all_roles_data)) $this->t->set_var('process_roles_list', '<tr><td colspan="3">'. lang('There are no roles defined for this process') .'</td></tr>');
360
361        }
362}
363?>
Note: See TracBrowser for help on using the repository browser.