source: trunk/instant_messenger/bkp/instant_messenger_32/inc/class.ldap_im.inc.php @ 151

Revision 151, 4.6 KB checked in by niltonneto, 16 years ago (diff)

Commit da nova versão do módulo, usando agente em C.
Vide Página do módulo do Trac:
http://www.expressolivre.org/dev/wiki/messenger

A versão anterior encontra-se na subpasta bkp (32/64).

Line 
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'];
16                $this->connect_ldap(false);
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) != "")
30                        @ldap_bind($this->conn,$this->user,$this->password);
31                else           
32                        @ldap_bind($this->conn);
33        }
34       
35        function get_photo_ldap($user,$getPhoto)
36        {
37                $user = ( $user == "user" ) ? $_SESSION['phpgw_info']['instant_messenger']['user'] : $user ;
38               
39                if ($this->conn) {
40                        $filter="(&(uid=".$user.")(phpgwAccountType=u))";               
41                        $justthese = array("jpegphoto");
42                        $search = ldap_search($this->conn,$this->ldap_context, $filter, $justthese);
43                        $entry = ldap_first_entry($this->conn, $search);
44                        $jpeg_data = @ldap_get_values_len($this->conn, $entry, "jpegphoto");
45                       
46                        if( count($jpeg_data) > 1){
47
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{
61                                                return 1;
62                                        }                               
63                                }else{
64                                        return 0;
65                                }
66                        }else{
67                                return 0;
68                        }
69                }
70        }
71       
72        function photo_ldap($user)
73        {
74                $uid = ( $user['uid'] == "user" ) ? $_SESSION['phpgw_info']['instant_messenger']['user'] : $user['uid'] ;
75                return $this->get_photo_ldap($uid,false);
76        }
77       
78        function list_users_ldap($search)
79        {
80
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);
85                        $entry = ldap_get_entries($this->conn,$search);
86                }
87               
88                if( $entry['count'] > 0){
89                        $i = 0;
90                        $result_user = array();
91                        foreach($entry as $tmp)
92                        {
93                                if($tmp['uidnumber'][0] != "" && $tmp['phpgwaccountvisible'][0] != "-1"){
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];
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));                                       
102                                        $i++;
103                                }                               
104                        }
105                        return $result_user;
106                }
107                return 0;
108        }
109       
110        function list_groups_ldap($search)
111        {
112       
113                if( $this->conn ){
114                        $filter = "(&(".$search.")(objectClass=posixGroup))";
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                }
119
120                if($entry['count'] > 0){
121                        $i = 0;
122                        $result_groups = array();
123                        foreach($entry as $tmpg){
124                                if($tmpg['gidnumber'] != ""){
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                                        }
132                                }
133                        }       
134                }
135               
136                if(count($result_groups) > 0 ){
137                        return $result_groups;
138                }else{
139                        return 0;
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] != ""){
156                                $result_org[$i] = $tmp['ou'][0];
157                                $i++;
158                        }
159                }
160                sort($result_org);
161                return $result_org;
162        }
163       
164        function info_user($user)
165        {
166                $uid = "uid=".$user['uid'];
167                $i= 0;
168               
169                $entry = $this->list_users_ldap($uid);
170               
171                if( count($entry) > 0 )
172                        return $entry;
173                else
174                        return false;   
175        }
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.