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 | include_once('class.db_functions.inc.php'); |
---|
13 | include_once(PHPGW_API_INC.'/class.config.inc.php'); |
---|
14 | |
---|
15 | class functions |
---|
16 | { |
---|
17 | var $public_functions = array |
---|
18 | ( |
---|
19 | 'make_array_acl' => True, |
---|
20 | 'check_acl' => True, |
---|
21 | 'read_acl' => True, |
---|
22 | 'exist_account_lid' => True, |
---|
23 | 'exist_email' => True, |
---|
24 | 'array_invert' => True |
---|
25 | ); |
---|
26 | |
---|
27 | var $nextmatchs; |
---|
28 | var $sectors_list = array(); |
---|
29 | var $current_config; |
---|
30 | |
---|
31 | function functions() |
---|
32 | { |
---|
33 | $this->db_functions = new db_functions; |
---|
34 | $GLOBALS['phpgw']->db = $this->db_functions->db; |
---|
35 | |
---|
36 | //$c = CreateObject('phpgwapi.config','expressoAdmin1_2'); |
---|
37 | $c = new config; |
---|
38 | $c->read_repository(); |
---|
39 | $this->current_config = $c->config_data; |
---|
40 | } |
---|
41 | |
---|
42 | // Account and type of access. Return: Have access ? (true/false) |
---|
43 | function check_acl($account_lid, $access) |
---|
44 | { |
---|
45 | $acl = $this->read_acl($account_lid); |
---|
46 | $array_acl = $this->make_array_acl($acl['acl']); |
---|
47 | |
---|
48 | switch($access) |
---|
49 | { |
---|
50 | case list_users: |
---|
51 | if ($array_acl[acl_add_users] || $array_acl[acl_edit_users] || $array_acl[acl_delete_users] || $array_acl[acl_change_users_password] || $array_acl[acl_change_users_quote] || $array_acl[acl_edit_sambausers_attributes] || $array_acl[acl_view_users] || $array_acl[acl_manipulate_corporative_information]) |
---|
52 | return true; |
---|
53 | break; |
---|
54 | case list_groups: |
---|
55 | if ($array_acl[acl_add_groups] || $array_acl[acl_edit_groups] || $array_acl[acl_delete_groups]) |
---|
56 | return true; |
---|
57 | break; |
---|
58 | case list_maillists: |
---|
59 | if ($array_acl[acl_add_maillists] || $array_acl[acl_edit_maillists] || $array_acl[acl_delete_maillists]) |
---|
60 | return true; |
---|
61 | break; |
---|
62 | case list_sectors: |
---|
63 | if ($array_acl[acl_create_sectors] || $array_acl[acl_edit_sectors] || $array_acl[acl_delete_sectors]) |
---|
64 | return true; |
---|
65 | break; |
---|
66 | case list_computers: |
---|
67 | if ($array_acl[acl_create_computers] || $array_acl[acl_edit_computers] || $array_acl[acl_delete_computers]) |
---|
68 | return true; |
---|
69 | break; |
---|
70 | |
---|
71 | case display_groups: |
---|
72 | if ( $array_acl[acl_edit_users] || $array_acl[acl_view_users] || ($array_acl[acl_edit_sambausers_attributes] && ($this->current_config['expressoAdmin_samba_support'] == 'true')) ) |
---|
73 | return true; |
---|
74 | break; |
---|
75 | case display_emailconfig: |
---|
76 | if ($array_acl[acl_edit_users] || $array_acl[acl_view_users]) |
---|
77 | return true; |
---|
78 | break; |
---|
79 | case display_applications: |
---|
80 | if ($array_acl[acl_edit_users] || $array_acl[acl_view_users]) |
---|
81 | return true; |
---|
82 | break; |
---|
83 | case display_emaillists: |
---|
84 | if ($array_acl[acl_edit_users] || $array_acl[acl_view_users]) |
---|
85 | return true; |
---|
86 | break; |
---|
87 | |
---|
88 | default: |
---|
89 | return $array_acl["acl_$access"]; |
---|
90 | } |
---|
91 | return false; |
---|
92 | } |
---|
93 | |
---|
94 | /* OLD FUNCTION |
---|
95 | function check_acl($account_lid, $access) |
---|
96 | { |
---|
97 | $acl = $this->read_acl($account_lid); |
---|
98 | $array_acl = $this->make_array_acl($acl['acl']); |
---|
99 | |
---|
100 | //What access ?? In the IF, verify if have access. |
---|
101 | switch($access) |
---|
102 | { |
---|
103 | case list_users: |
---|
104 | if ($array_acl[acl_add_users] || $array_acl[acl_edit_users] || $array_acl[acl_delete_users] || $array_acl[acl_change_users_password] || $array_acl[acl_change_users_quote] || $array_acl[acl_edit_sambausers_attributes] || $array_acl[acl_view_users] || $array_acl[acl_manipulate_corporative_information]) |
---|
105 | return true; |
---|
106 | break; |
---|
107 | case add_users: |
---|
108 | if ($array_acl[acl_add_users]) |
---|
109 | return true; |
---|
110 | break; |
---|
111 | case edit_users: |
---|
112 | if ($array_acl[acl_edit_users]) |
---|
113 | return true; |
---|
114 | break; |
---|
115 | case delete_users: |
---|
116 | if ($array_acl[acl_delete_users]) |
---|
117 | return true; |
---|
118 | break; |
---|
119 | case rename_users: |
---|
120 | if ($array_acl[acl_rename_users]) |
---|
121 | return true; |
---|
122 | break; |
---|
123 | case view_users: |
---|
124 | if ($array_acl[acl_view_users]) |
---|
125 | return true; |
---|
126 | break; |
---|
127 | case edit_users_picture: |
---|
128 | if ($array_acl[acl_edit_users_picture]) |
---|
129 | return true; |
---|
130 | break; |
---|
131 | case manipulate_corporative_information: |
---|
132 | if ($array_acl[acl_manipulate_corporative_information]) |
---|
133 | return true; |
---|
134 | break; |
---|
135 | case change_users_password: |
---|
136 | if ($array_acl[acl_change_users_password]) |
---|
137 | return true; |
---|
138 | break; |
---|
139 | case change_users_quote: |
---|
140 | if ($array_acl[acl_change_users_quote]) |
---|
141 | return true; |
---|
142 | break; |
---|
143 | case set_user_default_password: |
---|
144 | if ($array_acl[acl_set_user_default_password]) |
---|
145 | return true; |
---|
146 | break; |
---|
147 | case empty_user_inbox: |
---|
148 | if (($array_acl[acl_empty_user_inbox]) && ($array_acl[acl_edit_users])) |
---|
149 | return true; |
---|
150 | break; |
---|
151 | case edit_sambausers_attributes: case list_maillists: |
---|
152 | if ($array_acl[acl_add_maillists] || $array_acl[acl_edit_maillists] || $array_acl[acl_delete_maillists]) |
---|
153 | return true; |
---|
154 | break; |
---|
155 | |
---|
156 | if ($array_acl[acl_edit_sambausers_attributes]) |
---|
157 | return true; |
---|
158 | break; |
---|
159 | case edit_sambadomains: |
---|
160 | if ($array_acl[acl_edit_sambadomains]) |
---|
161 | return true; |
---|
162 | break; |
---|
163 | |
---|
164 | case list_groups: |
---|
165 | if ($array_acl[acl_add_groups] || $array_acl[acl_edit_groups] || $array_acl[acl_delete_groups]) |
---|
166 | return true; |
---|
167 | break; |
---|
168 | case add_groups: |
---|
169 | if ($array_acl[acl_add_groups]) |
---|
170 | return true; |
---|
171 | break; |
---|
172 | case edit_groups: |
---|
173 | if ($array_acl[acl_edit_groups]) |
---|
174 | return true; |
---|
175 | break; |
---|
176 | case delete_groups: |
---|
177 | if ($array_acl[acl_delete_groups]) |
---|
178 | return true; |
---|
179 | break; |
---|
180 | case edit_email_groups: |
---|
181 | if ($array_acl[acl_edit_email_groups]) |
---|
182 | return true; |
---|
183 | break; |
---|
184 | |
---|
185 | case list_maillists: |
---|
186 | if ($array_acl[acl_add_maillists] || $array_acl[acl_edit_maillists] || $array_acl[acl_delete_maillists]) |
---|
187 | return true; |
---|
188 | break; |
---|
189 | case add_maillists: |
---|
190 | if ($array_acl[acl_add_maillists]) |
---|
191 | return true; |
---|
192 | break; |
---|
193 | case edit_maillists: |
---|
194 | if ($array_acl[acl_edit_maillists]) |
---|
195 | return true; |
---|
196 | break; |
---|
197 | case delete_maillists: |
---|
198 | if ($array_acl[acl_delete_maillists]) |
---|
199 | return true; |
---|
200 | break; |
---|
201 | |
---|
202 | case list_sectors: |
---|
203 | if ($array_acl[acl_create_sectors] || $array_acl[acl_edit_sectors] || $array_acl[acl_delete_sectors]) |
---|
204 | return true; |
---|
205 | break; |
---|
206 | case create_sectors: |
---|
207 | if ($array_acl[acl_create_sectors]) |
---|
208 | return true; |
---|
209 | break; |
---|
210 | case edit_sectors: |
---|
211 | if ($array_acl[acl_edit_sectors]) |
---|
212 | return true; |
---|
213 | break; |
---|
214 | case delete_sectors: |
---|
215 | if ($array_acl[acl_delete_sectors]) |
---|
216 | return true; |
---|
217 | break; |
---|
218 | |
---|
219 | case view_global_sessions: |
---|
220 | if ($array_acl[acl_view_global_sessions]) |
---|
221 | return true; |
---|
222 | break; |
---|
223 | |
---|
224 | case list_computers: |
---|
225 | if ($array_acl[acl_create_computers] || $array_acl[acl_edit_computers] || $array_acl[acl_delete_computers]) |
---|
226 | return true; |
---|
227 | break; |
---|
228 | case create_computers: |
---|
229 | if ($array_acl[acl_create_computers]) |
---|
230 | return true; |
---|
231 | break; |
---|
232 | case edit_computers: |
---|
233 | if ($array_acl[acl_edit_computers]) |
---|
234 | return true; |
---|
235 | break; |
---|
236 | case delete_computers: |
---|
237 | if ($array_acl[acl_delete_computers]) |
---|
238 | return true; |
---|
239 | break; |
---|
240 | |
---|
241 | case view_logs: |
---|
242 | if ($array_acl[acl_view_logs]) |
---|
243 | return true; |
---|
244 | break; |
---|
245 | |
---|
246 | case display_groups: |
---|
247 | if ( $array_acl[acl_edit_users] || $array_acl[acl_view_users] || ($array_acl[acl_edit_sambausers_attributes] && ($this->current_config['expressoAdmin_samba_support'] == 'true')) ) |
---|
248 | return true; |
---|
249 | break; |
---|
250 | case display_emailconfig: |
---|
251 | if ($array_acl[acl_edit_users] || $array_acl[acl_view_users]) |
---|
252 | return true; |
---|
253 | break; |
---|
254 | case display_applications: |
---|
255 | if ($array_acl[acl_edit_users] || $array_acl[acl_view_users]) |
---|
256 | return true; |
---|
257 | break; |
---|
258 | case display_emaillists: |
---|
259 | if ($array_acl[acl_edit_users] || $array_acl[acl_view_users]) |
---|
260 | return true; |
---|
261 | break; |
---|
262 | |
---|
263 | default: |
---|
264 | return $array_acl["acl_$access"]; |
---|
265 | } |
---|
266 | return false; |
---|
267 | } |
---|
268 | */ |
---|
269 | |
---|
270 | // Read acl from db |
---|
271 | function read_acl($account_lid) |
---|
272 | { |
---|
273 | $acl = $this->db_functions->read_acl($account_lid); |
---|
274 | |
---|
275 | $result['acl'] = $acl[0]['acl']; |
---|
276 | $result['manager_lid'] = $acl[0]['manager_lid']; |
---|
277 | $result['raw_context'] = $acl[0]['context']; |
---|
278 | |
---|
279 | $all_contexts = split("%", $acl[0]['context']); |
---|
280 | foreach ($all_contexts as $index=>$context) |
---|
281 | { |
---|
282 | $result['contexts'][] = $context; |
---|
283 | $result['contexts_display'][] = str_replace(", ", ".", ldap_dn2ufn( $context )); |
---|
284 | } |
---|
285 | |
---|
286 | return $result; |
---|
287 | } |
---|
288 | |
---|
289 | // Make a array read humam |
---|
290 | // Last acl: 536.870.912 |
---|
291 | function make_array_acl($acl) |
---|
292 | { |
---|
293 | $array_acl_tmp = array(); |
---|
294 | $tmp = array( "acl_add_users", |
---|
295 | "acl_edit_users", |
---|
296 | "acl_delete_users", |
---|
297 | "acl_EMPTY1", |
---|
298 | "acl_add_groups", |
---|
299 | "acl_edit_groups", |
---|
300 | "acl_delete_groups", |
---|
301 | "acl_change_users_password", |
---|
302 | "acl_add_maillists", |
---|
303 | "acl_edit_maillists", |
---|
304 | "acl_delete_maillists", |
---|
305 | "acl_EMPTY2", |
---|
306 | "acl_create_sectors", |
---|
307 | "acl_edit_sectors", |
---|
308 | "acl_delete_sectors", |
---|
309 | "acl_edit_sambausers_attributes", |
---|
310 | "acl_view_global_sessions", |
---|
311 | "acl_view_logs", |
---|
312 | "acl_change_users_quote", |
---|
313 | "acl_set_user_default_password", |
---|
314 | "acl_create_computers", |
---|
315 | "acl_edit_computers", |
---|
316 | "acl_delete_computers", |
---|
317 | "acl_rename_users", |
---|
318 | "acl_edit_sambadomains", |
---|
319 | "acl_view_users", |
---|
320 | "acl_edit_email_groups", |
---|
321 | "acl_empty_user_inbox", |
---|
322 | "acl_manipulate_corporative_information", |
---|
323 | "acl_edit_users_picture" |
---|
324 | ); |
---|
325 | |
---|
326 | foreach ($tmp as $index => $right) |
---|
327 | { |
---|
328 | $bin = ''; |
---|
329 | for ($i=0; $i<$index; $i++) |
---|
330 | { |
---|
331 | $bin .= '0'; |
---|
332 | } |
---|
333 | $bin = '1' . $bin; |
---|
334 | |
---|
335 | $array_acl[$right] = $acl & bindec($bin); |
---|
336 | } |
---|
337 | return $array_acl; |
---|
338 | /* |
---|
339 | $array_acl['acl_add_users'] = $acl & 1; |
---|
340 | $array_acl['acl_edit_users'] = $acl & 2; |
---|
341 | $array_acl['acl_delete_users'] = $acl & 4; |
---|
342 | //8 |
---|
343 | $array_acl['acl_add_groups'] = $acl & 16; |
---|
344 | $array_acl['acl_edit_groups'] = $acl & 32; |
---|
345 | $array_acl['acl_delete_groups'] = $acl & 64; |
---|
346 | $array_acl['acl_change_users_password'] = $acl & 128; |
---|
347 | $array_acl['acl_add_maillists'] = $acl & 256; |
---|
348 | $array_acl['acl_edit_maillists'] = $acl & 512; |
---|
349 | $array_acl['acl_delete_maillists'] = $acl & 1024; |
---|
350 | //2048 |
---|
351 | $array_acl['acl_create_sectors'] = $acl & 4096; |
---|
352 | $array_acl['acl_edit_sectors'] = $acl & 8192; |
---|
353 | $array_acl['acl_delete_sectors'] = $acl & 16384; |
---|
354 | $array_acl['acl_edit_sambausers_attributes'] = $acl & 32768; |
---|
355 | $array_acl['acl_view_global_sessions'] = $acl & 65536; |
---|
356 | $array_acl['acl_view_logs'] = $acl & 131072; |
---|
357 | $array_acl['acl_change_users_quote'] = $acl & 262144; |
---|
358 | $array_acl['acl_set_user_default_password'] = $acl & 524288; |
---|
359 | $array_acl['acl_create_computers'] = $acl & 1048576; |
---|
360 | $array_acl['acl_edit_computers'] = $acl & 2097152; |
---|
361 | $array_acl['acl_delete_computers'] = $acl & 4194304; |
---|
362 | $array_acl['acl_rename_users'] = $acl & 8388608; |
---|
363 | $array_acl['acl_edit_sambadomains'] = $acl & 16777216; |
---|
364 | $array_acl['acl_view_users'] = $acl & 33554432; |
---|
365 | $array_acl['acl_edit_email_groups'] = $acl & 67108864; |
---|
366 | $array_acl['acl_empty_user_inbox'] = $acl & 134217728; |
---|
367 | $array_acl['acl_manipulate_corporative_information'] = $acl & 268435456; |
---|
368 | $array_acl['acl_edit_users_picture'] = $acl & 536870912; |
---|
369 | return $array_acl; |
---|
370 | */ |
---|
371 | } |
---|
372 | |
---|
373 | function get_list($type, $query, $contexts) |
---|
374 | { |
---|
375 | $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; |
---|
376 | $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; |
---|
377 | $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
378 | ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
379 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); |
---|
380 | ldap_bind($ldap_conn,$dn,$passwd); |
---|
381 | |
---|
382 | if ($type == 'accounts') |
---|
383 | { |
---|
384 | $justthese = array("uidnumber", "uid", "cn", "mail"); |
---|
385 | $filter="(&(phpgwAccountType=u)(|(uid=*".$query."*)(sn=*".$query."*)(cn=*".$query."*)(givenName=*".$query."*)(mail=$query*)(mailAlternateAddress=$query*)))"; |
---|
386 | |
---|
387 | $tmp = array(); |
---|
388 | foreach ($contexts as $index=>$context) |
---|
389 | { |
---|
390 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
391 | $info = ldap_get_entries($ldap_conn, $search); |
---|
392 | |
---|
393 | for ($i=0; $i < $info['count']; $i++) |
---|
394 | { |
---|
395 | $tmp[$info[$i]['uid'][0]]['account_id'] = $info[$i]['uidnumber'][0]; |
---|
396 | $tmp[$info[$i]['uid'][0]]['account_lid'] = $info[$i]['uid'][0]; |
---|
397 | $tmp[$info[$i]['uid'][0]]['account_cn'] = $info[$i]['cn'][0]; |
---|
398 | $tmp[$info[$i]['uid'][0]]['account_mail']= $info[$i]['mail'][0]; |
---|
399 | $sort[] = $info[$i]['uid'][0]; |
---|
400 | } |
---|
401 | } |
---|
402 | ldap_close($ldap_conn); |
---|
403 | |
---|
404 | if (count($sort)) |
---|
405 | { |
---|
406 | natcasesort($sort); |
---|
407 | foreach ($sort as $user_uid) |
---|
408 | $return[$user_uid] = $tmp[$user_uid]; |
---|
409 | } |
---|
410 | |
---|
411 | return $return; |
---|
412 | } |
---|
413 | elseif($type == 'groups') |
---|
414 | { |
---|
415 | $filter="(&(phpgwAccountType=g)(cn=*$query*))"; |
---|
416 | $justthese = array("gidnumber", "cn", "description"); |
---|
417 | |
---|
418 | $tmp = array(); |
---|
419 | foreach ($contexts as $index=>$context) |
---|
420 | { |
---|
421 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
422 | $info = ldap_get_entries($ldap_conn, $search); |
---|
423 | for ($i=0; $i < $info['count']; $i++) |
---|
424 | { |
---|
425 | $tmp[$info[$i]['cn'][0]]['cn']= $info[$i]['cn'][0]; |
---|
426 | $tmp[$info[$i]['cn'][0]]['description']= $info[$i]['description'][0]; |
---|
427 | $tmp[$info[$i]['cn'][0]]['gidnumber']= $info[$i]['gidnumber'][0]; |
---|
428 | $sort[] = $info[$i]['cn'][0]; |
---|
429 | } |
---|
430 | } |
---|
431 | ldap_close($ldap_conn); |
---|
432 | |
---|
433 | natcasesort($sort); |
---|
434 | foreach ($sort as $group_cn) |
---|
435 | $return[$group_cn] = $tmp[$group_cn]; |
---|
436 | |
---|
437 | return $return; |
---|
438 | } |
---|
439 | elseif($type == 'maillists') |
---|
440 | { |
---|
441 | $filter="(&(phpgwAccountType=l)(|(cn=*".$query."*)(uid=*".$query."*)(mail=*".$query."*)))"; |
---|
442 | $justthese = array("uidnumber", "cn", "uid", "mail"); |
---|
443 | |
---|
444 | $tmp = array(); |
---|
445 | foreach ($contexts as $index=>$context) |
---|
446 | { |
---|
447 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
448 | $info = ldap_get_entries($ldap_conn, $search); |
---|
449 | |
---|
450 | for ($i=0; $i < $info['count']; $i++) |
---|
451 | { |
---|
452 | $tmp[$info[$i]['uid'][0]]['uid'] = $info[$i]['uid'][0]; |
---|
453 | $tmp[$info[$i]['uid'][0]]['name'] = $info[$i]['cn'][0]; |
---|
454 | $tmp[$info[$i]['uid'][0]]['uidnumber'] = $info[$i]['uidnumber'][0]; |
---|
455 | $tmp[$info[$i]['uid'][0]]['email'] = $info[$i]['mail'][0]; |
---|
456 | $sort[] = $info[$i]['uid'][0]; |
---|
457 | } |
---|
458 | } |
---|
459 | ldap_close($ldap_conn); |
---|
460 | |
---|
461 | natcasesort($sort); |
---|
462 | foreach ($sort as $maillist_uid) |
---|
463 | $return[$maillist_uid] = $tmp[$maillist_uid]; |
---|
464 | |
---|
465 | return $return; |
---|
466 | } |
---|
467 | elseif($type == 'computers') |
---|
468 | { |
---|
469 | $filter="(&(objectClass=sambaSAMAccount)(|(sambaAcctFlags=[W ])(sambaAcctFlags=[DW ])(sambaAcctFlags=[I ])(sambaAcctFlags=[S ]))(cn=*".$query."*))"; |
---|
470 | $justthese = array("cn","uidNumber","description"); |
---|
471 | |
---|
472 | $tmp = array(); |
---|
473 | foreach ($contexts as $index=>$context) |
---|
474 | { |
---|
475 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
476 | $info = ldap_get_entries($ldap_conn, $search); |
---|
477 | for ($i=0; $i < $info['count']; $i++) |
---|
478 | { |
---|
479 | $tmp[$info[$i]['cn'][0]]['cn'] = $info[$i]['cn'][0]; |
---|
480 | $tmp[$info[$i]['cn'][0]]['uidNumber'] = $info[$i]['uidnumber'][0]; |
---|
481 | $tmp[$info[$i]['cn'][0]]['description'] = utf8_decode($info[$i]['description'][0]); |
---|
482 | $sort[] = $info[$i]['cn'][0]; |
---|
483 | } |
---|
484 | |
---|
485 | } |
---|
486 | ldap_close($ldap_conn); |
---|
487 | |
---|
488 | natcasesort($sort); |
---|
489 | foreach ($sort as $computer_cn) |
---|
490 | $return[$computer_cn] = $tmp[$computer_cn]; |
---|
491 | |
---|
492 | return $return; |
---|
493 | } |
---|
494 | } |
---|
495 | |
---|
496 | function get_organizations($context, $selected='', $referral=false, $show_invisible_ou=true, $master=false) |
---|
497 | { |
---|
498 | $s = CreateObject('phpgwapi.sector_search_ldap'); |
---|
499 | $sectors_info = $s->get_organizations($context, $selected, $referral, $show_invisible_ou, $master); |
---|
500 | return $sectors_info; |
---|
501 | } |
---|
502 | |
---|
503 | function get_sectors($selected='', $referral=false, $show_invisible_ou=true) |
---|
504 | { |
---|
505 | $s = CreateObject('phpgwapi.sector_search_ldap'); |
---|
506 | $sectors_info = $s->get_sectors($selected, $referral, $show_invisible_ou); |
---|
507 | return $sectors_info; |
---|
508 | } |
---|
509 | |
---|
510 | // Get list of all levels, this function is used for sectors module. |
---|
511 | function get_sectors_list($contexts) |
---|
512 | { |
---|
513 | $a_sectors = array(); |
---|
514 | |
---|
515 | $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; |
---|
516 | $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; |
---|
517 | $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
518 | |
---|
519 | ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
520 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); |
---|
521 | ldap_bind($ldap_conn,$dn,$passwd); |
---|
522 | |
---|
523 | $justthese = array("dn"); |
---|
524 | $filter = "(ou=*)"; |
---|
525 | |
---|
526 | $systemName = strtolower($GLOBALS['phpgw_info']['server']['system_name']); |
---|
527 | if ($systemName != '') |
---|
528 | $filter = "(&$filter(phpgwSystem=$systemName))"; |
---|
529 | |
---|
530 | foreach ($contexts as $context) |
---|
531 | { |
---|
532 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
533 | $info = ldap_get_entries($ldap_conn, $search); |
---|
534 | for ($i=0; $i<$info["count"]; $i++) |
---|
535 | { |
---|
536 | $a_sectors[] = $info[$i]['dn']; |
---|
537 | } |
---|
538 | } |
---|
539 | |
---|
540 | ldap_close($ldap_conn); |
---|
541 | |
---|
542 | // Retiro o count do array info e inverto o array para ordenação. |
---|
543 | foreach ($a_sectors as $context) |
---|
544 | { |
---|
545 | $array_dn = ldap_explode_dn ( $context, 1 ); |
---|
546 | |
---|
547 | $array_dn_reverse = array_reverse ( $array_dn, true ); |
---|
548 | |
---|
549 | // Retirar o indice count do array. |
---|
550 | array_pop ( $array_dn_reverse ); |
---|
551 | |
---|
552 | $inverted_dn[$context] = implode ( "#", $array_dn_reverse ); |
---|
553 | } |
---|
554 | |
---|
555 | // Ordenação |
---|
556 | natcasesort($inverted_dn); |
---|
557 | |
---|
558 | // Construção do select |
---|
559 | $level = 0; |
---|
560 | $options = array(); |
---|
561 | foreach ($inverted_dn as $dn=>$invert_ufn) |
---|
562 | { |
---|
563 | $display = ''; |
---|
564 | |
---|
565 | $array_dn_reverse = explode ( "#", $invert_ufn ); |
---|
566 | $array_dn = array_reverse ( $array_dn_reverse, true ); |
---|
567 | |
---|
568 | $level = count( $array_dn ) - (int)(count(explode(",", $GLOBALS['phpgw_info']['server']['ldap_context'])) + 1); |
---|
569 | |
---|
570 | if ($level == 0) |
---|
571 | $display .= '+'; |
---|
572 | else |
---|
573 | { |
---|
574 | for ($i=0; $i<$level; $i++) |
---|
575 | $display .= '---'; |
---|
576 | } |
---|
577 | |
---|
578 | reset ( $array_dn ); |
---|
579 | $display .= ' ' . (current ( $array_dn ) ); |
---|
580 | |
---|
581 | $dn = trim(strtolower($dn)); |
---|
582 | $options[$dn] = $display; |
---|
583 | } |
---|
584 | return $options; |
---|
585 | } |
---|
586 | |
---|
587 | function exist_account_lid($account_lid) |
---|
588 | { |
---|
589 | $conection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
590 | $sri = ldap_search($conection, $GLOBALS['phpgw_info']['server']['ldap_context'], "uid=" . $account_lid); |
---|
591 | $result = ldap_get_entries($conection, $sri); |
---|
592 | return $result['count']; |
---|
593 | } |
---|
594 | |
---|
595 | function exist_email($mail) |
---|
596 | { |
---|
597 | $conection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
598 | $sri = ldap_search($conection, $GLOBALS['phpgw_info']['server']['ldap_context'], "mail=" . $mail); |
---|
599 | $result = ldap_get_entries($conection, $sri); |
---|
600 | ldap_close($conection); |
---|
601 | |
---|
602 | if ($result['count'] == 0) |
---|
603 | return false; |
---|
604 | else |
---|
605 | return true; |
---|
606 | } |
---|
607 | |
---|
608 | function array_invert($array) |
---|
609 | { |
---|
610 | $result[] = end($array); |
---|
611 | while ($item = prev($array)) |
---|
612 | $result[] = $item; |
---|
613 | return $result; |
---|
614 | } |
---|
615 | |
---|
616 | function get_next_id() |
---|
617 | { |
---|
618 | // Busco o ID dos accounts |
---|
619 | $query_accounts = "SELECT id FROM phpgw_nextid WHERE appname = 'accounts'"; |
---|
620 | $GLOBALS['phpgw']->db->query($query_accounts); |
---|
621 | while($GLOBALS['phpgw']->db->next_record()) |
---|
622 | { |
---|
623 | $result_accounts[] = $GLOBALS['phpgw']->db->row(); |
---|
624 | } |
---|
625 | $accounts_id = $result_accounts[0]['id']; |
---|
626 | |
---|
627 | // Busco o ID dos groups |
---|
628 | $query_groups = "SELECT id FROM phpgw_nextid WHERE appname = 'groups'"; |
---|
629 | $GLOBALS['phpgw']->db->query($query_groups); |
---|
630 | while($GLOBALS['phpgw']->db->next_record()) |
---|
631 | { |
---|
632 | $result_groups[] = $GLOBALS['phpgw']->db->row(); |
---|
633 | } |
---|
634 | $groups_id = $result_groups[0]['id']; |
---|
635 | |
---|
636 | //Retorna o maior dos ID's |
---|
637 | if ($accounts_id >= $groups_id) |
---|
638 | return $accounts_id; |
---|
639 | else |
---|
640 | return $groups_id; |
---|
641 | } |
---|
642 | |
---|
643 | function make_list_app($account_lid, $user_applications='', $disabled='') |
---|
644 | { |
---|
645 | // create list of ALL available apps |
---|
646 | $availableAppsGLOBALS = $GLOBALS['phpgw_info']['apps']; |
---|
647 | |
---|
648 | // create list of available apps for the user |
---|
649 | $query = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '".$account_lid."'"; |
---|
650 | $GLOBALS['phpgw']->db->query($query); |
---|
651 | while($GLOBALS['phpgw']->db->next_record()) |
---|
652 | { |
---|
653 | $availableApps[] = $GLOBALS['phpgw']->db->row(); |
---|
654 | } |
---|
655 | |
---|
656 | // Retira alguns modulos |
---|
657 | if (count($availableApps)) |
---|
658 | { |
---|
659 | foreach ($availableApps as $key => $value) |
---|
660 | { |
---|
661 | if ($value['app'] != 'phpgwapi') |
---|
662 | $tmp[] = $availableApps[$key]; |
---|
663 | } |
---|
664 | } |
---|
665 | $availableApps = $tmp; |
---|
666 | |
---|
667 | // Cria um array com as aplicacoes disponiveis para o manager, com as atributos das aplicacoes. |
---|
668 | $availableAppsUser = array(); |
---|
669 | if (count($availableApps)) |
---|
670 | { |
---|
671 | foreach($availableApps as $app => $title) |
---|
672 | { |
---|
673 | if ($availableAppsGLOBALS[$title['app']]) |
---|
674 | $availableAppsUser[$title['app']] = $availableAppsGLOBALS[$title['app']]; |
---|
675 | } |
---|
676 | } |
---|
677 | |
---|
678 | // Loop para criar dinamicamente uma tabela com 3 colunas, cada coluna com um aplicativo e um check box. |
---|
679 | $applications_list = ''; |
---|
680 | $app_col1 = ''; |
---|
681 | $app_col2 = ''; |
---|
682 | $app_col3 = ''; |
---|
683 | $total_apps = count($availableAppsUser); |
---|
684 | $i = 0; |
---|
685 | foreach($availableAppsUser as $app => $data) |
---|
686 | { |
---|
687 | // 1 coluna |
---|
688 | if (($i +1) % 3 == 1) |
---|
689 | { |
---|
690 | $checked = $user_applications[$app] ? 'CHECKED' : ''; |
---|
691 | $app_col1 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n", |
---|
692 | $data['title'],$app,$checked, $disabled); |
---|
693 | if ($i == ($total_apps-1)) |
---|
694 | $applications_list .= sprintf('<tr bgcolor="%s">%s</tr>','#DDDDDD', $app_col1); |
---|
695 | } |
---|
696 | |
---|
697 | // 2 coluna |
---|
698 | if (($i +1) % 3 == 2) |
---|
699 | { |
---|
700 | $checked = $user_applications[$app] ? 'CHECKED' : ''; |
---|
701 | $app_col2 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n", |
---|
702 | $data['title'],$app,$checked, $disabled); |
---|
703 | |
---|
704 | if ($i == ($total_apps-1)) |
---|
705 | $applications_list .= sprintf('<tr bgcolor="%s">%s%s</tr>','#DDDDDD', $app_col1,$app_col2); |
---|
706 | } |
---|
707 | // 3 coluna |
---|
708 | if (($i +1) % 3 == 0) |
---|
709 | { |
---|
710 | $checked = $user_applications[$app] ? 'CHECKED' : ''; |
---|
711 | $app_col3 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n", |
---|
712 | $data['title'],$app,$checked, $disabled); |
---|
713 | |
---|
714 | // Cria nova linha |
---|
715 | $applications_list .= sprintf('<tr bgcolor="%s">%s%s%s</tr>','#DDDDDD', $app_col1, $app_col2, $app_col3); |
---|
716 | } |
---|
717 | $i++; |
---|
718 | } |
---|
719 | return $applications_list; |
---|
720 | } |
---|
721 | |
---|
722 | function exist_attribute_in_ldap($dn, $attribute, $value) |
---|
723 | { |
---|
724 | $connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
725 | $search = ldap_search($connection, $dn, $attribute. "=" . $value); |
---|
726 | $result = ldap_get_entries($connection, $search); |
---|
727 | ldap_close($connection); |
---|
728 | //_debug_array($result); |
---|
729 | if ($result['count'] == 0) |
---|
730 | return false; |
---|
731 | else |
---|
732 | return true; |
---|
733 | } |
---|
734 | |
---|
735 | function getReturnExecuteForm(){ |
---|
736 | $response = $_SESSION['response']; |
---|
737 | $_SESSION['response'] = null; |
---|
738 | return $response; |
---|
739 | } |
---|
740 | |
---|
741 | function write_log2($action, $groupinfo='', $userinfo='', $appinfo='', $msg_log='') |
---|
742 | { |
---|
743 | $sql = "INSERT INTO phpgw_expressoadmin_log (date, manager, action, groupinfo, userinfo, appinfo, msg) " |
---|
744 | . "VALUES('now','" . $_SESSION['phpgw_info']['expresso']['user']['account_lid'] . "','" . strtolower($action) . "','" . strtolower($groupinfo) . "','" . strtolower($userinfo) . "','" . strtolower($appinfo) . "','" .strtolower($msg_log) . "')"; |
---|
745 | $GLOBALS['phpgw']->db->query($sql); |
---|
746 | return; |
---|
747 | } |
---|
748 | |
---|
749 | } |
---|
750 | |
---|
751 | class sectors_object |
---|
752 | { |
---|
753 | var $sector_name; |
---|
754 | var $sector_context; |
---|
755 | var $sector_level; |
---|
756 | var $sector_leaf; |
---|
757 | var $sectors_list = array(); |
---|
758 | var $level; |
---|
759 | |
---|
760 | function sectors_object($sector_name, $sector_context, $sector_level, $sector_leaf) |
---|
761 | { |
---|
762 | $this->sector_name = $sector_name; |
---|
763 | $this->sector_context = $sector_context; |
---|
764 | $this->sector_level = $sector_level; |
---|
765 | $this->sector_leaf = $sector_leaf; |
---|
766 | } |
---|
767 | } |
---|