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

Revision 46, 16.2 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

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