Ignore:
Timestamp:
09/17/10 11:11:28 (14 years ago)
Author:
alexandrecorreia
Message:

Ticket #1316 - Correcoes e melhorias na busca dos contatos para o Modulo IM.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/jabberit_messenger/jmessenger/inc/class.ContactsIm.inc.php

    r3102 r3260  
    2525                // (OU) User 
    2626                $this->ou_User = $this->dn_User; 
    27                 $this->ou_User = substr($this->ou_User,strpos($this->ou_User, "ou=")); 
     27                $this->ou_User = substr($this->ou_User, strpos($this->ou_User, "ou=") ); 
    2828                $this->ou_User = strtoupper(substr($this->ou_User, 0, strpos($this->ou_User, ",dc="))); 
    2929                 
     
    4949        public final function getListContacts($param) 
    5050        { 
    51                  
    5251                $order          = array(); 
    5352                $ou_User        = substr($this->ou_User, (strpos($this->ou_User,"=")+1)); 
    54                 $return         = '<empty/>'; 
     53                $return         = "<empty></empty>"; 
    5554                $users          = $this->getUsersIm($param['name']); 
    56  
    57                  
    58                 if (!is_array($users) && trim($users) === 'Many Results') 
    59                         return "<error>Many Results</error>"; 
    60  
     55                 
     56                if ( !is_array($users) ) 
     57                        return "<error></error>"; 
     58                 
     59                if( count($users) == 0  ) 
     60                        return "<empty></empty>"; 
     61                 
     62                if( count($users) > $this->ldap->getMaxResults() ) 
     63                { 
     64                        if( isset($_SESSION['phpgw_info']['jabberit_messenger']['photo']) ) 
     65                                unset($_SESSION['phpgw_info']['jabberit_messenger']['photo']); 
     66                         
     67                        return "<manyresults></manyresults>"; 
     68                } 
     69                                 
    6170                // Hosts Jabber 
    6271                $hostsJabber = unserialize($_SESSION['phpgw_info']['jabberit_messenger']['map_org_realm_jabberit']); 
     
    113122        $result                 = array(); 
    114123        $uidType                = "uid"; 
    115                 $serversLdap    = unserialize(trim($_SESSION['phpgw_info']['jabberit_messenger']['groups_search'])); 
    116  
    117         if( $serversLdap ) 
    118         { 
    119                 if( array_key_exists($this->serverLdap, $serversLdap) ) 
    120                 { 
    121                         $groups = unserialize($serversLdap[$this->serverLdap]); 
    122                 } 
    123  
    124                 if( count($groups) > 0 ) 
    125                 { 
    126                                 foreach($groups as $tmp) 
    127                                 { 
    128                                         $group = explode(":",$tmp); 
    129                                         $array_result = $this->ldap->getGroupsMemberUid($group[0], $this->serverLdap ); 
    130                                         @array_shift($array_result[0]['memberuid']); 
    131                                         $array_uids = @array_merge($array_uids, $array_result[0]['memberuid']); 
    132                                         unset($array_result); 
    133                                 } 
    134                 } 
    135         }                                
    136                  
    137         if( count($array_uids) == 0 ) 
    138         { 
     124                $serversLdap    = unserialize( trim($_SESSION['phpgw_info']['jabberit_messenger']['groups_search']) ); 
     125 
     126                if( $serversLdap ) 
     127                { 
     128                        // Usa Grupos Ldap 
     129                         
     130                        $filters = array( ); 
     131                         
     132                        foreach( $serversLdap as $servers => $groups ) 
     133                        { 
     134                                $filter = ''; 
     135                                foreach( unserialize($groups) as $group ) 
     136                                        $filter .= '(gidnumber' . strstr( $group, ':' ) . ')'; 
     137 
     138                                $filters[ $servers ] = str_replace( ':', '=', $filter ); 
     139                        } 
     140                         
     141                        foreach( $serversLdap as $key => $tmp ) 
     142                        { 
     143                                if( $key === $this->serverLdap ) 
     144                                { 
     145                                        $result[$key] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*"); 
     146                                } 
     147                                else 
     148                                { 
     149                                        if( !$this->groupsLocked() ) 
     150                                                $result[$key] =  $this->ldap->getUsersLdapCatalog("cn=*".$pName."*", $key ); 
     151                                } 
     152                        } 
     153                                 
     154                        $_RESULT = $this->ldap->getMembers($result, $filters); 
     155                         
     156                        foreach( $_RESULT as $key => $value ) 
     157                                $array_uids = array_merge($array_uids, $_RESULT[$key]);  
     158                } 
     159                else 
     160                { 
     161                // Consulta Banco 
    139162                $array_uids = $this->db->get_accounts_acl(); 
    140                 $uidType = "uidnumber";  
    141         }         
    142  
    143         for( $i = 0; $i < count($array_uids) ; $i+=50 ) 
    144         {    
    145             $partial_uids = array_slice($array_uids,$i,50); 
    146             $filter_uid = implode(")(".$uidType."=",$partial_uids); 
    147             $filter_uid = "(".$uidType."=". $filter_uid. ")"; 
    148  
    149                         if( $this->groupsLocked() ) 
    150                         { 
    151                     $orgs[] = $this->ou_User; 
    152                     $orgsGroupsLocked = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked']);  
    153                      
    154                                 foreach( $orgsGroupsLocked as $tmp ) 
    155                                 { 
    156                                         if( $tmp != "" ) 
     163                $uidType = "uidnumber"; 
     164                } 
     165 
     166                if( $this->groupsLocked() ) 
     167                { 
     168            $orgs[]                     = substr($this->ou_User, ( strpos($this->ou_User, "ou=") + 3 ) ); 
     169            $orgsGroupsLocked   = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked']);  
     170             
     171                        foreach( $orgsGroupsLocked as $tmp ) 
     172                        { 
     173                                if( $tmp != "") 
     174                                        $orgs[] = $tmp; 
     175                        } 
     176 
     177            $orgs = array_unique($orgs); 
     178 
     179                        $_restrict = array(); 
     180                         
     181                        for( $i = 0 ; $i < count($orgs) ; $i++ ) 
     182                        { 
     183                                for( $j = 0 ; $j < count($array_uids) ; $j++ ) 
     184                                { 
     185                                        if( trim($array_uids[$j]['ou']) === trim($orgs[$i]) ) 
    157186                                        { 
    158                                                 if( strpos($tmp, "/") !== false ) 
    159                                                 { 
    160                                                         $tt = explode("/", $tmp); 
    161                                                         $newOU = implode(",OU=",array_reverse($tt)); 
    162                                                         $orgs[] = "OU=". $newOU ; 
    163                                                 } 
    164                                                 else  
    165                                                         $orgs[] = "OU=". $tmp; 
    166                                         }             
    167                                 } 
    168  
    169                     $orgs = array_unique($orgs); 
    170  
    171                                 foreach( $orgs as $orgB ) 
    172                                         $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid, $orgB ); 
    173  
    174                         } 
    175                         else 
    176                                 $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid); 
    177         } 
    178          
    179         if( !$this->groupsLocked() ) 
    180         { 
    181                         unset($serversLdap[$this->serverLdap]); 
    182  
    183                         if( $serversLdap  && count($serversLdap)) 
    184                         { 
    185                                 foreach( $serversLdap as $key => $tmp ) 
    186                                 { 
    187                                         $array_uids_external = array( ); 
    188                                         $groupsExternal = unserialize($tmp); 
    189  
    190                                         if( count($groupsExternal) ) 
    191                                         { 
    192                                                 foreach( $groupsExternal as $tmpExt ) 
    193                                                 { 
    194                                                         $group = explode(":",$tmpExt); 
    195                                                         $array_result = $this->ldap->getGroupsMemberUid( $group[0], $key ); 
    196                                                          
    197                                                         if( $array_result[0]['memberuid']['count'] ) 
    198                                                                 unset($array_result[0]['memberuid']['count']); 
    199  
    200                                                         $array_uids_external = @array_merge($array_uids_external, $array_result[0]['memberuid']); 
    201                                                 } 
    202                                                  
    203                                                  
    204                                                 if( is_array($array_uids_external) ) 
    205                                                 { 
    206                                                         for( $i = 0; $i < count( $array_uids_external ) ; $i+=50 ) 
    207                                                 {    
    208                                                 $partial_uids_external  = array_slice($array_uids_external,$i,50); 
    209                                                 $filter_uid_external    = implode(")(".$this->attribute."=",$partial_uids_external); 
    210                                                 $filter_uid_external    = "(".$this->attribute."=". $filter_uid_external. ")"; 
    211                                                 $result[] = $this->ldap->getUsersLdapCatalog("cn=*".$pName."*", $filter_uid_external, $key ); 
    212                                                 } 
    213                                         } 
    214                                         } 
    215                                 } 
    216                         } 
    217  
    218                         if( count($this->hostsJabberLdap) ) 
    219                         { 
    220                                 for($i = 0 ; $i < count($this->hostsJabberLdap); $i++) 
    221                                 { 
    222                                         if( !@array_key_exists($this->hostsJabberLdap[$i]['serverLdap'], $serversLdap) ) 
    223                                         { 
    224                                                 $result[] = $this->ldap->getUsersLdapCatalog("cn=*".$pName."*", false, $this->hostsJabberLdap[$i]['serverLdap'] ); 
    225                                         } 
    226                                 } 
    227                         } 
    228         } 
    229          
    230         if ( is_array($result) ) 
    231         { 
    232                 for( $i = 0; $i < count($result); $i++ ) 
    233                         if( is_array($result[$i]) ) 
    234                                 $members = @array_merge($members,$result[$i]); 
    235         } 
    236               
    237         if( count($members) > 150) 
    238         { 
    239                 $ou = substr( $this->ou_User, strpos($this->ou_User, "=") + 1 ); 
    240                  
    241                         for($i = 0 ; $i < count($members); $i++ ) 
    242                         { 
    243                                 if( $ou == $members[$i]['ou'] ) 
    244                                 { 
    245                                         $uids_org[] = $members[$i]; 
    246                                 } 
    247                                 else 
    248                                 { 
    249                                         if(isset($_SESSION['phpgw_info']['jabberit_messenger']['photo'])) 
    250                                                 unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$members[$i]['ou']]); 
    251                                 } 
    252                         } 
    253                          
    254                         return $uids_org; 
    255         }             
    256  
    257                 return $members;         
     187                                                $_restrict[] = $array_uids[$j]; 
     188                                        }        
     189                                }        
     190                        } 
     191                         
     192                        return $_restrict; 
     193                } 
     194                else 
     195                {        
     196                        return $array_uids; 
     197                }        
    258198        } 
    259199         
     
    355295                        if( count($search) > 0 ) 
    356296                        { 
    357                                 // Verifica permissões do grupo 
     297                                // Verifica permissões do grupo 
    358298                                foreach($groupsLocked as $value) 
    359299                                {                                                        
     
    392332                                if( array_search($this->ou_User, $search) === false ) 
    393333                                { 
    394                                         // Verifica permissões do grupo 
     334                                        // Verifica permissões do grupo 
    395335                                        foreach($groupsLocked as $value) 
    396336                                        {                                                        
Note: See TracChangeset for help on using the changeset viewer.