source: branches/2.4/expressoAdmin1_2/inc/class.uisectors.inc.php @ 6754

Revision 6754, 18.5 KB checked in by niltonneto, 12 years ago (diff)

Ticket #0000 - Copiadas as alterações do Trunk. Versão final da 2.4.1.

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