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

Revision 24, 13.4 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                       
26                function uigroups()
27                {
28                        $this->group            = CreateObject('expressoAdmin1_2.group');
29                        $this->nextmatchs       = createobject('phpgwapi.nextmatchs');
30                        $this->functions        = CreateObject('expressoAdmin1_2.functions');
31                       
32                        $c = CreateObject('phpgwapi.config','expressoAdmin1_2');
33                        $c->read_repository();
34                        $this->current_config = $c->config_data;
35                       
36                        if(!@is_object($GLOBALS['phpgw']->js))
37                        {
38                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
39                        }
40                        $GLOBALS['phpgw']->js->validate_file('jscode','connector','expressoAdmin1_2');#diretorio, arquivo.js, aplicacao
41                        $GLOBALS['phpgw']->js->validate_file('jscode','expressoadmin','expressoAdmin1_2');
42                        $GLOBALS['phpgw']->js->validate_file('jscode','groups','expressoAdmin1_2');
43                }
44               
45                function list_groups()
46                {
47                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
48                        $acl = $this->functions->read_acl($account_lid);
49                        $context = $acl[0]['context'];
50                        $context_display = $acl[0]['context_display'];
51                       
52                        // Verifica se tem acesso a este modulo
53                        if (!$this->functions->check_acl($account_lid,'list_groups'))
54                        {
55                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
56                        }
57
58                        if(isset($_POST['query']))
59                        {
60                                // limit query to limit characters
61                                if(eregi('^[a-z_0-9_-].+$',$_POST['query']))
62                                        $GLOBALS['query'] = $_POST['query'];
63                        }
64                                               
65                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
66                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
67                       
68                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('User groups');
69                        $GLOBALS['phpgw']->common->phpgw_header();
70
71                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
72                        $p->set_file(array('groups'   => 'groups.tpl'));
73                        $p->set_block('groups','list','list');
74                        $p->set_block('groups','row','row');
75                        $p->set_block('groups','row_empty','row_empty');
76
77                        // Seta as variaveis padroes.
78                        $var = Array(
79                                'th_bg'                                 => $GLOBALS['phpgw_info']['theme']['th_bg'],
80                                'back_url'                              => $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'),
81                                'add_action'                    => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uigroups.add_groups'),
82                                'add_group_disabled'    => $this->functions->check_acl($account_lid,'add_groups') ? '' : 'disabled',
83                                'context'                               => $context,
84                                'context_display'               => $context_display,
85                                'lang_groups_names'             => lang('Groups Names'),
86                                'lang_description'              => lang('Description'),
87                                'lang_add_groups'               => lang('Add Groups'),
88                                'lang_edit'                     => lang('Edit'),
89                                'lang_delete'                   => lang('Delete'),
90                                'lang_back'                             => lang('back'),
91                                'lang_context'                  => lang('context'),
92                                'lang_search'                   => lang('search')
93                        );
94                        $p->set_var($var);
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'], $context);
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']."\",\"".$context."\");'>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                       
170                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
171                        $acl = $this->functions->read_acl($account_lid);
172                        $manager_context = $acl[0]['context'];
173                       
174                        // Verifica se tem acesso a este modulo
175                        if (!$this->functions->check_acl($account_lid,'add_groups'))
176                        {
177                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
178                        }
179
180                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
181                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
182                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Create Group');
183                        $GLOBALS['phpgw']->common->phpgw_header();
184                       
185                        // Set o template
186                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
187                        $p->set_file(Array('create_group' => 'groups_form.tpl'));
188
189                        // Pega combo das organizações e seleciona um dos setores em caso de um erro na validaçao dos dados.
190                        $combo_manager_org = $this->functions->get_organizations($manager_context, trim(strtolower($group_info['context'])));
191                        $combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], trim(strtolower($group_info['context'])));
192                       
193                        // Chama funcao para criar lista de aplicativos disponiveis.
194                        $apps = $this->functions->make_list_app($account_lid, $manager_context, '');
195                       
196                        // Seta variaveis utilizadas pelo tpl.
197                        $var = Array(
198                                'color_bg1'                                     => "#E8F0F0",
199                                'color_bg2'                                     => "#D3DCE3",
200                                'type'                                          => 'create_group',
201                                'cn'                                            => '',
202                                'restrictionsOnGroup'           => $this->current_config['expressoAdmin_restrictionsOnGroup'],
203                                'ldap_context'                          => $GLOBALS['phpgw_info']['server']['ldap_context'],
204                                'lang_back'                                     => lang('Back'),
205                                'lang_save'                                     => lang('save'),
206                                'lang_org'                                      => lang('Organizations'),
207                                'lang_group_name'                       => lang('group name'),
208                                'lang_group_users'                      => lang('Group users'),
209                                'lang_applications'                     => lang('Applications'),
210                                'lang_add_user'                         => lang('Add User'),
211                                'lang_rem_user'                         => lang('Remove User'),
212                                'lang_all_users'                        => lang('Select users from all sub-organizations'),
213                                'apps'                                          => $apps,
214                                'use_attrs_samba_checked'       => $this->current_config['expressoAdmin_samba_support'] == 'true' ? 'CHECKED' : '',
215                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uigroups.list_groups'),
216                                'combo_manager_org'                     => $combo_manager_org,
217                                'combo_all_orgs'                        => $combo_all_orgs
218                        );
219                        $p->set_var($var);
220
221                        $p->pfp('out','create_group');
222                }
223               
224                function edit_groups()
225                {
226                        $GLOBALS['phpgw']->js->set_onload('get_available_users(document.forms[0].org_context.value, document.forms[0].ea_check_allUsers.checked);');
227                       
228                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
229                        $acl = $this->functions->read_acl($account_lid);
230                        $manager_context = $acl[0]['context'];
231                       
232                        // Verifica se tem acesso a este modulo
233                        if (!$this->functions->check_acl($account_lid,'edit_groups'))
234                        {
235                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
236                        }
237
238                        // GET all infomations about the group.
239                        $group_info = $this->group->get_info($_GET['gidnumber'], $manager_context);
240
241                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
242                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
243                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Group');
244                        $GLOBALS['phpgw']->common->phpgw_header();
245
246                        // Set o template
247                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
248                        $p->set_file(Array('create_group' => 'groups_form.tpl'));
249
250                        // Pega combo das organizações e seleciona a org do grupo.
251                        $combo_manager_org = $this->functions->get_organizations($manager_context, trim(strtolower($group_info['context'])));
252                        $combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], trim(strtolower($group_info['context'])));
253
254                        // Usuarios do grupo.
255                        $user_count = 0;
256                        if (count($group_info['memberuid_info']) > 0)
257                        {
258                                foreach ($group_info['memberuid_info'] as $uid=>$user_data)
259                                {
260                                        $array_users[$user_data['uidnumber']] = $user_data['cn'];
261                                        $array_users_uid[$user_data['uidnumber']] = $uid;
262                                        $array_users_type[$user_data['uidnumber']] = $user_data['type'];
263                                }
264                                natcasesort($array_users);
265                                foreach ($array_users as $uidnumber=>$cn)
266                                {
267                                        $user_count++;
268                                        if ($array_users_type[$uidnumber] == 'u')
269                                        {
270                                                $users .= "<option value=" . $uidnumber . ">" . $cn . " [" . $array_users_uid[$uidnumber] . "]</option>";
271                                        }
272                                        else
273                                        {
274                                                $unknow .= "<option value=-1>" . $cn . " [Corrigir manualmente]</option>";
275                                        }
276                                }
277                               
278                                $opt_tmp_users  = '<option  value="-1" disabled>-----------------------------&nbsp;&nbsp;&nbsp;&nbsp;Usuários&nbsp;&nbsp;&nbsp;&nbsp;---------------------------- </option>'."\n";
279                                $opt_tmp_unknow = '<option  value="-1" disabled>--------------------&nbsp;&nbsp;&nbsp;&nbsp;Usuários não encontrados&nbsp;&nbsp;&nbsp;&nbsp;------------------ </option>'."\n";
280                                $ea_select_usersInGroup = $unknow != '' ? $opt_tmp_unknow . $unknow . $opt_tmp_users . $users : $opt_tmp_users . $users;
281                        }
282                       
283                        // Chama funcao para criar lista de aplicativos disponiveis.
284                        $apps = $this->functions->make_list_app($account_lid, $manager_context, $group_info['apps']);
285                       
286                        // Seta variaveis utilizadas pelo tpl.
287                        $var = Array(
288                                'color_bg1'                                     => "#E8F0F0",
289                                'color_bg2'                                     => "#D3DCE3",
290                                'type'                                          => 'edit_group',
291                                'ldap_context'                          => $GLOBALS['phpgw_info']['server']['ldap_context'],
292                                'lang_back'                                     => lang('Back'),
293                                'lang_save'                                     => lang('save'),
294                                'lang_org'                                      => lang('Organizations'),
295                                'lang_group_name'                       => lang('group name'),
296                                'lang_group_users'                      => lang('Group users'),
297                                'lang_applications'                     => lang('Applications'),
298                                'lang_add_user'                         => lang('Add User'),
299                                'lang_rem_user'                         => lang('Remove User'),
300                                'lang_all_users'                        => lang('Select users from all sub-organizations'),
301                                'gidnumber'                                     => $group_info['gidnumber'],
302                                'manager_context'                       => $manager_context,
303                                'cn'                                            => $group_info['cn'],
304                                'user_count'                            => $user_count,
305                                'description'                           => $group_info['description'],
306                                'apps'                                          => $apps,
307                                'use_attrs_samba_checked'       => $group_info['sambaGroup'] ? 'CHECKED' : '',
308                                'phpgwaccountvisible_checked'   => $group_info['phpgwaccountvisible'] == '-1' ? 'CHECKED' : '',
309                                'back_url'                                      => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uigroups.list_groups'),
310                                'combo_manager_org'                     => $combo_manager_org,
311                                'combo_all_orgs'                        => $combo_all_orgs,
312                                'ea_select_usersInGroup'        => $ea_select_usersInGroup
313                        );
314                        $p->set_var($var);
315
316                        $p->pfp('out','create_group');
317                }
318                               
319                function row_action($action,$type,$gidnumber,$group_name)
320                {
321                        return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
322                                'menuaction'            => 'expressoAdmin1_2.uigroups.'.$action.'_'.$type,
323                                'gidnumber'             => $gidnumber,
324                                'group_name'    => $group_name
325                        )).'"> '.lang($action).' </a>';
326                }
327               
328                function css()
329                {
330                        $appCSS = '';
331/*                      'th.activetab
332                        {
333                                color:#000000;
334                                background-color:#D3DCE3;
335                                border-top-width : 1px;
336                                border-top-style : solid;
337                                border-top-color : Black;
338                                border-left-width : 1px;
339                                border-left-style : solid;
340                                border-left-color : Black;
341                                border-right-width : 1px;
342                                border-right-style : solid;
343                                border-right-color : Black;
344                        }
345                       
346                        th.inactivetab
347                        {
348                                color:#000000;
349                                background-color:#E8F0F0;
350                                border-bottom-width : 1px;
351                                border-bottom-style : solid;
352                                border-bottom-color : Black;
353                        }
354                       
355                        .td_left { border-left : 1px solid Gray; border-top : 1px solid Gray; }
356                        .td_right { border-right : 1px solid Gray; border-top : 1px solid Gray; }
357                       
358                        div.activetab{ display:inline; }
359                        div.inactivetab{ display:none; }';*/
360                       
361                        return $appCSS;
362                }
363               
364        }
365?>
Note: See TracBrowser for help on using the repository browser.