source: sandbox/2.3-MailArchiver/expressoAdmin1_2/inc/class.uigroups.inc.php @ 6779

Revision 6779, 15.1 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

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']."\");'>".lang('to delete')."</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('run',4,'admin'))
156                        {
157                                $p->set_var('input_add','<input type="submit" value="' . lang('Add') . '">');
158                        }
159                        if (! $GLOBALS['phpgw']->acl->check('run',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                        // Chama funcao para criar lista de campos disponiveis na edicao de dados pessoais.
201                        $personal_data_fields = $this->functions->make_list_personal_data_fields($manager_lid);
202                       
203                        // Cria combo de dominio samba
204                        if ($this->current_config['expressoAdmin_samba_support'] == 'true')
205                        {
206                                $a_sambadomains = $this->db_functions->get_sambadomains_list();
207                                $sambadomainname_options = '';
208                                if (count($a_sambadomains))
209                                {
210                                        foreach ($a_sambadomains as $a_sambadomain)
211                                        {
212                                                // So mostra os sambaDomainName do contexto do manager
213                                                if ($this->ldap_functions->exist_sambadomains($manager_contexts, $a_sambadomain['samba_domain_name']))
214                                                        $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "'>" . $a_sambadomain['samba_domain_name'] . "</option>";
215                                        }
216                                }
217                        }
218                       
219                        // Seta variaveis utilizadas pelo tpl.
220                        $var = Array(
221                                'color_bg1'                                     => "#E8F0F0",
222                                'color_bg2'                                     => "#D3DCE3",
223                                'type'                                          => 'create_group',
224                                'cn'                                            => '',
225                                'restrictionsOnGroup'           => $this->current_config['expressoAdmin_restrictionsOnGroup'],
226                                'type'                                          => 'create_group',
227                                'ldap_context'                          => $GLOBALS['phpgw_info']['server']['ldap_context'],
228                                'ufn_ldap_context'                      => ldap_dn2ufn($GLOBALS['phpgw_info']['server']['ldap_context']),
229                                'concatenateDomain'                     => $this->current_config['expressoAdmin_concatenateDomain'],
230                                'defaultDomain'                         => $this->current_config['expressoAdmin_defaultDomain'],
231                                'apps'                                          => $apps,
232                                'personal_data_fields'          => $personal_data_fields,
233                                'use_attrs_samba_checked'       => '',
234                                'disabled_samba'                        => 'disabled',
235                                'display_samba_options'         => $this->current_config['expressoAdmin_samba_support'] == 'true' ? '' : '"display:none"',
236                                'disable_email_groups'          => $this->functions->check_acl($manager_lid,'edit_email_groups') ? '' : 'disabled',
237                                'sambadomainname_options'       => $sambadomainname_options,
238                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uigroups.list_groups'),
239                                'combo_manager_org'                     => $combo_manager_org,
240                                'combo_all_orgs'                        => $combo_all_orgs
241                        );
242                        $p->set_var($var);
243                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
244                       
245                        $p->pfp('out','create_group');
246                }
247               
248                function edit_groups()
249                {
250                        $GLOBALS['phpgw']->js->set_onload('get_available_users(document.forms[0].org_context.value, document.forms[0].ea_check_allUsers.checked);');
251
252                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
253                        $manager_acl = $this->functions->read_acl($manager_lid);
254                        $manager_contexts = $manager_acl['contexts'];
255
256                        // Verifica se tem acesso a este modulo
257                        if (!$this->functions->check_acl($manager_lid,'edit_groups'))
258                        {
259                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
260                        }
261
262                        // GET all infomations about the group.
263                        $group_info = $this->group->get_info($_GET['gidnumber']);
264
265                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
266                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
267                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Group');
268                        $GLOBALS['phpgw']->common->phpgw_header();
269
270                        // Set o template
271                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
272                        $p->set_file(Array('create_group' => 'groups_form.tpl'));
273                        $p->set_block('create_group','list','list');
274
275                        // Obtem combo das organizações e seleciona a org do grupo.
276                        foreach ($manager_contexts as $index=>$context)
277                                $combo_manager_org .= $this->functions->get_organizations($context, trim(strtolower($group_info['context'])));
278                        $combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], trim(strtolower($group_info['context'])));
279
280                        // Usuarios do grupo.
281                        $user_count = 0;
282                        if (count($group_info['memberuid_info']) > 0)
283                        {
284                                foreach ($group_info['memberuid_info'] as $uid=>$user_data)
285                                {
286                                        if ($user_data['uidnumber'])
287                                        {
288                                                $array_users[$user_data['uidnumber']] = $user_data['cn'];
289                                                $array_users_uid[$user_data['uidnumber']] = $uid;
290                                                $array_users_type[$user_data['uidnumber']] = $user_data['type'];
291                                        }
292                                        else
293                                        {
294                                                $array_users[$uid] = $user_data['cn'];
295                                        }
296                                }
297                                natcasesort($array_users);
298                               
299                                foreach ($array_users as $uidnumber=>$cn)
300                                {
301                                        $user_count++;
302                                        if ($array_users_type[$uidnumber] == 'u')
303                                        {
304                                                $users .= "<option value=" . $uidnumber . ">" . $cn . " [" . $array_users_uid[$uidnumber] . "]</option>";
305                                        }
306                                        else
307                                        {
308                                                $unknow .= "<option value=-1>" . $cn . " [Corrigir manualmente]</option>";
309                                        }
310                                }
311                               
312                                $opt_tmp_users  = '<option  value="-1" disabled>-----------------------------&nbsp;&nbsp;&nbsp;&nbsp;'.lang('users').'&nbsp;&nbsp;&nbsp;&nbsp;---------------------------- </option>'."\n";
313                                $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";
314                                $ea_select_usersInGroup = $unknow != '' ? $opt_tmp_unknow . $unknow . $opt_tmp_users . $users : $opt_tmp_users . $users;
315                        }
316                       
317                        // Chama funcao para criar lista de aplicativos disponiveis.
318                        $apps = $this->functions->make_list_app($manager_lid, $group_info['apps']);
319                        // Chama funcao para criar lista de campos disponiveis na edicao de dados pessoais.
320                        $personal_data_fields = $this->functions->make_list_personal_data_fields($manager_lid, $group_info['acl_block_personal_data']);
321                       
322                        // Cria combo de dominios do samba
323                        if ($this->current_config['expressoAdmin_samba_support'] == 'true')
324                        {
325                                $a_sambadomains = $this->db_functions->get_sambadomains_list();
326                                $sambadomainname_options = '';
327                                if (count($a_sambadomains))
328                                {
329                                        foreach ($a_sambadomains as $a_sambadomain)
330                                        {
331                                                if ($a_sambadomain['samba_domain_sid'] == $group_info['sambasid'])
332                                                        $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "' SELECTED>" . $a_sambadomain['samba_domain_name'] . "</option>";
333                                                else
334                                                        $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "'>" . $a_sambadomain['samba_domain_name'] . "</option>";
335                                        }
336                                }
337                        }
338                       
339                        // Seta variaveis utilizadas pelo tpl.
340                        $var = Array(
341                                'color_bg1'                                     => "#E8F0F0",
342                                'color_bg2'                                     => "#D3DCE3",
343                                'type'                                          => 'edit_group',
344                                'ldap_context'                          => $GLOBALS['phpgw_info']['server']['ldap_context'],
345                                'gidnumber'                                     => $group_info['gidnumber'],
346                                'cn'                                            => $group_info['cn'],
347                                'user_count'                            => $user_count,
348                                'email'                                         => $group_info['email'],
349                                'description'                           => $group_info['description'],
350                                'apps'                                          => $apps,
351                                'personal_data_fields'          => $personal_data_fields,
352                                'use_attrs_samba_checked'       => $group_info['sambaGroup'] ? 'CHECKED' : '',
353                                'disabled_samba'                        => $group_info['sambaGroup'] ? '' : 'disabled',
354                                'disable_email_groups'          => $this->functions->check_acl($manager_lid,'edit_email_groups') ? '' : 'disabled',
355                                'sambadomainname_options'       => $sambadomainname_options,
356                                'phpgwaccountvisible_checked'   => $group_info['phpgwaccountvisible'] == '-1' ? 'CHECKED' : '',
357                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uigroups.list_groups'),
358                                'combo_manager_org'                     => $combo_manager_org,
359                                'combo_all_orgs'                        => $combo_all_orgs,
360                                'ea_select_usersInGroup'        => $ea_select_usersInGroup
361                        );
362                        $p->set_var($var);
363                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
364                        $p->pfp('out','create_group');
365                }
366                               
367                function row_action($action,$type,$gidnumber,$group_name)
368                {
369                        return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
370                                'menuaction'            => 'expressoAdmin1_2.uigroups.'.$action.'_'.$type,
371                                'gidnumber'             => $gidnumber,
372                                'group_name'    => $group_name
373                        )).'"> '.lang($action).' </a>';
374                }
375               
376                function css()
377                {
378                        $appCSS = '';
379                        return $appCSS;
380                }
381               
382        }
383?>
Note: See TracBrowser for help on using the repository browser.