Changeset 285 for trunk/contactcenter/inc/class.bo_ldap_manager.inc.php
- Timestamp:
- 05/23/08 17:10:39 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/contactcenter/inc/class.bo_ldap_manager.inc.php
r284 r285 12 12 \***************************************************************************/ 13 13 14 14 15 15 /* 16 16 This class is responsible for the LDAP control/generic functions and for … … 19 19 include_once('class.Thread.inc.php'); 20 20 21 class bo_ldap_manager 21 class bo_ldap_manager 22 22 { 23 23 24 24 var $srcs; 25 25 26 26 27 function bo_ldap_manager () 27 28 { 28 29 29 if (!($this->srcs = $GLOBALS['phpgw']->session->appsession('bo_ldap_manager.srcs','contactcenter'))) 30 30 { 31 31 $c = CreateObject('phpgwapi.config','contactcenter'); 32 32 $data = $c->read_repository(); 33 33 34 34 if (!$data or $data['cc_global_source0'] !== 'ldap') 35 35 { … … 37 37 return; 38 38 } 39 39 40 40 $this->srcs = array( 41 41 1 => array( … … 46 46 'pw' => $data['cc_ldap_pw0'], 47 47 'obj' => 'inetOrgPerson', 48 'branch' => strtolower('ou') 48 'branch' => strtolower('ou'), 49 'visible' => $data['cc_ldap_query_automatic'] 49 50 ) 50 51 51 ); 52 52 } … … 56 56 { 57 57 } 58 58 59 59 /* 60 60 61 61 @function get_all_ldap_sources 62 62 @abstract Returns an array containing all LDAP sources informations 63 63 @author Raphael Derosso Pereira 64 64 65 65 @return array All LDAP information 66 66 $return = array( … … 69 69 'dn' => (string), 70 70 'acc' => (string), 71 'pw' => (string) 71 'pw' => (string) 72 72 ), 73 73 ... 74 74 ) 75 75 76 76 TODO: Return multiple sources... 77 77 */ … … 80 80 return $this->srcs; 81 81 } 82 82 83 83 /* 84 84 * @function get_external_ldap_sources … … 102 102 function get_ldap_fields_association ( $id_source ) 103 103 { 104 104 105 105 $op_iop = array( 106 106 'contact.id_contact' => array('dn'), … … 111 111 'contact.family_names' => array('sn'), 112 112 'contact.names_ordered' => array('cn'),//,'displayName'), 113 114 113 'contact.suffixes.suffix' => false, 115 114 'contact.birthdate' => false, … … 117 116 'contact.pgp_key' => false, 118 117 'contact.notes' => false, 119 'contact.mail_forwarding_address' 120 'contact.account_type' 121 122 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'), 123 122 'contact.object_class' => array('objectClass'), 124 123 'contact.business_info.title' => array('title'), 125 'contact.business_info.department' => array('ou'), // Setor do empregado... 126 'contact.business_info.empNumber' => array('employeeNumber'), // Matricula do empregado 124 'contact.business_info.department' => array('ou'), 127 125 'contact.company.company_name' => array('o'), 128 126 'contact.company.company_notes' => array('businessCategory'), 129 127 130 128 'contact.contact_related.names_ordered' => 'contact.contact_related.typeof_relation.contact_relation_name', 131 129 'contact.contact_related.typeof_relation.contact_relation_name' => array( … … 133 131 'secretary' => array('secretary') 134 132 ), 135 133 136 134 'contact.address.address1' => 'contact.address.typeof_address.contact_address_type_name', 137 135 'contact.address.typeof_address.contact_address_type_name' => array( 138 136 'home' => array('street', 'st', 'postalAddress', 'homePostalAddress'), 139 137 ), 140 138 141 139 'contact.address.postal_code' => 'contact.address.typeof_address.contact_address_type_name', 142 140 'contact.address.typeof_address.contact_address_type_name' => array( 143 141 'home' => array('PostalCode'), 144 142 ), 145 143 146 144 'contact.address.city.city_name' => 'contact.address.typeof_address.contact_address_type_name', 147 145 'contact.address.typeof_address.contact_address_type_name' => array( 148 146 'home' => array('l'), 149 147 ), 150 148 151 149 'contact.address.city.state.state_name' => 'contact.address.typeof_address.contact_address_type_name', 152 150 'contact.address.typeof_address.contact_address_type_name' => array( 153 151 'home' => false, 154 152 ), 155 153 156 154 'contact.address.city.country.id_country' => 'contact.address.typeof_address.contact_address_type_name', 157 155 'contact.address.typeof_address.contact_address_type_name' => array( 158 156 'home' => array('c') 159 157 ), 160 158 161 159 'contact.connection.connection_value' => 'contact.connection.typeof_connection.contact_connection_type_name', 162 160 'contact.connection.typeof_connection.contact_connection_type_name' => array ( … … 169 167 ), 170 168 ); 171 169 172 170 return $op_iop; 173 174 171 } 175 172 … … 232 229 233 230 /*! 234 231 235 232 @function get_ldap_tree 236 233 @abstract Returns the LDAP tree corresponding to the specified level 237 234 @author Raphael Derosso Pereira 238 235 239 236 @param (integer) $id_source The ID of the LDAP source 240 237 241 238 @param (string) $context The context to be used as root branch 242 239 243 240 @param (boolean) $recursive Make it a recursive construction. 244 241 CAUTION! This is EXTREMELY SLOW on large LDAP databases, 245 242 specially when they're not indexed 246 */ 247 function get_ldap_tree($id_source, $context = false, $recursive = false) 243 */ 244 function get_ldap_tree($id_source, $context = false, $recursive = false) 248 245 { 249 246 if (!$this->srcs[$id_source]) … … 251 248 return null; 252 249 } 253 250 254 251 $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->srcs[$id_source]['host'], $this->srcs[$id_source]['acc'],$this->srcs[$id_source]['pw'], false); 255 252 if (!$ldap) … … 257 254 return false; 258 255 } 259 256 260 257 if ($recursive) 261 258 { … … 265 262 return $tree; 266 263 } 267 268 return $this->get_ldap_tree_level($id_source, $ldap, $context, $this->srcs[$id_source]['obj'],$this->srcs[$id_source]['branch'], 0); 269 } 264 265 return $this->get_ldap_tree_level($id_source, $ldap, $context, $this->srcs[$id_source]['obj'],$this->srcs[$id_source]['branch']); 266 } 267 // SERPRO 270 268 271 269 /*! … … 336 334 return null; 337 335 } 338 336 339 337 $count = ldap_count_entries($resource,$result_res); 340 338 if ( $count == 0 ) … … 353 351 } 354 352 } 355 353 356 354 $entries = ldap_get_entries($resource, $result_res); 357 355 358 356 for ($i = 0; $i < $entries['count']; $i++) 359 357 { 360 358 $subtree = $this->get_ldap_tree_recursive($resource, $entries[$i]['dn'], $objectClass); 361 359 362 360 $dn_parts=ldap_explode_dn($entries[$i]['dn'],1); 363 364 365 366 if ($subtree !== null and is_array($subtree)) 361 362 if ($subtree !== null and is_array($subtree)) 367 363 { 368 364 $tree[$i]['name'] = $dn_parts[0]; … … 381 377 'sub_branch' => false 382 378 ); 383 } 379 } 384 380 } 385 381 … … 393 389 } 394 390 } 395 391 396 392 function get_ldap_referrals($ds, $dn, $filter) { 397 393 398 394 ldap_set_option($ds, LDAP_OPT_REFERRALS, 0); 399 395 ldap_set_option($ds,LDAP_OPT_PROTOCOL_VERSION,3); 400 396 401 397 if ($ds) { 402 398 ldap_bind($ds); 403 $sr=ldap_list($ds,$dn, $filter); 399 $sr=ldap_list($ds,$dn, $filter); 404 400 $ref = ldap_first_reference($ds, $sr); 405 401 $array_referral = array(); 406 402 $idx = 0; 407 403 408 404 while ($ref) { 409 405 $array_referral[$idx++] = ldap_get_dn($ds, $ref); … … 412 408 return $array_referral; 413 409 } 414 else 410 else 415 411 return false; 416 412 } 417 413 418 414 function get_ldap_sub_branches_referrals($ds, $dn, $filter) { 419 415 420 416 $referral = $this -> get_ldap_referrals($ds, $dn, $filter); 421 417 $sub_branches = array(); 422 418 423 419 for($i = 0; $i <count($referral); $i++) { 424 420 $dn = str_replace("??base","",preg_replace('!^(ldap://[^/]+)/(.*$)!', '\\2', $referral[$i])); 425 $dn = explode(",",$dn); 421 $dn = explode(",",$dn); 426 422 $dn = strtoupper(str_replace("ou=", "",$dn[0])); 427 423 $dn = str_replace("DC=", "",$dn); 428 424 429 425 $sub_branch = array( 430 426 'name' => $dn, 431 427 'type' => 'unknown', 432 428 'value' => $referral[$i], 433 'sub_branch' => false 434 ); 435 $sub_branches[$i] = $sub_branch; 429 'sub_branch' => false 430 ); 431 $sub_branches[$i] = $sub_branch; 436 432 } 437 433 return $sub_branches; 438 434 } 435 439 436 440 437 function translate_accentuation($text) … … 464 461 //$filter = '(!(objectClass='.$objectClass.'))'; 465 462 // Don't show OU's whith phpgwAccountVisible equal to '-1' 466 467 463 if ($external) 468 464 { … … 483 479 if ($result_res === false) 484 480 { 485 if (ldap_errno($resource) === 3)486 {487 return array('error_msg' => ldap_error($resource));488 }489 481 return null; 490 482 } … … 591 583 $tree['ldap'] = array('id_source' => $id_source, 'context' => $context); 592 584 } 585 593 586 usort($tree['sub_branch'], array($this, "compareTreeNodes")); 594 587 return $tree; … … 596 589 597 590 function compareTreeNodes($a, $b) { 598 591 599 592 return strnatcasecmp($a['name'], $b['name']); 600 } 593 } 601 594 602 595 }
Note: See TracChangeset
for help on using the changeset viewer.