From 61d0659715455c905142d1b842ea2059d657c6b8 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 15 May 2007 14:23:28 +0000 Subject: [PATCH] fix for bug #450: Advanced search does not work regarding categories --- addressbook/inc/class.socontacts_sql.inc.php | 22 ++++++++++++++++++++ addressbook/inc/class.uicontacts.inc.php | 11 ++++++++++ 2 files changed, 33 insertions(+) diff --git a/addressbook/inc/class.socontacts_sql.inc.php b/addressbook/inc/class.socontacts_sql.inc.php index cda7f2d30c..bd44cf8c20 100644 --- a/addressbook/inc/class.socontacts_sql.inc.php +++ b/addressbook/inc/class.socontacts_sql.inc.php @@ -276,6 +276,11 @@ class socontacts_sql extends so_sql $criteria[] = $this->db->expression($this->extra_table,'(',array('contact_name'=>substr($col,1),'contact_value'=>$val),')'); $search_customfields = true; } + elseif($col == 'cat_id') // search in comma-sep. cat-column + { + $criteria = array_merge($criteria,$this->_cat_search($val)); + unset($criteria[$col]); + } } } if ($search_customfields) // search the custom-fields @@ -345,6 +350,23 @@ class socontacts_sql extends so_sql return '('.implode(' OR ',$cat_filter).')'; } + /** + * fix cat_id criteria to search in comma-separated multiple cats + * + * @internal + * @param int/array $cats + * @return array of sql-strings to be OR'ed or AND'ed together + */ + function _cat_search($cats) + { + $cat_filter = array(); + foreach(is_array($cats) ? $cats : array($cats) as $cat) + { + if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; + } + return $cat_filter; + } + /** * Change the ownership of contacts owned by a given account * diff --git a/addressbook/inc/class.uicontacts.inc.php b/addressbook/inc/class.uicontacts.inc.php index 79eec797ad..d1d5e07b59 100644 --- a/addressbook/inc/class.uicontacts.inc.php +++ b/addressbook/inc/class.uicontacts.inc.php @@ -1527,6 +1527,17 @@ $readonlys['button[vcard]'] = true; '%' => lang('contains'), false => lang('exact'), ); + if ($this->customfields) + { + foreach($this->customfields as $name => $data) + { + if ($data['type'] == 'select') + { + if (!isset($content['#'.$name])) $content['#'.$name] = ''; + if(!isset($data['values'][''])) $sel_options['#'.$name][''] = lang('Select one'); + } + } + } // configure edit template as search dialog $readonlys['change_photo'] = true; $readonlys['fileas_type'] = true;