1 | <?php |
---|
2 | class 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 | $result = ""; |
---|
38 | if ($this->conn) { |
---|
39 | $filter="uid=".$user; |
---|
40 | $justthese = array("jpegphoto"); |
---|
41 | $search = ldap_search($this->conn,$this->ldap_context, $filter, $justthese); |
---|
42 | $entry = ldap_first_entry($this->conn, $search); |
---|
43 | if($entry != 'undefined'){ |
---|
44 | $jpeg_data = @ldap_get_values_len($this->conn, $entry, "jpegphoto"); |
---|
45 | $photo = imagecreatefromstring($jpeg_data[0]); |
---|
46 | if($photo){ |
---|
47 | if($getPhoto){ |
---|
48 | header("Content-Type: image/jpeg"); |
---|
49 | $width = imagesx($photo); |
---|
50 | $height = imagesy($photo); |
---|
51 | $twidth = 49; |
---|
52 | $theight = 65; |
---|
53 | $small_photo = imagecreatetruecolor ($twidth, $theight); |
---|
54 | imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height); |
---|
55 | imagejpeg($small_photo,'',100); |
---|
56 | return; |
---|
57 | }else{ |
---|
58 | return true; |
---|
59 | } |
---|
60 | }else{ |
---|
61 | return false; |
---|
62 | } |
---|
63 | }else{ |
---|
64 | return false; |
---|
65 | } |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | function photo_ldap($user) |
---|
70 | { |
---|
71 | return $this->get_photo_ldap($user['uid'],false); |
---|
72 | } |
---|
73 | |
---|
74 | function list_users_ldap($orgLdap,$type,$uid) |
---|
75 | { |
---|
76 | $result_users = array(); |
---|
77 | $i = 0; |
---|
78 | |
---|
79 | if ($this->conn) { |
---|
80 | $filter = $type ."=". $uid; |
---|
81 | $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible"); |
---|
82 | $search = ldap_search($this->conn,"ou=".$orgLdap.",".$this->ldap_context, $filter, $justthese); |
---|
83 | $entry = ldap_get_entries($this->conn, $search); |
---|
84 | } |
---|
85 | |
---|
86 | if($entry['count'] == 0){ |
---|
87 | $result_users['count'] = 0; |
---|
88 | $result_users['uidnumber'] = $uid; |
---|
89 | return $result_users; |
---|
90 | } |
---|
91 | |
---|
92 | $result_users['uid'] = $entry[0]['uid'][0]; |
---|
93 | $result_users['uidnumber'] = $entry[0]['uidnumber'][0]; |
---|
94 | $result_users['cn'] = $entry[0]['cn'][0]; |
---|
95 | $result_users['mail'] = $entry[0]['mail'][0]; |
---|
96 | $result_users['phpgwAccountVisible'] = @$entry[0]['phpgwaccountvisible'][0]; |
---|
97 | |
---|
98 | return $result_users; |
---|
99 | } |
---|
100 | |
---|
101 | function list_groups_ldap($orgLdap, $gid) |
---|
102 | { |
---|
103 | $result_groups = ""; |
---|
104 | $i = 0; |
---|
105 | |
---|
106 | if ($this->conn) { |
---|
107 | $filter="gidNumber=".$gid; |
---|
108 | $justthese = array("gidnumber","cn","memberuid"); |
---|
109 | $search = ldap_search($this->conn,"ou=".$orgLdap.",".$this->ldap_context, $filter, $justthese); |
---|
110 | $entry = ldap_get_entries($this->conn, $search); |
---|
111 | } |
---|
112 | |
---|
113 | if($entry['count'] == "1"){ |
---|
114 | $result_groups = array_shift($entry[0]['memberuid']); |
---|
115 | return $entry[0]['memberuid']; |
---|
116 | } |
---|
117 | return false; |
---|
118 | } |
---|
119 | |
---|
120 | function list_organizations_ldap() |
---|
121 | { |
---|
122 | $result_org = array(); |
---|
123 | $i = 0; |
---|
124 | if ($this->conn) { |
---|
125 | $filter="ou=*"; |
---|
126 | $justthese = array("ou"); |
---|
127 | $search = ldap_list($this->conn,$this->ldap_context, $filter, $justthese); |
---|
128 | $entry = ldap_get_entries($this->conn, $search); |
---|
129 | } |
---|
130 | |
---|
131 | foreach($entry as $tmp){ |
---|
132 | if($tmp['ou'][0] != ""){ |
---|
133 | $result_org[$i]['ou'] = $tmp['ou'][0]; |
---|
134 | $i++; |
---|
135 | } |
---|
136 | } |
---|
137 | return $result_org; |
---|
138 | } |
---|
139 | |
---|
140 | } |
---|
141 | |
---|
142 | if(trim($_REQUEST['user']) != ""){ |
---|
143 | $obj_img = new ldap_im(); |
---|
144 | $obj_img->get_photo_ldap($_REQUEST['user'],true); |
---|
145 | } |
---|
146 | |
---|
147 | ?> |
---|