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

Revision 396, 12.2 KB checked in by niltonneto, 16 years ago (diff)

Modificações referente a opção de configurar um ldap_master
no setup do Expresso, usado somente para escrita.

  • 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_context'                  => lang('context'),
72                                'header_name'                   => lang('SECTORS'),
73                                'lang_add_sub_sectors'  => lang('Add Sub-Sectors'),
74                                'header_edit'                   => lang('Edit'),
75                                'lang_back'                             => lang('back'),
76                                'header_delete'                 => lang('Delete')
77                        );
78                        $p->set_var($var);
79
80                        if (!count($sectors_info))
81                        {
82                                $p->set_var('message',lang('No matches found'));
83                                $p->parse('rows','row_empty',True);
84                        }
85                        else
86                        {
87                                if ($this->functions->check_acl($manager_lid,'edit_sectors'))
88                                {
89                                        $can_edit = True;
90                                }
91
92                                if ($this->functions->check_acl($manager_lid,'delete_sectors'))
93                                {
94                                        $can_delete = True;
95                                }
96
97                                foreach($sectors_info as $context=>$sector)
98                                {
99                                        $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
100                                       
101                                        $var = Array(
102                                                'tr_color'    => $tr_color,
103                                                'sector_name'  => $sector,
104                                                'add_link' => $this->row_action('add','sector',$context)
105                                        );
106                                        $p->set_var($var);
107
108                                        if ($can_edit)
109                                        {
110                                                $p->set_var('edit_link',$this->row_action('edit','sector',$context));
111                                        }
112                                        else
113                                        {
114                                                $p->set_var('edit_link','&nbsp;');
115                                        }
116
117                                        if ($can_delete)
118                                        {
119                                                $p->set_var('delete_link',$this->row_action('delete','sector',$context));
120                                        }
121                                        else
122                                        {
123                                                $p->set_var('delete_link','&nbsp;');
124                                        }
125                                       
126                                        $p->fp('rows','row',True);
127                                }
128                        }
129                        $var = Array(
130                                'action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.add_sector')
131                        );
132                        $p->set_var($var);
133
134                        if (! $GLOBALS['phpgw']->acl->check('group_access',4,'admin'))
135                        {
136                                $p->set_var('input_add','<input type="submit" value="' . lang('Add Sectors') . '">');
137                        }
138                       
139                        $p->parse('rows','row_empty',True);
140                        $p->pfp('out','list');
141                }
142
143               
144                function add_sector($context='')
145                {
146                        //_debug_array($_GET);
147                        //_debug_array($_POST);
148
149                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
150                        $acl = $this->functions->read_acl($manager_lid);
151                       
152                        $context = $_GET['context'];
153                       
154                        // Verifica se tem acesso a este modulo
155                        if (!$this->functions->check_acl($manager_lid,'create_sectors'))
156                        {
157                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
158                        }
159
160                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
161                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
162                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Create Sector');
163                        $GLOBALS['phpgw']->common->phpgw_header();
164                       
165                        // Set o template
166                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
167                        $p->set_file(Array('create_sector' => 'sectors_form.tpl'));
168
169                        // Seta variaveis utilizadas pelo tpl.
170                        $var = Array(
171                                'action'                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.validate_data_sectors_add'),
172                                'back_url'                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
173                                'th_bg'                         => $GLOBALS['phpgw_info']['theme']['th_bg'],
174                                'context'                       => $context == '' ? $GLOBALS['phpgw_info']['server']['ldap_context'] : $context,
175                                'sector'                        => $_POST['sector'],
176                                'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '',
177                               
178                                'lang_add'                      => lang('Add'),
179                                'lang_save'                     => lang('Save'),
180                                'lang_back'                     => lang('Back'),
181                                'lang_context'          => lang('Context'),
182                                'lang_sector_name'      => lang('Sector name'),
183                                'lang_occult_ou'        => lang('Occult Sector'),
184                                'error_messages'        => $_POST['error_messages'] == '' ? '' : "<script type='text/javascript'>alert('".$_POST['error_messages']."')</script>",
185                        );
186                        $p->set_var($var);
187
188                        $p->pfp('out','create_sector');
189                }
190               
191                function edit_sector()
192                {
193                        //_debug_array($_POST);
194                       
195                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
196                        $acl = $this->functions->read_acl($account_lid);
197                        $manager_context = $acl[0]['context'];
198                       
199                        $context = $_GET['context'];
200                        $a_tmp = explode(",", ldap_dn2ufn($context));
201                        $sector_name = $a_tmp[0];
202                       
203                        // Verifica se tem acesso a este modulo
204                        if (!$this->functions->check_acl($account_lid,'edit_sectors'))
205                        {
206                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
207                        }
208
209                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
210                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
211                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Sector');
212                        $GLOBALS['phpgw']->common->phpgw_header();
213                       
214                        // Set o template
215                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
216                        $p->set_file(Array('edit_sector' => 'sectors_form.tpl'));
217                       
218                        if (!$_POST)
219                        {
220                                $sector_info = $this->so->get_info($context);
221                                $_POST['sector_visible'] = $sector_info[0]['phpgwaccountvisible'][0];
222                        }
223                       
224                        // Seta variaveis utilizadas pelo tpl.
225                        $var = Array(
226                                'action'                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.bosectors.save_sector'),
227                                'back_url'                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
228                                'th_bg'                         => $GLOBALS['phpgw_info']['theme']['th_bg'],
229                                'context'                       => $context == '' ? $manager_context : $context,
230                                'sector'                                => $_POST['sector'] == '' ? $sector_name : $_POST['sector'],
231                                'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '',
232                               
233                                'lang_add'                      => lang('Add'),
234                                'disable'                       => 'disabled',
235                                'lang_save'                     => lang('Save'),
236                                'lang_back'                     => lang('Back'),
237                                'lang_context'          => lang('Context'),
238                                'lang_sector_name'      => lang('Sector name'),
239                                'lang_occult_ou'        => lang('Occult Sector'),
240                                'error_messages'        => $_POST['error_messages'] == '' ? '' : "<script type='text/javascript'>alert('".$_POST['error_messages']."')</script>",
241                        );
242                        $p->set_var($var);
243
244                        $p->pfp('out','edit_sector');
245                }
246               
247                function validate_data_sectors_add()
248                {
249                        //_debug_array($_POST);
250
251                        $sector_name    = $_POST['sector'];
252                        $context                = $_POST['context'];
253                       
254                        // Verifica se o nome do sector nao esta vazio.
255                        if ($sector_name == '')
256                        {
257                                $_POST['error_messages'] = lang('Sector name is empty.');
258                                ExecMethod('expressoAdmin1_2.uisectors.add_sector');
259                                return;
260                        }
261                       
262                        // Verifica se o nome do setor existe no contexto atual.
263                        if ($this->so->exist_sector_name($sector_name, $context))
264                        {
265                                $_POST['error_messages'] = lang('Sector name already exist.');
266                                ExecMethod('expressoAdmin1_2.uisectors.add_sector');
267                                return;
268                        }
269                       
270                        ExecMethod('expressoAdmin1_2.bosectors.create_sector');
271                }
272
273                function delete_sector()
274                {
275                        //_debug_array($_GET);
276                       
277                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
278                        $acl = $this->functions->read_acl($account_lid);
279                        $manager_context = $acl[0]['context'];
280                       
281                        // Verifica se tem acesso a este modulo
282                        if (!$this->functions->check_acl($account_lid,'delete_sectors'))
283                        {
284                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
285                        }
286                       
287                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
288                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
289                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Delete Sectors');
290                        $GLOBALS['phpgw']->common->phpgw_header();
291
292                        // Set o template
293                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
294                        $p->set_file(Array('delete_sector' => 'sectors_delete.tpl'));
295                       
296                        $tmp_sector_name = $_GET['context'];
297                        $tmp_sector_name = explode(",",$tmp_sector_name);
298                        $tmp_sector_name = $tmp_sector_name[0];
299                        $tmp_sector_name = explode("=", $tmp_sector_name);
300                        $sector_name = $tmp_sector_name[1];
301                       
302                        // Get users of sector
303                        $sector_users           = $this->so->get_sector_users($_GET['context']);
304                        $sector_groups          = $this->so->get_sector_groups($_GET['context']);
305                        $sector_subsectors      = $this->so->get_sector_subsectors($_GET['context']);
306                       
307                        //_debug_array($sector_users);
308                        //_debug_array($sector_groups);
309                        //_debug_array($sector_subsectors);
310
311                        $users_list = '';
312                        foreach ($sector_users as $user)
313                        {
314                                $users_list .= $user['cn'][0] . '<br>';
315                        }
316                       
317                        $groups_list = '';
318                        foreach ($sector_groups as $group)
319                        {
320                                $groups_list .= $group['cn'][0] . '<br>';       
321                        }
322
323                        $subsectors_list = '';
324                        foreach ($sector_subsectors as $subsector)
325                        {
326                                if ($subsector['dn'] != $_GET['context'])
327                                        $subsectors_list .= $subsector['ou'][0] . '<br>';
328                        }
329
330                        // Seta variaveis utilizadas pelo tpl.
331                        $var = Array(
332                                'color_bg1'                                     => "#E8F0F0",
333                                'lang_back'                                     => lang('Back'),
334                                'lang_delete'                           => lang('Delete'),
335                                'lang_delete_sector'            => lang('Do you realy want delete this sector?'),
336                                'lang_content_the_users'        => lang('Content the folling users'),
337                                'lang_content_the_groups'       => lang('Content the folling groups'),
338                                'lang_content_the_sectors'      => lang('Content the folling sectors'),
339                                'lang_obs'                                      => lang('All users, groups and sub-sectors of this sector will be DELETED!'),
340                               
341                                'manager_context'                       => $manager_context,
342                                'dn'                                            => $_GET['context'],
343                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
344                                'action'                                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.bosectors.delete_sector'),
345                               
346                                'sector_name'                           => $sector_name,
347                                'users_list'                            => $users_list,
348                                'groups_list'                           => $groups_list,
349                                'sectors_list'                          => $subsectors_list
350                        );
351                        $p->set_var($var);
352                        $p->pfp('out','delete_sector');                 
353                }
354               
355                function row_action($action,$type,$context)
356                {
357                        return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
358                                'menuaction'            => 'expressoAdmin1_2.uisectors.'.$action.'_'.$type,
359                                'context'               => $context
360                        )).'"> '.lang($action).' </a>';
361                }
362               
363                function css()
364                {
365                        $appCSS = '';
366                        return $appCSS;
367                }
368               
369        }
370?>
Note: See TracBrowser for help on using the repository browser.