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