diff --git a/dictionaries/en.dictionary.itop.ui.php b/dictionaries/en.dictionary.itop.ui.php index 0043fe1c3..949f73f72 100644 --- a/dictionaries/en.dictionary.itop.ui.php +++ b/dictionaries/en.dictionary.itop.ui.php @@ -692,6 +692,7 @@ We hope you’ll enjoy this version as much as we enjoyed imagining and creating 'UI:CSVImport:TreatFirstLineAsHeader' => 'Treat the first line as a header (column names)', 'UI:CSVImport:Skip_N_LinesAtTheBeginning' => 'Skip %1$s line(s) at the beginning of the file', 'UI:CSVImport:CSVDataPreview' => 'CSV Data Preview', + 'UI:CSVImport:Column' => 'Column %1$s', 'UI:CSVImport:SelectFile' => 'Select the file to import:', 'UI:CSVImport:Tab:LoadFromFile' => 'Load from a file', 'UI:CSVImport:Tab:CopyPaste' => 'Copy and paste data', diff --git a/dictionaries/fr.dictionary.itop.ui.php b/dictionaries/fr.dictionary.itop.ui.php index 5ce828572..59889989f 100644 --- a/dictionaries/fr.dictionary.itop.ui.php +++ b/dictionaries/fr.dictionary.itop.ui.php @@ -666,6 +666,7 @@ Nous espérons que vous aimerez cette version autant que nous avons eu du plaisi 'UI:CSVImport:TreatFirstLineAsHeader' => 'La première ligne est l\'en-tête (noms des colonnes)', 'UI:CSVImport:Skip_N_LinesAtTheBeginning' => 'Ignorer les %1$s premières lignes du fichier', 'UI:CSVImport:CSVDataPreview' => 'Aperçu des données CSV', + 'UI:CSVImport:Column' => 'Colonne %1$s', 'UI:CSVImport:SelectFile' => 'Sélectionnez le fichier à importer:', 'UI:CSVImport:Tab:LoadFromFile' => 'Import depuis un fichier', 'UI:CSVImport:Tab:CopyPaste' => 'Copier/Coller de données', diff --git a/pages/ajax.csvimport.php b/pages/ajax.csvimport.php index 4c4d7b43d..1e918660b 100644 --- a/pages/ajax.csvimport.php +++ b/pages/ajax.csvimport.php @@ -219,7 +219,7 @@ try $sData = stripslashes(utils::ReadParam('csvdata', true, false, 'raw_data')); $oCSVParser = new CSVParser($sData, $sSeparator, $sTextQualifier, MetaModel::GetConfig()->Get('max_execution_time_per_loop')); $iMaxIndex = 10; // Display maximum 10 lines for the preview - $aData = $oCSVParser->ToArray($iLinesToSkip, null, $iMaxIndex); + $aData = $oCSVParser->ToArray($iLinesToSkip, null, $bFirstLineAsHeader ? $iMaxIndex + 1 : $iMaxIndex); $iTarget = count($aData); if ($iTarget == 0) { $oPage->p(Dict::S('UI:CSVImport:NoData')); @@ -227,39 +227,45 @@ try $sMaxLen = (strlen(''.$iTarget) < 3) ? 3 : strlen(''.$iTarget); // Pad line numbers to the appropriate number of chars, but at least 3 $sFormat = '%0'.$sMaxLen.'d'; - //$oTitle = TitleUIBlockFactory::MakeForPage(Dict::S('UI:Title:DataPreview')); - //$oPage->AddSubBlock($oTitle); - - //$oContainer = UIContentBlockUIBlockFactory::MakeStandard(); - //$oContainer->AddCSSClass("ibo-is-visible"); - //$oPage->AddSubBlock($oContainer); - - $index = 1; $aColumns = []; $aTableData = []; - foreach ($aData as $aRow) { - $sCSSClass = 'csv_row'.($index % 2); - if (($bFirstLineAsHeader) && ($index == 1)) { - $aColumns[] = ["label" => sprintf($sFormat, $index)]; - foreach ($aRow as $sCell) { - $aColumns[] = ["label" => utils::EscapeHtml($sCell)]; - } + $iNbCols = 0; + + // iterate throw data elements... + for ($iDataLineNumber = 0 ; $iDataLineNumber < count($aData) && count($aTableData) <= $iMaxIndex ; $iDataLineNumber++) { + + // get data element + $aRow = $aData[$iDataLineNumber]; + + // when first line + if ($iDataLineNumber === 0) { + + // columns $iNbCols = count($aRow); - } else { - $aTableRow = []; - if ($index == 1) { - $iNbCols = count($aRow); + $aColumns[] = ''; + + // first line as header + if($bFirstLineAsHeader){ + foreach ($aRow as $sCell) { + $aColumns[] = ["label" => utils::EscapeHtml($sCell)]; + } + continue; } - $aTableRow[] = sprintf($sFormat, $index); - foreach ($aRow as $sCell) { - $aTableRow[] = utils::EscapeHtml($sCell); + + // default headers + for ($iDataColumnNumber = 0 ; $iDataColumnNumber < count($aRow) ; $iDataColumnNumber++) { + $aColumns[] = ["label" => Dict::Format('UI:CSVImport:Column', $iDataColumnNumber+1)]; } - $aTableData[$index] = $aTableRow; + } - $index++; - if ($index > $iMaxIndex) { - break; + + // create table row + $aTableRow = []; + $aTableRow[] = sprintf($sFormat, count($aTableData) + 1); + foreach ($aRow as $sCell) { + $aTableRow[] = utils::EscapeHtml($sCell); } + $aTableData[] = $aTableRow; } $oTable = DataTableUIBlockFactory::MakeForForm("parser_preview", $aColumns, $aTableData); $oPage->AddSubBlock($oTable);