From 41a0727481ad099cdd98aad8e3e287ac5e0af57a Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio Date: Wed, 18 Apr 2018 18:02:38 +0200 Subject: [PATCH 1/3] NEW: work on CommonObject 'array' field type --- htdocs/core/class/commonobject.class.php | 56 ++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index f7e0d451506..0fe540cb3ac 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5555,6 +5555,39 @@ abstract class CommonObject // If prefix is 'search_', field is used as a filter, we use a common text field. $out=''; } + elseif ($type == 'array') + { + $newval = $val; + $newval['type'] = 'varchar(256)'; + + $out=''; + + $inputs = array(); + if(! empty($value)) { + foreach($value as $option) { + $out.= ' '; + $out.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $showsize).'
'; + } + } + + $out.= ''; + + $newInput = ' '; + $newInput.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'
'; + + $out.= ' +'; + } if (!empty($hidden)) { $out=''; } @@ -5926,6 +5959,10 @@ abstract class CommonObject { $value=preg_replace('/./i','*',$value); } + elseif ($type == 'array') + { + $value = implode('
', $value); + } //print $type.'-'.$size; $out=$value; @@ -6614,7 +6651,14 @@ abstract class CommonObject } else if($this->isArray($info)) { - $queryarray[$field] = serialize($this->{$field}); + if(! empty($this->{$field})) { + if(! is_array($this->{$field})) { + $this->{$field} = array($this->{$field}); + } + $queryarray[$field] = serialize($this->{$field}); + } else { + $queryarray[$field] = NULL; + } } else if($this->isInt($info)) { @@ -6658,9 +6702,13 @@ abstract class CommonObject } elseif($this->isArray($info)) { - $this->{$field} = @unserialize($obj->{$field}); - // Hack for data not in UTF8 - if($this->{$field } === false) @unserialize(utf8_decode($obj->{$field})); + if(! empty($obj->{$field})) { + $this->{$field} = @unserialize($obj->{$field}); + // Hack for data not in UTF8 + if($this->{$field } === false) @unserialize(utf8_decode($obj->{$field})); + } else { + $this->{$field} = array(); + } } elseif($this->isInt($info)) { From 2bf66780cbb788a0c068f11e360de1316a52577a Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio Date: Thu, 19 Apr 2018 10:25:19 +0200 Subject: [PATCH 2/3] FIX: travis + code readability --- htdocs/core/class/commonobject.class.php | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 0fe540cb3ac..e3c93618b08 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5566,27 +5566,27 @@ abstract class CommonObject if(! empty($value)) { foreach($value as $option) { $out.= ' '; - $out.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $showsize).'
'; + $out.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $showsize).'
'; } } $out.= ''; $newInput = ' '; - $newInput.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'
'; + $newInput.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'
'; $out.= ' -'; + $(document).on("click", "a.'.dol_escape_js($keyprefix.$key.$keysuffix).'_del", function() { + $(this).parent().remove(); + }); + }); + '; } if (!empty($hidden)) { $out=''; @@ -5961,7 +5961,7 @@ $(document).ready(function() { } elseif ($type == 'array') { - $value = implode('
', $value); + $value = implode('
', $value); } //print $type.'-'.$size; From 39e890e2d75f76ca69d1587e2936786a5d76dbf0 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio Date: Fri, 20 Apr 2018 16:43:27 +0200 Subject: [PATCH 3/3] FIX: handle non-js users --- htdocs/core/class/commonobject.class.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index e3c93618b08..478bb3ea460 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5575,18 +5575,20 @@ abstract class CommonObject $newInput = ' '; $newInput.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'
'; - $out.= ' - '; + '; + } } if (!empty($hidden)) { $out='';