source: trunk/expressoAdmin1_2/inc/class.uisectors.inc.php @ 1145

Revision 1145, 12.0 KB checked in by rodsouza, 15 years ago (diff)

Ticket #581 - Restrict the manager to create sub-organizations in organizations where he has not permission.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /************************************************************************************\
3        * Expresso Administração                                                                                                     *
4        * by Joao Alfredo Knopik Junior (joao.alfredo@gmail.com, jakjr@celepar.pr.gov.br)        *
5        * -----------------------------------------------------------------------------------*
6        *  This program is free software; you can redistribute it and/or modify it                       *
7        *  under the terms of the GNU General Public License as published by the                         *
8        *  Free Software Foundation; either version 2 of the License, or (at your                        *
9        *  option) any later version.                                                                                                            *
10        \************************************************************************************/
11
12        class uisectors
13        {
14                var $public_functions = array
15                (
16                        'list_sectors'                                  => True,
17                        'add_sector'                                    => True,
18                        'validate_data_sectors_add'             => True,
19                        'edit_sector'                                   => True,
20                        'validate_data_sectors_edit'    => True,
21                        'delete_sector'                                 => True,
22                        'css'                                                   => True
23                );
24
25                var $bo;
26                var $nextmatchs;
27                var $functions;
28                       
29                function uisectors()
30                {
31                        $this->bo = CreateObject('expressoAdmin1_2.bosectors');
32                        $this->so = $this->bo->so;
33                        $this->functions = $this->bo->functions;
34                        $this->nextmatchs = createobject('phpgwapi.nextmatchs');
35                }
36               
37                function list_sectors()
38                {
39                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
40                        $acl = $this->functions->read_acl($manager_lid);
41                        $contexts = $acl['contexts'];
42                        foreach ($acl['contexts_display'] as $index=>$tmp_context)
43                        {
44                                $context_display .= '<br>'.$tmp_context;
45                        }
46
47                        // Verifica se o administrador tem acesso.
48                        if (!$this->functions->check_acl($manager_lid,'list_sectors'))
49                        {
50                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
51                        }
52                       
53                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
54                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
55
56                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Sectors');
57                        $GLOBALS['phpgw']->common->phpgw_header();
58
59                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
60                        $p->set_file(array('sectors' => 'sectors.tpl'));
61                        $p->set_block('sectors','list','list');
62                        $p->set_block('sectors','row','row');
63                        $p->set_block('sectors','row_empty','row_empty');
64                       
65                        $sectors_info = $this->functions->get_sectors_list($contexts);
66                       
67                        $var = Array(
68                                'th_bg'                                 => $GLOBALS['phpgw_info']['theme']['th_bg'],
69                                'back_url'                              => $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'),
70                                'context_display'               => $context_display,
71                                'lang_inactives'                        => lang('list inactives')
72                        );
73                        $p->set_var($var);
74                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
75
76                        if (!count($sectors_info))
77                        {
78                                $p->set_var('message',lang('No matches found'));
79                                $p->parse('rows','row_empty',True);
80                        }
81                        else
82                        {
83                                if ($this->functions->check_acl($manager_lid,'edit_sectors'))
84                                {
85                                        $can_edit = True;
86                                }
87
88                                if ($this->functions->check_acl($manager_lid,'delete_sectors'))
89                                {
90                                        $can_delete = True;
91                                }
92
93                                foreach($sectors_info as $context=>$sector)
94                                {
95                                        $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
96                                       
97                                        $var = Array(
98                                                'tr_color'    => $tr_color,
99                                                'sector_name'  => $sector,
100                                                'add_link' => $this->row_action('add','sector',$context)
101                                        );                                     
102                                        if(isset($GLOBALS['phpgw_info']['server']['time_to_account_expires']))
103                                                $var['inactives_link'] = $this->row_action('list_inactive','users',$context,'uiaccounts');
104                                        else
105                                                $var['inactives_link'] = lang('disabled');
106
107                                        $p->set_var($var);
108
109                                        if ($can_edit)
110                                        {
111                                                $p->set_var('edit_link',$this->row_action('edit','sector',$context));
112                                        }
113                                        else
114                                        {
115                                                $p->set_var('edit_link','&nbsp;');
116                                        }
117
118                                        if ($can_delete)
119                                        {
120                                                $p->set_var('delete_link',$this->row_action('delete','sector',$context));
121                                        }
122                                        else
123                                        {
124                                                $p->set_var('delete_link','&nbsp;');
125                                        }
126                                       
127                                        $p->fp('rows','row',True);
128                                }
129                        }
130                        $var = Array(
131                                'action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.add_sector')
132                        );
133                        $p->set_var($var);
134
135                        if (! $GLOBALS['phpgw']->acl->check('group_access',4,'admin'))
136                        {
137                                $p->set_var('input_add','<input type="submit" value="' . lang('Add Sectors') . '">');
138                        }
139                       
140                        $p->parse('rows','row_empty',True);
141                        $p->pfp('out','list');
142                }
143
144               
145                function add_sector($context='')
146                {
147                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
148                        $acl = $this->functions->read_acl($manager_lid);
149
150                        $manager_contexts = $acl['contexts'];
151                        $combo_manager_org = '';
152                        foreach ($manager_contexts as $index=>$context)
153                                $combo_manager_org .= $this->functions->get_organizations( $context );
154
155                        $context = $_GET['context'];
156                       
157                        // Verifica se tem acesso a este modulo
158                        if (!$this->functions->check_acl($manager_lid,'create_sectors'))
159                        {
160                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
161                        }
162
163                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
164                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
165                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Create Sector');
166                        $GLOBALS['phpgw']->common->phpgw_header();
167                       
168                        // Set o template
169                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
170                        $p->set_file(Array('create_sector' => 'sectors_form.tpl'));
171                        $p->set_block('create_sector','list','list');
172
173                        // Seta variaveis utilizadas pelo tpl.
174                        $var = Array(
175                                'action'                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.validate_data_sectors_add'),
176                                'back_url'                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
177                                'th_bg'                         => $GLOBALS['phpgw_info']['theme']['th_bg'],
178                                'context'                       => $context == '' ? $GLOBALS['phpgw_info']['server']['ldap_context'] : $context,
179                                'sector'                        => $_POST['sector'],
180                                'manager_org'           => $combo_manager_org,
181                                'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '',
182                                'error_messages'        => $_POST['error_messages'] == '' ? '' : "<script type='text/javascript'>alert('".$_POST['error_messages']."')</script>",
183                        );
184                        $p->set_var($var);
185                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
186
187                        $p->pfp('out','create_sector');
188                }
189               
190                function edit_sector()
191                {
192                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
193                        $acl = $this->functions->read_acl($account_lid);
194                        $manager_context = $acl[0]['context'];
195                       
196                        $context = $_GET['context'];
197
198                        $combo_manager_org = $this->functions->get_organizations($_GET['context'], '', true, true, true);
199                        $combo_manager_org = substr( $combo_manager_org, 0, ( strpos($combo_manager_org, '</option>') + 9 ) );
200
201                        $a_tmp = explode(",", ldap_dn2ufn($context));
202                        $sector_name = $a_tmp[0];
203                       
204                        // Verifica se tem acesso a este modulo
205                        if (!$this->functions->check_acl($account_lid,'edit_sectors'))
206                        {
207                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
208                        }
209
210                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
211                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
212                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Sector');
213                        $GLOBALS['phpgw']->common->phpgw_header();
214                       
215                        // Set o template
216                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
217                        $p->set_file(Array('edit_sector' => 'sectors_form.tpl'));
218                        $p->set_block('edit_sector','list','list');
219                       
220                        if (!$_POST)
221                        {
222                                $sector_info = $this->so->get_info($context);
223                                $_POST['sector_visible'] = $sector_info[0]['phpgwaccountvisible'][0];
224                        }
225                       
226                        // Seta variaveis utilizadas pelo tpl.
227                        $var = Array(
228                                'action'                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.bosectors.save_sector'),
229                                'back_url'                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
230                                'th_bg'                         => $GLOBALS['phpgw_info']['theme']['th_bg'],
231                                'context'                       => $context == '' ? $manager_context : $context,
232                                'sector'                        => $_POST['sector'] == '' ? $sector_name : $_POST['sector'],
233                                'manager_org'           => $combo_manager_org,
234                                'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '',
235                               
236                                'lang_add'                      => lang('Add'),
237                                'disable'                       => 'disabled',
238                                'error_messages'        => $_POST['error_messages'] == '' ? '' : "<script type='text/javascript'>alert('".$_POST['error_messages']."')</script>",
239                        );
240                        $p->set_var($var);
241                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
242                       
243                        $p->pfp('out','edit_sector');
244                }
245               
246                function validate_data_sectors_add()
247                {
248                        $sector_name    = $_POST['sector'];
249                        $context                = $_POST['context'];
250                       
251                        // Verifica se o nome do sector nao esta vazio.
252                        if ($sector_name == '')
253                        {
254                                $_POST['error_messages'] = lang('Sector name is empty.');
255                                ExecMethod('expressoAdmin1_2.uisectors.add_sector');
256                                return;
257                        }
258                       
259                        // Verifica se o nome do setor existe no contexto atual.
260                        if ($this->so->exist_sector_name($sector_name, $context))
261                        {
262                                $_POST['error_messages'] = lang('Sector name already exist.');
263                                ExecMethod('expressoAdmin1_2.uisectors.add_sector');
264                                return;
265                        }
266                       
267                        ExecMethod('expressoAdmin1_2.bosectors.create_sector');
268                }
269
270                function delete_sector()
271                {
272                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
273                        $acl = $this->functions->read_acl($account_lid);
274                        $manager_context = $acl[0]['context'];
275                       
276                        // Verifica se tem acesso a este modulo
277                        if (!$this->functions->check_acl($account_lid,'delete_sectors'))
278                        {
279                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
280                        }
281                       
282                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
283                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
284                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Delete Sectors');
285                        $GLOBALS['phpgw']->common->phpgw_header();
286
287                        // Set o template
288                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
289                        $p->set_file(Array('delete_sector' => 'sectors_delete.tpl'));
290                        $p->set_block('delete_sector','list','list');
291                       
292                        $tmp_sector_name = $_GET['context'];
293                        $tmp_sector_name = explode(",",$tmp_sector_name);
294                        $tmp_sector_name = $tmp_sector_name[0];
295                        $tmp_sector_name = explode("=", $tmp_sector_name);
296                        $sector_name = $tmp_sector_name[1];
297                       
298                        // Get users of sector
299                        $sector_users           = $this->so->get_sector_users($_GET['context']);
300                        $sector_groups          = $this->so->get_sector_groups($_GET['context']);
301                        $sector_subsectors      = $this->so->get_sector_subsectors($_GET['context']);
302                       
303                        $users_list = '';
304                        foreach ($sector_users as $user)
305                        {
306                                $users_list .= $user['cn'][0] . '<br>';
307                        }
308                       
309                        $groups_list = '';
310                        foreach ($sector_groups as $group)
311                        {
312                                $groups_list .= $group['cn'][0] . '<br>';       
313                        }
314
315                        $subsectors_list = '';
316                        foreach ($sector_subsectors as $subsector)
317                        {
318                                if ($subsector['dn'] != $_GET['context'])
319                                        $subsectors_list .= $subsector['ou'][0] . '<br>';
320                        }
321
322                        // Seta variaveis utilizadas pelo tpl.
323                        $var = Array(
324                                'color_bg1'                                     => "#E8F0F0",
325                                'manager_context'                       => $manager_context,
326                                'dn'                                            => $_GET['context'],
327                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
328                                'action'                                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.bosectors.delete_sector'),
329                               
330                                'sector_name'                           => $sector_name,
331                                'users_list'                            => $users_list,
332                                'groups_list'                           => $groups_list,
333                                'sectors_list'                          => $subsectors_list
334                        );
335                        $p->set_var($var);
336                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
337                        $p->pfp('out','delete_sector');                 
338                }
339               
340                function row_action($action,$type,$context,$class='uisectors')
341                {
342                        return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
343                                'menuaction'            => 'expressoAdmin1_2.'.$class.'.'.$action.'_'.$type,
344                                'context'               => $context
345                        )).'"> '.lang($action).' </a>';
346                }
347               
348                function css()
349                {
350                        $appCSS = '';
351                        return $appCSS;
352                }
353               
354        }
355?>
Note: See TracBrowser for help on using the repository browser.