alecpl
2010-05-10 25fdec592dc0a37c6ccb0d566e288807aacf9114
- Fix autocomplete shows entries without email (#1486452)


4 files modified
44 ■■■■ changed files
CHANGELOG 1 ●●●● patch | view | raw | blame | history
program/include/rcube_contacts.php 28 ●●●● patch | view | raw | blame | history
program/include/rcube_ldap.php 13 ●●●●● patch | view | raw | blame | history
program/steps/mail/autocomplete.inc 2 ●●● patch | view | raw | blame | history
CHANGELOG
@@ -1,6 +1,7 @@
CHANGELOG RoundCube Webmail
===========================
- Fix autocomplete shows entries without email (#1486452)
- Fix listupdate event doesn't trigger on search response (#1486708)
- Fix select_all_mode value after selecting a message (#1486720)
- Set focus to editor on reply in HTML mode (#1486632)
program/include/rcube_contacts.php
@@ -215,28 +215,42 @@
     * @param boolean True for strict (=), False for partial (LIKE) matching
     * @param boolean True if results are requested, False if count only
     * @param boolean True to skip the count query (select only)
     * @param array   List of fields that cannot be empty
     * @return Indexed list of contact records and 'count' value
     */
    function search($fields, $value, $strict=false, $select=true, $nocount=false)
    function search($fields, $value, $strict=false, $select=true, $nocount=false, $required=array())
    {
        if (!is_array($fields))
            $fields = array($fields);
        if (!is_array($required) && !empty($required))
            $required = array($required);
        $add_where = array();
        $where = $and_where = array();
        foreach ($fields as $col) {
            if ($col == 'ID' || $col == $this->primary_key) {
                $ids         = !is_array($value) ? explode(',', $value) : $value;
                $ids         = $this->db->array2list($ids, 'integer');
                $add_where[] = 'c.' . $this->primary_key.' IN ('.$ids.')';
                $where[] = 'c.' . $this->primary_key.' IN ('.$ids.')';
            }
            else if ($strict)
                $add_where[] = $this->db->quoteIdentifier($col).'='.$this->db->quote($value);
                $where[] = $this->db->quoteIdentifier($col).' = '.$this->db->quote($value);
            else
                $add_where[] = $this->db->ilike($col, '%'.$value.'%');
                $where[] = $this->db->ilike($col, '%'.$value.'%');
        }
    
        if (!empty($add_where)) {
            $this->set_search_set(join(' OR ', $add_where));
        foreach ($required as $col) {
            $and_where[] = $this->db->quoteIdentifier($col).' <> '.$this->db->quote('');
        }
        if (!empty($where))
            $where = join(' OR ', $where);
        if (!empty($and_where))
            $where = ($where ? "($where) AND " : '') . join(' AND ', $and_where);
        if (!empty($where)) {
            $this->set_search_set($where);
            if ($select)
                $this->list_records(null, 0, $nocount);
            else
program/include/rcube_ldap.php
@@ -306,9 +306,11 @@
   * @param string  Search value
   * @param boolean True for strict, False for partial (fuzzy) matching
   * @param boolean True if results are requested, False if count only
   * @param boolean (Not used)
   * @param array   List of fields that cannot be empty
   * @return array  Indexed list of contact records and 'count' value
   */
  function search($fields, $value, $strict=false, $select=true)
  function search($fields, $value, $strict=false, $select=true, $nocount=false, $required=array())
  {
    // special treatment for ID-based search
    if ($fields == 'ID' || $fields == $this->primary_key)
@@ -340,6 +342,15 @@
    }
    $filter .= ')';
    
    // add required (non empty) fields filter
    $req_filter = '';
    foreach ((array)$required as $field)
      if ($f = $this->_map_field($field))
        $req_filter .= "($f=*)";
    if (!empty($req_filter))
      $filter = '(&' . $req_filter . $filter . ')';
    // avoid double-wildcard if $value is empty
    $filter = preg_replace('/\*+/', '*', $filter);
    
program/steps/mail/autocomplete.inc
@@ -42,7 +42,7 @@
    $abook = $RCMAIL->get_address_book($id);
    $abook->set_pagesize($MAXNUM);
    if ($result = $abook->search(array('email','name'), $search, false, true, true)) {
    if ($result = $abook->search(array('email','name'), $search, false, true, true, 'email')) {
      while ($sql_arr = $result->iterate()) {
          $contacts[] = format_email_recipient($sql_arr['email'], $sql_arr['name']);
          if (count($contacts) >= $MAXNUM)