ldap = new ldap_im();
$this->db = new db_im();
$ou_User = $_SESSION['phpgw_info']['jabberit_messenger']['account_dn'];
$ou_User = substr($this->ou_User,strpos($this->ou_User, "ou="));
$ou_User = strtoupper(substr($this->ou_User, 0, strpos($this->ou_User, ",dc=")));
// (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=")));
}
public final function getParticipantsExternal()
{
if( !$this->groupsLocked() && $_SESSION['phpgw_info']['jabberit_messenger']['use_external_participants_jabberit'] )
return "true";
else
return "false";
}
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)
{
$users = $this->users_auth_im($param['name']);
$order = array();
if (!is_array($users) && trim($users) === 'Many Results')
return "Many Results";
if( is_array($users) )
{
foreach($users as $tmp)
{
if ( !array_key_exists($tmp['dn'], $order) )
$order[$tmp['dn']] = array();
$order[$tmp['dn']][] = '' . $tmp['cn'] . '' . $tmp['mail'] .'' . $tmp['uid'] . '' . $tmp['photo'] . '';
}
ksort($order);
$return = '';
foreach ( $order as $key => $val )
$return .= '<'.$key.'>'.implode('',$val).''.$key.'>';
$return .= '';
}
else
$return = '';
return $return;
}
private final function users_auth_im($pName)
{
$array_uids = $this->db->get_accounts_acl();
$count = count($array_uids);
$uids_members = array();
$result = array();
for($i = 0; $i < $count ;$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 $tmp )
$result[] = $this->ldap->list_users_ldap("cn=*".$pName."*", $filter_uid, $tmp);
}
else
$result[] = $this->ldap->list_users_ldap("cn=*".$pName."*", $filter_uid);
}
if ( is_array($result) )
{
for($i = 0; $i < count($result); $i++)
if(is_array($result[$i]))
$uids_members = array_merge($uids_members,$result[$i]);
}
if( count($uids_members) > 50 )
{
unset($_SESSION['phpgw_info']['jabberit_messenger']['photo']);
return 'Many Results';
}
if( count($uids_members) > 0 )
return $uids_members;
else
return 0;
}
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->list_groups_memberUid($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";
}
}
}
?>