source: trunk/instant_messenger/inc/class.ldap_im.inc.php @ 68

Revision 68, 4.6 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:executable set to *
RevLine 
[20]1<?php
2class ldap_im
3{
4        private $ldap_host;
5        private $ldap_context;
6        private $conn;
7        private $user;
8        private $password;
9       
10        function __construct()
11        {
12                $this->ldap_host        = $_SESSION['phpgw_info']['instant_messenger']['server_ldap_jabber'];
13                $this->ldap_context = $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber'];
14                $this->user             = $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber'];
15                $this->password         = $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber'];
[33]16                $this->connect_ldap(false);
[20]17        }
18       
19        function __destruct()
20        {
21                ldap_close($this->conn);
22        }
23       
24        function connect_ldap($refer)
25        {
26                $this->conn = ldap_connect($this->ldap_host);
27                ldap_set_option($this->conn, LDAP_OPT_PROTOCOL_VERSION, 3);
28                ldap_set_option($this->conn, LDAP_OPT_REFERRALS, $refer);
29                if(trim($this->user) != "")
[32]30                        @ldap_bind($this->conn,$this->user,$this->password);
[20]31                else           
[32]32                        @ldap_bind($this->conn);
[20]33        }
34       
35        function get_photo_ldap($user,$getPhoto)
36        {
[55]37                $user = ( $user == "user" ) ? $_SESSION['phpgw_info']['instant_messenger']['user'] : $user ;
38               
[20]39                if ($this->conn) {
[33]40                        $filter="(&(uid=".$user.")(phpgwAccountType=u))";               
[20]41                        $justthese = array("jpegphoto");
42                        $search = ldap_search($this->conn,$this->ldap_context, $filter, $justthese);
43                        $entry = ldap_first_entry($this->conn, $search);
[33]44                        $jpeg_data = @ldap_get_values_len($this->conn, $entry, "jpegphoto");
45                       
46                        if( count($jpeg_data) > 1){
47
[20]48                                $photo = imagecreatefromstring($jpeg_data[0]);
49                                if($photo){
50                                        if($getPhoto){
51                                                header("Content-Type: image/jpeg");
52                                                $width = imagesx($photo);
53                                                $height = imagesy($photo);
54                                                $twidth = 49;
55                                                $theight = 65;
56                                                $small_photo = imagecreatetruecolor ($twidth, $theight);
57                                                imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height);
58                                                imagejpeg($small_photo,'',100);
59                                                return;         
60                                        }else{
[27]61                                                return 1;
[20]62                                        }                               
63                                }else{
[27]64                                        return 0;
[20]65                                }
66                        }else{
[27]67                                return 0;
[20]68                        }
69                }
70        }
71       
72        function photo_ldap($user)
73        {
[55]74                $uid = ( $user['uid'] == "user" ) ? $_SESSION['phpgw_info']['instant_messenger']['user'] : $user['uid'] ;
75                return $this->get_photo_ldap($uid,false);
[20]76        }
77       
[33]78        function list_users_ldap($search)
[20]79        {
[68]80
[33]81                if($this->conn){
82                        $filter = "(&(".$search.")(phpgwAccountType=u))";
83                        $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn");
84                        $search = ldap_search($this->conn,$this->ldap_context,$filter,$justthese);
[32]85                        $entry = ldap_get_entries($this->conn,$search);
[20]86                }
[33]87               
[32]88                if( $entry['count'] > 0){
89                        $i = 0;
[33]90                        $result_user = array();
[32]91                        foreach($entry as $tmp)
92                        {
[33]93                                if($tmp['uidnumber'][0] != "" && $tmp['phpgwaccountvisible'][0] != "-1"){
[32]94                                        $result_user[$i]['uidnumber'] = $tmp['uidnumber'][0];                   
95                                        $result_user[$i]['mail'] = $tmp['mail'][0];
96                                        $result_user[$i]['uid'] = $tmp['uid'][0];
97                                        $result_user[$i]['cn'] = $tmp['cn'][0];
[33]98                                        $ou = explode("dc=",$tmp['dn']);
99                                        $ou = explode("ou=",$ou[0]);
100                                        $ou = array_pop($ou);
101                                        $result_user[$i]['dn'] = strtoupper(substr($ou,0,strlen($ou)-1));                                       
[32]102                                        $i++;
103                                }                               
104                        }
105                        return $result_user;
[20]106                }
[32]107                return 0;
[20]108        }
109       
[33]110        function list_groups_ldap($search)
[20]111        {
[41]112       
[32]113                if( $this->conn ){
[41]114                        $filter = "(&(".$search.")(objectClass=posixGroup))";
[32]115                        $justthese = array("gidnumber","cn","memberuid");                       
116                        $search = ldap_search($this->conn,$this->ldap_context, $filter, $justthese);
117                        $entry = ldap_get_entries($this->conn,$search);
118                }
[41]119
[33]120                if($entry['count'] > 0){
[32]121                        $i = 0;
[33]122                        $result_groups = array();
123                        foreach($entry as $tmpg){
124                                if($tmpg['gidnumber'] != ""){
[41]125                                        if(array_key_exists("memberuid", $tmpg)){
126                                                $result_groups[$i]['gidnumber'] = $tmpg['gidnumber'][0];                                               
127                                                @array_shift($tmpg['memberuid']);
128                                                foreach($tmpg['memberuid'] as $tmp)
129                                                        $result_groups[$i]['members'][] = $tmp;                                 
130                                                $i++;
131                                        }
[32]132                                }
[33]133                        }       
[41]134                }
135               
136                if(count($result_groups) > 0 ){
[32]137                        return $result_groups;
[41]138                }else{
139                        return 0;
[20]140                }
141        }
142       
143        function list_organizations_ldap()
144        {
145                $result_org = array();
146                $i = 0;
147                if ($this->conn) {
148                        $filter="ou=*";         
149                        $justthese = array("ou");
150                        $search = ldap_list($this->conn,$this->ldap_context, $filter, $justthese);
151                        $entry = ldap_get_entries($this->conn, $search);
152                }
153               
154                foreach($entry as $tmp){
155                        if($tmp['ou'][0] != ""){
[32]156                                $result_org[$i] = $tmp['ou'][0];
[20]157                                $i++;
158                        }
159                }
[32]160                sort($result_org);
[20]161                return $result_org;
162        }
163       
[27]164        function info_user($user)
165        {
[33]166                $uid = "uid=".$user['uid'];
[27]167                $i= 0;
168               
[33]169                $entry = $this->list_users_ldap($uid);
[27]170               
[33]171                if( count($entry) > 0 )
[32]172                        return $entry;
[33]173                else
[32]174                        return false;   
[27]175        }
[20]176}
177
178if(trim($_REQUEST['user']) != ""){
179        $obj_img = new ldap_im();
180        $obj_img->get_photo_ldap($_REQUEST['user'],true);
181}
182
183?>
Note: See TracBrowser for help on using the repository browser.