Changeset 3266


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.

Location:
branches/2.2/jabberit_messenger
Files:
6 edited

Legend:

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

    r3102 r3266  
    7474                $order          = array(); 
    7575                $ou_User        = substr($this->ou_User, (strpos($this->ou_User,"=")+1)); 
    76                 $return         = '<empty/>'; 
     76                $return         = ""; 
    7777                $users          = $this->getUsersIm($param['name']); 
    7878 
    79                  
    80                 if (!is_array($users) && trim($users) === 'Many Results') 
    81                         return "<error>Many Results</error>"; 
    82  
     79                if( count($users) == 0  ) 
     80                        return "<empty></empty>"; 
     81                 
     82                if( $users === "manyresults" ) 
     83                { 
     84                        if( isset($_SESSION['phpgw_info']['jabberit_messenger']['photo']) ) 
     85                                unset($_SESSION['phpgw_info']['jabberit_messenger']['photo']); 
     86                         
     87                        return "<manyresults></manyresults>"; 
     88                } 
     89                                 
    8390                // Hosts Jabber 
    8491                $hostsJabber = unserialize($_SESSION['phpgw_info']['jabberit_messenger']['map_org_realm_jabberit']); 
     
    130137 
    131138        private final function getUsersIm($pName) 
    132         {    
     139        { 
    133140                $array_uids             = array(); 
     141                $countUids              = 0; 
    134142        $members                = array(); 
    135143        $result                 = array(); 
    136144        $uidType                = "uid"; 
    137                 $serversLdap    = unserialize(trim($_SESSION['phpgw_info']['jabberit_messenger']['groups_search'])); 
    138                  
    139         if( $serversLdap ) 
    140         { 
    141                 if( array_key_exists($this->serverLdap, $serversLdap) ) 
    142                 { 
    143                         $groups = unserialize($serversLdap[$this->serverLdap]); 
    144                 } 
    145  
    146                 if( count($groups) > 0 ) 
    147                 { 
    148                                 foreach($groups as $tmp) 
    149                                 { 
    150                                         $group = explode(":",$tmp); 
    151                                         $array_result = $this->ldap->getGroupsMemberUid($group[0], $this->serverLdap ); 
    152                                         @array_shift($array_result[0]['memberuid']); 
    153                                         $array_uids = @array_merge($array_uids, $array_result[0]['memberuid']); 
    154                                         unset($array_result); 
    155                                 } 
    156                 } 
    157         }                                
    158                  
    159         if( count($array_uids) == 0 ) 
    160         { 
    161                 $array_uids = $this->db->get_accounts_acl(); 
    162                 $uidType = "uidnumber";  
    163         }         
    164  
    165         for( $i = 0; $i < count($array_uids) ; $i+=50 ) 
    166         {    
    167             $partial_uids = array_slice($array_uids,$i,50); 
    168             $filter_uid = implode(")(".$uidType."=",$partial_uids); 
    169             $filter_uid = "(".$uidType."=". $filter_uid. ")"; 
    170  
    171                         if( $this->groupsLocked() ) 
    172                         { 
    173                     $orgs[] = $this->ou_User; 
    174                     $orgsGroupsLocked = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked']);  
    175                      
    176                                 foreach( $orgsGroupsLocked as $tmp ) 
    177                                 { 
    178                                         if( $tmp != "" ) 
    179                                         { 
    180                                                 if( strpos($tmp, "/") !== false ) 
    181                                                 { 
    182                                                         $tt = explode("/", $tmp); 
    183                                                         $newOU = implode(",OU=",array_reverse($tt)); 
    184                                                         $orgs[] = "OU=". $newOU ; 
    185                                                 } 
    186                                                 else  
    187                                                         $orgs[] = "OU=". $tmp; 
    188                                         }             
    189                                 } 
    190  
    191                     $orgs = array_unique($orgs); 
    192  
    193                                 foreach( $orgs as $orgB ) 
    194                                         $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid, $orgB ); 
    195  
    196                         } 
    197                         else 
    198                                 $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid); 
    199         } 
    200          
    201         if( !$this->groupsLocked() ) 
    202         { 
    203                         unset($serversLdap[$this->serverLdap]); 
    204  
    205                         if( $serversLdap  && count($serversLdap)) 
    206                         { 
    207                                 foreach( $serversLdap as $key => $tmp ) 
    208                                 { 
    209                                         $array_uids_external = array( ); 
    210                                         $groupsExternal = unserialize($tmp); 
    211  
    212                                         if( count($groupsExternal) ) 
    213                                         { 
    214                                                 foreach( $groupsExternal as $tmpExt ) 
    215                                                 { 
    216                                                         $group = explode(":",$tmpExt); 
    217                                                         $array_result = $this->ldap->getGroupsMemberUid( $group[0], $key ); 
    218                                                          
    219                                                         if( $array_result[0]['memberuid']['count'] ) 
    220                                                                 unset($array_result[0]['memberuid']['count']); 
    221  
    222                                                         $array_uids_external = @array_merge($array_uids_external, $array_result[0]['memberuid']); 
    223                                                 } 
    224                                                  
    225                                                  
    226                                                 if( is_array($array_uids_external) ) 
    227                                                 { 
    228                                                         for( $i = 0; $i < count( $array_uids_external ) ; $i+=50 ) 
    229                                                 {    
    230                                                 $partial_uids_external  = array_slice($array_uids_external,$i,50); 
    231                                                 $filter_uid_external    = implode(")(uid=",$partial_uids_external); 
    232                                                 $filter_uid_external    = "(uid=". $filter_uid_external. ")"; 
    233                                                 $result[] = $this->ldap->getUsersLdapCatalog("cn=*".$pName."*", $filter_uid_external, $key ); 
    234                                                 } 
    235                                         } 
    236                                         } 
    237                                 } 
    238                         } 
    239  
    240                         if( count($this->hostsJabberLdap) ) 
    241                         { 
    242                                 for($i = 0 ; $i < count($this->hostsJabberLdap); $i++) 
    243                                 { 
    244                                         if( !@array_key_exists($this->hostsJabberLdap[$i]['serverLdap'], $serversLdap) ) 
    245                                         { 
    246                                                 $result[] = $this->ldap->getUsersLdapCatalog("cn=*".$pName."*", false, $this->hostsJabberLdap[$i]['serverLdap'] ); 
    247                                         } 
    248                                 } 
    249                         } 
    250         } 
    251          
    252         if ( is_array($result) ) 
    253         { 
    254                 for( $i = 0; $i < count($result); $i++ ) 
    255                         if( is_array($result[$i]) ) 
    256                                 $members = @array_merge($members,$result[$i]); 
    257         } 
    258               
    259         if( count($members) > 150) 
    260         { 
    261                 $ou = substr( $this->ou_User, strpos($this->ou_User, "=") + 1 ); 
    262                  
    263                         for($i = 0 ; $i < count($members); $i++ ) 
    264                         { 
    265                                 if( $ou == $members[$i]['ou'] ) 
    266                                 { 
    267                                         $uids_org[] = $members[$i]; 
     145                $serversLdap    = unserialize( trim($_SESSION['phpgw_info']['jabberit_messenger']['groups_search']) ); 
     146 
     147                if( $serversLdap ) 
     148                { 
     149                        // Usa Grupos Ldap 
     150                        $filters = array( ); 
     151                         
     152                        foreach( $serversLdap as $servers => $groups ) 
     153                        { 
     154                                $filter = ''; 
     155                                foreach( unserialize($groups) as $group ) 
     156                                        $filter .= '(gidnumber' . strstr( $group, ':' ) . ')'; 
     157 
     158                                $filters[ $servers ] = str_replace( ':', '=', $filter ); 
     159                        } 
     160 
     161                        foreach( $serversLdap as $key => $tmp ) 
     162                        { 
     163                                if( $key === $this->serverLdap ) 
     164                                { 
     165                                        $result[$key] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*"); 
     166                                        $countUids += count($result[$key]); 
    268167                                } 
    269168                                else 
    270169                                { 
    271                                         if(isset($_SESSION['phpgw_info']['jabberit_messenger']['photo'])) 
    272                                                 unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$members[$i]['ou']]); 
    273                                 } 
    274                         } 
    275                          
    276                         return $uids_org; 
    277         }             
    278  
    279                 return $members;         
     170                                        if( !$this->groupsLocked() ) 
     171                                        { 
     172                                                $result[$key] =  $this->ldap->getUsersLdapCatalog("cn=*".$pName."*", $key ); 
     173                                                $countUids += count($result[$key]); 
     174                                        } 
     175                                } 
     176                        } 
     177 
     178                        if( $countUids >  $this->ldap->getMaxResults() ) 
     179                        { 
     180                                return "manyresults"; 
     181                        } 
     182 
     183                        $_RESULT = $this->ldap->getMembers($result, $filters); 
     184                         
     185                        foreach( $_RESULT as $key => $value ) 
     186                                $array_uids = array_merge($array_uids, $_RESULT[$key]); 
     187                } 
     188                else 
     189                { 
     190                $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*"); 
     191                
     192                foreach( $result as $key => $value ) 
     193                { 
     194                                $array_uids = array_merge($array_uids, $result[$key]); 
     195                } 
     196                 
     197                if( count($array_uids) >  $this->ldap->getMaxResults() ) 
     198                        { 
     199                                return "manyresults"; 
     200                        } 
     201                } 
     202 
     203                if( $this->groupsLocked() ) 
     204                { 
     205            $orgs[]                     = substr($this->ou_User, ( strpos($this->ou_User, "ou=") + 3 ) ); 
     206            $orgsGroupsLocked   = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked']);  
     207             
     208                        foreach( $orgsGroupsLocked as $tmp ) 
     209                        { 
     210                                if( $tmp != "") 
     211                                        $orgs[] = $tmp; 
     212                        } 
     213 
     214            $orgs = array_unique($orgs); 
     215 
     216                        $_restrict = array(); 
     217                         
     218                        for( $i = 0 ; $i < count($orgs) ; $i++ ) 
     219                        { 
     220                                for( $j = 0 ; $j < count($array_uids) ; $j++ ) 
     221                                { 
     222                                        if( trim($array_uids[$j]['ou']) === trim($orgs[$i]) ) 
     223                                        { 
     224                                                $_restrict[] = $array_uids[$j]; 
     225                                        }        
     226                                }        
     227                        } 
     228                         
     229                        return $_restrict; 
     230                } 
     231                else 
     232                {        
     233                        return $array_uids; 
     234                }        
    280235        } 
    281236         
  • branches/2.2/jabberit_messenger/inc/class.db_im.inc.php

    r3102 r3266  
    111111                } 
    112112                return $apps; 
    113         } 
    114  
    115         public final function get_accounts_acl() 
    116         { 
    117                 $query  = "SELECT acl_account FROM phpgw_acl WHERE acl_location IN (SELECT CAST(acl_account AS varchar) FROM phpgw_acl WHERE acl_appname = 'jabberit_messenger') "; 
    118                 $query .= "UNION SELECT acl_account FROM phpgw_acl WHERE acl_appname = 'jabberit_messenger'"; 
    119                  
    120                 if( $this->db->query($query) )   
    121                 { 
    122                         $users = array(); 
    123                         $new_users = array(); 
    124                         while($this->db->next_record()) 
    125                                 $users[] = $this->db->row(); 
    126  
    127                         if(is_array($users)) 
    128                                 foreach($users as $tmp) 
    129                                         $new_users[] = $tmp['acl_account']; 
    130                          
    131                         return $new_users; 
    132                 } 
    133                  
    134                 return false; 
    135113        } 
    136114         
  • 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                }                
  • branches/2.2/jabberit_messenger/jmessenger/inc/class.ContactsIm.inc.php

    r3263 r3266  
    121121        $uidType                = "uid"; 
    122122                $serversLdap    = unserialize( trim($_SESSION['phpgw_info']['jabberit_messenger']['groups_search']) ); 
    123                  
    124123 
    125124                if( $serversLdap ) 
     
    168167                else 
    169168                { 
    170                 // Consulta Banco 
    171                 $array_uids = $this->db->get_accounts_acl(); 
    172                 $uidType = "uidnumber"; 
     169                $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*"); 
     170                
     171                foreach( $result as $key => $value ) 
     172                { 
     173                                $array_uids = array_merge($array_uids, $result[$key]); 
     174                } 
     175                                 
     176                        if( count($array_uids) >  $this->ldap->getMaxResults() ) 
     177                        { 
     178                                return "manyresults"; 
     179                        } 
    173180                } 
    174181 
  • branches/2.2/jabberit_messenger/js/ldap.js

    r3102 r3266  
    138138                                        { 
    139139                                                var _pList = { 
    140                                                                                 'many_results' : jabberitGetLang('More than 50 results. Please, try to refine your search.'), 
    141                                                                                 'empty' : jabberitGetLang('None result was found.') 
     140                                                                                'lang_addContact'       : "Adicionar Contatos" , 
     141                                                                                'lang_empty'            : "Nenhum resultado encontrado !", 
     142                                                                                'lang_error'            : "Tente Novamente!", 
     143                                                                                'lang_many_results' : "Muitos Resultados ! Por favor tente refinar sua busca !" 
    142144                                                                         };      
    143145                                                 
  • branches/2.2/jabberit_messenger/xsl/list_ldap_contacts.xsl

    r3102 r3266  
    33        <xsl:output method="html" omit-xml-declaration="yes"/> 
    44 
    5         <xsl:param name="many_results" /> 
    6         <xsl:param name="empty" /> 
     5        <xsl:param name="lang_addContact" /> 
     6        <xsl:param name="lang_empty" /> 
     7        <xsl:param name="lang_error" /> 
     8        <xsl:param name="lang_many_results" /> 
     9         
     10        <xsl:template match="/"> 
    711 
    8         <xsl:template match="/"> 
    9                 <xsl:choose> 
    10                         <xsl:when test="error"> 
    11                                 <label><xsl:value-of select="$many_results" /></label> 
    12                         </xsl:when> 
    13                         <xsl:when test="empty"> 
    14                                 <label><xsl:value-of select="$empty" /></label> 
    15                         </xsl:when> 
    16                         <xsl:otherwise> 
    17                                 <xsl:apply-templates select="uids/*" mode="uids" /> 
    18                         </xsl:otherwise> 
    19                 </xsl:choose> 
     12                <xsl:if test="error"> 
     13                        <label style="color:red;"><xsl:value-of select="$lang_error" /></label> 
     14                </xsl:if> 
     15                 
     16                <xsl:if test="empty"> 
     17                        <label style="color:red;"><xsl:value-of select="$lang_empty" /></label> 
     18                </xsl:if> 
     19                 
     20                <xsl:if test="manyresults"> 
     21                        <label style="color:red;"><xsl:value-of select="$lang_many_results" /></label> 
     22                </xsl:if> 
     23 
     24                <xsl:if test="uids"> 
     25                        <xsl:apply-templates select="uids/*" mode="uids" /> 
     26                </xsl:if> 
     27                 
    2028        </xsl:template> 
    2129 
     
    2937                                <br/> 
    3038                                <br/> 
    31                                 <label id="__label__{mail};{uid}" style="color:blue;cursor:pointer;">Adicionar Contato</label> 
     39                                <label id="__label__{mail};{uid}" style="color:blue;cursor:pointer;"><xsl:value-of select="$lang_addContact" /></label> 
    3240                                <br/> 
    3341                        </span> 
Note: See TracChangeset for help on using the changeset viewer.