host = $handle['host'];
$this->context = $handle['context'];
$this->dn = $handle['dn'];
$this->passwd = $handle['passwd'];
$this->refer = true;
$this->version3 = true;
}
private final function ldapConnect()
{
if(!function_exists('ldap_connect'))
{
printf("Erro : Ldap Não suportado %s
" , $this->host);
return False;
}
if(!$this->conn = ldap_connect($this->host))
{
printf("Erro: não pode conectar no servidor ldap %s!
", $this->host);
return False;
}
if( $this->version3 )
{
if( !ldap_set_option($this->conn,LDAP_OPT_PROTOCOL_VERSION,3) )
$this->version = false;
}
ldap_set_option($this->conn, LDAP_OPT_REFERRALS, $this->refer);
// verifica refer
if( $this->refer )
{
@ldap_set_rebind_proc($this->conn, ldap_rebind);
}
// bind as admin
if($this->dn && $this->passwd && !ldap_bind($this->conn, $this->dn, $this->passwd)){
echo "
ExpressoLivre indisponível no momento";
return False;
}
// bind as anonymous
if(!$this->dn && !$this->passwd && !@ldap_bind($this->conn))
{
echo "ExpressoLivre indisponível no momento";
return False;
}
}
public final function getNameOrganization($pUid, $pCharset)
{
$this->ldapConnect();
if( $this->conn )
{
$filter = "(&(phpgwaccounttype=u)(uid=".$pUid.")(!(phpgwaccountvisible=-1)))";
$justthese = array("uid","cn","dn");
$search = ldap_search($this->conn,$this->context,$filter,$justthese);
$entry = ldap_get_entries($this->conn,$search);
$cn = $entry[0]['cn'][0];
$ou = explode("dc=", $entry[0]['dn']);
$ou = explode("ou=",$ou[0]);
$ou = array_pop($ou);
$dn = strtoupper(substr($ou,0,strlen($ou)-1));
$return = utf8_encode("Nome : " . $cn . ";Organização : " . $dn);
if( $pCharset === "1" )
return $return;
else
return mb_convert_encoding($return, "ISO-8859-1", "UTF-8");
$return = utf8_encode("Nome : Não Identificado ;Organização : Não Identificado");
if( $pCharset === 1 )
return $return;
else
return mb_convert_encoding($return, "ISO-8859-1", "UTF-8");
}
}
public final function getPhotoLdap($uid)
{
$this->ldapConnect();
if( $this->conn )
{
$filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))";
$justthese = array("uid","jpegPhoto");
$search = ldap_search($this->conn,$this->context,$filter,$justthese);
$entry1 = ldap_get_entries($this->conn,$search);
$entry = ldap_first_entry( $this->conn, $search );
if( $entry1['count'] > 0 )
{
$i = 0;
$photo = "";
$return_photo = "";
$photo = @ldap_get_values_len($this->conn, $entry, 'jpegphoto');
if ($photo)
$return_photo = $photo[0];
return $return_photo;
}
}
return false;
}
public final function getPhotoSession($pUid)
{
if(isset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pUid]))
{
$photo = imagecreatefromstring($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pUid]);
header("Content-Type: image/jpeg");
$width = imagesx($photo);
$height = imagesy($photo);
$twidth = 60;
$theight = 80;
$small_photo = imagecreatetruecolor ($twidth, $theight);
imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height);
imagejpeg($small_photo,'',100);
unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pUid]);
return;
}
}
}
if(trim($_REQUEST['uid']) != "")
{
$uid = trim($_REQUEST['uid']);
$a = new ldapPhoto();
if( strpos($uid,"@"))
{
$uid = substr($uid, 0, strpos($uid,"@"));
$photo = $a->getPhotoLdap($uid);
$photoWidth = 70;
$photoHeight = 90;
$newImage = imagecreatetruecolor($photoWidth,$photoHeight);
if($photo)
{
$photo = imagecreatefromstring($photo);
imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo));
}
else
{
$photo = @imagecreatefrompng("../templates/default/images/photo.png");
imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo));
}
ob_start();
imagepng($newImage);
$imagePhoto = ob_get_contents();
imagedestroy($newImage);
ob_end_clean();
printf("%s",base64_encode($imagePhoto));
}
else
{
$a->getPhotoSession($uid);
}
}
if(trim($_POST['jid']) != "")
{
$jid = trim($_POST['jid']);
if( strpos($jid,"@"))
$jid = substr($jid, 0, strpos($jid,"@"));
$charset = trim($_POST['charset']);
$a = new ldapPhoto();
printf("%s",$a->getNameOrganization($jid, $charset));
}
?>