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 sosectors |
---|
13 | { |
---|
14 | var $functions; |
---|
15 | |
---|
16 | function sosectors() |
---|
17 | { |
---|
18 | $this->functions = createobject('expressoAdmin1_2.functions'); |
---|
19 | } |
---|
20 | |
---|
21 | function exist_sector_name($sector_name, $context) |
---|
22 | { |
---|
23 | $connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
24 | $search = ldap_list($connection, $context, "ou=" . $sector_name); |
---|
25 | $result = ldap_get_entries($connection, $search); |
---|
26 | |
---|
27 | if ($result['count'] == 0) |
---|
28 | return false; |
---|
29 | else |
---|
30 | return true; |
---|
31 | } |
---|
32 | |
---|
33 | function write_ldap($dn, $info) |
---|
34 | { |
---|
35 | $connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
36 | |
---|
37 | if (ldap_add($connection, $dn, $info)) |
---|
38 | { |
---|
39 | //Escreve no log |
---|
40 | $this->functions->write_log2($GLOBALS['phpgw']->accounts->data['account_lid'], 'write in ldap', $dn,'','',''); |
---|
41 | ldap_close($connection); |
---|
42 | return true; |
---|
43 | } |
---|
44 | else |
---|
45 | { |
---|
46 | echo 'Erro na escrita no LDAP, funcao write_ldap'; |
---|
47 | ldap_close($connection); |
---|
48 | return false; |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | function get_sector_users($context) |
---|
53 | { |
---|
54 | $connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
55 | $justthese = array("cn", "uidNumber", "uid"); |
---|
56 | $filter="(&(phpgwAccountType=u)(uid=*))"; |
---|
57 | $search=ldap_search($connection, $context, $filter, $justthese); |
---|
58 | $result = ldap_get_entries($connection, $search); |
---|
59 | return $result; |
---|
60 | } |
---|
61 | |
---|
62 | function get_sector_groups($context) |
---|
63 | { |
---|
64 | $connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
65 | $justthese = array("cn", "gidnumber"); |
---|
66 | $filter="(&(phpgwAccountType=g)(cn=*))"; |
---|
67 | $search=ldap_search($connection, $context, $filter, $justthese); |
---|
68 | $result = ldap_get_entries($connection, $search); |
---|
69 | return $result; |
---|
70 | } |
---|
71 | |
---|
72 | function get_sector_subsectors($context) |
---|
73 | { |
---|
74 | $connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
75 | $justthese = array("ou"); |
---|
76 | $filter="(objectClass=organizationalUnit)"; |
---|
77 | $search=ldap_search($connection, $context, $filter, $justthese); |
---|
78 | $result = ldap_get_entries($connection, $search); |
---|
79 | return $result; |
---|
80 | } |
---|
81 | |
---|
82 | function delete_sector_ldap_recursively($connection, $dn) |
---|
83 | { |
---|
84 | //searching for sub entries |
---|
85 | $search=ldap_list($connection,$dn,"ObjectClass=organizationalUnit",array("")); |
---|
86 | $info = ldap_get_entries($connection, $search); |
---|
87 | |
---|
88 | for($i=0;$i<$info['count'];$i++) |
---|
89 | { |
---|
90 | //deleting recursively sub entries |
---|
91 | $result=$this->delete_sector_ldap_recursively($connection,$info[$i]['dn']); |
---|
92 | if(!$result) |
---|
93 | { |
---|
94 | //return result code, if delete fails |
---|
95 | return($result); |
---|
96 | } |
---|
97 | } |
---|
98 | return(ldap_delete($connection,$dn)); |
---|
99 | } |
---|
100 | } |
---|
101 | ?> |
---|