27require_once
'../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/imports/class/import.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/modules/import/modules_import.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/import.lib.php';
37$langs->loadLangs(array(
'exports',
'compta',
'errors'));
45 'invoice_line' =>
'bill',
47 'order_line' =>
'order',
49 'propal_line' =>
'propal',
50 'intervention' =>
'intervention',
51 'inter_line' =>
'intervention',
53 'member_type' =>
'group',
54 'subscription' =>
'payment',
55 'payment' =>
'payment',
57 'tax_type' =>
'generic',
59 'account' =>
'account',
60 'product' =>
'product',
61 'virtualproduct'=>
'product',
62 'subproduct' =>
'product',
63 'product_supplier_ref' =>
'product',
65 'warehouse' =>
'stock',
67 'stockbatch' =>
'stock',
68 'category' =>
'category',
69 'shipment' =>
'sending',
70 'shipment_line'=>
'sending',
71 'reception'=>
'sending',
72 'reception_line'=>
'sending',
73 'expensereport'=>
'trip',
74 'expensereport_line'=>
'trip',
75 'holiday' =>
'holiday',
76 'contract_line' =>
'contract',
77 'translation' =>
'generic',
85 'company' =>
'Company',
86 'contact' =>
'Contact',
88 'invoice_line' =>
'InvoiceLine',
90 'order_line' =>
'OrderLine',
91 'propal' =>
'Proposal',
92 'propal_line' =>
'ProposalLine',
93 'intervention' =>
'Intervention',
94 'inter_line' =>
'InterLine',
96 'member_type' =>
'MemberType',
97 'subscription' =>
'Subscription',
98 'tax' =>
'SocialContribution',
99 'tax_type' =>
'DictionarySocialContributions',
100 'account' =>
'BankTransactions',
101 'payment' =>
'Payment',
102 'product' =>
'Product',
103 'virtualproduct' =>
'AssociatedProducts',
104 'subproduct' =>
'SubProduct',
105 'product_supplier_ref' =>
'SupplierPrices',
106 'service' =>
'Service',
108 'movement' =>
'StockMovement',
110 'stockbatch' =>
'StockDetailPerBatch',
111 'warehouse' =>
'Warehouse',
112 'category' =>
'Category',
114 'trip' =>
'TripsAndExpenses',
115 'shipment' =>
'Shipments',
116 'shipment_line'=>
'ShipmentLine',
117 'project' =>
'Projects',
118 'projecttask' =>
'Tasks',
119 'task_time' =>
'TaskTimeSpent',
121 'expensereport'=>
'ExpenseReport',
122 'expensereport_line'=>
'ExpenseReportLine',
123 'holiday' =>
'TitreRequestCP',
124 'contract' =>
'Contract',
125 'contract_line'=>
'ContractLine',
126 'translation' =>
'Translation',
128 'bomline' =>
'BOMLine'
131$datatoimport =
GETPOST(
'datatoimport');
133$filetoimport =
GETPOST(
'filetoimport');
134$action =
GETPOST(
'action',
'alpha');
135$confirm =
GETPOST(
'confirm',
'alpha');
137$import_name =
GETPOST(
'import_name');
139$importmodelid =
GETPOST(
'importmodelid',
'int');
140$excludefirstline = (
GETPOST(
'excludefirstline') ?
GETPOST(
'excludefirstline') : 2);
141$endatlinenb = (
GETPOST(
'endatlinenb') ?
GETPOST(
'endatlinenb') :
'');
142$updatekeys = (
GETPOST(
'updatekeys',
'array') ?
GETPOST(
'updatekeys',
'array') : array());
143$separator = (
GETPOST(
'separator',
'alphanohtml') ?
GETPOST(
'separator',
'alphanohtml', 3) :
'');
144$enclosure = (
GETPOST(
'enclosure',
'nohtml') ?
GETPOST(
'enclosure',
'nohtml') :
'"');
145$charset =
GETPOST(
'charset',
'aZ09');
146$separator_used = str_replace(
'\t',
"\t", $separator);
150$hookmanager->initHooks(array(
'imports'));
153$objimport =
new Import($db);
154$objimport->load_arrays($user, ($step == 1 ?
'' : $datatoimport));
156if (empty($updatekeys) && !empty($objimport->array_import_preselected_updatekeys[0])) {
157 $updatekeys = array_keys($objimport->array_import_preselected_updatekeys[0]);
162$form =
new Form($db);
167if (empty($array_match_file_to_database)) {
168 $serialized_array_match_file_to_database = isset($_SESSION[
"dol_array_match_file_to_database_select"]) ? $_SESSION[
"dol_array_match_file_to_database_select"] :
'';
169 $array_match_file_to_database = array();
170 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
171 foreach ($fieldsarray as $elem) {
172 $tabelem = explode(
'=', $elem, 2);
174 $val = (isset($tabelem[1]) ? $tabelem[1] :
'');
176 $array_match_file_to_database[$key] = $val;
221if ($action ==
'deleteprof') {
223 $objimport->fetch(
GETPOST(
"id",
'int'));
224 $result = $objimport->delete($user);
229if ($action ==
'add_import_model') {
233 foreach ($array_match_file_to_database as $key => $val) {
237 $hexa .= $key.
'='.$val;
240 $objimport->model_name = $import_name;
241 $objimport->datatoimport = $datatoimport;
242 $objimport->hexa = $hexa;
243 $objimport->fk_user = (
GETPOST(
'visibility',
'aZ09') ==
'all' ? 0 : $user->id);
245 $result = $objimport->create($user);
247 setEventMessages($langs->trans(
"ImportModelSaved", $objimport->model_name),
null,
'mesgs');
250 $langs->load(
"errors");
251 if ($objimport->errno ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
252 setEventMessages($langs->trans(
"ErrorImportDuplicateProfil"),
null,
'errors');
258 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"ImportModelName")),
null,
'errors');
262if ($step == 3 && $datatoimport) {
267 $fullpath = $conf->import->dir_temp.
"/".$nowyearmonth.
'-'.$_FILES[
'userfile'][
'name'];
269 dol_syslog(
"File ".$fullpath.
" was added for import");
271 $langs->load(
"errors");
277 if ($action ==
'confirm_deletefile' && $confirm ==
'yes') {
278 $langs->load(
"other");
280 $param =
'&datatoimport='.urlencode($datatoimport).
'&format='.urlencode($format);
281 if ($excludefirstline) {
282 $param .=
'&excludefirstline='.urlencode($excludefirstline);
285 $param .=
'&endatlinenb='.urlencode($endatlinenb);
288 $file = $conf->import->dir_temp.
'/'.
GETPOST(
'urlfile');
295 Header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?step='.$step.$param);
300if ($step == 4 && $action ==
'select_model') {
302 $_SESSION[
"dol_array_match_file_to_database"] =
'';
303 $serialized_array_match_file_to_database =
'';
304 $array_match_file_to_database = array();
308 $result = $objimport->fetch($importmodelid);
310 $serialized_array_match_file_to_database = $objimport->hexa;
311 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
312 foreach ($fieldsarray as $elem) {
313 $tabelem = explode(
'=', $elem);
317 $array_match_file_to_database[$key] = $val;
320 $_SESSION[
"dol_array_match_file_to_database"] = $serialized_array_match_file_to_database;
321 $_SESSION[
'dol_array_match_file_to_database_select'] = $_SESSION[
"dol_array_match_file_to_database"];
324if ($action ==
'saveselectorder') {
326 $serialized_array_match_file_to_database =
'';
328 $selectorder = explode(
",",
GETPOST(
'selectorder'));
329 $fieldtarget = $fieldstarget = $objimport->array_import_fields[0];
330 foreach ($selectorder as $key => $code) {
331 $serialized_array_match_file_to_database .= $key.
'='.$code;
332 $serialized_array_match_file_to_database .=
',';
334 $serialized_array_match_file_to_database = substr($serialized_array_match_file_to_database, 0, -1);
335 dol_syslog(
'dol_array_match_file_to_database_select='.$serialized_array_match_file_to_database);
336 $_SESSION[
"dol_array_match_file_to_database_select"] = $serialized_array_match_file_to_database;
348$help_url =
'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones';
352if ($step == 1 || !$datatoimport) {
354 $serialized_array_match_file_to_database =
'';
355 $array_match_file_to_database = array();
356 $_SESSION[
"dol_array_match_file_to_database"] =
'';
357 $_SESSION[
"dol_array_match_file_to_database_select"] =
'';
360 if ($excludefirstline) {
361 $param .=
'&excludefirstline='.urlencode($excludefirstline);
364 $param .=
'&endatlinenb='.urlencode($endatlinenb);
367 $param .=
'&separator='.urlencode($separator);
370 $param .=
'&enclosure='.urlencode($enclosure);
373 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
379 print
'<div class="opacitymedium">'.$langs->trans(
"SelectImportDataSet").
'</div><br>';
382 print
'<div class="div-table-responsive-no-min">';
383 print
'<table class="noborder centpercent">';
384 print
'<tr class="liste_titre">';
385 print
'<td>'.$langs->trans(
"Module").
'</td>';
386 print
'<td>'.$langs->trans(
"ImportableDatas").
'</td>';
387 print
'<td> </td>';
390 if (count($objimport->array_import_module)) {
391 $sortedarrayofmodules =
dol_sort_array($objimport->array_import_module,
'position_of_profile',
'asc', 0, 0, 1);
392 foreach ($sortedarrayofmodules as $key => $value) {
394 print
'<tr class="oddeven"><td>';
395 $titleofmodule = $objimport->array_import_module[$key][
'module']->getName();
397 if (in_array($objimport->array_import_code[$key], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
398 $titleofmodule = $langs->trans(
"ProductOrService");
400 print $titleofmodule;
402 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[$key]);
403 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
404 print
img_object($objimport->array_import_module[$key][
'module']->getName(), $entityicon).
' ';
405 print $objimport->array_import_label[$key];
406 print
'</td><td style="text-align: right">';
407 if ($objimport->array_import_perms[$key]) {
408 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>';
410 print $langs->trans(
"NotEnoughPermissions");
415 print
'<tr><td class="oddeven" colspan="3">'.$langs->trans(
"NoImportableData").
'</td></tr>';
425if ($step == 2 && $datatoimport) {
426 $param =
'&datatoimport='.urlencode($datatoimport);
427 if ($excludefirstline) {
428 $param .=
'&excludefirstline='.urlencode($excludefirstline);
431 $param .=
'&endatlinenb='.urlencode($endatlinenb);
434 $param .=
'&separator='.urlencode($separator);
437 $param .=
'&enclosure='.urlencode($enclosure);
440 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
446 print
'<div class="underbanner clearboth"></div>';
447 print
'<div class="fichecenter">';
449 print
'<table class="border tableforfield centpercent">';
452 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
454 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
456 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
457 $titleofmodule = $langs->trans(
"ProductOrService");
459 print $titleofmodule;
463 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
465 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
466 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
467 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
468 print $objimport->array_import_label[0];
476 print
'<form name="userfile" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" METHOD="POST">';
477 print
'<input type="hidden" name="token" value="'.newToken().
'">';
481 print
'<span class="opacitymedium">';
482 $s = $langs->trans(
"ChooseFormatOfFileToImport",
'{s1}');
483 $s = str_replace(
'{s1}',
img_picto(
'',
'next'), $s);
485 print
'</span><br><br>';
489 print
'<div class="div-table-responsive-no-min">';
490 print
'<table class="noborder centpercent" cellpadding="4">';
495 print
'<tr class="liste_titre"><td colspan="5">';
496 print $langs->trans(
"FileMustHaveOneOfFollowingFormat");
498 $list = $objmodelimport->listOfAvailableImportFormat($db);
499 foreach ($list as $key) {
500 print
'<tr class="oddeven">';
501 print
'<td width="16">'.img_picto_common($key, $objmodelimport->getPictoForKey($key)).
'</td>';
502 $text = $objmodelimport->getDriverDescForKey($key);
503 print
'<td>'.$form->textwithpicto($objmodelimport->getDriverLabelForKey($key), $text).
'</td>';
504 print
'<td style="text-align:center">';
505 $filename = $langs->trans(
"ExampleOfImportFile").
'_'.$datatoimport.
'.'.$key;
506 print
'<a href="'.DOL_URL_ROOT.
'/imports/emptyexample.php?format='.$key.$param.
'&output=file&file='.urlencode($filename).
'" target="_blank" rel="noopener noreferrer">';
507 print
img_picto(
'',
'download',
'class="paddingright opacitymedium"');
508 print $langs->trans(
"DownloadEmptyExampleShort");
510 print $form->textwithpicto(
'', $langs->trans(
"DownloadEmptyExample").
'.<br>'.$langs->trans(
"StarAreMandatory"));
513 print
'<td style="text-align:right">';
514 print
'<a href="'.DOL_URL_ROOT.
'/imports/import.php?step=3&format='.$key.$param.
'">'.
img_picto($langs->trans(
"SelectFormat"),
'next',
'class="fa-15"').
'</a>';
527if ($step == 3 && $datatoimport) {
528 $param =
'&datatoimport='.urlencode($datatoimport).
'&format='.urlencode($format);
529 if ($excludefirstline) {
530 $param .=
'&excludefirstline='.urlencode($excludefirstline);
533 $param .=
'&endatlinenb='.urlencode($endatlinenb);
536 $param .=
'&separator='.urlencode($separator);
539 $param .=
'&enclosure='.urlencode($enclosure);
542 $list = $objmodelimport->listOfAvailableImportFormat($db);
544 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
553 if ($action ==
'delete') {
554 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?urlfile='.urlencode(
GETPOST(
'urlfile')).
'&step=3'.$param, $langs->trans(
'DeleteFile'), $langs->trans(
'ConfirmDeleteFile'),
'confirm_deletefile',
'', 0, 1);
557 print
'<div class="underbanner clearboth"></div>';
558 print
'<div class="fichecenter">';
560 print
'<table class="border tableforfield centpercent">';
563 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
565 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
567 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
568 $titleofmodule = $langs->trans(
"ProductOrService");
570 print $titleofmodule;
574 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
576 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
577 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
578 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
579 print $objimport->array_import_label[0];
585 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
587 print
'<div class="underbanner clearboth"></div>';
588 print
'<div class="fichecenter">';
589 print
'<table width="100%" class="border tableforfield">';
592 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
593 print
'<td class="nowraponall">';
594 $text = $objmodelimport->getDriverDescForKey($format);
595 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
596 print
'</td><td style="text-align:right" class="nowrap">';
597 $filename = $langs->trans(
"ExampleOfImportFile").
'_'.$datatoimport.
'.'.$format;
598 print
'<a href="'.DOL_URL_ROOT.
'/imports/emptyexample.php?format='.$format.$param.
'&output=file&file='.urlencode($filename).
'" target="_blank" rel="noopener noreferrer">';
599 print
img_picto(
'',
'download',
'class="paddingright opacitymedium"');
600 print $langs->trans(
"DownloadEmptyExampleShort");
602 print $form->textwithpicto(
'', $langs->trans(
"DownloadEmptyExample").
'.<br>'.$langs->trans(
"StarAreMandatory"));
611 if ($format ==
'xlsx' && !class_exists(
'XMLWriter')) {
612 $langs->load(
"install");
613 print
info_admin($langs->trans(
"ErrorPHPDoesNotSupport",
'php-xml'), 0, 0, 1,
'error');
619 print
'<form name="userfile" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="POST">';
620 print
'<input type="hidden" name="token" value="'.newToken().
'">';
621 print
'<input type="hidden" value="'.$step.
'" name="step">';
622 print
'<input type="hidden" value="'.dol_escape_htmltag($format).
'" name="format">';
623 print
'<input type="hidden" value="'.$excludefirstline.
'" name="excludefirstline">';
624 print
'<input type="hidden" value="'.$endatlinenb.
'" name="endatlinenb">';
625 print
'<input type="hidden" value="'.dol_escape_htmltag($separator).
'" name="separator">';
626 print
'<input type="hidden" value="'.dol_escape_htmltag($enclosure).
'" name="enclosure">';
627 print
'<input type="hidden" value="'.dol_escape_htmltag($datatoimport).
'" name="datatoimport">';
629 print
'<span class="opacitymedium">';
630 $s = $langs->trans(
"ChooseFileToImport",
'{s1}');
631 $s = str_replace(
'{s1}',
img_picto(
'',
'next'), $s);
633 print
'</span><br><br>';
638 print
'<div class="marginbottomonly">';
640 $maxmin = $maxfilesizearray[
'maxmin'];
642 print
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
644 print
'<input type="file" name="userfile" size="20" maxlength="80"> ';
646 print
'<input type="submit" class="button small" value="'.$langs->trans(
"AddFile").
'"'.$out.
' name="sendit">';
649 $max = $conf->global->MAIN_UPLOAD_DOC;
650 $maxphp = @ini_get(
'upload_max_filesize');
651 if (preg_match(
'/k$/i', $maxphp)) {
652 $maxphp = (int) substr($maxphp, 0, -1);
654 if (preg_match(
'/m$/i', $maxphp)) {
655 $maxphp = (int) substr($maxphp, 0, -1) * 1024;
657 if (preg_match(
'/g$/i', $maxphp)) {
658 $maxphp = (int) substr($maxphp, 0, -1) * 1024 * 1024;
660 if (preg_match(
'/t$/i', $maxphp)) {
661 $maxphp = (int) substr($maxphp, 0, -1) * 1024 * 1024 * 1024;
663 $maxphp2 = @ini_get(
'post_max_size');
664 if (preg_match(
'/k$/i', $maxphp2)) {
665 $maxphp2 = (int) substr($maxphp2, 0, -1);
667 if (preg_match(
'/m$/i', $maxphp2)) {
668 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024;
670 if (preg_match(
'/g$/i', $maxphp2)) {
671 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024 * 1024;
673 if (preg_match(
'/t$/i', $maxphp2)) {
674 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024 * 1024 * 1024;
678 $maxphptoshow = $maxphptoshowparam =
'';
680 $maxmin = min($max, $maxphp);
681 $maxphptoshow = $maxphp;
682 $maxphptoshowparam =
'upload_max_filesize';
685 $maxmin = min($max, $maxphp2);
686 if ($maxphp2 < $maxphp) {
687 $maxphptoshow = $maxphp2;
688 $maxphptoshowparam =
'post_max_size';
692 $langs->load(
'other');
694 $out .=
info_admin($langs->trans(
"ThisLimitIsDefinedInSetup", $max, $maxphptoshow), 1);
696 $out .=
' ('.$langs->trans(
"UploadDisabled").
')';
702 $filearray =
dol_dir_list($conf->import->dir_temp,
'files', 0,
'',
'',
'name', SORT_DESC);
703 if (count($filearray) > 0) {
704 print
'<div class="div-table-responsive-no-min">';
705 print
'<table class="noborder centpercent" width="100%" cellpadding="4">';
707 $dir = $conf->import->dir_temp;
711 foreach ($filearray as $key => $val) {
712 $file = $val[
'name'];
716 $file = mb_convert_encoding($file,
'UTF-8',
'ISO-8859-1');
719 if (preg_match(
'/^\./', $file)) {
723 $modulepart =
'import';
724 $urlsource = $_SERVER[
"PHP_SELF"].
'?step='.$step.$param.
'&filetoimport='.urlencode($filetoimport);
725 $relativepath = $file;
727 print
'<tr class="oddeven">';
729 print
img_mime($file,
'',
'pictofixedwidth');
730 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=3'.$param.
'" target="_blank" rel="noopener noreferrer">';
735 print
'<td style="text-align:right">'.dol_print_size(
dol_filesize($dir.
'/'.$file)).
'</td>';
737 print
'<td style="text-align:right">'.dol_print_date(
dol_filemtime($dir.
'/'.$file),
'dayhour').
'</td>';
739 print
'<td style="text-align:right"><a href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.newToken().
'&step=3'.$param.
'&urlfile='.urlencode($relativepath);
740 print
'">'.img_delete().
'</a></td>';
742 print
'<td style="text-align:right">';
743 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?step=4'.$param.
'&filetoimport='.urlencode($relativepath).
'">'.
img_picto($langs->trans(
"NewImport"),
'next',
'class="fa-15"').
'</a>';
757if ($step == 4 && $datatoimport) {
759 $serialized_array_match_file_to_database = isset($_SESSION[
"dol_array_match_file_to_database_select"]) ? $_SESSION[
"dol_array_match_file_to_database_select"] :
'';
760 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
761 $array_match_file_to_database = array();
762 foreach ($fieldsarray as $elem) {
763 $tabelem = explode(
'=', $elem, 2);
765 $val = (isset($tabelem[1]) ? $tabelem[1] :
'');
767 $array_match_file_to_database[$key] = $val;
776 $list = $objmodelimport->listOfAvailableImportFormat($db);
778 if (empty($separator)) {
779 $separator = (!
getDolGlobalString(
'IMPORT_CSV_SEPARATOR_TO_USE') ?
',' : $conf->global->IMPORT_CSV_SEPARATOR_TO_USE);
783 if ($model ==
'csv' && strlen($separator) == 1 && !GETPOSTISSET(
'separator')) {
785 $fh = fopen($conf->import->dir_temp.
'/'.$filetoimport,
'r');
787 $sline = fgets($fh, 1000000);
789 $nboccurence = substr_count($sline, $separator);
790 $nboccurencea = substr_count($sline,
',');
791 $nboccurenceb = substr_count($sline,
';');
793 if ($nboccurence == 0) {
794 if ($nboccurencea > 2) {
796 } elseif ($nboccurenceb > 2) {
804 $separator_used = str_replace(
'\t',
"\t", $separator);
807 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
808 $file =
"import_".$model.
".modules.php";
809 $classname =
"Import".ucfirst($model);
810 require_once $dir.$file;
811 $obj =
new $classname($db, $datatoimport);
812 if ($model ==
'csv') {
813 $obj->separator = $separator_used;
814 $obj->enclosure = $enclosure;
817 if ($model ==
'xlsx') {
818 if (!preg_match(
'/\.xlsx$/i', $filetoimport)) {
819 $langs->load(
"errors");
820 $param =
'&datatoimport='.$datatoimport.
'&format='.$format;
821 setEventMessages($langs->trans(
"ErrorFileMustHaveFormat", $model),
null,
'errors');
822 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?step=3'.$param.
'&filetoimport='.urlencode($relativepath));
828 $array_match_file_to_database = array();
832 $fieldssource = array();
833 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport, $langs);
836 $arrayrecord = $obj->import_read_record();
840 foreach ($arrayrecord as $key => $val) {
841 if ($val[
"type"] != -1) {
842 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 128);
845 $fieldssource[$i][
'example1'] = $langs->trans(
'Empty');
849 $obj->import_close_file();
853 $fieldstarget = $objimport->array_import_fields[0];
854 $minpos = min(count($fieldssource), count($fieldstarget));
858 $initialloadofstep4 =
false;
859 if (empty($_SESSION[
'dol_array_match_file_to_database_select'])) {
860 $initialloadofstep4 =
true;
864 if (count($array_match_file_to_database) == 0) {
870 $num = count($fieldssource);
871 while ($pos <= $num) {
872 if ($num >= 1 && $pos <= $num) {
874 foreach ($fieldstarget as $key => $val) {
875 if ($posbis < $pos) {
880 $array_match_file_to_database[$pos] = $key;
887 $array_match_database_to_file = array_flip($array_match_file_to_database);
891 $fieldstarget_tmp = array();
892 $arraykeysfieldtarget = array_keys($fieldstarget);
894 foreach ($fieldstarget as $key => $label) {
895 $isrequired = preg_match(
'/\*$/', $label);
896 if (!empty($isrequired)) {
897 $newlabel = substr($label, 0, -1);
898 $fieldstarget_tmp[$key] = array(
"label"=>$newlabel,
"required"=>
true);
900 $fieldstarget_tmp[$key] = array(
"label"=>$label,
"required"=>
false);
902 if (!empty($array_match_database_to_file[$key])) {
903 $fieldstarget_tmp[$key][
"imported"] =
true;
904 $fieldstarget_tmp[$key][
"position"] = $array_match_database_to_file[$key]-1;
906 while (!empty($array_match_database_to_file[$keytoswap])) {
907 if ($position+1 > $array_match_database_to_file[$keytoswap]) {
908 $keytoswapwith = $array_match_database_to_file[$keytoswap]-1;
909 $tmp = [$keytoswap=>$fieldstarget_tmp[$keytoswap]];
910 unset($fieldstarget_tmp[$keytoswap]);
911 $fieldstarget_tmp =
arrayInsert($fieldstarget_tmp, $keytoswapwith, $tmp);
912 $keytoswapwith = $arraykeysfieldtarget[$array_match_database_to_file[$keytoswap]-1];
913 $tmp = $fieldstarget_tmp[$keytoswapwith];
914 unset($fieldstarget_tmp[$keytoswapwith]);
915 $fieldstarget_tmp[$keytoswapwith] = $tmp;
916 $keytoswap = $keytoswapwith;
922 $fieldstarget_tmp[$key][
"imported"] =
false;
926 $fieldstarget = $fieldstarget_tmp;
935 $param =
'&format='.$format.
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport);
936 if ($excludefirstline) {
937 $param .=
'&excludefirstline='.urlencode($excludefirstline);
940 $param .=
'&endatlinenb='.urlencode($endatlinenb);
943 $param .=
'&separator='.urlencode($separator);
946 $param .=
'&enclosure='.urlencode($enclosure);
949 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
955 print
'<div class="underbanner clearboth"></div>';
956 print
'<div class="fichecenter">';
958 print
'<table class="centpercent border tableforfield">';
961 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
963 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
965 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
966 $titleofmodule = $langs->trans(
"ProductOrService");
968 print $titleofmodule;
972 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
974 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
975 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
976 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
977 print $objimport->array_import_label[0];
983 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
985 print
'<div class="underbanner clearboth"></div>';
986 print
'<div class="fichecenter">';
987 print
'<table width="100%" class="border tableforfield">';
990 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
992 $text = $objmodelimport->getDriverDescForKey($format);
993 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
997 if ($model ==
'csv') {
998 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
1000 print
'<form method="POST">';
1001 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1002 print
'<input type="hidden" value="'.$step.
'" name="step">';
1003 print
'<input type="hidden" value="'.$format.
'" name="format">';
1004 print
'<input type="hidden" value="'.$excludefirstline.
'" name="excludefirstline">';
1005 print
'<input type="hidden" value="'.$endatlinenb.
'" name="endatlinenb">';
1006 print
'<input type="hidden" value="'.$datatoimport.
'" name="datatoimport">';
1007 print
'<input type="hidden" value="'.$filetoimport.
'" name="filetoimport">';
1008 print $langs->trans(
"Separator").
' : ';
1009 print
'<input type="text" class="width25 center" name="separator" value="'.dol_escape_htmltag($separator).
'"/>';
1010 print
' '.$langs->trans(
"Enclosure").
' : ';
1011 print
'<input type="text" class="width25 center" name="enclosure" value="'.dol_escape_htmltag($enclosure).
'"/> ';
1012 print
'<input name="update" type="submit" value="'.$langs->trans(
'Update').
'" class="button smallpaddingimp" />';
1018 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
1020 $modulepart =
'import';
1021 $relativepath =
GETPOST(
'filetoimport');
1022 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
1023 print
img_mime($file,
'',
'pictofixedwidth');
1024 print $filetoimport;
1025 print
img_picto($langs->trans(
"Download"),
'download',
'class="paddingleft opacitymedium"');
1038 print
'<!-- List of source fields -->'.
"\n";
1039 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1040 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1041 print
'<input type="hidden" name="action" value="select_model">';
1042 print
'<input type="hidden" name="step" value="4">';
1043 print
'<input type="hidden" name="format" value="'.$format.
'">';
1044 print
'<input type="hidden" name="datatoimport" value="'.$datatoimport.
'">';
1045 print
'<input type="hidden" name="filetoimport" value="'.$filetoimport.
'">';
1046 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1047 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1048 print
'<input type="hidden" name="separator" value="'.dol_escape_htmltag($separator).
'">';
1049 print
'<input type="hidden" name="enclosure" value="'.dol_escape_htmltag($enclosure).
'">';
1052 print
'<div class="marginbottomonly">';
1053 print
'<span class="opacitymedium">';
1054 $s = $langs->trans(
"SelectImportFieldsSource",
'{s1}');
1055 $s = str_replace(
'{s1}',
img_picto(
'',
'grip_title',
'',
false, 0, 0,
'',
'', 0), $s);
1058 $htmlother->select_import_model($importmodelid,
'importmodelid', $datatoimport, 1, $user->id);
1059 print
'<input type="submit" class="button small reposition" value="'.$langs->trans(
"Select").
'">';
1064 print
'<div class="div-table-responsive-no-min">';
1065 print
'<table class="noborder centpercent">';
1066 print
'<tr class="liste_titre">';
1067 print
'<td>'.$langs->trans(
"FieldsInSourceFile").
'</td>';
1068 print
'<td>'.$langs->trans(
"FieldsInTargetDatabase").
'</td>';
1073 print
'<tr valign="top"><td width="50%" class="nopaddingleftimp">';
1075 $fieldsplaced = array();
1076 $valforsourcefieldnb = array();
1077 $listofkeys = array();
1078 foreach ($array_match_file_to_database as $key => $val) {
1079 $listofkeys[$key] = 1;
1082 print
"\n<!-- Box left container -->\n";
1083 print
'<div id="left" class="connectedSortable">'.
"\n";
1089 foreach ($fieldssource as $key => $val) {
1090 show_elem($fieldssource, $key, $val, $var);
1091 $listofkeys[$key] = 1;
1092 $fieldsplaced[$key] = 1;
1093 $valforsourcefieldnb[$lefti] = $key;
1103 print
"<!-- End box left container -->\n";
1106 print
'</td><td width="50%" class="nopaddingrightimp">';
1110 $optionsall = array();
1111 foreach ($fieldstarget as $code => $line) {
1114 $tmparray = explode(
'|', $line[
"label"]);
1116 foreach ($tmparray as $tmpkey => $tmpval) {
1117 $labeltoshow .= ($labeltoshow ?
' '.$langs->trans(
'or').
' ' :
'').$langs->transnoentities($tmpval);
1119 $optionsall[$code] = array(
'labelkey'=>$line[
'label'],
'labelkeyarray'=>$tmparray,
'label'=>$labeltoshow,
'required'=>(empty($line[
"required"]) ? 0 : 1),
'position'=>!empty($line[
'position']) ? $line[
'position'] : 0);
1124 $optionsall[$code][
'picto'] = $picto;
1131 $mandatoryfieldshavesource =
true;
1144 $modetoautofillmapping =
'session';
1145 if ($initialloadofstep4) {
1146 $modetoautofillmapping =
'guess';
1150 print
'<table class="nobordernopadding centpercent tableimport">';
1151 foreach ($fieldssource as $code => $line) {
1155 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
1156 $entity = (!empty($objimport->array_import_entities[0][$code]) ? $objimport->array_import_entities[0][$code] : $objimport->array_import_icon[0]);
1158 $entityicon = !empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity;
1159 $entitylang = !empty($entitytolang[$entity]) ? $entitytolang[$entity] : $objimport->array_import_label[0];
1161 print
'<td class="nowraponall hideonsmartphone" style="font-weight: normal">=> </td>';
1162 print
'<td class="nowraponall" style="font-weight: normal">';
1167 $selectforline =
'';
1168 $selectforline .=
'<select id="selectorderimport_'.($i+1).
'" class="targetselectchange minwidth300" name="select_'.($i+1).
'">';
1169 if (!empty($line[
"imported"])) {
1170 $selectforline .=
'<option value="-1"> </option>';
1172 $selectforline .=
'<option selected="" value="-1"> </option>';
1176 $codeselectedarray = array();
1177 foreach ($optionsall as $tmpcode => $tmpval) {
1179 if (!empty($tmpval[
'picto'])) {
1180 $label .=
img_picto(
'', $tmpval[
'picto'],
'class="pictofixedwidth"');
1182 $label .= $tmpval[
'required'] ?
'<strong>' :
'';
1183 $label .= $tmpval[
'label'];
1184 $label .= $tmpval[
'required'] ?
'*</strong>' :
'';
1186 $tablealias = preg_replace(
'/(\..*)$/i',
'', $tmpcode);
1187 $tablename = !empty($objimport->array_import_tables[0][$tablealias]) ? $objimport->array_import_tables[0][$tablealias] :
"";
1191 $filecolumn = ($i + 1);
1193 if (empty($objimport->array_import_convertvalue[0][$tmpcode])) {
1196 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromref') {
1197 $htmltext .= $langs->trans(
"DataComeFromIdFoundFromRef", $langs->transnoentitiesnoconv($entitylang)).
'<br>';
1199 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromcodeid') {
1200 $htmltext .= $langs->trans(
"DataComeFromIdFoundFromCodeId", $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$tmpcode][
'dict'])).
'<br>';
1204 $example = !empty($objimport->array_import_examplevalues[0][$tmpcode]) ? $objimport->array_import_examplevalues[0][$tmpcode] :
"";
1206 if (empty($objimport->array_import_convertvalue[0][$tmpcode])) {
1208 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.str_replace(
'"',
'', $example).
'</b><br>';
1211 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromref') {
1212 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.$langs->transnoentitiesnoconv(
"ExampleAnyRefFoundIntoElement", $entitylang).($example ?
' ('.$langs->transnoentitiesnoconv(
"Example").
': '.str_replace(
'"',
'', $example).
')' :
'').
'</b><br>';
1213 } elseif ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromcodeid') {
1214 $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>';
1215 } elseif ($example) {
1216 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.str_replace(
'"',
'', $example).
'</b><br>';
1220 if (!empty($objimport->array_import_regex[0][$tmpcode])) {
1221 $htmltext .= $langs->trans(
"FormatControlRule").
': <b>'.str_replace(
'"',
'', $objimport->array_import_regex[0][$tmpcode]).
'</b><br>';
1225 $htmltext .= $langs->trans(
"InformationOnTargetTables").
': <b>'.$tablename.
"->".preg_replace(
'/^.*\./',
'', $tmpcode).
"</b>";
1227 $labelhtml = $label.
' '.$form->textwithpicto(
'', $htmltext, 1,
'help',
'', 1);
1229 $selectforline .=
'<option value="'.$tmpcode.
'"';
1230 if ($modetoautofillmapping ==
'orderoftargets') {
1233 $selectforline .=
' selected';
1235 } elseif ($modetoautofillmapping ==
'guess') {
1239 if (preg_match(
'/^(.+)\((.+\..+)\)$/', $line[
'example1'], $regs)) {
1240 $tmpstring1 = $regs[1];
1241 $tmpstring2 = $regs[2];
1243 $tmpstring1 = $line[
'example1'];
1246 $tmpstring1 = strtolower(str_replace(
'*',
'', trim($tmpstring1)));
1247 $tmpstring2 = strtolower(str_replace(
'*',
'', trim($tmpstring2)));
1250 foreach ($tmpval[
'labelkeyarray'] as $tmpval2) {
1251 $labeltarget = $langs->transnoentities($tmpval2);
1253 if ($tmpstring1 && ($tmpstring1 == $tmpcode || $tmpstring1 == strtolower($labeltarget)
1254 || $tmpstring1 == strtolower(
dol_string_unaccent($labeltarget)) || $tmpstring1 == strtolower($tmpval2))) {
1255 if (empty($codeselectedarray[$code])) {
1256 $selectforline .=
' selected';
1257 $codeselectedarray[$code] = 1;
1260 } elseif ($tmpstring2 && ($tmpstring2 == $tmpcode || $tmpstring2 == strtolower($labeltarget)
1261 || $tmpstring2 == strtolower(
dol_string_unaccent($labeltarget)) || $tmpstring2 == strtolower($tmpval2))) {
1262 if (empty($codeselectedarray[$code])) {
1263 $selectforline .=
' selected';
1264 $codeselectedarray[$code] = 1;
1269 } elseif ($modetoautofillmapping ==
'session' && !empty($_SESSION[
'dol_array_match_file_to_database_select'])) {
1270 $tmpselectioninsession =
dolExplodeIntoArray($_SESSION[
'dol_array_match_file_to_database_select'],
',',
'=');
1272 if (!empty($tmpselectioninsession[($i+1)]) && $tmpselectioninsession[($i+1)] == $tmpcode) {
1273 $selectforline .=
' selected';
1275 $selectforline .=
' data-debug="'.$tmpcode.
'-'.$code.
'-'.$j.
'-'.(!empty($tmpselectioninsession[($i+1)]) ? $tmpselectioninsession[($i+1)] :
"").
'"';
1277 $selectforline .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
1278 $selectforline .=
'>';
1279 $selectforline .= $label;
1280 $selectforline .=
'</options>';
1283 $selectforline .=
'</select>';
1284 $selectforline .=
ajax_combobox(
'selectorderimport_'.($i+1));
1286 print $selectforline;
1291 print
'<td class="nowraponall" style="font-weight:normal; text-align:right">';
1294 $htmltext =
'<b><u>'.$langs->trans(
"FieldSource").
'</u></b><br>';
1296 $htmltext .= $langs->trans(
"DataComeFromFileFieldNb", $filecolumntoshow).
'<br>';
1298 print $form->textwithpicto(
'', $htmltext);
1309 print
'<tr class="liste_titre"><td colspan="2">'.$langs->trans(
"Note").
'</td></tr>';
1310 print
'<tr><td colspan="2"><div id="div-mandatory-target-fields-not-mapped"></div></td></tr>';
1316 if (!empty($conf->use_javascript_ajax)) {
1317 print
'<script type="text/javascript">'.
"\n";
1318 print
'var previousselectedvalueimport = "0";'.
"\n";
1319 print
'var previousselectedlabelimport = "0";'.
"\n";
1320 print
'var arrayofselectedvalues = [];'.
"\n";
1321 print
'var arrayoftargetfields = [];'.
"\n";
1322 print
'var arrayoftargetmandatoryfields = [];'.
"\n";
1326 foreach ($fieldstarget as $key => $val) {
1327 print
"arrayoftargetfields[".$tmpi.
"] = '".
dol_escape_js($langs->trans($val[
'label'])).
"'; ";
1328 if ($val[
'required']) {
1329 print
"arrayoftargetmandatoryfields[".$tmpi.
"] = '".
dol_escape_js($key).
"'; ";
1335 print
'$(document).ready(function () {'.
"\n";
1337 print
'setOptionsToDisabled();'.
"\n";
1338 print
'saveSelection();'.
"\n";
1340 print
'$(".targetselectchange").focus(function(){'.
"\n";
1341 print
' previousselectedvalueimport = $(this).val();'.
"\n";
1342 print
' previousselectedlabelimport = $(this).children("option:selected").text();'.
"\n";
1343 print
' console.log("previousselectedvalueimport="+previousselectedvalueimport)'.
"\n";
1350 print
'function setOptionsToDisabled() {'.
"\n";
1351 print
' console.log("Remove the disabled flag everywhere");'.
"\n";
1352 print
' $("select.targetselectchange").not($( this )).find(\'option\').prop("disabled", false);'.
"\n";
1353 print
' arrayofselectedvalues = [];'.
"\n";
1355 print
' $("select.targetselectchange").each(function(){'.
"\n";
1356 print
' id = $(this).attr(\'id\')'.
"\n";
1357 print
' value = $(this).val()'.
"\n";
1358 print
' console.log("a selected value has been found for component "+id+" = "+value);'.
"\n";
1359 print
' arrayofselectedvalues.push(value);'.
"\n";
1362 print
' console.log("List of all selected values arrayofselectedvalues");'.
"\n";
1363 print
' console.log(arrayofselectedvalues);'.
"\n";
1364 print
' console.log("Set the option to disabled for every entry that is currently selected somewhere else (so into arrayofselectedvalues)");'.
"\n";
1366 print
' $.each(arrayofselectedvalues, function(key, value) {'.
"\n";
1367 print
' if (value != -1) {'.
"\n";
1368 print
' console.log("Process key="+key+" value="+value+" to disable.");'.
"\n";
1369 print
' $("select.targetselectchange").find(\'option[value="\'+value+\'"]:not(:selected)\').prop("disabled", true);'.
"\n";
1375 print
'function saveSelection() {'.
"\n";
1377 print
' arrayselectedfields = [];'.
"\n";
1378 print
' arrayselectedfields.push(0);'.
"\n";
1380 print
' $.each( arrayofselectedvalues, function( key, value ) {'.
"\n";
1381 print
' if (value != -1) {'.
"\n";
1382 print
' arrayselectedfields.push(value);'.
"\n";
1383 print
' } else {'.
"\n";
1384 print
' arrayselectedfields.push(0);'.
"\n";
1388 print
" $.ajax({\n";
1389 print
" type: 'POST',\n";
1390 print
" dataType: 'json',\n";
1391 print
" url: '".dol_escape_js($_SERVER[
"PHP_SELF"]).
"?action=saveselectorder&token=".newToken().
"',\n";
1392 print
" data: 'selectorder='+arrayselectedfields.toString(),\n";
1393 print
" success: function(){\n";
1394 print
" console.log('The selected fields have been saved into '+arrayselectedfields.toString());\n";
1399 print
' console.log("arrayselectedfields");';
1400 print
' console.log(arrayselectedfields);';
1401 print
' console.log("arrayoftargetmandatoryfields");';
1402 print
' console.log(arrayoftargetmandatoryfields);';
1403 print
" listtoshow = '';";
1404 print
" nbelement = arrayoftargetmandatoryfields.length
1405 for (let i = 0; i < nbelement; i++) {
1406 if (arrayoftargetmandatoryfields[i] && ! arrayselectedfields.includes(arrayoftargetmandatoryfields[i])) {
1407 console.log(arrayoftargetmandatoryfields[i]+' not mapped');
1408 listtoshow = listtoshow + (listtoshow ? ', ' : '') + '<b>' + arrayoftargetfields[i] + '*</b>';
1411 console.log(listtoshow);
1413 listtoshow = '".dol_escape_js(
img_warning($langs->trans(
"MandatoryTargetFieldsNotMapped")).
' '.$langs->trans(
"MandatoryTargetFieldsNotMapped")).
": ' + listtoshow;
1414 $('#div-mandatory-target-fields-not-mapped').html(listtoshow);
1416 $('#div-mandatory-target-fields-not-mapped').html('<span class=\"opacitymedium\">".
dol_escape_js($langs->trans(
"AllTargetMandatoryFieldsAreMapped")).
"</span>');
1423 print
'$(".targetselectchange").change(function(){'.
"\n";
1424 print
' setOptionsToDisabled();'.
"\n";
1426 print
' if(previousselectedlabelimport != "" && previousselectedvalueimport != -1) {'.
"\n";
1427 print
' let valuetochange = $(this).val(); '.
"\n";
1428 print
' $(".boxtdunused").each(function(){'.
"\n";
1429 print
' if ($(this).text().includes(valuetochange)){'.
"\n";
1430 print
' arraychild = $(this)[0].childNodes'.
"\n";
1431 print
' arraytexttomodify = arraychild[0].textContent.split(" ")'.
"\n";
1432 print
' arraytexttomodify[1] = previousselectedvalueimport '.
"\n";
1433 print
' textmodified = arraytexttomodify.join(" ") '.
"\n";
1434 print
' arraychild[0].textContent = textmodified'.
"\n";
1435 print
' arraychild[1].innerHTML = previousselectedlabelimport'.
"\n";
1439 print
' $(this).blur()'.
"\n";
1441 print
' saveSelection()'.
"\n";
1445 print
'</script>'.
"\n";
1451 print
'<div class="tabsAction">';
1453 if (count($array_match_file_to_database)) {
1454 if ($mandatoryfieldshavesource) {
1455 print
'<a class="butAction saveorderselect" href="import.php?step=5'.$param.
'&filetoimport='.urlencode($filetoimport).
'">'.$langs->trans(
"NextStep").
'</a>';
1457 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"SomeMandatoryFieldHaveNoSource")).
'">'.$langs->trans(
"NextStep").
'</a>';
1465 if (count($array_match_file_to_database)) {
1467 print
'<!-- Area to add new import profile -->'.
"\n";
1468 print
'<div class="marginbottomonly"><span class="opacitymedium">'.$langs->trans(
"SaveImportModel").
'</span></div>';
1470 print
'<form class="nocellnopadd" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1471 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1472 print
'<input type="hidden" name="action" value="add_import_model">';
1473 print
'<input type="hidden" name="step" value="'.$step.
'">';
1474 print
'<input type="hidden" name="format" value="'.$format.
'">';
1475 print
'<input type="hidden" name="datatoimport" value="'.$datatoimport.
'">';
1476 print
'<input type="hidden" name="filetoimport" value="'.$filetoimport.
'">';
1477 print
'<input type="hidden" name="hexa" value="'.$hexa.
'">';
1478 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1479 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1480 print
'<input type="hidden" name="page_y" value="">';
1481 print
'<input type="hidden" value="'.dol_escape_htmltag($separator).
'" name="separator">';
1482 print
'<input type="hidden" value="'.dol_escape_htmltag($enclosure).
'" name="enclosure">';
1484 print
'<div class="div-table-responsive-no-min">';
1485 print
'<table summary="selectofimportprofil" class="noborder centpercent">';
1486 print
'<tr class="liste_titre">';
1487 print
'<td>'.$langs->trans(
"ImportModelName").
'</td>';
1488 print
'<td>'.$langs->trans(
"Visibility").
'</td>';
1492 $nameofimportprofile = str_replace(
' ',
'-', $langs->trans(
"ImportProfile").
' '.$titleofmodule.
' '.
dol_print_date(
dol_now(
'gmt'),
'dayxcard'));
1494 $nameofimportprofile = $import_name;
1497 print
'<tr class="oddeven">';
1498 print
'<td><input name="import_name" class="minwidth300" value="'.$nameofimportprofile.
'"></td>';
1500 $arrayvisibility = array(
'private'=>$langs->trans(
"Private"),
'all'=>$langs->trans(
"Everybody"));
1501 print $form->selectarray(
'visibility', $arrayvisibility,
'private');
1503 print
'<td class="right">';
1504 print
'<input type="submit" class="button smallpaddingimp reposition" value="'.$langs->trans(
"SaveImportProfile").
'">';
1508 $sql =
"SELECT rowid, label, fk_user, entity";
1509 $sql .=
" FROM ".MAIN_DB_PREFIX.
"import_model";
1510 $sql .=
" WHERE type = '".$db->escape($datatoimport).
"'";
1512 $sql .=
" AND fk_user IN (0, ".((int) $user->id).
")";
1514 $sql .=
" ORDER BY rowid";
1516 $resql = $db->query($sql);
1518 $num = $db->num_rows($resql);
1520 $tmpuser =
new User($db);
1524 $obj = $db->fetch_object($resql);
1526 print
'<tr class="oddeven"><td>';
1529 print
'<td class="tdoverflowmax150">';
1530 if (empty($obj->fk_user)) {
1531 print $langs->trans(
"Everybody");
1533 $tmpuser->fetch($obj->fk_user);
1534 print $tmpuser->getNomUrl(-1);
1537 print
'<td class="right">';
1538 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?step='.$step.$param.
'&action=deleteprof&token='.newToken().
'&id='.$obj->rowid.
'&filetoimport='.urlencode($filetoimport).
'">';
1556if ($step == 5 && $datatoimport) {
1557 $max_execution_time_for_importexport = (!
getDolGlobalString(
'IMPORT_MAX_EXECUTION_TIME') ? 300 : $conf->global->IMPORT_MAX_EXECUTION_TIME);
1558 $max_time = @ini_get(
"max_execution_time");
1559 if ($max_time && $max_time < $max_execution_time_for_importexport) {
1560 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.");
1561 @ini_set(
"max_execution_time", $max_execution_time_for_importexport);
1565 $list = $objmodelimport->listOfAvailableImportFormat($db);
1568 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
1569 $file =
"import_".$model.
".modules.php";
1570 $classname =
"Import".ucfirst($model);
1571 require_once $dir.$file;
1572 $obj =
new $classname($db, $datatoimport);
1573 if ($model ==
'csv') {
1574 $obj->separator = $separator_used;
1575 $obj->enclosure = $enclosure;
1579 $fieldssource = array();
1580 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport, $langs);
1584 $arrayrecord = $obj->import_read_record();
1587 foreach ($arrayrecord as $key => $val) {
1588 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 24);
1591 $obj->import_close_file();
1594 $nboflines = $obj->import_get_nb_of_lines($conf->import->dir_temp.
'/'.$filetoimport);
1596 $param =
'&leftmenu=import&format='.urlencode($format).
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport).
'&nboflines='.urlencode($nboflines).
'&separator='.urlencode($separator).
'&enclosure='.urlencode($enclosure);
1598 if ($excludefirstline) {
1599 $param .=
'&excludefirstline='.urlencode($excludefirstline);
1602 $param .=
'&endatlinenb='.urlencode($endatlinenb);
1604 if (!empty($updatekeys)) {
1605 $param .=
'&updatekeys[]='.implode(
'&updatekeys[]=', $updatekeys);
1608 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
1613 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?'.$param2.
'" method="POST">';
1614 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1615 print
'<input type="hidden" name="step" value="5">';
1616 print
'<input type="hidden" name="action" value="launchsimu">';
1620 print
'<div class="underbanner clearboth"></div>';
1621 print
'<div class="fichecenter">';
1623 print
'<table width="100%" class="border tableforfield">';
1626 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
1628 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
1630 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
1631 $titleofmodule = $langs->trans(
"ProductOrService");
1633 print $titleofmodule;
1637 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
1639 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
1640 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
1641 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
1642 print $objimport->array_import_label[0];
1648 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
1650 print
'<div class="underbanner clearboth"></div>';
1651 print
'<div class="fichecenter">';
1652 print
'<table width="100%" class="border tableforfield">';
1655 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
1657 $text = $objmodelimport->getDriverDescForKey($format);
1658 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
1662 if ($model ==
'csv') {
1663 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
1666 print
' '.$langs->trans(
"Enclosure").
' : '.
dol_escape_htmltag($enclosure);
1671 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
1673 $modulepart =
'import';
1674 $relativepath =
GETPOST(
'filetoimport');
1675 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
1676 print
img_mime($file,
'',
'pictofixedwidth');
1677 print $filetoimport;
1678 print
img_picto($langs->trans(
"Download"),
'download',
'class="paddingleft opacitymedium"');
1684 print $langs->trans(
"NbOfSourceLines");
1691 print $langs->trans(
"ImportFromToLine");
1693 if ($action ==
'launchsimu') {
1694 print
'<input type="number" class="maxwidth50 right" name="excludefirstlinebis" disabled="disabled" value="'.$excludefirstline.
'">';
1695 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1697 print
'<input type="number" class="maxwidth50 right" name="excludefirstline" value="'.$excludefirstline.
'">';
1698 print $form->textwithpicto(
"", $langs->trans(
"SetThisValueTo2ToExcludeFirstLine"));
1701 if ($action ==
'launchsimu') {
1702 print
'<input type="text" class="maxwidth50" name="endatlinenbbis" disabled="disabled" value="'.$endatlinenb.
'">';
1703 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1705 print
'<input type="text" class="maxwidth50" name="endatlinenb" value="'.$endatlinenb.
'">';
1706 print $form->textwithpicto(
"", $langs->trans(
"KeepEmptyToGoToEndOfFile"));
1708 if ($action ==
'launchsimu') {
1709 print
' <a href="'.$_SERVER[
"PHP_SELF"].
'?step=5'.$param.
'">'.$langs->trans(
"Modify").
'</a>';
1711 if ($excludefirstline == 2) {
1712 print $form->textwithpicto(
"", $langs->trans(
"WarningFirstImportedLine", $excludefirstline), 1,
'warning',
"warningexcludefirstline");
1714 $( document ).ready(function() {
1715 $("input[name=\'excludefirstline\']").on("change",function(){
1716 if($(this).val() <= 1){
1717 $(".warningexcludefirstline").hide();
1719 $(".warningexcludefirstline").show();
1729 print $form->textwithpicto($langs->trans(
"KeysToUseForUpdates"), $langs->trans(
"SelectPrimaryColumnsForUpdateAttempt"));
1731 if ($action ==
'launchsimu') {
1732 if (count($updatekeys)) {
1733 print $form->multiselectarray(
'updatekeysbis', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0,
'', 1,
'80%',
'disabled');
1735 print
'<span class="opacitymedium">'.$langs->trans(
"NoUpdateAttempt").
'</span> -';
1737 foreach ($updatekeys as $val) {
1738 print
'<input type="hidden" name="updatekeys[]" value="'.$val.
'">';
1740 print
' <a href="'.$_SERVER[
"PHP_SELF"].
'?step=5'.$param.
'">'.$langs->trans(
"Modify").
'</a>';
1742 if (is_array($objimport->array_import_updatekeys[0]) && count($objimport->array_import_updatekeys[0])) {
1743 print $form->multiselectarray(
'updatekeys', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0,
'', 1,
'80%');
1746 print
'<span class="opacitymedium">'.$langs->trans(
"UpdateNotYetSupportedForThisImport").
'</span>';
1758 print
load_fiche_titre($langs->trans(
"InformationOnTargetTables"),
'',
'file-import');
1760 print
'<div class="underbanner clearboth"></div>';
1761 print
'<div class="fichecenter">';
1763 print
'<table width="100%" class="border tableforfield">';
1766 print
'<tr><td class="titlefieldcreate">';
1767 print $langs->trans(
"TablesTarget");
1769 $listtables = array();
1770 $sort_array_match_file_to_database = $array_match_file_to_database;
1771 foreach ($array_match_file_to_database as $code => $label) {
1773 if ($code > count($fieldssource)) {
1777 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
1778 $listtables[$alias] = $objimport->array_import_tables[0][$alias];
1780 if (count($listtables)) {
1783 foreach ($listtables as $val) {
1802 print $langs->trans(
"Error");
1808 print $langs->trans(
"FieldsTarget").
'</td><td>';
1809 $listfields = array();
1812 $sort_array_match_file_to_database = $array_match_file_to_database;
1813 ksort($sort_array_match_file_to_database);
1815 foreach ($sort_array_match_file_to_database as $code => $label) {
1818 if ($code > count($fieldssource)) {
1822 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
1823 $listfields[$i] =
'<span class="nowrap">'.$langs->trans(
"Column").
' '.
num2Alpha($code - 1).
' -> '.$label.
'</span>';
1825 print count($listfields) ? (join(
', ', $listfields)) : $langs->trans(
"Error");
1834 if ($action !=
'launchsimu') {
1836 print
'<br><span class="opacitymedium">';
1837 print $langs->trans(
"NowClickToTestTheImport", $langs->transnoentitiesnoconv(
"RunSimulateImportFile")).
'</span><br>';
1841 print
'<div class="center">';
1842 if ($user->hasRight(
'import',
'run')) {
1843 print
'<input type="submit" class="butAction" value="'.$langs->trans(
"RunSimulateImportFile").
'">';
1845 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunSimulateImportFile").
'</a>';
1850 $arrayoferrors = array();
1851 $arrayofwarnings = array();
1852 $maxnboferrors = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_ERRORS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_ERRORS;
1853 $maxnbofwarnings = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_WARNINGS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_WARNINGS;
1865 $pathfile = $conf->import->dir_temp.
'/'.$filetoimport;
1866 $result = $obj->import_open_file($pathfile, $langs);
1868 global $tablewithentity_cache;
1869 $tablewithentity_cache = array();
1874 while (($sourcelinenb < $nboflines) && !$endoffile) {
1878 $arrayrecord = $obj->import_read_record();
1879 if ($arrayrecord ===
false) {
1880 $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');
1884 if ($excludefirstline && ($sourcelinenb < $excludefirstline)) {
1887 if ($endatlinenb && ($sourcelinenb > $endatlinenb)) {
1891 $parameters = array(
1893 'datatoimport' => $datatoimport,
1895 'arrayrecord' => $arrayrecord,
1896 'array_match_file_to_database' => $array_match_file_to_database,
1897 'objimport' => $objimport,
1898 'fieldssource' => $fieldssource,
1899 'importid' => $importid,
1900 'updatekeys' => $updatekeys,
1901 'arrayoferrors' => &$arrayoferrors,
1902 'arrayofwarnings' => &$arrayofwarnings,
1906 $reshook = $hookmanager->executeHooks(
'ImportInsert', $parameters);
1908 $arrayoferrors[$sourcelinenb][] = [
1909 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
1913 if (empty($reshook)) {
1915 $result = $obj->import_insert($arrayrecord, $array_match_file_to_database, $objimport, count($fieldssource), $importid, $updatekeys);
1917 if (count($obj->errors)) {
1918 $arrayoferrors[$sourcelinenb] = $obj->errors;
1920 if (count($obj->warnings)) {
1921 $arrayofwarnings[$sourcelinenb] = $obj->warnings;
1923 if (!count($obj->errors) && !count($obj->warnings)) {
1928 $reshook = $hookmanager->executeHooks(
'AfterImportInsert', $parameters);
1930 $arrayoferrors[$sourcelinenb][] = [
1931 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
1936 $obj->import_close_file();
1938 print $langs->trans(
"ErrorFailedToOpenFile", $pathfile);
1945 if (!empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0])) {
1947 foreach ($objimport->array_import_run_sql_after[0] as $sqlafterimport) {
1949 $resqlafterimport = $db->query($sqlafterimport);
1950 if (!$resqlafterimport) {
1951 $arrayoferrors[
'none'][] = array(
'lib'=>$langs->trans(
"Error running final request: ".$sqlafterimport));
1960 if (!count($arrayoferrors) && !count($arrayofwarnings)) {
1962 print
'<div class="info">';
1963 print
'<div class=""><b>'.$langs->trans(
"ResultOfSimulationNoError").
'</b></div>';
1964 print $langs->trans(
"NbInsertSim", empty($obj->nbinsert) ? 0 : $obj->nbinsert).
'<br>';
1965 print $langs->trans(
"NbUpdateSim", empty($obj->nbupdate) ? 0 : $obj->nbupdate).
'<br>';
1970 print
'<div class="warning">';
1971 print $langs->trans(
"NbOfLinesOK", $nbok).
'...<br>';
1978 if (count($arrayoferrors)) {
1979 print
img_error().
' <b>'.$langs->trans(
"ErrorsOnXLines", count($arrayoferrors)).
'</b><br>';
1980 print
'<table width="100%" class="border"><tr><td>';
1981 foreach ($arrayoferrors as $key => $val) {
1983 if ($nboferrors > $maxnboferrors) {
1984 print $langs->trans(
"TooMuchErrors", (count($arrayoferrors) - $nboferrors)).
"<br>";
1988 foreach ($val as $i => $err) {
1989 print
' > '.dol_escape_htmltag($err[
'lib']).
'<br>';
1992 print
'</td></tr></table>';
1998 if (count($arrayofwarnings)) {
1999 print
img_warning().
' <b>'.$langs->trans(
"WarningsOnXLines", count($arrayofwarnings)).
'</b><br>';
2000 print
'<table width="100%" class="border"><tr><td>';
2001 foreach ($arrayofwarnings as $key => $val) {
2003 if ($nbofwarnings > $maxnbofwarnings) {
2004 print $langs->trans(
"TooMuchWarnings", (count($arrayofwarnings) - $nbofwarnings)).
"<br>";
2008 foreach ($val as $i => $err) {
2009 print
' > '.dol_escape_htmltag($err[
'lib']).
'<br>';
2012 print
'</td></tr></table>';
2019 print
'<div class="center">';
2020 print
'<span class="opacitymedium">'.$langs->trans(
"NowClickToRunTheImport", $langs->transnoentitiesnoconv(
"RunImportFile")).
'</span><br>';
2029 print
'<div class="center">';
2030 if ($user->hasRight(
'import',
'run')) {
2031 if (empty($nboferrors)) {
2032 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/imports/import.php?leftmenu=import&step=6&importid='.$importid.$param.
'">'.$langs->trans(
"RunImportFile").
'</a>';
2036 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"CorrectErrorBeforeRunningImport")).
'">'.$langs->trans(
"RunImportFile").
'</a>';
2039 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunSimulateImportFile").
'</a>';
2041 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunImportFile").
'</a>';
2051if ($step == 6 && $datatoimport) {
2052 $max_execution_time_for_importexport = (!
getDolGlobalString(
'IMPORT_MAX_EXECUTION_TIME') ? 300 : $conf->global->IMPORT_MAX_EXECUTION_TIME);
2053 $max_time = @ini_get(
"max_execution_time");
2054 if ($max_time && $max_time < $max_execution_time_for_importexport) {
2055 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.");
2056 @ini_set(
"max_execution_time", $max_execution_time_for_importexport);
2060 $list = $objmodelimport->listOfAvailableImportFormat($db);
2061 $importid =
GETPOST(
"importid",
'alphanohtml');
2065 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
2066 $file =
"import_".$model.
".modules.php";
2067 $classname =
"Import".ucfirst($model);
2068 require_once $dir.$file;
2069 $obj =
new $classname($db, $datatoimport);
2070 if ($model ==
'csv') {
2071 $obj->separator = $separator_used;
2072 $obj->enclosure = $enclosure;
2076 $fieldssource = array();
2077 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport, $langs);
2080 $arrayrecord = $obj->import_read_record();
2083 foreach ($arrayrecord as $key => $val) {
2084 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 24);
2087 $obj->import_close_file();
2090 $nboflines = (!empty($_GET[
"nboflines"]) ? $_GET[
"nboflines"] :
dol_count_nb_of_line($conf->import->dir_temp.
'/'.$filetoimport));
2092 $param =
'&format='.$format.
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport).
'&nboflines='.urlencode($nboflines);
2093 if ($excludefirstline) {
2094 $param .=
'&excludefirstline='.urlencode($excludefirstline);
2097 $param .=
'&endatlinenb='.urlencode($endatlinenb);
2100 $param .=
'&separator='.urlencode($separator);
2103 $param .=
'&enclosure='.urlencode($enclosure);
2106 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
2112 print
'<div class="underbanner clearboth"></div>';
2113 print
'<div class="fichecenter">';
2115 print
'<table width="100%" class="border">';
2118 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
2120 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
2122 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
2123 $titleofmodule = $langs->trans(
"ProductOrService");
2125 print $titleofmodule;
2129 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
2131 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
2132 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
2133 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
2134 print $objimport->array_import_label[0];
2140 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
2142 print
'<div class="underbanner clearboth"></div>';
2143 print
'<div class="fichecenter">';
2144 print
'<table width="100%" class="border">';
2147 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
2149 $text = $objmodelimport->getDriverDescForKey($format);
2150 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
2154 if ($model ==
'csv') {
2155 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
2157 print $langs->trans(
"Separator").
' : ';
2158 print htmlentities($separator);
2159 print
' '.$langs->trans(
"Enclosure").
' : ';
2160 print htmlentities($enclosure);
2165 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
2167 $modulepart =
'import';
2168 $relativepath =
GETPOST(
'filetoimport');
2169 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
2170 print
img_mime($file,
'',
'pictofixedwidth');
2171 print $filetoimport;
2177 print $langs->trans(
"NbOfSourceLines");
2184 print $langs->trans(
"ImportFromLine");
2186 print
'<input type="text" size="4" name="excludefirstline" disabled="disabled" value="'.$excludefirstline.
'">';
2191 print $langs->trans(
"EndAtLineNb");
2193 print
'<input type="text" size="4" name="endatlinenb" disabled="disabled" value="'.$endatlinenb.
'">';
2201 print
'<b>'.$langs->trans(
"InformationOnTargetTables").
'</b>';
2202 print
'<div class="underbanner clearboth"></div>';
2203 print
'<div class="fichecenter">';
2204 print
'<table class="border centpercent">';
2207 print
'<tr><td width="25%">';
2208 print $langs->trans(
"TablesTarget");
2210 $listtables = array();
2211 foreach ($array_match_file_to_database as $code => $label) {
2213 if ($code > count($fieldssource)) {
2217 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
2218 $listtables[$alias] = $objimport->array_import_tables[0][$alias];
2220 if (count($listtables)) {
2222 foreach ($listtables as $val) {
2241 print $langs->trans(
"Error");
2247 print $langs->trans(
"FieldsTarget").
'</td><td>';
2248 $listfields = array();
2250 $sort_array_match_file_to_database = $array_match_file_to_database;
2251 ksort($sort_array_match_file_to_database);
2253 foreach ($sort_array_match_file_to_database as $code => $label) {
2256 if ($code > count($fieldssource)) {
2260 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
2261 $listfields[$i] = $langs->trans(
"Field").
' '.$code.
'->'.$label;
2263 print count($listfields) ? (join(
', ', $listfields)) : $langs->trans(
"Error");
2270 $arrayoferrors = array();
2271 $arrayofwarnings = array();
2272 $maxnboferrors = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_ERRORS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_ERRORS;
2273 $maxnbofwarnings = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_WARNINGS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_WARNINGS;
2285 $pathfile = $conf->import->dir_temp.
'/'.$filetoimport;
2286 $result = $obj->import_open_file($pathfile, $langs);
2288 global $tablewithentity_cache;
2289 $tablewithentity_cache = array();
2293 while ($sourcelinenb < $nboflines && !$endoffile) {
2295 $arrayrecord = $obj->import_read_record();
2296 if ($arrayrecord ===
false) {
2297 $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');
2301 if ($excludefirstline && ($sourcelinenb < $excludefirstline)) {
2304 if ($endatlinenb && ($sourcelinenb > $endatlinenb)) {
2308 $parameters = array(
2310 'datatoimport' => $datatoimport,
2312 'arrayrecord' => $arrayrecord,
2313 'array_match_file_to_database' => $array_match_file_to_database,
2314 'objimport' => $objimport,
2315 'fieldssource' => $fieldssource,
2316 'importid' => $importid,
2317 'updatekeys' => $updatekeys,
2318 'arrayoferrors' => &$arrayoferrors,
2319 'arrayofwarnings' => &$arrayofwarnings,
2323 $reshook = $hookmanager->executeHooks(
'ImportInsert', $parameters);
2325 $arrayoferrors[$sourcelinenb][] = [
2326 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
2330 if (empty($reshook)) {
2332 $result = $obj->import_insert($arrayrecord, $array_match_file_to_database, $objimport, count($fieldssource), $importid, $updatekeys);
2334 if (count($obj->errors)) {
2335 $arrayoferrors[$sourcelinenb] = $obj->errors;
2337 if (count($obj->warnings)) {
2338 $arrayofwarnings[$sourcelinenb] = $obj->warnings;
2341 if (!count($obj->errors) && !count($obj->warnings)) {
2346 $reshook = $hookmanager->executeHooks(
'AfterImportInsert', $parameters);
2348 $arrayoferrors[$sourcelinenb][] = [
2349 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
2354 $obj->import_close_file();
2356 print $langs->trans(
"ErrorFailedToOpenFile", $pathfile);
2359 if (count($arrayoferrors) > 0) {
2366 if (!empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0])) {
2368 foreach ($objimport->array_import_run_sql_after[0] as $sqlafterimport) {
2370 $resqlafterimport = $db->query($sqlafterimport);
2371 if (!$resqlafterimport) {
2372 $arrayoferrors[
'none'][] = array(
'lib'=>$langs->trans(
"Error running final request: ".$sqlafterimport));
2390 print
'<div class="info">';
2391 print $langs->trans(
"NbOfLinesImported", $nbok).
'</b><br>';
2392 print $langs->trans(
"NbInsert", empty($obj->nbinsert) ? 0 : $obj->nbinsert).
'<br>';
2393 print $langs->trans(
"NbUpdate", empty($obj->nbupdate) ? 0 : $obj->nbupdate).
'<br>';
2395 print
'<div class="center">';
2396 print $langs->trans(
"FileWasImported", $importid).
'<br>';
2397 print
'<span class="opacitymedium">'.$langs->trans(
"YouCanUseImportIdToFindRecord", $importid).
'</span><br>';
2420function show_elem($fieldssource, $pos, $key, $var, $nostyle =
'')
2422 global $conf, $langs;
2426 if ($key ==
'none') {
2428 print
"\n\n<!-- Box_no-key start-->\n";
2429 print
'<div class="box boximport" style="padding:0;">'.
"\n";
2430 print
'<table summary="boxtable_no-key" class="centpercent nobordernopadding">'.
"\n";
2432 print
"\n\n<!-- Box ".$pos.
" start -->\n";
2433 print
'<div class="box boximport" style="padding: 0;" id="boxto_'.$pos.
'">'.
"\n";
2435 print
'<table summary="boxtable'.$pos.
'" class="nobordernopadding centpercent tableimport">'.
"\n";
2438 if (($pos && $pos > count($fieldssource)) && (!isset($fieldssource[$pos][
"imported"]))) {
2448 } elseif ($key ==
'none') {
2449 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
2450 print
'<td class="nocellnopadding" width="16" style="font-weight: normal">';
2453 print
'<td style="font-weight: normal">';
2459 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
2460 print
'<td class="nocellnopadding" width="16" style="font-weight: normal">';
2463 print
img_picto($langs->trans(
"Column").
' '.
num2Alpha($pos - 1),
'file',
'class="pictofixedwith"');
2465 if (isset($fieldssource[$pos][
'imported']) && $fieldssource[$pos][
'imported'] ==
false) {
2466 print
'<td class="nowraponall boxtdunused" style="font-weight: normal">';
2468 print
'<td class="nowraponall tdoverflowmax500" style="font-weight: normal">';
2470 print $langs->trans(
"Column").
' '.
num2Alpha($pos - 1).
' (#'.$pos.
')';
2471 if (empty($fieldssource[$pos][
'example1'])) {
2472 $example = $fieldssource[$pos][
'label'];
2474 $example = $fieldssource[$pos][
'example1'];
2478 $example = mb_convert_encoding($example,
'UTF-8',
'ISO-8859-1');
2480 if (!empty($conf->dol_optimize_smallscreen)) {
2486 print
'<i class="opacitymedium">'.dol_escape_htmltag($example).
'</i>';
2495 print
"<!-- Box end -->\n\n";
2508 $i = count($fieldssource) + 1;
2511 foreach ($listofkey as $key => $val) {
2512 $maxkey = max($maxkey, $key);
2515 while ($i <= $maxkey) {
2516 if (empty($listofkey[$i])) {
2538 if ($position == count($array)) {
2539 $ret = $array + $insertArray;
2542 foreach ($array as $key => $value) {
2543 if ($position == $i++) {
2544 $ret += $insertArray;
2547 $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='')
Make control on an uploaded file from an GUI page and move it to final destination.
dol_count_nb_of_line($file)
Count number of lines in a file.
dol_dir_list($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.
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
img_error($titlealt='default')
Show error logo.
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.
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.
getnewkey(&$fieldssource, &$listofkey)
Return not used field number.
arrayInsert($array, $position, $insertArray)
Return array with element inserted in it at position $position.
show_elem($fieldssource, $pos, $key, $var, $nostyle='')
Function to put the movable box of a source field.
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.