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

Revision 3359, 15.6 KB checked in by eduardoalex, 13 years ago (diff)

Ticket #1226 - Correcao do erro narrado no ticket em questão

  • 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                                'manager_org'           => $combo_manager_org,
199                                'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '',
200                                'error_messages'        => $_POST['error_messages'] == '' ? '' : "<script type='text/javascript'>alert('".$_POST['error_messages']."')</script>",
201                        );
202                       
203                        if($this->functions->db_functions->use_cota_control()) {
204                                $var["open_comment_cotas"] = "";
205                                $var["close_comment_cotas"] ="";
206                        }
207                        else {
208                                $var["open_comment_cotas"] = "<!--";
209                                $var["close_comment_cotas"] ="-->";
210                        }       
211                       
212                        $p->set_var($var);
213                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
214
215                        $p->pfp('out','create_sector');
216                }
217               
218                function edit_sector()
219                {
220                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
221                        $acl = $this->functions->read_acl($account_lid);
222                        $manager_context = $acl[0]['context'];
223                       
224                        $context = $_GET['context'];
225
226                        $combo_manager_org = $this->functions->get_organizations($_GET['context'], '', true, true, true);
227                        $combo_manager_org = substr( $combo_manager_org, 0, ( strpos($combo_manager_org, '</option>') + 9 ) );
228
229                        $a_tmp = explode(",", ldap_dn2ufn($context));
230                        $sector_name = $a_tmp[0];
231                       
232                        // Verifica se tem acesso a este modulo
233                        if (!$this->functions->check_acl($account_lid,'edit_sectors'))
234                        {
235                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
236                        }
237
238                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
239                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
240                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Sector');
241                        $GLOBALS['phpgw']->common->phpgw_header();
242                       
243                        // Set o template
244                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
245                        $p->set_file(Array('edit_sector' => 'sectors_form.tpl'));
246                        $p->set_block('edit_sector','list','list');
247                       
248                        if (!$_POST)
249                        {
250                                $sector_info = $this->so->get_info($context);
251                                $sector_disk_quota = $sector_info[0]['diskquota'][0];
252                                $sector_users_quota = $sector_info[0]['usersquota'][0];
253                                $sector_associated_domain = $sector_info[0]['associateddomain'][0];
254                                $_POST['sector_visible'] = $sector_info[0]['phpgwaccountvisible'][0];
255                        }
256                       
257                        // Seta variaveis utilizadas pelo tpl.
258                        $var = Array(
259                                'action'                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.bosectors.save_sector'),
260                                'back_url'                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
261                                'th_bg'                         => $GLOBALS['phpgw_info']['theme']['th_bg'],
262                                'context'                       => $context == '' ? $manager_context : $context,
263                                'sector'                        => $_POST['sector'] == '' ? $sector_name : $_POST['sector'],
264                                'manager_org'           => $combo_manager_org,
265                                'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '',
266                                'associated_domain'        => $_POST['associated_domain'] == '' ? $sector_associated_domain : $_POST['associated_domain'],
267                                'disk_quota'        => $_POST['disk_quota'] == '' ? $sector_disk_quota : $_POST['disk_quota'],
268                                'users_quota'       => $_POST['users_quota'] == '' ? $sector_users_quota : $_POST['users_quota'],
269                                'lang_add'                      => lang('Add'),
270                                'disable'                       => 'disabled',
271                                'error_messages'        => $_POST['error_messages'] == '' ? '' : "<script type='text/javascript'>alert('".$_POST['error_messages']."')</script>",
272                                'lang_disk_quota'   => lang('disk quota'),
273                                'lang_users_quota'  => lang('users quota')
274                        );
275                        if($this->functions->db_functions->use_cota_control()) {
276                                $var["open_comment_cotas"] = "";
277                                $var["close_comment_cotas"] ="";
278                        }
279                        else {
280                                $var["open_comment_cotas"] = "<!--";
281                                $var["close_comment_cotas"] ="-->";
282                        }
283                        $p->set_var($var);
284                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
285                       
286                        $p->pfp('out','edit_sector');
287                }
288               
289                function view_cota()
290                {
291                        $context = $_GET['context'];
292                        $a_tmp = explode(",", ldap_dn2ufn($context));
293
294                        $sector_name = $a_tmp[0];
295                        if($this->functions->db_functions->use_cota_control()) {
296                                $sector_info = $this->so->get_info($context);
297                                $sector_disk_cota = $sector_info[0]['diskquota'][0];
298                                $sector_users_cota = $sector_info[0]['usersquota'][0];
299                        }
300                        else {
301                                $sector_disk_cota = lang('cotas control disabled');
302                                $sector_users_cota = lang('cotas control disabled');                           
303                        }
304
305
306                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
307                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
308                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Sector');
309                        $GLOBALS['phpgw']->common->phpgw_header();
310                       
311                        // Set o template
312                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
313                        $p->set_file(Array('ver_cota' => 'sectors_cota.tpl'));
314                       
315               
316                        // Seta variaveis utilizadas pelo tpl.
317                        $var = Array(
318                                'back_url'                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
319                                'th_bg'                         => $GLOBALS['phpgw_info']['theme']['th_bg'],
320                                'context'                       => $context,
321                                'sector'                        => $sector_name,
322                                'disk_cota'        => $sector_disk_cota,
323                                'users_cota'       => $sector_users_cota,
324                                'actual_users'          => $this->functions->get_num_users($context),
325                                'actual_disk'           => round($this->functions->get_actual_disk_usage($context),2),                         
326                               
327                                'lang_back'                     => lang('Back'),
328                                'lang_context'          => lang('Context'),
329                                'lang_sector_name'      => lang('Sector name'),
330                                'lang_disk_cota'   => lang('disk usage cota'),
331                                'lang_users_cota'  => lang('user number cota'),
332                                'lang_user_number'  => lang('user number'),
333                                'lang_disk_used'    => lang('disk usage'),                             
334                                'error_messages'        => $_POST['error_messages'] == '' ? '' : "<script type='text/javascript'>alert('".$_POST['error_messages']."')</script>",
335                        );
336                        $p->set_var($var);
337
338                        $p->pfp('out','ver_cota');
339                }                       
340               
341                function validate_data_sectors_add()
342                {
343                        $sector_name    = $_POST['sector'];
344                        $context                = $_POST['context'];
345                       
346                        // Verifica se o nome do sector nao esta vazio.
347                        if ($sector_name == '')
348                        {
349                                $_POST['error_messages'] = lang('Sector name is empty.');
350                                ExecMethod('expressoAdmin1_2.uisectors.add_sector');
351                                return;
352                        }
353                       
354                        // Verifica se o nome do setor existe no contexto atual.
355                        if ($this->so->exist_sector_name($sector_name, $context))
356                        {
357                                $_POST['error_messages'] = lang('Sector name already exist.');
358                                ExecMethod('expressoAdmin1_2.uisectors.add_sector');
359                                return;
360                        }
361                       
362                        ExecMethod('expressoAdmin1_2.bosectors.create_sector');
363                }
364
365                function delete_sector()
366                {
367                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
368                        $acl = $this->functions->read_acl($account_lid);
369                        $manager_context = $acl[0]['context'];
370                       
371                        // Verifica se tem acesso a este modulo
372                        if (!$this->functions->check_acl($account_lid,'delete_sectors'))
373                        {
374                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
375                        }
376                       
377                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
378                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
379                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Delete Sectors');
380                        $GLOBALS['phpgw']->common->phpgw_header();
381
382                        // Set o template
383                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
384                        $p->set_file(Array('delete_sector' => 'sectors_delete.tpl'));
385                        $p->set_block('delete_sector','list','list');
386                       
387                        $tmp_sector_name = $_GET['context'];
388                        $tmp_sector_name = explode(",",$tmp_sector_name);
389                        $tmp_sector_name = $tmp_sector_name[0];
390                        $tmp_sector_name = explode("=", $tmp_sector_name);
391                        $sector_name = $tmp_sector_name[1];
392                       
393                        // Get users of sector
394                        $sector_users           = $this->so->get_sector_users($_GET['context']);
395                        $sector_groups          = $this->so->get_sector_groups($_GET['context']);
396                        $sector_subsectors      = $this->so->get_sector_subsectors($_GET['context']);
397                       
398                        $users_list = '';
399                        foreach ($sector_users as $user)
400                        {
401                                $users_list .= $user['cn'][0] . '<br>';
402                        }
403                       
404                        $groups_list = '';
405                        foreach ($sector_groups as $group)
406                        {
407                                $groups_list .= $group['cn'][0] . '<br>';       
408                        }
409
410                        $subsectors_list = '';
411                        foreach ($sector_subsectors as $subsector)
412                        {
413                                if ($subsector['dn'] != $_GET['context'])
414                                        $subsectors_list .= $subsector['ou'][0] . '<br>';
415                        }
416
417                        // Seta variaveis utilizadas pelo tpl.
418                        $var = Array(
419                                'color_bg1'                                     => "#E8F0F0",
420                                'manager_context'                       => $manager_context,
421                                'dn'                                            => $_GET['context'],
422                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
423                                'action'                                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.bosectors.delete_sector'),
424                               
425                                'sector_name'                           => $sector_name,
426                                'users_list'                            => $users_list,
427                                'groups_list'                           => $groups_list,
428                                'sectors_list'                          => $subsectors_list
429                        );
430                        $p->set_var($var);
431                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
432                        $p->pfp('out','delete_sector');                 
433                }
434               
435                function row_action($action,$type,$context,$class='uisectors')
436                {
437                        return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
438                                'menuaction'            => 'expressoAdmin1_2.'.$class.'.'.$action.'_'.$type,
439                                'context'               => $context
440                        )).'"> '.lang($action).' </a>';
441                }
442               
443                function css()
444                {
445                        $appCSS = '';
446                        return $appCSS;
447                }
448               
449        }
450?>
Note: See TracBrowser for help on using the repository browser.