diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index 0000189c998..40b13da0599 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -715,19 +715,16 @@ class ImportCsv extends ModeleImports } if (!empty($newval) && $arrayrecord[($key - 1)]['type'] > 0) { $socialkey = array_search("socialnetworks", $listfields); + $socialnetwork = explode("_", $fieldname)[1]; 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)."'"; + $listvalues[$socialkey] = json_encode($json); } 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))."'"; + $listvalues[$socialkey] = json_encode($json); } } } else { @@ -745,6 +742,12 @@ 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 ->import_fieldshidden_array of the descriptor file. // Previously we processed the ->import_fields_array. diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index 46a14450f3e..bac7c56cbaa 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -153,18 +153,6 @@ $htmlother = new FormOther($db); $formfile = new FormFile($db); // Init $array_match_file_to_database from _SESSION -$serialized_array_match_file_to_database = isset($_SESSION["dol_array_match_file_to_database"]) ? $_SESSION["dol_array_match_file_to_database"] : ''; -$array_match_file_to_database = array(); -$fieldsarray = explode(',', $serialized_array_match_file_to_database); -foreach ($fieldsarray as $elem) { - $tabelem = explode('=', $elem, 2); - $key = $tabelem[0]; - $val = (isset($tabelem[1]) ? $tabelem[1] : ''); - if ($key && $val) { - $array_match_file_to_database[$key] = $val; - } -} - if (empty($array_match_file_to_database)) { $serialized_array_match_file_to_database = isset($_SESSION["dol_array_match_file_to_database_select"]) ? $_SESSION["dol_array_match_file_to_database_select"] : ''; $array_match_file_to_database = array(); @@ -1072,14 +1060,14 @@ if ($step == 4 && $datatoimport) { if (!$line["imported"]) { $optionsnotused .= $text; } - $optionsall[$code] = array('label'=>$langs->trans($line["label"]), 'required'=>(empty($line["required"]) ? 0 : 1), 'position'=>$line['position']); + $optionsall[$code] = array('label'=>$langs->trans($line["label"]), 'required'=>(empty($line["required"]) ? 0 : 1), 'position'=>!empty($line['position']) ? $line['position'] : 0); } // $optionsall is an array of all possible fields. key=>array('label'=>..., 'xxx') $height = '32px'; //needs px for css height attribute below $i = 0; $mandatoryfieldshavesource = true; - + $more = ""; //var_dump($fieldstarget); //var_dump($optionsall); //exit; @@ -1100,7 +1088,7 @@ if ($step == 4 && $datatoimport) { $entity = (!empty($objimport->array_import_entities[0][$code]) ? $objimport->array_import_entities[0][$code] : $objimport->array_import_icon[0]); $tablealias = preg_replace('/(\..*)$/i', '', $code); - $tablename = $objimport->array_import_tables[0][$tablealias]; + $tablename = !empty($objimport->array_import_tables[0][$tablealias]) ? $objimport->array_import_tables[0][$tablealias] : ""; $entityicon = !empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity; // $entityicon must string name of picto of the field like 'project', 'company', 'contact', 'modulename', ... $entitylang = $entitytolang[$entity] ? $entitytolang[$entity] : $objimport->array_import_label[0]; // $entitylang must be a translation key to describe object the field is related to, like 'Company', 'Contact', 'MyModyle', ... @@ -1118,8 +1106,8 @@ if ($step == 4 && $datatoimport) { //var_dump($_SESSION['dol_array_match_file_to_database']); //var_dump($modetoautofillmapping); - print ''; + if (!empty($line["imported"])) { print ''; } else { print ''; @@ -1166,10 +1154,10 @@ if ($step == 4 && $datatoimport) { //var_dump($code); //var_dump($tmpselectioninsession); //if ($tmpselectioninsession[$j] == $code) { - if ($tmpselectioninsession[($i+1)] == $tmpcode) { + if (!empty($tmpselectioninsession[($i+1)]) && $tmpselectioninsession[($i+1)] == $tmpcode) { print ' selected'; } - print ' data-debug="'.$tmpcode.'-'.$code.'-'.$j.'-'.$tmpselectioninsession[($i+1)].'"'; + print ' data-debug="'.$tmpcode.'-'.$code.'-'.$j.'-'.(!empty($tmpselectioninsession[($i+1)]) ? $tmpselectioninsession[($i+1)] : "").'"'; } print ' data-html="'.dol_escape_htmltag($label).'"'; print '>'; @@ -1234,7 +1222,7 @@ if ($step == 4 && $datatoimport) { $htmltext .= $langs->trans("DataCodeIDSourceIsInsertedInto").'
'; } } - $htmltext .= $langs->trans("FieldTitle").": ".$langs->trans($line["label"])."
"; + $htmltext .= $langs->trans("FieldTitle").": ".$langs->trans($fieldstarget[$arraykeysfieldtarget[$code-1]]["label"])."
"; $htmltext .= $langs->trans("Table")." -> ".$langs->trans("Field").': '.$tablename." -> ".preg_replace('/^.*\./', '', $code)."
"; print $form->textwithpicto($more, $htmltext); print '';