[2] | 1 | <?php |
---|
| 2 | /***************************************************************************\ |
---|
| 3 | * eGroupWare - Contacts Center * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * Written by: * |
---|
| 6 | * - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net> * |
---|
| 7 | * ------------------------------------------------------------------------- * |
---|
| 8 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 9 | * under the terms of the GNU General Public License as published by the * |
---|
| 10 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 11 | * option) any later version. * |
---|
| 12 | \***************************************************************************/ |
---|
| 13 | |
---|
[285] | 14 | |
---|
[2] | 15 | /* |
---|
| 16 | This class is responsible for the LDAP control/generic functions and for |
---|
| 17 | configuration gathering |
---|
| 18 | */ |
---|
[284] | 19 | include_once('class.Thread.inc.php'); |
---|
[2] | 20 | |
---|
[285] | 21 | class bo_ldap_manager |
---|
[2] | 22 | { |
---|
[285] | 23 | |
---|
[2] | 24 | var $srcs; |
---|
| 25 | |
---|
[285] | 26 | |
---|
[2] | 27 | function bo_ldap_manager () |
---|
| 28 | { |
---|
| 29 | if (!($this->srcs = $GLOBALS['phpgw']->session->appsession('bo_ldap_manager.srcs','contactcenter'))) |
---|
| 30 | { |
---|
| 31 | $c = CreateObject('phpgwapi.config','contactcenter'); |
---|
| 32 | $data = $c->read_repository(); |
---|
[285] | 33 | |
---|
[2] | 34 | if (!$data or $data['cc_global_source0'] !== 'ldap') |
---|
| 35 | { |
---|
| 36 | $this->srcs = null; |
---|
| 37 | return; |
---|
| 38 | } |
---|
[285] | 39 | |
---|
[2] | 40 | $this->srcs = array( |
---|
| 41 | 1 => array( |
---|
| 42 | 'name' => $data['cc_catalog_name'], |
---|
| 43 | 'host' => $data['cc_ldap_host0'], |
---|
| 44 | 'dn' => $data['cc_ldap_context0'], |
---|
| 45 | 'acc' => $data['cc_ldap_browse_dn0'], |
---|
| 46 | 'pw' => $data['cc_ldap_pw0'], |
---|
| 47 | 'obj' => 'inetOrgPerson', |
---|
[285] | 48 | 'branch' => strtolower('ou'), |
---|
| 49 | 'visible' => $data['cc_ldap_query_automatic'] |
---|
[2] | 50 | ) |
---|
| 51 | ); |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | function new_ldap_source ( $source_name, $charset, $host, $port, $dn_root, $dn_admin, $admin_pass, $contact_objectclass ) |
---|
| 56 | { |
---|
| 57 | } |
---|
[285] | 58 | |
---|
[2] | 59 | /* |
---|
[285] | 60 | |
---|
[2] | 61 | @function get_all_ldap_sources |
---|
| 62 | @abstract Returns an array containing all LDAP sources informations |
---|
| 63 | @author Raphael Derosso Pereira |
---|
[285] | 64 | |
---|
[2] | 65 | @return array All LDAP information |
---|
| 66 | $return = array( |
---|
| 67 | <id_source> => array( |
---|
| 68 | 'host' => (string), |
---|
| 69 | 'dn' => (string), |
---|
| 70 | 'acc' => (string), |
---|
[285] | 71 | 'pw' => (string) |
---|
[2] | 72 | ), |
---|
| 73 | ... |
---|
| 74 | ) |
---|
[285] | 75 | |
---|
[2] | 76 | TODO: Return multiple sources... |
---|
| 77 | */ |
---|
| 78 | function get_all_ldap_sources ( ) |
---|
| 79 | { |
---|
| 80 | return $this->srcs; |
---|
| 81 | } |
---|
[285] | 82 | |
---|
[284] | 83 | /* |
---|
| 84 | * @function get_external_ldap_sources |
---|
| 85 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
| 86 | * @abstract returns an array with the external sources |
---|
| 87 | * @return (array) the external sources |
---|
| 88 | */ |
---|
| 89 | |
---|
| 90 | function get_external_ldap_sources() |
---|
| 91 | { |
---|
| 92 | include(PHPGW_INCLUDE_ROOT . '/contactcenter/setup/external_catalogs.inc.php' ); |
---|
| 93 | //include('external_catalogs.inc.php' ); |
---|
| 94 | return $external_srcs; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | /* |
---|
| 98 | * @function get_ldap_fields_association |
---|
| 99 | * @abstract get the fields associantion for ldap source |
---|
| 100 | * @return an array with attribute mappings |
---|
| 101 | */ |
---|
[2] | 102 | function get_ldap_fields_association ( $id_source ) |
---|
| 103 | { |
---|
[285] | 104 | |
---|
[2] | 105 | $op_iop = array( |
---|
| 106 | 'contact.id_contact' => array('dn'), |
---|
| 107 | 'contact.photo' => array('jpegPhoto'), |
---|
| 108 | 'contact.prefixes.prefix' => false, |
---|
| 109 | 'contact.alias' => array('alias'), |
---|
| 110 | 'contact.given_names' => array('givenName'), |
---|
| 111 | 'contact.family_names' => array('sn'), |
---|
| 112 | 'contact.names_ordered' => array('cn'),//,'displayName'), |
---|
| 113 | 'contact.suffixes.suffix' => false, |
---|
| 114 | 'contact.birthdate' => false, |
---|
| 115 | 'contact.sex' => false, |
---|
| 116 | 'contact.pgp_key' => false, |
---|
| 117 | 'contact.notes' => false, |
---|
[285] | 118 | 'contact.mail_forwarding_address' => array('mailForwardingAddress'), |
---|
| 119 | 'contact.account_type' => array('phpgwAccountType'), |
---|
| 120 | 'contact.account_status' => array('phpgwAccountStatus'), |
---|
| 121 | 'contact.account_visible' => array('phpgwAccountVisible'), |
---|
[284] | 122 | 'contact.object_class' => array('objectClass'), |
---|
[2] | 123 | 'contact.business_info.title' => array('title'), |
---|
[285] | 124 | 'contact.business_info.department' => array('ou'), |
---|
[2] | 125 | 'contact.company.company_name' => array('o'), |
---|
| 126 | 'contact.company.company_notes' => array('businessCategory'), |
---|
[285] | 127 | |
---|
[2] | 128 | 'contact.contact_related.names_ordered' => 'contact.contact_related.typeof_relation.contact_relation_name', |
---|
| 129 | 'contact.contact_related.typeof_relation.contact_relation_name' => array( |
---|
| 130 | 'manager' => array('manager'), |
---|
| 131 | 'secretary' => array('secretary') |
---|
| 132 | ), |
---|
[285] | 133 | |
---|
[2] | 134 | 'contact.address.address1' => 'contact.address.typeof_address.contact_address_type_name', |
---|
| 135 | 'contact.address.typeof_address.contact_address_type_name' => array( |
---|
| 136 | 'home' => array('street', 'st', 'postalAddress', 'homePostalAddress'), |
---|
| 137 | ), |
---|
[285] | 138 | |
---|
[2] | 139 | 'contact.address.postal_code' => 'contact.address.typeof_address.contact_address_type_name', |
---|
| 140 | 'contact.address.typeof_address.contact_address_type_name' => array( |
---|
| 141 | 'home' => array('PostalCode'), |
---|
| 142 | ), |
---|
[285] | 143 | |
---|
[2] | 144 | 'contact.address.city.city_name' => 'contact.address.typeof_address.contact_address_type_name', |
---|
| 145 | 'contact.address.typeof_address.contact_address_type_name' => array( |
---|
| 146 | 'home' => array('l'), |
---|
| 147 | ), |
---|
[285] | 148 | |
---|
[2] | 149 | 'contact.address.city.state.state_name' => 'contact.address.typeof_address.contact_address_type_name', |
---|
| 150 | 'contact.address.typeof_address.contact_address_type_name' => array( |
---|
| 151 | 'home' => false, |
---|
| 152 | ), |
---|
[285] | 153 | |
---|
[2] | 154 | 'contact.address.city.country.id_country' => 'contact.address.typeof_address.contact_address_type_name', |
---|
| 155 | 'contact.address.typeof_address.contact_address_type_name' => array( |
---|
| 156 | 'home' => array('c') |
---|
| 157 | ), |
---|
[285] | 158 | |
---|
[2] | 159 | 'contact.connection.connection_value' => 'contact.connection.typeof_connection.contact_connection_type_name', |
---|
| 160 | 'contact.connection.typeof_connection.contact_connection_type_name' => array ( |
---|
| 161 | 'email' => array('mail'), |
---|
| 162 | 'phone' => array('telephoneNumber'), |
---|
| 163 | 'mobile' => array('mobile'), |
---|
| 164 | 'pager' => array('pager'), |
---|
| 165 | 'fax' => array('facsimileTelephoneNumber'), |
---|
| 166 | 'telex' => array('telexNumber') |
---|
| 167 | ), |
---|
| 168 | ); |
---|
[285] | 169 | |
---|
[2] | 170 | return $op_iop; |
---|
| 171 | } |
---|
| 172 | |
---|
[284] | 173 | /* |
---|
| 174 | * @function get_external_ldap_fields_association |
---|
| 175 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
| 176 | * @abstract get the fields association for an external ldap_source |
---|
| 177 | * @return an array with attribute mappings |
---|
| 178 | */ |
---|
| 179 | function get_external_ldap_fields_association ( $id_source ) |
---|
| 180 | { |
---|
| 181 | include(PHPGW_INCLUDE_ROOT . '/contactcenter/setup/external_catalogs.inc.php' ); |
---|
| 182 | //include('external_catalogs.inc.php' ); |
---|
| 183 | return $external_mappings[$id_source]; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | /* |
---|
| 187 | * @function test_connection |
---|
| 188 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
| 189 | * @abstract Test if we can bind to a ldap server in a reasonable time |
---|
| 190 | * @param (string) $host ldap server's hostname |
---|
| 191 | * @param (string) $account ldap bind dn |
---|
| 192 | * @param (string) $password a bind dn's password |
---|
| 193 | * @return (array) an array with the answer from the subprocess, null otherwise |
---|
| 194 | */ |
---|
| 195 | function test_connection($host, $account, $password, $timeout = 5) |
---|
| 196 | { |
---|
| 197 | //opens a subprocess for nonblocking bind |
---|
| 198 | $tsearch = Thread::Create('class.ldap_assync.inc.php', array('host' => $host, |
---|
| 199 | 'account' => $account, |
---|
| 200 | 'password' => $password |
---|
| 201 | ) |
---|
| 202 | ); |
---|
| 203 | |
---|
| 204 | // It's problably more efficient to let method readResponse control the timeout through |
---|
| 205 | // stream_select native timeout. |
---|
| 206 | $response = NULL; |
---|
| 207 | for ($i = 0; $i < $timeout; $i++) |
---|
| 208 | { |
---|
| 209 | if ($tsearch->isActive()) |
---|
| 210 | { |
---|
| 211 | sleep(1); |
---|
| 212 | if (($response = $tsearch->readResponse()) !== NULL) |
---|
| 213 | { |
---|
| 214 | $tsearch->close(); |
---|
| 215 | return $response; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | } |
---|
| 219 | else |
---|
| 220 | { |
---|
| 221 | $response = $tsearch->readResponse(); |
---|
| 222 | break; |
---|
| 223 | } |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | $tsearch->close(); |
---|
| 227 | return null; |
---|
| 228 | } |
---|
| 229 | |
---|
[2] | 230 | /*! |
---|
[285] | 231 | |
---|
[2] | 232 | @function get_ldap_tree |
---|
| 233 | @abstract Returns the LDAP tree corresponding to the specified level |
---|
| 234 | @author Raphael Derosso Pereira |
---|
[285] | 235 | |
---|
[2] | 236 | @param (integer) $id_source The ID of the LDAP source |
---|
[285] | 237 | |
---|
[2] | 238 | @param (string) $context The context to be used as root branch |
---|
[285] | 239 | |
---|
[2] | 240 | @param (boolean) $recursive Make it a recursive construction. |
---|
| 241 | CAUTION! This is EXTREMELY SLOW on large LDAP databases, |
---|
| 242 | specially when they're not indexed |
---|
[285] | 243 | */ |
---|
| 244 | function get_ldap_tree($id_source, $context = false, $recursive = false) |
---|
[2] | 245 | { |
---|
| 246 | if (!$this->srcs[$id_source]) |
---|
| 247 | { |
---|
| 248 | return null; |
---|
| 249 | } |
---|
[285] | 250 | |
---|
[314] | 251 | $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->srcs[$id_source]['host'], $this->srcs[$id_source]['acc'],$this->srcs[$id_source]['pw'], true); |
---|
[2] | 252 | if (!$ldap) |
---|
| 253 | { |
---|
| 254 | return false; |
---|
| 255 | } |
---|
[285] | 256 | |
---|
[2] | 257 | if ($recursive) |
---|
| 258 | { |
---|
| 259 | $tree = $this->get_ldap_tree_recursive($ldap, $context, $this->srcs[$id_source]['obj'],$this->srcs[$id_source]['branch']); |
---|
| 260 | $tree['recursive'] = true; |
---|
| 261 | |
---|
| 262 | return $tree; |
---|
| 263 | } |
---|
[285] | 264 | |
---|
| 265 | return $this->get_ldap_tree_level($id_source, $ldap, $context, $this->srcs[$id_source]['obj'],$this->srcs[$id_source]['branch']); |
---|
[2] | 266 | } |
---|
[285] | 267 | // SERPRO |
---|
[2] | 268 | |
---|
[284] | 269 | /*! |
---|
[2] | 270 | |
---|
[284] | 271 | @function get_external_ldap_tree |
---|
| 272 | @abstract Returns the LDAP external tree corresponding to the specified level |
---|
| 273 | @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
| 274 | @param (integer) $id_source The ID of the external LDAP source |
---|
| 275 | @param (string) $context The context to be used as root branch |
---|
| 276 | @param (boolean) $recursive Make it a recursive construction. |
---|
| 277 | CAUTION! This is EXTREMELY SLOW on large LDAP databases, |
---|
| 278 | specially when they're not indexed |
---|
| 279 | */ |
---|
| 280 | function get_external_ldap_tree($id_source, $context = false, $recursive = false) |
---|
| 281 | { |
---|
| 282 | |
---|
| 283 | |
---|
| 284 | include(PHPGW_INCLUDE_ROOT . '/contactcenter/setup/external_catalogs.inc.php' ); |
---|
| 285 | //include('external_catalogs.inc.php' ); |
---|
| 286 | |
---|
| 287 | if (!$external_srcs[$id_source]) |
---|
| 288 | { |
---|
| 289 | return null; |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | // calls test_connection first. If succeeded continue, return error message otherwise. |
---|
| 293 | if (!($response = $this->test_connection($external_srcs[$id_source]['host'], $external_srcs[$id_source]['acc'], $external_srcs[$id_source]['pw'], 10))) |
---|
| 294 | { |
---|
| 295 | return array( |
---|
| 296 | 'msg' => lang("Catalog %1 temporarily unavailable. Please try again later!", $external_srcs[$id_source]['name']), |
---|
| 297 | 'timeout' => 'true' |
---|
| 298 | ); |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | $ldap = $GLOBALS['phpgw']->common->ldapConnect($external_srcs[$id_source]['host'], $external_srcs[$id_source]['acc'],$external_srcs[$id_source]['pw'], false); |
---|
| 302 | if (!$ldap) |
---|
| 303 | { |
---|
| 304 | return false; |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | // Option recursive commented out |
---|
| 308 | /* |
---|
| 309 | if ($recursive) |
---|
| 310 | { |
---|
| 311 | $tree = $this->get_ldap_tree_recursive($ldap, $context, $this->srcs[$id_source]['obj'],$this->srcs[$id_source]['branch']); |
---|
| 312 | $tree['recursive'] = true; |
---|
| 313 | |
---|
| 314 | return $tree; |
---|
| 315 | } |
---|
| 316 | */ |
---|
| 317 | |
---|
| 318 | return $this->get_ldap_tree_level($id_source, $ldap, $context, $external_srcs[$id_source]['obj'],$external_srcs[$id_source]['branch'], 1); |
---|
| 319 | } |
---|
| 320 | |
---|
[2] | 321 | /*! |
---|
| 322 | |
---|
| 323 | THIS FUNCTION IS NOT TESTED AND IS PROBABLY BROKEN! |
---|
| 324 | I WILL CORRECT IT IN THE NEAR FUTURE |
---|
| 325 | |
---|
| 326 | */ |
---|
| 327 | function get_ldap_tree_recursive($resource, $context, $objectClass) |
---|
| 328 | { |
---|
| 329 | $filter = '(!(objectClass='.$objectClass.'))'; |
---|
| 330 | $result_res = ldap_list($resource, $context, $filter); |
---|
| 331 | |
---|
| 332 | if ($result_res === false) |
---|
| 333 | { |
---|
| 334 | return null; |
---|
| 335 | } |
---|
[285] | 336 | |
---|
[2] | 337 | $count = ldap_count_entries($resource,$result_res); |
---|
| 338 | if ( $count == 0 ) |
---|
| 339 | { |
---|
| 340 | $filter = 'objectClass='.$objectClass; |
---|
| 341 | $result_res2 = ldap_list($resource, $context, $filter); |
---|
| 342 | $entries_count = ldap_count_entries($resource, $result_res2); |
---|
| 343 | |
---|
| 344 | if ($result_res2 !== false && $entries_count > 0) |
---|
| 345 | { |
---|
| 346 | return $entries_count; |
---|
| 347 | } |
---|
| 348 | else |
---|
| 349 | { |
---|
| 350 | return null; |
---|
| 351 | } |
---|
| 352 | } |
---|
[285] | 353 | |
---|
[2] | 354 | $entries = ldap_get_entries($resource, $result_res); |
---|
[285] | 355 | |
---|
[2] | 356 | for ($i = 0; $i < $entries['count']; $i++) |
---|
| 357 | { |
---|
| 358 | $subtree = $this->get_ldap_tree_recursive($resource, $entries[$i]['dn'], $objectClass); |
---|
[285] | 359 | |
---|
[2] | 360 | $dn_parts=ldap_explode_dn($entries[$i]['dn'],1); |
---|
[285] | 361 | |
---|
| 362 | if ($subtree !== null and is_array($subtree)) |
---|
[2] | 363 | { |
---|
| 364 | $tree[$i]['name'] = $dn_parts[0]; |
---|
| 365 | $tree[$i]['type'] = 'catalog_group'; |
---|
| 366 | $tree[$i]['recursive'] = true; |
---|
| 367 | $tree[$i]['sub_branch'] = $subtree; |
---|
| 368 | } |
---|
| 369 | else if (is_int($subtree) and $subtree !== null) |
---|
| 370 | { |
---|
| 371 | $tree[$i] = array( |
---|
| 372 | 'name' => $dn_parts[0], |
---|
| 373 | 'type' => 'catalog', |
---|
| 374 | 'class' => 'global_contact_manager', |
---|
| 375 | 'icon' => 'share-mini.png', |
---|
| 376 | 'value' => $entries[$i]['dn'], |
---|
| 377 | 'sub_branch' => false |
---|
| 378 | ); |
---|
[285] | 379 | } |
---|
[2] | 380 | } |
---|
| 381 | |
---|
| 382 | if (is_array($tree)) |
---|
| 383 | { |
---|
| 384 | return $tree; |
---|
| 385 | } |
---|
| 386 | else |
---|
| 387 | { |
---|
| 388 | return null; |
---|
| 389 | } |
---|
| 390 | } |
---|
[285] | 391 | |
---|
[2] | 392 | function get_ldap_referrals($ds, $dn, $filter) { |
---|
[285] | 393 | |
---|
[2] | 394 | ldap_set_option($ds, LDAP_OPT_REFERRALS, 0); |
---|
| 395 | ldap_set_option($ds,LDAP_OPT_PROTOCOL_VERSION,3); |
---|
[285] | 396 | |
---|
[2] | 397 | if ($ds) { |
---|
| 398 | ldap_bind($ds); |
---|
[285] | 399 | $sr=ldap_list($ds,$dn, $filter); |
---|
[2] | 400 | $ref = ldap_first_reference($ds, $sr); |
---|
| 401 | $array_referral = array(); |
---|
| 402 | $idx = 0; |
---|
[285] | 403 | |
---|
[2] | 404 | while ($ref) { |
---|
| 405 | $array_referral[$idx++] = ldap_get_dn($ds, $ref); |
---|
| 406 | $ref = ldap_next_reference($ds, $ref); |
---|
| 407 | } |
---|
| 408 | return $array_referral; |
---|
| 409 | } |
---|
[285] | 410 | else |
---|
[2] | 411 | return false; |
---|
[314] | 412 | |
---|
| 413 | |
---|
[2] | 414 | } |
---|
| 415 | |
---|
| 416 | function get_ldap_sub_branches_referrals($ds, $dn, $filter) { |
---|
[285] | 417 | |
---|
[2] | 418 | $referral = $this -> get_ldap_referrals($ds, $dn, $filter); |
---|
| 419 | $sub_branches = array(); |
---|
[285] | 420 | |
---|
[2] | 421 | for($i = 0; $i <count($referral); $i++) { |
---|
| 422 | $dn = str_replace("??base","",preg_replace('!^(ldap://[^/]+)/(.*$)!', '\\2', $referral[$i])); |
---|
[285] | 423 | $dn = explode(",",$dn); |
---|
[2] | 424 | $dn = strtoupper(str_replace("ou=", "",$dn[0])); |
---|
| 425 | $dn = str_replace("DC=", "",$dn); |
---|
[285] | 426 | |
---|
[2] | 427 | $sub_branch = array( |
---|
| 428 | 'name' => $dn, |
---|
| 429 | 'type' => 'unknown', |
---|
| 430 | 'value' => $referral[$i], |
---|
[285] | 431 | 'sub_branch' => false |
---|
| 432 | ); |
---|
| 433 | $sub_branches[$i] = $sub_branch; |
---|
[2] | 434 | } |
---|
| 435 | return $sub_branches; |
---|
| 436 | } |
---|
[285] | 437 | |
---|
[2] | 438 | |
---|
[284] | 439 | function translate_accentuation($text) |
---|
[2] | 440 | { |
---|
[284] | 441 | /* |
---|
| 442 | * Esta operação resolve o problema causado pela conversão de caracteres acentuados realizada |
---|
| 443 | * pela função ldap_explode_dn(). |
---|
| 444 | */ |
---|
| 445 | |
---|
| 446 | return utf8_decode(preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $text)); |
---|
| 447 | } |
---|
| 448 | |
---|
| 449 | function get_ldap_tree_level($id_source, $resource, $context, $objectClass, $branch_dn, $external = 0) |
---|
| 450 | { |
---|
[314] | 451 | |
---|
[284] | 452 | /* |
---|
| 453 | * TODO: Search timeouts |
---|
| 454 | */ |
---|
[314] | 455 | |
---|
| 456 | $dn_parts = ldap_explode_dn($context,1); |
---|
[23] | 457 | //$filter = '(!(objectClass='.$objectClass.'))'; |
---|
| 458 | // Don't show OU's whith phpgwAccountVisible equal to '-1' |
---|
[284] | 459 | if ($external) |
---|
| 460 | { |
---|
| 461 | // external source: get all organizationalUnits |
---|
| 462 | $filter = '(objectClass=organizationalUnit)'; |
---|
| 463 | } |
---|
| 464 | else |
---|
| 465 | { |
---|
| 466 | // get any objectClass except the objectClass used for the source |
---|
| 467 | // and whose attribute phpgwAccountVisible value is different from -1 |
---|
| 468 | $filter = '(&(!(objectClass='.$objectClass.')) (!(phpgwAccountVisible=-1)))'; |
---|
| 469 | } |
---|
[383] | 470 | $context = preg_replace("/dc=(.*)/i",$this->srcs[$id_source]['dn'],$context); |
---|
[314] | 471 | $result_res = @ldap_list($resource, $context, $filter, array(), 0, 0); |
---|
[333] | 472 | if (!$result_res) |
---|
[2] | 473 | return null; |
---|
[333] | 474 | |
---|
| 475 | @ldap_sort($resource, $result_res, 'ou'); |
---|
[2] | 476 | $count = ldap_count_entries($resource,$result_res); |
---|
[314] | 477 | |
---|
[2] | 478 | if ( $count == 0 ) |
---|
| 479 | { |
---|
[284] | 480 | $filter = '(objectClass='.$objectClass.')'; |
---|
| 481 | // Get only one attribute of the source's objectClass |
---|
[314] | 482 | $result_res2 = @ldap_list($resource, $context, $filter, Array('cn'), 0, 1); |
---|
[333] | 483 | if (!$result_res2) |
---|
| 484 | return null; |
---|
| 485 | |
---|
[2] | 486 | $entries_count = ldap_count_entries($resource, $result_res2); |
---|
| 487 | |
---|
| 488 | if ($result_res2 !== false && $entries_count > 0) |
---|
| 489 | { |
---|
| 490 | return array( |
---|
[284] | 491 | 'name' => $this->translate_accentuation($dn_parts[0]), |
---|
[2] | 492 | 'type' => 'catalog', |
---|
| 493 | 'class' => 'bo_global_ldap_catalog', |
---|
[284] | 494 | // Pass the variable $external as a parameter to the constructor |
---|
| 495 | 'class_args' => array($id_source, $context, $external), |
---|
[2] | 496 | 'icon' => 'globalcatalog-mini.png', |
---|
| 497 | 'value' => $context, |
---|
| 498 | 'sub_branch' => false |
---|
| 499 | ); |
---|
| 500 | } |
---|
| 501 | else |
---|
| 502 | { |
---|
| 503 | return array( |
---|
[284] | 504 | 'name' => $this->translate_accentuation($dn_parts[0]), |
---|
[2] | 505 | 'type' => 'empty' |
---|
| 506 | ); |
---|
| 507 | } |
---|
| 508 | } |
---|
[314] | 509 | |
---|
[2] | 510 | $sub_branch_found = false; |
---|
| 511 | $i = 0; |
---|
| 512 | for ($entry = ldap_first_entry($resource, $result_res); |
---|
| 513 | $entry != false; |
---|
| 514 | $entry = ldap_next_entry($resource, $entry)) |
---|
| 515 | { |
---|
| 516 | $dn = ldap_get_dn($resource, $entry); |
---|
| 517 | $dn_parts_1 = ldap_explode_dn($dn,1); |
---|
| 518 | $dn_parts_full = ldap_explode_dn($dn,0); |
---|
| 519 | list($group) = explode('=',$dn_parts_full[0]); |
---|
[284] | 520 | |
---|
| 521 | //Faz a comparação do branch como case insensitive |
---|
| 522 | if (strtolower($group) == strtolower($branch_dn) or $branch_dn === 'all') |
---|
[2] | 523 | { |
---|
| 524 | $tree['sub_branch'][$i] = array( |
---|
[284] | 525 | 'name' => $this->translate_accentuation($dn_parts_1[0]), |
---|
[2] | 526 | 'type' => 'unknown', |
---|
[314] | 527 | 'value' => $dn, |
---|
[284] | 528 | 'sub_branch' => false |
---|
[2] | 529 | ); |
---|
| 530 | $sub_branch_found = true; |
---|
| 531 | } |
---|
| 532 | $i++; |
---|
| 533 | } |
---|
[314] | 534 | |
---|
[2] | 535 | $filter = 'objectClass='.$objectClass; |
---|
[314] | 536 | $result_res2 = @ldap_list($resource, $context, $filter, Array('cn'), 0, 1); |
---|
[2] | 537 | $entries_count = ldap_count_entries($resource, $result_res2); |
---|
| 538 | |
---|
| 539 | if ($result_res2 !== false && $entries_count > 0 && $sub_branch_found) |
---|
| 540 | { |
---|
[284] | 541 | $tree['name'] = $this->translate_accentuation($dn_parts[0]); |
---|
[2] | 542 | $tree['type'] = 'mixed_catalog_group'; |
---|
| 543 | $tree['class'] = 'bo_global_ldap_catalog'; |
---|
[284] | 544 | // Pass the variable $external as a parameter to the constructor |
---|
| 545 | $tree['class_args'] = array($id_source,$context,$external); |
---|
[2] | 546 | $tree['icon'] = 'globalcatalog-mini.png'; |
---|
| 547 | $tree['value'] = $context; |
---|
| 548 | } |
---|
| 549 | elseif ($result_res2 !== false && $entries_count > 0 && !$sub_branch_found) |
---|
| 550 | { |
---|
| 551 | return array( |
---|
[284] | 552 | 'name' => $this->translate_accentuation($dn_parts[0]), |
---|
[2] | 553 | 'type' => 'catalog', |
---|
| 554 | 'class' => 'bo_global_ldap_catalog', |
---|
[284] | 555 | // Pass the variable $external as a parameter to the constructor |
---|
| 556 | 'class_args' => array($id_source, $context,$external), |
---|
[2] | 557 | 'icon' => 'globalcatalog-mini.png', |
---|
| 558 | 'value' => $context, |
---|
| 559 | 'sub_branch' => false |
---|
| 560 | ); |
---|
| 561 | } |
---|
| 562 | else |
---|
| 563 | { |
---|
[284] | 564 | $tree['name'] = $this->translate_accentuation($dn_parts[0]); |
---|
[2] | 565 | $tree['type'] = 'catalog_group'; |
---|
| 566 | $tree['class'] = 'bo_catalog_group_catalog'; |
---|
[284] | 567 | // Pass the variable $external as a parameter to the constructor |
---|
| 568 | $tree['class_args'] = array('$this', '$this->get_branch_by_level($this->catalog_level[0])', $external); |
---|
[2] | 569 | $tree['value'] = $context; |
---|
| 570 | $tree['ldap'] = array('id_source' => $id_source, 'context' => $context); |
---|
| 571 | } |
---|
[285] | 572 | |
---|
[2] | 573 | usort($tree['sub_branch'], array($this, "compareTreeNodes")); |
---|
| 574 | return $tree; |
---|
| 575 | } |
---|
| 576 | |
---|
| 577 | function compareTreeNodes($a, $b) { |
---|
[285] | 578 | |
---|
[2] | 579 | return strnatcasecmp($a['name'], $b['name']); |
---|
[285] | 580 | } |
---|
[2] | 581 | |
---|
| 582 | } |
---|
| 583 | ?> |
---|