Changeset 25fdec5 in github


Ignore:
Timestamp:
May 10, 2010 3:38:45 PM (3 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
1ac779f
Parents:
5933d98
Message:
  • Fix autocomplete shows entries without email (#1486452)
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    rc833ed4 r25fdec5  
    22=========================== 
    33 
     4- Fix autocomplete shows entries without email (#1486452) 
    45- Fix listupdate event doesn't trigger on search response (#1486708) 
    56- Fix select_all_mode value after selecting a message (#1486720) 
  • program/include/rcube_contacts.php

    ra004bb8 r25fdec5  
    3939    private $cache; 
    4040    private $table_cols = array('name', 'email', 'firstname', 'surname', 'vcard'); 
    41    
     41 
    4242    /** public properties */ 
    4343    var $primary_key = 'contact_id'; 
     
    4949    var $ready = false; 
    5050 
    51    
     51 
    5252    /** 
    5353     * Object constructor 
     
    7676    } 
    7777 
    78    
     78 
    7979    /** 
    8080     * Getter for saved search properties 
     
    110110        $this->cache = null; 
    111111    } 
    112    
     112 
    113113 
    114114    /** 
     
    121121    { 
    122122        $results = array(); 
    123      
     123 
    124124        if (!$this->groups) 
    125125            return $results; 
     
    189189            $this->result->add($sql_arr); 
    190190        } 
    191      
     191 
    192192        $cnt = count($this->result->records); 
    193193 
     
    203203                $this->result->count = $this->_count(); 
    204204        } 
    205      
     205 
    206206        return $this->result; 
    207207    } 
     
    216216     * @param boolean True if results are requested, False if count only 
    217217     * @param boolean True to skip the count query (select only) 
     218     * @param array   List of fields that cannot be empty 
    218219     * @return Indexed list of contact records and 'count' value 
    219220     */ 
    220     function search($fields, $value, $strict=false, $select=true, $nocount=false) 
     221    function search($fields, $value, $strict=false, $select=true, $nocount=false, $required=array()) 
    221222    { 
    222223        if (!is_array($fields)) 
    223224            $fields = array($fields); 
    224  
    225         $add_where = array(); 
     225        if (!is_array($required) && !empty($required)) 
     226            $required = array($required); 
     227 
     228        $where = $and_where = array(); 
     229 
    226230        foreach ($fields as $col) { 
    227231            if ($col == 'ID' || $col == $this->primary_key) { 
    228                 $ids         = !is_array($value) ? explode(',', $value) : $value; 
    229                 $ids         = $this->db->array2list($ids, 'integer'); 
    230                 $add_where[] = 'c.' . $this->primary_key.' IN ('.$ids.')'; 
     232                $ids     = !is_array($value) ? explode(',', $value) : $value; 
     233                $ids     = $this->db->array2list($ids, 'integer'); 
     234                $where[] = 'c.' . $this->primary_key.' IN ('.$ids.')'; 
    231235            } 
    232236            else if ($strict) 
    233                 $add_where[] = $this->db->quoteIdentifier($col).'='.$this->db->quote($value); 
     237                $where[] = $this->db->quoteIdentifier($col).' = '.$this->db->quote($value); 
    234238            else 
    235                 $add_where[] = $this->db->ilike($col, '%'.$value.'%'); 
    236         } 
    237      
    238         if (!empty($add_where)) { 
    239             $this->set_search_set(join(' OR ', $add_where)); 
     239                $where[] = $this->db->ilike($col, '%'.$value.'%'); 
     240        } 
     241 
     242        foreach ($required as $col) { 
     243            $and_where[] = $this->db->quoteIdentifier($col).' <> '.$this->db->quote(''); 
     244        } 
     245 
     246        if (!empty($where)) 
     247            $where = join(' OR ', $where); 
     248 
     249        if (!empty($and_where)) 
     250            $where = ($where ? "($where) AND " : '') . join(' AND ', $and_where); 
     251 
     252        if (!empty($where)) { 
     253            $this->set_search_set($where); 
    240254            if ($select) 
    241255                $this->list_records(null, 0, $nocount); 
     
    256270    { 
    257271        $count = isset($this->cache['count']) ? $this->cache['count'] : $this->_count(); 
    258      
     272 
    259273        return new rcube_result_set($count, ($this->list_page-1) * $this->page_size); 
    260274    } 
     
    271285            $join = " LEFT JOIN ".get_table_name('contactgroupmembers')." AS m". 
    272286                " ON (m.contact_id=c.".$this->primary_key.")"; 
    273        
     287 
    274288        // count contacts for this user 
    275289        $sql_result = $this->db->query( 
     
    302316        return $this->result; 
    303317    } 
    304    
    305    
     318 
     319 
    306320    /** 
    307321     * Get a specific contact record 
     
    315329        if ($this->result && ($first = $this->result->first()) && $first[$this->primary_key] == $id) 
    316330            return $assoc ? $first : $this->result; 
    317        
     331 
    318332        $this->db->query( 
    319333            "SELECT * FROM ".$this->db_name. 
     
    423437            $updated = $this->db->affected_rows(); 
    424438        } 
    425      
     439 
    426440        return $updated; 
    427441    } 
     
    478492        // make sure we have a unique name 
    479493        $name = $this->unique_groupname($name); 
    480      
     494 
    481495        $this->db->query( 
    482496            "INSERT INTO ".get_table_name('contactgroups'). 
     
    484498            " VALUES (".intval($this->user_id).", ".$this->db->now().", ".$this->db->quote($name).")" 
    485499        ); 
    486      
     500 
    487501        if ($insert_id = $this->db->insert_id('contactgroups')) 
    488502            $result = array('id' => $insert_id, 'name' => $name); 
    489      
     503 
    490504        return $result; 
    491505    } 
     
    525539        // make sure we have a unique name 
    526540        $name = $this->unique_groupname($newname); 
    527      
     541 
    528542        $sql_result = $this->db->query( 
    529543            "UPDATE ".get_table_name('contactgroups'). 
     
    548562        if (!is_array($ids)) 
    549563            $ids = explode(',', $ids); 
    550      
     564 
    551565        $added = 0; 
    552      
     566 
    553567        foreach ($ids as $contact_id) { 
    554568            $sql_result = $this->db->query( 
     
    613627        $checkname = $name; 
    614628        $num = 2; $hit = false; 
    615      
     629 
    616630        do { 
    617631            $sql_result = $this->db->query( 
     
    622636                $this->user_id, 
    623637                $checkname); 
    624      
     638 
    625639            // append number to make name unique 
    626640            if ($hit = $this->db->num_rows($sql_result)) 
    627641                $checkname = $name . ' ' . $num++; 
    628642        } while ($hit > 0); 
    629      
     643 
    630644        return $checkname; 
    631645    } 
  • program/include/rcube_ldap.php

    r93c01888 r25fdec5  
    307307   * @param boolean True for strict, False for partial (fuzzy) matching 
    308308   * @param boolean True if results are requested, False if count only 
     309   * @param boolean (Not used) 
     310   * @param array   List of fields that cannot be empty 
    309311   * @return array  Indexed list of contact records and 'count' value 
    310312   */ 
    311   function search($fields, $value, $strict=false, $select=true) 
     313  function search($fields, $value, $strict=false, $select=true, $nocount=false, $required=array()) 
    312314  { 
    313315    // special treatment for ID-based search 
     
    340342    } 
    341343    $filter .= ')'; 
    342      
     344 
     345    // add required (non empty) fields filter 
     346    $req_filter = ''; 
     347    foreach ((array)$required as $field) 
     348      if ($f = $this->_map_field($field)) 
     349        $req_filter .= "($f=*)"; 
     350 
     351    if (!empty($req_filter)) 
     352      $filter = '(&' . $req_filter . $filter . ')'; 
     353 
    343354    // avoid double-wildcard if $value is empty 
    344355    $filter = preg_replace('/\*+/', '*', $filter); 
    345      
     356 
    346357    // add general filter to query 
    347358    if (!empty($this->prop['filter'])) 
  • program/steps/mail/autocomplete.inc

    r53d6261 r25fdec5  
    3232    while ($result && ($sql_arr = $result->iterate())) 
    3333      $members[] = format_email_recipient($sql_arr['email'], $sql_arr['name']); 
    34        
     34 
    3535    $OUTPUT->command('replace_group_recipients', $gid, join(', ', $members)); 
    3636  } 
     
    4343    $abook->set_pagesize($MAXNUM); 
    4444 
    45     if ($result = $abook->search(array('email','name'), $search, false, true, true)) { 
     45    if ($result = $abook->search(array('email','name'), $search, false, true, true, 'email')) { 
    4646      while ($sql_arr = $result->iterate()) { 
    4747          $contacts[] = format_email_recipient($sql_arr['email'], $sql_arr['name']); 
     
    5050      } 
    5151    } 
    52      
     52 
    5353    // also list matching contact groups 
    5454    if ($abook->groups) { 
     
    5757        $abook->set_group($group['ID']); 
    5858        $result = $abook->count(); 
    59          
     59 
    6060        if ($result->count) { 
    6161          $contacts[] = array('name' => $group['name'] . ' (' . intval($result->count) . ')', 'id' => $group['ID'], 'source' => $id); 
     
    6666    } 
    6767  } 
    68    
     68 
    6969  usort($contacts, 'contact_results_sort'); 
    7070} 
Note: See TracChangeset for help on using the changeset viewer.