diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index e09ab803353..b400a4e7c1b 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -2959,7 +2959,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 95c02af8e73..0000189c998 100644
--- a/htdocs/core/modules/import/import_csv.modules.php
+++ b/htdocs/core/modules/import/import_csv.modules.php
@@ -709,15 +709,37 @@ 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];
+ $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 = $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 7877275b034..257a9a13c6a 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,38 @@ 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];
+ $json = new stdClass();
+ $json->$socialnetwork = $newval;
+ $newvalue = json_encode($json);
+ $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 ec3f978d011..a9eb5899fc8 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);