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

Revision 287, 5.0 KB checked in by niltonneto, 16 years ago (diff)

Verificar Wiki/Trac? do módulo.

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