ldap_host = $_SESSION['phpgw_info']['expressomail']['ldap_server']['host'];
$this->ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn'];
$this->ds = ldap_connect($this->ldap_host);
ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $refer);
if ($refer)
{
ldap_set_rebind_proc($this->ds, ldapRebind);
}
@ldap_bind($this->ds, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']);
}
//Teste jakjr retornando o DS
function ldapConnect2($refer = false){
$ds = ldap_connect($_SESSION['phpgw_info']['expressomail']['ldap_server']['host']);
if (!$ds)
return false;
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, $refer);
if ($refer)
ldap_set_rebind_proc($ds, ldapRebind);
@ldap_bind($ds, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']);
return $ds;
}
// usa o host e context do setup.
function ldapRootConnect($refer = false){
$this->ldap_host = $_SESSION['phpgw_info']['expressomail']['server']['ldap_host'];
$this->ldap_context = $_SESSION['phpgw_info']['expressomail']['server']['ldap_context'];
$this->ds = ldap_connect($this->ldap_host);
ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $refer);
ldap_bind($this->ds, $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'],$_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']);
}
function quicksearch($params)
{
include_once("class.functions.inc.php");
$functions = new functions;
$search_for = $params['search_for'];
$field = $params['field'];
$ID = $params['ID'];
$contacts_result = array();
$contacts_result['field'] = $field;
$contacts_result['ID'] = $ID;
// follow the referral
$this->ldapConnect(true);
if ($this->ds)
{
if (($field != 'null') && ($ID != 'null'))
{
$filter="(& (|(phpgwAccountType=u)(phpgwAccountType=l)) (|(cn=*$search_for*)(mail=$search_for*)) (!(phpgwaccountvisible=-1)) )";
$justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid");
}
else
{
$filter="(& (phpgwAccountType=u)(cn=*$search_for*) (!(phpgwaccountvisible=-1)) )";
$justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "jpegPhoto", "uid");
}
$sr=ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
$count_entries = ldap_count_entries($this->ds,$sr);
// Get user org dn.
$user_dn = $_SESSION['phpgw_info']['expressomail']['user']['account_dn'];
$user_sector_dn = ldap_explode_dn ( $user_dn, false );
array_shift($user_sector_dn);
array_shift($user_sector_dn);
$user_sector_dn = implode(",", $user_sector_dn);
// New search only on user sector
if ($count_entries > 200)
{
// Close old ldap conection
ldap_close($this->ds);
// Reopen a local ldap connection, following referral
$this->ldapRootConnect(true);
$sr=ldap_search($this->ds, $user_sector_dn, $filter, $justthese);
$count_entries = ldap_count_entries($this->ds,$sr);
if ($count_entries > 200){
$return = array();
$return['status'] = false;
$return['error'] = "many results";
return $return;
}
else
{
$quickSearch_only_in_userSector = true;
}
}
$info = ldap_get_entries($this->ds, $sr);
$tmp = array();
$tmp_users_from_user_org = array();
for ($i=0; $i<$info["count"]; $i++)
{
// Usuario sempre serao da minha org.
if ($quickSearch_only_in_userSector)
{
$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];
}
else
{
if (preg_match("/$user_sector_dn/i", $info[$i]['dn']))
{
$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];
}
else
{
$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];
}
}
}
natcasesort($tmp_users_from_user_org);
natcasesort($tmp);
if (($field != 'null') && ($ID != 'null'))
{
$i = 0;
$tmp = array_merge($tmp, $tmp_users_from_user_org);
natcasesort($tmp);
foreach ($tmp as $info => $cn)
{
$contacts_result[$i] = array();
$contacts_result[$i]["cn"] = $cn;
list ($contacts_result[$i]["mail"], $contacts_result[$i]["phone"], $contacts_result[$i]["mobile"]) = split ('%', $info);
$i++;
}
$contacts_result['quickSearch_only_in_userSector'] = $quickSearch_only_in_userSector;
}
else
{
$options_users_from_user_org = '';
$options = '';
/* List of users from user org */
$i = 0;
foreach ($tmp_users_from_user_org as $info => $cn)
{
$contacts_result[$i] = array();
$options_users_from_user_org .= $this->make_quicksearch_card($info, $cn);
$i++;
}
/* List of users from others org */
foreach ($tmp as $info => $cn)
{
$contacts_result[$i] = array();
$options .= $this->make_quicksearch_card($info, $cn);
$i++;
}
if ($quickSearch_only_in_userSector)
{
if ($options != '')
{
$head_option =
'
' .
'
' .
$functions->getLang('More than 200 results were found') . '. ' .
$functions->getLang('Showing only the results found in your organization') . '.';
'