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

Revision 414, 14.6 KB checked in by niltonneto, 16 years ago (diff)

Alterações feitas por João Alfredo.
Email: jakjr@…

  • 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','expressoadmin','expressoAdmin1_2');
46                        $GLOBALS['phpgw']->js->validate_file('jscode','groups','expressoAdmin1_2');
47                }
48               
49                function list_groups()
50                {
51                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
52                        $manager_acl = $this->functions->read_acl($account_lid);
53                        $raw_context = $acl['raw_context'];
54                        $contexts = $manager_acl['contexts'];
55                        foreach ($manager_acl['contexts_display'] as $index=>$tmp_context)
56                        {
57                                $context_display .= '<br>'.$tmp_context;
58                        }
59                       
60                        // Verifica se tem acesso a este modulo
61                        if (!$this->functions->check_acl($account_lid,'list_groups'))
62                        {
63                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
64                        }
65
66                        if(isset($_POST['query']))
67                        {
68                                // limit query to limit characters
69                                if(eregi('^[a-z_0-9_-].+$',$_POST['query']))
70                                        $GLOBALS['query'] = $_POST['query'];
71                        }
72                                               
73                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
74                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
75                       
76                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('User groups');
77                        $GLOBALS['phpgw']->common->phpgw_header();
78
79                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
80                        $p->set_file(array('groups'   => 'groups.tpl'));
81                        $p->set_block('groups','list','list');
82                        $p->set_block('groups','row','row');
83                        $p->set_block('groups','row_empty','row_empty');
84
85                        // Seta as variaveis padroes.
86                        $var = Array(
87                                'th_bg'                                 => $GLOBALS['phpgw_info']['theme']['th_bg'],
88                                'back_url'                              => $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'),
89                                'add_action'                    => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uigroups.add_groups'),
90                                'add_group_disabled'    => $this->functions->check_acl($account_lid,'add_groups') ? '' : 'disabled',
91                                'context_display'               => $context_display
92                        );
93                        $p->set_var($var);
94                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
95                       
96                        // Save query
97                        $p->set_var('query', $GLOBALS['query']);
98                       
99                        //Admin make a search
100                        if ($GLOBALS['query'] != '')
101                        {
102                                $groups_info = $this->functions->get_list('groups', $GLOBALS['query'], $contexts);
103                        }
104                        $total = count($groups_info);
105
106                        if (!count($total) && $GLOBALS['query'] != '')
107                        {
108                                $p->set_var('message',lang('No matches found'));
109                        }
110                        else if ($total)
111                        {
112                                if ($this->functions->check_acl($account_lid,'edit_groups'))
113                                {
114                                        $can_edit = True;
115                                }
116                                if ($this->functions->check_acl($account_lid,'delete_groups'))
117                                {
118                                        $can_delete = True;
119                                }
120
121                                foreach($groups_info as $group)
122                                {
123                                        $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
124                                        $var = Array(
125                                                'tr_color'              => $tr_color,
126                                                'row_cn'                        => $group['cn'],
127                                                'row_description'       => $group['description']
128                                        );
129                                        $p->set_var($var);
130
131                                        if ($can_edit)
132                                        {
133                                                $p->set_var('edit_link',$this->row_action('edit','groups',$group['gidnumber'],$group['cn']));
134                                        }
135                                        else
136                                        {
137                                                $p->set_var('edit_link','&nbsp;');
138                                        }
139
140                                        if ($can_delete)
141                                        {
142                                                $p->set_var('delete_link',"<a href='#' onClick='javascript:delete_group(\"".$group['cn']."\",\"".$group['gidnumber']."\");'>Excluir</a>");
143                                        }
144                                        else
145                                        {
146                                                $p->set_var('delete_link','&nbsp;');
147                                        }
148
149                                        $p->fp('rows','row',True);
150                                }
151                        }
152                        $p->parse('rows','row_empty',True);
153                        $p->set_var($var);
154
155                        if (! $GLOBALS['phpgw']->acl->check('group_access',4,'admin'))
156                        {
157                                $p->set_var('input_add','<input type="submit" value="' . lang('Add') . '">');
158                        }
159                        if (! $GLOBALS['phpgw']->acl->check('group_access',2,'admin'))
160                        {
161                                $p->set_var('input_search',lang('Search') . '&nbsp;<input name="query" value="'.htmlspecialchars(stripslashes($GLOBALS['query'])).'">');
162                        }
163                        $p->pfp('out','list');
164                }
165               
166                function add_groups()
167                {
168                        $GLOBALS['phpgw']->js->set_onload('get_available_users(document.forms[0].org_context.value, document.forms[0].ea_check_allUsers.checked);');
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                        $GLOBALS['phpgw']->js->set_onload('get_available_users(document.forms[0].org_context.value, document.forms[0].ea_check_allUsers.checked);');
248
249                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
250                        $manager_acl = $this->functions->read_acl($manager_lid);
251                        $manager_contexts = $manager_acl['contexts'];
252
253                        // Verifica se tem acesso a este modulo
254                        if (!$this->functions->check_acl($manager_lid,'edit_groups'))
255                        {
256                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
257                        }
258
259                        // GET all infomations about the group.
260                        $group_info = $this->group->get_info($_GET['gidnumber']);
261
262                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
263                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
264                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Group');
265                        $GLOBALS['phpgw']->common->phpgw_header();
266
267                        // Set o template
268                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
269                        $p->set_file(Array('create_group' => 'groups_form.tpl'));
270                        $p->set_block('create_group','list','list');
271
272                        // Obtem combo das organizações e seleciona a org do grupo.
273                        foreach ($manager_contexts as $index=>$context)
274                                $combo_manager_org .= $this->functions->get_organizations($context, trim(strtolower($group_info['context'])));
275                        $combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], trim(strtolower($group_info['context'])));
276
277                        // Usuarios do grupo.
278                        $user_count = 0;
279                        if (count($group_info['memberuid_info']) > 0)
280                        {
281                                foreach ($group_info['memberuid_info'] as $uid=>$user_data)
282                                {
283                                        if ($user_data['uidnumber'])
284                                        {
285                                                $array_users[$user_data['uidnumber']] = $user_data['cn'];
286                                                $array_users_uid[$user_data['uidnumber']] = $uid;
287                                                $array_users_type[$user_data['uidnumber']] = $user_data['type'];
288                                        }
289                                        else
290                                        {
291                                                $array_users[$uid] = $user_data['cn'];
292                                        }
293                                }
294                                natcasesort($array_users);
295                               
296                                foreach ($array_users as $uidnumber=>$cn)
297                                {
298                                        $user_count++;
299                                        if ($array_users_type[$uidnumber] == 'u')
300                                        {
301                                                $users .= "<option value=" . $uidnumber . ">" . $cn . " [" . $array_users_uid[$uidnumber] . "]</option>";
302                                        }
303                                        else
304                                        {
305                                                $unknow .= "<option value=-1>" . $cn . " [Corrigir manualmente]</option>";
306                                        }
307                                }
308                               
309                                $opt_tmp_users  = '<option  value="-1" disabled>-----------------------------&nbsp;&nbsp;&nbsp;&nbsp;Usuários&nbsp;&nbsp;&nbsp;&nbsp;---------------------------- </option>'."\n";
310                                $opt_tmp_unknow = '<option  value="-1" disabled>------------&nbsp;&nbsp;&nbsp;&nbsp;Usuários não encontrados no BD, somente no LDAP     &nbsp;&nbsp;&nbsp;&nbsp;------------</option>'."\n";
311                                $ea_select_usersInGroup = $unknow != '' ? $opt_tmp_unknow . $unknow . $opt_tmp_users . $users : $opt_tmp_users . $users;
312                        }
313                       
314                        // Chama funcao para criar lista de aplicativos disponiveis.
315                        $apps = $this->functions->make_list_app($manager_lid, $group_info['apps']);
316                       
317                        // Cria combo de dominios do samba
318                        if ($this->current_config['expressoAdmin_samba_support'] == 'true')
319                        {
320                                $a_sambadomains = $this->db_functions->get_sambadomains_list();
321                                $sambadomainname_options = '';
322                                if (count($a_sambadomains))
323                                {
324                                        foreach ($a_sambadomains as $a_sambadomain)
325                                        {
326                                                if ($a_sambadomain['samba_domain_sid'] == $group_info['sambasid'])
327                                                        $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "' SELECTED>" . $a_sambadomain['samba_domain_name'] . "</option>";
328                                                else
329                                                        $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "'>" . $a_sambadomain['samba_domain_name'] . "</option>";
330                                        }
331                                }
332                        }
333                       
334                        // Seta variaveis utilizadas pelo tpl.
335                        $var = Array(
336                                'color_bg1'                                     => "#E8F0F0",
337                                'color_bg2'                                     => "#D3DCE3",
338                                'type'                                          => 'edit_group',
339                                'ldap_context'                          => $GLOBALS['phpgw_info']['server']['ldap_context'],
340                                'gidnumber'                                     => $group_info['gidnumber'],
341                                'cn'                                            => $group_info['cn'],
342                                'user_count'                            => $user_count,
343                                'email'                                         => $group_info['email'],
344                                'description'                           => $group_info['description'],
345                                'apps'                                          => $apps,
346                                'use_attrs_samba_checked'       => $group_info['sambaGroup'] ? 'CHECKED' : '',
347                                'disabled_samba'                        => $group_info['sambaGroup'] ? '' : 'disabled',
348                                'disable_email_groups'          => $this->functions->check_acl($manager_lid,'edit_email_groups') ? '' : 'disabled',
349                                'sambadomainname_options'       => $sambadomainname_options,
350                                'phpgwaccountvisible_checked'   => $group_info['phpgwaccountvisible'] == '-1' ? 'CHECKED' : '',
351                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uigroups.list_groups'),
352                                'combo_manager_org'                     => $combo_manager_org,
353                                'combo_all_orgs'                        => $combo_all_orgs,
354                                'ea_select_usersInGroup'        => $ea_select_usersInGroup
355                        );
356                        $p->set_var($var);
357                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
358                        $p->pfp('out','create_group');
359                }
360                               
361                function row_action($action,$type,$gidnumber,$group_name)
362                {
363                        return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
364                                'menuaction'            => 'expressoAdmin1_2.uigroups.'.$action.'_'.$type,
365                                'gidnumber'             => $gidnumber,
366                                'group_name'    => $group_name
367                        )).'"> '.lang($action).' </a>';
368                }
369               
370                function css()
371                {
372                        $appCSS = '';
373                        return $appCSS;
374                }
375               
376        }
377?>
Note: See TracBrowser for help on using the repository browser.