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

Revision 2, 10.1 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • 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                        'delete_sector'                                 => True,
20                        'css'                                                   => True
21                );
22
23                var $bo;
24                var $nextmatchs;
25                var $functions;
26                       
27                function uisectors()
28                {
29                        $this->bo = CreateObject('expressoAdmin1_2.bosectors');
30                        $this->so = $this->bo->so;
31                        $this->functions = $this->bo->functions;
32                        $this->nextmatchs = createobject('phpgwapi.nextmatchs');
33                }
34               
35                function list_sectors()
36                {
37                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
38                        $tmp = $this->functions->read_acl($account_lid);
39                        $manager_context = $tmp[0]['context'];
40                        $context_display = $tmp[0]['context_display'];
41                       
42                        // Verifica se o administrador tem acesso.
43                        if (!$this->functions->check_acl($account_lid,'list_sectors'))
44                        {
45                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
46                        }
47                       
48                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
49                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
50
51                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Sectors');
52                        $GLOBALS['phpgw']->common->phpgw_header();
53
54                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
55                        $p->set_file(array('sectors' => 'sectors.tpl'));
56                        $p->set_block('sectors','list','list');
57                        $p->set_block('sectors','row','row');
58                        $p->set_block('sectors','row_empty','row_empty');
59                       
60                        $sectors_info = $this->functions->get_sectors_list($manager_context);
61                        //_debug_array($sectors_info);
62                       
63                        $var = Array(
64                                'th_bg'                                 => $GLOBALS['phpgw_info']['theme']['th_bg'],
65                                'back_url'                              => $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'),
66                                'context'                               => $manager_context,
67                                'context_display'               => $context_display,
68                                'lang_context'                  => lang('context'),
69                                'header_name'                   => lang('SECTORS'),
70                                'lang_add_sub_sectors'  => lang('Add Sub-Sectors'),
71                                'header_edit'                   => lang('Edit'),
72                                'lang_back'                             => lang('back'),
73                                'header_delete'                 => lang('Delete')
74                        );
75                        $p->set_var($var);
76
77                        if (!count($sectors_info))
78                        {
79                                $p->set_var('message',lang('No matches found'));
80                                $p->parse('rows','row_empty',True);
81                        }
82                        else
83                        {
84                                if ($this->functions->check_acl($account_lid,'edit_sectors'))
85                                {
86                                        $can_edit = True;
87                                }
88
89                                if ($this->functions->check_acl($account_lid,'delete_sectors'))
90                                {
91                                        $can_delete = True;
92                                }
93
94                                foreach($sectors_info as $sector)
95                                {
96                                        $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
97                                       
98                                        if ($sector->sector_level == 1)
99                                        {
100                                                $sector->sector_name = '+'.$sector->sector_name;
101                                        }
102                                        else
103                                        {
104                                                for ($i=1; $i < $sector->sector_level; $i++)
105                                                        $sector->sector_name = '----'.$sector->sector_name;
106                                        }
107                                       
108                                        $var = Array(
109                                                'tr_color'    => $tr_color,
110                                                'sector_name'  => (!$sector->sector_name?'&nbsp;':$sector->sector_name),
111                                                'add_link' => $this->row_action('add','sector',$sector->sector_context)
112                                        );
113                                        $p->set_var($var);
114
115                                        if ($can_delete)
116                                        {
117                                                $p->set_var('delete_link',$this->row_action('delete','sector',$sector->sector_context));
118                                        }
119                                        else
120                                        {
121                                                $p->set_var('delete_link','&nbsp;');
122                                        }
123                                       
124                                        $p->fp('rows','row',True);
125                                }
126                        }
127                        $var = Array(
128                                'action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.add_sector')
129                        );
130                        $p->set_var($var);
131
132                        if (! $GLOBALS['phpgw']->acl->check('group_access',4,'admin'))
133                        {
134                                $p->set_var('input_add','<input type="submit" value="' . lang('Add Sectors') . '">');
135                        }
136                       
137                        $p->parse('rows','row_empty',True);
138                        $p->pfp('out','list');
139                }
140
141               
142                function add_sector($context='')
143                {
144                        //_debug_array($_GET);
145                        //_debug_array($_POST);
146                       
147                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
148                        $acl = $this->functions->read_acl($account_lid);
149                        $manager_context = $acl[0]['context'];
150                       
151                        $context = $_GET['context'];
152                       
153                        // Verifica se tem acesso a este modulo
154                        if (!$this->functions->check_acl($account_lid,'create_sectors'))
155                        {
156                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
157                        }
158
159                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
160                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
161                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Create Sector');
162                        $GLOBALS['phpgw']->common->phpgw_header();
163                       
164                        // Set o template
165                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
166                        $p->set_file(Array('create_sector' => 'sectors_form.tpl'));
167                                               
168                        // Seta variaveis utilizadas pelo tpl.
169                        $var = Array(
170                                'action'                                                => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.validate_data_sectors_add'),
171                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
172                                'th_bg'                                         => $GLOBALS['phpgw_info']['theme']['th_bg'],
173                                'context'                                       => $context == '' ? $manager_context : $context,
174                                'sector'                                        => $_POST['sector'],
175                               
176                                'lang_add'                                      => lang('Add'),
177                                'lang_save'                             => lang('Save'),
178                                'lang_back'                             => lang('Back'),
179                                'lang_context'                  => lang('Context'),
180                                'lang_sector_name'      => lang('Sector name'),
181                                'error_messages'                => $_POST['error_messages'] == '' ? '' : "<script type='text/javascript'>alert('".$_POST['error_messages']."')</script>",
182                        );
183                        $p->set_var($var);
184
185                        $p->pfp('out','create_sector');
186                }
187               
188                function validate_data_sectors_add()
189                {
190                        //_debug_array($_POST);
191
192                        $sector_name    = $_POST['sector'];
193                        $context = $_POST['context'];
194                       
195                        // Verifica se o nome do sector nao esta vazio.
196                        if ($sector_name == '')
197                        {
198                                $_POST['error_messages'] = lang('Sector name is empty.');
199                                ExecMethod('expressoAdmin1_2.uisectors.add_sector');
200                                return;
201                        }
202                       
203                        // Verifica se o nome do setor existe no contexto atual.
204                        if ($this->so->exist_sector_name($sector_name, $context))
205                        {
206                                $_POST['error_messages'] = lang('Sector name already exist.');
207                                ExecMethod('expressoAdmin1_2.uisectors.add_sector');
208                                return;
209                        }
210                       
211                        ExecMethod('expressoAdmin1_2.bosectors.create_sector');
212                }
213               
214                function delete_sector()
215                {
216                        //_debug_array($_GET);
217                       
218                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
219                        $acl = $this->functions->read_acl($account_lid);
220                        $manager_context = $acl[0]['context'];
221                       
222                        // Verifica se tem acesso a este modulo
223                        if (!$this->functions->check_acl($account_lid,'delete_sectors'))
224                        {
225                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
226                        }
227                       
228                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
229                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
230                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Delete Sectors');
231                        $GLOBALS['phpgw']->common->phpgw_header();
232
233                        // Set o template
234                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
235                        $p->set_file(Array('delete_sector' => 'sectors_delete.tpl'));
236                       
237                        $tmp_sector_name = $_GET['context'];
238                        $tmp_sector_name = explode(",",$tmp_sector_name);
239                        $tmp_sector_name = $tmp_sector_name[0];
240                        $tmp_sector_name = explode("=", $tmp_sector_name);
241                        $sector_name = $tmp_sector_name[1];
242                       
243                        // Get users of sector
244                        $sector_users                   = $this->so->get_sector_users($_GET['context']);
245                        $sector_groups          = $this->so->get_sector_groups($_GET['context']);
246                        $sector_subsectors      = $this->so->get_sector_subsectors($_GET['context']);
247                       
248                        //_debug_array($sector_users);
249                        //_debug_array($sector_groups);
250                        //_debug_array($sector_subsectors);
251
252                        $users_list = '';
253                        foreach ($sector_users as $user)
254                        {
255                                $users_list .= $user['cn'][0] . '<br>';
256                        }
257                       
258                        $groups_list = '';
259                        foreach ($sector_groups as $group)
260                        {
261                                $groups_list .= $group['cn'][0] . '<br>';       
262                        }
263
264                        $subsectors_list = '';
265                        foreach ($sector_subsectors as $subsector)
266                        {
267                                if ($subsector['dn'] != $_GET['context'])
268                                        $subsectors_list .= $subsector['ou'][0] . '<br>';
269                        }
270
271                        // Seta variaveis utilizadas pelo tpl.
272                        $var = Array(
273                                'color_bg1'                                     => "#E8F0F0",
274                                'lang_back'                                     => lang('Back'),
275                                'lang_delete'                           => lang('Delete'),
276                                'lang_delete_sector'            => lang('Do you realy want delete this sector?'),
277                                'lang_content_the_users'        => lang('Content the folling users'),
278                                'lang_content_the_groups'       => lang('Content the folling groups'),
279                                'lang_content_the_sectors'      => lang('Content the folling sectors'),
280                                'lang_obs'                                      => lang('All users, groups and sub-sectors of this sector will be DELETED!'),
281                               
282                                'manager_context'                       => $manager_context,
283                                'dn'                                            => $_GET['context'],
284                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
285                                'action'                                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.bosectors.delete_sector'),
286                               
287                                'sector_name'                           => $sector_name,
288                                'users_list'                            => $users_list,
289                                'groups_list'                           => $groups_list,
290                                'sectors_list'                          => $subsectors_list
291                        );
292                        $p->set_var($var);
293                        $p->pfp('out','delete_sector');                 
294                }
295               
296                function row_action($action,$type,$context)
297                {
298                        return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
299                                'menuaction'            => 'expressoAdmin1_2.uisectors.'.$action.'_'.$type,
300                                'context'               => $context
301                        )).'"> '.lang($action).' </a>';
302                }
303               
304                function css()
305                {
306                        $appCSS = '';
307                        return $appCSS;
308                }
309               
310        }
311?>
Note: See TracBrowser for help on using the repository browser.