Ignore:
Timestamp:
09/20/10 18:23:03 (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/inc/class.ldap_im.inc.php

    r3102 r3266  
    4242                 
    4343                // Result Ldap 
    44                 $this->max_result = 20; 
     44                $this->max_result = 15; 
    4545                 
    4646                if ( file_exists('inc/attributeLdap.php') ) 
     
    4949                        $this->attribute = trim($attributeTypeName); 
    5050                } 
     51                else 
     52                        $this->attribute = "uid"; 
    5153        } 
    5254 
     
    7173        private final function ldapRoot() 
    7274        { 
     75                $this->ldap_host        = $_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit']; 
     76                $this->ldap_context     = $_SESSION['phpgw_info']['jabberit_messenger']['context_ldap_jabberit']; 
     77                $this->ldap_user        = $_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit']; 
     78                $this->ldap_pass        = $_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit']; 
     79                 
    7380                $this->ldapConn(); 
    7481        } 
     
    100107 
    101108                return $conn; 
     109        } 
     110 
     111        private function getLdapHost() 
     112        { 
     113                return  $_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit']; 
    102114        } 
    103115 
     
    167179 
    168180                return $result_groups; 
     181        } 
     182 
     183        public final function getMaxResults() 
     184        { 
     185                return $this->max_result; 
     186        } 
     187 
     188        public final function getMembers( $pMembers, $pServers ) 
     189        { 
     190                $members = $pMembers; 
     191                 
     192                foreach( $pServers as $servers => $groups ) 
     193                { 
     194                        if( $servers == $this->getLdapHost() || $servers == 'localhost') 
     195                        { 
     196                                $this->ldapRoot(); 
     197                                 
     198                                $count = count($members[$servers]); 
     199                                 
     200                                for( $i = 0; $i < $count; $i++ ) 
     201                                { 
     202                                        if ( ! $this->getMemberUid($groups, $members[$servers][$i]['uid'] ) ) 
     203                                                unset( $members[$servers][$i] ); 
     204                                } 
     205 
     206                                if( $this->ldap ) 
     207                                        @ldap_close($this->ldap); 
     208                        } 
     209                        else 
     210                        { 
     211                                $confHosts      = $this->hostsJabber; 
     212                         
     213                                for($i = 0; $i < count($confHosts); $i++ ) 
     214                                { 
     215                                        if( $this->ldap ) 
     216                                                @ldap_close($this->ldap); 
     217                                                 
     218                                        if( trim($servers) === trim($confHosts[$i]['serverLdap']) ) 
     219                                        { 
     220                                                $this->ldap_host        = $confHosts[$i]['serverLdap']; 
     221                                                $this->ldap_context = $confHosts[$i]['contextLdap']; 
     222                                                $this->ldap_user        = $confHosts[$i]['user']; 
     223                                                $this->ldap_org         = $confHosts[$i]['org']; 
     224                                                $this->ldap_pass        = $confHosts[$i]['password']; 
     225                                                $this->ldap             = $this->ldapCatalog(); 
     226 
     227                                                $count = count($members[$servers]); 
     228                                                 
     229                                                for( $i = 0; $i < $count; $i++ ) 
     230                                                { 
     231                                                        if ( ! $this->getMemberUid($groups, $members[$servers][$i]['uid'] ) ) 
     232                                                                unset( $members[$servers][$i] ); 
     233                                                } 
     234                 
     235                                                if( $this->ldap ) 
     236                                                        @ldap_close($this->ldap); 
     237                                        } 
     238                                } 
     239                        } 
     240                } 
     241                 
     242                return $members; 
     243        } 
     244 
     245        private function getMemberUid( $pGidNumber, $pMemberUid ) 
     246        { 
     247                $filter         = "(&(phpgwAccountType=g)(|{$pGidNumber})(memberuid={$pMemberUid}))"; 
     248                $justthese      = array("memberuid"); 
     249         
     250                if( $this->ldap ) 
     251                { 
     252                        $search = ldap_search($this->ldap, $this->ldap_context, $filter, $justthese ); 
     253                        $result = ldap_get_entries($this->ldap,$search); 
     254                        if( $result["count"] ) 
     255                                return true; 
     256                } 
     257 
     258                return false; 
    169259        } 
    170260 
     
    301391        } 
    302392 
    303         public final function getUsersLdapCatalog( $search, $uid = false, $pLdap = false ) 
     393        public final function getUsersLdapCatalog( $search, $pLdap = false, $uid = false ) 
    304394        { 
    305395                $confHosts      = $this->hostsJabber; 
     
    331421                                        $return = array_merge($return, $result); 
    332422                                        else 
    333                                                 $return = $result;                               
     423                                                $return = $result; 
    334424                                } 
    335425                                 
     
    342432        } 
    343433 
    344         public final function getUsersLdapRoot( $search, $uidnumber, $ous = false ) 
     434        public final function getUsersLdapRoot( $search, $uidnumber = false, $ous = false ) 
    345435        { 
    346436                $result = array(); 
     
    350440                { 
    351441                        $searchRoot     = ( $ous ) ? $ous.",".$this->ldap_context : $this->ldap_context ; 
    352                         $filter         = "(&(phpgwaccounttype=u)(|".$uidnumber.")(".$search ."))"; 
     442                        $filter         = ($uidnumber) ? "(&(phpgwaccounttype=u)(|".$uidnumber.")(".$search ."))" : "(&(phpgwaccounttype=u)(".$search ."))"; 
    353443                        $justthese      = array( $this->attribute, "uidNumber", "cn", "mail", "phpgwAccountVisible", "dn", "jpegPhoto" );                                                                
    354                         $search         = ldap_search( $this->ldap, $searchRoot, $filter, $justthese, 0, $this->max_result + 1); 
    355                         $entry          = ldap_get_entries( $this->ldap, $search ); 
     444                        $search         = @ldap_search( $this->ldap, $searchRoot, $filter, $justthese, 0, $this->max_result + 1); 
     445                        $entry          = @ldap_get_entries( $this->ldap, $search ); 
    356446                        $result         = $this->resultArray( $entry, $this->ldap ); 
    357447                }                
Note: See TracChangeset for help on using the changeset viewer.