From 90366b1b81799d1244275e1559f1b9d8589204d8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 13 Apr 2022 16:21:25 +0200 Subject: [PATCH] Revert "NEW : Import with select boxes" --- htdocs/imports/import.php | 188 +++++++++----------------------- htdocs/langs/en_US/exports.lang | 4 +- htdocs/langs/fr_FR/exports.lang | 4 +- 3 files changed, 54 insertions(+), 142 deletions(-) diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index 9ec98f8a495..01f152f1ea5 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -136,14 +136,13 @@ $step = (GETPOST('step') ? GETPOST('step') : 1); $import_name = GETPOST('import_name'); $hexa = GETPOST('hexa'); $importmodelid = GETPOST('importmodelid'); -$excludefirstline = (GETPOST('excludefirstline') ? GETPOST('excludefirstline') : 2); +$excludefirstline = (GETPOST('excludefirstline') ? GETPOST('excludefirstline') : 1); $endatlinenb = (GETPOST('endatlinenb') ? GETPOST('endatlinenb') : ''); $updatekeys = (GETPOST('updatekeys', 'array') ? GETPOST('updatekeys', 'array') : array()); $separator = (GETPOST('separator', 'nohtml') ? GETPOST('separator', 'nohtml') : (!empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE) ? $conf->global->IMPORT_CSV_SEPARATOR_TO_USE : ',')); $enclosure = (GETPOST('enclosure', 'nohtml') ? GETPOST('enclosure', 'nohtml') : '"'); $separator_used = str_replace('\t', "\t", $separator); - $objimport = new Import($db); $objimport->load_arrays($user, ($step == 1 ? '' : $datatoimport)); @@ -161,7 +160,7 @@ foreach ($fieldsarray as $elem) { $tabelem = explode('=', $elem, 2); $key = $tabelem[0]; $val = (isset($tabelem[1]) ? $tabelem[1] : ''); - if ($key && $val && ($key > 0 && $step != 4)) { + if ($key && $val) { $array_match_file_to_database[$key] = $val; } } @@ -326,16 +325,13 @@ if ($action == 'saveorder') { $pos = 0; foreach ($fieldsarray as $fieldnb) { // For each elem in list. fieldnb start from 1 to ... // Get name of database fields at position $pos and put it into $namefield - $posbis = 0; - - $namefield = ''; + $posbis = 0; $namefield = ''; foreach ($fieldstarget as $key => $val) { // key: val: //dol_syslog('AjaxImport key='.$key.' val='.$val); if ($posbis < $pos) { $posbis++; continue; } - // We found the key of targets that is at position pos $namefield = $key; //dol_syslog('AjaxImport Field name found for file field nb '.$fieldnb.'='.$namefield); @@ -1008,7 +1004,7 @@ if ($step == 4 && $datatoimport) { $lefti = 1; foreach ($array_match_file_to_database as $key => $val) { $var = !$var; - show_elem($fieldssource, $key, $val, $var, 1, '', $listofkeys); // key is field number in source file + show_elem($fieldssource, $key, $val, $var); // key is field number in source file //print '> '.$lefti.'-'.$key.'-'.$val; $listofkeys[$key] = 1; $fieldsplaced[$key] = 1; @@ -1027,7 +1023,7 @@ if ($step == 4 && $datatoimport) { while ($lefti <= $num) { $var = !$var; $newkey = getnewkey($fieldssource, $listofkeys); - show_elem($fieldssource, $newkey, '', $var, 1, '', $listofkeys); // key start after field number in source file + show_elem($fieldssource, $newkey, '', $var); // key start after field number in source file //print '> '.$lefti.'-'.$newkey; $listofkeys[$key] = 1; $lefti++; @@ -1041,14 +1037,11 @@ if ($step == 4 && $datatoimport) { print ''; // List of target fields - // $height = '24px'; //needs px for css height attribute below - $height = '30px'; + $height = '24px'; //needs px for css height attribute below $i = 0; $mandatoryfieldshavesource = true; - $fieldselect = 1; - print ''; - $pos = 1; + print '
'; foreach ($fieldstarget as $code => $label) { print ''; @@ -1058,7 +1051,7 @@ if ($step == 4 && $datatoimport) { $tablealias = preg_replace('/(\..*)$/i', '', $code); $tablename = $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', ... + $entityicon = $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', ... print ''; @@ -1078,7 +1071,7 @@ if ($step == 4 && $datatoimport) { print ''; // Info field print ''; print ''; - $fieldselect++; } print '
=>'.img_object('', $entityicon).' '.$langs->trans($entitylang).''; - $filecolumn = !empty($array_match_database_to_file[$code])?$array_match_database_to_file[$code]:0; + $filecolumn = $array_match_database_to_file[$code]; // Source field info $htmltext = ''.$langs->trans("FieldSource").'
'; if ($filecolumn > count($fieldssource)) { @@ -1098,7 +1091,7 @@ if ($step == 4 && $datatoimport) { } // Source required $htmltext .= $langs->trans("SourceRequired").': '.yn(preg_match('/\*$/', $label)).'
'; - $example = !empty($objimport->array_import_examplevalues[0][$code])?$objimport->array_import_examplevalues[0][$code]:""; + $example = $objimport->array_import_examplevalues[0][$code]; // Example if (empty($objimport->array_import_convertvalue[0][$code])) { // If source file does not need convertion if ($example) { @@ -1136,7 +1129,6 @@ if ($step == 4 && $datatoimport) { print '
'; @@ -1155,7 +1147,7 @@ if ($step == 4 && $datatoimport) { if (empty($fieldsplaced[$key])) { // $nbofnotimportedfields++; - show_elem($fieldssource, $key, '', $var, 0, 'nostyle', $listofkeys); + show_elem($fieldssource, $key, '', $var, 'nostyle'); //print '> '.$lefti.'-'.$key; $listofkeys[$key] = 1; $lefti++; @@ -1164,7 +1156,7 @@ if ($step == 4 && $datatoimport) { // Print one more empty field $newkey = getnewkey($fieldssource, $listofkeys); - show_elem($fieldssource, $newkey, '', $var, 1, 'nostyle', $listofkeys); + show_elem($fieldssource, $newkey, '', $var, 'nostyle'); //print '> '.$lefti.'-'.$newkey; $listofkeys[$newkey] = 1; $nbofnotimportedfields++; @@ -1177,7 +1169,7 @@ if ($step == 4 && $datatoimport) { $i = 0; while ($i < $nbofnotimportedfields) { // Print empty cells - show_elem('', '', 'none', $var, 0, 'nostyle', $listofkeys); + show_elem('', '', 'none', $var, 'nostyle'); $i++; } print ''; @@ -1188,51 +1180,35 @@ if ($step == 4 && $datatoimport) { if ($conf->use_javascript_ajax) { print ''."\n"; @@ -1495,20 +1471,6 @@ if ($step == 5 && $datatoimport) { if ($action == 'launchsimu') { print '   '.$langs->trans("Modify").''; } - if ($excludefirstline == 2) { - print $form->textwithpicto("", $langs->trans("WarningFirstImportedLine", $excludefirstline), 1, 'warning', "warningexcludefirstline"); - print ''; - } print ''; // Keys for data UPDATE (not INSERT of new data) @@ -2131,21 +2093,18 @@ $db->close(); /** * Function to put the movable box of a source field * - * @param array $fieldssource List of source fields - * @param int $pos Pos - * @param string $key Key - * @param boolean $var Line style (odd or not) - * @param boolean $isimportedfield Verify if it's an imported field - * @param int $nostyle Hide style - * @param array $listofkeys List of keys for select boxes + * @param array $fieldssource List of source fields + * @param int $pos Pos + * @param string $key Key + * @param boolean $var Line style (odd or not) + * @param int $nostyle Hide style * @return void */ -function show_elem($fieldssource, $pos, $key, $var, $isimportedfield, $nostyle = '', &$listofkeys = array()) +function show_elem($fieldssource, $pos, $key, $var, $nostyle = '') { global $langs, $bc; - // $height = '24px'; - $height = '30px'; + $height = '24px'; if ($key == 'none') { //stop multiple duplicate ids with no number @@ -2162,7 +2121,7 @@ function show_elem($fieldssource, $pos, $key, $var, $isimportedfield, $nostyle = if ($pos && $pos > count($fieldssource)) { // No fields print ''; print ''; - //print img_picto(($pos > 0 ? $langs->trans("MoveField", $pos) : ''), 'grip_title', 'class="boxhandle" style="cursor:move;"'); + print img_picto(($pos > 0 ? $langs->trans("MoveField", $pos) : ''), 'grip_title', 'class="boxhandle" style="cursor:move;"'); print ''; print ''; print $langs->trans("NoFields"); @@ -2177,65 +2136,22 @@ function show_elem($fieldssource, $pos, $key, $var, $isimportedfield, $nostyle = print ' '; print ''; print ''; - } elseif (empty($isimportedfield)) { - $example = !empty($fieldssource[$pos]['example1'])?$fieldssource[$pos]['example1']:""; - if ($example) { - if (!utf8_check($example)) { - $example = utf8_encode($example); - } - print ''; - print ''; - print ' '; - print ''; - print ''; - print $langs->trans("EmptyField").': '; - print ' ('.$example.')'; - print ''; - print ''; - } } else { // Print field of source file print ''; print ''; // The image must have the class 'boxhandle' beause it's value used in DOM draggable objects to define the area used to catch the full object - //print img_picto($langs->trans("MoveField", $pos), 'grip_title', 'class="boxhandle" style="cursor:move;"'); + print img_picto($langs->trans("MoveField", $pos), 'grip_title', 'class="boxhandle" style="cursor:move;"'); print ''; - print ''; - $example = !empty($fieldssource[$pos]['example1'])?$fieldssource[$pos]['example1']:""; - if ($example != "") { - print $langs->trans("Field").' '.$pos.': '; - } else { - print $langs->trans("EmptyField").': '; - } + print ''; + print $langs->trans("Field").' '.$pos; + $example = $fieldssource[$pos]['example1']; if ($example) { if (!utf8_check($example)) { $example = utf8_encode($example); } - } - $nameselect = ($pos > 0) ? $pos : (-$pos); - print ''; - print '