ldap = new ldap_im();
$this->db = new db_im();
// (OU) User
$this->ou_User = $_SESSION['phpgw_info']['jabberit_messenger']['account_dn'];
$this->ou_User = substr($this->ou_User,strpos($this->ou_User, "ou="));
$this->ou_User = strtoupper(substr($this->ou_User, 0, strpos($this->ou_User, ",dc=")));
// Server Name Jabber
$this->serverJabber = $_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit'];
}
private final function groupsLocked()
{
$memberShip = array();
$groupsLocked = explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']);
foreach($_SESSION['phpgw_info']['jabberit_messenger']['membership'] as $tmp)
$memberShip[] = $tmp['account_name'];
foreach($groupsLocked as $tmp)
{
$groups = explode(":", $tmp);
if( array_search($groups[1], $memberShip) !== False )
{
$_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked'] = $groups[2];
return true;
}
}
return false;
}
public final function list_contacts($param)
{
$order = array();
$ou_User = substr($this->ou_User, (strpos($this->ou_User,"=")+1));
$return = '';
$users = $this->users_auth_im($param['name']);
if (!is_array($users) && trim($users) === 'Many Results')
return "Many Results";
// Hosts Jabber
$hostsJabber = unserialize($_SESSION['phpgw_info']['jabberit_messenger']['map_org_realm_jabberit']);
if( is_array($users) )
{
for($i = 0; $i < count($users); $i++)
{
if( is_array($hostsJabber) )
{
foreach($hostsJabber as $itens)
{
if( trim($users[$i]['ou']) === trim($itens['org']) && strpos($users[$i]['jid'],"@") === false )
{
$users[$i]['jid'] = $users[$i]['jid']."@".$itens['jabberName'];
}
}
}
if( strpos($users[$i]['jid'],"@") === false )
{
$users[$i]['jid'] = $users[$i]['jid']."@".$this->serverJabber;
}
}
foreach($users as $tmp)
{
if ( !array_key_exists($tmp['ou'], $order) )
$order[$tmp['ou']] = array();
$order[$tmp['ou']][] = ''.$tmp['ou'].''.$tmp['cn'].''.$tmp['mail'].''.$tmp['uid'].''.$tmp['jid'].''.$tmp['photo'].'';
}
ksort($order);
$return = '';
foreach ( $order as $key => $val )
$return .= '<'.$key.'>'.implode('',$val).''.$key.'>';
$return .= '';
}
return $return;
}
private final function users_auth_im($pName)
{
$array_uids = $this->db->get_accounts_acl();
$members = array();
$result = array();
for( $i = 0; $i < count($array_uids) ; $i+=50 )
{
$partial_uids = array_slice($array_uids,$i,50);
$filter_uid = implode(")(uidnumber=",$partial_uids);
$filter_uid = "(uidnumber=". $filter_uid. ")";
if( $this->groupsLocked() )
{
$orgs[] = $this->ou_User;
$orgsGroupsLocked = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked']);
foreach( $orgsGroupsLocked as $tmp )
{
if( $tmp != "" )
$orgs[] = "OU=". $tmp;
}
$orgs = array_unique($orgs);
foreach( $orgs as $orgB )
$result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid, $orgB );
}
else
$result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid);
}
if( !$this->groupsLocked() )
$result[] = $this->ldap->getUsersLdapCatalog("cn=*".$pName."*");
if ( is_array($result) )
{
for( $i = 0; $i < count($result); $i++ )
if( is_array($result[$i]) )
$members = array_merge($members,$result[$i]);
}
if( count($members) > 150)
{
$ou = substr( $this->ou_User, strpos($this->ou_User, "=") + 1 );
for($i = 0 ; $i < count($members); $i++ )
{
if( $ou == $members[$i]['ou'] )
$uids_org[] = $members[$i];
else
if(isset($_SESSION['phpgw_info']['jabberit_messenger']['photo']))
unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$members[$i]['ou']]);
}
return $uids_org;
}
return $members;
}
public final function verifyAddNewContact($pUid)
{
$groupsLocked = explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']);
$gidNumbers = array();
$uid = $pUid['uid'];
foreach($groupsLocked as $tmp)
{
$groups = explode(":", $tmp);
$gidNumbers[] = $groups[1];
}
$filter_gid = implode(")(gidnumber=",$gidNumbers);
$filter_gid = "(gidnumber=". $filter_gid. ")";
$result = $this->ldap->getGroupsMemberUid($filter_gid);
if( $result && is_array($result) )
{
array_shift($result);
$i = 0;
foreach($result as $value)
{
$Groups[$i]['dn'] = $value['dn'];
$Groups[$i]['gidnumber'] = $value['gidnumber'][0];
if(array_key_exists('memberuid',$value))
{
array_shift($value['memberuid']);
$Groups[$i++]['memberuid'] = $value['memberuid'];
}
}
$search = array();
$search_Gid = array();
// Verifica Uid em Grupo Bloqueado
foreach($Groups as $value)
{
if( array_search( $uid , $value['memberuid'] ) !== false )
{
$ou = substr($value['dn'],strpos($value['dn'], "ou="));
$search[] = strtoupper(substr($ou, 0, strpos($ou, ",dc=")));
$search_Gid[] = $value['gidnumber'];
}
}
}
if( $this->groupsLocked() )
{
if( count($search) > 0 )
{
// Verifica permissões do grupo
foreach($groupsLocked as $value)
{
$tpGroups = explode(":",$value);
if( $tpGroups[1] == $search_Gid[0] )
{
$ousTp = explode(",",$tpGroups[2]);
$ou_User = substr($this->ou_User,3);
if( array_search( $ou_User, $ousTp) !== false )
return "true";
}
}
return "false";
}
else
return "true";
}
else
{
// Se Bloqueado verifica o Grupo
if( count($search) > 0 )
{
if( array_search($this->ou_User, $search) === false )
{
// Verifica permissões do grupo
foreach($groupsLocked as $value)
{
$tpGroups = explode(":",$value);
if( $tpGroups[1] == $search_Gid[0] )
{
$ousTp = explode(",",$tpGroups[2]);
$ou_User = substr($this->ou_User,3);
if( array_search( $ou_User, $ousTp) !== false )
return "true";
}
}
return "false";
}
return "true";
}
return "true";
}
}
}
?>