Changeset 387
- Timestamp:
- 08/06/08 18:05:35 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/inc/class.ldap_functions.inc.php
r381 r387 1 <?php 1 <?php 2 2 include_once("class.imap_functions.inc.php"); 3 3 include_once("class.functions.inc.php"); … … 7 7 @ldap_bind($ldap_connection, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']); 8 8 } 9 9 10 10 class ldap_functions 11 11 { … … 21 21 @include("../contactcenter/setup/external_catalogs.inc.php"); 22 22 $this->external_srcs= $external_srcs; 23 $this->max_result = 200; 24 $this->functions = new functions(); 25 } 23 $this->max_result = 200; 24 $this->functions = new functions(); 25 } 26 26 // Using ContactCenter configuration. 27 27 function ldapConnect($refer = false,$catalog = 0){ … … 39 39 $this->bind_dn = $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc']; 40 40 $this->bind_dn_pw = $_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']; 41 $this->branch = 'ou'; 42 } 43 41 $this->branch = 'ou'; 42 } 43 44 44 $this->ds = ldap_connect($this->ldap_host); 45 45 ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3); … … 48 48 ldap_set_rebind_proc($this->ds, ldapRebind); 49 49 } 50 @ldap_bind($this->ds,$this->bind_dn,$this->bind_dn_pw ); 50 @ldap_bind($this->ds,$this->bind_dn,$this->bind_dn_pw ); 51 51 } 52 52 … … 54 54 function ldapConnect2($refer = false){ 55 55 $ds = ldap_connect($_SESSION['phpgw_info']['expressomail']['ldap_server']['host']); 56 56 57 57 if (!$ds) 58 58 return false; 59 59 60 60 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); 61 61 ldap_set_option($ds, LDAP_OPT_REFERRALS, $refer); … … 63 63 ldap_set_rebind_proc($ds, ldapRebind); 64 64 @ldap_bind($ds, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']); 65 66 return $ds; 65 66 return $ds; 67 67 } 68 68 … … 75 75 ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3); 76 76 ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $refer); 77 ldap_bind($this->ds, $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'],$_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']); 77 ldap_bind($this->ds, $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'],$_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']); 78 78 79 79 } 80 80 81 81 function quicksearch($params) 82 { 82 { 83 83 include_once("class.functions.inc.php"); 84 $functions = new functions; 84 $functions = new functions; 85 85 86 86 $search_for = utf8_encode($params['search_for']); 87 87 $field = $params['field']; 88 88 $ID = $params['ID']; 89 89 90 90 $search_for = explode(" ",$search_for); 91 91 $aux=""; … … 105 105 $contacts_result['field'] = $field; 106 106 $contacts_result['ID'] = $ID; 107 107 108 108 // follow the referral 109 109 $this->ldapConnect(true); 110 110 111 111 if ($this->ds) 112 112 { … … 126 126 $count_entries = ldap_count_entries($this->ds,$sr); 127 127 128 // Get user org dn. 128 // Get user org dn. 129 129 $user_dn = $_SESSION['phpgw_info']['expressomail']['user']['account_dn']; 130 130 $user_sector_dn = ldap_explode_dn ( $user_dn, false ); … … 132 132 array_shift($user_sector_dn); 133 133 $user_sector_dn = implode(",", $user_sector_dn); 134 134 135 135 // New search only on user sector 136 136 if ($count_entries > $this->max_result) … … 138 138 // Close old ldap conection 139 139 ldap_close($this->ds); 140 140 141 141 // Reopen a local ldap connection, following referral 142 142 $this->ldapRootConnect(true); 143 143 144 144 $sr= ldap_search($this->ds, $user_sector_dn, $filter, $justthese); 145 145 if(!$sr) 146 146 return null; 147 147 $count_entries = ldap_count_entries($this->ds,$sr); 148 148 149 149 if ($count_entries > $this->max_result){ 150 150 $return = array(); 151 151 $return['status'] = false; 152 $return['error'] = "many results"; 152 $return['error'] = "many results"; 153 153 return $return; 154 154 } … … 158 158 } 159 159 } 160 160 161 161 $info = ldap_get_entries($this->ds, $sr); 162 162 163 163 $tmp = array(); 164 164 $tmp_users_from_user_org = array(); 165 165 166 166 if (!$quickSearch_only_in_userSector) { 167 167 $catalogsNum=count($this->external_srcs); … … 176 176 $count_entries = ldap_count_entries($this->ds,$sr); 177 177 $search = ldap_get_entries($this->ds, $sr); 178 for ($ i=0; $i<$search["count"]; $i++) {179 $info[] = $search[$ i];178 for ($j=0; $j<$search["count"]; $j++) { 179 $info[] = $search[$j]; 180 180 } 181 181 $info["count"] = count($info)-1; … … 204 204 natcasesort($tmp_users_from_user_org); 205 205 natcasesort($tmp); 206 206 207 207 if (($field != 'null') && ($ID != 'null')) 208 208 { 209 209 $i = 0; 210 210 211 211 $tmp = array_merge($tmp, $tmp_users_from_user_org); 212 212 natcasesort($tmp); 213 213 214 214 foreach ($tmp as $info => $cn) 215 215 { … … 242 242 $i++; 243 243 } 244 244 245 245 if ($quickSearch_only_in_userSector) 246 246 { … … 293 293 { 294 294 include_once("class.functions.inc.php"); 295 $functions = new functions; 296 295 $functions = new functions; 296 297 297 $contacts_result = array(); 298 298 $contacts_result["cn"] = $cn; 299 299 list ($contacts_result["mail"], $contacts_result["phone"], $contacts_result["mobile"], $contacts_result["uid"], $contacts_result["jpegphoto"]) = split ('%', $info); 300 300 301 301 if ($contacts_result['jpegphoto']) 302 302 $photo_link = '<img src="./inc/show_user_photo.php?mail='.$contacts_result['mail'].'">'; 303 303 else 304 304 $photo_link = '<img src="./templates/default/images/photo.png">'; 305 305 306 306 $phoneUser = $contacts_result['phone']; 307 307 308 308 if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['voip_enabled'] && $phoneUser) { 309 309 $phoneUser = '<a title="'.$this->functions->getLang("Call to Comercial Number").'" href="#" onclick="InfoContact.connectVoip(\''.$phoneUser.'\',\'com\')">'.$phoneUser.'</a>'; … … 332 332 } 333 333 334 function get_catalogs(){ 334 function get_catalogs(){ 335 335 $catalogs = array(); 336 $catalogs[0] = $this->functions->getLang("Global Catalog"); 337 if($this->external_srcs) 336 $catalogs[0] = $this->functions->getLang("Global Catalog"); 337 if($this->external_srcs) 338 338 foreach ($this->external_srcs as $key => $valor ){ 339 339 $catalogs[$key] = $valor['name']; … … 353 353 $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese); 354 354 $info = ldap_get_entries($this->ds, $sr); 355 355 356 356 for ($i=0; $i<$info["count"]; $i++) 357 357 $organizations[$i] = $info[$i]["ou"][0]; 358 358 359 359 ldap_close($this->ds); 360 sort($organizations); 360 sort($organizations); 361 361 return $organizations; 362 362 }else{ … … 369 369 $this->ldapRootConnect($referral); 370 370 if ($this->ds) { 371 $filter="ou=*"; 371 $filter="ou=*"; 372 372 $justthese = array("ou"); 373 373 $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese); 374 374 $info = ldap_get_entries($this->ds, $sr); 375 375 376 376 for ($i=0; $i<$info["count"]; $i++) 377 377 { … … 379 379 $organizations[$i]['dn'] = $info[$i]["dn"]; 380 380 } 381 381 382 382 ldap_close($this->ds); 383 sort($organizations); 383 sort($organizations); 384 384 } 385 385 return $organizations; … … 387 387 388 388 function catalogsearch($params) 389 { 389 { 390 390 $cn = $params['search_for'] ? "*".utf8_encode($params['search_for'])."*" : "*"; 391 $max_result = $params['max_result'] ? $params['max_result'] : $this->max_result; 391 $max_result = $params['max_result'] ? $params['max_result'] : $this->max_result; 392 392 $catalog = $params['catalog']; 393 393 $error = False; 394 394 395 395 $this->ldapConnect(true,$catalog); 396 397 $params['organization'] == 'all' ? $user_context = $this->ldap_context :$user_context = $this->branch."=".$params['organization'].",".$this->ldap_context; 398 399 if ($this->ds) { 396 397 $params['organization'] == 'all' ? $user_context = $this->ldap_context :$user_context = $this->branch."=".$params['organization'].",".$this->ldap_context; 398 399 if ($this->ds) { 400 400 if ($catalog == 0){ 401 401 //os atributos "employeeNumber" e "ou" foram adicionado ao vetor de busca; … … 409 409 //$user_context = $this->branch."=".$params['organization'].",".$external_srcs[$catalog]['dn']; 410 410 } 411 411 412 412 $sr=@ldap_search($this->ds, $user_context, $filter, $justthese, 0, $max_result+1); 413 413 if(!$sr) … … 416 416 if ($count_entries > $max_result){ 417 417 $info = null; 418 $error = True; 418 $error = True; 419 419 } 420 420 else 421 $info = ldap_get_entries($this->ds, $sr); 422 423 ldap_close($this->ds); 424 421 $info = ldap_get_entries($this->ds, $sr); 422 423 ldap_close($this->ds); 424 425 425 $u_tmp = array(); 426 426 $g_tmp = array(); 427 427 428 428 for ($i=0; $i<$info["count"]; $i++){ 429 429 if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'U') && ($info[$i]["phpgwaccountvisible"][0] != '-1')) 430 430 //aqui eh feita a concatenacao do departamento ao cn; 431 431 $u_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]). '%' . $info[$i]["ou"][0]; 432 if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'L') && ($info[$i]["phpgwaccountvisible"][0] != '-1')) 432 if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'L') && ($info[$i]["phpgwaccountvisible"][0] != '-1')) 433 433 $g_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]); 434 } 435 434 } 435 436 436 natcasesort($u_tmp); 437 437 natcasesort($g_tmp); 438 438 439 439 $i = 0; 440 $users = array(); 441 442 foreach ($u_tmp as $mail => $cn){ 440 $users = array(); 441 442 foreach ($u_tmp as $mail => $cn){ 443 443 444 444 $tmp = explode("%", $cn); //explode o cn pelo caracter "%" e joga em $tmp; … … 449 449 } 450 450 unset($u_tmp); 451 452 $i = 0; 451 452 $i = 0; 453 453 $groups = array(); 454 455 foreach ($g_tmp as $mail => $cn){ 454 455 foreach ($g_tmp as $mail => $cn){ 456 456 $groups[$i++] = array("name" => $cn, "email" => $mail); 457 457 } 458 458 unset($g_tmp); 459 459 460 460 return array('users' => $users, 'groups' => $groups, 'error' => $error); 461 }else 461 }else 462 462 return null; 463 463 } 464 464 465 465 function get_emails_ldap(){ 466 466 467 467 $result['mail']= array(); 468 $result['mailalter']= array(); 468 $result['mailalter']= array(); 469 469 $user = $_SESSION['phpgw_info']['expressomail']['user']['account_lid']; 470 470 $this->ldapRootConnect(false); 471 471 if ($this->ds) { 472 $filter="uid=".$user; 472 $filter="uid=".$user; 473 473 $justthese = array("mail","mailAlternateAddress"); 474 474 $sr = ldap_search($this->ds,$this->ldap_context, $filter, $justthese); 475 475 $ent = ldap_get_entries($this->ds, $sr); 476 476 ldap_close($this->ds); 477 477 478 478 for ($i=0; $i<$ent["count"]; $i++){ 479 479 $result['mail'][] = $ent[$i]["mail"][0]; 480 $result['mailalter'][] = $ent[$i]["mailalternateaddress"][0]; 480 $result['mailalter'][] = $ent[$i]["mailalternateaddress"][0]; 481 481 } 482 482 } 483 483 return $result; 484 484 } 485 485 486 486 //Busca usuarios de um contexto e ja retorna as options do select; 487 487 function get_available_users($params) … … 503 503 $info = ldap_get_entries($this->ds, $sr); 504 504 for ($i=0; $i<$info["count"]; $i++) 505 $groups[$uids=$info[$i]["gidnumber"][0]] = Array('name' => $uids=$info[$i]["cn"][0], 'type' => g); 505 $groups[$uids=$info[$i]["gidnumber"][0]] = Array('name' => $uids=$info[$i]["cn"][0], 'type' => g); 506 506 $justthese = array("phpgwaccountvisible","uidNumber","cn"); 507 507 if ($params['type'] == 'search') … … 519 519 } 520 520 ldap_close($this->ds); 521 521 522 522 @asort($users); 523 @reset($users); 523 @reset($users); 524 524 @asort($groups); 525 525 @reset($groups); … … 544 544 { 545 545 $this->ldapRootConnect(); 546 546 547 547 $context= $params['context']; 548 548 $justthese = array("cn", "uid", "cn"); 549 549 $filter = "(&(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))"; 550 550 551 if ($this->ds) 551 if ($this->ds) 552 552 { 553 553 $sr=ldap_search($this->ds, $context, $filter, $justthese); 554 554 $entries = ldap_get_entries($this->ds, $sr); 555 555 556 556 for ($i=0; $i<$entries["count"]; $i++){ 557 557 if($_SESSION['phpgw_info']['expressomail']['user']['account_lid'] != $entries[$i]["uid"][0]){ … … 559 559 } 560 560 } 561 561 562 562 natcasesort($u_tmp); 563 563 564 564 $i = 0; 565 565 $users = array(); 566 566 567 567 if (count($u_tmp)) 568 568 { … … 578 578 } 579 579 } 580 580 581 581 function uid2cn($uid) 582 { 582 { 583 583 // do not follow the referral 584 584 $this->ldapRootConnect(false); 585 585 if ($this->ds) 586 586 { 587 $filter="(&(phpgwAccountType=u)(uid=$uid))"; 587 $filter="(&(phpgwAccountType=u)(uid=$uid))"; 588 588 $justthese = array("cn"); 589 589 $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); … … 595 595 return false; 596 596 } 597 function getSharedUsersFrom($params){ 597 function getSharedUsersFrom($params){ 598 598 $filter = ''; 599 599 $i = 0; 600 600 if($params['uids']) { 601 $uids = explode(";",$params['uids']); 602 $this->imap = new imap_functions(); 601 $uids = explode(";",$params['uids']); 602 $this->imap = new imap_functions(); 603 603 foreach($uids as $index => $uid){ 604 $params = array(); 604 $params = array(); 605 605 $acl = $this->imap->getacltouser($uid); 606 606 if(preg_match("/a/",$acl)) … … 608 608 } 609 609 } 610 611 $this->ldapRootConnect(false); 610 611 $this->ldapRootConnect(false); 612 612 if ($this->ds) { 613 613 $justthese = array("cn","mail"); … … 615 615 $filter="(&(phpgwAccountType=u)(|$filter))"; 616 616 $sr = ldap_search($this->ds, $this->ldap_context, $filter, $justthese); 617 ldap_sort($this->ds,$sr,"cn"); 618 $info = ldap_get_entries($this->ds, $sr); 617 ldap_sort($this->ds,$sr,"cn"); 618 $info = ldap_get_entries($this->ds, $sr); 619 619 for ($i = 0;$i < $info["count"]; $i++) 620 620 $info[$i]['cn'][0] = utf8_decode($info[$i]['cn'][0]); 621 621 } 622 622 $info['myname'] = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 623 623 624 624 //Find institucional_account. 625 625 $filter="(&(phpgwAccountType=i)(mailForwardingAddress=".$_SESSION['phpgw_info']['expressomail']['user']['email']."))"; 626 $sr = ldap_search($this->ds, $this->ldap_context, $filter, $justthese); 626 $sr = ldap_search($this->ds, $this->ldap_context, $filter, $justthese); 627 627 if(!ldap_count_entries($this->ds,$sr)) 628 628 return $info; … … 646 646 $ds = $this->ldapConnect2(true); 647 647 if ($ds) 648 { 648 { 649 649 $sr=@ldap_search($ds, $ldap_context, $filter, $justthese); 650 650 651 651 if (!$sr) 652 652 return null; 653 653 654 654 $entry = ldap_first_entry($ds, $sr); 655 656 if($entry) { 655 656 if($entry) { 657 657 $obj = array("cn" => utf8_decode(current(ldap_get_values($ds, $entry, "cn"))), 658 658 "email" => $params['email'],
Note: See TracChangeset
for help on using the changeset viewer.