source: companies/serpro/instant_messenger/inc/class.ldap_im.inc.php @ 903

Revision 903, 5.4 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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/*
84 * ----------------------------------------------------------------------------
85 * SERPRO
86 */
87                        //$justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn");
88                        $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","description");
89/*
90 * ----------------------------------------------------------------------------
91 */
92                        $search = ldap_search($this->conn,$this->ldap_context,$filter,$justthese);
93                        $entry = ldap_get_entries($this->conn,$search);
94                }
95
96                if( $entry['count'] > 0){
97                        $i = 0;
98                        $result_user = array();
99                        foreach($entry as $tmp)
100                        {
101                                if($tmp['uidnumber'][0] != "" && $tmp['phpgwaccountvisible'][0] != "-1"){
102                                        $result_user[$i]['uidnumber'] = $tmp['uidnumber'][0];
103                                        $result_user[$i]['mail'] = $tmp['mail'][0];
104                                        $result_user[$i]['uid'] = $tmp['uid'][0];
105                                        $result_user[$i]['cn'] = $tmp['cn'][0];
106/*
107 * ----------------------------------------------------------------------------
108 * SERPRO
109 */
110                                        $result_user[$i]['description'] = $tmp['description'][0];
111/*
112 * ----------------------------------------------------------------------------
113 */
114                                        $ou = explode("dc=",$tmp['dn']);
115                                        $ou = explode("ou=",$ou[0]);
116                                        $ou = array_pop($ou);
117                                        $result_user[$i]['dn'] = strtoupper(substr($ou,0,strlen($ou)-1));
118                                        $i++;
119                                }
120                        }
121                        return $result_user;
122                }
123                return 0;
124        }
125
126        function list_groups_ldap($search)
127        {
128
129                if( $this->conn ){
130                        $filter = "(&(".$search.")(objectClass=posixGroup))";
131                        $justthese = array("gidnumber","cn","memberuid");
132                        $search = ldap_search($this->conn,$this->ldap_context, $filter, $justthese);
133                        $entry = ldap_get_entries($this->conn,$search);
134                }
135
136                if($entry['count'] > 0){
137                        $i = 0;
138                        $result_groups = array();
139                        foreach($entry as $tmpg){
140                                if($tmpg['gidnumber'] != ""){
141                                        if(array_key_exists("memberuid", $tmpg)){
142                                                $result_groups[$i]['gidnumber'] = $tmpg['gidnumber'][0];
143                                                @array_shift($tmpg['memberuid']);
144                                                foreach($tmpg['memberuid'] as $tmp)
145                                                $result_groups[$i]['members'][] = $tmp;
146                                                $i++;
147                                        }
148                                }
149                        }
150                }
151
152                if(count($result_groups) > 0 ){
153                        return $result_groups;
154                }else{
155                        return 0;
156                }
157        }
158
159        function list_organizations_ldap()
160        {
161                $result_org = array();
162                $i = 0;
163                if ($this->conn) {
164                        $filter="ou=*";
165                        $justthese = array("ou");
166                        $search = ldap_list($this->conn,$this->ldap_context, $filter, $justthese);
167                        $entry = ldap_get_entries($this->conn, $search);
168                }
169
170                foreach($entry as $tmp){
171                        if($tmp['ou'][0] != ""){
172                                $result_org[$i] = $tmp['ou'][0];
173                                $i++;
174                        }
175                }
176                sort($result_org);
177                return $result_org;
178        }
179
180        function info_user($user)
181        {
182                $uid = "uid=".$user['uid'];
183                $i= 0;
184
185                $entry = $this->list_users_ldap($uid);
186
187                if( count($entry) > 0 )
188                return $entry;
189                else
190                return false;
191        }
192       
193/*
194 * ----------------------------------------------------------------------------
195 * SERPRO
196 */
197        function get_user_description($uid) {
198           $user['uid'] = $uid;
199           
200           $info = $this->info_user($user);
201           
202           if($info === false) return null;
203           
204           if(count($info) == 1) return $info[0][description];
205           
206           return '';
207        }
208/*
209 * ----------------------------------------------------------------------------
210 */
211}
212
213if(trim($_REQUEST['user']) != ""){
214        $obj_img = new ldap_im();
215        $obj_img->get_photo_ldap($_REQUEST['user'],true);
216}
217
218?>
Note: See TracBrowser for help on using the repository browser.