source: trunk/expressoAdmin1_2/inc/class.uigroups.inc.php @ 7655

Revision 7655, 14.5 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Melhorias de performance no codigo do Expresso.

  • 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 uigroups
13        {
14                var $public_functions = array
15                (
16                        'list_groups'   => True,
17                        'add_groups'    => True,
18                        'edit_groups'   => True,
19                        'css'                   => True
20                );
21
22                var $nextmatchs;
23                var $group;
24                var $functions;
25                var $ldap_functions;
26                var $db_functions;
27                       
28                function uigroups()
29                {
30                        $this->group            = CreateObject('expressoAdmin1_2.group');
31                        $this->nextmatchs       = createobject('phpgwapi.nextmatchs');
32                        $this->functions        = CreateObject('expressoAdmin1_2.functions');
33                        $this->ldap_functions = CreateObject('expressoAdmin1_2.ldap_functions');
34                        $this->db_functions = CreateObject('expressoAdmin1_2.db_functions');
35                       
36                        $c = CreateObject('phpgwapi.config','expressoAdmin1_2');
37                        $c->read_repository();
38                        $this->current_config = $c->config_data;
39                       
40                        if(!@is_object($GLOBALS['phpgw']->js))
41                        {
42                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
43                        }
44                        $GLOBALS['phpgw']->js->validate_file('jscode','connector','expressoAdmin1_2');#diretorio, arquivo.js, aplicacao
45                        $GLOBALS['phpgw']->js->validate_file('jscode','finder','expressoAdmin1_2');
46                        $GLOBALS['phpgw']->js->validate_file('jscode','expressoadmin','expressoAdmin1_2');
47                        $GLOBALS['phpgw']->js->validate_file('jscode','groups','expressoAdmin1_2');
48                }
49               
50                function list_groups()
51                {
52                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
53                        $manager_acl = $this->functions->read_acl($account_lid);
54                        $raw_context = $acl['raw_context'];
55                        $contexts = $manager_acl['contexts'];
56                        foreach ($manager_acl['contexts_display'] as $index=>$tmp_context)
57                        {
58                                $context_display .= '<br>'.$tmp_context;
59                        }
60                       
61                        // Verifica se tem acesso a este modulo
62                        if (!$this->functions->check_acl($account_lid,'list_groups'))
63                        {
64                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
65                        }
66
67                        if(isset($_POST['query']))
68                        {
69                                // limit query to limit characters
70                                if(preg_match('/^[a-z_0-9_-].+$/i',$_POST['query']))
71                                        $GLOBALS['query'] = $_POST['query'];
72                        }
73                                               
74                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
75                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
76                       
77                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('User groups');
78                        $GLOBALS['phpgw']->common->phpgw_header();
79
80                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
81                        $p->set_file(array('groups'   => 'groups.tpl'));
82                        $p->set_block('groups','list','list');
83                        $p->set_block('groups','row','row');
84                        $p->set_block('groups','row_empty','row_empty');
85
86                        // Seta as variaveis padroes.
87                        $var = Array(
88                                'th_bg'                                 => $GLOBALS['phpgw_info']['theme']['th_bg'],
89                                'back_url'                              => $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'),
90                                'add_action'                    => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uigroups.add_groups'),
91                                'add_group_disabled'    => $this->functions->check_acl($account_lid,'add_groups') ? '' : 'disabled',
92                                'context_display'               => $context_display
93                        );
94                        $p->set_var($var);
95                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
96                       
97                        // Save query
98                        $p->set_var('query', $GLOBALS['query']);
99                       
100                        //Admin make a search
101                        if ($GLOBALS['query'] != '')
102                        {
103                                $groups_info = $this->functions->get_list('groups', $GLOBALS['query'], $contexts);
104                        }
105                        $total = count($groups_info);
106
107                        if (!count($total) && $GLOBALS['query'] != '')
108                        {
109                                $p->set_var('message',lang('No matches found'));
110                        }
111                        else if ($total)
112                        {
113                                if ($this->functions->check_acl($account_lid,'edit_groups'))
114                                {
115                                        $can_edit = True;
116                                }
117                                if ($this->functions->check_acl($account_lid,'delete_groups'))
118                                {
119                                        $can_delete = True;
120                                }
121
122                                foreach($groups_info as $group)
123                                {
124                                        $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
125                                        $var = Array(
126                                                'tr_color'              => $tr_color,
127                                                'row_cn'                        => $group['cn'],
128                                                'row_description'       => $group['description']
129                                        );
130                                        $p->set_var($var);
131
132                                        if ($can_edit)
133                                        {
134                                                $p->set_var('edit_link',$this->row_action('edit','groups',$group['gidnumber'],$group['cn']));
135                                        }
136                                        else
137                                        {
138                                                $p->set_var('edit_link','&nbsp;');
139                                        }
140
141                                        if ($can_delete)
142                                        {
143                                                $p->set_var('delete_link',"<a href='#' onClick='javascript:delete_group(\"".$group['cn']."\",\"".$group['gidnumber']."\");'>".lang('to delete')."</a>");
144                                        }
145                                        else
146                                        {
147                                                $p->set_var('delete_link','&nbsp;');
148                                        }
149
150                                        $p->fp('rows','row',True);
151                                }
152                        }
153                        $p->parse('rows','row_empty',True);
154                        $p->set_var($var);
155
156                        if (! $GLOBALS['phpgw']->acl->check('run',4,'admin'))
157                        {
158                                $p->set_var('input_add','<input type="submit" value="' . lang('Add') . '">');
159                        }
160                        if (! $GLOBALS['phpgw']->acl->check('run',2,'admin'))
161                        {
162                                $p->set_var('input_search',lang('Search') . '&nbsp;<input name="query" value="'.htmlspecialchars(stripslashes($GLOBALS['query'])).'">');
163                        }
164                        $p->pfp('out','list');
165                }
166               
167                function add_groups()
168                {
169                        if ($this->current_config['expressoAdmin_samba_support'] == 'true')
170                                $GLOBALS['phpgw']->js->set_onload('get_available_sambadomains(document.forms[0].context.value, \'create_group\');');
171
172                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
173                        $manager_acl = $this->functions->read_acl($manager_lid);
174                        $manager_contexts = $manager_acl['contexts'];
175                       
176                        // Verifica se tem acesso a este modulo
177                        if (!$this->functions->check_acl($manager_lid,'add_groups'))
178                        {
179                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
180                        }
181
182                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
183                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
184                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Create Group');
185                        $GLOBALS['phpgw']->common->phpgw_header();
186                       
187                        // Set o template
188                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
189                        $p->set_file(Array('create_group' => 'groups_form.tpl'));
190                        $p->set_block('create_group','list','list');
191
192                        // Pega combo das organizações e seleciona um dos setores em caso de um erro na validaçao dos dados.
193                        //$combo_manager_org = $this->functions->get_organizations($manager_context, trim(strtolower($group_info['context'])));
194                        foreach ($manager_contexts as $index=>$context)
195                                $combo_manager_org .= $this->functions->get_organizations($context, trim(strtolower($group_info['context'])));
196                        $combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], trim(strtolower($group_info['context'])));
197                       
198                        // Chama funcao para criar lista de aplicativos disponiveis.
199                        $apps = $this->functions->make_list_app($manager_lid);
200                       
201                        // Cria combo de dominio samba
202                        if ($this->current_config['expressoAdmin_samba_support'] == 'true')
203                        {
204                                $a_sambadomains = $this->db_functions->get_sambadomains_list();
205                                $sambadomainname_options = '';
206                                if (count($a_sambadomains))
207                                {
208                                        foreach ($a_sambadomains as $a_sambadomain)
209                                        {
210                                                // So mostra os sambaDomainName do contexto do manager
211                                                if ($this->ldap_functions->exist_sambadomains($manager_contexts, $a_sambadomain['samba_domain_name']))
212                                                        $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "'>" . $a_sambadomain['samba_domain_name'] . "</option>";
213                                        }
214                                }
215                        }
216                       
217                        // Seta variaveis utilizadas pelo tpl.
218                        $var = Array(
219                                'color_bg1'                                     => "#E8F0F0",
220                                'color_bg2'                                     => "#D3DCE3",
221                                'type'                                          => 'create_group',
222                                'cn'                                            => '',
223                                'restrictionsOnGroup'           => $this->current_config['expressoAdmin_restrictionsOnGroup'],
224                                'type'                                          => 'create_group',
225                                'ldap_context'                          => $GLOBALS['phpgw_info']['server']['ldap_context'],
226                                'ufn_ldap_context'                      => ldap_dn2ufn($GLOBALS['phpgw_info']['server']['ldap_context']),
227                                'concatenateDomain'                     => $this->current_config['expressoAdmin_concatenateDomain'],
228                                'defaultDomain'                         => $this->current_config['expressoAdmin_defaultDomain'],
229                                'apps'                                          => $apps,
230                                'use_attrs_samba_checked'       => '',
231                                'disabled_samba'                        => 'disabled',
232                                'display_samba_options'         => $this->current_config['expressoAdmin_samba_support'] == 'true' ? '' : '"display:none"',
233                                'disable_email_groups'          => $this->functions->check_acl($manager_lid,'edit_email_groups') ? '' : 'disabled',
234                                'sambadomainname_options'       => $sambadomainname_options,
235                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uigroups.list_groups'),
236                                'combo_manager_org'                     => $combo_manager_org,
237                                'combo_all_orgs'                        => $combo_all_orgs
238                        );
239                        $p->set_var($var);
240                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
241                       
242                        $p->pfp('out','create_group');
243                }
244               
245                function edit_groups()
246                {
247                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
248                        $manager_acl = $this->functions->read_acl($manager_lid);
249                        $manager_contexts = $manager_acl['contexts'];
250
251                        // Verifica se tem acesso a este modulo
252                        if (!$this->functions->check_acl($manager_lid,'edit_groups'))
253                        {
254                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
255                        }
256
257                        // GET all infomations about the group.
258                        $group_info = $this->group->get_info($_GET['gidnumber']);
259
260                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
261                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
262                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Group');
263                        $GLOBALS['phpgw']->common->phpgw_header();
264
265                        // Set o template
266                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
267                        $p->set_file(Array('create_group' => 'groups_form.tpl'));
268                        $p->set_block('create_group','list','list');
269
270                        // Obtem combo das organizações e seleciona a org do grupo.
271                        foreach ($manager_contexts as $index=>$context)
272                                $combo_manager_org .= $this->functions->get_organizations($context, trim(strtolower($group_info['context'])));
273                        $combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], trim(strtolower($group_info['context'])));
274
275                        // Usuarios do grupo.
276                        $user_count = 0;
277                        if (count($group_info['memberuid_info']) > 0)
278                        {
279                                foreach ($group_info['memberuid_info'] as $uid=>$user_data)
280                                {
281                                        if ($user_data['uidnumber'])
282                                        {
283                                                $array_users[$user_data['uidnumber']] = $user_data['cn'];
284                                                $array_users_uid[$user_data['uidnumber']] = $uid;
285                                                $array_users_type[$user_data['uidnumber']] = $user_data['type'];
286                                        }
287                                        else
288                                        {
289                                                $array_users[$uid] = $user_data['cn'];
290                                        }
291                                }
292                                natcasesort($array_users);
293                               
294                                foreach ($array_users as $uidnumber=>$cn)
295                                {
296                                        ++$user_count;
297                                        if ($array_users_type[$uidnumber] == 'u')
298                                        {
299                                                $users .= "<option value=" . $uidnumber . ">" . utf8_decode($cn) . " (" . $array_users_uid[$uidnumber] . ")</option>";
300                                        }
301/*                                      else
302                                        {
303                                                $unknow .= "<option value=-1>" . utf8_decode($cn) . " (Corrigir manualmente)</option>";
304                                        }*/
305                                }
306                               
307                                $opt_tmp_users  = '<option  value="-1" disabled>-----------------------------&nbsp;&nbsp;&nbsp;&nbsp;'.lang('users').'&nbsp;&nbsp;&nbsp;&nbsp;---------------------------- </option>'."\n";
308                                $opt_tmp_unknow = '<option  value="-1" disabled>------------&nbsp;&nbsp;&nbsp;&nbsp;'.lang('users did not find on DB, only on ldap').'&nbsp;&nbsp;&nbsp;&nbsp;------------</option>'."\n";
309                                $ea_select_usersInGroup = $unknow != '' ? $opt_tmp_unknow . $unknow . $opt_tmp_users . $users : $opt_tmp_users . $users;
310                        }
311                       
312                        // Chama funcao para criar lista de aplicativos disponiveis.
313                        $apps = $this->functions->make_list_app($manager_lid, $group_info['apps']);
314                       
315                        // Cria combo de dominios do samba
316                        if ($this->current_config['expressoAdmin_samba_support'] == 'true')
317                        {
318                                $a_sambadomains = $this->db_functions->get_sambadomains_list();
319                                $sambadomainname_options = '';
320                                if (count($a_sambadomains))
321                                {
322                                        foreach ($a_sambadomains as $a_sambadomain)
323                                        {
324                                                if ($a_sambadomain['samba_domain_sid'] == $group_info['sambasid'])
325                                                        $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "' SELECTED>" . $a_sambadomain['samba_domain_name'] . "</option>";
326                                                else
327                                                        $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "'>" . $a_sambadomain['samba_domain_name'] . "</option>";
328                                        }
329                                }
330                        }
331                       
332                        // Seta variaveis utilizadas pelo tpl.
333                        $var = Array(
334                                'color_bg1'                                     => "#E8F0F0",
335                                'color_bg2'                                     => "#D3DCE3",
336                                'type'                                          => 'edit_group',
337                                'ldap_context'                          => $GLOBALS['phpgw_info']['server']['ldap_context'],
338                                'gidnumber'                                     => $group_info['gidnumber'],
339                                'cn'                                            => $group_info['cn'],
340                                'user_count'                            => $user_count,
341                                'email'                                         => $group_info['email'],
342                                'description'                           => $group_info['description'],
343                                'apps'                                          => $apps,
344                                'use_attrs_samba_checked'       => $group_info['sambaGroup'] ? 'CHECKED' : '',
345                                'disabled_samba'                        => $group_info['sambaGroup'] ? '' : 'disabled',
346                                'disable_email_groups'          => $this->functions->check_acl($manager_lid,'edit_email_groups') ? '' : 'disabled',
347                                'sambadomainname_options'       => $sambadomainname_options,
348                                'phpgwaccountvisible_checked'   => $group_info['phpgwaccountvisible'] == '-1' ? 'CHECKED' : '',
349                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uigroups.list_groups'),
350                                'combo_manager_org'                     => $combo_manager_org,
351                                'combo_all_orgs'                        => $combo_all_orgs,
352                                'ea_select_usersInGroup'        => $ea_select_usersInGroup
353                        );
354                        $p->set_var($var);
355                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
356                        $p->pfp('out','create_group');
357                }
358                               
359                function row_action($action,$type,$gidnumber,$group_name)
360                {
361                        return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
362                                'menuaction'            => 'expressoAdmin1_2.uigroups.'.$action.'_'.$type,
363                                'gidnumber'             => $gidnumber,
364                                'group_name'    => $group_name
365                        )).'"> '.lang($action).' </a>';
366                }
367               
368                function css()
369                {
370                        $appCSS = '';
371                        return $appCSS;
372                }
373               
374        }
375?>
Note: See TracBrowser for help on using the repository browser.