source: branches/2.0/jabberit_messenger/inc/class.contacts_im.inc.php @ 1160

Revision 1160, 7.4 KB checked in by alexandrecorreia, 15 years ago (diff)

Ticket #571 - Somente criando os *.jars( applet.jar, filetransfer.jar e xhtml.jar )

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