ldap_host = $_SESSION['phpgw_info']['instant_messenger']['server_ldap_jabber']; $this->ldap_context = $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber']; $this->user = $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber']; $this->password = $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber']; $this->connect_ldap(false); } function __destruct() { ldap_close($this->conn); } function connect_ldap($refer) { $this->conn = ldap_connect($this->ldap_host); ldap_set_option($this->conn, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($this->conn, LDAP_OPT_REFERRALS, $refer); if(trim($this->user) != "") @ldap_bind($this->conn,$this->user,$this->password); else @ldap_bind($this->conn); } function get_photo_ldap($user,$getPhoto) { $user = ( $user == "user" ) ? $_SESSION['phpgw_info']['instant_messenger']['user'] : $user ; if ($this->conn) { $filter="(&(uid=".$user.")(phpgwAccountType=u))"; $justthese = array("jpegphoto"); $search = ldap_search($this->conn,$this->ldap_context, $filter, $justthese); $entry = ldap_first_entry($this->conn, $search); $jpeg_data = @ldap_get_values_len($this->conn, $entry, "jpegphoto"); if( count($jpeg_data) > 1){ $photo = imagecreatefromstring($jpeg_data[0]); if($photo){ if($getPhoto){ header("Content-Type: image/jpeg"); $width = imagesx($photo); $height = imagesy($photo); $twidth = 49; $theight = 65; $small_photo = imagecreatetruecolor ($twidth, $theight); imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height); imagejpeg($small_photo,'',100); return; }else{ return 1; } }else{ return 0; } }else{ return 0; } } } function photo_ldap($user) { $uid = ( $user['uid'] == "user" ) ? $_SESSION['phpgw_info']['instant_messenger']['user'] : $user['uid'] ; return $this->get_photo_ldap($uid,false); } function list_users_ldap($search) { if($this->conn){ $filter = "(&(".$search.")(phpgwAccountType=u))"; $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn"); $search = ldap_search($this->conn,$this->ldap_context,$filter,$justthese); $entry = ldap_get_entries($this->conn,$search); } if( $entry['count'] > 0){ $i = 0; $result_user = array(); foreach($entry as $tmp) { if($tmp['uidnumber'][0] != "" && $tmp['phpgwaccountvisible'][0] != "-1"){ $result_user[$i]['uidnumber'] = $tmp['uidnumber'][0]; $result_user[$i]['mail'] = $tmp['mail'][0]; $result_user[$i]['uid'] = $tmp['uid'][0]; $result_user[$i]['cn'] = $tmp['cn'][0]; $ou = explode("dc=",$tmp['dn']); $ou = explode("ou=",$ou[0]); $ou = array_pop($ou); $result_user[$i]['dn'] = strtoupper(substr($ou,0,strlen($ou)-1)); $i++; } } return $result_user; } return 0; } function list_groups_ldap($search) { if( $this->conn ){ $filter = "(&(".$search.")(objectClass=posixGroup))"; $justthese = array("gidnumber","cn","memberuid"); $search = ldap_search($this->conn,$this->ldap_context, $filter, $justthese); $entry = ldap_get_entries($this->conn,$search); } if($entry['count'] > 0){ $i = 0; $result_groups = array(); foreach($entry as $tmpg){ if($tmpg['gidnumber'] != ""){ if(array_key_exists("memberuid", $tmpg)){ $result_groups[$i]['gidnumber'] = $tmpg['gidnumber'][0]; @array_shift($tmpg['memberuid']); foreach($tmpg['memberuid'] as $tmp) $result_groups[$i]['members'][] = $tmp; $i++; } } } } if(count($result_groups) > 0 ){ return $result_groups; }else{ return 0; } } function list_organizations_ldap() { $result_org = array(); $i = 0; if ($this->conn) { $filter="ou=*"; $justthese = array("ou"); $search = ldap_list($this->conn,$this->ldap_context, $filter, $justthese); $entry = ldap_get_entries($this->conn, $search); } foreach($entry as $tmp){ if($tmp['ou'][0] != ""){ $result_org[$i] = $tmp['ou'][0]; $i++; } } sort($result_org); return $result_org; } function info_user($user) { $uid = "uid=".$user['uid']; $i= 0; $entry = $this->list_users_ldap($uid); if( count($entry) > 0 ) return $entry; else return false; } } if(trim($_REQUEST['user']) != ""){ $obj_img = new ldap_im(); $obj_img->get_photo_ldap($_REQUEST['user'],true); } ?>