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

Revision 414, 11.2 KB checked in by niltonneto, 16 years ago (diff)

Alterações feitas por João Alfredo.
Email: jakjr@…

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