Changeset 4538 for sandbox


Ignore:
Timestamp:
05/27/11 15:02:52 (13 years ago)
Author:
airton
Message:

Ticket #1934 - Parametrização das buscas LDAP no Contactcenter

Location:
sandbox/2.2.0.2/contactcenter
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • sandbox/2.2.0.2/contactcenter/inc/class.abo_catalog.inc.php

    r2 r4538  
    685685                                        case 'LIKE': 
    686686                                        case 'iLIKE': 
     687                                        case 'LIKE and ~=': 
    687688                                        case 'NOT NULL': 
    688689                                        case 'NOT IN': 
     
    726727                                                $return_t[] = 'UPPER( '.$associative_tree[$restrict_data['field']]['table'].'.'. 
    727728                                                              $associative_tree[$restrict_data['field']]['field'].') LIKE UPPER(\''.$restrict_data['value'].'\')'; 
     729                                                break; 
     730                                         
     731                                        case 'LIKE and ~=': 
     732                                                $return_t[] = 'UPPER( '.$associative_tree[$restrict_data['field']]['table'].'.'. 
     733                                                              $associative_tree[$restrict_data['field']]['field'].') LIKE UPPER(\''."%".$restrict_data['value']."%".'\')';       
    728734                                                break; 
    729735                                         
  • sandbox/2.2.0.2/contactcenter/inc/class.bo_global_ldap_catalog.inc.php

    r4353 r4538  
    115115                function find($what, $rules=false, $other=false, $area=false, $recursive=false) 
    116116                { 
    117                         $restric_fields = $this->get_restrictions_without_branch($rules); 
    118                          
    119                         $trans_f = $this->translate_fields($what, $restric_fields); 
    120                          
    121                         foreach($trans_f as $orig => $field_a) 
    122                         { 
    123                                 foreach($field_a as $field) 
    124                                 { 
    125                                         $fields[] = $field; 
    126                                 } 
    127                         } 
    128  
    129                         $fields = array_unique($fields); 
    130                          
    131             //Testa se a busca foi realizada com aspas 
    132             $rules_search = $rules[3]['value']; 
    133             $rules_len = (strlen($rules_search)) -1; 
    134  
    135             if((($rules_search{1}) == "\"") && (($rules_search{$rules_len -1}) == "\"")){ 
    136                                 $rules_search = substr($rules_search,2,$rules_len-3); 
    137                                 $filter = "(&(|(objectClass=phpgwAccount))(&(!(phpgwAccountVisible=-1)))(|(cn=* $rules_search *)(cn=$rules_search *)(cn=* $rules_search)))"; 
    138             } 
    139             else{ 
    140                                 $filter = $this->process_restrictions($rules, $trans_f); 
    141             } 
    142                          
    143             if ($area) 
    144             { 
    145                  $obj = CreateObject('phpgwapi.config','contactcenter'); 
    146                  $opts = $obj->read_repository(); 
    147                  $filter = substr($filter,0,-1) .'(' . $opts['cc_ldap_atrib'] . '=*' . $area . '*))'; 
    148                  $opts = null; 
    149                  $obj = null; 
    150             } 
    151             // Find objects where 'mail' attribute is not null. 
    152                         $filter = "(&".$filter."(mail=*))"; 
    153              
     117                    $find = ''; 
     118                    if($rules) 
     119                    { 
     120                        foreach ($rules as $rule) 
     121                        { 
     122                            if($rule['field'] == 'contact.names_ordered' && $find === '') 
     123                                $find .= $rule['value']; 
     124                            else if($rule['field'] == 'contact.names_ordered') 
     125                                $find .= ' '.$rule['value']; 
     126                        } 
     127                    } 
     128 
     129                    if(!((strlen($find) == 2 && substr($find, -1) == '%') || $find == '%' )) 
     130                          return $this->findAddress($find,$other); 
     131 
     132                    $restric_fields = $this->get_restrictions_without_branch($rules); 
     133 
     134                    $trans_f = $this->translate_fields($what, $restric_fields); 
     135 
     136                    foreach($trans_f as $orig => $field_a) 
     137                    { 
     138                        foreach($field_a as $field) 
     139                        { 
     140                            $fields[] = $field; 
     141                        } 
     142                    } 
     143 
     144                    $fields = array_unique($fields); 
     145 
     146                    //Testa se a busca foi realizada com aspas 
     147                    $rules_search = $rules[3]['value']; 
     148                    $rules_len = (strlen($rules_search)) -1; 
     149 
     150                    if((($rules_search{1}) == "\"") && (($rules_search{$rules_len -1}) == "\"")){ 
     151                                        $rules_search = substr($rules_search,2,$rules_len-3); 
     152                                        $filter = "(&(|(objectClass=phpgwAccount))(&(!(phpgwAccountVisible=-1)))(|(cn=* $rules_search *)(cn=$rules_search *)(cn=* $rules_search)))"; 
     153                    } 
     154                    else{ 
     155                                        $filter = $this->process_restrictions($rules, $trans_f); 
     156                    } 
     157 
     158                    // Find objects where 'mail' attribute is not null. 
     159                    $filter = "(&".$filter."(mail=*))"; 
    154160                        $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'], $this->src_info['acc'], $this->src_info['pw'], true); 
    155161                        $result_r = $recursive ? ldap_search($ldap , $this->src_info['context'], $filter, $fields, 0, $this->src_info['max_results']) : 
    156             ldap_list($ldap , $this->src_info['context'], $filter, $fields, 0, $this->src_info['max_results']); 
    157  
    158                         if (!$result_r) 
     162                        ldap_list($ldap , $this->src_info['context'], $filter, $fields, 0, $this->src_info['max_results']); 
     163 
     164                         if (!$result_r) 
    159165                        { 
    160166                                return false; 
    161167                        } 
    162                          
    163                         if ($other['order']) 
    164                         { 
    165                                 $sort_f = array($other['order']); 
    166                                 $ldap_sort_by = $this->translate_fields($sort_f, $restric_fields); 
    167                         } 
    168  
    169                         if ($ldap_sort_by) 
    170                         { 
     168 
     169                    if ($other['order']) 
     170                    { 
     171                            $sort_f = array($other['order']); 
     172                            $ldap_sort_by = $this->translate_fields($sort_f, $restric_fields); 
     173                        } 
     174 
     175                    if ($ldap_sort_by) 
     176                    { 
    171177                                if (!ldap_sort($ldap, $result_r, $ldap_sort_by[$other['order']][0])) 
    172178                                { 
    173                                         return false; 
    174                                 } 
    175                         } 
    176                          
    177                         $result_u = ldap_get_entries($ldap, $result_r); 
    178                         //      No entries found. 
    179                         if(!$result_u) 
    180                                 return true; 
    181                          
    182                         $i = 0; 
    183                         foreach ($result_u as $index => $result_p) 
    184                         { 
    185                                 if ($index === 'count' or $index === 'dn' or (!$this->external and $result_p['phpgwaccountvisible'][0] == '-1')) 
    186                                 { 
    187                                         continue; 
    188                                 } 
    189                                  
    190                                 foreach ($trans_f as $orig => $trans) 
    191                                 { 
    192                                         $orig = substr($orig, strrpos($orig, '.')+1, strlen($orig)); 
    193                                         foreach ($trans as $f) 
    194                                         { 
    195                                                 if ($f === 'dn') 
    196                                                 { 
    197                                                         $return[$i][$orig] = $result_p['dn']; 
    198                                                 } 
    199                                                 else if ($result_p[$f][0]) 
    200                                                 { 
    201                                                         $return[$i][$orig] = $result_p[$f][0]; 
    202                                                 } 
    203                                         } 
    204                                 } 
    205                                 $i++; 
    206                         } 
    207                         if($return) 
    208                                 usort($return, array($this, "compareObjects")); 
    209                         return $return; 
    210                 } 
     179                                    return false; 
     180                            } 
     181                    } 
     182 
     183                    $iTotalEntries = ldap_count_entries( $ldap, $result_r ); 
     184 
     185                    if($iTotalEntries < 1 ) 
     186                            return true; 
     187 
     188                    $iEnd = $iTotalEntries; 
     189 
     190                    $return = array(); 
     191 
     192                    $rEntry = ldap_first_entry( $ldap, $result_r ); 
     193                    for ( $iCurrent = 0; $iCurrent < $iEnd ;$iCurrent++) 
     194                    { 
     195 
     196                        $result_p = ldap_get_attributes($ldap, $rEntry ); 
     197 
     198                        if(!$this->external and $result_p['phpgwaccountvisible'][0] == '-1'){ 
     199                            continue; 
     200                        } 
     201 
     202                        $returnTemp = array(); 
     203                        $returnTemp['id_contact'] = ldap_get_dn($ldap, $rEntry); 
     204                        $returnTemp['names_ordered'] = $result_p['cn']['0']; 
     205 
     206                        array_push( $return, $returnTemp ); 
     207                        $rEntry = ldap_next_entry( $ldap, $rEntry ); 
     208 
     209                    } 
     210 
     211 
     212                    usort($return, array($this, "compareObjects")); 
     213                    return $return; 
     214                } 
     215 
     216                function findAddress($find, $other=false) 
     217                { 
     218 
     219                    require_once $_SESSION['rootPath'].'/API/class.servicelocator.php'; 
     220                    $ldapService = ServiceLocator::getService('ldap'); 
     221                    $filter =  $ldapService->getSearchFilter($find); 
     222                    $fields = array('cn','dn'); 
     223                    $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'], $this->src_info['acc'], $this->src_info['pw'], true); 
     224                    $result_r = ldap_search($ldap , $this->src_info['context'], $filter, $fields); 
     225 
     226 
     227                    if (!$result_r) 
     228                    { 
     229                            return false; 
     230                    } 
     231 
     232                    if ($other['order']) 
     233                    { 
     234                            $sort_f = array($other['order']); 
     235                            $ldap_sort_by = $this->translate_fields($sort_f, $restric_fields); 
     236                    } 
     237 
     238                    if ($ldap_sort_by) 
     239                    { 
     240                            if (!ldap_sort($ldap, $result_r, $ldap_sort_by[$other['order']][0])) 
     241                            { 
     242                                    return false; 
     243                            } 
     244                    } 
     245 
     246                    $iTotalEntries = ldap_count_entries( $ldap, $result_r ); 
     247 
     248                    if($iTotalEntries < 1 ) 
     249                            return true; 
     250 
     251                    $iEnd = $iTotalEntries; 
     252 
     253                    $return = array(); 
     254 
     255                    $rEntry = ldap_first_entry( $ldap, $result_r ); 
     256                    for ( $iCurrent = 0; $iCurrent < $iEnd ;$iCurrent++) 
     257                    { 
     258 
     259                        $result_p = ldap_get_attributes($ldap, $rEntry ); 
     260 
     261                        $returnTemp = array(); 
     262                        $returnTemp['id_contact'] = ldap_get_dn($ldap, $rEntry); 
     263                        $returnTemp['names_ordered'] = $result_p['cn']['0']; 
     264 
     265                        array_push( $return, $returnTemp ); 
     266                        $rEntry = ldap_next_entry( $ldap, $rEntry ); 
     267 
     268                    } 
     269 
     270 
     271                    usort($return, array($this, "compareObjects")); 
     272                    return $return; 
     273                } 
     274 
    211275                // Compare function for usort. 
    212276                function compareObjects($a, $b) { 
  • sandbox/2.2.0.2/contactcenter/inc/class.bo_ldap_manager.inc.php

    r4500 r4538  
    5757                                                'branch' => $ou, //strtolower('ou'), 
    5858                                                'montaDN'=> $subLevels, //$data['cc_ldap_subLevels'], 
    59                                                 'visible'=> $data['cc_ldap_query_automatic'] 
     59                                                'visible'=> $data['cc_ldap_query_automatic'], 
     60                                                'max_results' => $data['cc_ldap_max_results'] 
    6061                                        ) 
    6162                                ); 
     
    9394                /* 
    9495                * @function get_external_ldap_sources 
    95                 * @author Mï¿œrio Cï¿œsar Kolling <mario.kolling@serpro.gov.br> 
     96                * @author Mário César Kolling <mario.kolling@serpro.gov.br> 
    9697                * @abstract returns an array with the external sources 
    9798                * @return (array) the external sources 
  • sandbox/2.2.0.2/contactcenter/inc/class.ui_data.inc.php

    r4513 r4538  
    31723172                        if (!is_array($data) || (!$data['search_for'] && !$full_search) || !is_array($data['fields'])) 
    31733173                        { 
    3174                                 echo serialize(array( 
    3175                                         'msg'    => lang('Invalid parameters'), 
    3176                                         'status' => 'abort' 
    3177                                 )); 
    3178  
    3179                                 return array('error' => lang('Invalid parameters')); 
     3174                            echo serialize(array( 
     3175                                    'msg'    => lang('Invalid parameters'), 
     3176                                    'status' => 'abort' 
     3177                            )); 
     3178 
     3179                            return array('error' => lang('Invalid parameters')); 
    31803180                        } 
    31813181 
     
    32113211                        else 
    32123212                        { 
    3213                                 $names = explode(' ', $data['search_for']); 
    3214  
    3215                                 if (!is_array($names)) 
    3216                                 { 
    3217                                         if(!$full_search) { 
    3218                                                 echo serialize(array( 
    3219                                                         'msg'    => lang('Invalid Search Parameter'), 
    3220                                                         'status' => 'abort' 
    3221                                                 )); 
    3222                                                 exit; 
    3223                                         } 
    3224                                         else  
    3225                                                 $names = array(); 
    3226  
    3227                                 } 
     3213                            $names = explode(' ', $data['search_for']); 
     3214 
     3215                            if (!is_array($names)) 
     3216                            { 
     3217                                    if(!$full_search) { 
     3218                                            echo serialize(array( 
     3219                                                    'msg'    => lang('Invalid Search Parameter'), 
     3220                                                    'status' => 'abort' 
     3221                                            )); 
     3222                                            exit; 
     3223                                    } 
     3224                                    else  
     3225                                            $names = array(); 
     3226 
     3227                            } 
    32283228 
    32293229                                if (!$external && $this->page_info['actual_catalog']['class'] != 'bo_people_catalog' && 
     
    32873287                                                        array_push($rules,array( 
    32883288                                                                                        'field' => $this->aux_full_search($field,false), 
    3289                                                                                         'type' => 'iLIKE', 
    3290                                                                                         'value' => '%'.$value.'%' 
     3289                                                                                        'type'  => 'LIKE and ~=', 
     3290                                                                                        'value' => $name 
    32913291                                                                                        )); 
    3292                                         } 
     3292                                                } 
    32933293                                 
    32943294                                } 
     
    33003300                                                array_push($rules, array( 
    33013301                                                        'field' => $data['fields']['search'], 
    3302                                                         'type'  => 'iLIKE', 
    3303                                                         'value' => '%'.$name.'%' 
     3302                                                        'type'  => 'LIKE and ~=', 
     3303                                                        'value' => $name 
    33043304                                                )); 
    33053305                                        } 
  • sandbox/2.2.0.2/contactcenter/templates/classic/config.tpl

    r285 r4538  
    6060                </td> 
    6161        </tr> 
     62        <tr class="row_on"> 
     63                <td>{lang_LDAP_max_results}:</td> 
     64                <td><input name="newsettings[cc_ldap_max_results]" value="{value_cc_ldap_max_results}" size="40" /></td> 
     65        </tr> 
     66 
    6267   
    6368  <!-- <tr class="row_on"> 
  • sandbox/2.2.0.2/contactcenter/templates/default/config.tpl

    r4500 r4538  
    5353                <td><input name="newsettings[cc_ldap_pw0]" type="password" value="" size="40" /></td> 
    5454        </tr> 
     55        <tr class="row_on"> 
     56                <td>{lang_LDAP_max_results}:</td> 
     57                <td><input name="newsettings[cc_ldap_max_results]" value="{value_cc_ldap_max_results}" size="40" /></td> 
     58        </tr> 
    5559        <tr class="row_off"> 
    5660                <td>{lang_Open_automatic_contact} :</td> 
     
    6266                </td> 
    6367        </tr> 
    64         <tr class="row_on"> 
     68        <tr class="row_off"> 
    6569                <td>{lang_Minimal_character_to_name_search}:</td> 
    6670                <td> 
     
    7276                </td> 
    7377        </tr> 
    74         <tr class="row_off"> 
     78        <tr class="row_on"> 
    7579                <td>Montar DN do contatos dinamicamente?</td> 
    7680                <td> 
     
    143147                <td><input type="text" size="40" name="newsettings[cc_ldap_ass_fulln0]" value="{value_cc_ldap_ass_fulln0}"></td> 
    144148        </tr>--> 
    145         <tr class="th"> 
    146                 <td colspan="2" align="center"><b>{lang_Extended_search_configuration}:</b></td> 
    147         </tr> 
    148         <tr> 
    149                 <td></td> 
    150         </tr> 
    151         <tr class="row_off"> 
    152                 <td>{lang_LDAP_attribute_to_search} :</td> 
    153                 <td><input name="newsettings[cc_ldap_atrib]" value="{value_cc_ldap_atrib}" size="40" /></td> 
    154         </tr> 
    155         <tr class="row_on"> 
    156                 <td>{lang_Label} :</td> 
    157                 <td><input name="newsettings[cc_ldap_legend]" value="{value_cc_ldap_legend}" size="40" /></td> 
    158         </tr> 
    159  
     149         
     150         
    160151<!-- END body --> 
    161152<!-- BEGIN footer --> 
Note: See TracChangeset for help on using the changeset viewer.