Changeset 4929 for trunk/expressoMail1_2


Ignore:
Timestamp:
08/16/11 15:46:38 (13 years ago)
Author:
roberto.santosjunior
Message:

Ticket #1820 - Pesquisa rápida de contatos com aspas.r4906

Location:
trunk/expressoMail1_2
Files:
3 edited

Legend:

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

    r4457 r4929  
    8787                include_once("class.functions.inc.php"); 
    8888                $functions = new functions; 
    89                  
     89 
     90//              $search_for     = utf8_encode($params['search_for']); 
     91  //Testa se a busca foi realizada com aspas 
     92                $search_for     = utf8_encode($params['search_for']); 
     93                $search_len = (strlen($search_for)) - 1; 
     94                $quote_status=false; 
     95 
     96                if((($search_for{0}) == "\"") && (($search_for{$search_len}) == "\"")){ 
     97                    $search_for{0} = " "; 
     98                    $search_for{$search_len} = " "; 
     99                    $quote_status=true; 
     100                } 
     101 
     102 
     103 
    90104                $field          = $params['field']; 
    91105                $ID                     = $params['ID']; 
    92  
     106                 
    93107                $ldapService = ServiceLocator::getService('ldap'); 
    94108                $filter =  $ldapService->getSearchFilter($params['search_for']); 
    95          
     109 
    96110                $contacts_result = array(); 
    97111                $contacts_result['field'] = $field; 
     
    101115                // follow the referral 
    102116                $this->ldapConnect(true); 
    103                  
     117 
    104118                if ($this->ds) 
    105         { 
    106                 $ldapService->connection = $this->ds; 
     119                { 
     120                        if (($field != 'null') && ($ID != 'null')) 
     121                        { 
     122                                $filter="(& (&(|(phpgwAccountType=u)(phpgwAccountType=g)(phpgwAccountType=l))(mail=*)) (|(cn=*$search_for*)(mail=*$search_for*)) (!(phpgwaccountvisible=-1)) )"; 
     123                                if($extendedinfo) 
     124                                $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid", "employeeNumber", "ou"); 
     125                                else 
     126                                    $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid"); 
     127                        } 
     128                        else 
     129                        { 
     130                                if($quote_status){ 
     131                                        $filter="(& (phpgwAccountType=u) (|(cn=* $search_for *)(cn=$search_for *)(cn=* $search_for)) (!(phpgwaccountvisible=-1)) )"; 
     132                                } 
     133                                else{ 
     134                                        $filter="(& (phpgwAccountType=u)(cn=*$search_for*) (!(phpgwaccountvisible=-1)) )"; 
     135                                } 
     136                        //      $filter="(& (phpgwAccountType=u)(cn=*$search_for*) (!(phpgwaccountvisible=-1)) )"; 
     137                                if($extendedinfo) 
     138                                $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible","jpegPhoto", "uid", "employeeNumber", "ou"); 
     139                                else 
     140                                    $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible","jpegPhoto", "uid"); 
     141                        } 
     142                        $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result + 1); 
     143                        if(!$sr) 
     144                                return null; 
     145                        $count_entries = ldap_count_entries($this->ds,$sr); 
    107146 
    108147                $justthese = array("cn", "mail", "telephonenumber", "mobile", "phpgwaccountvisible", "uid", "employeenumber", "ou"); 
     
    110149 
    111150                if( $field == 'null' || $ID == 'null' ) 
    112                 { 
     151                        { 
    113152                    $justthese[] = "jpegphoto"; 
    114153                    $types = 'u'; 
     
    119158                $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result); 
    120159                         
    121                 if(!$sr) 
    122                     return null; 
    123  
    124                 $count_entries = ldap_count_entries($this->ds,$sr); 
     160                                if(!$sr) 
     161                                        return null; 
     162 
     163                                $count_entries = ldap_count_entries($this->ds,$sr); 
    125164 
    126165                $info = ldap_get_entries($this->ds, $sr); 
     
    130169            { 
    131170                $overload = $count_entries; 
    132             } 
    133             else 
    134             { 
    135                 $catalogsNum=count($this->external_srcs); 
     171                                } 
     172                                else 
     173                                { 
     174                                $catalogsNum=count($this->external_srcs); 
    136175                for ($i=0; $i<=$catalogsNum; $i++)      { 
    137                         if ($this->external_srcs[$i]["quicksearch"]) { 
    138                                 $this->ldapConnect(true,$i); 
    139                                 $filter="(|(cn=*$search_for*)(mail=*$search_for*))"; 
    140                                 $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid","employeeNumber", "ou"); 
    141                                 $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result+1); 
    142                                 if(!$sr) 
    143                                         return null; 
    144                                 $count_entries = ldap_count_entries($this->ds,$sr); 
    145                                 $search = ldap_get_entries($this->ds, $sr); 
    146                                 for ($j=0; $j<$search["count"]; $j++) { 
    147                                         $info[] = $search[$j]; 
    148                                 } 
    149                                 $info["count"] = count($info)-1; 
    150                         } 
    151                 } 
    152             } 
     176                                        if ($this->external_srcs[$i]["quicksearch"]) { 
     177                                                $this->ldapConnect(true,$i); 
     178                                                $filter="(|(cn=*$search_for*)(mail=*$search_for*))"; 
     179                                                $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid","employeeNumber", "ou"); 
     180                                                $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result+1); 
     181                                                if(!$sr) 
     182                                                        return null; 
     183                                                $count_entries = ldap_count_entries($this->ds,$sr); 
     184                                                $search = ldap_get_entries($this->ds, $sr); 
     185                                                for ($j=0; $j<$search["count"]; $j++) { 
     186                                                        $info[] = $search[$j]; 
     187                                                } 
     188                                                $info["count"] = count($info)-1; 
     189                                        } 
     190                                } 
     191                        } 
    153192 
    154193            $tmp = array(); 
    155194            $tmp_users_from_user_org = array(); 
    156195 
    157             for ($i=0; $i<$info["count"]; $i++) 
    158             { 
     196                        for ($i=0; $i<$info["count"]; $i++) 
     197                        { 
    159198                $key = $info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' .                       $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count'] . '%' . $info[$i]["employeenumber"][0] . '%' .      $info[$i]["ou"][0]; 
    160199 
    161200                if (/*(!$quickSearch_only_in_userSector) &&*/ preg_match("/$user_sector_dn/i", $info[$i]['dn'])) 
    162                 { 
     201                                { 
    163202                        $tmp_users_from_user_org[$key] = utf8_decode($info[$i]["cn"][0]); 
    164203                        continue; 
    165                 } 
     204                                } 
    166205 
    167206                $tmp[$key] = utf8_decode($info[$i]["cn"][0]); 
    168             } 
    169  
    170             natcasesort($tmp_users_from_user_org); 
    171             natcasesort($tmp); 
    172  
    173             if (($field != 'null') && ($ID != 'null')) 
    174             { 
    175                     $i = 0; 
    176  
    177                     $tmp = array_merge($tmp, $tmp_users_from_user_org); 
    178                     natcasesort($tmp); 
    179  
    180                     foreach ($tmp as $info => $cn) 
    181                     { 
    182                             $contacts_result[$i] = array(); 
    183                             $contacts_result[$i]["cn"] = $cn; 
    184                             list ($contacts_result[$i]["mail"], $contacts_result[$i]["phone"], $contacts_result[$i]["mobile"], $contacts_result[$i]["uid"], $contacts_result[$i]["jpegphoto"], $contacts_result[$i]["employeenumber"], $contacts_result[$i]["ou"]) = split ('%', $info); 
    185                             $i++; 
    186                     } 
    187                     $contacts_result['quickSearch_only_in_userSector'] = $quickSearch_only_in_userSector; 
     207                                        } 
     208 
     209                        natcasesort($tmp_users_from_user_org); 
     210                        natcasesort($tmp); 
     211 
     212                        if (($field != 'null') && ($ID != 'null')) 
     213                        { 
     214                                $i = 0; 
     215 
     216                                $tmp = array_merge($tmp, $tmp_users_from_user_org); 
     217                                natcasesort($tmp); 
     218 
     219                                foreach ($tmp as $info => $cn) 
     220                                { 
     221                                        $contacts_result[$i] = array(); 
     222                                        $contacts_result[$i]["cn"] = $cn; 
     223                                        list ($contacts_result[$i]["mail"], $contacts_result[$i]["phone"], $contacts_result[$i]["mobile"], $contacts_result[$i]["uid"], $contacts_result[$i]["jpegphoto"], $contacts_result[$i]["employeenumber"], $contacts_result[$i]["ou"]) = split ('%', $info); 
     224                                        $i++; 
     225                                } 
     226                                $contacts_result['quickSearch_only_in_userSector'] = $quickSearch_only_in_userSector; 
    188227                    $contacts_result['maxResult'] = $ldapService->limit; 
    189             } 
    190             else 
    191             { 
    192                     $options_users_from_user_org = ''; 
    193                     $options = ''; 
     228                        } 
     229                        else 
     230                        { 
     231                                $options_users_from_user_org = ''; 
     232                                $options = ''; 
    194233 
    195234             
    196                     $i = 0; 
    197                     foreach ($tmp_users_from_user_org as $info => $cn) 
    198                     { 
    199                             $contacts_result[$i] = array(); 
    200                             $options_users_from_user_org .= $this->make_quicksearch_card($info, $cn); 
    201                             $i++; 
    202                     } 
     235                                $i = 0; 
     236                                foreach ($tmp_users_from_user_org as $info => $cn) 
     237                                { 
     238                                        $contacts_result[$i] = array(); 
     239                                        $options_users_from_user_org .= $this->make_quicksearch_card($info, $cn); 
     240                                        $i++; 
     241                                } 
    203242 
    204243             
    205                     foreach ($tmp as $info => $cn) 
    206                     { 
    207                             $contacts_result[$i] = array(); 
    208                             $options .= $this->make_quicksearch_card($info, $cn); 
    209                             $i++; 
    210                     } 
    211  
    212  
    213                     if (($options_users_from_user_org != '') && ($options != '')) 
    214                     {                                    
    215                             $head_option0 = 
    216                                     '<tr class="quicksearchcontacts_unselected">' . 
    217                                             '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' . 
    218                                                     $this->functions->getLang('Users from your organization') . '</B> ['.count($tmp_users_from_user_org).']'; 
    219                                             '</td>' . 
    220                                     '</tr>'; 
    221  
    222                             $head_option1 = 
    223                                     '<tr class="quicksearchcontacts_unselected">' . 
    224                                             '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' . 
    225                                                     $this->functions->getLang('Users from others organizations') . '</B> ['.count($tmp).']'; 
    226                                             '</td>' . 
    227                                     '</tr>'; 
    228                     } 
     244                                foreach ($tmp as $info => $cn) 
     245                                { 
     246                                        $contacts_result[$i] = array(); 
     247                                        $options .= $this->make_quicksearch_card($info, $cn); 
     248                                        $i++; 
     249                                } 
     250 
     251 
     252                                        if (($options_users_from_user_org != '') && ($options != '')) 
     253                                        { 
     254                                                $head_option0 = 
     255                                                        '<tr class="quicksearchcontacts_unselected">' . 
     256                                                                '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' . 
     257                                                                        $this->functions->getLang('Users from your organization') . '</B> ['.count($tmp_users_from_user_org).']'; 
     258                                                                '</td>' . 
     259                                                        '</tr>'; 
     260 
     261                                                $head_option1 = 
     262                                                        '<tr class="quicksearchcontacts_unselected">' . 
     263                                                                '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' . 
     264                                                                        $this->functions->getLang('Users from others organizations') . '</B> ['.count($tmp).']'; 
     265                                                                '</td>' . 
     266                                                        '</tr>'; 
     267                                        } 
    229268                     
    230269                    $head_option = ''; 
     
    238277                    $contacts_result = $head_option.$head_option0 . $options_users_from_user_org . $head_option1. $options; 
    239278 
    240                 } 
    241             } 
    242  
    243             ldap_close($this->ds); 
    244  
    245             return $contacts_result; 
     279                                } 
     280                        } 
     281 
     282                ldap_close($this->ds); 
     283 
     284                return $contacts_result; 
    246285        } 
    247286 
     
    385424        //Busca usuarios de um contexto e ja retorna as options do select - usado por template serpro; 
    386425        function search_users($params) 
    387     { 
    388                 $owner = $_SESSION['phpgw_info']['expressomail']['user']['owner']; 
     426        { 
     427                $owner = $_SESSION['phpgw_info']['expressomail']['user']['owner']; 
    389428                        $ldapService = ServiceLocator::getService('ldap'); 
    390429                        $ldapService->connect($_SESSION['phpgw_info']['expressomail']['server']['ldap_host'], 
    391430                        $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'], 
    392431                        $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']); 
    393                          
     432 
    394433                        $groups = $ldapService->accountSearch($params['filter'], array("gidNumber","cn"), $params['context'] , 'g', 'cn');  
    395434                        $users = $ldapService->accountSearch($params['filter'], array("uidNumber","cn"), $params['context'] , 'u', 'cn'); 
     
    397436                        $user_options  = array(); 
    398437                        foreach($groups as $group) 
    399                         { 
     438                { 
    400439                                $group_options[] = '"'.$group['gidNumber'].'U'.'":"'.$group['cn'].'"'; 
    401440                } 
    402                          
     441 
    403442                foreach($users as $user)  
    404                 { 
     443                    { 
    405444                                if($owner != $user['uidNumber']) 
    406445                                        $user_options[] = '"'.$user['uidNumber'].'U'.'":"'.$user['cn'].'"'; 
    407                         } 
    408                          
     446                    } 
     447         
    409448                        $user_options = '{'.implode( ',', $user_options ).'}'; 
    410449                        $group_options = '{'.implode( ',', $group_options ).'}'; 
    411                  
     450 
    412451                return array("users" => $user_options, "groups" => $group_options); 
    413     } 
     452        } 
    414453 
    415454        function catalogsearch($params) 
     
    420459                $catalog = $params['catalog']; 
    421460                $error = False; 
    422                  
     461 
    423462                //if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info']) 
    424463                    //$extendedinfo=true; 
     
    432471 
    433472                if ($this->ds) { 
    434                         $justthese = array("cn", "mail", "phpgwaccounttype", "phpgwAccountVisible", "employeeNumber", "ou"); 
     473                                $justthese = array("cn", "mail", "phpgwaccounttype", "phpgwAccountVisible", "employeeNumber", "ou"); 
    435474                        $sr=@ldap_search($this->ds, $user_context, $filter, $justthese, 0, $ldapService->limit+1); 
    436                          
     475 
    437476                        if(!$sr) 
    438477                                return null; 
     
    571610                $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'], 
    572611                $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']); 
    573                  
     612 
    574613                $entries = $ldapService->accountSearch($params['sentence'], array('cn', 'uid'), $params['context'], 'u', 'cn'); 
    575                  
     614 
    576615                $options = array(); 
    577                  
     616 
    578617                foreach ($entries as $value)  
    579618                        $options[] = '"'.$value['uid'].'"'.':'.'"'.$value['cn'].'"'; 
    580                  
     619 
    581620                return "{".implode(',',$options)."}";            
    582         } 
     621                                } 
    583622 
    584623        function uid2cn($uid) 
  • trunk/expressoMail1_2/js/common_functions.js

    r4855 r4929  
    607607 
    608608        if (search_for.length < preferences.search_characters_number){ 
    609             alert(get_lang('Your search argument must be longer than %1 characters.', preferences.search_characters_number)); 
     609            //alert(get_lang('Your search argument must be longer than %1 characters.', preferences.search_characters_number)); 
     610            alert(get_lang('Your search argument must be longer than %1 characters. Use quotes to refine your search', preferences.search_characters_number)); 
    610611            return false; 
    611612        } 
  • trunk/expressoMail1_2/setup/phpgw_pt-br.lang

    r4843 r4929  
    622622Your message was sent to queue  expressoMail1_2 pt-br   Sua mensagem foi enviada com sucesso para a fila 
    623623Your search argument must be longer than %1 characters. expressoMail1_2 pt-br   Seus argumentos para a pesquisa precisam ter mais que %1 dígitos. 
     624Your search argument must be longer than %1 characters. Use quotes to refine your search        expressoMail1_2 pt-br   Seus argumentos para a pesquisa precisam ter mais que %1 dígitos. Use aspas para refinar a sua pesquisa. 
    624625Your session could not be verified.     expressoMail1_2 pt-br   Sua sessão expirou. Entre novamente no Expresso. 
    625626Your Spam folder was empty.     expressoMail1_2 pt-br   Sua pasta Spam foi limpa. 
Note: See TracChangeset for help on using the changeset viewer.