29require_once
'../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/imports/class/import.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/modules/import/modules_import.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/import.lib.php';
39$langs->loadLangs(array(
'exports',
'compta',
'errors',
'projects',
'admin'));
47 'invoice_line' =>
'bill',
49 'order_line' =>
'order',
51 'propal_line' =>
'propal',
52 'intervention' =>
'intervention',
53 'inter_line' =>
'intervention',
55 'member_type' =>
'group',
56 'subscription' =>
'payment',
57 'payment' =>
'payment',
59 'tax_type' =>
'generic',
61 'account' =>
'account',
62 'product' =>
'product',
63 'virtualproduct' =>
'product',
64 'subproduct' =>
'product',
65 'product_supplier_ref' =>
'product',
67 'warehouse' =>
'stock',
69 'stockbatch' =>
'stock',
70 'category' =>
'category',
71 'shipment' =>
'sending',
72 'shipment_line' =>
'sending',
73 'reception' =>
'sending',
74 'reception_line' =>
'sending',
75 'expensereport' =>
'trip',
76 'expensereport_line' =>
'trip',
77 'holiday' =>
'holiday',
78 'contract_line' =>
'contract',
79 'translation' =>
'generic',
87 'company' =>
'Company',
88 'contact' =>
'Contact',
90 'invoice_line' =>
'InvoiceLine',
92 'order_line' =>
'OrderLine',
93 'propal' =>
'Proposal',
94 'propal_line' =>
'ProposalLine',
95 'intervention' =>
'Intervention',
96 'inter_line' =>
'InterLine',
98 'member_type' =>
'MemberType',
99 'subscription' =>
'Subscription',
100 'tax' =>
'SocialContribution',
101 'tax_type' =>
'DictionarySocialContributions',
102 'account' =>
'BankTransactions',
103 'payment' =>
'Payment',
104 'product' =>
'Product',
105 'virtualproduct' =>
'AssociatedProducts',
106 'subproduct' =>
'SubProduct',
107 'product_supplier_ref' =>
'SupplierPrices',
108 'service' =>
'Service',
110 'movement' =>
'StockMovement',
112 'stockbatch' =>
'StockDetailPerBatch',
113 'warehouse' =>
'Warehouse',
114 'category' =>
'Category',
116 'trip' =>
'TripsAndExpenses',
117 'shipment' =>
'Shipments',
118 'shipment_line' =>
'ShipmentLine',
119 'project' =>
'Projects',
120 'projecttask' =>
'Tasks',
121 'task_time' =>
'TaskTimeSpent',
123 'expensereport' =>
'ExpenseReport',
124 'expensereport_line' =>
'ExpenseReportLine',
125 'holiday' =>
'TitreRequestCP',
126 'contract' =>
'Contract',
127 'contract_line' =>
'ContractLine',
128 'translation' =>
'Translation',
130 'bomline' =>
'BOMLine'
133$datatoimport =
GETPOST(
'datatoimport');
135$filetoimport =
GETPOST(
'filetoimport');
136$action =
GETPOST(
'action',
'alpha');
137$confirm =
GETPOST(
'confirm',
'alpha');
139$import_name =
GETPOST(
'import_name');
142$excludefirstline = (
GETPOST(
'excludefirstline') ?
GETPOST(
'excludefirstline') : 2);
143$endatlinenb = (
GETPOST(
'endatlinenb') ?
GETPOST(
'endatlinenb') :
'');
144$updatekeys = (
GETPOST(
'updatekeys',
'array') ?
GETPOST(
'updatekeys',
'array') : array());
145$separator = (
GETPOST(
'separator',
'nohtml') ?
GETPOST(
'separator',
'nohtml', 3) :
'');
146$enclosure = (
GETPOST(
'enclosure',
'nohtml') ?
GETPOST(
'enclosure',
'nohtml') :
'"');
147$charset =
GETPOST(
'charset',
'aZ09');
148$separator_used = str_replace(
'\t',
"\t", $separator);
152$hookmanager->initHooks(array(
'imports'));
155$objimport =
new Import($db);
156$objimport->load_arrays($user, ($step == 1 ?
'' : $datatoimport));
158if (empty($updatekeys) && !empty($objimport->array_import_preselected_updatekeys[0])) {
159 $updatekeys = $objimport->array_import_preselected_updatekeys[0];
164$form =
new Form($db);
169if (empty($array_match_file_to_database)) {
170 $serialized_array_match_file_to_database = isset($_SESSION[
"dol_array_match_file_to_database_select"]) ? $_SESSION[
"dol_array_match_file_to_database_select"] :
'';
171 $array_match_file_to_database = array();
172 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
173 foreach ($fieldsarray as $elem) {
174 $tabelem = explode(
'=', $elem, 2);
176 $val = (isset($tabelem[1]) ? $tabelem[1] :
'');
178 $array_match_file_to_database[$key] = $val;
188if ($action ==
'deleteprof') {
191 $result = $objimport->delete($user);
196if ($action ==
'add_import_model') {
200 foreach ($array_match_file_to_database as $key => $val) {
204 $hexa .= $key.
'='.$val;
207 $objimport->model_name = $import_name;
208 $objimport->datatoimport = $datatoimport;
209 $objimport->hexa = $hexa;
210 $objimport->fk_user = (
GETPOST(
'visibility',
'aZ09') ==
'all' ? 0 : $user->id);
212 $result = $objimport->create($user);
214 setEventMessages($langs->trans(
"ImportModelSaved", $objimport->model_name),
null,
'mesgs');
217 $langs->load(
"errors");
218 if ($objimport->errno ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
219 setEventMessages($langs->trans(
"ErrorImportDuplicateProfil"),
null,
'errors');
225 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"ImportModelName")),
null,
'errors');
229if ($step == 3 && $datatoimport) {
234 $fullpath = $conf->import->dir_temp.
"/".$nowyearmonth.
'-'.$_FILES[
'userfile'][
'name'];
236 dol_syslog(
"File ".$fullpath.
" was added for import");
238 $langs->load(
"errors");
244 if ($action ==
'confirm_deletefile' && $confirm ==
'yes') {
245 $langs->load(
"other");
247 $param =
'&datatoimport='.urlencode($datatoimport).
'&format='.urlencode($format);
248 if ($excludefirstline) {
249 $param .=
'&excludefirstline='.urlencode($excludefirstline);
252 $param .=
'&endatlinenb='.urlencode($endatlinenb);
255 $file = $conf->import->dir_temp.
'/'.
GETPOST(
'urlfile');
262 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?step='.$step.$param);
267if ($step == 4 && $action ==
'select_model') {
269 $_SESSION[
"dol_array_match_file_to_database"] =
'';
270 $serialized_array_match_file_to_database =
'';
271 $array_match_file_to_database = array();
275 $result = $objimport->fetch($importmodelid);
277 $serialized_array_match_file_to_database = $objimport->hexa;
278 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
279 foreach ($fieldsarray as $elem) {
280 $tabelem = explode(
'=', $elem);
284 $array_match_file_to_database[$key] = $val;
287 $_SESSION[
"dol_array_match_file_to_database"] = $serialized_array_match_file_to_database;
288 $_SESSION[
'dol_array_match_file_to_database_select'] = $_SESSION[
"dol_array_match_file_to_database"];
291if ($action ==
'saveselectorder') {
293 $serialized_array_match_file_to_database =
'';
295 $selectorder = explode(
",",
GETPOST(
'selectorder'));
296 $fieldtarget = $fieldstarget = $objimport->array_import_fields[0];
297 foreach ($selectorder as $key => $code) {
298 $serialized_array_match_file_to_database .= $key.
'='.$code;
299 $serialized_array_match_file_to_database .=
',';
301 $serialized_array_match_file_to_database = substr($serialized_array_match_file_to_database, 0, -1);
302 dol_syslog(
'dol_array_match_file_to_database_select='.$serialized_array_match_file_to_database);
303 $_SESSION[
"dol_array_match_file_to_database_select"] = $serialized_array_match_file_to_database;
315$help_url =
'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones';
319if ($step == 1 || !$datatoimport) {
321 $serialized_array_match_file_to_database =
'';
322 $array_match_file_to_database = array();
323 $_SESSION[
"dol_array_match_file_to_database"] =
'';
324 $_SESSION[
"dol_array_match_file_to_database_select"] =
'';
327 if ($excludefirstline) {
328 $param .=
'&excludefirstline='.urlencode($excludefirstline);
331 $param .=
'&endatlinenb='.urlencode($endatlinenb);
334 $param .=
'&separator='.urlencode($separator);
337 $param .=
'&enclosure='.urlencode($enclosure);
340 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
346 print
'<div class="opacitymedium">'.$langs->trans(
"SelectImportDataSet").
'</div><br>';
349 print
'<div class="div-table-responsive-no-min">';
350 print
'<table class="noborder centpercent">';
351 print
'<tr class="liste_titre">';
352 print
'<td>'.$langs->trans(
"Module").
'</td>';
353 print
'<td>'.$langs->trans(
"ImportableDatas").
'</td>';
354 print
'<td> </td>';
357 if (count($objimport->array_import_module)) {
358 $sortedarrayofmodules =
dol_sort_array($objimport->array_import_module,
'position_of_profile',
'asc', 0, 0, 1);
359 foreach ($sortedarrayofmodules as $key => $value) {
361 print
'<tr class="oddeven"><td>';
362 $titleofmodule = $objimport->array_import_module[$key][
'module']->getName();
364 if (in_array($objimport->array_import_code[$key], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
365 $titleofmodule = $langs->trans(
"ProductOrService");
367 print $titleofmodule;
369 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[$key]);
370 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
371 print
img_object($objimport->array_import_module[$key][
'module']->getName(), $entityicon).
' ';
372 print $objimport->array_import_label[$key];
373 print
'</td><td style="text-align: right">';
374 if ($objimport->array_import_perms[$key]) {
375 print
'<a href="'.DOL_URL_ROOT.
'/imports/import.php?step=2&datatoimport='.$objimport->array_import_code[$key].$param.
'">'.
img_picto($langs->trans(
"NewImport"),
'next',
'class="fa-15"').
'</a>';
377 print $langs->trans(
"NotEnoughPermissions");
382 print
'<tr><td class="oddeven" colspan="3">'.$langs->trans(
"NoImportableData").
'</td></tr>';
392if ($step == 2 && $datatoimport) {
393 $param =
'&datatoimport='.urlencode($datatoimport);
394 if ($excludefirstline) {
395 $param .=
'&excludefirstline='.urlencode($excludefirstline);
398 $param .=
'&endatlinenb='.urlencode($endatlinenb);
401 $param .=
'&separator='.urlencode($separator);
404 $param .=
'&enclosure='.urlencode($enclosure);
407 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
413 print
'<div class="underbanner clearboth"></div>';
414 print
'<div class="fichecenter">';
416 print
'<table class="border tableforfield centpercent">';
419 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
421 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
423 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
424 $titleofmodule = $langs->trans(
"ProductOrService");
426 print $titleofmodule;
430 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
432 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
433 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
434 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
435 print $objimport->array_import_label[0];
443 print
'<form name="userfile" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" METHOD="POST">';
444 print
'<input type="hidden" name="token" value="'.newToken().
'">';
448 print
'<span class="opacitymedium">';
449 $s = $langs->trans(
"ChooseFormatOfFileToImport",
'{s1}');
450 $s = str_replace(
'{s1}',
img_picto(
'',
'next'), $s);
452 print
'</span><br><br>';
456 print
'<div class="div-table-responsive-no-min">';
457 print
'<table class="noborder centpercent" cellpadding="4">';
462 print
'<tr class="liste_titre"><td colspan="5">';
463 print $langs->trans(
"FileMustHaveOneOfFollowingFormat");
465 $list = $objmodelimport->listOfAvailableImportFormat($db);
466 foreach ($list as $key) {
467 print
'<tr class="oddeven">';
468 print
'<td width="16">'.img_picto_common($key, $objmodelimport->getPictoForKey($key)).
'</td>';
469 $htmltext = $objmodelimport->getDriverDescForKey($key);
470 print
'<td>'.$form->textwithpicto($objmodelimport->getDriverLabelForKey($key), $htmltext).
'</td>';
471 print
'<td style="text-align:center">';
472 if (empty($objmodelimport->drivererror[$key])) {
473 $filename = $langs->transnoentitiesnoconv(
"ExampleOfImportFile").
'_'.$datatoimport.
'.'.$key;
474 print
'<a href="'.DOL_URL_ROOT.
'/imports/emptyexample.php?format='.$key.$param.
'&output=file&file='.urlencode($filename).
'" target="_blank" rel="noopener noreferrer">';
475 print
img_picto(
'',
'download',
'class="paddingright opacitymedium"');
476 print $langs->trans(
"DownloadEmptyExampleShort");
478 print $form->textwithpicto(
'', $langs->trans(
"DownloadEmptyExample").
'.<br>'.$langs->trans(
"StarAreMandatory"));
484 print
'<td style="text-align:right">';
485 if (empty($objmodelimport->drivererror[$key])) {
486 print
'<a href="'.DOL_URL_ROOT.
'/imports/import.php?step=3&format='.$key.$param.
'">'.
img_picto($langs->trans(
"SelectFormat"),
'next',
'class="fa-15"').
'</a>';
500if ($step == 3 && $datatoimport) {
501 $param =
'&datatoimport='.urlencode($datatoimport).
'&format='.urlencode($format);
502 if ($excludefirstline) {
503 $param .=
'&excludefirstline='.urlencode($excludefirstline);
506 $param .=
'&endatlinenb='.urlencode($endatlinenb);
509 $param .=
'&separator='.urlencode($separator);
512 $param .=
'&enclosure='.urlencode($enclosure);
515 $list = $objmodelimport->listOfAvailableImportFormat($db);
517 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
526 if ($action ==
'delete') {
527 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?urlfile='.urlencode(
GETPOST(
'urlfile')).
'&step=3'.$param, $langs->trans(
'DeleteFile'), $langs->trans(
'ConfirmDeleteFile'),
'confirm_deletefile',
'', 0, 1);
530 print
'<div class="underbanner clearboth"></div>';
531 print
'<div class="fichecenter">';
533 print
'<table class="border tableforfield centpercent">';
536 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
538 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
540 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
541 $titleofmodule = $langs->trans(
"ProductOrService");
543 print $titleofmodule;
547 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
549 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
550 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
551 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
552 print $objimport->array_import_label[0];
558 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
560 print
'<div class="underbanner clearboth"></div>';
561 print
'<div class="fichecenter">';
562 print
'<table width="100%" class="border tableforfield">';
565 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
566 print
'<td class="nowraponall">';
567 $text = $objmodelimport->getDriverDescForKey($format);
569 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
570 print
'</td><td style="text-align:right" class="nowrap">';
571 $filename = $langs->transnoentitiesnoconv(
"ExampleOfImportFile").
'_'.$datatoimport.
'.'.$format;
572 print
'<a href="'.DOL_URL_ROOT.
'/imports/emptyexample.php?format='.$format.$param.
'&output=file&file='.urlencode($filename).
'" target="_blank" rel="noopener noreferrer">';
573 print
img_picto(
'',
'download',
'class="paddingright opacitymedium"');
574 print $langs->trans(
"DownloadEmptyExampleShort");
576 print $form->textwithpicto(
'', $langs->trans(
"DownloadEmptyExample").
'.<br>'.$langs->trans(
"StarAreMandatory"));
585 if ($format ==
'xlsx' && !class_exists(
'XMLWriter')) {
586 $langs->load(
"install");
587 print
info_admin($langs->trans(
"ErrorPHPDoesNotSupport",
'php-xml'), 0, 0, 1,
'error');
593 print
'<form name="userfile" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="POST">';
594 print
'<input type="hidden" name="token" value="'.newToken().
'">';
595 print
'<input type="hidden" value="'.$step.
'" name="step">';
596 print
'<input type="hidden" value="'.dol_escape_htmltag($format).
'" name="format">';
597 print
'<input type="hidden" value="'.$excludefirstline.
'" name="excludefirstline">';
598 print
'<input type="hidden" value="'.$endatlinenb.
'" name="endatlinenb">';
599 print
'<input type="hidden" value="'.dol_escape_htmltag($separator).
'" name="separator">';
600 print
'<input type="hidden" value="'.dol_escape_htmltag($enclosure).
'" name="enclosure">';
601 print
'<input type="hidden" value="'.dol_escape_htmltag($datatoimport).
'" name="datatoimport">';
603 print
'<span class="opacitymedium">';
604 $s = $langs->trans(
"ChooseFileToImport",
'{s1}');
605 $s = str_replace(
'{s1}',
img_picto(
'',
'next'), $s);
607 print
'</span><br><br>';
612 print
'<div class="marginbottomonly">';
614 $maxmin = $maxfilesizearray[
'maxmin'];
616 print
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
618 print
'<input type="file" name="userfile" size="20" maxlength="80"> ';
620 print
'<input type="submit" class="button small" value="'.$langs->trans(
"AddFile").
'"'.$out.
' name="sendit">';
624 $maxphp = @ini_get(
'upload_max_filesize');
625 if (preg_match(
'/k$/i', $maxphp)) {
626 $maxphp = (int) substr($maxphp, 0, -1);
628 if (preg_match(
'/m$/i', $maxphp)) {
629 $maxphp = (int) substr($maxphp, 0, -1) * 1024;
631 if (preg_match(
'/g$/i', $maxphp)) {
632 $maxphp = (int) substr($maxphp, 0, -1) * 1024 * 1024;
634 if (preg_match(
'/t$/i', $maxphp)) {
635 $maxphp = (int) substr($maxphp, 0, -1) * 1024 * 1024 * 1024;
637 $maxphp2 = @ini_get(
'post_max_size');
638 if (preg_match(
'/k$/i', $maxphp2)) {
639 $maxphp2 = (int) substr($maxphp2, 0, -1);
641 if (preg_match(
'/m$/i', $maxphp2)) {
642 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024;
644 if (preg_match(
'/g$/i', $maxphp2)) {
645 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024 * 1024;
647 if (preg_match(
'/t$/i', $maxphp2)) {
648 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024 * 1024 * 1024;
652 $maxphptoshow = $maxphptoshowparam =
'';
654 $maxmin = min($max, $maxphp);
655 $maxphptoshow = $maxphp;
656 $maxphptoshowparam =
'upload_max_filesize';
659 $maxmin = min($max, $maxphp2);
660 if ($maxphp2 < $maxphp) {
661 $maxphptoshow = $maxphp2;
662 $maxphptoshowparam =
'post_max_size';
666 $langs->load(
'other');
668 $out .=
info_admin($langs->trans(
"ThisLimitIsDefinedInSetup", $max, $maxphptoshow), 1);
670 $out .=
' ('.$langs->trans(
"UploadDisabled").
')';
676 $filearray =
dol_dir_list($conf->import->dir_temp,
'files', 0,
'',
'',
'name', SORT_DESC);
677 if (count($filearray) > 0) {
678 print
'<div class="div-table-responsive-no-min">';
679 print
'<table class="noborder centpercent" width="100%" cellpadding="4">';
681 $dir = $conf->import->dir_temp;
685 foreach ($filearray as $key => $val) {
686 $file = $val[
'name'];
690 $file = mb_convert_encoding($file,
'UTF-8',
'ISO-8859-1');
693 if (preg_match(
'/^\./', $file)) {
697 $modulepart =
'import';
698 $urlsource = $_SERVER[
"PHP_SELF"].
'?step='.$step.$param.
'&filetoimport='.urlencode($filetoimport);
699 $relativepath = $file;
701 print
'<tr class="oddeven">';
703 print
img_mime($file,
'',
'pictofixedwidth');
704 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=3'.$param.
'" target="_blank" rel="noopener noreferrer">';
709 print
'<td style="text-align:right">'.dol_print_size(
dol_filesize($dir.
'/'.$file)).
'</td>';
711 print
'<td style="text-align:right">'.dol_print_date(
dol_filemtime($dir.
'/'.$file),
'dayhour').
'</td>';
713 print
'<td style="text-align:right"><a href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.
newToken().
'&step=3'.$param.
'&urlfile='.urlencode($relativepath);
714 print
'">'.img_delete().
'</a></td>';
716 print
'<td style="text-align:right">';
717 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?step=4'.$param.
'&filetoimport='.urlencode($relativepath).
'">'.
img_picto($langs->trans(
"NewImport"),
'next',
'class="fa-15"').
'</a>';
731if ($step == 4 && $datatoimport) {
733 $serialized_array_match_file_to_database = isset($_SESSION[
"dol_array_match_file_to_database_select"]) ? $_SESSION[
"dol_array_match_file_to_database_select"] :
'';
734 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
735 $array_match_file_to_database = array();
736 foreach ($fieldsarray as $elem) {
737 $tabelem = explode(
'=', $elem, 2);
739 $val = (isset($tabelem[1]) ? $tabelem[1] :
'');
741 $array_match_file_to_database[$key] = $val;
750 $list = $objmodelimport->listOfAvailableImportFormat($db);
752 if (empty($separator)) {
753 $separator = (!
getDolGlobalString(
'IMPORT_CSV_SEPARATOR_TO_USE') ?
',' : $conf->global->IMPORT_CSV_SEPARATOR_TO_USE);
757 if ($model ==
'csv' && strlen($separator) == 1 && !GETPOSTISSET(
'separator')) {
759 $fh = fopen($conf->import->dir_temp.
'/'.$filetoimport,
'r');
761 $sline = fgets($fh, 1000000);
763 $nboccurence = substr_count($sline, $separator);
764 $nboccurencea = substr_count($sline,
',');
765 $nboccurenceb = substr_count($sline,
';');
767 if ($nboccurence == 0) {
768 if ($nboccurencea > 2) {
770 } elseif ($nboccurenceb > 2) {
778 $separator_used = str_replace(
'\t',
"\t", $separator);
781 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
782 $file =
"import_".$model.
".modules.php";
783 $classname =
"Import".ucfirst($model);
784 require_once $dir.$file;
785 $obj =
new $classname($db, $datatoimport);
787 if (!empty($obj->error)) {
788 $langs->load(
"errors");
789 $param =
'&datatoimport='.$datatoimport.
'&format='.$format;
791 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?step=3'.$param.
'&filetoimport='.urlencode($relativepath));
796 if ($model ==
'csv') {
797 $obj->separator = $separator_used;
798 $obj->enclosure = $enclosure;
801 if ($model ==
'xlsx') {
802 if (!preg_match(
'/\.xlsx$/i', $filetoimport)) {
803 $langs->load(
"errors");
804 $param =
'&datatoimport='.$datatoimport.
'&format='.$format;
805 setEventMessages($langs->trans(
"ErrorFileMustHaveFormat", $model),
null,
'errors');
806 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?step=3'.$param.
'&filetoimport='.urlencode($relativepath));
812 $array_match_file_to_database = array();
816 $fieldssource = array();
817 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport, $langs);
820 $arrayrecord = $obj->import_read_record();
824 foreach ($arrayrecord as $key => $val) {
825 if ($val[
"type"] != -1) {
826 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 128);
829 $fieldssource[$i][
'example1'] = $langs->trans(
'Empty');
833 $obj->import_close_file();
837 $fieldstarget = $objimport->array_import_fields[0];
838 $minpos = min(count($fieldssource), count($fieldstarget));
842 $initialloadofstep4 =
false;
843 if (empty($_SESSION[
'dol_array_match_file_to_database_select'])) {
844 $initialloadofstep4 =
true;
848 if (count($array_match_file_to_database) == 0) {
854 $num = count($fieldssource);
855 while ($pos <= $num) {
856 if ($num >= 1 && $pos <= $num) {
858 foreach ($fieldstarget as $key => $val) {
859 if ($posbis < $pos) {
864 $array_match_file_to_database[$pos] = $key;
871 $array_match_database_to_file = array_flip($array_match_file_to_database);
875 $fieldstarget_tmp = array();
876 $arraykeysfieldtarget = array_keys($fieldstarget);
878 foreach ($fieldstarget as $key => $label) {
879 $isrequired = preg_match(
'/\*$/', $label);
880 if (!empty($isrequired)) {
881 $newlabel = substr($label, 0, -1);
882 $fieldstarget_tmp[$key] = array(
"label" => $newlabel,
"required" =>
true);
884 $fieldstarget_tmp[$key] = array(
"label" => $label,
"required" =>
false);
886 if (!empty($array_match_database_to_file[$key])) {
887 $fieldstarget_tmp[$key][
"imported"] =
true;
888 $fieldstarget_tmp[$key][
"position"] = $array_match_database_to_file[$key] - 1;
890 while (!empty($array_match_database_to_file[$keytoswap])) {
891 if ($position + 1 > $array_match_database_to_file[$keytoswap]) {
892 $keytoswapwith = $array_match_database_to_file[$keytoswap] - 1;
893 $tmp = [$keytoswap => $fieldstarget_tmp[$keytoswap]];
894 unset($fieldstarget_tmp[$keytoswap]);
895 $fieldstarget_tmp =
arrayInsert($fieldstarget_tmp, $keytoswapwith, $tmp);
896 $keytoswapwith = $arraykeysfieldtarget[$array_match_database_to_file[$keytoswap] - 1];
897 $tmp = $fieldstarget_tmp[$keytoswapwith];
898 unset($fieldstarget_tmp[$keytoswapwith]);
899 $fieldstarget_tmp[$keytoswapwith] = $tmp;
900 $keytoswap = $keytoswapwith;
906 $fieldstarget_tmp[$key][
"imported"] =
false;
910 $fieldstarget = $fieldstarget_tmp;
919 $param =
'&format='.$format.
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport);
920 if ($excludefirstline) {
921 $param .=
'&excludefirstline='.urlencode($excludefirstline);
924 $param .=
'&endatlinenb='.urlencode($endatlinenb);
927 $param .=
'&separator='.urlencode($separator);
930 $param .=
'&enclosure='.urlencode($enclosure);
933 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
939 print
'<div class="underbanner clearboth"></div>';
940 print
'<div class="fichecenter">';
942 print
'<table class="centpercent border tableforfield">';
945 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
947 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
949 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
950 $titleofmodule = $langs->trans(
"ProductOrService");
952 print $titleofmodule;
956 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
958 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
959 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
960 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
961 print $objimport->array_import_label[0];
967 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
969 print
'<div class="underbanner clearboth"></div>';
970 print
'<div class="fichecenter">';
971 print
'<table width="100%" class="border tableforfield">';
974 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
976 $text = $objmodelimport->getDriverDescForKey($format);
978 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
982 if ($model ==
'csv') {
983 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
985 print
'<form method="POST">';
986 print
'<input type="hidden" name="token" value="'.newToken().
'">';
987 print
'<input type="hidden" value="'.$step.
'" name="step">';
988 print
'<input type="hidden" value="'.$format.
'" name="format">';
989 print
'<input type="hidden" value="'.$excludefirstline.
'" name="excludefirstline">';
990 print
'<input type="hidden" value="'.$endatlinenb.
'" name="endatlinenb">';
991 print
'<input type="hidden" value="'.$datatoimport.
'" name="datatoimport">';
992 print
'<input type="hidden" value="'.$filetoimport.
'" name="filetoimport">';
993 print $langs->trans(
"Separator").
' : ';
994 print
'<input type="text" class="width25 center" name="separator" value="'.dol_escape_htmltag($separator).
'"/>';
995 print
' '.$langs->trans(
"Enclosure").
' : ';
996 print
'<input type="text" class="width25 center" name="enclosure" value="'.dol_escape_htmltag($enclosure).
'"/> ';
997 print
'<input name="update" type="submit" value="'.$langs->trans(
'Update').
'" class="button smallpaddingimp" />';
1003 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
1005 $modulepart =
'import';
1006 $relativepath =
GETPOST(
'filetoimport');
1007 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
1008 print
img_mime($file,
'',
'pictofixedwidth');
1009 print $filetoimport;
1010 print
img_picto($langs->trans(
"Download"),
'download',
'class="paddingleft opacitymedium"');
1023 print
'<!-- List of source fields -->'.
"\n";
1024 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1025 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1026 print
'<input type="hidden" name="action" value="select_model">';
1027 print
'<input type="hidden" name="step" value="4">';
1028 print
'<input type="hidden" name="format" value="'.$format.
'">';
1029 print
'<input type="hidden" name="datatoimport" value="'.$datatoimport.
'">';
1030 print
'<input type="hidden" name="filetoimport" value="'.$filetoimport.
'">';
1031 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1032 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1033 print
'<input type="hidden" name="separator" value="'.dol_escape_htmltag($separator).
'">';
1034 print
'<input type="hidden" name="enclosure" value="'.dol_escape_htmltag($enclosure).
'">';
1037 print
'<div class="marginbottomonly">';
1038 print
'<span class="opacitymedium">';
1039 $s = $langs->trans(
"SelectImportFieldsSource",
'{s1}');
1040 $s = str_replace(
'{s1}',
img_picto(
'',
'grip_title',
'',
false, 0, 0,
'',
'', 0), $s);
1043 $htmlother->select_import_model($importmodelid,
'importmodelid', $datatoimport, 1, $user->id);
1044 print
'<input type="submit" class="button small reposition" value="'.$langs->trans(
"Select").
'">';
1049 print
'<div class="div-table-responsive-no-min">';
1050 print
'<table class="noborder centpercent">';
1051 print
'<tr class="liste_titre">';
1052 print
'<td>'.$langs->trans(
"FieldsInSourceFile").
'</td>';
1053 print
'<td>'.$langs->trans(
"FieldsInTargetDatabase").
'</td>';
1058 print
'<tr valign="top"><td width="50%" class="nopaddingleftimp">';
1060 $fieldsplaced = array();
1061 $valforsourcefieldnb = array();
1062 $listofkeys = array();
1063 foreach ($array_match_file_to_database as $key => $val) {
1064 $listofkeys[$key] = 1;
1067 print
"\n<!-- Box left container -->\n";
1068 print
'<div id="left" class="connectedSortable">'.
"\n";
1073 foreach ($fieldssource as $key => $val) {
1076 $listofkeys[$key] = 1;
1077 $fieldsplaced[$key] = 1;
1078 $valforsourcefieldnb[$lefti] = $key;
1088 print
"<!-- End box left container -->\n";
1091 print
'</td><td width="50%" class="nopaddingrightimp">';
1095 $optionsall = array();
1096 foreach ($fieldstarget as $code => $line) {
1099 $tmparray = explode(
'|', $line[
"label"]);
1101 foreach ($tmparray as $tmpkey => $tmpval) {
1102 $labeltoshow .= ($labeltoshow ?
' '.$langs->trans(
'or').
' ' :
'').$langs->transnoentities($tmpval);
1104 $optionsall[$code] = array(
'labelkey' => $line[
'label'],
'labelkeyarray' => $tmparray,
'label' => $labeltoshow,
'required' => (empty($line[
"required"]) ? 0 : 1),
'position' => !empty($line[
'position']) ? $line[
'position'] : 0);
1109 $optionsall[$code][
'picto'] = $picto;
1116 $mandatoryfieldshavesource =
true;
1129 $modetoautofillmapping =
'session';
1130 if ($initialloadofstep4) {
1131 $modetoautofillmapping =
'guess';
1135 print
'<table class="nobordernopadding centpercent tableimport">';
1136 foreach ($fieldssource as $code => $line) {
1140 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
1141 $entity = (!empty($objimport->array_import_entities[0][$code]) ? $objimport->array_import_entities[0][$code] : $objimport->array_import_icon[0]);
1143 $entityicon = !empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity;
1144 $entitylang = !empty($entitytolang[$entity]) ? $entitytolang[$entity] : $objimport->array_import_label[0];
1146 print
'<td class="nowraponall hideonsmartphone" style="font-weight: normal">=> </td>';
1147 print
'<td class="nowraponall" style="font-weight: normal">';
1152 $selectforline =
'';
1153 $selectforline .=
'<select id="selectorderimport_'.($i + 1).
'" class="targetselectchange minwidth300" name="select_'.($i + 1).
'">';
1154 if (!empty($line[
"imported"])) {
1155 $selectforline .=
'<option value="-1"> </option>';
1157 $selectforline .=
'<option selected="" value="-1"> </option>';
1161 $codeselectedarray = array();
1162 foreach ($optionsall as $tmpcode => $tmpval) {
1164 if (!empty($tmpval[
'picto'])) {
1165 $label .=
img_picto(
'', $tmpval[
'picto'],
'class="pictofixedwidth"');
1167 $label .= $tmpval[
'required'] ?
'<strong>' :
'';
1168 $label .= $tmpval[
'label'];
1169 $label .= $tmpval[
'required'] ?
'*</strong>' :
'';
1171 $tablealias = preg_replace(
'/(\..*)$/i',
'', $tmpcode);
1172 $tablename = !empty($objimport->array_import_tables[0][$tablealias]) ? $objimport->array_import_tables[0][$tablealias] :
"";
1176 $filecolumn = ($i + 1);
1178 if (empty($objimport->array_import_convertvalue[0][$tmpcode])) {
1181 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromref') {
1182 $htmltext .= $langs->trans(
"DataComeFromIdFoundFromRef", $langs->transnoentitiesnoconv($entitylang)).
'<br>';
1184 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromcodeid') {
1185 $htmltext .= $langs->trans(
"DataComeFromIdFoundFromCodeId", $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$tmpcode][
'dict'])).
'<br>';
1189 $example = !empty($objimport->array_import_examplevalues[0][$tmpcode]) ? $objimport->array_import_examplevalues[0][$tmpcode] :
"";
1191 if (empty($objimport->array_import_convertvalue[0][$tmpcode])) {
1193 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.str_replace(
'"',
'', $example).
'</b><br>';
1196 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromref') {
1197 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.$langs->transnoentitiesnoconv(
"ExampleAnyRefFoundIntoElement", $entitylang).($example ?
' ('.$langs->transnoentitiesnoconv(
"Example").
': '.str_replace(
'"',
'', $example).
')' :
'').
'</b><br>';
1198 } elseif ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromcodeid') {
1199 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.$langs->trans(
"ExampleAnyCodeOrIdFoundIntoDictionary", $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$tmpcode][
'dict'])).($example ?
' ('.$langs->transnoentitiesnoconv(
"Example").
': '.str_replace(
'"',
'', $example).
')' :
'').
'</b><br>';
1200 } elseif ($example) {
1201 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.str_replace(
'"',
'', $example).
'</b><br>';
1205 if (!empty($objimport->array_import_regex[0][$tmpcode])) {
1206 $htmltext .= $langs->trans(
"FormatControlRule").
': <b>'.str_replace(
'"',
'', $objimport->array_import_regex[0][$tmpcode]).
'</b><br>';
1210 $htmltext .= $langs->trans(
"InformationOnTargetTables").
': <b>'.$tablename.
"->".preg_replace(
'/^.*\./',
'', $tmpcode).
"</b>";
1212 $labelhtml = $label.
' '.$form->textwithpicto(
'', $htmltext, 1,
'help',
'', 1);
1214 $selectforline .=
'<option value="'.$tmpcode.
'"';
1215 if ($modetoautofillmapping ==
'orderoftargets') {
1218 $selectforline .=
' selected';
1220 } elseif ($modetoautofillmapping ==
'guess') {
1224 if (preg_match(
'/^(.+)\((.+\..+)\)$/', $line[
'example1'], $regs)) {
1225 $tmpstring1 = $regs[1];
1226 $tmpstring2 = $regs[2];
1228 $tmpstring1 = $line[
'example1'];
1236 foreach ($tmpval[
'labelkeyarray'] as $tmpval2) {
1237 $labeltarget = $langs->transnoentities($tmpval2);
1239 if ($tmpstring1 && ($tmpstring1 == $tmpcode || $tmpstring1 == strtolower($labeltarget)
1240 || $tmpstring1 == strtolower(
dol_string_unaccent($labeltarget)) || $tmpstring1 == strtolower($tmpval2))) {
1241 if (empty($codeselectedarray[$code])) {
1242 $selectforline .=
' selected';
1243 $codeselectedarray[$code] = 1;
1246 } elseif ($tmpstring2 && ($tmpstring2 == $tmpcode || $tmpstring2 == strtolower($labeltarget)
1247 || $tmpstring2 == strtolower(
dol_string_unaccent($labeltarget)) || $tmpstring2 == strtolower($tmpval2))) {
1248 if (empty($codeselectedarray[$code])) {
1249 $selectforline .=
' selected';
1250 $codeselectedarray[$code] = 1;
1255 } elseif ($modetoautofillmapping ==
'session' && !empty($_SESSION[
'dol_array_match_file_to_database_select'])) {
1256 $tmpselectioninsession =
dolExplodeIntoArray($_SESSION[
'dol_array_match_file_to_database_select'],
',',
'=');
1258 if (!empty($tmpselectioninsession[(
string) ($i + 1)]) && $tmpselectioninsession[(
string) ($i + 1)] == $tmpcode) {
1259 $selectforline .=
' selected';
1261 $selectforline .=
' data-debug="'.$tmpcode.
'-'.$code.
'-'.$j.
'-'.(!empty($tmpselectioninsession[(
string) ($i + 1)]) ? $tmpselectioninsession[(string) ($i + 1)] :
"").
'"';
1263 $selectforline .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
1264 $selectforline .=
'>';
1265 $selectforline .= $label;
1266 $selectforline .=
'</options>';
1269 $selectforline .=
'</select>';
1270 $selectforline .=
ajax_combobox(
'selectorderimport_'.($i + 1));
1272 print $selectforline;
1277 print
'<td class="nowraponall" style="font-weight:normal; text-align:right">';
1280 $htmltext =
'<b><u>'.$langs->trans(
"FieldSource").
'</u></b><br>';
1282 $htmltext .= $langs->trans(
"DataComeFromFileFieldNb", $filecolumntoshow).
'<br>';
1284 print $form->textwithpicto(
'', $htmltext);
1295 print
'<tr class="liste_titre"><td colspan="2">'.$langs->trans(
"Note").
'</td></tr>';
1296 print
'<tr><td colspan="2"><div id="div-mandatory-target-fields-not-mapped"></div></td></tr>';
1302 if (!empty($conf->use_javascript_ajax)) {
1303 print
'<script type="text/javascript">'.
"\n";
1304 print
'var previousselectedvalueimport = "0";'.
"\n";
1305 print
'var previousselectedlabelimport = "0";'.
"\n";
1306 print
'var arrayofselectedvalues = [];'.
"\n";
1307 print
'var arrayoftargetfields = [];'.
"\n";
1308 print
'var arrayoftargetmandatoryfields = [];'.
"\n";
1312 foreach ($fieldstarget as $key => $val) {
1313 print
"arrayoftargetfields[".$tmpi.
"] = '".
dol_escape_js($langs->trans($val[
'label'])).
"'; ";
1314 if ($val[
'required']) {
1315 print
"arrayoftargetmandatoryfields[".$tmpi.
"] = '".
dol_escape_js($key).
"'; ";
1321 print
'$(document).ready(function () {'.
"\n";
1323 print
'setOptionsToDisabled();'.
"\n";
1324 print
'saveSelection();'.
"\n";
1326 print
'$(".targetselectchange").focus(function(){'.
"\n";
1327 print
' previousselectedvalueimport = $(this).val();'.
"\n";
1328 print
' previousselectedlabelimport = $(this).children("option:selected").text();'.
"\n";
1329 print
' console.log("previousselectedvalueimport="+previousselectedvalueimport)'.
"\n";
1336 print
'function setOptionsToDisabled() {'.
"\n";
1337 print
' console.log("Remove the disabled flag everywhere");'.
"\n";
1338 print
' $("select.targetselectchange").not($( this )).find(\'option\').prop("disabled", false);'.
"\n";
1339 print
' arrayofselectedvalues = [];'.
"\n";
1341 print
' $("select.targetselectchange").each(function(){'.
"\n";
1342 print
' id = $(this).attr(\'id\')'.
"\n";
1343 print
' value = $(this).val()'.
"\n";
1344 print
' console.log("a selected value has been found for component "+id+" = "+value);'.
"\n";
1345 print
' arrayofselectedvalues.push(value);'.
"\n";
1348 print
' console.log("List of all selected values arrayofselectedvalues");'.
"\n";
1349 print
' console.log(arrayofselectedvalues);'.
"\n";
1350 print
' console.log("Set the option to disabled for every entry that is currently selected somewhere else (so into arrayofselectedvalues)");'.
"\n";
1352 print
' $.each(arrayofselectedvalues, function(key, value) {'.
"\n";
1353 print
' if (value != -1) {'.
"\n";
1354 print
' console.log("Process key="+key+" value="+value+" to disable.");'.
"\n";
1355 print
' $("select.targetselectchange").find(\'option[value="\'+value+\'"]:not(:selected)\').prop("disabled", true);'.
"\n";
1361 print
'function saveSelection() {'.
"\n";
1363 print
' arrayselectedfields = [];'.
"\n";
1364 print
' arrayselectedfields.push(0);'.
"\n";
1366 print
' $.each( arrayofselectedvalues, function( key, value ) {'.
"\n";
1367 print
' if (value != -1) {'.
"\n";
1368 print
' arrayselectedfields.push(value);'.
"\n";
1369 print
' } else {'.
"\n";
1370 print
' arrayselectedfields.push(0);'.
"\n";
1374 print
" $.ajax({\n";
1375 print
" type: 'POST',\n";
1376 print
" dataType: 'json',\n";
1377 print
" url: '".dol_escape_js($_SERVER[
"PHP_SELF"]).
"?action=saveselectorder&token=".
newToken().
"',\n";
1378 print
" data: 'selectorder='+arrayselectedfields.toString(),\n";
1379 print
" success: function(){\n";
1380 print
" console.log('The selected fields have been saved into '+arrayselectedfields.toString());\n";
1385 print
' console.log("arrayselectedfields");';
1386 print
' console.log(arrayselectedfields);';
1387 print
' console.log("arrayoftargetmandatoryfields");';
1388 print
' console.log(arrayoftargetmandatoryfields);';
1389 print
" listtoshow = '';";
1390 print
" nbelement = arrayoftargetmandatoryfields.length
1391 for (let i = 0; i < nbelement; i++) {
1392 if (arrayoftargetmandatoryfields[i] && ! arrayselectedfields.includes(arrayoftargetmandatoryfields[i])) {
1393 console.log(arrayoftargetmandatoryfields[i]+' not mapped');
1394 listtoshow = listtoshow + (listtoshow ? ', ' : '') + '<b>' + arrayoftargetfields[i] + '*</b>';
1397 console.log(listtoshow);
1399 listtoshow = '".dol_escape_js(
img_warning($langs->trans(
"MandatoryTargetFieldsNotMapped")).
' '.$langs->trans(
"MandatoryTargetFieldsNotMapped")).
": ' + listtoshow;
1400 $('#div-mandatory-target-fields-not-mapped').html(listtoshow);
1402 $('#div-mandatory-target-fields-not-mapped').html('<span class=\"opacitymedium\">".
dol_escape_js($langs->trans(
"AllTargetMandatoryFieldsAreMapped")).
"</span>');
1409 print
'$(".targetselectchange").change(function(){'.
"\n";
1410 print
' setOptionsToDisabled();'.
"\n";
1412 print
' if(previousselectedlabelimport != "" && previousselectedvalueimport != -1) {'.
"\n";
1413 print
' let valuetochange = $(this).val(); '.
"\n";
1414 print
' $(".boxtdunused").each(function(){'.
"\n";
1415 print
' if ($(this).text().includes(valuetochange)){'.
"\n";
1416 print
' arraychild = $(this)[0].childNodes'.
"\n";
1417 print
' arraytexttomodify = arraychild[0].textContent.split(" ")'.
"\n";
1418 print
' arraytexttomodify[1] = previousselectedvalueimport '.
"\n";
1419 print
' textmodified = arraytexttomodify.join(" ") '.
"\n";
1420 print
' arraychild[0].textContent = textmodified'.
"\n";
1421 print
' arraychild[1].innerHTML = previousselectedlabelimport'.
"\n";
1425 print
' $(this).blur()'.
"\n";
1427 print
' saveSelection()'.
"\n";
1431 print
'</script>'.
"\n";
1437 print
'<div class="tabsAction">';
1439 if (count($array_match_file_to_database)) {
1440 if ($mandatoryfieldshavesource) {
1441 print
'<a class="butAction saveorderselect" href="import.php?step=5'.$param.
'&filetoimport='.urlencode($filetoimport).
'">'.$langs->trans(
"NextStep").
'</a>';
1443 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"SomeMandatoryFieldHaveNoSource")).
'">'.$langs->trans(
"NextStep").
'</a>';
1451 if (count($array_match_file_to_database)) {
1453 print
'<!-- Area to add new import profile -->'.
"\n";
1454 print
'<div class="marginbottomonly"><span class="opacitymedium">'.$langs->trans(
"SaveImportModel").
'</span></div>';
1456 print
'<form class="nocellnopadd" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1457 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1458 print
'<input type="hidden" name="action" value="add_import_model">';
1459 print
'<input type="hidden" name="step" value="'.$step.
'">';
1460 print
'<input type="hidden" name="format" value="'.$format.
'">';
1461 print
'<input type="hidden" name="datatoimport" value="'.$datatoimport.
'">';
1462 print
'<input type="hidden" name="filetoimport" value="'.$filetoimport.
'">';
1463 print
'<input type="hidden" name="hexa" value="'.$hexa.
'">';
1464 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1465 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1466 print
'<input type="hidden" name="page_y" value="">';
1467 print
'<input type="hidden" value="'.dol_escape_htmltag($separator).
'" name="separator">';
1468 print
'<input type="hidden" value="'.dol_escape_htmltag($enclosure).
'" name="enclosure">';
1470 print
'<div class="div-table-responsive-no-min">';
1471 print
'<table summary="selectofimportprofil" class="noborder centpercent">';
1472 print
'<tr class="liste_titre">';
1473 print
'<td>'.$langs->trans(
"ImportModelName").
'</td>';
1474 print
'<td>'.$langs->trans(
"Visibility").
'</td>';
1478 $nameofimportprofile = str_replace(
' ',
'-', $langs->trans(
"ImportProfile").
' '.$titleofmodule.
' '.
dol_print_date(
dol_now(
'gmt'),
'dayxcard'));
1480 $nameofimportprofile = $import_name;
1483 print
'<tr class="oddeven">';
1484 print
'<td><input name="import_name" class="minwidth300" value="'.$nameofimportprofile.
'"></td>';
1486 $arrayvisibility = array(
'private' => $langs->trans(
"Private"),
'all' => $langs->trans(
"Everybody"));
1487 print $form->selectarray(
'visibility', $arrayvisibility,
'private');
1489 print
'<td class="right">';
1490 print
'<input type="submit" class="button smallpaddingimp reposition" value="'.$langs->trans(
"SaveImportProfile").
'">';
1494 $sql =
"SELECT rowid, label, fk_user, entity";
1495 $sql .=
" FROM ".MAIN_DB_PREFIX.
"import_model";
1496 $sql .=
" WHERE type = '".$db->escape($datatoimport).
"'";
1498 $sql .=
" AND fk_user IN (0, ".((int) $user->id).
")";
1500 $sql .=
" ORDER BY rowid";
1502 $resql = $db->query($sql);
1504 $num = $db->num_rows($resql);
1506 $tmpuser =
new User($db);
1510 $obj = $db->fetch_object($resql);
1512 print
'<tr class="oddeven"><td>';
1515 print
'<td class="tdoverflowmax150">';
1516 if (empty($obj->fk_user)) {
1517 print $langs->trans(
"Everybody");
1519 $tmpuser->fetch($obj->fk_user);
1520 print $tmpuser->getNomUrl(-1);
1523 print
'<td class="right">';
1524 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?step='.$step.$param.
'&action=deleteprof&token='.
newToken().
'&id='.$obj->rowid.
'&filetoimport='.urlencode($filetoimport).
'">';
1542if ($step == 5 && $datatoimport) {
1543 $max_execution_time_for_importexport =
getDolGlobalInt(
'IMPORT_MAX_EXECUTION_TIME', 300);
1544 $max_time = @ini_get(
"max_execution_time");
1545 if ($max_time && $max_time < $max_execution_time_for_importexport) {
1546 dol_syslog(
"max_execution_time=".$max_time.
" is lower than max_execution_time_for_importexport=".$max_execution_time_for_importexport.
". We try to increase it dynamically.");
1547 @ini_set(
"max_execution_time", $max_execution_time_for_importexport);
1551 $list = $objmodelimport->listOfAvailableImportFormat($db);
1554 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
1555 $file =
"import_".$model.
".modules.php";
1556 $classname =
"Import".ucfirst($model);
1557 require_once $dir.$file;
1558 $obj =
new $classname($db, $datatoimport);
1559 if ($model ==
'csv') {
1560 $obj->separator = $separator_used;
1561 $obj->enclosure = $enclosure;
1565 $fieldssource = array();
1566 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport, $langs);
1570 $arrayrecord = $obj->import_read_record();
1573 foreach ($arrayrecord as $key => $val) {
1574 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 24);
1577 $obj->import_close_file();
1580 $nboflines = $obj->import_get_nb_of_lines($conf->import->dir_temp.
'/'.$filetoimport);
1582 $param =
'&leftmenu=import&format='.urlencode($format).
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport).
'&nboflines='.((int) $nboflines).
'&separator='.urlencode($separator).
'&enclosure='.urlencode($enclosure);
1584 if ($excludefirstline) {
1585 $param .=
'&excludefirstline='.urlencode($excludefirstline);
1588 $param .=
'&endatlinenb='.urlencode($endatlinenb);
1590 if (!empty($updatekeys)) {
1591 $param .=
'&updatekeys[]='.implode(
'&updatekeys[]=', $updatekeys);
1594 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
1599 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?'.$param2.
'" method="POST">';
1600 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1601 print
'<input type="hidden" name="step" value="5">';
1602 print
'<input type="hidden" name="action" value="launchsimu">';
1606 print
'<div class="underbanner clearboth"></div>';
1607 print
'<div class="fichecenter">';
1609 print
'<table width="100%" class="border tableforfield">';
1612 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
1614 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
1616 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
1617 $titleofmodule = $langs->trans(
"ProductOrService");
1619 print $titleofmodule;
1623 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
1625 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
1626 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
1627 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
1628 print $objimport->array_import_label[0];
1634 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
1636 print
'<div class="underbanner clearboth"></div>';
1637 print
'<div class="fichecenter">';
1638 print
'<table width="100%" class="border tableforfield">';
1641 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
1643 $text = $objmodelimport->getDriverDescForKey($format);
1645 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
1649 if ($model ==
'csv') {
1650 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
1653 print
' '.$langs->trans(
"Enclosure").
' : '.
dol_escape_htmltag($enclosure);
1658 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
1660 $modulepart =
'import';
1661 $relativepath =
GETPOST(
'filetoimport');
1662 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
1663 print
img_mime($file,
'',
'pictofixedwidth');
1664 print $filetoimport;
1665 print
img_picto($langs->trans(
"Download"),
'download',
'class="paddingleft opacitymedium"');
1671 print $langs->trans(
"NbOfSourceLines");
1678 print $langs->trans(
"ImportFromToLine");
1680 if ($action ==
'launchsimu') {
1681 print
'<input type="number" class="maxwidth50 right" name="excludefirstlinebis" disabled="disabled" value="'.$excludefirstline.
'">';
1682 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1684 print
'<input type="number" class="maxwidth50 right" name="excludefirstline" value="'.$excludefirstline.
'">';
1685 print $form->textwithpicto(
"", $langs->trans(
"SetThisValueTo2ToExcludeFirstLine"));
1688 if ($action ==
'launchsimu') {
1689 print
'<input type="text" class="maxwidth50" name="endatlinenbbis" disabled="disabled" value="'.$endatlinenb.
'">';
1690 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1692 print
'<input type="text" class="maxwidth50" name="endatlinenb" value="'.$endatlinenb.
'">';
1693 print $form->textwithpicto(
"", $langs->trans(
"KeepEmptyToGoToEndOfFile"));
1695 if ($action ==
'launchsimu') {
1696 print
' <a href="'.$_SERVER[
"PHP_SELF"].
'?step=5'.$param.
'">'.$langs->trans(
"Modify").
'</a>';
1698 if ($excludefirstline == 2) {
1699 print $form->textwithpicto(
"", $langs->trans(
"WarningFirstImportedLine", $excludefirstline), 1,
'warning',
"warningexcludefirstline");
1701 $( document ).ready(function() {
1702 $("input[name=\'excludefirstline\']").on("change",function(){
1703 if($(this).val() <= 1){
1704 $(".warningexcludefirstline").hide();
1706 $(".warningexcludefirstline").show();
1716 print $form->textwithpicto($langs->trans(
"KeysToUseForUpdates"), $langs->trans(
"SelectPrimaryColumnsForUpdateAttempt"));
1718 if ($action ==
'launchsimu') {
1719 if (count($updatekeys)) {
1720 print $form->multiselectarray(
'updatekeysbis', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0,
'', 1,
'80%',
'disabled');
1722 print
'<span class="opacitymedium">'.$langs->trans(
"NoUpdateAttempt").
'</span> -';
1724 foreach ($updatekeys as $val) {
1725 print
'<input type="hidden" name="updatekeys[]" value="'.$val.
'">';
1727 print
' <a href="'.$_SERVER[
"PHP_SELF"].
'?step=5'.$param.
'">'.$langs->trans(
"Modify").
'</a>';
1729 if (is_array($objimport->array_import_updatekeys[0]) && count($objimport->array_import_updatekeys[0])) {
1730 print $form->multiselectarray(
'updatekeys', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0,
'', 1,
'80%');
1733 print
'<span class="opacitymedium">'.$langs->trans(
"UpdateNotYetSupportedForThisImport").
'</span>';
1745 print
load_fiche_titre($langs->trans(
"InformationOnTargetTables"),
'',
'file-import');
1747 print
'<div class="underbanner clearboth"></div>';
1748 print
'<div class="fichecenter">';
1750 print
'<table width="100%" class="border tableforfield">';
1753 print
'<tr><td class="titlefieldcreate">';
1754 print $langs->trans(
"TablesTarget");
1756 $listtables = array();
1757 $sort_array_match_file_to_database = $array_match_file_to_database;
1758 foreach ($array_match_file_to_database as $code => $label) {
1760 if ($code > count($fieldssource)) {
1764 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
1765 $listtables[$alias] = $objimport->array_import_tables[0][$alias];
1767 if (count($listtables)) {
1770 foreach ($listtables as $val) {
1789 print $langs->trans(
"Error");
1795 print $langs->trans(
"FieldsTarget").
'</td><td>';
1796 $listfields = array();
1799 $sort_array_match_file_to_database = $array_match_file_to_database;
1800 ksort($sort_array_match_file_to_database);
1802 foreach ($sort_array_match_file_to_database as $code => $label) {
1805 if ($code > count($fieldssource)) {
1809 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
1810 $listfields[$i] =
'<span class="nowrap">'.$langs->trans(
"Column").
' '.
num2Alpha($code - 1).
' -> '.$label.
'</span>';
1812 print count($listfields) ? (implode(
', ', $listfields)) : $langs->trans(
"Error");
1821 if ($action !=
'launchsimu') {
1823 print
'<br><span class="opacitymedium">';
1824 print $langs->trans(
"NowClickToTestTheImport", $langs->transnoentitiesnoconv(
"RunSimulateImportFile")).
'</span><br>';
1828 print
'<div class="center">';
1829 if ($user->hasRight(
'import',
'run')) {
1830 print
'<input type="submit" class="butAction" value="'.$langs->trans(
"RunSimulateImportFile").
'">';
1832 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunSimulateImportFile").
'</a>';
1837 $arrayoferrors = array();
1838 $arrayofwarnings = array();
1839 $maxnboferrors = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_ERRORS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_ERRORS;
1840 $maxnbofwarnings = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_WARNINGS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_WARNINGS;
1852 $pathfile = $conf->import->dir_temp.
'/'.$filetoimport;
1853 $result = $obj->import_open_file($pathfile, $langs);
1855 global $tablewithentity_cache;
1856 $tablewithentity_cache = array();
1861 while (($sourcelinenb < $nboflines) && !$endoffile) {
1865 $arrayrecord = $obj->import_read_record();
1866 if ($arrayrecord ===
false) {
1867 $arrayofwarnings[$sourcelinenb][0] = array(
'lib' =>
'File has '.$nboflines.
' lines. However we reach the end of file or an empty line at record '.$sourcelinenb.
'. This may occurs when some records are split onto several lines and not correctly delimited by the "Char delimiter", or if there is line with no data on all fields.',
'type' =>
'EOF_RECORD_ON_SEVERAL_LINES');
1871 if ($excludefirstline && ($sourcelinenb < $excludefirstline)) {
1874 if ($endatlinenb && ($sourcelinenb > $endatlinenb)) {
1878 $parameters = array(
1880 'datatoimport' => $datatoimport,
1882 'arrayrecord' => $arrayrecord,
1883 'array_match_file_to_database' => $array_match_file_to_database,
1884 'objimport' => $objimport,
1885 'fieldssource' => $fieldssource,
1886 'importid' => $importid,
1887 'updatekeys' => $updatekeys,
1888 'arrayoferrors' => &$arrayoferrors,
1889 'arrayofwarnings' => &$arrayofwarnings,
1893 $reshook = $hookmanager->executeHooks(
'ImportInsert', $parameters);
1895 $arrayoferrors[$sourcelinenb][] = [
1896 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
1900 if (empty($reshook)) {
1902 $result = $obj->import_insert($arrayrecord, $array_match_file_to_database, $objimport, count($fieldssource), $importid, $updatekeys);
1904 if (count($obj->errors)) {
1905 $arrayoferrors[$sourcelinenb] = $obj->errors;
1907 if (count($obj->warnings)) {
1908 $arrayofwarnings[$sourcelinenb] = $obj->warnings;
1910 if (!count($obj->errors) && !count($obj->warnings)) {
1916 $obj->import_close_file();
1918 print $langs->trans(
"ErrorFailedToOpenFile", $pathfile);
1925 if (!empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0])) {
1927 foreach ($objimport->array_import_run_sql_after[0] as $sqlafterimport) {
1929 $resqlafterimport = $db->query($sqlafterimport);
1930 if (!$resqlafterimport) {
1931 $arrayoferrors[
'none'][] = array(
'lib' => $langs->trans(
"Error running final request: ".$sqlafterimport));
1940 if (!count($arrayoferrors) && !count($arrayofwarnings)) {
1942 print
'<div class="info">';
1943 print
'<div class=""><b>'.$langs->trans(
"ResultOfSimulationNoError").
'</b></div>';
1944 print $langs->trans(
"NbInsertSim", empty($obj->nbinsert) ? 0 : $obj->nbinsert).
'<br>';
1945 print $langs->trans(
"NbUpdateSim", empty($obj->nbupdate) ? 0 : $obj->nbupdate).
'<br>';
1950 print
'<div class="warning">';
1951 print $langs->trans(
"NbOfLinesOK", $nbok).
'...<br>';
1958 if (count($arrayoferrors)) {
1959 print
img_error().
' <b>'.$langs->trans(
"ErrorsOnXLines", count($arrayoferrors)).
'</b><br>';
1960 print
'<table width="100%" class="border"><tr><td>';
1961 foreach ($arrayoferrors as $key => $val) {
1963 if ($nboferrors > $maxnboferrors) {
1964 print $langs->trans(
"TooMuchErrors", (count($arrayoferrors) - $nboferrors)).
"<br>";
1968 foreach ($val as $i => $err) {
1969 print
' > '.dol_escape_htmltag($err[
'lib']).
'<br>';
1972 print
'</td></tr></table>';
1978 if (count($arrayofwarnings)) {
1979 print
img_warning().
' <b>'.$langs->trans(
"WarningsOnXLines", count($arrayofwarnings)).
'</b><br>';
1980 print
'<table width="100%" class="border"><tr><td>';
1981 foreach ($arrayofwarnings as $key => $val) {
1983 if ($nbofwarnings > $maxnbofwarnings) {
1984 print $langs->trans(
"TooMuchWarnings", (count($arrayofwarnings) - $nbofwarnings)).
"<br>";
1988 foreach ($val as $i => $err) {
1989 print
' > '.dol_escape_htmltag($err[
'lib']).
'<br>';
1992 print
'</td></tr></table>';
1999 print
'<div class="center">';
2000 print
'<span class="opacitymedium">'.$langs->trans(
"NowClickToRunTheImport", $langs->transnoentitiesnoconv(
"RunImportFile")).
'</span><br>';
2009 print
'<div class="center">';
2010 if ($user->hasRight(
'import',
'run')) {
2011 if (empty($nboferrors)) {
2012 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/imports/import.php?leftmenu=import&step=6&importid='.$importid.$param.
'">'.$langs->trans(
"RunImportFile").
'</a>';
2016 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"CorrectErrorBeforeRunningImport")).
'">'.$langs->trans(
"RunImportFile").
'</a>';
2019 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunSimulateImportFile").
'</a>';
2021 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunImportFile").
'</a>';
2031if ($step == 6 && $datatoimport) {
2032 $max_execution_time_for_importexport =
getDolGlobalInt(
'IMPORT_MAX_EXECUTION_TIME', 300);
2033 $max_time = @ini_get(
"max_execution_time");
2034 if ($max_time && $max_time < $max_execution_time_for_importexport) {
2035 dol_syslog(
"max_execution_time=".$max_time.
" is lower than max_execution_time_for_importexport=".$max_execution_time_for_importexport.
". We try to increase it dynamically.");
2036 @ini_set(
"max_execution_time", $max_execution_time_for_importexport);
2040 $list = $objmodelimport->listOfAvailableImportFormat($db);
2041 $importid =
GETPOST(
"importid",
'alphanohtml');
2045 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
2046 $file =
"import_".$model.
".modules.php";
2047 $classname =
"Import".ucfirst($model);
2048 require_once $dir.$file;
2049 $obj =
new $classname($db, $datatoimport);
2050 if ($model ==
'csv') {
2051 $obj->separator = $separator_used;
2052 $obj->enclosure = $enclosure;
2056 $fieldssource = array();
2057 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport, $langs);
2060 $arrayrecord = $obj->import_read_record();
2063 foreach ($arrayrecord as $key => $val) {
2064 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 24);
2067 $obj->import_close_file();
2072 $param =
'&format='.$format.
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport).
'&nboflines='.((int) $nboflines);
2073 if ($excludefirstline) {
2074 $param .=
'&excludefirstline='.urlencode($excludefirstline);
2077 $param .=
'&endatlinenb='.urlencode($endatlinenb);
2080 $param .=
'&separator='.urlencode($separator);
2083 $param .=
'&enclosure='.urlencode($enclosure);
2086 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
2092 print
'<div class="underbanner clearboth"></div>';
2093 print
'<div class="fichecenter">';
2095 print
'<table width="100%" class="border">';
2098 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
2100 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
2102 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
2103 $titleofmodule = $langs->trans(
"ProductOrService");
2105 print $titleofmodule;
2109 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
2111 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
2112 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
2113 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
2114 print $objimport->array_import_label[0];
2120 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
2122 print
'<div class="underbanner clearboth"></div>';
2123 print
'<div class="fichecenter">';
2124 print
'<table width="100%" class="border">';
2127 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
2129 $text = $objmodelimport->getDriverDescForKey($format);
2131 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
2135 if ($model ==
'csv') {
2136 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
2138 print $langs->trans(
"Separator").
' : ';
2139 print htmlentities($separator);
2140 print
' '.$langs->trans(
"Enclosure").
' : ';
2141 print htmlentities($enclosure);
2146 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
2148 $modulepart =
'import';
2149 $relativepath =
GETPOST(
'filetoimport');
2150 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
2151 print
img_mime($file,
'',
'pictofixedwidth');
2152 print $filetoimport;
2158 print $langs->trans(
"NbOfSourceLines");
2165 print $langs->trans(
"ImportFromLine");
2167 print
'<input type="text" size="4" name="excludefirstline" disabled="disabled" value="'.$excludefirstline.
'">';
2172 print $langs->trans(
"EndAtLineNb");
2174 print
'<input type="text" size="4" name="endatlinenb" disabled="disabled" value="'.$endatlinenb.
'">';
2182 print
'<b>'.$langs->trans(
"InformationOnTargetTables").
'</b>';
2183 print
'<div class="underbanner clearboth"></div>';
2184 print
'<div class="fichecenter">';
2185 print
'<table class="border centpercent">';
2188 print
'<tr><td width="25%">';
2189 print $langs->trans(
"TablesTarget");
2191 $listtables = array();
2192 foreach ($array_match_file_to_database as $code => $label) {
2194 if ($code > count($fieldssource)) {
2198 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
2199 $listtables[$alias] = $objimport->array_import_tables[0][$alias];
2201 if (count($listtables)) {
2203 foreach ($listtables as $val) {
2222 print $langs->trans(
"Error");
2228 print $langs->trans(
"FieldsTarget").
'</td><td>';
2229 $listfields = array();
2231 $sort_array_match_file_to_database = $array_match_file_to_database;
2232 ksort($sort_array_match_file_to_database);
2234 foreach ($sort_array_match_file_to_database as $code => $label) {
2237 if ($code > count($fieldssource)) {
2241 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
2242 $listfields[$i] = $langs->trans(
"Field").
' '.$code.
'->'.$label;
2244 print count($listfields) ? (implode(
', ', $listfields)) : $langs->trans(
"Error");
2251 $arrayoferrors = array();
2252 $arrayofwarnings = array();
2253 $maxnboferrors = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_ERRORS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_ERRORS;
2254 $maxnbofwarnings = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_WARNINGS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_WARNINGS;
2266 $pathfile = $conf->import->dir_temp.
'/'.$filetoimport;
2267 $result = $obj->import_open_file($pathfile, $langs);
2269 global $tablewithentity_cache;
2270 $tablewithentity_cache = array();
2274 while ($sourcelinenb < $nboflines && !$endoffile) {
2276 $arrayrecord = $obj->import_read_record();
2277 if ($arrayrecord ===
false) {
2278 $arrayofwarnings[$sourcelinenb][0] = array(
'lib' =>
'File has '.$nboflines.
' lines. However we reach the end of file or an empty line at record '.$sourcelinenb.
'. This may occurs when some records are split onto several lines and not correctly delimited by the "Char delimiter", or if there is line with no data on all fields.',
'type' =>
'EOF_RECORD_ON_SEVERAL_LINES');
2282 if ($excludefirstline && ($sourcelinenb < $excludefirstline)) {
2285 if ($endatlinenb && ($sourcelinenb > $endatlinenb)) {
2289 $parameters = array(
2291 'datatoimport' => $datatoimport,
2293 'arrayrecord' => $arrayrecord,
2294 'array_match_file_to_database' => $array_match_file_to_database,
2295 'objimport' => $objimport,
2296 'fieldssource' => $fieldssource,
2297 'importid' => $importid,
2298 'updatekeys' => $updatekeys,
2299 'arrayoferrors' => &$arrayoferrors,
2300 'arrayofwarnings' => &$arrayofwarnings,
2304 $reshook = $hookmanager->executeHooks(
'ImportInsert', $parameters);
2306 $arrayoferrors[$sourcelinenb][] = [
2307 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
2311 if (empty($reshook)) {
2313 $result = $obj->import_insert($arrayrecord, $array_match_file_to_database, $objimport, count($fieldssource), $importid, $updatekeys);
2315 if (count($obj->errors)) {
2316 $arrayoferrors[$sourcelinenb] = $obj->errors;
2318 if (count($obj->warnings)) {
2319 $arrayofwarnings[$sourcelinenb] = $obj->warnings;
2322 if (!count($obj->errors) && !count($obj->warnings)) {
2327 $reshook = $hookmanager->executeHooks(
'AfterImportInsert', $parameters);
2329 $arrayoferrors[$sourcelinenb][] = [
2330 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
2335 $obj->import_close_file();
2337 print $langs->trans(
"ErrorFailedToOpenFile", $pathfile);
2340 if (count($arrayoferrors) > 0) {
2347 if (!empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0])) {
2349 foreach ($objimport->array_import_run_sql_after[0] as $sqlafterimport) {
2351 $resqlafterimport = $db->query($sqlafterimport);
2352 if (!$resqlafterimport) {
2353 $arrayoferrors[
'none'][] = array(
'lib' => $langs->trans(
"Error running final request: ".$sqlafterimport));
2371 print
'<div class="info">';
2372 print $langs->trans(
"NbOfLinesImported", $nbok).
'</b><br>';
2373 print $langs->trans(
"NbInsert", empty($obj->nbinsert) ? 0 : $obj->nbinsert).
'<br>';
2374 print $langs->trans(
"NbUpdate", empty($obj->nbupdate) ? 0 : $obj->nbupdate).
'<br>';
2376 print
'<div class="center">';
2377 print $langs->trans(
"FileWasImported", $importid).
'<br>';
2378 print
'<span class="opacitymedium">'.$langs->trans(
"YouCanUseImportIdToFindRecord", $importid).
'</span><br>';
2401 global $conf, $langs;
2405 if ($key ==
'none') {
2407 print
"\n\n<!-- Box_no-key start-->\n";
2408 print
'<div class="box boximport" style="padding:0;">'.
"\n";
2409 print
'<table summary="boxtable_no-key" class="centpercent nobordernopadding">'.
"\n";
2411 print
"\n\n<!-- Box ".$pos.
" start -->\n";
2412 print
'<div class="box boximport" style="padding: 0;" id="boxto_'.$pos.
'">'.
"\n";
2414 print
'<table summary="boxtable'.$pos.
'" class="nobordernopadding centpercent tableimport">'.
"\n";
2417 if (($pos && $pos > count($fieldssource)) && (!isset($fieldssource[$pos][
"imported"]))) {
2427 } elseif ($key ==
'none') {
2428 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
2429 print
'<td class="nocellnopadding" width="16" style="font-weight: normal">';
2432 print
'<td style="font-weight: normal">';
2438 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
2439 print
'<td class="nocellnopadding" width="16" style="font-weight: normal">';
2442 print
img_picto($langs->trans(
"Column").
' '.
num2Alpha($pos - 1),
'file',
'class="pictofixedwith"');
2444 if (isset($fieldssource[$pos][
'imported']) && $fieldssource[$pos][
'imported'] ==
false) {
2445 print
'<td class="nowraponall boxtdunused" style="font-weight: normal">';
2447 print
'<td class="nowraponall tdoverflowmax500" style="font-weight: normal">';
2449 print $langs->trans(
"Column").
' '.
num2Alpha($pos - 1).
' (#'.$pos.
')';
2450 if (empty($fieldssource[$pos][
'example1'])) {
2451 $example = $fieldssource[$pos][
'label'];
2453 $example = $fieldssource[$pos][
'example1'];
2457 $example = mb_convert_encoding($example,
'UTF-8',
'ISO-8859-1');
2461 print
'<i class="opacitymedium">'.dol_escape_htmltag($example).
'</i>';
2470 print
"<!-- Box end -->\n\n";
2483 $i = count($fieldssource) + 1;
2486 foreach ($listofkey as $key => $val) {
2487 $maxkey = max($maxkey, $key);
2490 while ($i <= $maxkey) {
2491 if (empty($listofkey[$i])) {
2513 if ($position == count($array)) {
2514 $ret = $array + $insertArray;
2517 foreach ($array as $key => $value) {
2518 if ($position == $i++) {
2519 $ret += $insertArray;
2522 $ret[$key] = $value;
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Parent class for import file readers.
Class to manage Dolibarr users.
dol_filemtime($pathoffile)
Return time of a file.
dol_filesize($pathoffile)
Return size of a file.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Check validity of a file upload from an GUI page, and move it to its final destination.
dol_count_nb_of_line($file)
Count number of lines in a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
num2Alpha($n)
Return a numeric value into an Excel like column number.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
img_error($titlealt='default')
Show error logo.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
utf8_check($str)
Check if a string is in UTF8.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
import_prepare_head($param, $maxstep=0)
Function to return list of tabs for import pages.
show_elem($fieldssource, $pos, $key)
Function to put the movable box of a source field.
getnewkey(&$fieldssource, &$listofkey)
Return not used field number.
arrayInsert($array, $position, $insertArray)
Return array with element inserted in it at position $position.
getMaxFileSizeArray()
Return the max allowed for file upload.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.