Skip to content
Snippets Groups Projects
Commit c482fa38 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Work on import module

parent 79a35598
Branches
Tags
No related merge requests found
...@@ -29,6 +29,7 @@ require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.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."/html.formother.class.php");
require_once(DOL_DOCUMENT_ROOT."/imports/import.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.'/includes/modules/import/modules_import.php');
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
$langs->load("exports"); $langs->load("exports");
...@@ -187,6 +188,26 @@ if ($action == 'add_import_model') ...@@ -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') if ($step == 4 && $action == 'select_model')
{ {
// Reinit match arrays // Reinit match arrays
...@@ -345,7 +366,6 @@ if ($step == 2 && $datatoimport) ...@@ -345,7 +366,6 @@ if ($step == 2 && $datatoimport)
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">'; print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
$filetoimport=''; $filetoimport='';
$fullpathfiletoimport='';
$var=true; $var=true;
// Add format informations and link to download example // Add format informations and link to download example
...@@ -359,7 +379,8 @@ if ($step == 2 && $datatoimport) ...@@ -359,7 +379,8 @@ if ($step == 2 && $datatoimport)
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td width="16">'.img_picto_common($key,$objmodelimport->getPicto($key)).'</td>'; 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>'; 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 // Action button
print '<td align="right">'; print '<td align="right">';
...@@ -434,7 +455,6 @@ if ($step == 3 && $datatoimport) ...@@ -434,7 +455,6 @@ if ($step == 3 && $datatoimport)
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">'; print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
$filetoimport=''; $filetoimport='';
$fullpathfiletoimport='';
$var=true; $var=true;
print '<tr><td colspan="6">'.$langs->trans("ChooseFileToImport",img_picto('','filenew')).'</td></tr>'; print '<tr><td colspan="6">'.$langs->trans("ChooseFileToImport",img_picto('','filenew')).'</td></tr>';
...@@ -451,23 +471,6 @@ if ($step == 3 && $datatoimport) ...@@ -451,23 +471,6 @@ if ($step == 3 && $datatoimport)
print '<input type="hidden" value="'.$datatoimport.'" name="datatoimport">'; print '<input type="hidden" value="'.$datatoimport.'" name="datatoimport">';
print "</tr>\n"; 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; $dir = $conf->import->dir_temp;
// Search available imports // Search available imports
...@@ -901,6 +904,8 @@ if ($step == 4 && $datatoimport) ...@@ -901,6 +904,8 @@ if ($step == 4 && $datatoimport)
if ($step == 5 && $datatoimport) if ($step == 5 && $datatoimport)
{ {
if (empty($dontimportfirstline)) $dontimportfirstline=0;
asort($array_match_file_to_database); asort($array_match_file_to_database);
$param='&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport); $param='&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport);
...@@ -958,26 +963,60 @@ if ($step == 5 && $datatoimport) ...@@ -958,26 +963,60 @@ if ($step == 5 && $datatoimport)
print '<tr><td width="25%">'.$langs->trans("FileToImport").'</td>'; print '<tr><td width="25%">'.$langs->trans("FileToImport").'</td>';
print '<td>'.$filetoimport.'</td></tr>'; print '<td>'.$filetoimport.'</td></tr>';
print '</table>'; /* print '</table>';
print '<br>'; print '<br>';
// Nbre champs importes print '<b>'.$langs->trans("ImportSummary").'</b>';
print $langs->trans("ImportedFields");
$list=''; // 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) foreach($array_match_file_to_database as $code=>$label)
{ {
$list.=($list?',':''); $listfields.=($listfields?',':'');
$list.=$langs->trans($objimport->array_import_fields[0][$code]); $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 '<center>';
print $langs->trans("NowClickToLoadImportFile").'<br>';
print '<form action="'.$_SERVER["PHP_SELF"].'?step=6&'.$param.'">'; print '<form action="'.$_SERVER["PHP_SELF"].'?step=6&'.$param.'">';
print '<input class="button" type="submit" value="'.$langs->trans("RunSimulateImportFile").'">';
print '<input class="button" type="submit" value="'.$langs->trans("ImportFile").'">';
print '</form>'; print '</form>';
print '</center>'; print '</center>';
......
...@@ -69,3 +69,10 @@ MoveField=Move field column number %s ...@@ -69,3 +69,10 @@ MoveField=Move field column number %s
ExampleOfImportFile=Example_of_import_file ExampleOfImportFile=Example_of_import_file
SaveImportProfile=Save this import profile SaveImportProfile=Save this import profile
ErrorImportDuplicateProfil=Failed to save this import profile with this name. An existing profile already exists with this name. 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
...@@ -69,3 +69,10 @@ MoveField=Déplacer champ colonne numéro %s ...@@ -69,3 +69,10 @@ MoveField=Déplacer champ colonne numéro %s
ExampleOfImportFile=Exemple_de_fichier_import ExampleOfImportFile=Exemple_de_fichier_import
SaveImportProfile=Sauvegarder ce profil d'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. 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
...@@ -188,7 +188,8 @@ function dol_mimetype($file) ...@@ -188,7 +188,8 @@ function dol_mimetype($file)
/** /**
* \brief Test if a folder is empty * \brief Test if a folder is empty
* \return true is empty or non-existing, false if it contains files * \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) function dol_dir_is_emtpy($folder)
{ {
...@@ -212,4 +213,31 @@ function dol_dir_is_emtpy($folder) ...@@ -212,4 +213,31 @@ function dol_dir_is_emtpy($folder)
return true; // Le repertoire n'existe pas 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;
}
?> ?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment