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