source: trunk/jabberit_messenger/inc/class.contacts_im.inc.php @ 988

Revision 988, 7.6 KB checked in by niltonneto, 15 years ago (diff)

Ticket #505 - Correção de busca dos usuários da própria base de dados.

  • Property svn:executable set to *
Line 
1<?php
2  /***************************************************************************\
3  *  Expresso - Expresso Messenger                                            *
4  *     - Alexandre Correia / Rodrigo Souza                                                               *
5  *     - JETI - http://jeti-im.org/                                                                              *
6  * ------------------------------------------------------------------------- *
7  *  This program is free software; you can redistribute it and/or modify it  *
8  *  under the terms of the GNU General Public License as published by the    *
9  *  Free Software Foundation; either version 2 of the License, or (at your   *
10  *  option) any later version.                                               *
11  \***************************************************************************/
12
13
14require_once "class.ldap_im.inc.php";
15require_once "class.db_im.inc.php";
16
17class contacts_im
18{
19        private $ldap;
20        private $db;
21        private $ou_User;
22        private $serverJabber;
23               
24        function __construct()
25        {
26                $this->ldap = new ldap_im();
27                $this->db = new db_im();
28
29                // (OU) User
30                $this->ou_User = $_SESSION['phpgw_info']['jabberit_messenger']['account_dn'];
31                $this->ou_User = substr($this->ou_User,strpos($this->ou_User, "ou="));
32                $this->ou_User = strtoupper(substr($this->ou_User, 0, strpos($this->ou_User, ",dc=")));
33               
34                // Server Name Jabber
35                $this->serverJabber = $_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit'];
36        }
37
38        private final function groupsLocked()
39        {
40                $memberShip = array();
41                $groupsLocked =  explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']);
42               
43                foreach($_SESSION['phpgw_info']['jabberit_messenger']['membership'] as $tmp)
44                        $memberShip[] = $tmp['account_name'];
45               
46                foreach($groupsLocked as $tmp)
47                {
48                        $groups = explode(":", $tmp);
49                        if( array_search($groups[1], $memberShip) !== False )
50                        {       
51                                $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked'] = $groups[2];
52                                return true;
53                        }
54                }
55               
56                return false;
57        }
58
59        public final function list_contacts($param)
60        {
61                $order          = array();
62                $ou_User        = substr($this->ou_User, (strpos($this->ou_User,"=")+1));
63                $return         = '<empty/>';
64                $users          = $this->users_auth_im($param['name']);
65               
66                if (!is_array($users) && trim($users) === 'Many Results')
67                        return "<error>Many Results</error>";
68
69                // Hosts Jabber
70                $hostsJabber = unserialize($_SESSION['phpgw_info']['jabberit_messenger']['map_org_realm_jabberit']);
71
72                foreach($hostsJabber as $conf )
73                        if( array_search("*", $conf) )
74                                $hostDefault = $conf['jabberName'];
75                       
76                if( is_array($users) )
77                {       
78                        for($i = 0; $i < count($users); $i++)                           
79                        {
80                                if( is_array($hostsJabber) )
81                                {
82                                        foreach($hostsJabber as $itens)
83                                        {
84                                                if( trim($users[$i]['ou']) === trim($itens['org']) )
85                                                        $users[$i]['jid'] = $users[$i]['jid']."@".$itens['jabberName'];
86                                                else
87                                                {
88                                                        if( $users[$i]['ou'] === $ou_User )
89                                                                if(strpos($users[$i]['jid'],"@") === false)
90                                                                        $users[$i]['jid'] = $users[$i]['jid']."@".$this->serverJabber;
91                                                        else
92                                                                if(strpos($users[$i]['jid'],"@") === false)
93                                                                        $users[$i]['jid'] = $users[$i]['jid']."@".$hostDefault;
94                                                }
95                                        }
96                                }
97                        }
98
99                        foreach($users as $tmp)
100                        {
101                                if ( !array_key_exists($tmp['ou'], $order) )
102                                        $order[$tmp['ou']] = array();
103
104                                $order[$tmp['ou']][] = '<data><ou>'.$tmp['ou'].'</ou><cn>'.$tmp['cn'].'</cn><mail>'.$tmp['mail'].'</mail><uid>'.$tmp['uid'].'</uid><jid>'.$tmp['jid'].'</jid><photo>'.$tmp['photo'].'</photo></data>';
105                        }
106                       
107                        ksort($order);
108                               
109                        $return = '<uids>';
110                        foreach ( $order as $key => $val )
111                                $return .= '<'.$key.'>'.implode('',$val).'</'.$key.'>';
112                        $return .= '</uids>';
113                }
114               
115                return $return;
116        }
117
118        private final function users_auth_im($pName)
119        {   
120        $array_uids = $this->db->get_accounts_acl();
121        $members = array();
122        $result = array();
123               
124        for( $i = 0; $i < count($array_uids) ; $i+=50 )
125        {   
126            $partial_uids = array_slice($array_uids,$i,50);
127            $filter_uid = implode(")(uidnumber=",$partial_uids);
128            $filter_uid = "(uidnumber=". $filter_uid. ")";
129
130                        if( $this->groupsLocked() )
131                        {
132                    $orgs[] = $this->ou_User;
133                    $orgsGroupsLocked = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked']);
134                   
135                                foreach( $orgsGroupsLocked as $tmp )
136                                {
137                                        if( $tmp != "" )
138                                                $orgs[] = "OU=". $tmp;           
139                                }
140                               
141                    $orgs = array_unique($orgs);
142
143                                foreach( $orgs as $orgB )                               
144                                        $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid, $orgB );
145                        }
146                        else
147                                $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid);
148        }
149        if(!$this->groupsLocked())
150                $result[] = $this->ldap->getUsersLdapCatalog("cn=*".$pName."*");
151
152        if ( is_array($result) )
153        {
154                for( $i = 0; $i < count($result); $i++ )
155                        if( is_array($result[$i]) )
156                                $members = array_merge($members,$result[$i]);
157        }
158             
159        if( count($members) > 150)
160        {
161                $ou = substr( $this->ou_User, strpos($this->ou_User, "=") + 1 );
162                        for($i = 0 ; $i < count($members); $i++ )
163                        {
164                                if( $ou == $members[$i]['ou'] )
165                                        $uids_org[] = $members[$i];
166                                else
167                                        if(isset($_SESSION['phpgw_info']['jabberit_messenger']['photo']))
168                                                unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$members[$i]['ou']]);
169                        }
170                        return $uids_org;
171        }           
172
173                return $members;       
174        }
175       
176        public final function verifyAddNewContact($pUid)
177        {
178                $groupsLocked =  explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']);
179                $gidNumbers = array();
180                $uid = $pUid['uid'];
181
182                foreach($groupsLocked as $tmp)
183                {
184                        $groups = explode(":", $tmp);
185                        $gidNumbers[] = $groups[1];
186                }
187               
188                $filter_gid = implode(")(gidnumber=",$gidNumbers);
189            $filter_gid = "(gidnumber=". $filter_gid. ")";
190               
191                $result = $this->ldap->getGroupsMemberUid($filter_gid);
192
193                if( $result && is_array($result) )
194                {
195                        array_shift($result);
196                        $i = 0;
197                       
198                        foreach($result as $value)
199                        {
200                                $Groups[$i]['dn'] = $value['dn'];
201                                $Groups[$i]['gidnumber'] = $value['gidnumber'][0];
202                                if(array_key_exists('memberuid',$value))
203                                {
204                                        array_shift($value['memberuid']);
205                                        $Groups[$i++]['memberuid'] = $value['memberuid'];
206                                }
207                        }
208
209                        $search = array();
210                        $search_Gid = array();
211                       
212                        // Verifica Uid em Grupo Bloqueado
213                        foreach($Groups as $value)
214                        {                       
215                                if( array_search( $uid , $value['memberuid'] ) !== false )
216                                {
217                                        $ou = substr($value['dn'],strpos($value['dn'], "ou="));
218                                        $search[] = strtoupper(substr($ou, 0, strpos($ou, ",dc=")));
219                                        $search_Gid[] = $value['gidnumber'];
220                                }       
221                        }
222                }
223
224                if( $this->groupsLocked() )
225                {
226                        if( count($search) > 0 )
227                        {
228                                // Verifica permissões do grupo
229                                foreach($groupsLocked as $value)
230                                {                                                       
231                                        $tpGroups = explode(":",$value);
232                                        if( $tpGroups[1] == $search_Gid[0] )
233                                        {
234                                                $ousTp = explode(",",$tpGroups[2]);
235                                                $ou_User = substr($this->ou_User,3);
236                                               
237                                                if( array_search( $ou_User, $ousTp) !== false )
238                                                        return "true";
239                                        }
240                                }
241                                return "false";
242                        }
243                        else
244                                return "true";
245                }
246                else
247                {               
248                        // Se Bloqueado verifica o Grupo       
249                        if( count($search) > 0 )
250                        {
251                                if( array_search($this->ou_User, $search) === false )
252                                {
253                                        // Verifica permissões do grupo
254                                        foreach($groupsLocked as $value)
255                                        {                                                       
256                                                $tpGroups = explode(":",$value);
257                                                if( $tpGroups[1] == $search_Gid[0] )
258                                                {
259                                                        $ousTp = explode(",",$tpGroups[2]);
260                                                        $ou_User = substr($this->ou_User,3);
261                                                               
262                                                        if( array_search( $ou_User, $ousTp) !== false )
263                                                                return "true";
264                                                }
265                                        }
266                                        return "false";
267                                }
268                                return "true";
269                        }                                       
270                        return "true";
271                }
272        }
273}
274
275?>
Note: See TracBrowser for help on using the repository browser.