From f466899d8dba6826c060f403cdeba843344d1bf9 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Tue, 31 May 2016 09:18:44 +0200 Subject: [PATCH] Simplified code --- program/lib/Roundcube/rcube_contacts.php | 25 +++++------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/program/lib/Roundcube/rcube_contacts.php b/program/lib/Roundcube/rcube_contacts.php index f2de8a3313a..a5f03bc7c6f 100644 --- a/program/lib/Roundcube/rcube_contacts.php +++ b/program/lib/Roundcube/rcube_contacts.php @@ -237,7 +237,7 @@ function list_records($cols = null, $subset = 0, $nocount = false) " WHERE c.`del` <> 1" . " AND c.`user_id` = ?" . ($this->group_id ? " AND m.`contactgroup_id` = ?" : ""). - ($this->filter ? " AND (".$this->filter.")" : "") . + ($this->filter ? " AND ".$this->filter : "") . " ORDER BY ". $this->db->concat($order_cols) . " " . $this->sort_order, $start_row, @@ -314,25 +314,13 @@ function search($fields, $value, $mode = 0, $select = true, $nocount = false, $r foreach ((array)$fields as $idx => $col) { $val = $value[$idx]; - if (!strlen($val)) + if (!strlen($val)) { continue; + } // table column if (in_array($col, $this->table_cols)) { - switch ($mode) { - case 1: // strict - $where[] = '(' . $this->db->quote_identifier($col) . ' = ' . $this->db->quote($val) - . ' OR ' . $this->db->ilike($col, $val . $AS . '%') - . ' OR ' . $this->db->ilike($col, '%' . $AS . $val . $AS . '%') - . ' OR ' . $this->db->ilike($col, '%' . $AS . $val) . ')'; - break; - case 2: // prefix - $where[] = '(' . $this->db->ilike($col, $val . '%') - . ' OR ' . $this->db->ilike($col, $AS . $val . '%') . ')'; - break; - default: // partial - $where[] = $this->db->ilike($col, '%' . $val . '%'); - } + $where[] = $this->fulltext_sql_where($val, $mode, $col); } // vCard field else { @@ -360,7 +348,7 @@ function search($fields, $value, $mode = 0, $select = true, $nocount = false, $r } foreach (array_intersect($required, $this->table_cols) as $col) { - $and_where[] = $this->db->quote_identifier($col).' <> '.$this->db->quote(''); + $where[] = $this->db->quote_identifier($col).' <> '.$this->db->quote(''); } $required = array_diff($required, $this->table_cols); @@ -369,9 +357,6 @@ function search($fields, $value, $mode = 0, $select = true, $nocount = false, $r $where = join(" AND ", $where); } - if (!empty($and_where)) - $where = ($where ? "($where) AND " : '') . join(' AND ', $and_where); - // Post-searching in vCard data fields // we will search in all records and then build a where clause for their IDs if (!empty($post_search) || !empty($required)) {