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

Revision 991, 7.4 KB checked in by niltonneto, 15 years ago (diff)

Ticket #505 - Correção do jid do contato. Sem dominio quando é de outra OU.

  • 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                if( is_array($users) )
73                {       
74                        for($i = 0; $i < count($users); $i++)                           
75                        {
76                                if( is_array($hostsJabber) )
77                                {
78                                        foreach($hostsJabber as $itens)
79                                        {
80                                                if( trim($users[$i]['ou']) === trim($itens['org']) && strpos($users[$i]['jid'],"@") === false)
81                                                                $users[$i]['jid'] = $users[$i]['jid']."@".$itens['jabberName'];                                         
82                                                else
83                                                {
84                                                        if(strpos($users[$i]['jid'],"@") === false)
85                                                                        $users[$i]['jid'] = $users[$i]['jid']."@".$this->serverJabber;
86                                                }
87                                        }
88                                }
89                        }
90
91                        foreach($users as $tmp)
92                        {
93                                if ( !array_key_exists($tmp['ou'], $order) )
94                                        $order[$tmp['ou']] = array();
95
96                                $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>';
97                        }
98                       
99                        ksort($order);
100                               
101                        $return = '<uids>';
102                        foreach ( $order as $key => $val )
103                                $return .= '<'.$key.'>'.implode('',$val).'</'.$key.'>';
104                        $return .= '</uids>';
105                }
106               
107                return $return;
108        }
109
110        private final function users_auth_im($pName)
111        {   
112        $array_uids = $this->db->get_accounts_acl();
113        $members = array();
114        $result = array();
115               
116        for( $i = 0; $i < count($array_uids) ; $i+=50 )
117        {   
118            $partial_uids = array_slice($array_uids,$i,50);
119            $filter_uid = implode(")(uidnumber=",$partial_uids);
120            $filter_uid = "(uidnumber=". $filter_uid. ")";
121
122                        if( $this->groupsLocked() )
123                        {
124                    $orgs[] = $this->ou_User;
125                    $orgsGroupsLocked = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked']);
126                   
127                                foreach( $orgsGroupsLocked as $tmp )
128                                {
129                                        if( $tmp != "" )
130                                                $orgs[] = "OU=". $tmp;           
131                                }
132                               
133                    $orgs = array_unique($orgs);
134
135                                foreach( $orgs as $orgB )                               
136                                        $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid, $orgB );
137                        }
138                        else
139                                $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid);
140        }
141        if(!$this->groupsLocked())
142                $result[] = $this->ldap->getUsersLdapCatalog("cn=*".$pName."*");
143
144        if ( is_array($result) )
145        {
146                for( $i = 0; $i < count($result); $i++ )
147                        if( is_array($result[$i]) )
148                                $members = array_merge($members,$result[$i]);
149        }
150             
151        if( count($members) > 150)
152        {
153                $ou = substr( $this->ou_User, strpos($this->ou_User, "=") + 1 );
154                        for($i = 0 ; $i < count($members); $i++ )
155                        {
156                                if( $ou == $members[$i]['ou'] )
157                                        $uids_org[] = $members[$i];
158                                else
159                                        if(isset($_SESSION['phpgw_info']['jabberit_messenger']['photo']))
160                                                unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$members[$i]['ou']]);
161                        }
162                        return $uids_org;
163        }           
164
165                return $members;       
166        }
167       
168        public final function verifyAddNewContact($pUid)
169        {
170                $groupsLocked =  explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']);
171                $gidNumbers = array();
172                $uid = $pUid['uid'];
173
174                foreach($groupsLocked as $tmp)
175                {
176                        $groups = explode(":", $tmp);
177                        $gidNumbers[] = $groups[1];
178                }
179               
180                $filter_gid = implode(")(gidnumber=",$gidNumbers);
181            $filter_gid = "(gidnumber=". $filter_gid. ")";
182               
183                $result = $this->ldap->getGroupsMemberUid($filter_gid);
184
185                if( $result && is_array($result) )
186                {
187                        array_shift($result);
188                        $i = 0;
189                       
190                        foreach($result as $value)
191                        {
192                                $Groups[$i]['dn'] = $value['dn'];
193                                $Groups[$i]['gidnumber'] = $value['gidnumber'][0];
194                                if(array_key_exists('memberuid',$value))
195                                {
196                                        array_shift($value['memberuid']);
197                                        $Groups[$i++]['memberuid'] = $value['memberuid'];
198                                }
199                        }
200
201                        $search = array();
202                        $search_Gid = array();
203                       
204                        // Verifica Uid em Grupo Bloqueado
205                        foreach($Groups as $value)
206                        {                       
207                                if( array_search( $uid , $value['memberuid'] ) !== false )
208                                {
209                                        $ou = substr($value['dn'],strpos($value['dn'], "ou="));
210                                        $search[] = strtoupper(substr($ou, 0, strpos($ou, ",dc=")));
211                                        $search_Gid[] = $value['gidnumber'];
212                                }       
213                        }
214                }
215
216                if( $this->groupsLocked() )
217                {
218                        if( count($search) > 0 )
219                        {
220                                // Verifica permissões do grupo
221                                foreach($groupsLocked as $value)
222                                {                                                       
223                                        $tpGroups = explode(":",$value);
224                                        if( $tpGroups[1] == $search_Gid[0] )
225                                        {
226                                                $ousTp = explode(",",$tpGroups[2]);
227                                                $ou_User = substr($this->ou_User,3);
228                                               
229                                                if( array_search( $ou_User, $ousTp) !== false )
230                                                        return "true";
231                                        }
232                                }
233                                return "false";
234                        }
235                        else
236                                return "true";
237                }
238                else
239                {               
240                        // Se Bloqueado verifica o Grupo       
241                        if( count($search) > 0 )
242                        {
243                                if( array_search($this->ou_User, $search) === false )
244                                {
245                                        // Verifica permissões do grupo
246                                        foreach($groupsLocked as $value)
247                                        {                                                       
248                                                $tpGroups = explode(":",$value);
249                                                if( $tpGroups[1] == $search_Gid[0] )
250                                                {
251                                                        $ousTp = explode(",",$tpGroups[2]);
252                                                        $ou_User = substr($this->ou_User,3);
253                                                               
254                                                        if( array_search( $ou_User, $ousTp) !== false )
255                                                                return "true";
256                                                }
257                                        }
258                                        return "false";
259                                }
260                                return "true";
261                        }                                       
262                        return "true";
263                }
264        }
265}
266
267?>
Note: See TracBrowser for help on using the repository browser.