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 *
RevLine 
[382]1<?php
[417]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  \***************************************************************************/
[382]12
[417]13
[382]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;
[697]21        private $ou_User;
[895]22        private $serverJabber;
[697]23               
[977]24        function __construct()
[382]25        {
26                $this->ldap = new ldap_im();
[697]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=")));
[895]33               
34                // Server Name Jabber
35                $this->serverJabber = $_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit'];
[382]36        }
37
[558]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'];
[598]45               
[558]46                foreach($groupsLocked as $tmp)
47                {
48                        $groups = explode(":", $tmp);
[697]49                        if( array_search($groups[1], $memberShip) !== False )
50                        {       
51                                $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked'] = $groups[2];
[558]52                                return true;
[697]53                        }
[558]54                }
55               
56                return false;
57        }
58
[382]59        public final function list_contacts($param)
60        {
[946]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']);
[895]65               
[382]66                if (!is_array($users) && trim($users) === 'Many Results')
67                        return "<error>Many Results</error>";
68
[977]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) )
[946]74                                $hostDefault = $conf['jabberName'];
75                       
[382]76                if( is_array($users) )
77                {       
[946]78                        for($i = 0; $i < count($users); $i++)                           
[895]79                        {
[977]80                                if( is_array($hostsJabber) )
[895]81                                {
[977]82                                        foreach($hostsJabber as $itens)
[895]83                                        {
[977]84                                                if( trim($users[$i]['ou']) === trim($itens['org']) )
85                                                        $users[$i]['jid'] = $users[$i]['jid']."@".$itens['jabberName'];
[946]86                                                else
87                                                {
88                                                        if( $users[$i]['ou'] === $ou_User )
[977]89                                                                if(strpos($users[$i]['jid'],"@") === false)
[946]90                                                                        $users[$i]['jid'] = $users[$i]['jid']."@".$this->serverJabber;
91                                                        else
[977]92                                                                if(strpos($users[$i]['jid'],"@") === false)
[946]93                                                                        $users[$i]['jid'] = $users[$i]['jid']."@".$hostDefault;
94                                                }
[895]95                                        }
96                                }
97                        }
[946]98
[382]99                        foreach($users as $tmp)
100                        {
[946]101                                if ( !array_key_exists($tmp['ou'], $order) )
102                                        $order[$tmp['ou']] = array();
[382]103
[946]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>';
[382]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        }
[697]117
[551]118        private final function users_auth_im($pName)
119        {   
120        $array_uids = $this->db->get_accounts_acl();
[988]121        $members = array();
[697]122        $result = array();
[988]123               
[987]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 )
[697]136                                {
[987]137                                        if( $tmp != "" )
138                                                $orgs[] = "OU=". $tmp;           
[697]139                                }
[987]140                               
141                    $orgs = array_unique($orgs);
[697]142
[988]143                                foreach( $orgs as $orgB )                               
144                                        $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid, $orgB );
[987]145                        }
146                        else
[988]147                                $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid);
[987]148        }
[988]149        if(!$this->groupsLocked())
150                $result[] = $this->ldap->getUsersLdapCatalog("cn=*".$pName."*");
[987]151
[697]152        if ( is_array($result) )
153        {
[946]154                for( $i = 0; $i < count($result); $i++ )
155                        if( is_array($result[$i]) )
156                                $members = array_merge($members,$result[$i]);
[697]157        }
[946]158             
159        if( count($members) > 150)
[697]160        {
[946]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;
[697]171        }           
[977]172
[946]173                return $members;       
[551]174        }
[697]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               
[946]191                $result = $this->ldap->getGroupsMemberUid($filter_gid);
[697]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        }
[382]273}
[946]274
[697]275?>
Note: See TracBrowser for help on using the repository browser.