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

Revision 32, 12.6 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

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