diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index 08eb9a6f42d..8c3e5bfeab9 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -750,13 +750,6 @@ class ImportCsv extends ModeleImports $i++; } - // We db escape social network field because he isn't in field creation - if (in_array("socialnetworks", $listfields)) { - $socialkey = array_search("socialnetworks", $listfields); - $tmpsql = $listvalues[$socialkey]; - $listvalues[$socialkey] = "'".$this->db->escape($tmpsql)."'"; - } - // We add hidden fields (but only if there is at least one field to add into table) // We process here all the fields that were declared into the array $this->import_fieldshidden_array of the descriptor file. // Previously we processed the ->import_fields_array. @@ -838,8 +831,18 @@ class ImportCsv extends ModeleImports foreach ($updatekeys as $key) { $col = $objimport->array_import_updatekeys[0][$key]; $key = preg_replace('/^.*\./i', '', $key); - $where[] = $key.' = '.$data[$key]; - $filters[] = $col.' = '.$data[$key]; + if ($conf->socialnetworks->enabled && strpos($key, "socialnetworks") !== false) { + $tmp = explode("_", $key); + $key = $tmp[0]; + $socialnetwork = $tmp[1]; + $jsondata = $data[$key]; + $json = json_decode($jsondata); + $where[] = $key." LIKE '%\"".$socialnetwork."\":\"".$this->db->escape($json->$socialnetwork)."\"%'"; + $filters[] = $col." LIKE '%\"".$socialnetwork."\":\"".$this->db->escape($json->$socialnetwork)."\"%'"; + } else { + $where[] = $key.' = '.$data[$key]; + $filters[] = $col.' = '.$data[$key]; + } } $sqlSelect .= " WHERE ".implode(' AND ', $where); @@ -896,6 +899,13 @@ class ImportCsv extends ModeleImports } if (!empty($lastinsertid)) { + // We db escape social network field because he isn't in field creation + if (in_array("socialnetworks", $listfields)) { + $socialkey = array_search("socialnetworks", $listfields); + $tmpsql = $listvalues[$socialkey]; + $listvalues[$socialkey] = "'".$this->db->escape($tmpsql)."'"; + } + // Build SQL UPDATE request $sqlstart = "UPDATE ".$tablename; @@ -933,6 +943,13 @@ class ImportCsv extends ModeleImports // Update not done, we do insert if (!$error && !$updatedone) { + // We db escape social network field because he isn't in field creation + if (in_array("socialnetworks", $listfields)) { + $socialkey = array_search("socialnetworks", $listfields); + $tmpsql = $listvalues[$socialkey]; + $listvalues[$socialkey] = "'".$this->db->escape($tmpsql)."'"; + } + // Build SQL INSERT request $sqlstart = "INSERT INTO ".$tablename."(".implode(", ", $listfields).", import_key"; $sqlend = ") VALUES(".implode(', ', $listvalues).", '".$this->db->escape($importid)."'"; diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php index a7fcf6f0d0f..4740f7d3390 100644 --- a/htdocs/core/modules/import/import_xlsx.modules.php +++ b/htdocs/core/modules/import/import_xlsx.modules.php @@ -795,13 +795,6 @@ class ImportXlsx extends ModeleImports $i++; } - // We db escape social network field because he isn't in field creation - if (in_array("socialnetworks", $listfields)) { - $socialkey = array_search("socialnetworks", $listfields); - $tmpsql = $listvalues[$socialkey]; - $listvalues[$socialkey] = "'".$this->db->escape($tmpsql)."'"; - } - // We add hidden fields (but only if there is at least one field to add into table) // We process here all the fields that were declared into the array $this->import_fieldshidden_array of the descriptor file. // Previously we processed the ->import_fields_array. @@ -883,8 +876,18 @@ class ImportXlsx extends ModeleImports foreach ($updatekeys as $key) { $col = $objimport->array_import_updatekeys[0][$key]; $key = preg_replace('/^.*\./i', '', $key); - $where[] = $key . ' = ' . $data[$key]; - $filters[] = $col . ' = ' . $data[$key]; + if ($conf->socialnetworks->enabled && strpos($key, "socialnetworks") !== false) { + $tmp = explode("_", $key); + $key = $tmp[0]; + $socialnetwork = $tmp[1]; + $jsondata = $data[$key]; + $json = json_decode($jsondata); + $where[] = $key." LIKE '%\"".$socialnetwork."\":\"".$this->db->escape($json->$socialnetwork)."\"%'"; + $filters[] = $col." LIKE '%\"".$socialnetwork."\":\"".$this->db->escape($json->$socialnetwork)."\"%'"; + } else { + $where[] = $key.' = '.$data[$key]; + $filters[] = $col.' = '.$data[$key]; + } } $sqlSelect .= " WHERE " . implode(' AND ', $where); @@ -941,6 +944,13 @@ class ImportXlsx extends ModeleImports } if (!empty($lastinsertid)) { + // We db escape social network field because he isn't in field creation + if (in_array("socialnetworks", $listfields)) { + $socialkey = array_search("socialnetworks", $listfields); + $tmpsql = $listvalues[$socialkey]; + $listvalues[$socialkey] = "'".$this->db->escape($tmpsql)."'"; + } + // Build SQL UPDATE request $sqlstart = "UPDATE " . $tablename; @@ -978,6 +988,13 @@ class ImportXlsx extends ModeleImports // Update not done, we do insert if (!$error && !$updatedone) { + // We db escape social network field because he isn't in field creation + if (in_array("socialnetworks", $listfields)) { + $socialkey = array_search("socialnetworks", $listfields); + $tmpsql = $listvalues[$socialkey]; + $listvalues[$socialkey] = "'".$this->db->escape($tmpsql)."'"; + } + // Build SQL INSERT request $sqlstart = "INSERT INTO " . $tablename . "(" . implode(", ", $listfields) . ", import_key"; $sqlend = ") VALUES(" . implode(', ', $listvalues) . ", '" . $this->db->escape($importid) . "'"; diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index a6d9b95d19c..322988e7a7b 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -693,6 +693,15 @@ class modSociete extends DolibarrModules 's.code_compta' => 'CustomerAccountancyCode', 's.code_compta_fournisseur' => 'SupplierAccountancyCode' ); + 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_updatekeys_array[$r][$fieldname] = $fieldlabel; + } + } // Add profids as criteria to search duplicates $langs->load("companies"); $i=1;