Changeset 387


Ignore:
Timestamp:
08/06/08 18:05:35 (16 years ago)
Author:
rafaelraymundo
Message:

Trac #280 da Comunidade Expresso
Corrigido o bug de loop infinito dentro do quicksearch

/trunk/source/expressoMail1_2/inc/class.ldap_functions.inc.php


Alterada a funcao quicksearch com o seguinte laço modificado i/j
for ($j=0; $j<$searchcount?; $j++){

$info[] = $search[$j];



File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/expressoMail1_2/inc/class.ldap_functions.inc.php

    r381 r387  
    1 <?php                    
     1<?php 
    22include_once("class.imap_functions.inc.php"); 
    33include_once("class.functions.inc.php"); 
     
    77        @ldap_bind($ldap_connection, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']); 
    88} 
    9                          
     9 
    1010class ldap_functions 
    1111{ 
     
    2121                @include("../contactcenter/setup/external_catalogs.inc.php"); 
    2222                $this->external_srcs= $external_srcs; 
    23                 $this->max_result       = 200;           
    24                 $this->functions = new functions();              
    25         }        
     23                $this->max_result       = 200; 
     24                $this->functions = new functions(); 
     25        } 
    2626        // Using ContactCenter configuration. 
    2727        function ldapConnect($refer = false,$catalog = 0){ 
     
    3939                        $this->bind_dn = $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc']; 
    4040                        $this->bind_dn_pw = $_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']; 
    41                         $this->branch = 'ou';                            
    42                 } 
    43                  
     41                        $this->branch = 'ou'; 
     42                } 
     43 
    4444                $this->ds = ldap_connect($this->ldap_host); 
    4545                ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3); 
     
    4848                        ldap_set_rebind_proc($this->ds, ldapRebind); 
    4949                } 
    50                 @ldap_bind($this->ds,$this->bind_dn,$this->bind_dn_pw );                 
     50                @ldap_bind($this->ds,$this->bind_dn,$this->bind_dn_pw ); 
    5151        } 
    5252 
     
    5454        function ldapConnect2($refer = false){ 
    5555                $ds = ldap_connect($_SESSION['phpgw_info']['expressomail']['ldap_server']['host']); 
    56                  
     56 
    5757                if (!$ds) 
    5858                        return false; 
    59                  
     59 
    6060                ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); 
    6161                ldap_set_option($ds, LDAP_OPT_REFERRALS, $refer); 
     
    6363                        ldap_set_rebind_proc($ds, ldapRebind); 
    6464                @ldap_bind($ds, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']); 
    65                  
    66                 return $ds;                              
     65 
     66                return $ds; 
    6767        } 
    6868 
     
    7575                ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3); 
    7676                ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $refer); 
    77                 ldap_bind($this->ds, $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'],$_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']);                               
     77                ldap_bind($this->ds, $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'],$_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']); 
    7878 
    7979        } 
    8080 
    8181        function quicksearch($params) 
    82         {        
     82        { 
    8383                include_once("class.functions.inc.php"); 
    84                 $functions = new functions;                                              
     84                $functions = new functions; 
    8585 
    8686                $search_for     = utf8_encode($params['search_for']); 
    8787                $field          = $params['field']; 
    8888                $ID                     = $params['ID']; 
    89                  
     89 
    9090                $search_for     = explode(" ",$search_for); 
    9191                $aux=""; 
     
    105105                $contacts_result['field'] = $field; 
    106106                $contacts_result['ID'] = $ID; 
    107                  
     107 
    108108                // follow the referral 
    109109                $this->ldapConnect(true); 
    110                                  
     110 
    111111                if ($this->ds) 
    112112                { 
     
    126126                        $count_entries = ldap_count_entries($this->ds,$sr); 
    127127 
    128                         // Get user org dn.                      
     128                        // Get user org dn. 
    129129                        $user_dn = $_SESSION['phpgw_info']['expressomail']['user']['account_dn']; 
    130130                        $user_sector_dn = ldap_explode_dn ( $user_dn, false ); 
     
    132132                        array_shift($user_sector_dn); 
    133133                        $user_sector_dn = implode(",", $user_sector_dn); 
    134                          
     134 
    135135                        // New search only on user sector 
    136136                        if ($count_entries > $this->max_result) 
     
    138138                                // Close old ldap conection 
    139139                                ldap_close($this->ds); 
    140                                  
     140 
    141141                                // Reopen a local ldap connection, following referral 
    142142                                $this->ldapRootConnect(true); 
    143                                  
     143 
    144144                                $sr= ldap_search($this->ds, $user_sector_dn, $filter, $justthese); 
    145145                                if(!$sr) 
    146146                                        return null; 
    147147                                $count_entries = ldap_count_entries($this->ds,$sr); 
    148                                  
     148 
    149149                                if ($count_entries > $this->max_result){ 
    150150                                        $return = array(); 
    151151                                        $return['status'] = false; 
    152                                         $return['error'] = "many results";                                       
     152                                        $return['error'] = "many results"; 
    153153                                        return $return; 
    154154                                } 
     
    158158                                } 
    159159                        } 
    160                          
     160 
    161161                        $info = ldap_get_entries($this->ds, $sr); 
    162                          
     162 
    163163                        $tmp = array(); 
    164164                        $tmp_users_from_user_org = array(); 
    165                          
     165 
    166166                        if (!$quickSearch_only_in_userSector) { 
    167167                                $catalogsNum=count($this->external_srcs); 
     
    176176                                                $count_entries = ldap_count_entries($this->ds,$sr); 
    177177                                                $search = ldap_get_entries($this->ds, $sr); 
    178                                                 for ($i=0; $i<$search["count"]; $i++) { 
    179                                                         $info[] = $search[$i]; 
     178                                                for ($j=0; $j<$search["count"]; $j++) { 
     179                                                        $info[] = $search[$j]; 
    180180                                                } 
    181181                                                $info["count"] = count($info)-1; 
     
    204204                        natcasesort($tmp_users_from_user_org); 
    205205                        natcasesort($tmp); 
    206                          
     206 
    207207                        if (($field != 'null') && ($ID != 'null')) 
    208208                        { 
    209209                                $i = 0; 
    210                                  
     210 
    211211                                $tmp = array_merge($tmp, $tmp_users_from_user_org); 
    212212                                natcasesort($tmp); 
    213                                  
     213 
    214214                                foreach ($tmp as $info => $cn) 
    215215                                { 
     
    242242                                        $i++; 
    243243                                } 
    244                                  
     244 
    245245                                if ($quickSearch_only_in_userSector) 
    246246                                { 
     
    293293        { 
    294294                include_once("class.functions.inc.php"); 
    295                 $functions = new functions;                                              
    296                  
     295                $functions = new functions; 
     296 
    297297                $contacts_result = array(); 
    298298                $contacts_result["cn"] = $cn; 
    299299                list ($contacts_result["mail"], $contacts_result["phone"], $contacts_result["mobile"], $contacts_result["uid"], $contacts_result["jpegphoto"]) = split ('%', $info); 
    300                                          
     300 
    301301                if ($contacts_result['jpegphoto']) 
    302302                        $photo_link = '<img src="./inc/show_user_photo.php?mail='.$contacts_result['mail'].'">'; 
    303303                else 
    304304                        $photo_link = '<img src="./templates/default/images/photo.png">'; 
    305                                          
     305 
    306306                $phoneUser = $contacts_result['phone']; 
    307                                          
     307 
    308308                if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['voip_enabled'] && $phoneUser) { 
    309309                        $phoneUser = '<a title="'.$this->functions->getLang("Call to Comercial Number").'" href="#" onclick="InfoContact.connectVoip(\''.$phoneUser.'\',\'com\')">'.$phoneUser.'</a>'; 
     
    332332        } 
    333333 
    334         function get_catalogs(){                 
     334        function get_catalogs(){ 
    335335                $catalogs = array(); 
    336                 $catalogs[0] = $this->functions->getLang("Global Catalog");              
    337                 if($this->external_srcs)  
     336                $catalogs[0] = $this->functions->getLang("Global Catalog"); 
     337                if($this->external_srcs) 
    338338                        foreach ($this->external_srcs as $key => $valor ){ 
    339339                        $catalogs[$key] = $valor['name']; 
     
    353353                        $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese); 
    354354                        $info = ldap_get_entries($this->ds, $sr); 
    355                          
     355 
    356356                        for ($i=0; $i<$info["count"]; $i++) 
    357357                                $organizations[$i] = $info[$i]["ou"][0]; 
    358358 
    359359                        ldap_close($this->ds); 
    360                         sort($organizations);                                    
     360                        sort($organizations); 
    361361                return $organizations; 
    362362                        }else{ 
     
    369369                $this->ldapRootConnect($referral); 
    370370                if ($this->ds) { 
    371                         $filter="ou=*";          
     371                        $filter="ou=*"; 
    372372                        $justthese = array("ou"); 
    373373                        $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese); 
    374374                        $info = ldap_get_entries($this->ds, $sr); 
    375                          
     375 
    376376                        for ($i=0; $i<$info["count"]; $i++) 
    377377                        { 
     
    379379                                $organizations[$i]['dn'] = $info[$i]["dn"]; 
    380380                        } 
    381                          
     381 
    382382                        ldap_close($this->ds); 
    383                         sort($organizations);                                    
     383                        sort($organizations); 
    384384                } 
    385385                return $organizations; 
     
    387387 
    388388        function catalogsearch($params) 
    389         {        
     389        { 
    390390                $cn     = $params['search_for'] ? "*".utf8_encode($params['search_for'])."*" : "*"; 
    391                 $max_result       = $params['max_result'] ? $params['max_result'] : $this->max_result;           
     391                $max_result       = $params['max_result'] ? $params['max_result'] : $this->max_result; 
    392392                $catalog = $params['catalog']; 
    393393                $error = False; 
    394                  
     394 
    395395                $this->ldapConnect(true,$catalog); 
    396                  
    397                 $params['organization'] == 'all' ? $user_context = $this->ldap_context :$user_context = $this->branch."=".$params['organization'].",".$this->ldap_context;               
    398                  
    399                 if ($this->ds) {                                                                                         
     396 
     397                $params['organization'] == 'all' ? $user_context = $this->ldap_context :$user_context = $this->branch."=".$params['organization'].",".$this->ldap_context; 
     398 
     399                if ($this->ds) { 
    400400                        if ($catalog == 0){ 
    401401                                //os atributos "employeeNumber" e "ou" foram adicionado ao vetor de busca; 
     
    409409                                //$user_context = $this->branch."=".$params['organization'].",".$external_srcs[$catalog]['dn']; 
    410410                        } 
    411                          
     411 
    412412                        $sr=@ldap_search($this->ds, $user_context, $filter, $justthese, 0, $max_result+1); 
    413413                        if(!$sr) 
     
    416416                        if ($count_entries > $max_result){ 
    417417                                $info = null; 
    418                                 $error = True;                                   
     418                                $error = True; 
    419419                        } 
    420420                        else 
    421                                 $info = ldap_get_entries($this->ds, $sr);                
    422                          
    423                         ldap_close($this->ds);                   
    424                          
     421                                $info = ldap_get_entries($this->ds, $sr); 
     422 
     423                        ldap_close($this->ds); 
     424 
    425425                        $u_tmp = array(); 
    426426                        $g_tmp = array(); 
    427                          
     427 
    428428                        for ($i=0; $i<$info["count"]; $i++){ 
    429429                                if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'U') && ($info[$i]["phpgwaccountvisible"][0] != '-1')) 
    430430                                        //aqui eh feita a concatenacao do departamento ao cn; 
    431431                                        $u_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]). '%' . $info[$i]["ou"][0]; 
    432                                 if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'L') && ($info[$i]["phpgwaccountvisible"][0] != '-1'))                                                       
     432                                if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'L') && ($info[$i]["phpgwaccountvisible"][0] != '-1')) 
    433433                                        $g_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]); 
    434                         }                                                                                
    435                          
     434                        } 
     435 
    436436                        natcasesort($u_tmp); 
    437437                        natcasesort($g_tmp); 
    438                          
     438 
    439439                        $i = 0; 
    440                         $users = array();                        
    441                          
    442                         foreach ($u_tmp as $mail => $cn){                                
     440                        $users = array(); 
     441 
     442                        foreach ($u_tmp as $mail => $cn){ 
    443443 
    444444                                $tmp = explode("%", $cn); //explode o cn pelo caracter "%" e joga em $tmp; 
     
    449449                        } 
    450450                        unset($u_tmp); 
    451                          
    452                         $i = 0;                  
     451 
     452                        $i = 0; 
    453453                        $groups = array(); 
    454                          
    455                         foreach ($g_tmp as $mail => $cn){                                
     454 
     455                        foreach ($g_tmp as $mail => $cn){ 
    456456                                $groups[$i++] = array("name" => $cn, "email" => $mail); 
    457457                        } 
    458458                        unset($g_tmp); 
    459                          
     459 
    460460                        return  array('users' => $users, 'groups' => $groups, 'error' => $error); 
    461                 }else                            
     461                }else 
    462462                return null; 
    463463        } 
    464          
     464 
    465465        function get_emails_ldap(){ 
    466466 
    467467                $result['mail']= array(); 
    468                 $result['mailalter']= array();           
     468                $result['mailalter']= array(); 
    469469                $user = $_SESSION['phpgw_info']['expressomail']['user']['account_lid']; 
    470470                $this->ldapRootConnect(false); 
    471471                if ($this->ds) { 
    472                         $filter="uid=".$user;            
     472                        $filter="uid=".$user; 
    473473                        $justthese = array("mail","mailAlternateAddress"); 
    474474                        $sr = ldap_search($this->ds,$this->ldap_context, $filter, $justthese); 
    475475                        $ent = ldap_get_entries($this->ds, $sr); 
    476476                        ldap_close($this->ds); 
    477                          
     477 
    478478                        for ($i=0; $i<$ent["count"]; $i++){ 
    479479                                $result['mail'][] = $ent[$i]["mail"][0]; 
    480                                 $result['mailalter'][] = $ent[$i]["mailalternateaddress"][0];                            
     480                                $result['mailalter'][] = $ent[$i]["mailalternateaddress"][0]; 
    481481                        } 
    482482                } 
    483483                return $result; 
    484484        } 
    485          
     485 
    486486        //Busca usuarios de um contexto e ja retorna as options do select; 
    487487        function get_available_users($params) 
     
    503503            $info = ldap_get_entries($this->ds, $sr); 
    504504            for ($i=0; $i<$info["count"]; $i++) 
    505                 $groups[$uids=$info[$i]["gidnumber"][0]] = Array('name'    =>    $uids=$info[$i]["cn"][0], 'type'    =>    g);             
     505                $groups[$uids=$info[$i]["gidnumber"][0]] = Array('name'    =>    $uids=$info[$i]["cn"][0], 'type'    =>    g); 
    506506            $justthese = array("phpgwaccountvisible","uidNumber","cn"); 
    507507            if ($params['type'] == 'search') 
     
    519519        } 
    520520        ldap_close($this->ds); 
    521              
     521 
    522522        @asort($users); 
    523         @reset($users);     
     523        @reset($users); 
    524524        @asort($groups); 
    525525        @reset($groups); 
     
    544544        { 
    545545                $this->ldapRootConnect(); 
    546                  
     546 
    547547                $context= $params['context']; 
    548548                $justthese = array("cn", "uid", "cn"); 
    549549                $filter = "(&(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))"; 
    550550 
    551             if ($this->ds)  
     551            if ($this->ds) 
    552552            { 
    553553                        $sr=ldap_search($this->ds, $context, $filter, $justthese); 
    554554                        $entries = ldap_get_entries($this->ds, $sr); 
    555                          
     555 
    556556                        for ($i=0; $i<$entries["count"]; $i++){ 
    557557                                if($_SESSION['phpgw_info']['expressomail']['user']['account_lid'] != $entries[$i]["uid"][0]){ 
     
    559559                                } 
    560560                        } 
    561                          
     561 
    562562                        natcasesort($u_tmp); 
    563563 
    564564                        $i = 0; 
    565565                        $users = array(); 
    566                          
     566 
    567567                        if (count($u_tmp)) 
    568568                        { 
     
    578578                } 
    579579        } 
    580          
     580 
    581581        function uid2cn($uid) 
    582         {        
     582        { 
    583583                // do not follow the referral 
    584584                $this->ldapRootConnect(false); 
    585585                if ($this->ds) 
    586586                { 
    587                         $filter="(&(phpgwAccountType=u)(uid=$uid))";             
     587                        $filter="(&(phpgwAccountType=u)(uid=$uid))"; 
    588588                        $justthese = array("cn"); 
    589589                        $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); 
     
    595595                return false; 
    596596        } 
    597         function getSharedUsersFrom($params){                                            
     597        function getSharedUsersFrom($params){ 
    598598                $filter = ''; 
    599599                $i = 0; 
    600600                if($params['uids']) { 
    601                         $uids = explode(";",$params['uids']);            
    602                         $this->imap = new imap_functions();              
     601                        $uids = explode(";",$params['uids']); 
     602                        $this->imap = new imap_functions(); 
    603603                        foreach($uids as $index => $uid){ 
    604                                 $params = array();               
     604                                $params = array(); 
    605605                                $acl = $this->imap->getacltouser($uid); 
    606606                                if(preg_match("/a/",$acl)) 
     
    608608                        } 
    609609                } 
    610                  
    611                 $this->ldapRootConnect(false);           
     610 
     611                $this->ldapRootConnect(false); 
    612612                if ($this->ds) { 
    613613                        $justthese = array("cn","mail"); 
     
    615615                                $filter="(&(phpgwAccountType=u)(|$filter))"; 
    616616                                $sr             =       ldap_search($this->ds, $this->ldap_context, $filter, $justthese); 
    617                                 ldap_sort($this->ds,$sr,"cn");                   
    618                                 $info   =       ldap_get_entries($this->ds, $sr);                                                                                
     617                                ldap_sort($this->ds,$sr,"cn"); 
     618                                $info   =       ldap_get_entries($this->ds, $sr); 
    619619                                for ($i = 0;$i < $info["count"]; $i++) 
    620620                                        $info[$i]['cn'][0] = utf8_decode($info[$i]['cn'][0]); 
    621621                        } 
    622622                        $info['myname'] = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 
    623                          
     623 
    624624                        //Find institucional_account. 
    625625                        $filter="(&(phpgwAccountType=i)(mailForwardingAddress=".$_SESSION['phpgw_info']['expressomail']['user']['email']."))"; 
    626                         $sr     = ldap_search($this->ds, $this->ldap_context, $filter, $justthese);                      
     626                        $sr     = ldap_search($this->ds, $this->ldap_context, $filter, $justthese); 
    627627                        if(!ldap_count_entries($this->ds,$sr)) 
    628628                                return $info; 
     
    646646                $ds = $this->ldapConnect2(true); 
    647647                if ($ds) 
    648                 {                        
     648                { 
    649649                        $sr=@ldap_search($ds, $ldap_context, $filter, $justthese); 
    650                          
     650 
    651651                        if (!$sr) 
    652652                                return null; 
    653                          
     653 
    654654                        $entry = ldap_first_entry($ds, $sr); 
    655                          
    656                         if($entry) {                                             
     655 
     656                        if($entry) { 
    657657                                $obj =  array("cn" => utf8_decode(current(ldap_get_values($ds, $entry, "cn"))), 
    658658                                                  "email" => $params['email'], 
Note: See TracChangeset for help on using the changeset viewer.