source: branches/2.2/expressoAdmin1_2/inc/class.uisectors.inc.php @ 3887

Revision 3887, 15.9 KB checked in by eduardoalex, 13 years ago (diff)

Ticket #1250 - Adição do controle de quotas por OU

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