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 | var $ldap_connection; |
---|
16 | var $db_functions; |
---|
17 | |
---|
18 | function sosectors() |
---|
19 | { |
---|
20 | $this->functions = createobject('expressoAdmin1_2.functions'); |
---|
21 | $this->db_functions = CreateObject('expressoAdmin1_2.db_functions'); |
---|
22 | |
---|
23 | if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) && |
---|
24 | (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) && |
---|
25 | (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) ) |
---|
26 | { |
---|
27 | $this->ldap_connection = $GLOBALS['phpgw']->common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'], |
---|
28 | $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'], |
---|
29 | $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']); |
---|
30 | } |
---|
31 | else |
---|
32 | { |
---|
33 | $this->ldap_connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
34 | } |
---|
35 | } |
---|
36 | |
---|
37 | function exist_sector_name($sector_name, $context) |
---|
38 | { |
---|
39 | $search = ldap_list($this->ldap_connection, $context, "ou=" . $sector_name); |
---|
40 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
41 | |
---|
42 | if ($result['count'] == 0) |
---|
43 | return false; |
---|
44 | else |
---|
45 | return true; |
---|
46 | } |
---|
47 | |
---|
48 | function write_ldap($dn, $info) |
---|
49 | { |
---|
50 | $info['ou'] = utf8_encode($info['ou']); |
---|
51 | |
---|
52 | if (ldap_add($this->ldap_connection, utf8_encode($dn), $info)) |
---|
53 | { |
---|
54 | $this->db_functions->write_log("write on ldap", "$dn"); |
---|
55 | ldap_close($this->ldap_connection); |
---|
56 | return true; |
---|
57 | } |
---|
58 | else |
---|
59 | { |
---|
60 | echo lang('Error written in LDAP, function write_ldap'); |
---|
61 | ldap_close($this->ldap_connection); |
---|
62 | return false; |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | function get_sector_users($context) |
---|
67 | { |
---|
68 | $justthese = array("cn", "uidNumber", "uid"); |
---|
69 | $filter="(&(phpgwAccountType=u)(uid=*))"; |
---|
70 | $search=ldap_search($this->ldap_connection, $context, $filter, $justthese); |
---|
71 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
72 | return $result; |
---|
73 | } |
---|
74 | |
---|
75 | function get_sector_groups($context) |
---|
76 | { |
---|
77 | $justthese = array("cn", "gidnumber"); |
---|
78 | $filter="(&(phpgwAccountType=g)(cn=*))"; |
---|
79 | $search=ldap_search($this->ldap_connection, $context, $filter, $justthese); |
---|
80 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
81 | return $result; |
---|
82 | } |
---|
83 | |
---|
84 | function get_sector_subsectors($context) |
---|
85 | { |
---|
86 | $justthese = array("ou"); |
---|
87 | $filter="(objectClass=organizationalUnit)"; |
---|
88 | $search=ldap_search($this->ldap_connection, $context, $filter, $justthese); |
---|
89 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
90 | return $result; |
---|
91 | } |
---|
92 | |
---|
93 | function delete_sector_ldap_recursively($connection, $dn) |
---|
94 | { |
---|
95 | //searching for sub entries |
---|
96 | $search=ldap_list($connection,$dn,"ObjectClass=*",array("")); |
---|
97 | $info = ldap_get_entries($connection, $search); |
---|
98 | |
---|
99 | for($i=0;$i<$info['count'];$i++) |
---|
100 | { |
---|
101 | //deleting recursively sub entries |
---|
102 | $result=$this->delete_sector_ldap_recursively($connection,$info[$i]['dn']); |
---|
103 | if(!$result) |
---|
104 | { |
---|
105 | //return result code, if delete fails |
---|
106 | return($result); |
---|
107 | } |
---|
108 | } |
---|
109 | return(ldap_delete($connection,$dn)); |
---|
110 | } |
---|
111 | |
---|
112 | function get_info($context) |
---|
113 | { |
---|
114 | $filter="(objectClass=organizationalUnit)"; |
---|
115 | $search=ldap_search($this->ldap_connection, $context, $filter); |
---|
116 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
117 | return $result; |
---|
118 | } |
---|
119 | |
---|
120 | function add_attribute($dn, $info) |
---|
121 | { |
---|
122 | if (ldap_mod_add($this->ldap_connection, $dn, $info)) |
---|
123 | { |
---|
124 | ldap_close($this->ldap_connection); |
---|
125 | return true; |
---|
126 | } |
---|
127 | else |
---|
128 | { |
---|
129 | echo lang('Error written in LDAP, function add_attribute'). ldap_error($this->ldap_connection); |
---|
130 | ldap_close($this->ldap_connection); |
---|
131 | return false; |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | function remove_attribute($dn, $info) |
---|
136 | { |
---|
137 | if (ldap_mod_del($this->ldap_connection, $dn, $info)) |
---|
138 | { |
---|
139 | ldap_close($this->ldap_connection); |
---|
140 | return true; |
---|
141 | } |
---|
142 | else |
---|
143 | { |
---|
144 | echo lang('Error written in LDAP, function remove_attribute'). ldap_error($this->ldap_connection); |
---|
145 | ldap_close($this->ldap_connection); |
---|
146 | return false; |
---|
147 | } |
---|
148 | } |
---|
149 | } |
---|
150 | ?> |
---|