forked from extern/egroupware
fixed not working multiple value "select-account" or "home-accounts" (rows > 1) custom fields
This commit is contained in:
parent
547feb2391
commit
341342bc39
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Addressbook - SQL backend
|
||||
* EGroupware : Addressbook - SQL backend
|
||||
*
|
||||
* @link http://www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @package addressbook
|
||||
* @copyright (c) 2006-12 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2006-13 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @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']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare generalized SQL Storage Object with build in custom field support
|
||||
* EGroupware generalized SQL Storage Object with build in custom field support
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package etemplate
|
||||
* @link http://www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
||||
* @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 )
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @link http://www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @package infolog
|
||||
* @copyright (c) 2003-11 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2003-13 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @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),
|
||||
|
Loading…
Reference in New Issue
Block a user