diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index d2ac2e86eb370c2845af699cdca7e0d4f44653cc..6da18d36fe1138425a00eeddf45c22936e1679f5 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -29,6 +29,7 @@ require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/html.formother.class.php"); require_once(DOL_DOCUMENT_ROOT."/imports/import.class.php"); require_once(DOL_DOCUMENT_ROOT.'/includes/modules/import/modules_import.php'); +require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); $langs->load("exports"); @@ -187,6 +188,26 @@ if ($action == 'add_import_model') } } +if ($step == 3 && $datatoimport) +{ + if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) + { + create_exdir($conf->import->dir_temp); + $nowyearmonth=dol_date('YmdHis',dol_now(),0); + + $fullpath=$conf->import->dir_temp . "/" . $nowyearmonth . '-'.$_FILES['userfile']['name']; + if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $fullpath,1) > 0) + { + dol_syslog("File ".$fullpath." was added for import"); + } + else + { + $langs->load("errors"); + $mesg = $langs->trans("ErrorFailedToSaveFile"); + } + } +} + if ($step == 4 && $action == 'select_model') { // Reinit match arrays @@ -345,7 +366,6 @@ if ($step == 2 && $datatoimport) print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">'; $filetoimport=''; - $fullpathfiletoimport=''; $var=true; // Add format informations and link to download example @@ -359,7 +379,8 @@ if ($step == 2 && $datatoimport) $var=!$var; print '<tr '.$bc[$var].'>'; print '<td width="16">'.img_picto_common($key,$objmodelimport->getPicto($key)).'</td>'; - print '<td>'.$objmodelimport->getDriverLabel($key).'</td>'; + $text=$objmodelimport->getDriverDesc($key); + print '<td>'.$html->textwithpicto($objmodelimport->getDriverLabel($key),$text).'</td>'; print '<td align="center"><a href="'.DOL_URL_ROOT.'/imports/emptyexample.php?format='.$key.'&datatoimport='.$datatoimport.'" target="_blank">'.$langs->trans("DownloadEmptyExample").'</a></td>'; // Action button print '<td align="right">'; @@ -434,7 +455,6 @@ if ($step == 3 && $datatoimport) print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">'; $filetoimport=''; - $fullpathfiletoimport=''; $var=true; print '<tr><td colspan="6">'.$langs->trans("ChooseFileToImport",img_picto('','filenew')).'</td></tr>'; @@ -451,23 +471,6 @@ if ($step == 3 && $datatoimport) print '<input type="hidden" value="'.$datatoimport.'" name="datatoimport">'; print "</tr>\n"; - if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) - { - create_exdir($conf->import->dir_temp); - $nowyearmonth=dol_date('YmdHis',dol_now(),0); - - $fullpath=$conf->import->dir_temp . "/" . $nowyearmonth . '-'.$_FILES['userfile']['name']; - if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $fullpath,1) > 0) - { - dol_syslog("File ".$fullpath." was added for import"); - } - else - { - $langs->load("errors"); - $mesg = $langs->trans("ErrorFailedToSaveFile"); - } - } - $dir = $conf->import->dir_temp; // Search available imports @@ -901,6 +904,8 @@ if ($step == 4 && $datatoimport) if ($step == 5 && $datatoimport) { + if (empty($dontimportfirstline)) $dontimportfirstline=0; + asort($array_match_file_to_database); $param='&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport); @@ -958,26 +963,60 @@ if ($step == 5 && $datatoimport) print '<tr><td width="25%">'.$langs->trans("FileToImport").'</td>'; print '<td>'.$filetoimport.'</td></tr>'; - print '</table>'; +/* print '</table>'; print '<br>'; - // Nbre champs importes - print $langs->trans("ImportedFields"); - $list=''; + print '<b>'.$langs->trans("ImportSummary").'</b>'; + + // Show import summary + print '<table summary="importsummary" width="100%" class="border">'; +*/ + + // Nb of fields + print '<tr><td>'; + print $langs->trans("NbOfSourceLines"); + print '</td><td>'; + $nboflines=dol_count_nb_of_line($conf->import->dir_temp.'/'.$filetoimport); + print $nboflines; + print '</td></tr>'; + + // Checkbox do not import first line + print '<tr><td>'; + print $langs->trans("DoNotImportFirstLine"); + print '</td><td>'; + print '<input type="checkbox" name="nofirstline" value='.$dontimportfirstline.'>'; + print '</td></tr>'; + + // Tables imported + print '<tr><td>'; + print $langs->trans("TablesTarget"); + print '</td><td>'; + $listtables=''; + print $listables?$listables:$langs->trans("Error"); + print '</td></tr>'; + + // Fields imported + print '<tr><td>'; + print $langs->trans("FieldsTarget").'</td><td>'; + $listfields=''; foreach($array_match_file_to_database as $code=>$label) { - $list.=($list?',':''); - $list.=$langs->trans($objimport->array_import_fields[0][$code]); + $listfields.=($listfields?',':''); + $listfields.=$langs->trans($objimport->array_import_fields[0][$code]); } + print $listfields?$listfields:$langs->trans("Error"); + print '</td></tr>'; + print '</table>'; + + print '<br>'; + print $langs->trans("NowClickToTestTheImport",$langs->transnoentitiesnoconv("RunSimulateImportFile")).'<br>'; + print '<br>'; print '<center>'; - print $langs->trans("NowClickToLoadImportFile").'<br>'; print '<form action="'.$_SERVER["PHP_SELF"].'?step=6&'.$param.'">'; - - print '<input class="button" type="submit" value="'.$langs->trans("ImportFile").'">'; - + print '<input class="button" type="submit" value="'.$langs->trans("RunSimulateImportFile").'">'; print '</form>'; print '</center>'; diff --git a/htdocs/langs/en_US/exports.lang b/htdocs/langs/en_US/exports.lang index 0f4ce8b8ddc60d99a09443ca3dc0e65e7ec8141d..5ccf7f948ff1efa1f9567e5912ec7bee91998443 100644 --- a/htdocs/langs/en_US/exports.lang +++ b/htdocs/langs/en_US/exports.lang @@ -69,3 +69,10 @@ MoveField=Move field column number %s ExampleOfImportFile=Example_of_import_file SaveImportProfile=Save this import profile ErrorImportDuplicateProfil=Failed to save this import profile with this name. An existing profile already exists with this name. +ImportSummary=Import setup summary +TablesTarget=Targeted tables +FieldsTarget=Targeted fields +DoNotImportFirstLine=Do not import first line of source file +NbOfSourceLines=Number of lines in source file +NowClickToTestTheImport=Check import parameters you have defined. If they are correct, click on button "<b>%s</b>" to launch a simulation of import process (no data will be changed in your database, it's only a simulation for the moment)... +RunSimulateImportFile=Launch the import simulation diff --git a/htdocs/langs/fr_FR/exports.lang b/htdocs/langs/fr_FR/exports.lang index aff1a8892f4b2f4de89090dee3564d61cc2d49a4..9d3b440267c834c4112517e24b3d171b5e1cbaa2 100644 --- a/htdocs/langs/fr_FR/exports.lang +++ b/htdocs/langs/fr_FR/exports.lang @@ -68,4 +68,11 @@ NoFields=Aucun champ MoveField=Déplacer champ colonne numéro %s ExampleOfImportFile=Exemple_de_fichier_import SaveImportProfile=Sauvegarder ce profil d'import -ErrorImportDuplicateProfil=Impossible de sauvegarder le profil d'import sous ce nom. Un profil existant existe déjà pour ce nom. \ No newline at end of file +ErrorImportDuplicateProfil=Impossible de sauvegarder le profil d'import sous ce nom. Un profil existant existe déjà pour ce nom. +ImportSummary=Résumé de la configuration d'import +TablesTarget=Tables cibles +FieldsTarget=Champs cibles +DoNotImportFirstLine=Ne pas importer la première ligne du fichier source +NbOfSourceLines=Nombre de lignes du fichier source +NowClickToTestTheImport=Vérifiez les paramètres d'import que vous avez défini. S'ils vous conviennent, cliquez sur le bouton "<b>%s</b>" pour lancer une simulation d'import (aucune donnée ne sera modifié, il s'agit dans un premier temps d'une simple simulation)... +RunSimulateImportFile=Lancer la simulation d'import \ No newline at end of file diff --git a/htdocs/lib/files.lib.php b/htdocs/lib/files.lib.php index 6ea2d4c20556f7fc77d6fc0bf962212d562d4dc0..9329b17e31110f5b24cf0a3ac40d003ac6400472 100644 --- a/htdocs/lib/files.lib.php +++ b/htdocs/lib/files.lib.php @@ -187,8 +187,9 @@ function dol_mimetype($file) /** - * \brief Test if a folder is empty - * \return true is empty or non-existing, false if it contains files + * \brief Test if a folder is empty + * \param folder Name of folder + * \return boolean True if dir is empty or non-existing, false if it contains files */ function dol_dir_is_emtpy($folder) { @@ -212,4 +213,31 @@ function dol_dir_is_emtpy($folder) return true; // Le repertoire n'existe pas } +/** + * \brief Count number of lines in a file + * \param file Filename + * \return int <0 if KO, Number of lines in files if OK + */ +function dol_count_nb_of_line($file) +{ + $nb=0; + //print 'x'.$file; + $fp=fopen($file,'r'); + if ($fp) + { + while (!feof($fp)) + { + $line=fgets($fp); + $nb++; + } + fclose($fp); + } + else + { + $nb=-1; + } + + return $nb; +} + ?>