From 341342bc39f121f5e4b06b91055fc6db00647c43 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 12 Jun 2013 14:12:58 +0000 Subject: [PATCH] fixed not working multiple value "select-account" or "home-accounts" (rows > 1) custom fields --- addressbook/inc/class.addressbook_sql.inc.php | 30 ++----------------- etemplate/inc/class.so_sql_cf.inc.php | 19 +++++++----- infolog/inc/class.infolog_so.inc.php | 5 ++-- 3 files changed, 17 insertions(+), 37 deletions(-) diff --git a/addressbook/inc/class.addressbook_sql.inc.php b/addressbook/inc/class.addressbook_sql.inc.php index 9f01ad2ec3..e5666e5a05 100644 --- a/addressbook/inc/class.addressbook_sql.inc.php +++ b/addressbook/inc/class.addressbook_sql.inc.php @@ -1,11 +1,11 @@ * @package addressbook - * @copyright (c) 2006-12 by Ralf Becker + * @copyright (c) 2006-13 by Ralf Becker * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @version $Id$ */ @@ -816,31 +816,7 @@ class addressbook_sql extends so_sql_cf */ function save_customfields($data) { - foreach ((array)$this->customfields as $name => $options) - { - if (!isset($data[$field = $this->get_cf_field($name)])) continue; - - $where = array( - $this->extra_id => $data['id'], - $this->extra_key => $name, - ); - $is_multiple = $this->is_multiple($name); - - // we explicitly need to delete fields, if value is empty or field allows multiple values or we have no unique index - if(empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index) - { - $this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app); - if (empty($data[$field])) continue; // nothing else to do for empty values - } - foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) : (array)$data[$field] as $value) - { - if (!$this->db->insert($this->extra_table,array($this->extra_value => $value, 'contact_owner' => $data['owner']),$where,__LINE__,__FILE__,$this->app)) - { - return $this->db->Errno; - } - } - } - return false; // no error + return parent::save_customfields($data, array('contact_owner' => $data['owner'])); } /** diff --git a/etemplate/inc/class.so_sql_cf.inc.php b/etemplate/inc/class.so_sql_cf.inc.php index bd55b7d6c1..1738026e8b 100644 --- a/etemplate/inc/class.so_sql_cf.inc.php +++ b/etemplate/inc/class.so_sql_cf.inc.php @@ -1,12 +1,12 @@ - * @copyright 2009 by RalfBecker@outdoor-training.de + * @copyright 2009-13 by RalfBecker@outdoor-training.de * @version $Id$ */ @@ -206,16 +206,17 @@ class so_sql_cf extends so_sql * saves custom field data * * @param array $data data to save (cf's have to be prefixed with self::CF_PREFIX = #) + * @param array $extra_cols=array() * @return bool false on success, errornumber on failure */ - function save_customfields($data) + function save_customfields($data, array $extra_cols=array()) { foreach ((array)$this->customfields as $name => $options) { if (!isset($data[$field = $this->get_cf_field($name)])) continue; $where = array( - $this->extra_id => $data[$this->autoinc_id], + $this->extra_id => isset($data[$this->autoinc_id]) ? $data[$this->autoinc_id] : $data[$this->db_key_cols[$this->autoinc_id]], $this->extra_key => $name, ); $is_multiple = $this->is_multiple($name); @@ -226,9 +227,11 @@ class so_sql_cf extends so_sql $this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app); if (empty($data[$field])) continue; // nothing else to do for empty values } - foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) : (array)$data[$field] as $value) + foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) : + // regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated + (array)(!$is_multiple && is_array($data[$field]) ? implode(',', $data[$field]) : $data[$field]) as $value) { - if (!$this->db->insert($this->extra_table,array($this->extra_value => $value),$where,__LINE__,__FILE__,$this->app)) + if (!$this->db->insert($this->extra_table,array($this->extra_value => $value)+$extra_cols,$where,__LINE__,__FILE__,$this->app)) { return $this->db->Errno; } @@ -590,11 +593,11 @@ class so_sql_cf extends so_sql elseif(is_int($name) && $this->is_cf($val)) // lettersearch: #cfname LIKE 's%' { $_cf = explode(' ',$val); - foreach($_cf as $ci => $cf_np) + foreach($_cf as $ci => $cf_np) { // building cf_name by glueing parts together (, in case someone used whitespace in their custom field names) $tcf_name = ($tcf_name?$tcf_name.' ':'').$cf_np; - // reacts on the first one found that matches an existing customfield, should be better then the old behavior of + // reacts on the first one found that matches an existing customfield, should be better then the old behavior of // simply splitting by " " and using the first part if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn,(array)$_cfnames,true)!==false ) { diff --git a/infolog/inc/class.infolog_so.inc.php b/infolog/inc/class.infolog_so.inc.php index fc89ce75c4..7af62966d8 100644 --- a/infolog/inc/class.infolog_so.inc.php +++ b/infolog/inc/class.infolog_so.inc.php @@ -5,7 +5,7 @@ * @link http://www.egroupware.org * @author Ralf Becker * @package infolog - * @copyright (c) 2003-11 by Ralf Becker + * @copyright (c) 2003-13 by Ralf Becker * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @version $Id$ */ @@ -599,7 +599,8 @@ class infolog_so if ($val) { $this->db->insert($this->extra_table,array( - 'info_extra_value' => is_array($val) ? serialize($val) : $val, + // store multivalued CalDAV properties as serialized array, everything else get comma-separated + 'info_extra_value' => is_array($val) ? ($key[1] == '#' ? serialize($val) : implode(',',$val)) : $val, ),array( 'info_id' => $info_id, 'info_extra_name' => substr($key,1),