From 2ec2dc59a40534f78448a9044ce6b9690e802c2f Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Fri, 13 May 2022 14:55:21 +0200 Subject: [PATCH 1/4] New : import fields in societe class --- .../modules/import/import_csv.modules.php | 36 +++++++++++++---- .../modules/import/import_xlsx.modules.php | 39 +++++++++++++++---- htdocs/core/modules/modSociete.class.php | 20 ++++++++++ 3 files changed, 79 insertions(+), 16 deletions(-) diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index e45630df298..62f0ca6d387 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -709,15 +709,35 @@ class ImportCsv extends ModeleImports } // Define $listfields and $listvalues to build SQL request - $listfields[] = $fieldname; - - // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert - if (empty($newval) && $arrayrecord[($key - 1)]['type'] < 0) { - $listvalues[] = ($newval == '0' ? $newval : "null"); - } elseif (empty($newval) && $arrayrecord[($key - 1)]['type'] == 0) { - $listvalues[] = "''"; + if ($conf->socialnetworks->enabled && strpos($fieldname, "socialnetworks") !== false) { + if (!in_array("socialnetworks", $listfields)) { + $listfields[] = "socialnetworks"; + } + if (!empty($newval) && $arrayrecord[($key - 1)]['type'] > 0) { + $socialkey = array_search("socialnetworks", $listfields); + if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] == "null") { + $socialnetwork = explode("_", $fieldname)[1]; + $newvalue = '\'{ "'.$socialnetwork.'" : "'.$this->db->escape($newval).'" }\''; + $listvalues[$socialkey] = $newvalue; + } else { + $socialnetwork = explode("_", $fieldname)[1]; + $jsondata = $listvalues[$socialkey]; + $jsondata = str_replace("'", "", $jsondata); + $json = json_decode($jsondata); + $json->$socialnetwork = $this->db->escape($newval); + $listvalues[$socialkey] = "'".$this->db->escape(json_encode($json))."'"; + } + } } else { - $listvalues[] = "'".$this->db->escape($newval)."'"; + $listfields[] = $fieldname; + // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert + if (empty($newval) && $arrayrecord[($key - 1)]['type'] < 0) { + $listvalues[] = ($newval == '0' ? $newval : "null"); + } elseif (empty($newval) && $arrayrecord[($key - 1)]['type'] == 0) { + $listvalues[] = "''"; + } else { + $listvalues[] = "'".$this->db->escape($newval)."'"; + } } } $i++; diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php index 9fa5cbf2c44..a64063fa9af 100644 --- a/htdocs/core/modules/import/import_xlsx.modules.php +++ b/htdocs/core/modules/import/import_xlsx.modules.php @@ -363,6 +363,8 @@ class ImportXlsx extends ModeleImports $warning = 0; $this->errors = array(); $this->warnings = array(); + $this->nbinsert = 0; + $this->nbupdate = 0; //dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid); @@ -750,15 +752,36 @@ class ImportXlsx extends ModeleImports } // Define $listfields and $listvalues to build SQL request - $listfields[] = $fieldname; - - // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert - if (empty($newval) && $arrayrecord[($key)]['type'] < 0) { - $listvalues[] = ($newval == '0' ? $newval : "null"); - } elseif (empty($newval) && $arrayrecord[($key)]['type'] == 0) { - $listvalues[] = "''"; + if ($conf->socialnetworks->enabled && strpos($fieldname, "socialnetworks") !== false) { + if (!in_array("socialnetworks", $listfields)) { + $listfields[] = "socialnetworks"; + } + if (!empty($newval) && $arrayrecord[($key)]['type'] > 0) { + $socialkey = array_search("socialnetworks", $listfields); + if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] == "null") { + $socialnetwork = explode("_", $fieldname)[1]; + $newvalue = '\'{ "'.$socialnetwork.'" : "'.$this->db->escape($newval).'" }\''; + $listvalues[$socialkey] = $newvalue; + } else { + $socialnetwork = explode("_", $fieldname)[1]; + $jsondata = $listvalues[$socialkey]; + $jsondata = str_replace("'", "", $jsondata); + $json = json_decode($jsondata); + $json->$socialnetwork = $this->db->escape($newval); + $listvalues[$socialkey] = "'".$this->db->escape(json_encode($json))."'"; + } + } } else { - $listvalues[] = "'" . $this->db->escape($newval) . "'"; + $listfields[] = $fieldname; + + // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert + if (empty($newval) && $arrayrecord[($key)]['type'] < 0) { + $listvalues[] = ($newval == '0' ? $newval : "null"); + } elseif (empty($newval) && $arrayrecord[($key)]['type'] == 0) { + $listvalues[] = "''"; + } else { + $listvalues[] = "'" . $this->db->escape($newval) . "'"; + } } } $i++; diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index 09089d57563..84a5e97f1bf 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -519,6 +519,16 @@ class modSociete extends DolibarrModules if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) { $this->import_fields_array[$r] += array('s.accountancy_code_sell'=>'ProductAccountancySellCode', 's.accountancy_code_buy'=>'ProductAccountancyBuyCode'); } + // Add social networks fields + if (!empty($conf->socialnetworks->enabled)) { + $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1"; + $resql = $this->db->query($sql); + while ($obj = $this->db->fetch_object($resql)) { + $fieldname = 's.socialnetworks_'.$obj->code; + $fieldlabel = ucfirst($obj->label); + $this->import_fields_array[$r][$fieldname] = $fieldlabel; + } + } // Add extra fields $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'societe' AND entity IN (0, ".$conf->entity.")"; $resql = $this->db->query($sql); @@ -695,6 +705,16 @@ class modSociete extends DolibarrModules 's.note_private' => "NotePrivate", 's.note_public' => "NotePublic" ); + // Add social networks fields + if (!empty($conf->socialnetworks->enabled)) { + $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1"; + $resql = $this->db->query($sql); + while ($obj = $this->db->fetch_object($resql)) { + $fieldname = 's.socialnetworks_'.$obj->code; + $fieldlabel = ucfirst($obj->label); + $this->import_fields_array[$r][$fieldname] = $fieldlabel; + } + } // Add extra fields $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type != 'separate' AND elementtype = 'socpeople' AND entity IN (0, ".$conf->entity.")"; $resql = $this->db->query($sql); From cfc8ce2ea86ce423540cfb5536dd9b8de709db0c Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Fri, 13 May 2022 15:02:17 +0200 Subject: [PATCH 2/4] Revert "New : import fields in societe class" This reverts commit 2ec2dc59a40534f78448a9044ce6b9690e802c2f. --- .../modules/import/import_csv.modules.php | 36 ++++------------- .../modules/import/import_xlsx.modules.php | 39 ++++--------------- htdocs/core/modules/modSociete.class.php | 20 ---------- 3 files changed, 16 insertions(+), 79 deletions(-) diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index 62f0ca6d387..e45630df298 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -709,35 +709,15 @@ class ImportCsv extends ModeleImports } // Define $listfields and $listvalues to build SQL request - if ($conf->socialnetworks->enabled && strpos($fieldname, "socialnetworks") !== false) { - if (!in_array("socialnetworks", $listfields)) { - $listfields[] = "socialnetworks"; - } - if (!empty($newval) && $arrayrecord[($key - 1)]['type'] > 0) { - $socialkey = array_search("socialnetworks", $listfields); - if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] == "null") { - $socialnetwork = explode("_", $fieldname)[1]; - $newvalue = '\'{ "'.$socialnetwork.'" : "'.$this->db->escape($newval).'" }\''; - $listvalues[$socialkey] = $newvalue; - } else { - $socialnetwork = explode("_", $fieldname)[1]; - $jsondata = $listvalues[$socialkey]; - $jsondata = str_replace("'", "", $jsondata); - $json = json_decode($jsondata); - $json->$socialnetwork = $this->db->escape($newval); - $listvalues[$socialkey] = "'".$this->db->escape(json_encode($json))."'"; - } - } + $listfields[] = $fieldname; + + // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert + if (empty($newval) && $arrayrecord[($key - 1)]['type'] < 0) { + $listvalues[] = ($newval == '0' ? $newval : "null"); + } elseif (empty($newval) && $arrayrecord[($key - 1)]['type'] == 0) { + $listvalues[] = "''"; } else { - $listfields[] = $fieldname; - // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert - if (empty($newval) && $arrayrecord[($key - 1)]['type'] < 0) { - $listvalues[] = ($newval == '0' ? $newval : "null"); - } elseif (empty($newval) && $arrayrecord[($key - 1)]['type'] == 0) { - $listvalues[] = "''"; - } else { - $listvalues[] = "'".$this->db->escape($newval)."'"; - } + $listvalues[] = "'".$this->db->escape($newval)."'"; } } $i++; diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php index a64063fa9af..9fa5cbf2c44 100644 --- a/htdocs/core/modules/import/import_xlsx.modules.php +++ b/htdocs/core/modules/import/import_xlsx.modules.php @@ -363,8 +363,6 @@ class ImportXlsx extends ModeleImports $warning = 0; $this->errors = array(); $this->warnings = array(); - $this->nbinsert = 0; - $this->nbupdate = 0; //dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid); @@ -752,36 +750,15 @@ class ImportXlsx extends ModeleImports } // Define $listfields and $listvalues to build SQL request - if ($conf->socialnetworks->enabled && strpos($fieldname, "socialnetworks") !== false) { - if (!in_array("socialnetworks", $listfields)) { - $listfields[] = "socialnetworks"; - } - if (!empty($newval) && $arrayrecord[($key)]['type'] > 0) { - $socialkey = array_search("socialnetworks", $listfields); - if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] == "null") { - $socialnetwork = explode("_", $fieldname)[1]; - $newvalue = '\'{ "'.$socialnetwork.'" : "'.$this->db->escape($newval).'" }\''; - $listvalues[$socialkey] = $newvalue; - } else { - $socialnetwork = explode("_", $fieldname)[1]; - $jsondata = $listvalues[$socialkey]; - $jsondata = str_replace("'", "", $jsondata); - $json = json_decode($jsondata); - $json->$socialnetwork = $this->db->escape($newval); - $listvalues[$socialkey] = "'".$this->db->escape(json_encode($json))."'"; - } - } - } else { - $listfields[] = $fieldname; + $listfields[] = $fieldname; - // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert - if (empty($newval) && $arrayrecord[($key)]['type'] < 0) { - $listvalues[] = ($newval == '0' ? $newval : "null"); - } elseif (empty($newval) && $arrayrecord[($key)]['type'] == 0) { - $listvalues[] = "''"; - } else { - $listvalues[] = "'" . $this->db->escape($newval) . "'"; - } + // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert + if (empty($newval) && $arrayrecord[($key)]['type'] < 0) { + $listvalues[] = ($newval == '0' ? $newval : "null"); + } elseif (empty($newval) && $arrayrecord[($key)]['type'] == 0) { + $listvalues[] = "''"; + } else { + $listvalues[] = "'" . $this->db->escape($newval) . "'"; } } $i++; diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index 84a5e97f1bf..09089d57563 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -519,16 +519,6 @@ class modSociete extends DolibarrModules if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) { $this->import_fields_array[$r] += array('s.accountancy_code_sell'=>'ProductAccountancySellCode', 's.accountancy_code_buy'=>'ProductAccountancyBuyCode'); } - // Add social networks fields - if (!empty($conf->socialnetworks->enabled)) { - $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1"; - $resql = $this->db->query($sql); - while ($obj = $this->db->fetch_object($resql)) { - $fieldname = 's.socialnetworks_'.$obj->code; - $fieldlabel = ucfirst($obj->label); - $this->import_fields_array[$r][$fieldname] = $fieldlabel; - } - } // Add extra fields $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'societe' AND entity IN (0, ".$conf->entity.")"; $resql = $this->db->query($sql); @@ -705,16 +695,6 @@ class modSociete extends DolibarrModules 's.note_private' => "NotePrivate", 's.note_public' => "NotePublic" ); - // Add social networks fields - if (!empty($conf->socialnetworks->enabled)) { - $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1"; - $resql = $this->db->query($sql); - while ($obj = $this->db->fetch_object($resql)) { - $fieldname = 's.socialnetworks_'.$obj->code; - $fieldlabel = ucfirst($obj->label); - $this->import_fields_array[$r][$fieldname] = $fieldlabel; - } - } // Add extra fields $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type != 'separate' AND elementtype = 'socpeople' AND entity IN (0, ".$conf->entity.")"; $resql = $this->db->query($sql); From 1e406276c580939be97f4d76fc24bb9052206544 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Fri, 13 May 2022 15:04:30 +0200 Subject: [PATCH 3/4] New : import fields in societe class --- .../modules/import/import_csv.modules.php | 36 +++++++++++++---- .../modules/import/import_xlsx.modules.php | 39 +++++++++++++++---- htdocs/core/modules/modSociete.class.php | 20 ++++++++++ 3 files changed, 79 insertions(+), 16 deletions(-) diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index e45630df298..62f0ca6d387 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -709,15 +709,35 @@ class ImportCsv extends ModeleImports } // Define $listfields and $listvalues to build SQL request - $listfields[] = $fieldname; - - // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert - if (empty($newval) && $arrayrecord[($key - 1)]['type'] < 0) { - $listvalues[] = ($newval == '0' ? $newval : "null"); - } elseif (empty($newval) && $arrayrecord[($key - 1)]['type'] == 0) { - $listvalues[] = "''"; + if ($conf->socialnetworks->enabled && strpos($fieldname, "socialnetworks") !== false) { + if (!in_array("socialnetworks", $listfields)) { + $listfields[] = "socialnetworks"; + } + if (!empty($newval) && $arrayrecord[($key - 1)]['type'] > 0) { + $socialkey = array_search("socialnetworks", $listfields); + if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] == "null") { + $socialnetwork = explode("_", $fieldname)[1]; + $newvalue = '\'{ "'.$socialnetwork.'" : "'.$this->db->escape($newval).'" }\''; + $listvalues[$socialkey] = $newvalue; + } else { + $socialnetwork = explode("_", $fieldname)[1]; + $jsondata = $listvalues[$socialkey]; + $jsondata = str_replace("'", "", $jsondata); + $json = json_decode($jsondata); + $json->$socialnetwork = $this->db->escape($newval); + $listvalues[$socialkey] = "'".$this->db->escape(json_encode($json))."'"; + } + } } else { - $listvalues[] = "'".$this->db->escape($newval)."'"; + $listfields[] = $fieldname; + // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert + if (empty($newval) && $arrayrecord[($key - 1)]['type'] < 0) { + $listvalues[] = ($newval == '0' ? $newval : "null"); + } elseif (empty($newval) && $arrayrecord[($key - 1)]['type'] == 0) { + $listvalues[] = "''"; + } else { + $listvalues[] = "'".$this->db->escape($newval)."'"; + } } } $i++; diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php index 9fa5cbf2c44..a64063fa9af 100644 --- a/htdocs/core/modules/import/import_xlsx.modules.php +++ b/htdocs/core/modules/import/import_xlsx.modules.php @@ -363,6 +363,8 @@ class ImportXlsx extends ModeleImports $warning = 0; $this->errors = array(); $this->warnings = array(); + $this->nbinsert = 0; + $this->nbupdate = 0; //dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid); @@ -750,15 +752,36 @@ class ImportXlsx extends ModeleImports } // Define $listfields and $listvalues to build SQL request - $listfields[] = $fieldname; - - // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert - if (empty($newval) && $arrayrecord[($key)]['type'] < 0) { - $listvalues[] = ($newval == '0' ? $newval : "null"); - } elseif (empty($newval) && $arrayrecord[($key)]['type'] == 0) { - $listvalues[] = "''"; + if ($conf->socialnetworks->enabled && strpos($fieldname, "socialnetworks") !== false) { + if (!in_array("socialnetworks", $listfields)) { + $listfields[] = "socialnetworks"; + } + if (!empty($newval) && $arrayrecord[($key)]['type'] > 0) { + $socialkey = array_search("socialnetworks", $listfields); + if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] == "null") { + $socialnetwork = explode("_", $fieldname)[1]; + $newvalue = '\'{ "'.$socialnetwork.'" : "'.$this->db->escape($newval).'" }\''; + $listvalues[$socialkey] = $newvalue; + } else { + $socialnetwork = explode("_", $fieldname)[1]; + $jsondata = $listvalues[$socialkey]; + $jsondata = str_replace("'", "", $jsondata); + $json = json_decode($jsondata); + $json->$socialnetwork = $this->db->escape($newval); + $listvalues[$socialkey] = "'".$this->db->escape(json_encode($json))."'"; + } + } } else { - $listvalues[] = "'" . $this->db->escape($newval) . "'"; + $listfields[] = $fieldname; + + // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert + if (empty($newval) && $arrayrecord[($key)]['type'] < 0) { + $listvalues[] = ($newval == '0' ? $newval : "null"); + } elseif (empty($newval) && $arrayrecord[($key)]['type'] == 0) { + $listvalues[] = "''"; + } else { + $listvalues[] = "'" . $this->db->escape($newval) . "'"; + } } } $i++; diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index e4cf484df58..3b0a297ae0c 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -519,6 +519,16 @@ class modSociete extends DolibarrModules if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) { $this->import_fields_array[$r] += array('s.accountancy_code_sell'=>'ProductAccountancySellCode', 's.accountancy_code_buy'=>'ProductAccountancyBuyCode'); } + // Add social networks fields + if (!empty($conf->socialnetworks->enabled)) { + $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1"; + $resql = $this->db->query($sql); + while ($obj = $this->db->fetch_object($resql)) { + $fieldname = 's.socialnetworks_'.$obj->code; + $fieldlabel = ucfirst($obj->label); + $this->import_fields_array[$r][$fieldname] = $fieldlabel; + } + } // Add extra fields $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'societe' AND entity IN (0, ".$conf->entity.")"; $resql = $this->db->query($sql); @@ -718,6 +728,16 @@ class modSociete extends DolibarrModules 's.note_private' => "NotePrivate", 's.note_public' => "NotePublic" ); + // Add social networks fields + if (!empty($conf->socialnetworks->enabled)) { + $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1"; + $resql = $this->db->query($sql); + while ($obj = $this->db->fetch_object($resql)) { + $fieldname = 's.socialnetworks_'.$obj->code; + $fieldlabel = ucfirst($obj->label); + $this->import_fields_array[$r][$fieldname] = $fieldlabel; + } + } // Add extra fields $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type != 'separate' AND elementtype = 'socpeople' AND entity IN (0, ".$conf->entity.")"; $resql = $this->db->query($sql); From c887f48deea212852876be93b02cf801e6ea1588 Mon Sep 17 00:00:00 2001 From: Lucas Marcouiller Date: Fri, 20 May 2022 21:12:55 +0200 Subject: [PATCH 4/4] fix in social import --- htdocs/core/lib/functions.lib.php | 2 +- htdocs/core/modules/import/import_csv.modules.php | 8 +++++--- htdocs/core/modules/import/import_xlsx.modules.php | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index e6852cdde03..bca479dd910 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2951,7 +2951,7 @@ function dol_print_socialnetworks($value, $cid, $socid, $type, $dictsocialnetwor } else { if (!empty($dictsocialnetworks[$type]['url'])) { $link = str_replace('{socialid}', $value, $dictsocialnetworks[$type]['url']); - $htmllink .= ' '.dol_escape_htmltag($value).''; + $htmllink .= ' '.dol_escape_htmltag($value).''; } else { $htmllink .= dol_escape_htmltag($value); } diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index 0ca104c40c4..eef7305e1bc 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -717,14 +717,16 @@ class ImportCsv extends ModeleImports $socialkey = array_search("socialnetworks", $listfields); if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] == "null") { $socialnetwork = explode("_", $fieldname)[1]; - $newvalue = '\'{ "'.$socialnetwork.'" : "'.$this->db->escape($newval).'" }\''; - $listvalues[$socialkey] = $newvalue; + $json = new stdClass(); + $json->$socialnetwork = $newval; + $newvalue = json_encode($json); + $listvalues[$socialkey] = "'".$this->db->escape($newvalue)."'"; } else { $socialnetwork = explode("_", $fieldname)[1]; $jsondata = $listvalues[$socialkey]; $jsondata = str_replace("'", "", $jsondata); $json = json_decode($jsondata); - $json->$socialnetwork = $this->db->escape($newval); + $json->$socialnetwork = $newval; $listvalues[$socialkey] = "'".$this->db->escape(json_encode($json))."'"; } } diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php index f80cddf85e8..65985e6856a 100644 --- a/htdocs/core/modules/import/import_xlsx.modules.php +++ b/htdocs/core/modules/import/import_xlsx.modules.php @@ -760,7 +760,9 @@ class ImportXlsx extends ModeleImports $socialkey = array_search("socialnetworks", $listfields); if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] == "null") { $socialnetwork = explode("_", $fieldname)[1]; - $newvalue = '\'{ "'.$socialnetwork.'" : "'.$this->db->escape($newval).'" }\''; + $json = new stdClass(); + $json->$socialnetwork = $newval; + $newvalue = json_encode($json); $listvalues[$socialkey] = $newvalue; } else { $socialnetwork = explode("_", $fieldname)[1];