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

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