Changeset 325 for trunk/expressoMail1_2/inc/class.ldap_functions.inc.php
- Timestamp:
- 06/24/08 16:45:40 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/inc/class.ldap_functions.inc.php
r320 r325 15 15 16 16 // usa o host e context do contact center. 17 function ldapConnect($refer = false){ 18 $this->ldap_host = $_SESSION['phpgw_info']['expressomail']['ldap_server']['host']; 19 $this->ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; 20 $this->ds = ldap_connect($this->ldap_host); 17 function ldapConnect($refer = false,$catalogo = 0){ 18 include("../contactcenter/setup/external_catalogs.inc.php"); 19 if ($catalogo == 0){ 20 $this->ldap_host = $_SESSION['phpgw_info']['expressomail']['ldap_server']['host']; 21 $this->ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; 22 $this->bind_dn = $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc']; 23 $this->bind_dn_pw = $_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']; 24 $this->branch = 'ou'; 25 }else { 26 27 $this->ldap_host = $external_srcs[$catalogo]['host']; 28 $this->ldap_context = $external_srcs[$catalogo]['dn']; 29 $this->bind_dn = $external_srcs[$catalogo]['acc']; 30 $this->bind_dn_pw = $external_srcs[$catalogo]['pw']; 31 $this->object_class = $external_srcs[$catalogo]['obj']; 32 $this->base_dn = $external_srcs[$catalogo]['dn']; 33 $this->branch = $external_srcs[$catalogo]['branch']; 34 35 } 36 $this->ds = ldap_connect($this->ldap_host); 21 37 ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3); 22 38 ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $refer); 23 if ($refer) 24 { 39 if ($refer){ 25 40 ldap_set_rebind_proc($this->ds, ldapRebind); 26 41 } 27 @ldap_bind($this->ds, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']); 42 @ldap_bind($this->ds,$this->bind_dn,$this->bind_dn_pw ); 43 28 44 } 29 45 … … 58 74 function quicksearch($params) 59 75 { 76 include_once("../contactcenter/setup/external_catalogs.inc.php"); 60 77 include_once("class.functions.inc.php"); 61 78 $functions = new functions; 62 79 63 $search_for = $params['search_for'];80 $search_for = utf8_encode($params['search_for']); 64 81 $field = $params['field']; 65 82 $ID = $params['ID']; 66 83 84 $search_for = explode(" ",$search_for); 85 $aux=""; 86 foreach ($search_for as $search) 87 { 88 if(!$aux) 89 { 90 $aux=$search; 91 } 92 else 93 { 94 $aux=$aux."*".$search; 95 } 96 } 97 $search_for=$aux; 67 98 $contacts_result = array(); 68 99 $contacts_result['field'] = $field; … … 73 104 74 105 if ($this->ds) 75 {106 { 76 107 if (($field != 'null') && ($ID != 'null')) 77 {78 $filter="(& (|(phpgwAccountType=u)(phpgwAccountType=l)) (|(cn=*$search_for*)(mail= $search_for*)) (!(phpgwaccountvisible=-1)) )";79 $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid" );80 }108 { 109 $filter="(& (|(phpgwAccountType=u)(phpgwAccountType=l)) (|(cn=*$search_for*)(mail=*$search_for*)) (!(phpgwaccountvisible=-1)) )"; 110 $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid", "employeeNumber", "ou"); 111 } 81 112 else 82 {113 { 83 114 $filter="(& (phpgwAccountType=u)(cn=*$search_for*) (!(phpgwaccountvisible=-1)) )"; 84 $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "jpegPhoto", "uid"); 85 } 86 87 $sr=ldap_search($this->ds, $this->ldap_context, $filter, $justthese); 115 $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "jpegPhoto", "uid", "employeeNumber", "ou"); 116 } 117 $sr=ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, 201); 88 118 $count_entries = ldap_count_entries($this->ds,$sr); 89 119 90 120 // Get user org dn. 91 121 $user_dn = $_SESSION['phpgw_info']['expressomail']['user']['account_dn']; … … 104 134 $this->ldapRootConnect(true); 105 135 106 $sr=ldap_search($this->ds, $user_sector_dn, $filter, $justthese );136 $sr=ldap_search($this->ds, $user_sector_dn, $filter, $justthese, 0, 201); 107 137 $count_entries = ldap_count_entries($this->ds,$sr); 108 138 … … 123 153 $tmp = array(); 124 154 $tmp_users_from_user_org = array(); 155 156 if (!$quickSearch_only_in_userSector) 157 { 158 $catalogsNum=count($external_srcs); 159 for ($i=0; $i<=count($external_srcs); $i++) 160 { 161 if ($external_srcs[$i]["quicksearch"]) 162 { 163 $this->ldapConnect(true,$i); 164 $filter="(|(cn=*$search_for*)(mail=*$search_for*))"; 165 $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid", "employeeNumber", "ou"); 166 $sr=ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, 201); 167 $count_entries = ldap_count_entries($this->ds,$sr); 168 $search = ldap_get_entries($this->ds, $sr); 169 for ($i=0; $i<$search["count"]; $i++) 170 { 171 $info[] = $search[$i]; 172 } 173 $info["count"] = count($info)-1; 174 } 175 } 176 } 177 125 178 for ($i=0; $i<$info["count"]; $i++) 126 { 127 // Usuario sempre serao da minha org. 179 { 128 180 if ($quickSearch_only_in_userSector) 129 {130 $tmp[$info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' . $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count'] ] = $info[$i]["cn"][0];131 }181 { 182 $tmp[$info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' . $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count'] . '%' . $info[$i]["employeenumber"][0] . '%' . $info[$i]["ou"][0]] = utf8_decode($info[$i]["cn"][0]); 183 } 132 184 else 133 {185 { 134 186 if (preg_match("/$user_sector_dn/i", $info[$i]['dn'])) 135 { 136 $tmp_users_from_user_org[$info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' . $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count']] = $info[$i]["cn"][0]; 187 { 188 $tmp_users_from_user_org[$info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' . $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count'] . '%' . $info[$i]["employeenumber"][0] . '%' . $info[$i]["ou"][0]] = utf8_decode($info[$i]["cn"][0]); 189 } 190 else 191 { 192 $tmp[$info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' . $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count'] . '%' . $info[$i]["employeenumber"][0] . '%' . $info[$i]["ou"][0]] = utf8_decode($info[$i]["cn"][0]); 193 } 137 194 } 138 else 139 { 140 $tmp[$info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' . $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count']] = $info[$i]["cn"][0]; 141 } 142 } 143 } 195 } 144 196 natcasesort($tmp_users_from_user_org); 145 197 natcasesort($tmp); … … 156 208 $contacts_result[$i] = array(); 157 209 $contacts_result[$i]["cn"] = $cn; 158 list ($contacts_result[$i]["mail"], $contacts_result[$i]["phone"], $contacts_result[$i]["mobile"] ) = split ('%', $info);210 list ($contacts_result[$i]["mail"], $contacts_result[$i]["phone"], $contacts_result[$i]["mobile"], $contacts_result[$i]["uid"], $contacts_result[$i]["jpegphoto"], $contacts_result[$i]["employeenumber"], $contacts_result[$i]["ou"]) = split ('%', $info); 159 211 $i++; 160 212 } … … 272 324 } 273 325 326 function get_catalogs(){ 327 include("../contactcenter/setup/external_catalogs.inc.php"); 328 $catalogs = array(); 329 $catalogs[0] = "Catalogo geral"; 330 foreach ($external_srcs as $key => $valor ){ 331 $catalogs[$key] = $valor['name']; 332 } 333 return $catalogs; 334 } 274 335 function get_organizations($params){ 336 275 337 $organizations = array(); 276 $referral = $params['referral']; 277 $this->ldapConnect($referral); 278 if ($this->ds) { 279 $filter="ou=*"; 280 $justthese = array("ou"); 281 $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese); 282 $info = ldap_get_entries($this->ds, $sr); 283 284 for ($i=0; $i<$info["count"]; $i++) 285 $organizations[$i] = $info[$i]["ou"][0]; 286 287 ldap_close($this->ds); 288 sort($organizations); 289 } 290 return $organizations; 291 } 292 338 $params['referral']?$referral = $params['referral']:$referral = false; 339 $cat = $params['catalog']; 340 341 $this->ldapConnect($referral,$cat); 342 343 if($this->branch != '') { 344 $filter=$this->branch."=*"; 345 $justthese = array("$this->branch"); 346 $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese); 347 $info = ldap_get_entries($this->ds, $sr); 348 349 for ($i=0; $i<$info["count"]; $i++) 350 $organizations[$i] = $info[$i]["ou"][0]; 351 352 ldap_close($this->ds); 353 sort($organizations); 354 return $organizations; 355 }else{ 356 return null; 357 } 358 } 293 359 function get_organizations2($params){ 294 360 $organizations = array(); … … 315 381 function catalogsearch($params) 316 382 { 317 $this->ldapConnect(true); 318 $cn = $params['search_for'] ? "*".$params['search_for']."*" : "*"; 319 $user_context = "ou=".$params['organization'].",".$this->ldap_context; 320 $max_result = $params['max_result'] ? $params['max_result'] : '200'; 383 //$this->ldapConnect(true); 384 include("../contactcenter/inc/external_catalogs.inc.php"); 385 $cn = $params['search_for'] ? "*".utf8_encode($params['search_for'])."*" : "*"; 386 $max_result = $params['max_result'] ? $params['max_result'] : '200'; 387 $catalog = $params['catalog']; 321 388 $error = False; 389 390 $this->ldapConnect(false,$catalog); 391 392 $params['organization'] == 'todos'?$user_context = $this->ldap_context :$user_context = $this->branch."=".$params['organization'].",".$this->ldap_context; 322 393 323 394 if ($this->ds) { 324 $justthese = array("cn", "mail", "phpgwaccounttype", "phpgwAccountVisible"); 325 $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(cn=".$cn."))"; 326 $sr=ldap_search($this->ds, $user_context, $filter, $justthese); 327 395 if ($catalog == 0){ 396 //os atributos "employeeNumber" e "ou" foram adicionado ao vetor de busca; 397 $justthese = array("cn", "mail", "phpgwaccounttype", "phpgwAccountVisible", "employeeNumber", "ou"); 398 $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(cn=".$cn."))"; 399 //$user_context = "ou=".$params['organization'].",".$this->ldap_context; 400 }else { 401 //os atributos "employeeNumber" e "ou" foram adicionado ao vetor de busca; 402 $justthese = array("cn", "mail", "employeeNumber", "ou"); 403 $filter="(&(objectClass=".$this->object_class.")(cn=".$cn."))"; 404 //$user_context = $this->branch."=".$params['organization'].",".$external_srcs[$catalog]['dn']; 405 } 406 407 $sr=ldap_search($this->ds, $user_context, $filter, $justthese,0,200); 328 408 $count_entries = ldap_count_entries($this->ds,$sr); 329 409 if ($count_entries > $max_result){ … … 340 420 341 421 for ($i=0; $i<$info["count"]; $i++){ 342 if ($info[$i]["phpgwaccountvisible"][0] == '-1') 343 continue; 344 if((strtoupper($info[$i]["phpgwaccounttype"][0]) == 'U') && ($info[$i]["phpgwaccountvisible"][0] != '-1')) 345 $u_tmp[$info[$i]["mail"][0]] = $info[$i]["cn"][0]; 422 if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'U') && ($info[$i]["phpgwaccountvisible"][0] != '-1')) 423 //aqui eh feita a concatenacao do departamento ao cn; 424 $u_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]). '%' . $info[$i]["ou"][0]; 346 425 else 347 $g_tmp[$info[$i]["mail"][0]] = $info[$i]["cn"][0];426 $g_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]); 348 427 } 349 428 350 429 natcasesort($u_tmp); 351 430 natcasesort($g_tmp); 352 431 353 432 $i = 0; 354 $users = array(); 355 356 foreach ($u_tmp as $mail => $cn){ 357 $users[$i++] = array("name" => $cn, "email" => $mail); 358 } 433 $users = array(); 434 435 436 foreach ($u_tmp as $mail => $cn){ 437 438 $tmp = explode("%", $cn); //explode o cn pelo caracter "%" e joga em $tmp; 439 $name = $tmp[0]; //pega o primeiro item (cn) do vetor resultante do explode acima; 440 $department = $tmp[1]; //pega o segundo item (ou) do vetor resultanto do explode acima; 441 $users[$i++] = array("name" => $name, "email" => $mail, "department" => $department); 442 443 } 444 359 445 unset($u_tmp); 360 446 … … 368 454 369 455 return array('users' => $users, 'groups' => $groups, 'error' => $error); 370 } 456 }else 371 457 return null; 372 458 } … … 393 479 } 394 480 395 //Busca usu ários de um contexto e járetorna as options do select;481 //Busca usuï¿œrios de um contexto e jï¿œ retorna as options do select; 396 482 function get_available_users($params) 397 483 { 398 484 $this->ldapRootConnect(); 399 //Monta lista de Grupos e Usu ários485 //Monta lista de Grupos e Usuï¿œrios 400 486 $users = Array(); 401 487 $groups = Array(); … … 449 535 } 450 536 451 //Busca usu ários de um contexto e járetorna as options do select;537 //Busca usuï¿œrios de um contexto e jï¿œ retorna as options do select; 452 538 function get_available_users2($params) 453 539 { … … 499 585 500 586 $info = ldap_get_entries($this->ds, $sr); 501 return $info[0]["cn"][0];587 return utf8_decode($info[0]["cn"][0]); 502 588 } 503 589 return false; … … 524 610 $info = ldap_get_entries($this->ds, $sr); 525 611 $info['myname'] = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 612 for ($i = 0;$i < $info["count"]; $i++) 613 $info[$i]['cn'][0] = utf8_decode($info[$i]['cn'][0]); 526 614 return $info; 527 615 } … … 546 634 547 635 if($entry) { 548 $obj = array("cn" => ldap_get_values($ds, $entry, "cn"),636 $obj = array("cn" => utf8_decode(ldap_get_values($ds, $entry, "cn")), 549 637 "email" => $params['email'], 550 638 "uid" => ldap_get_values($ds, $entry, "uid"),
Note: See TracChangeset
for help on using the changeset viewer.