source: companies/celepar/jabberit_messenger/inc/class.contacts_im.inc.php @ 763

Revision 763, 6.8 KB checked in by niltonneto, 15 years ago (diff)

Importação inicial do Expresso da Celepar

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