ldap_host = (isset($_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit'])) ? $_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit'] : $GLOBALS['phpgw_info']['server']['ldap_host'];
$this->ldap_context = (isset($_SESSION['phpgw_info']['jabberit_messenger']['context_ldap_jabberit'])) ? $_SESSION['phpgw_info']['jabberit_messenger']['context_ldap_jabberit'] : $GLOBALS['phpgw_info']['server']['ldap_context'];
$this->ldap_dn = (isset($_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit'])) ? $_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit'] : $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
$this->ldap_pass = (isset($_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit'])) ? $_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit'] : $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
$this->jid = $_SESSION['phpgw_info']['jabberit_messenger']['user'];
$this->max_result = 50;
}
public final function __destruct()
{
if( $this->ldap )
ldap_close($this->ldap);
}
private final function _connect_ldap()
{
$this->common = new common();
if( !$this->ldap )
{
$GLOBALS['phpgw_info']['server']['ldap_version3'] = true;
$this->ldap = $this->common->ldapConnect( $this->ldap_host,$this->ldap_dn,$this->ldap_pass, false );
}
}
private final function _ldapConnect($refer = false)
{
function ldapRebindJabberit($ldap_connection, $ldap_url)
{
$acc = $_SESSION['phpgw_info']['jabberit_messenger']['ldapManager']['acc'];
$pw = $_SESSION['phpgw_info']['jabberit_messenger']['ldapManager']['pw'];
@ldap_bind($ldap_connection, $acc,$pw);
}
// Using ContactCenter configuration.
$this->ldap_host = $_SESSION['phpgw_info']['jabberit_messenger']['ldapManager']['host'];
$this->ldap_context = $_SESSION['phpgw_info']['jabberit_messenger']['ldapManager']['dn'];
$this->ldap_dn = $_SESSION['phpgw_info']['jabberit_messenger']['ldapManager']['acc'];
$this->ldap_pass = $_SESSION['phpgw_info']['jabberit_messenger']['ldapManager']['pw'];
$this->ldap = ldap_connect($this->ldap_host);
ldap_set_option($this->ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($this->ldap, LDAP_OPT_REFERRALS, $refer);
if ($refer)
{
ldap_set_rebind_proc($this->ldap, ldapRebindJabberit);
}
@ldap_bind($this->ldap,$this->ldap_dn,$this->ldap_pass);
}
public final function list_groups_memberUid($pGroup)
{
$this->_ldapConnect();
if( $this->ldap )
{
$filter = "(&(objectclass=posixgroup)(|".$pGroup."))";
$justthese = array("dn","memberuid","gidnumber");
$search = ldap_search($this->ldap,$this->ldap_context,$filter, $justthese);
$result = ldap_get_entries($this->ldap,$search);
if( $result['count'] > 0 )
return $result;
}
return false;
}
public final function list_participants_externals($pSearch)
{
$this->_ldapConnect(true);
$mail = $pSearch['mail'];
if( $this->ldap )
{
$filter = "(&(phpgwaccounttype=u)(mail=".$mail."))";
$justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto");
$search = ldap_search($this->ldap,$this->ldap_context,$filter,$justthese, 0, $this->max_result + 1);
$entry1 = ldap_get_entries($this->ldap,$search);
$entry = ldap_first_entry( $this->ldap, $search );
}
if( $entry1['count'] > 0 )
{
$i = 0;
$result_user = array();
$result = array();
while($entry)
{
if ( $entry1[$i]['phpgwaccountvisible'][0] != '-1' )
{
$result['uidnumber'] = @ldap_get_values($this->ldap, $entry, 'uidnumber');
$result['mail'] = @ldap_get_values($this->ldap, $entry, 'mail');
$result['uid'] = @ldap_get_values($this->ldap, $entry, 'uid');
$result['cn'] = @ldap_get_values($this->ldap, $entry, 'cn');
foreach ( $result as $key => $value )
$result_user[$i][$key] = $value[0];
$ou = explode('dc=', $entry1[$i]['dn']);
$ou = explode("ou=",$ou[0]);
$ou = array_pop($ou);
$result_user[$i]['dn'] = strtoupper(substr($ou,0,strlen($ou)-1));
$result_user[$i]['photo'] = 0;
$photo = @ldap_get_values_len($this->ldap, $entry, 'jpegphoto');
if ( $photo )
{
$result_user[$i]['photo'] = 1;
$_SESSION['phpgw_info']['jabberit_messenger']['photo'][trim($result_user[$i]['uid'])] = $photo[0];
}
$i++;
}
$entry = ldap_next_entry($this->ldap,$entry);
}
$return = "";
$return .= "<".$result_user[0]['dn'].">";
$return .= "".$result_user[0]['cn']."";
$return .= "".$result_user[0]['mail']."";
$return .= "".$result_user[0]['uid']."";
$return .= "".$result_user[0]['photo']."";
$return .= "".$result_user[0]['dn'].">";
$return .= "";
return $return;
}
return '';
}
public final function list_users_ldap( $search, $uidnumber, $ous = false )
{
$this->_connect_ldap();
if( $this->ldap )
{
$filter = "(&(phpgwaccounttype=u)(|".$uidnumber.")(".$search ."))";
$justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto");
// SERPRO
//$justthese = array("uid","uidNumber","cn","mail","description","phpgwAccountVisible","dn","jpegPhoto");
if( $ous != false )
$search = ldap_search($this->ldap,$ous.",".$this->ldap_context,$filter,$justthese, 0, $this->max_result + 1);
else
$search = ldap_search($this->ldap,$this->ldap_context,$filter,$justthese, 0, $this->max_result + 1);
$entry1 = ldap_get_entries($this->ldap,$search);
$entry = ldap_first_entry($this->ldap,$search);
}
if( $entry1['count'] > 0 )
{
if( count($entry1) < $this->max_result )
{
$i = 0;
$result_user = array();
$result = array();
while($entry)
{
if ( $entry1[$i]['phpgwaccountvisible'][0] != '-1' )
{
$result['uidnumber'] = @ldap_get_values($this->ldap, $entry, 'uidnumber');
$result['mail'] = @ldap_get_values($this->ldap, $entry, 'mail');
$result['uid'] = @ldap_get_values($this->ldap, $entry, 'uid');
$result['cn'] = @ldap_get_values($this->ldap, $entry, 'cn');
// SERPRO
//$result['description'] = @ldap_get_values($this->ldap, $entry, 'description');
foreach ( $result as $key => $value )
$result_user[$i][$key] = $value[0];
$ou = explode('dc=', $entry1[$i]['dn']);
$ou = explode("ou=",$ou[0]);
$ou = array_pop($ou);
$result_user[$i]['dn'] = strtoupper(substr($ou,0,strlen($ou)-1));
$result_user[$i]['photo'] = 0;
$photo = @ldap_get_values_len($this->ldap, $entry, 'jpegphoto');
if ( $photo )
{
$result_user[$i]['photo'] = 1;
$_SESSION['phpgw_info']['jabberit_messenger']['photo'][trim($result_user[$i]['uid'])] = $photo[0];
}
$organization = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['attributes_org_ldap_jabberit']);
if(is_array($organization))
{
foreach($organization as $attr)
{
$tmp = explode(";",$attr);
if( strtolower(trim($tmp[0])) == strtolower(trim($result_user[$i]['dn'])) )
{
switch(strtolower(trim($tmp[1])))
{
case "mail" :
$uid = $result_user[$i]['mail'];
$uid = substr($uid,0,strpos($uid,"@"));
$result_user[$i]['uid'] = $uid;
break;
case "description" :
// SERPRO
// parte antes do arroba;
$result_user[$i]['uid'] = $result_user[$i]['description'];
break;
}
}
}
}
$i++;
}
$entry = ldap_next_entry($this->ldap,$entry);
}
return $result_user;
}
else
{
return "Many Results";
}
}
return 0;
}
public final function listOrganizationsLdap()
{
$this->_connect_ldap();
if( $this->ldap )
{
$filter="ou=*";
$justthese = array("ou");
$search = ldap_search($this->ldap,$this->ldap_context,$filter,$justthese);
$entry = ldap_get_entries($this->ldap, $search);
}
foreach($entry as $tmp)
if($tmp['ou'][0] != "")
$result_org[] = $tmp['ou'][0];
return $result_org;
}
public final function getGroupsLdap($pOrg)
{
$this->_ldapConnect(true);
$organization = 'ou=' . $pOrg['ou'] .",". $this->ldap_context;
if( $this->ldap )
{
$filter = "(&(phpgwAccountType=g)(objectClass=posixGroup))";
$justthese = array("cn","gidNumber");
$search = ldap_list($this->ldap, $organization, $filter, $justthese);
$entry = ldap_get_entries( $this->ldap, $search );
if( $entry )
{
$result_groups = "";
foreach($entry as $tmp)
if( $tmp['gidnumber'][0] != "" )
$result_groups .= "".$tmp['cn'][0]."".$tmp['gidnumber'][0]."";
$result_groups .= "";
}
}
return $result_groups;
}
}
?>