mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
NEW Can define number of first and last line into import wizard.
This commit is contained in:
parent
266fb14a2c
commit
f762196c77
|
|
@ -76,6 +76,7 @@ $import_name = GETPOST('import_name');
|
|||
$hexa = GETPOST('hexa');
|
||||
$importmodelid = GETPOST('importmodelid');
|
||||
$excludefirstline = (GETPOST('excludefirstline') ? GETPOST('excludefirstline') : 0);
|
||||
$endatlinenb = (GETPOST('endatlinenb') ? GETPOST('endatlinenb') : '');
|
||||
$separator = (GETPOST('separator') ? GETPOST('separator') : (! empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE)?$conf->global->IMPORT_CSV_SEPARATOR_TO_USE:','));
|
||||
$enclosure = (GETPOST('enclosure') ? GETPOST('enclosure') : '"');
|
||||
|
||||
|
|
@ -221,8 +222,9 @@ if ($step == 3 && $datatoimport)
|
|||
$langs->load("other");
|
||||
|
||||
$param='&datatoimport='.$datatoimport.'&format='.$format;
|
||||
if ($excludefirstline) $param.='&excludefirstline=1';
|
||||
|
||||
if ($excludefirstline) $param.='&excludefirstline='.$excludefirstline;
|
||||
if ($endatlinenb) $param.='&endatlinenb='.$endatlinenb;
|
||||
|
||||
$file = $conf->import->dir_temp . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
|
||||
$ret=dol_delete_file($file);
|
||||
if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
|
||||
|
|
@ -328,7 +330,8 @@ if ($step == 1 || ! $datatoimport)
|
|||
$_SESSION["dol_array_match_file_to_database"]='';
|
||||
|
||||
$param='';
|
||||
if ($excludefirstline) $param.='&excludefirstline=1';
|
||||
if ($excludefirstline) $param.='&excludefirstline='.$excludefirstline;
|
||||
if ($endatlinenb) $param.='&endatlinenb='.$endatlinenb;
|
||||
if ($separator) $param.='&separator='.urlencode($separator);
|
||||
if ($enclosure) $param.='&enclosure='.urlencode($enclosure);
|
||||
|
||||
|
|
@ -395,7 +398,8 @@ if ($step == 1 || ! $datatoimport)
|
|||
if ($step == 2 && $datatoimport)
|
||||
{
|
||||
$param='&datatoimport='.$datatoimport;
|
||||
if ($excludefirstline) $param.='&excludefirstline=1';
|
||||
if ($excludefirstline) $param.='&excludefirstline='.$excludefirstline;
|
||||
if ($endatlinenb) $param.='&endatlinenb='.$endatlinenb;
|
||||
if ($separator) $param.='&separator='.urlencode($separator);
|
||||
if ($enclosure) $param.='&enclosure='.urlencode($enclosure);
|
||||
|
||||
|
|
@ -469,7 +473,8 @@ if ($step == 2 && $datatoimport)
|
|||
if ($step == 3 && $datatoimport)
|
||||
{
|
||||
$param='&datatoimport='.$datatoimport.'&format='.$format;
|
||||
if ($excludefirstline) $param.='&excludefirstline=1';
|
||||
if ($excludefirstline) $param.='&excludefirstline='.$excludefirstline;
|
||||
if ($endatlinenb) $param.='&endatlinenb='.$endatlinenb;
|
||||
if ($separator) $param.='&separator='.urlencode($separator);
|
||||
if ($enclosure) $param.='&enclosure='.urlencode($enclosure);
|
||||
|
||||
|
|
@ -547,6 +552,7 @@ if ($step == 3 && $datatoimport)
|
|||
print '<input type="hidden" value="'.$step.'" name="step">';
|
||||
print '<input type="hidden" value="'.$format.'" name="format">';
|
||||
print '<input type="hidden" value="'.$excludefirstline.'" name="excludefirstline">';
|
||||
print '<input type="hidden" value="'.$endatlinenb.'" name="endatlinenb">';
|
||||
print '<input type="hidden" value="'.$separator.'" name="separator">';
|
||||
print '<input type="hidden" value="'.$enclosure.'" name="enclosure">';
|
||||
print '<input type="hidden" value="'.$datatoimport.'" name="datatoimport">';
|
||||
|
|
@ -684,7 +690,8 @@ if ($step == 4 && $datatoimport)
|
|||
// Now $array_match_file_to_database contains fieldnb(1,2,3...)=>fielddatabase(key in $array_match_file_to_database)
|
||||
|
||||
$param='&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport);
|
||||
if ($excludefirstline) $param.='&excludefirstline=1';
|
||||
if ($excludefirstline) $param.='&excludefirstline='.$excludefirstline;
|
||||
if ($endatlinenb) $param.='&endatlinenb='.$endatlinenb;
|
||||
if ($separator) $param.='&separator='.urlencode($separator);
|
||||
if ($enclosure) $param.='&enclosure='.urlencode($enclosure);
|
||||
|
||||
|
|
@ -732,6 +739,7 @@ if ($step == 4 && $datatoimport)
|
|||
print '<input type="hidden" value="'.$step.'" name="step">';
|
||||
print '<input type="hidden" value="'.$format.'" name="format">';
|
||||
print '<input type="hidden" value="'.$excludefirstline.'" name="excludefirstline">';
|
||||
print '<input type="hidden" value="'.$endatlinenb.'" name="endatlinenb">';
|
||||
print '<input type="hidden" value="'.$datatoimport.'" name="datatoimport">';
|
||||
print '<input type="hidden" value="'.$filetoimport.'" name="filetoimport">';
|
||||
print $langs->trans("Separator").' : ';
|
||||
|
|
@ -767,7 +775,8 @@ if ($step == 4 && $datatoimport)
|
|||
print '<input type="hidden" name="datatoimport" value="'.$datatoimport.'">';
|
||||
print '<input type="hidden" name="filetoimport" value="'.$filetoimport.'">';
|
||||
print '<input type="hidden" name="excludefirstline" value="'.$excludefirstline.'">';
|
||||
print '<input type="hidden" name="separator" value="'.$separator.'">';
|
||||
print '<input type="hidden" name="endatlinenb" value="'.$endatlinenb.'">';
|
||||
print '<input type="hidden" name="separator" value="'.$separator.'">';
|
||||
print '<input type="hidden" name="enclosure" value="'.$enclosure.'">';
|
||||
print '<table><tr><td colspan="2">';
|
||||
print $langs->trans("SelectImportFields",img_picto('','uparrow','')).' ';
|
||||
|
|
@ -1051,7 +1060,8 @@ if ($step == 4 && $datatoimport)
|
|||
print '<input type="hidden" name="filetoimport" value="'.$filetoimport.'">';
|
||||
print '<input type="hidden" name="hexa" value="'.$hexa.'">';
|
||||
print '<input type="hidden" name="excludefirstline" value="'.$excludefirstline.'">';
|
||||
print '<input type="hidden" value="'.$separator.'" name="separator">';
|
||||
print '<input type="hidden" name="endatlinenb" value="'.$endatlinenb.'">';
|
||||
print '<input type="hidden" value="'.$separator.'" name="separator">';
|
||||
print '<input type="hidden" value="'.$enclosure.'" name="enclosure">';
|
||||
|
||||
print '<table summary="selectofimportprofil" class="noborder" width="100%">';
|
||||
|
|
@ -1138,15 +1148,19 @@ if ($step == 5 && $datatoimport)
|
|||
$nboflines=dol_count_nb_of_line($conf->import->dir_temp.'/'.$filetoimport);
|
||||
|
||||
$param='&leftmenu=import&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport).'&nboflines='.$nboflines.'&separator='.urlencode($separator).'&enclosure='.urlencode($enclosure);
|
||||
$param2 = $param;
|
||||
if ($excludefirstline) {
|
||||
$param.='&excludefirstline=1';
|
||||
}
|
||||
|
||||
$param2 = $param; // $param2 = $param without excludefirstline and endatlinenb
|
||||
if ($excludefirstline) $param.='&excludefirstline='.$excludefirstline;
|
||||
if ($endatlinenb) $param.='&endatlinenb='.$endatlinenb;
|
||||
|
||||
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones');
|
||||
|
||||
$head = import_prepare_head($param,5);
|
||||
|
||||
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'?'.$param2.'" method="POST">';
|
||||
print '<input type="hidden" name="step" value="5">'; // step 5
|
||||
print '<input type="hidden" name="action" value="launchsimu">'; // step 5
|
||||
|
||||
dol_fiche_head($head, 'step5', $langs->trans("NewImport"));
|
||||
|
||||
|
||||
|
|
@ -1180,6 +1194,17 @@ if ($step == 5 && $datatoimport)
|
|||
print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format),$text);
|
||||
print '</td></tr>';
|
||||
|
||||
// Separator and enclosure
|
||||
if ($model == 'csv') {
|
||||
print '<tr><td width="25%">'.$langs->trans("CsvOptions").'</td>';
|
||||
print '<td>';
|
||||
print $langs->trans("Separator").' : ';
|
||||
print htmlentities($separator);
|
||||
print ' '.$langs->trans("Enclosure").' : ';
|
||||
print htmlentities($enclosure);
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
// File to import
|
||||
print '<tr><td>'.$langs->trans("FileToImport").'</td>';
|
||||
print '<td>';
|
||||
|
|
@ -1197,16 +1222,40 @@ if ($step == 5 && $datatoimport)
|
|||
print $nboflines;
|
||||
print '</td></tr>';
|
||||
|
||||
// Checkbox do not import first line
|
||||
// Do not import first lines
|
||||
print '<tr><td>';
|
||||
print $langs->trans("Option");
|
||||
print $langs->trans("ImportFromLine");
|
||||
print '</td><td>';
|
||||
print '<input type="checkbox" name="excludefirstline" value="1"';
|
||||
print ($excludefirstline?' checked':'');
|
||||
print ' onClick="javascript: window.location=\''.$_SERVER["PHP_SELF"].'?step=5&excludefirstline='.($excludefirstline?'0':'1').$param2.'\';">';
|
||||
print ' '.$langs->trans("DoNotImportFirstLine");
|
||||
if ($action=='launchsimu')
|
||||
{
|
||||
print '<input type="text" size="4" name="excludefirstlinebis" disabled="disabled" value="'.$excludefirstline.'">';
|
||||
print '<input type="hidden" name="excludefirstline" value="'.$excludefirstline.'">';
|
||||
print ' <a href="'.$_SERVER["PHP_SELF"].'?step=5'.$param.'">'.$langs->trans("Modify").'</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<input type="text" size="4" name="excludefirstline" value="'.$excludefirstline.'">';
|
||||
print $form->textwithpicto("", $langs->trans("SetThisValueTo2ToExcludeFirstLine"));
|
||||
}
|
||||
print '</td></tr>';
|
||||
|
||||
// Do not import end lines
|
||||
print '<tr><td>';
|
||||
print $langs->trans("EndAtLineNb");
|
||||
print '</td><td>';
|
||||
if ($action=='launchsimu')
|
||||
{
|
||||
print '<input type="text" size="4" name="endatlinenbbis" disabled="disabled" value="'.$endatlinenb.'">';
|
||||
print '<input type="hidden" name="endatlinenb" value="'.$endatlinenb.'">';
|
||||
print ' <a href="'.$_SERVER["PHP_SELF"].'?step=5'.$param.'">'.$langs->trans("Modify").'</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<input type="text" size="4" name="endatlinenb" value="'.$endatlinenb.'">';
|
||||
print $form->textwithpicto("", $langs->trans("KeepEmptyToGoToEndOfFile"));
|
||||
}
|
||||
print '</td></tr>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '<br>';
|
||||
|
|
@ -1280,7 +1329,7 @@ if ($step == 5 && $datatoimport)
|
|||
dol_fiche_end();
|
||||
|
||||
|
||||
if (GETPOST('action') != 'launchsimu')
|
||||
if ($action != 'launchsimu')
|
||||
{
|
||||
// Show import id
|
||||
print $langs->trans("NowClickToTestTheImport",$langs->transnoentitiesnoconv("RunSimulateImportFile")).'<br>';
|
||||
|
|
@ -1290,7 +1339,7 @@ if ($step == 5 && $datatoimport)
|
|||
print '<div class="center">';
|
||||
if ($user->rights->import->run)
|
||||
{
|
||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/imports/import.php?leftmenu=import&step=5&action=launchsimu'.$param.'">'.$langs->trans("RunSimulateImportFile").'</a>';
|
||||
print '<input type="submit" class="butAction" value="'.$langs->trans("RunSimulateImportFile").'">';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1336,9 +1385,10 @@ if ($step == 5 && $datatoimport)
|
|||
$endoffile++;
|
||||
continue;
|
||||
}
|
||||
if ($excludefirstline && $sourcelinenb == 1) continue;
|
||||
if ($excludefirstline && ($sourcelinenb < $excludefirstline)) continue;
|
||||
if ($endatlinenb && ($sourcelinenb > $endatlinenb)) continue;
|
||||
|
||||
//
|
||||
// Run import
|
||||
$result=$obj->import_insert($arrayrecord,$array_match_file_to_database,$objimport,count($fieldssource),$importid);
|
||||
|
||||
if (count($obj->errors)) $arrayoferrors[$sourcelinenb]=$obj->errors;
|
||||
|
|
@ -1412,7 +1462,7 @@ if ($step == 5 && $datatoimport)
|
|||
|
||||
print '<div class="center">';
|
||||
print $langs->trans("NowClickToRunTheImport",$langs->transnoentitiesnoconv("RunImportFile")).'<br>';
|
||||
print $langs->trans("DataLoadedWithId",$importid).'<br>';
|
||||
if (empty($nboferrors)) print $langs->trans("DataLoadedWithId",$importid).'<br>';
|
||||
print '</div>';
|
||||
|
||||
print '<br>';
|
||||
|
|
@ -1427,7 +1477,7 @@ if ($step == 5 && $datatoimport)
|
|||
}
|
||||
else
|
||||
{
|
||||
//print '<a class="butAction" href="'.DOL_URL_ROOT.'/imports/import.php?leftmenu=import&step=5&action=launchsimu'.$param.'">'.$langs->trans("RunSimulateImportFile").'</a>';
|
||||
//print '<input type="submit" class="butAction" value="'.dol_escape_htmltag($langs->trans("RunSimulateImportFile")).'">';
|
||||
|
||||
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("CorrectErrorBeforeRunningImport")).'">'.$langs->trans("RunImportFile").'</a>';
|
||||
}
|
||||
|
|
@ -1439,7 +1489,10 @@ if ($step == 5 && $datatoimport)
|
|||
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("RunImportFile").'</a>';
|
||||
}
|
||||
print '</div>';
|
||||
|
||||
}
|
||||
|
||||
print '</form>';
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1482,7 +1535,8 @@ if ($step == 6 && $datatoimport)
|
|||
$nboflines=(! empty($_GET["nboflines"])?$_GET["nboflines"]:dol_count_nb_of_line($conf->import->dir_temp.'/'.$filetoimport));
|
||||
|
||||
$param='&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport).'&nboflines='.$nboflines;
|
||||
if ($excludefirstline) $param.='&excludefirstline=1';
|
||||
if ($excludefirstline) $param.='&excludefirstline='.$excludefirstline;
|
||||
if ($endatlinenb) $param.='&endatlinenb='.$endatlinenb;
|
||||
if ($separator) $param.='&separator='.urlencode($separator);
|
||||
if ($enclosure) $param.='&enclosure='.urlencode($enclosure);
|
||||
|
||||
|
|
@ -1540,16 +1594,20 @@ if ($step == 6 && $datatoimport)
|
|||
print $nboflines;
|
||||
print '</td></tr>';
|
||||
|
||||
// Checkbox do not import first line
|
||||
// Do not import first lines
|
||||
print '<tr><td>';
|
||||
print $langs->trans("Option");
|
||||
print $langs->trans("ImportFromLine");
|
||||
print '</td><td>';
|
||||
print '<input type="checkbox" name="excludefirstline" value="1" disabled';
|
||||
print ($excludefirstline?' checked':'');
|
||||
print '>';
|
||||
print ' '.$langs->trans("DoNotImportFirstLine");
|
||||
print '<input type="text" size="4" name="excludefirstline" disabled="disabled" value="'.$excludefirstline.'">';
|
||||
print '</td></tr>';
|
||||
|
||||
// Do not import end lines
|
||||
print '<tr><td>';
|
||||
print $langs->trans("EndAtLineNb");
|
||||
print '</td><td>';
|
||||
print '<input type="text" size="4" name="endatlinenb" disabled="disabled" value="'.$endatlinenb.'">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '<br>';
|
||||
|
|
@ -1651,9 +1709,12 @@ if ($step == 6 && $datatoimport)
|
|||
$endoffile++;
|
||||
continue;
|
||||
}
|
||||
if ($excludefirstline && $sourcelinenb == 1) continue;
|
||||
if ($excludefirstline && ($sourcelinenb < $excludefirstline)) continue;
|
||||
if ($endatlinenb && ($sourcelinenb > $endatlinenb)) continue;
|
||||
|
||||
// Run import
|
||||
$result=$obj->import_insert($arrayrecord,$array_match_file_to_database,$objimport,count($fieldssource),$importid);
|
||||
|
||||
if (count($obj->errors)) $arrayoferrors[$sourcelinenb]=$obj->errors;
|
||||
if (count($obj->warnings)) $arrayofwarnings[$sourcelinenb]=$obj->warnings;
|
||||
if (! count($obj->errors) && ! count($obj->warnings)) $nbok++;
|
||||
|
|
|
|||
|
|
@ -128,6 +128,10 @@ SpecialCode=Special code
|
|||
ExportStringFilter=%% allows replacing one or more characters in the text
|
||||
ExportDateFilter=YYYY, YYYYMM, YYYYMMDD : filters by one year/month/day<br>YYYY+YYYY, YYYYMM+YYYYMM, YYYYMMDD+YYYYMMDD : filters over a range of years/months/days<br> > YYYY, > YYYYMM, > YYYYMMDD : filters on all following years/months/days<br> < YYYY, < YYYYMM, < YYYYMMDD : filters on all previous years/months/days
|
||||
ExportNumericFilter='NNNNN' filters by one value<br>'NNNNN+NNNNN' filters over a range of values<br>'>NNNNN' filters by lower values<br>'>NNNNN' filters by higher values
|
||||
ImportFromLine=Import starting from line number
|
||||
EndAtLineNb=End at line number
|
||||
SetThisValueTo2ToExcludeFirstLine=For example, set this value to 3 to exclude the 2 first lines
|
||||
KeepEmptyToGoToEndOfFile=Keep this field empty to go up to the end of file
|
||||
## filters
|
||||
SelectFilterFields=If you want to filter on some values, just input values here.
|
||||
FilterableFields=Filterable Fields
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user