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

Revision 1516, 15.4 KB checked in by eduardoalex, 15 years ago (diff)

Ticket #419 - Parte principal da funcionalidade. Falta add atributos no ldap

  • 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                        'view_cota'                                             => True
24                );
25
26                var $bo;
27                var $nextmatchs;
28                var $functions;
29                       
30                function uisectors()
31                {
32                        $this->bo = CreateObject('expressoAdmin1_2.bosectors');
33                        $this->so = $this->bo->so;
34                        $this->functions = $this->bo->functions;
35                        $this->nextmatchs = createobject('phpgwapi.nextmatchs');
36                }
37               
38                function list_sectors()
39                {
40                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
41                        $acl = $this->functions->read_acl($manager_lid);
42                        $contexts = $acl['contexts'];
43                        foreach ($acl['contexts_display'] as $index=>$tmp_context)
44                        {
45                                $context_display .= '<br>'.$tmp_context;
46                        }
47
48                        // Verifica se o administrador tem acesso.
49                        if (!$this->functions->check_acl($manager_lid,'list_sectors'))
50                        {
51                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
52                        }
53                       
54                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
55                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
56
57                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Sectors');
58                        $GLOBALS['phpgw']->common->phpgw_header();
59
60                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
61                        $p->set_file(array('sectors' => 'sectors.tpl'));
62                        $p->set_block('sectors','list','list');
63                        $p->set_block('sectors','row','row');
64                        $p->set_block('sectors','row_empty','row_empty');
65                       
66                        //$sectors_info = $this->functions->get_sectors_list($contexts);
67                        $sectors_info = $this->functions->get_organizations2($contexts);
68                       
69                        $var = Array(
70                                'th_bg'                                 => $GLOBALS['phpgw_info']['theme']['th_bg'],
71                                'back_url'                              => $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'),
72                                'context_display'               => $context_display,
73                                'lang_inactives'                        => lang('list inactives'),
74                                'lang_ver_cota'         => lang('view cota')
75                        );
76                        $p->set_var($var);
77                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
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($manager_lid,'edit_sectors'))
87                                {
88                                        $can_edit = True;
89                                }
90
91                                if ($this->functions->check_acl($manager_lid,'delete_sectors'))
92                                {
93                                        $can_delete = True;
94                                }
95
96                                foreach($sectors_info as $context=>$sector)
97                                {
98                                        $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
99                                       
100                                        $var = Array(
101                                                'tr_color'    => $tr_color,
102                                                'sector_name'  => $sector['display'],
103                                                'cota_link' => $this->row_action('view','cota',$sector['dn']),
104                                                'add_link' => $this->row_action('add','sector',$sector['dn'])
105                                        );                                     
106                                        if(isset($GLOBALS['phpgw_info']['server']['time_to_account_expires']))
107                                                $var['inactives_link'] = $this->row_action('list_inactive','users',$sector['dn'],'uiaccounts');
108                                        else
109                                                $var['inactives_link'] = lang('disabled');
110
111                                        $p->set_var($var);
112
113                                        if ($can_edit)
114                                        {
115                                                $p->set_var('edit_link',$this->row_action('edit','sector',$sector['dn']));
116                                        }
117                                        else
118                                        {
119                                                $p->set_var('edit_link','&nbsp;');
120                                        }
121
122                                        if ($can_delete)
123                                        {
124                                                $p->set_var('delete_link',$this->row_action('delete','sector',$sector['dn']));
125                                        }
126                                        else
127                                        {
128                                                $p->set_var('delete_link','&nbsp;');
129                                        }
130                                       
131                                        $p->fp('rows','row',True);
132                                }
133                        }
134                        $var = Array(
135                                'action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.add_sector')
136                        );
137                        $p->set_var($var);
138
139                        if (! $GLOBALS['phpgw']->acl->check('group_access',4,'admin'))
140                        {
141                                $p->set_var('input_add','<input type="submit" value="' . lang('Add Sectors') . '">');
142                        }
143                       
144                        $p->parse('rows','row_empty',True);
145                        $p->pfp('out','list');
146                }
147
148               
149                function add_sector($context='')
150                {
151                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
152                        $acl = $this->functions->read_acl($manager_lid);
153
154                        $manager_contexts = $acl['contexts'];
155                        $combo_manager_org = '';
156
157                        if ( array_key_exists( 'context', $_GET ) )
158                        {
159                                $context = $_GET['context'];
160                                $combo_manager_org = $this->functions->get_organizations( $context, '', true, true, true );
161                        }
162                        else
163                        {
164                                foreach ($manager_contexts as $index=>$context)
165                                        $combo_manager_org .= $this->functions->get_organizations( $context );
166                        }
167
168                        // Verifica se tem acesso a este modulo
169                        if (!$this->functions->check_acl($manager_lid,'create_sectors'))
170                        {
171                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
172                        }
173
174                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
175                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
176                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Create Sector');
177                        $GLOBALS['phpgw']->common->phpgw_header();
178                       
179                        // Set o template
180                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
181                        $p->set_file(Array('create_sector' => 'sectors_form.tpl'));
182                        $p->set_block('create_sector','list','list');
183
184                        // Seta variaveis utilizadas pelo tpl.
185                        $var = Array(
186                                'action'                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.validate_data_sectors_add'),
187                                'back_url'                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
188                                'th_bg'                         => $GLOBALS['phpgw_info']['theme']['th_bg'],
189                                'context'                       => $context == '' ? $GLOBALS['phpgw_info']['server']['ldap_context'] : $context,
190                                'sector'                        => $_POST['sector'],
191                                'disk_quota'        => $_POST['disk_quota'],
192                                'users_quota'       => $_POST['users_quota'],
193                                'manager_org'           => $combo_manager_org,
194                                'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '',
195                                'error_messages'        => $_POST['error_messages'] == '' ? '' : "<script type='text/javascript'>alert('".$_POST['error_messages']."')</script>",
196                        );
197                       
198                        if($this->functions->db_functions->use_cota_control()) {
199                                $var["open_comment_cotas"] = "";
200                                $var["close_comment_cotas"] ="";
201                        }
202                        else {
203                                $var["open_comment_cotas"] = "<!--";
204                                $var["close_comment_cotas"] ="-->";
205                        }       
206                       
207                        $p->set_var($var);
208                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
209
210                        $p->pfp('out','create_sector');
211                }
212               
213                function edit_sector()
214                {
215                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
216                        $acl = $this->functions->read_acl($account_lid);
217                        $manager_context = $acl[0]['context'];
218                       
219                        $context = $_GET['context'];
220
221                        $combo_manager_org = $this->functions->get_organizations($_GET['context'], '', true, true, true);
222                        $combo_manager_org = substr( $combo_manager_org, 0, ( strpos($combo_manager_org, '</option>') + 9 ) );
223
224                        $a_tmp = explode(",", ldap_dn2ufn($context));
225                        $sector_name = $a_tmp[0];
226                       
227                        // Verifica se tem acesso a este modulo
228                        if (!$this->functions->check_acl($account_lid,'edit_sectors'))
229                        {
230                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
231                        }
232
233                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
234                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
235                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Sector');
236                        $GLOBALS['phpgw']->common->phpgw_header();
237                       
238                        // Set o template
239                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
240                        $p->set_file(Array('edit_sector' => 'sectors_form.tpl'));
241                        $p->set_block('edit_sector','list','list');
242                       
243                        if (!$_POST)
244                        {
245                                $sector_info = $this->so->get_info($context);
246                                $sector_disk_quota = $sector_info[0]['diskquota'][0];
247                                $sector_users_quota = $sector_info[0]['usersquota'][0];
248                                $_POST['sector_visible'] = $sector_info[0]['phpgwaccountvisible'][0];
249                        }
250                       
251                        // Seta variaveis utilizadas pelo tpl.
252                        $var = Array(
253                                'action'                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.bosectors.save_sector'),
254                                'back_url'                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
255                                'th_bg'                         => $GLOBALS['phpgw_info']['theme']['th_bg'],
256                                'context'                       => $context == '' ? $manager_context : $context,
257                                'sector'                        => $_POST['sector'] == '' ? $sector_name : $_POST['sector'],
258                                'manager_org'           => $combo_manager_org,
259                                'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '',
260                                'disk_quota'        => $_POST['disk_quota'] == '' ? $sector_disk_quota : $_POST['disk_quota'],
261                                'users_quota'       => $_POST['users_quota'] == '' ? $sector_users_quota : $_POST['users_quota'],
262                               
263                                'lang_add'                      => lang('Add'),
264                                'disable'                       => 'disabled',
265                                'error_messages'        => $_POST['error_messages'] == '' ? '' : "<script type='text/javascript'>alert('".$_POST['error_messages']."')</script>",
266                                'lang_disk_quota'   => lang('disk quota'),
267                                'lang_users_quota'  => lang('users quota')
268                        );
269                        if($this->functions->db_functions->use_cota_control()) {
270                                $var["open_comment_cotas"] = "";
271                                $var["close_comment_cotas"] ="";
272                        }
273                        else {
274                                $var["open_comment_cotas"] = "<!--";
275                                $var["close_comment_cotas"] ="-->";
276                        }
277                        $p->set_var($var);
278                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
279                       
280                        $p->pfp('out','edit_sector');
281                }
282               
283                function view_cota()
284                {
285                        $context = $_GET['context'];
286                        $a_tmp = explode(",", ldap_dn2ufn($context));
287
288                        $sector_name = $a_tmp[0];
289                        if($this->functions->db_functions->use_cota_control()) {
290                                $sector_info = $this->so->get_info($context);
291                                $sector_disk_cota = $sector_info[0]['diskquota'][0];
292                                $sector_users_cota = $sector_info[0]['usersquota'][0];
293                        }
294                        else {
295                                $sector_disk_cota = lang('cotas control disabled');
296                                $sector_users_cota = lang('cotas control disabled');                           
297                        }
298
299
300                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
301                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
302                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Sector');
303                        $GLOBALS['phpgw']->common->phpgw_header();
304                       
305                        // Set o template
306                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
307                        $p->set_file(Array('ver_cota' => 'sectors_cota.tpl'));
308                       
309               
310                        // Seta variaveis utilizadas pelo tpl.
311                        $var = Array(
312                                'back_url'                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
313                                'th_bg'                         => $GLOBALS['phpgw_info']['theme']['th_bg'],
314                                'context'                       => $context,
315                                'sector'                        => $sector_name,
316                                'disk_cota'        => $sector_disk_cota,
317                                'users_cota'       => $sector_users_cota,
318                                'actual_users'          => $this->functions->get_num_users($context),
319                                'actual_disk'           => round($this->functions->get_actual_disk_usage($context),2),                         
320                               
321                                'lang_back'                     => lang('Back'),
322                                'lang_context'          => lang('Context'),
323                                'lang_sector_name'      => lang('Sector name'),
324                                'lang_disk_cota'   => lang('disk usage cota'),
325                                'lang_users_cota'  => lang('user number cota'),
326                                'lang_user_number'  => lang('user number'),
327                                'lang_disk_used'    => lang('disk usage'),                             
328                                'error_messages'        => $_POST['error_messages'] == '' ? '' : "<script type='text/javascript'>alert('".$_POST['error_messages']."')</script>",
329                        );
330                        $p->set_var($var);
331
332                        $p->pfp('out','ver_cota');
333                }                       
334               
335                function validate_data_sectors_add()
336                {
337                        $sector_name    = $_POST['sector'];
338                        $context                = $_POST['context'];
339                       
340                        // Verifica se o nome do sector nao esta vazio.
341                        if ($sector_name == '')
342                        {
343                                $_POST['error_messages'] = lang('Sector name is empty.');
344                                ExecMethod('expressoAdmin1_2.uisectors.add_sector');
345                                return;
346                        }
347                       
348                        // Verifica se o nome do setor existe no contexto atual.
349                        if ($this->so->exist_sector_name($sector_name, $context))
350                        {
351                                $_POST['error_messages'] = lang('Sector name already exist.');
352                                ExecMethod('expressoAdmin1_2.uisectors.add_sector');
353                                return;
354                        }
355                       
356                        ExecMethod('expressoAdmin1_2.bosectors.create_sector');
357                }
358
359                function delete_sector()
360                {
361                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
362                        $acl = $this->functions->read_acl($account_lid);
363                        $manager_context = $acl[0]['context'];
364                       
365                        // Verifica se tem acesso a este modulo
366                        if (!$this->functions->check_acl($account_lid,'delete_sectors'))
367                        {
368                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
369                        }
370                       
371                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
372                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
373                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Delete Sectors');
374                        $GLOBALS['phpgw']->common->phpgw_header();
375
376                        // Set o template
377                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
378                        $p->set_file(Array('delete_sector' => 'sectors_delete.tpl'));
379                        $p->set_block('delete_sector','list','list');
380                       
381                        $tmp_sector_name = $_GET['context'];
382                        $tmp_sector_name = explode(",",$tmp_sector_name);
383                        $tmp_sector_name = $tmp_sector_name[0];
384                        $tmp_sector_name = explode("=", $tmp_sector_name);
385                        $sector_name = $tmp_sector_name[1];
386                       
387                        // Get users of sector
388                        $sector_users           = $this->so->get_sector_users($_GET['context']);
389                        $sector_groups          = $this->so->get_sector_groups($_GET['context']);
390                        $sector_subsectors      = $this->so->get_sector_subsectors($_GET['context']);
391                       
392                        $users_list = '';
393                        foreach ($sector_users as $user)
394                        {
395                                $users_list .= $user['cn'][0] . '<br>';
396                        }
397                       
398                        $groups_list = '';
399                        foreach ($sector_groups as $group)
400                        {
401                                $groups_list .= $group['cn'][0] . '<br>';       
402                        }
403
404                        $subsectors_list = '';
405                        foreach ($sector_subsectors as $subsector)
406                        {
407                                if ($subsector['dn'] != $_GET['context'])
408                                        $subsectors_list .= $subsector['ou'][0] . '<br>';
409                        }
410
411                        // Seta variaveis utilizadas pelo tpl.
412                        $var = Array(
413                                'color_bg1'                                     => "#E8F0F0",
414                                'manager_context'                       => $manager_context,
415                                'dn'                                            => $_GET['context'],
416                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
417                                'action'                                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.bosectors.delete_sector'),
418                               
419                                'sector_name'                           => $sector_name,
420                                'users_list'                            => $users_list,
421                                'groups_list'                           => $groups_list,
422                                'sectors_list'                          => $subsectors_list
423                        );
424                        $p->set_var($var);
425                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
426                        $p->pfp('out','delete_sector');                 
427                }
428               
429                function row_action($action,$type,$context,$class='uisectors')
430                {
431                        return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
432                                'menuaction'            => 'expressoAdmin1_2.'.$class.'.'.$action.'_'.$type,
433                                'context'               => $context
434                        )).'"> '.lang($action).' </a>';
435                }
436               
437                function css()
438                {
439                        $appCSS = '';
440                        return $appCSS;
441                }
442               
443        }
444?>
Note: See TracBrowser for help on using the repository browser.