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

Revision 309, 16.9 KB checked in by niltonneto, 16 years ago (diff)

Sincronização com versão publicada em 04/06/2008.

  • 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'                             => $context,
92                                'context_display'               => $context_display,
93                                'lang_groups_names'             => lang('Groups Names'),
94                                'lang_description'              => lang('Description'),
95                                'lang_add_groups'               => lang('Add Groups'),
96                                'lang_edit'                     => lang('Edit'),
97                                'lang_delete'                   => lang('Delete'),
98                                'lang_back'                             => lang('back'),
99                                'lang_context'                  => lang('context'),
100                                'lang_search'                   => lang('search')
101                        );
102                        $p->set_var($var);
103                       
104                        // Save query
105                        $p->set_var('query', $GLOBALS['query']);
106                       
107                        //Admin make a search
108                        if ($GLOBALS['query'] != '')
109                        {
110                                $groups_info = $this->functions->get_list('groups', $GLOBALS['query'], $contexts);
111                        }
112                        $total = count($groups_info);
113
114                        if (!count($total) && $GLOBALS['query'] != '')
115                        {
116                                $p->set_var('message',lang('No matches found'));
117                        }
118                        else if ($total)
119                        {
120                                if ($this->functions->check_acl($account_lid,'edit_groups'))
121                                {
122                                        $can_edit = True;
123                                }
124                                if ($this->functions->check_acl($account_lid,'delete_groups'))
125                                {
126                                        $can_delete = True;
127                                }
128
129                                foreach($groups_info as $group)
130                                {
131                                        $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
132                                        $var = Array(
133                                                'tr_color'              => $tr_color,
134                                                'row_cn'                        => $group['cn'],
135                                                'row_description'       => $group['description']
136                                        );
137                                        $p->set_var($var);
138
139                                        if ($can_edit)
140                                        {
141                                                $p->set_var('edit_link',$this->row_action('edit','groups',$group['gidnumber'],$group['cn']));
142                                        }
143                                        else
144                                        {
145                                                $p->set_var('edit_link','&nbsp;');
146                                        }
147
148                                        if ($can_delete)
149                                        {
150                                                $p->set_var('delete_link',"<a href='#' onClick='javascript:delete_group(\"".$group['cn']."\",\"".$group['gidnumber']."\");'>Excluir</a>");
151                                        }
152                                        else
153                                        {
154                                                $p->set_var('delete_link','&nbsp;');
155                                        }
156
157                                        $p->fp('rows','row',True);
158                                }
159                        }
160                        $p->parse('rows','row_empty',True);
161                        $p->set_var($var);
162
163                        if (! $GLOBALS['phpgw']->acl->check('group_access',4,'admin'))
164                        {
165                                $p->set_var('input_add','<input type="submit" value="' . lang('Add') . '">');
166                        }
167                        if (! $GLOBALS['phpgw']->acl->check('group_access',2,'admin'))
168                        {
169                                $p->set_var('input_search',lang('Search') . '&nbsp;<input name="query" value="'.htmlspecialchars(stripslashes($GLOBALS['query'])).'">');
170                        }
171                        $p->pfp('out','list');
172                }
173               
174                function add_groups()
175                {
176                        $GLOBALS['phpgw']->js->set_onload('get_available_users(document.forms[0].org_context.value, document.forms[0].ea_check_allUsers.checked);');
177                        if ($this->current_config['expressoAdmin_samba_support'] == 'true')
178                                $GLOBALS['phpgw']->js->set_onload('get_available_sambadomains(document.forms[0].context.value, \'create_group\');');
179
180                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
181                        $manager_acl = $this->functions->read_acl($manager_lid);
182                        $manager_contexts = $manager_acl['contexts'];
183                       
184                        // Verifica se tem acesso a este modulo
185                        if (!$this->functions->check_acl($manager_lid,'add_groups'))
186                        {
187                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
188                        }
189
190                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
191                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
192                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Create Group');
193                        $GLOBALS['phpgw']->common->phpgw_header();
194                       
195                        // Set o template
196                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
197                        $p->set_file(Array('create_group' => 'groups_form.tpl'));
198
199                        // Pega combo das organizações e seleciona um dos setores em caso de um erro na validaçao dos dados.
200                        //$combo_manager_org = $this->functions->get_organizations($manager_context, trim(strtolower($group_info['context'])));
201                        foreach ($manager_contexts as $index=>$context)
202                                $combo_manager_org .= $this->functions->get_organizations($context, trim(strtolower($group_info['context'])));
203                        $combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], trim(strtolower($group_info['context'])));
204                       
205                        // Chama funcao para criar lista de aplicativos disponiveis.
206                        $apps = $this->functions->make_list_app($manager_lid);
207                       
208                        // Cria combo de dominio samba
209                        if ($this->current_config['expressoAdmin_samba_support'] == 'true')
210                        {
211                                $a_sambadomains = $this->db_functions->get_sambadomains_list();
212                                $sambadomainname_options = '';
213                                if (count($a_sambadomains))
214                                {
215                                        foreach ($a_sambadomains as $a_sambadomain)
216                                        {
217                                                // So mostra os sambaDomainName do contexto do manager
218                                                if ($this->ldap_functions->exist_sambadomains($manager_contexts, $a_sambadomain['samba_domain_name']))
219                                                        $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "'>" . $a_sambadomain['samba_domain_name'] . "</option>";
220                                        }
221                                }
222                        }
223                       
224                        // Seta variaveis utilizadas pelo tpl.
225                        $var = Array(
226                                'color_bg1'                                     => "#E8F0F0",
227                                'color_bg2'                                     => "#D3DCE3",
228                                'type'                                          => 'create_group',
229                                'cn'                                            => '',
230                                'restrictionsOnGroup'           => $this->current_config['expressoAdmin_restrictionsOnGroup'],
231                                'type'                                          => 'create_group',
232                                'ldap_context'                          => $GLOBALS['phpgw_info']['server']['ldap_context'],
233                                'ufn_ldap_context'                      => ldap_dn2ufn($GLOBALS['phpgw_info']['server']['ldap_context']),
234                                'lang_back'                                     => lang('Back'),
235                                'lang_save'                                     => lang('save'),
236                                'lang_group_organization'       => lang('Group Organization'),
237                                'lang_search_organization'      => lang('Search Organiztion'),
238                                'lang_org'                                      => lang('Organizations'),
239                                'lang_group_name'                       => lang('group name'),
240                                'lang_description'                      => lang('Description'),
241                                'lang_email'                            => lang('E-mail'),
242                                'concatenateDomain'                     => $this->current_config['expressoAdmin_concatenateDomain'],
243                                'defaultDomain'                         => $this->current_config['expressoAdmin_defaultDomain'],
244                                'lang_group_users'                      => lang('Group users'),
245                                'lang_applications'                     => lang('Applications'),
246                                'lang_add_user'                         => lang('Add User'),
247                                'lang_rem_user'                         => lang('Remove User'),
248                                'lang_all_users'                        => lang('Select users from all sub-organizations'),
249                                'apps'                                          => $apps,
250                                //'use_attrs_samba_checked'     => $this->current_config['expressoAdmin_samba_support'] == 'true' ? 'CHECKED' : '',
251                                'use_attrs_samba_checked'       => '',
252                                'disabled_samba'                        => 'disabled',
253                                'display_samba_options'         => $this->current_config['expressoAdmin_samba_support'] == 'true' ? '' : '"display:none"',
254                                'disable_email_groups'          => $this->functions->check_acl($manager_lid,'edit_email_groups') ? '' : 'disabled',
255                                'sambadomainname_options'       => $sambadomainname_options,
256                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uigroups.list_groups'),
257                                'combo_manager_org'                     => $combo_manager_org,
258                                'combo_all_orgs'                        => $combo_all_orgs
259                        );
260                        $p->set_var($var);
261
262                        $p->pfp('out','create_group');
263                }
264               
265                function edit_groups()
266                {
267                        $GLOBALS['phpgw']->js->set_onload('get_available_users(document.forms[0].org_context.value, document.forms[0].ea_check_allUsers.checked);');
268
269                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
270                        $manager_acl = $this->functions->read_acl($manager_lid);
271                        $manager_contexts = $manager_acl['contexts'];
272
273                        // Verifica se tem acesso a este modulo
274                        if (!$this->functions->check_acl($manager_lid,'edit_groups'))
275                        {
276                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
277                        }
278
279                        // GET all infomations about the group.
280                        $group_info = $this->group->get_info($_GET['gidnumber']);
281
282                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
283                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
284                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Group');
285                        $GLOBALS['phpgw']->common->phpgw_header();
286
287                        // Set o template
288                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
289                        $p->set_file(Array('create_group' => 'groups_form.tpl'));
290
291                        // Obtem combo das organizações e seleciona a org do grupo.
292                        foreach ($manager_contexts as $index=>$context)
293                                $combo_manager_org .= $this->functions->get_organizations($context, trim(strtolower($group_info['context'])));
294                        $combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], trim(strtolower($group_info['context'])));
295
296                        // Usuarios do grupo.
297                        $user_count = 0;
298                        if (count($group_info['memberuid_info']) > 0)
299                        {
300                                foreach ($group_info['memberuid_info'] as $uid=>$user_data)
301                                {
302                                        if ($user_data['uidnumber'])
303                                        {
304                                                $array_users[$user_data['uidnumber']] = $user_data['cn'];
305                                                $array_users_uid[$user_data['uidnumber']] = $uid;
306                                                $array_users_type[$user_data['uidnumber']] = $user_data['type'];
307                                        }
308                                        else
309                                        {
310                                                $array_users[$uid] = $user_data['cn'];
311                                        }
312                                }
313                                natcasesort($array_users);
314                               
315                                foreach ($array_users as $uidnumber=>$cn)
316                                {
317                                        $user_count++;
318                                        if ($array_users_type[$uidnumber] == 'u')
319                                        {
320                                                $users .= "<option value=" . $uidnumber . ">" . $cn . " [" . $array_users_uid[$uidnumber] . "]</option>";
321                                        }
322                                        else
323                                        {
324                                                $unknow .= "<option value=-1>" . $cn . " [Corrigir manualmente]</option>";
325                                        }
326                                }
327                               
328                                $opt_tmp_users  = '<option  value="-1" disabled>-----------------------------&nbsp;&nbsp;&nbsp;&nbsp;Usuários&nbsp;&nbsp;&nbsp;&nbsp;---------------------------- </option>'."\n";
329                                $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";
330                                $ea_select_usersInGroup = $unknow != '' ? $opt_tmp_unknow . $unknow . $opt_tmp_users . $users : $opt_tmp_users . $users;
331                        }
332                       
333                        // Chama funcao para criar lista de aplicativos disponiveis.
334                        $apps = $this->functions->make_list_app($manager_lid, $group_info['apps']);
335                       
336                        // Cria combo de dominios do samba
337                        if ($this->current_config['expressoAdmin_samba_support'] == 'true')
338                        {
339                                $a_sambadomains = $this->db_functions->get_sambadomains_list();
340                                $sambadomainname_options = '';
341                                if (count($a_sambadomains))
342                                {
343                                        foreach ($a_sambadomains as $a_sambadomain)
344                                        {
345                                                if ($a_sambadomain['samba_domain_sid'] == $group_info['sambasid'])
346                                                        $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "' SELECTED>" . $a_sambadomain['samba_domain_name'] . "</option>";
347                                                else
348                                                        $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "'>" . $a_sambadomain['samba_domain_name'] . "</option>";
349                                        }
350                                }
351                        }
352                       
353                        // Seta variaveis utilizadas pelo tpl.
354                        $var = Array(
355                                'color_bg1'                                     => "#E8F0F0",
356                                'color_bg2'                                     => "#D3DCE3",
357                                'type'                                          => 'edit_group',
358                                'ldap_context'                          => $GLOBALS['phpgw_info']['server']['ldap_context'],
359                                'lang_back'                                     => lang('Back'),
360                                'lang_save'                                     => lang('save'),
361                                'lang_group_organization'       => lang('Group Organization'),
362                                'lang_search_organization'      => lang('Search Organiztion'),
363                                'lang_org'                                      => lang('Organizations'),
364                                'lang_group_name'                       => lang('group name'),
365                                'lang_description'                      => lang('Description'),
366                                'lang_email'                            => lang('E-mail'),
367                                'lang_group_users'                      => lang('Group users'),
368                                'lang_applications'                     => lang('Applications'),
369                                'lang_add_user'                         => lang('Add User'),
370                                'lang_rem_user'                         => lang('Remove User'),
371                                'lang_all_users'                        => lang('Select users from all sub-organizations'),
372                                'gidnumber'                                     => $group_info['gidnumber'],
373                                //'manager_context'                     => $manager_context,
374                                'cn'                                            => $group_info['cn'],
375                                'user_count'                            => $user_count,
376                                'email'                                         => $group_info['email'],
377                                'description'                           => $group_info['description'],
378                                'apps'                                          => $apps,
379                                'use_attrs_samba_checked'       => $group_info['sambaGroup'] ? 'CHECKED' : '',
380                                'disabled_samba'                        => $group_info['sambaGroup'] ? '' : 'disabled',
381                                'disable_email_groups'          => $this->functions->check_acl($manager_lid,'edit_email_groups') ? '' : 'disabled',
382                                'sambadomainname_options'       => $sambadomainname_options,
383                                'phpgwaccountvisible_checked'   => $group_info['phpgwaccountvisible'] == '-1' ? 'CHECKED' : '',
384                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uigroups.list_groups'),
385                                'combo_manager_org'                     => $combo_manager_org,
386                                'combo_all_orgs'                        => $combo_all_orgs,
387                                'ea_select_usersInGroup'        => $ea_select_usersInGroup
388                        );
389                        $p->set_var($var);
390
391                        $p->pfp('out','create_group');
392                }
393                               
394                function row_action($action,$type,$gidnumber,$group_name)
395                {
396                        return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
397                                'menuaction'            => 'expressoAdmin1_2.uigroups.'.$action.'_'.$type,
398                                'gidnumber'             => $gidnumber,
399                                'group_name'    => $group_name
400                        )).'"> '.lang($action).' </a>';
401                }
402               
403                function css()
404                {
405                        $appCSS = '';
406/*                      'th.activetab
407                        {
408                                color:#000000;
409                                background-color:#D3DCE3;
410                                border-top-width : 1px;
411                                border-top-style : solid;
412                                border-top-color : Black;
413                                border-left-width : 1px;
414                                border-left-style : solid;
415                                border-left-color : Black;
416                                border-right-width : 1px;
417                                border-right-style : solid;
418                                border-right-color : Black;
419                        }
420                       
421                        th.inactivetab
422                        {
423                                color:#000000;
424                                background-color:#E8F0F0;
425                                border-bottom-width : 1px;
426                                border-bottom-style : solid;
427                                border-bottom-color : Black;
428                        }
429                       
430                        .td_left { border-left : 1px solid Gray; border-top : 1px solid Gray; }
431                        .td_right { border-right : 1px solid Gray; border-top : 1px solid Gray; }
432                       
433                        div.activetab{ display:inline; }
434                        div.inactivetab{ display:none; }';*/
435                       
436                        return $appCSS;
437                }
438               
439        }
440?>
Note: See TracBrowser for help on using the repository browser.