source: companies/serpro/expressoAdmin1_2/inc/class.uisectors.inc.php @ 903

Revision 903, 12.3 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
40                        $tmp = $this->functions->read_acl($account_lid);
41                        $manager_context = $tmp[0]['context'];
42                        $context_display = $tmp[0]['context_display'];
43                       
44                        // Verifica se o administrador tem acesso.
45                        if (!$this->functions->check_acl($account_lid,'list_sectors'))
46                        {
47                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
48                        }
49                       
50                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
51                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
52
53                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Sectors');
54                        $GLOBALS['phpgw']->common->phpgw_header();
55
56                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
57                        $p->set_file(array('sectors' => 'sectors.tpl'));
58                        $p->set_block('sectors','list','list');
59                        $p->set_block('sectors','row','row');
60                        $p->set_block('sectors','row_empty','row_empty');
61                       
62                        //$sectors_info = $this->functions->get_sectors_list($manager_context);
63                        //_debug_array($sectors_info);
64                        $sectors_info = $this->functions->get_sectors_list($manager_context);
65                       
66                        $var = Array(
67                                'th_bg'                                 => $GLOBALS['phpgw_info']['theme']['th_bg'],
68                                'back_url'                              => $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'),
69                                'context'                               => $manager_context,
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($account_lid,'edit_sectors'))
88                                {
89                                        $can_edit = True;
90                                }
91
92                                if ($this->functions->check_acl($account_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                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
150                        $acl = $this->functions->read_acl($account_lid);
151                        $manager_context = $acl[0]['context'];
152                       
153                        $context = $_GET['context'];
154                       
155                        // Verifica se tem acesso a este modulo
156                        if (!$this->functions->check_acl($account_lid,'create_sectors'))
157                        {
158                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
159                        }
160
161                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
162                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
163                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Create Sector');
164                        $GLOBALS['phpgw']->common->phpgw_header();
165                       
166                        // Set o template
167                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
168                        $p->set_file(Array('create_sector' => 'sectors_form.tpl'));
169                                               
170                        // Seta variaveis utilizadas pelo tpl.
171                        $var = Array(
172                                'action'                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.validate_data_sectors_add'),
173                                'back_url'                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
174                                'th_bg'                         => $GLOBALS['phpgw_info']['theme']['th_bg'],
175                                'context'                       => $context == '' ? $manager_context : $context,
176                                'sector'                        => $_POST['sector'],
177                                'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '',
178                               
179                                'lang_add'                      => lang('Add'),
180                                'lang_save'                     => lang('Save'),
181                                'lang_back'                     => lang('Back'),
182                                'lang_context'          => lang('Context'),
183                                'lang_sector_name'      => lang('Sector name'),
184                                'lang_occult_ou'        => lang('Occult Sector'),
185                                'error_messages'        => $_POST['error_messages'] == '' ? '' : "<script type='text/javascript'>alert('".$_POST['error_messages']."')</script>",
186                        );
187                        $p->set_var($var);
188
189                        $p->pfp('out','create_sector');
190                }
191               
192                function edit_sector()
193                {
194                        //_debug_array($_POST);
195                       
196                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
197                        $acl = $this->functions->read_acl($account_lid);
198                        $manager_context = $acl[0]['context'];
199                       
200                        $context = $_GET['context'];
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                       
219                        if (!$_POST)
220                        {
221                                $sector_info = $this->so->get_info($context);
222                                $_POST['sector_visible'] = $sector_info[0]['phpgwaccountvisible'][0];
223                        }
224                       
225                        // Seta variaveis utilizadas pelo tpl.
226                        $var = Array(
227                                'action'                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.bosectors.save_sector'),
228                                'back_url'                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
229                                'th_bg'                         => $GLOBALS['phpgw_info']['theme']['th_bg'],
230                                'context'                       => $context == '' ? $manager_context : $context,
231                                'sector'                                => $_POST['sector'] == '' ? $sector_name : $_POST['sector'],
232                                'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '',
233                               
234                                'lang_add'                      => lang('Add'),
235                                'disable'                       => 'disabled',
236                                'lang_save'                     => lang('Save'),
237                                'lang_back'                     => lang('Back'),
238                                'lang_context'          => lang('Context'),
239                                'lang_sector_name'      => lang('Sector name'),
240                                'lang_occult_ou'        => lang('Occult Sector'),
241                                'error_messages'        => $_POST['error_messages'] == '' ? '' : "<script type='text/javascript'>alert('".$_POST['error_messages']."')</script>",
242                        );
243                        $p->set_var($var);
244
245                        $p->pfp('out','edit_sector');
246                }
247               
248                function validate_data_sectors_add()
249                {
250                        //_debug_array($_POST);
251
252                        $sector_name    = $_POST['sector'];
253                        $context = $_POST['context'];
254                       
255                        // Verifica se o nome do sector nao esta vazio.
256                        if ($sector_name == '')
257                        {
258                                $_POST['error_messages'] = lang('Sector name is empty.');
259                                ExecMethod('expressoAdmin1_2.uisectors.add_sector');
260                                return;
261                        }
262                       
263                        // Verifica se o nome do setor existe no contexto atual.
264                        if ($this->so->exist_sector_name($sector_name, $context))
265                        {
266                                $_POST['error_messages'] = lang('Sector name already exist.');
267                                ExecMethod('expressoAdmin1_2.uisectors.add_sector');
268                                return;
269                        }
270                       
271                        ExecMethod('expressoAdmin1_2.bosectors.create_sector');
272                }
273
274                function delete_sector()
275                {
276                        //_debug_array($_GET);
277                       
278                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
279                        $acl = $this->functions->read_acl($account_lid);
280                        $manager_context = $acl[0]['context'];
281                       
282                        // Verifica se tem acesso a este modulo
283                        if (!$this->functions->check_acl($account_lid,'delete_sectors'))
284                        {
285                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
286                        }
287                       
288                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
289                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
290                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Delete Sectors');
291                        $GLOBALS['phpgw']->common->phpgw_header();
292
293                        // Set o template
294                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
295                        $p->set_file(Array('delete_sector' => 'sectors_delete.tpl'));
296                       
297                        $tmp_sector_name = $_GET['context'];
298                        $tmp_sector_name = explode(",",$tmp_sector_name);
299                        $tmp_sector_name = $tmp_sector_name[0];
300                        $tmp_sector_name = explode("=", $tmp_sector_name);
301                        $sector_name = $tmp_sector_name[1];
302                       
303                        // Get users of sector
304                        $sector_users           = $this->so->get_sector_users($_GET['context']);
305                        $sector_groups          = $this->so->get_sector_groups($_GET['context']);
306                        $sector_subsectors      = $this->so->get_sector_subsectors($_GET['context']);
307                       
308                        //_debug_array($sector_users);
309                        //_debug_array($sector_groups);
310                        //_debug_array($sector_subsectors);
311
312                        $users_list = '';
313                        foreach ($sector_users as $user)
314                        {
315                                $users_list .= $user['cn'][0] . '<br>';
316                        }
317                       
318                        $groups_list = '';
319                        foreach ($sector_groups as $group)
320                        {
321                                $groups_list .= $group['cn'][0] . '<br>';       
322                        }
323
324                        $subsectors_list = '';
325                        foreach ($sector_subsectors as $subsector)
326                        {
327                                if ($subsector['dn'] != $_GET['context'])
328                                        $subsectors_list .= $subsector['ou'][0] . '<br>';
329                        }
330
331                        // Seta variaveis utilizadas pelo tpl.
332                        $var = Array(
333                                'color_bg1'                                     => "#E8F0F0",
334                                'lang_back'                                     => lang('Back'),
335                                'lang_delete'                           => lang('Delete'),
336                                'lang_delete_sector'            => lang('Do you realy want delete this sector?'),
337                                'lang_content_the_users'        => lang('Content the folling users'),
338                                'lang_content_the_groups'       => lang('Content the folling groups'),
339                                'lang_content_the_sectors'      => lang('Content the folling sectors'),
340                                'lang_obs'                                      => lang('All users, groups and sub-sectors of this sector will be DELETED!'),
341                               
342                                'manager_context'                       => $manager_context,
343                                'dn'                                            => $_GET['context'],
344                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
345                                'action'                                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.bosectors.delete_sector'),
346                               
347                                'sector_name'                           => $sector_name,
348                                'users_list'                            => $users_list,
349                                'groups_list'                           => $groups_list,
350                                'sectors_list'                          => $subsectors_list
351                        );
352                        $p->set_var($var);
353                        $p->pfp('out','delete_sector');                 
354                }
355               
356                function row_action($action,$type,$context)
357                {
358                        return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
359                                'menuaction'            => 'expressoAdmin1_2.uisectors.'.$action.'_'.$type,
360                                'context'               => $context
361                        )).'"> '.lang($action).' </a>';
362                }
363               
364                function css()
365                {
366                        $appCSS = '';
367                        return $appCSS;
368                }
369               
370        }
371?>
Note: See TracBrowser for help on using the repository browser.