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'));
42$hookmanager->initHooks(array(
'imports'));
50 'invoice_line' =>
'bill',
52 'order_line' =>
'order',
54 'propal_line' =>
'propal',
55 'intervention' =>
'intervention',
56 'inter_line' =>
'intervention',
58 'member_type' =>
'group',
59 'subscription' =>
'payment',
60 'payment' =>
'payment',
62 'tax_type' =>
'generic',
64 'account' =>
'account',
65 'product' =>
'product',
66 'virtualproduct' =>
'product',
67 'subproduct' =>
'product',
68 'product_supplier_ref' =>
'product',
70 'warehouse' =>
'stock',
72 'stockbatch' =>
'stock',
73 'category' =>
'category',
74 'shipment' =>
'sending',
75 'shipment_line' =>
'sending',
76 'reception' =>
'sending',
77 'reception_line' =>
'sending',
78 'expensereport' =>
'trip',
79 'expensereport_line' =>
'trip',
80 'holiday' =>
'holiday',
81 'contract_line' =>
'contract',
82 'translation' =>
'generic',
90 'company' =>
'Company',
91 'contact' =>
'Contact',
93 'invoice_line' =>
'InvoiceLine',
95 'order_line' =>
'OrderLine',
96 'propal' =>
'Proposal',
97 'propal_line' =>
'ProposalLine',
98 'intervention' =>
'Intervention',
99 'inter_line' =>
'InterLine',
100 'member' =>
'Member',
101 'member_type' =>
'MemberType',
102 'subscription' =>
'Subscription',
103 'tax' =>
'SocialContribution',
104 'tax_type' =>
'DictionarySocialContributions',
105 'account' =>
'BankTransactions',
106 'payment' =>
'Payment',
107 'product' =>
'Product',
108 'virtualproduct' =>
'AssociatedProducts',
109 'subproduct' =>
'SubProduct',
110 'product_supplier_ref' =>
'SupplierPrices',
111 'service' =>
'Service',
113 'movement' =>
'StockMovement',
115 'stockbatch' =>
'StockDetailPerBatch',
116 'warehouse' =>
'Warehouse',
117 'category' =>
'Category',
119 'trip' =>
'TripsAndExpenses',
120 'shipment' =>
'Shipments',
121 'shipment_line' =>
'ShipmentLine',
122 'project' =>
'Projects',
123 'projecttask' =>
'Tasks',
124 'task_time' =>
'TaskTimeSpent',
126 'expensereport' =>
'ExpenseReport',
127 'expensereport_line' =>
'ExpenseReportLine',
128 'holiday' =>
'TitreRequestCP',
129 'contract' =>
'Contract',
130 'contract_line' =>
'ContractLine',
131 'translation' =>
'Translation',
133 'bomline' =>
'BOMLine'
136$datatoimport =
GETPOST(
'datatoimport');
138$filetoimport =
GETPOST(
'filetoimport');
139$action =
GETPOST(
'action',
'alpha');
140$confirm =
GETPOST(
'confirm',
'alpha');
142$import_name =
GETPOST(
'import_name');
145$excludefirstline = (
GETPOST(
'excludefirstline') ?
GETPOST(
'excludefirstline') : 2);
146$endatlinenb = (
GETPOST(
'endatlinenb') ?
GETPOST(
'endatlinenb') :
'');
147$updatekeys = (
GETPOST(
'updatekeys',
'array') ?
GETPOST(
'updatekeys',
'array') : array());
148$separator = (
GETPOST(
'separator',
'nohtml') ?
GETPOST(
'separator',
'nohtml', 3) :
'');
149$enclosure = (
GETPOST(
'enclosure',
'nohtml') ?
GETPOST(
'enclosure',
'nohtml') :
'"');
150$charset =
GETPOST(
'charset',
'aZ09');
151$separator_used = str_replace(
'\t',
"\t", $separator);
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 = $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;
186if ($action ==
'deleteprof' && $user->hasRight(
'import',
'run')) {
189 $result = $objimport->delete($user);
194if ($action ==
'add_import_model' && $user->hasRight(
'import',
'run')) {
198 foreach ($array_match_file_to_database as $key => $val) {
202 $hexa .= $key.
'='.$val;
205 $objimport->model_name = $import_name;
206 $objimport->datatoimport = $datatoimport;
207 $objimport->hexa = $hexa;
208 $objimport->fk_user = (
GETPOST(
'visibility',
'aZ09') ==
'all' ? 0 : $user->id);
210 $result = $objimport->create($user);
212 setEventMessages($langs->trans(
"ImportModelSaved", $objimport->model_name),
null,
'mesgs');
215 $langs->load(
"errors");
216 if ($objimport->errno ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
217 setEventMessages($langs->trans(
"ErrorImportDuplicateProfil"),
null,
'errors');
223 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"ImportModelName")),
null,
'errors');
227if ($step == 3 && $datatoimport) {
232 $fullpath = $conf->import->dir_temp.
"/".$nowyearmonth.
'-'.$_FILES[
'userfile'][
'name'];
234 dol_syslog(
"File ".$fullpath.
" was added for import");
236 $langs->load(
"errors");
242 if ($action ==
'confirm_deletefile' && $confirm ==
'yes') {
243 $langs->load(
"other");
245 $param =
'&datatoimport='.urlencode($datatoimport).
'&format='.urlencode($format);
246 if ($excludefirstline) {
247 $param .=
'&excludefirstline='.urlencode($excludefirstline);
250 $param .=
'&endatlinenb='.urlencode($endatlinenb);
253 $file = $conf->import->dir_temp.
'/'.
GETPOST(
'urlfile');
260 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?step='.$step.$param);
265if ($step == 4 && $action ==
'select_model' && $user->hasRight(
'import',
'run')) {
267 $_SESSION[
"dol_array_match_file_to_database"] =
'';
268 $serialized_array_match_file_to_database =
'';
269 $array_match_file_to_database = array();
273 $result = $objimport->fetch($importmodelid);
275 $serialized_array_match_file_to_database = $objimport->hexa;
276 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
277 foreach ($fieldsarray as $elem) {
278 $tabelem = explode(
'=', $elem);
282 $array_match_file_to_database[$key] = $val;
285 $_SESSION[
"dol_array_match_file_to_database"] = $serialized_array_match_file_to_database;
286 $_SESSION[
'dol_array_match_file_to_database_select'] = $_SESSION[
"dol_array_match_file_to_database"];
289if ($action ==
'saveselectorder' && $user->hasRight(
'import',
'run')) {
291 $serialized_array_match_file_to_database =
'';
293 $selectorder = explode(
",",
GETPOST(
'selectorder'));
294 $fieldtarget = $fieldstarget = $objimport->array_import_fields[0];
295 foreach ($selectorder as $key => $code) {
296 $serialized_array_match_file_to_database .= $key.
'='.$code;
297 $serialized_array_match_file_to_database .=
',';
299 $serialized_array_match_file_to_database = substr($serialized_array_match_file_to_database, 0, -1);
300 dol_syslog(
'dol_array_match_file_to_database_select='.$serialized_array_match_file_to_database);
301 $_SESSION[
"dol_array_match_file_to_database_select"] = $serialized_array_match_file_to_database;
311$help_url =
'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones';
314if ($step == 1 || !$datatoimport) {
316 $serialized_array_match_file_to_database =
'';
317 $array_match_file_to_database = array();
318 $_SESSION[
"dol_array_match_file_to_database"] =
'';
319 $_SESSION[
"dol_array_match_file_to_database_select"] =
'';
322 if ($excludefirstline) {
323 $param .=
'&excludefirstline='.urlencode($excludefirstline);
326 $param .=
'&endatlinenb='.urlencode($endatlinenb);
329 $param .=
'&separator='.urlencode($separator);
332 $param .=
'&enclosure='.urlencode($enclosure);
335 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
341 print
'<div class="opacitymedium">'.$langs->trans(
"SelectImportDataSet").
'</div><br>';
344 print
'<div class="div-table-responsive-no-min">';
345 print
'<table class="noborder centpercent">';
346 print
'<tr class="liste_titre">';
347 print
'<td>'.$langs->trans(
"Module").
'</td>';
348 print
'<td>'.$langs->trans(
"ImportableDatas").
'</td>';
349 print
'<td> </td>';
352 if (count($objimport->array_import_module)) {
353 $sortedarrayofmodules =
dol_sort_array($objimport->array_import_module,
'position_of_profile',
'asc', 0, 0, 1);
354 foreach ($sortedarrayofmodules as $key => $value) {
356 print
'<tr class="oddeven"><td>';
357 $titleofmodule = $objimport->array_import_module[$key][
'module']->getName();
359 if (in_array($objimport->array_import_code[$key], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
360 $titleofmodule = $langs->trans(
"ProductOrService");
362 print $titleofmodule;
364 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[$key]);
365 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
366 print
img_object($objimport->array_import_module[$key][
'module']->getName(), $entityicon).
' ';
367 print $objimport->array_import_label[$key];
368 print
'</td><td style="text-align: right">';
369 if ($objimport->array_import_perms[$key]) {
370 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>';
372 print $langs->trans(
"NotEnoughPermissions");
377 print
'<tr><td class="oddeven" colspan="3">'.$langs->trans(
"NoImportableData").
'</td></tr>';
387if ($step == 2 && $datatoimport) {
388 $param =
'&datatoimport='.urlencode($datatoimport);
389 if ($excludefirstline) {
390 $param .=
'&excludefirstline='.urlencode($excludefirstline);
393 $param .=
'&endatlinenb='.urlencode($endatlinenb);
396 $param .=
'&separator='.urlencode($separator);
399 $param .=
'&enclosure='.urlencode($enclosure);
402 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
408 print
'<div class="underbanner clearboth"></div>';
409 print
'<div class="fichecenter">';
411 print
'<table class="border tableforfield centpercent">';
414 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
416 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
418 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
419 $titleofmodule = $langs->trans(
"ProductOrService");
421 print $titleofmodule;
425 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
427 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
428 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
429 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
430 print $objimport->array_import_label[0];
438 print
'<form name="userfile" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" METHOD="POST">';
439 print
'<input type="hidden" name="token" value="'.newToken().
'">';
443 print
'<span class="opacitymedium">';
444 $s = $langs->trans(
"ChooseFormatOfFileToImport",
'{s1}');
445 $s = str_replace(
'{s1}',
img_picto(
'',
'next'), $s);
447 print
'</span><br><br>';
451 print
'<div class="div-table-responsive-no-min">';
452 print
'<table class="noborder centpercent" cellpadding="4">';
457 print
'<tr class="liste_titre"><td colspan="5">';
458 print $langs->trans(
"FileMustHaveOneOfFollowingFormat");
460 $list = $objmodelimport->listOfAvailableImportFormat($db);
461 foreach ($list as $key) {
462 print
'<tr class="oddeven">';
463 print
'<td width="16">'.img_picto_common($key, $objmodelimport->getPictoForKey($key)).
'</td>';
464 $htmltext = $objmodelimport->getDriverDescForKey($key);
465 print
'<td>'.$form->textwithpicto($objmodelimport->getDriverLabelForKey($key), $htmltext).
'</td>';
466 print
'<td style="text-align:center">';
467 if (empty($objmodelimport->drivererror[$key])) {
468 $filename = $langs->transnoentitiesnoconv(
"ExampleOfImportFile").
'_'.$datatoimport.
'.'.$key;
469 print
'<a href="'.DOL_URL_ROOT.
'/imports/emptyexample.php?format='.$key.$param.
'&output=file&file='.urlencode($filename).
'" target="_blank" rel="noopener noreferrer">';
470 print
img_picto(
'',
'download',
'class="paddingright opacitymedium"');
471 print $langs->trans(
"DownloadEmptyExampleShort");
473 print $form->textwithpicto(
'', $langs->trans(
"DownloadEmptyExample").
'.<br>'.$langs->trans(
"StarAreMandatory"));
479 print
'<td style="text-align:right">';
480 if (empty($objmodelimport->drivererror[$key])) {
481 print
'<a href="'.DOL_URL_ROOT.
'/imports/import.php?step=3&format='.$key.$param.
'">'.
img_picto($langs->trans(
"SelectFormat"),
'next',
'class="fa-15"').
'</a>';
495if ($step == 3 && $datatoimport) {
496 $param =
'&datatoimport='.urlencode($datatoimport).
'&format='.urlencode($format);
497 if ($excludefirstline) {
498 $param .=
'&excludefirstline='.urlencode($excludefirstline);
501 $param .=
'&endatlinenb='.urlencode($endatlinenb);
504 $param .=
'&separator='.urlencode($separator);
507 $param .=
'&enclosure='.urlencode($enclosure);
510 $list = $objmodelimport->listOfAvailableImportFormat($db);
512 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
521 if ($action ==
'delete') {
522 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?urlfile='.urlencode(
GETPOST(
'urlfile')).
'&step=3'.$param, $langs->trans(
'DeleteFile'), $langs->trans(
'ConfirmDeleteFile'),
'confirm_deletefile',
'', 0, 1);
525 print
'<div class="underbanner clearboth"></div>';
526 print
'<div class="fichecenter">';
528 print
'<table class="border tableforfield centpercent">';
531 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
533 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
535 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
536 $titleofmodule = $langs->trans(
"ProductOrService");
538 print $titleofmodule;
542 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
544 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
545 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
546 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
547 print $objimport->array_import_label[0];
553 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
555 print
'<div class="underbanner clearboth"></div>';
556 print
'<div class="fichecenter">';
557 print
'<table width="100%" class="border tableforfield">';
560 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
561 print
'<td class="nowraponall">';
562 $text = $objmodelimport->getDriverDescForKey($format);
564 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
565 print
'</td><td style="text-align:right" class="nowrap">';
566 $filename = $langs->transnoentitiesnoconv(
"ExampleOfImportFile").
'_'.$datatoimport.
'.'.$format;
567 print
'<a href="'.DOL_URL_ROOT.
'/imports/emptyexample.php?format='.$format.$param.
'&output=file&file='.urlencode($filename).
'" target="_blank" rel="noopener noreferrer">';
568 print
img_picto(
'',
'download',
'class="paddingright opacitymedium"');
569 print $langs->trans(
"DownloadEmptyExampleShort");
571 print $form->textwithpicto(
'', $langs->trans(
"DownloadEmptyExample").
'.<br>'.$langs->trans(
"StarAreMandatory"));
580 if ($format ==
'xlsx' && !class_exists(
'XMLWriter')) {
581 $langs->load(
"install");
582 print
info_admin($langs->trans(
"ErrorPHPDoesNotSupport",
'php-xml'), 0, 0,
'1',
'error');
588 print
'<form name="userfile" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="POST">';
589 print
'<input type="hidden" name="token" value="'.newToken().
'">';
590 print
'<input type="hidden" value="'.$step.
'" name="step">';
591 print
'<input type="hidden" value="'.dol_escape_htmltag($format).
'" name="format">';
592 print
'<input type="hidden" value="'.$excludefirstline.
'" name="excludefirstline">';
593 print
'<input type="hidden" value="'.$endatlinenb.
'" name="endatlinenb">';
594 print
'<input type="hidden" value="'.dol_escape_htmltag($separator).
'" name="separator">';
595 print
'<input type="hidden" value="'.dol_escape_htmltag($enclosure).
'" name="enclosure">';
596 print
'<input type="hidden" value="'.dol_escape_htmltag($datatoimport).
'" name="datatoimport">';
598 print
'<span class="opacitymedium">';
599 $s = $langs->trans(
"ChooseFileToImport",
'{s1}');
600 $s = str_replace(
'{s1}',
img_picto(
'',
'next'), $s);
602 print
'</span><br><br>';
607 print
'<div class="marginbottomonly">';
609 $maxmin = $maxfilesizearray[
'maxmin'];
611 print
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
613 print
'<input type="file" name="userfile" size="20" maxlength="80"> ';
615 print
'<input type="submit" class="button small" value="'.$langs->trans(
"AddFile").
'"'.$out.
' name="sendit">';
619 $maxphp = @ini_get(
'upload_max_filesize');
620 if (preg_match(
'/k$/i', $maxphp)) {
621 $maxphp = (int) substr($maxphp, 0, -1);
623 if (preg_match(
'/m$/i', $maxphp)) {
624 $maxphp = (int) substr($maxphp, 0, -1) * 1024;
626 if (preg_match(
'/g$/i', $maxphp)) {
627 $maxphp = (int) substr($maxphp, 0, -1) * 1024 * 1024;
629 if (preg_match(
'/t$/i', $maxphp)) {
630 $maxphp = (int) substr($maxphp, 0, -1) * 1024 * 1024 * 1024;
632 $maxphp2 = @ini_get(
'post_max_size');
633 if (preg_match(
'/k$/i', $maxphp2)) {
634 $maxphp2 = (int) substr($maxphp2, 0, -1);
636 if (preg_match(
'/m$/i', $maxphp2)) {
637 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024;
639 if (preg_match(
'/g$/i', $maxphp2)) {
640 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024 * 1024;
642 if (preg_match(
'/t$/i', $maxphp2)) {
643 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024 * 1024 * 1024;
647 $maxphptoshow = $maxphptoshowparam =
'';
649 $maxmin = min($max, $maxphp);
650 $maxphptoshow = $maxphp;
651 $maxphptoshowparam =
'upload_max_filesize';
654 $maxmin = min($max, $maxphp2);
655 if ($maxphp2 < $maxphp) {
656 $maxphptoshow = $maxphp2;
657 $maxphptoshowparam =
'post_max_size';
661 $langs->load(
'other');
663 $out .=
info_admin($langs->trans(
"ThisLimitIsDefinedInSetup", $max, $maxphptoshow), 1);
665 $out .=
' ('.$langs->trans(
"UploadDisabled").
')';
671 $filearray =
dol_dir_list($conf->import->dir_temp,
'files', 0,
'',
'',
'name', SORT_DESC);
672 if (count($filearray) > 0) {
673 print
'<div class="div-table-responsive-no-min">';
674 print
'<table class="noborder centpercent" width="100%" cellpadding="4">';
676 $dir = $conf->import->dir_temp;
680 foreach ($filearray as $key => $val) {
681 $file = $val[
'name'];
685 $file = mb_convert_encoding($file,
'UTF-8',
'ISO-8859-1');
688 if (preg_match(
'/^\./', $file)) {
692 $modulepart =
'import';
693 $urlsource = $_SERVER[
"PHP_SELF"].
'?step='.$step.$param.
'&filetoimport='.urlencode($filetoimport);
694 $relativepath = $file;
696 print
'<tr class="oddeven">';
698 print
img_mime($file,
'',
'pictofixedwidth');
699 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=3'.$param.
'" target="_blank" rel="noopener noreferrer">';
704 print
'<td style="text-align:right">'.dol_print_size(
dol_filesize($dir.
'/'.$file)).
'</td>';
706 print
'<td style="text-align:right">'.dol_print_date(
dol_filemtime($dir.
'/'.$file),
'dayhour').
'</td>';
708 print
'<td style="text-align:right"><a href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.
newToken().
'&step=3'.$param.
'&urlfile='.urlencode($relativepath);
709 print
'">'.img_delete().
'</a></td>';
711 print
'<td style="text-align:right">';
712 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?step=4'.$param.
'&filetoimport='.urlencode($relativepath).
'">'.
img_picto($langs->trans(
"NewImport"),
'next',
'class="fa-15"').
'</a>';
726if ($step == 4 && $datatoimport) {
728 $serialized_array_match_file_to_database = isset($_SESSION[
"dol_array_match_file_to_database_select"]) ? $_SESSION[
"dol_array_match_file_to_database_select"] :
'';
729 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
730 $array_match_file_to_database = array();
731 foreach ($fieldsarray as $elem) {
732 $tabelem = explode(
'=', $elem, 2);
734 $val = (isset($tabelem[1]) ? $tabelem[1] :
'');
736 $array_match_file_to_database[$key] = $val;
745 $list = $objmodelimport->listOfAvailableImportFormat($db);
747 if (empty($separator)) {
748 $separator = (!
getDolGlobalString(
'IMPORT_CSV_SEPARATOR_TO_USE') ?
',' : $conf->global->IMPORT_CSV_SEPARATOR_TO_USE);
752 if ($model ==
'csv' && strlen($separator) == 1 && !GETPOSTISSET(
'separator')) {
753 '@phan-var-force ImportCsv $obj';
755 $fh = fopen($conf->import->dir_temp.
'/'.$filetoimport,
'r');
757 $sline = fgets($fh, 1000000);
759 $nboccurence = substr_count($sline, $separator);
760 $nboccurencea = substr_count($sline,
',');
761 $nboccurenceb = substr_count($sline,
';');
763 if ($nboccurence == 0) {
764 if ($nboccurencea > 2) {
766 } elseif ($nboccurenceb > 2) {
774 $separator_used = str_replace(
'\t',
"\t", $separator);
777 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
778 $file =
"import_".$model.
".modules.php";
779 $classname =
"Import".ucfirst($model);
780 require_once $dir.$file;
781 $obj =
new $classname($db, $datatoimport);
782 '@phan-var-force ModeleImports $obj';
783 if ($model ==
'csv') {
784 '@phan-var-force ImportCsv $obj';
785 $obj->separator = $separator_used;
786 $obj->enclosure = $enclosure;
789 if ($model ==
'xlsx') {
790 '@phan-var-force ImportXlsx $obj';
791 if (!preg_match(
'/\.xlsx$/i', $filetoimport)) {
792 $langs->load(
"errors");
793 $param =
'&datatoimport='.$datatoimport.
'&format='.$format;
794 setEventMessages($langs->trans(
"ErrorFileMustHaveFormat", $model),
null,
'errors');
795 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?step=3'.$param.
'&filetoimport='.urlencode($relativepath));
801 $array_match_file_to_database = array();
805 $fieldssource = array();
807 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport);
810 $arrayrecord = $obj->import_read_record();
814 foreach ($arrayrecord as $key => $val) {
815 if ($val[
"type"] != -1) {
816 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 128);
819 $fieldssource[$i][
'example1'] = $langs->trans(
'Empty');
822 $fieldssource[$i][
'imported'] = 0;
824 $obj->import_close_file();
828 $fieldstarget = $objimport->array_import_fields[0];
829 $minpos = min(count($fieldssource), count($fieldstarget));
833 $initialloadofstep4 =
false;
834 if (empty($_SESSION[
'dol_array_match_file_to_database_select'])) {
835 $initialloadofstep4 =
true;
839 if (count($array_match_file_to_database) == 0) {
845 $num = count($fieldssource);
846 while ($pos <= $num) {
847 if ($num >= 1 && $pos <= $num) {
849 foreach ($fieldstarget as $key => $val) {
850 if ($posbis < $pos) {
855 $array_match_file_to_database[$pos] = $key;
862 $array_match_database_to_file = array_flip($array_match_file_to_database);
866 $fieldstarget_tmp = array();
867 $arraykeysfieldtarget = array_keys($fieldstarget);
869 foreach ($fieldstarget as $key => $label) {
870 $isrequired = preg_match(
'/\*$/', $label);
871 if (!empty($isrequired)) {
872 $newlabel = substr($label, 0, -1);
873 $fieldstarget_tmp[$key] = array(
"label" => $newlabel,
"required" =>
true);
875 $fieldstarget_tmp[$key] = array(
"label" => $label,
"required" =>
false);
877 if (!empty($array_match_database_to_file[$key])) {
878 $fieldstarget_tmp[$key][
"imported"] =
true;
879 $fieldstarget_tmp[$key][
"position"] = $array_match_database_to_file[$key] - 1;
881 while (!empty($array_match_database_to_file[$keytoswap])) {
882 if ($position + 1 > $array_match_database_to_file[$keytoswap]) {
883 $keytoswapwith = $array_match_database_to_file[$keytoswap] - 1;
884 $tmp = [$keytoswap => $fieldstarget_tmp[$keytoswap]];
885 unset($fieldstarget_tmp[$keytoswap]);
886 $fieldstarget_tmp =
arrayInsert($fieldstarget_tmp, $keytoswapwith, $tmp);
887 $keytoswapwith = $arraykeysfieldtarget[$array_match_database_to_file[$keytoswap] - 1];
888 $tmp = $fieldstarget_tmp[$keytoswapwith];
889 unset($fieldstarget_tmp[$keytoswapwith]);
890 $fieldstarget_tmp[$keytoswapwith] = $tmp;
891 $keytoswap = $keytoswapwith;
897 $fieldstarget_tmp[$key][
"imported"] =
false;
901 $fieldstarget = $fieldstarget_tmp;
910 $param =
'&format='.$format.
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport);
911 if ($excludefirstline) {
912 $param .=
'&excludefirstline='.urlencode($excludefirstline);
915 $param .=
'&endatlinenb='.urlencode($endatlinenb);
918 $param .=
'&separator='.urlencode($separator);
921 $param .=
'&enclosure='.urlencode($enclosure);
924 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
930 print
'<div class="underbanner clearboth"></div>';
931 print
'<div class="fichecenter">';
933 print
'<table class="centpercent border tableforfield">';
936 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
938 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
940 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
941 $titleofmodule = $langs->trans(
"ProductOrService");
943 print $titleofmodule;
947 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
949 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
950 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
951 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
952 print $objimport->array_import_label[0];
958 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
960 print
'<div class="underbanner clearboth"></div>';
961 print
'<div class="fichecenter">';
962 print
'<table width="100%" class="border tableforfield">';
965 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
967 $text = $objmodelimport->getDriverDescForKey($format);
969 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
973 if ($model ==
'csv') {
974 '@phan-var-force ImportCsv $obj';
975 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
977 print
'<form method="POST">';
978 print
'<input type="hidden" name="token" value="'.newToken().
'">';
979 print
'<input type="hidden" value="'.$step.
'" name="step">';
980 print
'<input type="hidden" value="'.$format.
'" name="format">';
981 print
'<input type="hidden" value="'.$excludefirstline.
'" name="excludefirstline">';
982 print
'<input type="hidden" value="'.$endatlinenb.
'" name="endatlinenb">';
983 print
'<input type="hidden" value="'.$datatoimport.
'" name="datatoimport">';
984 print
'<input type="hidden" value="'.$filetoimport.
'" name="filetoimport">';
985 print $langs->trans(
"Separator").
' : ';
986 print
'<input type="text" class="width25 center" name="separator" value="'.dol_escape_htmltag($separator).
'"/>';
987 print
' '.$langs->trans(
"Enclosure").
' : ';
988 print
'<input type="text" class="width25 center" name="enclosure" value="'.dol_escape_htmltag($enclosure).
'"/> ';
989 print
'<input name="update" type="submit" value="'.$langs->trans(
'Update').
'" class="button smallpaddingimp" />';
995 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
997 $modulepart =
'import';
998 $relativepath =
GETPOST(
'filetoimport');
999 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
1000 print
img_mime($file,
'',
'pictofixedwidth');
1001 print $filetoimport;
1002 print
img_picto($langs->trans(
"Download"),
'download',
'class="paddingleft opacitymedium"');
1015 print
'<!-- List of source fields -->'.
"\n";
1016 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1017 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1018 print
'<input type="hidden" name="action" value="select_model">';
1019 print
'<input type="hidden" name="step" value="4">';
1020 print
'<input type="hidden" name="format" value="'.$format.
'">';
1021 print
'<input type="hidden" name="datatoimport" value="'.$datatoimport.
'">';
1022 print
'<input type="hidden" name="filetoimport" value="'.$filetoimport.
'">';
1023 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1024 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1025 print
'<input type="hidden" name="separator" value="'.dol_escape_htmltag($separator).
'">';
1026 print
'<input type="hidden" name="enclosure" value="'.dol_escape_htmltag($enclosure).
'">';
1029 print
'<div class="marginbottomonly">';
1030 print
'<span class="opacitymedium">';
1031 $s = $langs->trans(
"SelectImportFieldsSource",
'{s1}');
1032 $s = str_replace(
'{s1}',
img_picto(
'',
'grip_title',
'', 0, 0, 0,
'',
'', 0), $s);
1035 $htmlother->select_import_model($importmodelid,
'importmodelid', $datatoimport, 1, $user->id);
1036 print
'<input type="submit" class="button small reposition" value="'.$langs->trans(
"Select").
'">';
1041 print
'<div class="div-table-responsive-no-min">';
1042 print
'<table class="noborder centpercent">';
1043 print
'<tr class="liste_titre">';
1044 print
'<td>'.$langs->trans(
"FieldsInSourceFile").
'</td>';
1045 print
'<td>'.$langs->trans(
"FieldsInTargetDatabase").
'</td>';
1050 print
'<tr valign="top"><td width="50%" class="nopaddingleftimp">';
1052 $fieldsplaced = array();
1053 $valforsourcefieldnb = array();
1054 $listofkeys = array();
1055 foreach ($array_match_file_to_database as $key => $val) {
1056 $listofkeys[$key] = 1;
1059 print
"\n<!-- Box left container -->\n";
1060 print
'<div id="left" class="connectedSortable">'.
"\n";
1065 foreach ($fieldssource as $key => $val) {
1068 $listofkeys[$key] = 1;
1069 $fieldsplaced[$key] = 1;
1070 $valforsourcefieldnb[$lefti] = $key;
1080 print
"<!-- End box left container -->\n";
1083 print
'</td><td width="50%" class="nopaddingrightimp">';
1087 $optionsall = array();
1088 foreach ($fieldstarget as $code => $line) {
1089 $tmparray = explode(
'|', $line[
"label"]);
1091 foreach ($tmparray as $tmpkey => $tmpval) {
1092 $labeltoshow .= ($labeltoshow ?
' '.$langs->trans(
'or').
' ' :
'').$langs->transnoentities($tmpval);
1097 $optionsall[$code] = array(
1098 'labelkey' => $line[
'label'],
1099 'labelkeyarray' => $tmparray,
1100 'label' => $labeltoshow,
1101 'required' => (empty($line[
"required"]) ? 0 : 1),
1102 'position' => (!empty($line[
'position']) ? $line[
'position'] : 0),
1110 $mandatoryfieldshavesource =
true;
1123 $modetoautofillmapping =
'session';
1124 if ($initialloadofstep4) {
1125 $modetoautofillmapping =
'guess';
1129 print
'<table class="nobordernopadding centpercent tableimport">';
1130 foreach ($fieldssource as $code => $line) {
1134 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
1136 $entity = (!empty($objimport->array_import_entities[0][$code]) ? $objimport->array_import_entities[0][$code] : $objimport->array_import_icon[0]);
1138 $entityicon = !empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity;
1139 $entitylang = !empty($entitytolang[$entity]) ? $entitytolang[$entity] : $objimport->array_import_label[0];
1141 print
'<td class="nowraponall hideonsmartphone" style="font-weight: normal">=> </td>';
1142 print
'<td class="nowraponall" style="font-weight: normal">';
1144 $selectforline =
'';
1145 $selectforline .=
'<select id="selectorderimport_'.($i + 1).
'" class="targetselectchange minwidth300" name="select_'.($i + 1).
'">';
1146 if (!empty($line[
"imported"])) {
1147 $selectforline .=
'<option value="-1"> </option>';
1149 $selectforline .=
'<option selected="" value="-1"> </option>';
1153 $codeselectedarray = array();
1154 foreach ($optionsall as $tmpcode => $tmpval) {
1156 if (!empty($tmpval[
'picto'])) {
1157 $label .=
img_picto(
'', $tmpval[
'picto'],
'class="pictofixedwidth"');
1159 $label .= $tmpval[
'required'] ?
'<strong>' :
'';
1160 $label .= $tmpval[
'label'];
1161 $label .= $tmpval[
'required'] ?
'*</strong>' :
'';
1163 $tablealias = preg_replace(
'/(\..*)$/i',
'', $tmpcode);
1164 $tablename = !empty($objimport->array_import_tables[0][$tablealias]) ? $objimport->array_import_tables[0][$tablealias] :
"";
1168 $filecolumn = ($i + 1);
1170 if (empty($objimport->array_import_convertvalue[0][$tmpcode])) {
1173 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromref') {
1174 $htmltext .= $langs->trans(
"DataComeFromIdFoundFromRef", $langs->transnoentitiesnoconv($entitylang)).
'<br>';
1176 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromcodeid') {
1177 $htmltext .= $langs->trans(
"DataComeFromIdFoundFromCodeId", $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$tmpcode][
'dict'])).
'<br>';
1181 $example = !empty($objimport->array_import_examplevalues[0][$tmpcode]) ? $objimport->array_import_examplevalues[0][$tmpcode] :
"";
1183 if (empty($objimport->array_import_convertvalue[0][$tmpcode])) {
1185 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.str_replace(
'"',
'', $example).
'</b><br>';
1188 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromref') {
1189 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.$langs->transnoentitiesnoconv(
"ExampleAnyRefFoundIntoElement", $entitylang).($example ?
' ('.$langs->transnoentitiesnoconv(
"Example").
': '.str_replace(
'"',
'', $example).
')' :
'').
'</b><br>';
1190 } elseif ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromcodeid') {
1191 $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>';
1192 } elseif ($example) {
1193 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.str_replace(
'"',
'', $example).
'</b><br>';
1197 if (!empty($objimport->array_import_regex[0][$tmpcode])) {
1198 $htmltext .= $langs->trans(
"FormatControlRule").
': <b>'.str_replace(
'"',
'', $objimport->array_import_regex[0][$tmpcode]).
'</b><br>';
1202 $htmltext .= $langs->trans(
"InformationOnTargetTables").
': <b>'.$tablename.
"->".preg_replace(
'/^.*\./',
'', $tmpcode).
"</b>";
1204 $labelhtml = $label.
' '.$form->textwithpicto(
'', $htmltext, 1,
'help',
'', 1);
1206 $selectforline .=
'<option value="'.$tmpcode.
'"';
1207 if ($modetoautofillmapping ==
'orderoftargets') {
1210 $selectforline .=
' selected';
1212 } elseif ($modetoautofillmapping ==
'guess') {
1216 if (preg_match(
'/^(.+)\((.+\..+)\)$/', $line[
'example1'], $regs)) {
1217 $tmpstring1 = $regs[1];
1218 $tmpstring2 = $regs[2];
1220 $tmpstring1 = $line[
'example1'];
1228 foreach ($tmpval[
'labelkeyarray'] as $tmpval2) {
1229 $labeltarget = $langs->transnoentities($tmpval2);
1231 if ($tmpstring1 && ($tmpstring1 == $tmpcode || $tmpstring1 == strtolower($labeltarget)
1232 || $tmpstring1 == strtolower(
dol_string_unaccent($labeltarget)) || $tmpstring1 == strtolower($tmpval2))) {
1233 if (empty($codeselectedarray[$code])) {
1234 $selectforline .=
' selected';
1235 $codeselectedarray[$code] = 1;
1238 } elseif ($tmpstring2 && ($tmpstring2 == $tmpcode || $tmpstring2 == strtolower($labeltarget)
1239 || $tmpstring2 == strtolower(
dol_string_unaccent($labeltarget)) || $tmpstring2 == strtolower($tmpval2))) {
1240 if (empty($codeselectedarray[$code])) {
1241 $selectforline .=
' selected';
1242 $codeselectedarray[$code] = 1;
1247 } elseif ($modetoautofillmapping ==
'session' && !empty($_SESSION[
'dol_array_match_file_to_database_select'])) {
1248 $tmpselectioninsession =
dolExplodeIntoArray($_SESSION[
'dol_array_match_file_to_database_select'],
',',
'=');
1250 if (!empty($tmpselectioninsession[(
string) ($i + 1)]) && $tmpselectioninsession[(
string) ($i + 1)] == $tmpcode) {
1251 $selectforline .=
' selected';
1253 $selectforline .=
' data-debug="'.$tmpcode.
'-'.$code.
'-'.$j.
'-'.(!empty($tmpselectioninsession[(
string) ($i + 1)]) ? $tmpselectioninsession[(string) ($i + 1)] :
"").
'"';
1255 $selectforline .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
1256 $selectforline .=
'>';
1257 $selectforline .= $label;
1258 $selectforline .=
'</options>';
1261 $selectforline .=
'</select>';
1262 $selectforline .=
ajax_combobox(
'selectorderimport_'.($i + 1));
1264 print $selectforline;
1269 print
'<td class="nowraponall" style="font-weight:normal; text-align:right">';
1272 $htmltext =
'<b><u>'.$langs->trans(
"FieldSource").
'</u></b><br>';
1274 $htmltext .= $langs->trans(
"DataComeFromFileFieldNb", $filecolumntoshow).
'<br>';
1276 print $form->textwithpicto(
'', $htmltext);
1287 print
'<tr class="liste_titre"><td colspan="2">'.$langs->trans(
"Note").
'</td></tr>';
1288 print
'<tr><td colspan="2"><div id="div-mandatory-target-fields-not-mapped"></div></td></tr>';
1294 if (!empty($conf->use_javascript_ajax)) {
1295 print
'<script type="text/javascript">'.
"\n";
1296 print
'var previousselectedvalueimport = "0";'.
"\n";
1297 print
'var previousselectedlabelimport = "0";'.
"\n";
1298 print
'var arrayofselectedvalues = [];'.
"\n";
1299 print
'var arrayoftargetfields = [];'.
"\n";
1300 print
'var arrayoftargetmandatoryfields = [];'.
"\n";
1304 foreach ($fieldstarget as $key => $val) {
1305 print
"arrayoftargetfields[".$tmpi.
"] = '".
dol_escape_js($langs->trans($val[
'label'])).
"'; ";
1306 if ($val[
'required']) {
1307 print
"arrayoftargetmandatoryfields[".$tmpi.
"] = '".
dol_escape_js($key).
"'; ";
1313 print
'$(document).ready(function () {'.
"\n";
1315 print
'setOptionsToDisabled();'.
"\n";
1316 print
'saveSelection();'.
"\n";
1318 print
'$(".targetselectchange").focus(function(){'.
"\n";
1319 print
' previousselectedvalueimport = $(this).val();'.
"\n";
1320 print
' previousselectedlabelimport = $(this).children("option:selected").text();'.
"\n";
1321 print
' console.log("previousselectedvalueimport="+previousselectedvalueimport)'.
"\n";
1328 print
'function setOptionsToDisabled() {'.
"\n";
1329 print
' console.log("Remove the disabled flag everywhere");'.
"\n";
1330 print
' $("select.targetselectchange").not($( this )).find(\'option\').prop("disabled", false);'.
"\n";
1331 print
' arrayofselectedvalues = [];'.
"\n";
1333 print
' $("select.targetselectchange").each(function(){'.
"\n";
1334 print
' id = $(this).attr(\'id\')'.
"\n";
1335 print
' value = $(this).val()'.
"\n";
1336 print
' console.log("a selected value has been found for component "+id+" = "+value);'.
"\n";
1337 print
' arrayofselectedvalues.push(value);'.
"\n";
1340 print
' console.log("List of all selected values arrayofselectedvalues");'.
"\n";
1341 print
' console.log(arrayofselectedvalues);'.
"\n";
1342 print
' console.log("Set the option to disabled for every entry that is currently selected somewhere else (so into arrayofselectedvalues)");'.
"\n";
1344 print
' $.each(arrayofselectedvalues, function(key, value) {'.
"\n";
1345 print
' if (value != -1) {'.
"\n";
1346 print
' console.log("Process key="+key+" value="+value+" to disable.");'.
"\n";
1347 print
' $("select.targetselectchange").find(\'option[value="\'+value+\'"]:not(:selected)\').prop("disabled", true);'.
"\n";
1353 print
'function saveSelection() {'.
"\n";
1355 print
' arrayselectedfields = [];'.
"\n";
1356 print
' arrayselectedfields.push(0);'.
"\n";
1358 print
' $.each( arrayofselectedvalues, function( key, value ) {'.
"\n";
1359 print
' if (value != -1) {'.
"\n";
1360 print
' arrayselectedfields.push(value);'.
"\n";
1361 print
' } else {'.
"\n";
1362 print
' arrayselectedfields.push(0);'.
"\n";
1366 print
" $.ajax({\n";
1367 print
" type: 'POST',\n";
1368 print
" dataType: 'json',\n";
1369 print
" url: '".dol_escape_js($_SERVER[
"PHP_SELF"]).
"?action=saveselectorder&token=".
newToken().
"',\n";
1370 print
" data: 'selectorder='+arrayselectedfields.toString(),\n";
1371 print
" success: function(){\n";
1372 print
" console.log('The selected fields have been saved into '+arrayselectedfields.toString());\n";
1377 print
' console.log("arrayselectedfields");';
1378 print
' console.log(arrayselectedfields);';
1379 print
' console.log("arrayoftargetmandatoryfields");';
1380 print
' console.log(arrayoftargetmandatoryfields);';
1381 print
" listtoshow = '';";
1382 print
" nbelement = arrayoftargetmandatoryfields.length
1383 for (let i = 0; i < nbelement; i++) {
1384 if (arrayoftargetmandatoryfields[i] && ! arrayselectedfields.includes(arrayoftargetmandatoryfields[i])) {
1385 console.log(arrayoftargetmandatoryfields[i]+' not mapped');
1386 listtoshow = listtoshow + (listtoshow ? ', ' : '') + '<b>' + arrayoftargetfields[i] + '*</b>';
1389 console.log(listtoshow);
1391 listtoshow = '".dol_escape_js(
img_warning($langs->trans(
"MandatoryTargetFieldsNotMapped")).
' '.$langs->trans(
"MandatoryTargetFieldsNotMapped")).
": ' + listtoshow;
1392 $('#div-mandatory-target-fields-not-mapped').html(listtoshow);
1394 $('#div-mandatory-target-fields-not-mapped').html('<span class=\"opacitymedium\">".
dol_escape_js($langs->trans(
"AllTargetMandatoryFieldsAreMapped")).
"</span>');
1401 print
'$(".targetselectchange").change(function(){'.
"\n";
1402 print
' setOptionsToDisabled();'.
"\n";
1404 print
' if(previousselectedlabelimport != "" && previousselectedvalueimport != -1) {'.
"\n";
1405 print
' let valuetochange = $(this).val(); '.
"\n";
1406 print
' $(".boxtdunused").each(function(){'.
"\n";
1407 print
' if ($(this).text().includes(valuetochange)){'.
"\n";
1408 print
' arraychild = $(this)[0].childNodes'.
"\n";
1409 print
' arraytexttomodify = arraychild[0].textContent.split(" ")'.
"\n";
1410 print
' arraytexttomodify[1] = previousselectedvalueimport '.
"\n";
1411 print
' textmodified = arraytexttomodify.join(" ") '.
"\n";
1412 print
' arraychild[0].textContent = textmodified'.
"\n";
1413 print
' arraychild[1].innerHTML = previousselectedlabelimport'.
"\n";
1417 print
' $(this).blur()'.
"\n";
1419 print
' saveSelection()'.
"\n";
1423 print
'</script>'.
"\n";
1429 print
'<div class="tabsAction">';
1431 if (count($array_match_file_to_database)) {
1432 if ($mandatoryfieldshavesource) {
1433 print
'<a class="butAction saveorderselect" href="import.php?step=5'.$param.
'&filetoimport='.urlencode($filetoimport).
'">'.$langs->trans(
"NextStep").
'</a>';
1435 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"SomeMandatoryFieldHaveNoSource")).
'">'.$langs->trans(
"NextStep").
'</a>';
1443 if (count($array_match_file_to_database)) {
1445 print
'<!-- Area to add new import profile -->'.
"\n";
1446 print
'<div class="marginbottomonly"><span class="opacitymedium">'.$langs->trans(
"SaveImportModel").
'</span></div>';
1448 print
'<form class="nocellnopadd" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1449 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1450 print
'<input type="hidden" name="action" value="add_import_model">';
1451 print
'<input type="hidden" name="step" value="'.$step.
'">';
1452 print
'<input type="hidden" name="format" value="'.$format.
'">';
1453 print
'<input type="hidden" name="datatoimport" value="'.$datatoimport.
'">';
1454 print
'<input type="hidden" name="filetoimport" value="'.$filetoimport.
'">';
1455 print
'<input type="hidden" name="hexa" value="'.$hexa.
'">';
1456 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1457 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1458 print
'<input type="hidden" name="page_y" value="">';
1459 print
'<input type="hidden" value="'.dol_escape_htmltag($separator).
'" name="separator">';
1460 print
'<input type="hidden" value="'.dol_escape_htmltag($enclosure).
'" name="enclosure">';
1462 print
'<div class="div-table-responsive-no-min">';
1463 print
'<table summary="selectofimportprofil" class="noborder centpercent">';
1464 print
'<tr class="liste_titre">';
1465 print
'<td>'.$langs->trans(
"ImportModelName").
'</td>';
1466 print
'<td>'.$langs->trans(
"Visibility").
'</td>';
1470 $nameofimportprofile = str_replace(
' ',
'-', $langs->trans(
"ImportProfile").
' '.$titleofmodule.
' '.
dol_print_date(
dol_now(
'gmt'),
'dayxcard'));
1472 $nameofimportprofile = $import_name;
1475 print
'<tr class="oddeven">';
1476 print
'<td><input name="import_name" class="minwidth300" value="'.$nameofimportprofile.
'"></td>';
1478 $arrayvisibility = array(
'private' => $langs->trans(
"Private"),
'all' => $langs->trans(
"Everybody"));
1479 print $form->selectarray(
'visibility', $arrayvisibility,
'private');
1481 print
'<td class="right">';
1482 print
'<input type="submit" class="button smallpaddingimp reposition" value="'.$langs->trans(
"SaveImportProfile").
'">';
1486 $sql =
"SELECT rowid, label, fk_user, entity";
1487 $sql .=
" FROM ".MAIN_DB_PREFIX.
"import_model";
1488 $sql .=
" WHERE type = '".$db->escape($datatoimport).
"'";
1490 $sql .=
" AND fk_user IN (0, ".((int) $user->id).
")";
1492 $sql .=
" ORDER BY rowid";
1494 $resql = $db->query($sql);
1496 $num = $db->num_rows($resql);
1498 $tmpuser =
new User($db);
1502 $obj = $db->fetch_object($resql);
1504 print
'<tr class="oddeven"><td>';
1507 print
'<td class="tdoverflowmax150">';
1508 if (empty($obj->fk_user)) {
1509 print $langs->trans(
"Everybody");
1511 $tmpuser->fetch($obj->fk_user);
1512 print $tmpuser->getNomUrl(-1);
1515 print
'<td class="right">';
1516 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?step='.$step.$param.
'&action=deleteprof&token='.
newToken().
'&id='.$obj->rowid.
'&filetoimport='.urlencode($filetoimport).
'">';
1534if ($step == 5 && $datatoimport) {
1535 $max_execution_time_for_importexport =
getDolGlobalInt(
'IMPORT_MAX_EXECUTION_TIME', 300);
1536 $max_time = @ini_get(
"max_execution_time");
1537 if ($max_time && $max_time < $max_execution_time_for_importexport) {
1538 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.");
1539 @ini_set(
"max_execution_time", $max_execution_time_for_importexport);
1543 $list = $objmodelimport->listOfAvailableImportFormat($db);
1546 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
1547 $file =
"import_".$model.
".modules.php";
1548 $classname =
"Import".ucfirst($model);
1549 require_once $dir.$file;
1550 $obj =
new $classname($db, $datatoimport);
1551 '@phan-var-force ModeleImports $obj';
1552 if ($model ==
'csv') {
1553 '@phan-var-force ImportCsv $obj';
1554 $obj->separator = $separator_used;
1555 $obj->enclosure = $enclosure;
1559 $fieldssource = array();
1560 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport);
1564 $arrayrecord = $obj->import_read_record();
1567 foreach ($arrayrecord as $key => $val) {
1568 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 24);
1571 $obj->import_close_file();
1574 $nboflines = $obj->import_get_nb_of_lines($conf->import->dir_temp.
'/'.$filetoimport);
1576 $param =
'&leftmenu=import&format='.urlencode($format).
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport).
'&nboflines='.((int) $nboflines).
'&separator='.urlencode($separator).
'&enclosure='.urlencode($enclosure);
1578 if ($excludefirstline) {
1579 $param .=
'&excludefirstline='.urlencode($excludefirstline);
1582 $param .=
'&endatlinenb='.urlencode($endatlinenb);
1584 if (!empty($updatekeys)) {
1585 $param .=
'&updatekeys[]='.implode(
'&updatekeys[]=', $updatekeys);
1588 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
1593 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?'.$param2.
'" method="POST">';
1594 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1595 print
'<input type="hidden" name="step" value="5">';
1596 print
'<input type="hidden" name="action" value="launchsimu">';
1600 print
'<div class="underbanner clearboth"></div>';
1601 print
'<div class="fichecenter">';
1603 print
'<table width="100%" class="border tableforfield">';
1606 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
1608 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
1610 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
1611 $titleofmodule = $langs->trans(
"ProductOrService");
1613 print $titleofmodule;
1617 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
1619 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
1620 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
1621 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
1622 print $objimport->array_import_label[0];
1628 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
1630 print
'<div class="underbanner clearboth"></div>';
1631 print
'<div class="fichecenter">';
1632 print
'<table width="100%" class="border tableforfield">';
1635 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
1637 $text = $objmodelimport->getDriverDescForKey($format);
1639 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
1643 if ($model ==
'csv') {
1644 '@phan-var-force ImportCsv $obj';
1645 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
1648 print
' '.$langs->trans(
"Enclosure").
' : '.
dol_escape_htmltag($enclosure);
1653 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
1655 $modulepart =
'import';
1656 $relativepath =
GETPOST(
'filetoimport');
1657 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
1658 print
img_mime($file,
'',
'pictofixedwidth');
1659 print $filetoimport;
1660 print
img_picto($langs->trans(
"Download"),
'download',
'class="paddingleft opacitymedium"');
1666 print $langs->trans(
"NbOfSourceLines");
1673 print $langs->trans(
"ImportFromToLine");
1675 if ($action ==
'launchsimu') {
1676 print
'<input type="number" class="maxwidth50 right" name="excludefirstlinebis" disabled="disabled" value="'.$excludefirstline.
'">';
1677 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1679 print
'<input type="number" class="maxwidth50 right" name="excludefirstline" value="'.$excludefirstline.
'">';
1680 print $form->textwithpicto(
"", $langs->trans(
"SetThisValueTo2ToExcludeFirstLine"));
1683 if ($action ==
'launchsimu') {
1684 print
'<input type="text" class="maxwidth50" name="endatlinenbbis" disabled="disabled" value="'.$endatlinenb.
'">';
1685 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1687 print
'<input type="text" class="maxwidth50" name="endatlinenb" value="'.$endatlinenb.
'">';
1688 print $form->textwithpicto(
"", $langs->trans(
"KeepEmptyToGoToEndOfFile"));
1690 if ($action ==
'launchsimu') {
1691 print
' <a href="'.$_SERVER[
"PHP_SELF"].
'?step=5'.$param.
'">'.$langs->trans(
"Modify").
'</a>';
1693 if ($excludefirstline == 2) {
1694 print $form->textwithpicto(
"", $langs->trans(
"WarningFirstImportedLine", $excludefirstline), 1,
'warning',
"warningexcludefirstline");
1696 $( document ).ready(function() {
1697 $("input[name=\'excludefirstline\']").on("change",function(){
1698 if($(this).val() <= 1){
1699 $(".warningexcludefirstline").hide();
1701 $(".warningexcludefirstline").show();
1711 print $form->textwithpicto($langs->trans(
"KeysToUseForUpdates"), $langs->trans(
"SelectPrimaryColumnsForUpdateAttempt"));
1713 if ($action ==
'launchsimu') {
1714 if (count($updatekeys)) {
1715 print $form->multiselectarray(
'updatekeysbis', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0,
'', 1,
'80%',
'disabled');
1717 print
'<span class="opacitymedium">'.$langs->trans(
"NoUpdateAttempt").
'</span> -';
1719 foreach ($updatekeys as $val) {
1720 print
'<input type="hidden" name="updatekeys[]" value="'.$val.
'">';
1722 print
' <a href="'.$_SERVER[
"PHP_SELF"].
'?step=5'.$param.
'">'.$langs->trans(
"Modify").
'</a>';
1724 if (is_array($objimport->array_import_updatekeys[0]) && count($objimport->array_import_updatekeys[0])) {
1725 print $form->multiselectarray(
'updatekeys', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0,
'', 1,
'80%');
1728 print
'<span class="opacitymedium">'.$langs->trans(
"UpdateNotYetSupportedForThisImport").
'</span>';
1740 print
load_fiche_titre($langs->trans(
"InformationOnTargetTables"),
'',
'file-import');
1742 print
'<div class="underbanner clearboth"></div>';
1743 print
'<div class="fichecenter">';
1745 print
'<table width="100%" class="border tableforfield">';
1748 print
'<tr><td class="titlefieldcreate">';
1749 print $langs->trans(
"TablesTarget");
1751 $listtables = array();
1752 $sort_array_match_file_to_database = $array_match_file_to_database;
1753 foreach ($array_match_file_to_database as $code => $label) {
1755 if ($code > count($fieldssource)) {
1759 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
1760 $listtables[$alias] = $objimport->array_import_tables[0][$alias];
1762 if (count($listtables)) {
1765 foreach ($listtables as $val) {
1784 print $langs->trans(
"Error");
1790 print $langs->trans(
"FieldsTarget").
'</td><td>';
1791 $listfields = array();
1794 $sort_array_match_file_to_database = $array_match_file_to_database;
1795 ksort($sort_array_match_file_to_database);
1797 foreach ($sort_array_match_file_to_database as $code => $label) {
1800 if ($code > count($fieldssource)) {
1804 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
1805 $listfields[$i] =
'<span class="nowrap">'.$langs->trans(
"Column").
' '.
num2Alpha((
int) $code - 1).
' -> '.$label.
'</span>';
1807 print count($listfields) ? (implode(
', ', $listfields)) : $langs->trans(
"Error");
1816 if ($action !=
'launchsimu') {
1818 print
'<br><span class="opacitymedium">';
1819 print $langs->trans(
"NowClickToTestTheImport", $langs->transnoentitiesnoconv(
"RunSimulateImportFile")).
'</span><br>';
1823 print
'<div class="center">';
1824 if ($user->hasRight(
'import',
'run')) {
1825 print
'<input type="submit" class="butAction" value="'.$langs->trans(
"RunSimulateImportFile").
'">';
1827 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunSimulateImportFile").
'</a>';
1832 $arrayoferrors = array();
1833 $arrayofwarnings = array();
1834 $maxnboferrors = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_ERRORS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_ERRORS;
1835 $maxnbofwarnings = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_WARNINGS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_WARNINGS;
1847 $pathfile = $conf->import->dir_temp.
'/'.$filetoimport;
1848 $result = $obj->import_open_file($pathfile);
1850 global $tablewithentity_cache;
1851 $tablewithentity_cache = array();
1856 while (($sourcelinenb < $nboflines) && !$endoffile) {
1860 $arrayrecord = $obj->import_read_record();
1861 if ($arrayrecord ===
false) {
1862 $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');
1866 if ($excludefirstline && ($sourcelinenb < $excludefirstline)) {
1869 if ($endatlinenb && ($sourcelinenb > $endatlinenb)) {
1873 $parameters = array(
1875 'datatoimport' => $datatoimport,
1877 'arrayrecord' => $arrayrecord,
1878 'array_match_file_to_database' => $array_match_file_to_database,
1879 'objimport' => $objimport,
1880 'fieldssource' => $fieldssource,
1881 'importid' => $importid,
1882 'updatekeys' => $updatekeys,
1883 'arrayoferrors' => &$arrayoferrors,
1884 'arrayofwarnings' => &$arrayofwarnings,
1888 $reshook = $hookmanager->executeHooks(
'ImportInsert', $parameters);
1890 $arrayoferrors[$sourcelinenb][] = [
1891 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
1895 if (empty($reshook)) {
1897 $result = $obj->import_insert($arrayrecord, $array_match_file_to_database, $objimport, count($fieldssource), $importid, $updatekeys);
1899 if (count($obj->errors)) {
1900 $arrayoferrors[$sourcelinenb] = $obj->errors;
1902 if (count($obj->warnings)) {
1903 $arrayofwarnings[$sourcelinenb] = $obj->warnings;
1905 if (!count($obj->errors) && !count($obj->warnings)) {
1911 $obj->import_close_file();
1913 print $langs->trans(
"ErrorFailedToOpenFile", $pathfile);
1920 if (!empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0])) {
1922 foreach ($objimport->array_import_run_sql_after[0] as $sqlafterimport) {
1924 $resqlafterimport = $db->query($sqlafterimport);
1925 if (!$resqlafterimport) {
1926 $arrayoferrors[
'none'][] = array(
'lib' => $langs->trans(
"Error running final request: ".$sqlafterimport));
1935 if (!count($arrayoferrors) && !count($arrayofwarnings)) {
1937 print
'<div class="info">';
1938 print
'<div class=""><b>'.$langs->trans(
"ResultOfSimulationNoError").
'</b></div>';
1939 print $langs->trans(
"NbInsertSim", empty($obj->nbinsert) ? 0 : $obj->nbinsert).
'<br>';
1940 print $langs->trans(
"NbUpdateSim", empty($obj->nbupdate) ? 0 : $obj->nbupdate).
'<br>';
1945 print
'<div class="warning">';
1946 print $langs->trans(
"NbOfLinesOK", $nbok).
'...<br>';
1953 if (count($arrayoferrors)) {
1954 print
img_error().
' <b>'.$langs->trans(
"ErrorsOnXLines", count($arrayoferrors)).
'</b><br>';
1955 print
'<table width="100%" class="border"><tr><td>';
1956 foreach ($arrayoferrors as $key => $val) {
1958 if ($nboferrors > $maxnboferrors) {
1959 print $langs->trans(
"TooMuchErrors", (count($arrayoferrors) - $nboferrors)).
"<br>";
1963 foreach ($val as $i => $err) {
1964 print
' > '.dol_escape_htmltag($err[
'lib']).
'<br>';
1967 print
'</td></tr></table>';
1973 if (count($arrayofwarnings)) {
1974 print
img_warning().
' <b>'.$langs->trans(
"WarningsOnXLines", count($arrayofwarnings)).
'</b><br>';
1975 print
'<table width="100%" class="border"><tr><td>';
1976 foreach ($arrayofwarnings as $key => $val) {
1978 if ($nbofwarnings > $maxnbofwarnings) {
1979 print $langs->trans(
"TooMuchWarnings", (count($arrayofwarnings) - $nbofwarnings)).
"<br>";
1983 foreach ($val as $i => $err) {
1984 print
' > '.dol_escape_htmltag($err[
'lib']).
'<br>';
1987 print
'</td></tr></table>';
1994 print
'<div class="center">';
1995 print
'<span class="opacitymedium">'.$langs->trans(
"NowClickToRunTheImport", $langs->transnoentitiesnoconv(
"RunImportFile")).
'</span><br>';
2004 print
'<div class="center">';
2005 if ($user->hasRight(
'import',
'run')) {
2006 if (empty($nboferrors)) {
2007 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/imports/import.php?leftmenu=import&step=6&importid='.$importid.$param.
'">'.$langs->trans(
"RunImportFile").
'</a>';
2011 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"CorrectErrorBeforeRunningImport")).
'">'.$langs->trans(
"RunImportFile").
'</a>';
2014 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunSimulateImportFile").
'</a>';
2016 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunImportFile").
'</a>';
2026if ($step == 6 && $datatoimport) {
2027 $max_execution_time_for_importexport =
getDolGlobalInt(
'IMPORT_MAX_EXECUTION_TIME', 300);
2028 $max_time = @ini_get(
"max_execution_time");
2029 if ($max_time && $max_time < $max_execution_time_for_importexport) {
2030 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.");
2031 @ini_set(
"max_execution_time", $max_execution_time_for_importexport);
2035 $list = $objmodelimport->listOfAvailableImportFormat($db);
2036 $importid =
GETPOST(
"importid",
'alphanohtml');
2040 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
2041 $file =
"import_".$model.
".modules.php";
2042 $classname =
"Import".ucfirst($model);
2043 require_once $dir.$file;
2044 $obj =
new $classname($db, $datatoimport);
2045 '@phan-var-force ModeleImports $obj';
2046 if ($model ==
'csv') {
2047 '@phan-var-force ImportCsv $obj';
2048 $obj->separator = $separator_used;
2049 $obj->enclosure = $enclosure;
2053 $fieldssource = array();
2054 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport);
2057 $arrayrecord = $obj->import_read_record();
2060 foreach ($arrayrecord as $key => $val) {
2061 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 24);
2064 $obj->import_close_file();
2069 $param =
'&format='.$format.
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport).
'&nboflines='.((int) $nboflines);
2070 if ($excludefirstline) {
2071 $param .=
'&excludefirstline='.urlencode($excludefirstline);
2074 $param .=
'&endatlinenb='.urlencode($endatlinenb);
2077 $param .=
'&separator='.urlencode($separator);
2080 $param .=
'&enclosure='.urlencode($enclosure);
2083 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
2089 print
'<div class="underbanner clearboth"></div>';
2090 print
'<div class="fichecenter">';
2092 print
'<table width="100%" class="border">';
2095 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
2097 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
2099 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
2100 $titleofmodule = $langs->trans(
"ProductOrService");
2102 print $titleofmodule;
2106 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
2108 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
2109 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
2110 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
2111 print $objimport->array_import_label[0];
2117 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
2119 print
'<div class="underbanner clearboth"></div>';
2120 print
'<div class="fichecenter">';
2121 print
'<table width="100%" class="border">';
2124 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
2126 $text = $objmodelimport->getDriverDescForKey($format);
2128 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
2132 if ($model ==
'csv') {
2133 '@phan-var-force ImportCsv $obj';
2134 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
2136 print $langs->trans(
"Separator").
' : ';
2137 print htmlentities($separator);
2138 print
' '.$langs->trans(
"Enclosure").
' : ';
2139 print htmlentities($enclosure);
2144 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
2146 $modulepart =
'import';
2147 $relativepath =
GETPOST(
'filetoimport');
2148 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
2149 print
img_mime($file,
'',
'pictofixedwidth');
2150 print $filetoimport;
2156 print $langs->trans(
"NbOfSourceLines");
2163 print $langs->trans(
"ImportFromLine");
2165 print
'<input type="text" size="4" name="excludefirstline" disabled="disabled" value="'.$excludefirstline.
'">';
2170 print $langs->trans(
"EndAtLineNb");
2172 print
'<input type="text" size="4" name="endatlinenb" disabled="disabled" value="'.$endatlinenb.
'">';
2180 print
'<b>'.$langs->trans(
"InformationOnTargetTables").
'</b>';
2181 print
'<div class="underbanner clearboth"></div>';
2182 print
'<div class="fichecenter">';
2183 print
'<table class="border centpercent">';
2186 print
'<tr><td width="25%">';
2187 print $langs->trans(
"TablesTarget");
2189 $listtables = array();
2190 foreach ($array_match_file_to_database as $code => $label) {
2192 if ($code > count($fieldssource)) {
2196 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
2197 $listtables[$alias] = $objimport->array_import_tables[0][$alias];
2199 if (count($listtables)) {
2201 foreach ($listtables as $val) {
2220 print $langs->trans(
"Error");
2226 print $langs->trans(
"FieldsTarget").
'</td><td>';
2227 $listfields = array();
2229 $sort_array_match_file_to_database = $array_match_file_to_database;
2230 ksort($sort_array_match_file_to_database);
2232 foreach ($sort_array_match_file_to_database as $code => $label) {
2235 if ($code > count($fieldssource)) {
2239 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
2240 $listfields[$i] = $langs->trans(
"Field").
' '.$code.
'->'.$label;
2242 print count($listfields) ? (implode(
', ', $listfields)) : $langs->trans(
"Error");
2249 $arrayoferrors = array();
2250 $arrayofwarnings = array();
2251 $maxnboferrors = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_ERRORS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_ERRORS;
2252 $maxnbofwarnings = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_WARNINGS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_WARNINGS;
2264 $pathfile = $conf->import->dir_temp.
'/'.$filetoimport;
2265 $result = $obj->import_open_file($pathfile);
2267 global $tablewithentity_cache;
2268 $tablewithentity_cache = array();
2272 while ($sourcelinenb < $nboflines && !$endoffile) {
2274 $arrayrecord = $obj->import_read_record();
2275 if ($arrayrecord ===
false) {
2276 $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');
2280 if ($excludefirstline && ($sourcelinenb < $excludefirstline)) {
2283 if ($endatlinenb && ($sourcelinenb > $endatlinenb)) {
2287 $parameters = array(
2289 'datatoimport' => $datatoimport,
2291 'arrayrecord' => $arrayrecord,
2292 'array_match_file_to_database' => $array_match_file_to_database,
2293 'objimport' => $objimport,
2294 'fieldssource' => $fieldssource,
2295 'importid' => $importid,
2296 'updatekeys' => $updatekeys,
2297 'arrayoferrors' => &$arrayoferrors,
2298 'arrayofwarnings' => &$arrayofwarnings,
2302 $reshook = $hookmanager->executeHooks(
'ImportInsert', $parameters);
2304 $arrayoferrors[$sourcelinenb][] = [
2305 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
2309 if (empty($reshook)) {
2311 $result = $obj->import_insert($arrayrecord, $array_match_file_to_database, $objimport, count($fieldssource), $importid, $updatekeys);
2313 if (count($obj->errors)) {
2314 $arrayoferrors[$sourcelinenb] = $obj->errors;
2316 if (count($obj->warnings)) {
2317 $arrayofwarnings[$sourcelinenb] = $obj->warnings;
2320 if (!count($obj->errors) && !count($obj->warnings)) {
2325 $reshook = $hookmanager->executeHooks(
'AfterImportInsert', $parameters);
2327 $arrayoferrors[$sourcelinenb][] = [
2328 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
2333 $obj->import_close_file();
2335 print $langs->trans(
"ErrorFailedToOpenFile", $pathfile);
2338 if (count($arrayoferrors) > 0) {
2345 if (!empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0])) {
2347 foreach ($objimport->array_import_run_sql_after[0] as $sqlafterimport) {
2349 $resqlafterimport = $db->query($sqlafterimport);
2350 if (!$resqlafterimport) {
2351 $arrayoferrors[
'none'][] = array(
'lib' => $langs->trans(
"Error running final request: ".$sqlafterimport));
2369 print
'<div class="info">';
2370 print $langs->trans(
"NbOfLinesImported", $nbok).
'</b><br>';
2371 print $langs->trans(
"NbInsert", empty($obj->nbinsert) ? 0 : $obj->nbinsert).
'<br>';
2372 print $langs->trans(
"NbUpdate", empty($obj->nbupdate) ? 0 : $obj->nbupdate).
'<br>';
2374 print
'<div class="center">';
2375 print $langs->trans(
"FileWasImported", $importid).
'<br>';
2376 print
'<span class="opacitymedium">'.$langs->trans(
"YouCanUseImportIdToFindRecord", $importid).
'</span><br>';
2399 global $conf, $langs;
2403 if ($key ==
'none') {
2405 print
"\n\n<!-- Box_no-key start-->\n";
2406 print
'<div class="box boximport" style="padding:0;">'.
"\n";
2407 print
'<table summary="boxtable_no-key" class="centpercent nobordernopadding">'.
"\n";
2409 print
"\n\n<!-- Box ".$pos.
" start -->\n";
2410 print
'<div class="box boximport" style="padding: 0;" id="boxto_'.$pos.
'">'.
"\n";
2412 print
'<table summary="boxtable'.$pos.
'" class="nobordernopadding centpercent tableimport">'.
"\n";
2415 if (($pos && $pos > count($fieldssource)) && (!isset($fieldssource[$pos][
"imported"]))) {
2425 } elseif ($key ==
'none') {
2426 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
2427 print
'<td class="nocellnopadd" width="16" style="font-weight: normal">';
2430 print
'<td style="font-weight: normal">';
2436 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
2437 print
'<td class="nocellnopadd" width="16" style="font-weight: normal">';
2440 print
img_picto($langs->trans(
"Column").
' '.
num2Alpha($pos - 1),
'file',
'class="pictofixedwidth"');
2442 if (isset($fieldssource[$pos][
'imported']) && $fieldssource[$pos][
'imported'] ==
false) {
2443 print
'<td class="nowraponall boxtdunused" style="font-weight: normal">';
2445 print
'<td class="nowraponall tdoverflowmax500" style="font-weight: normal">';
2447 print $langs->trans(
"Column").
' '.
num2Alpha($pos - 1).
' (#'.$pos.
')';
2448 if (empty($fieldssource[$pos][
'example1'])) {
2449 $example = $fieldssource[$pos][
'label'];
2451 $example = $fieldssource[$pos][
'example1'];
2455 $example = mb_convert_encoding($example,
'UTF-8',
'ISO-8859-1');
2459 print
'<i class="opacitymedium">'.dol_escape_htmltag($example).
'</i>';
2468 print
"<!-- Box end -->\n\n";
2481 $i = count($fieldssource) + 1;
2484 foreach ($listofkey as $key => $val) {
2485 $maxkey = max($maxkey, $key);
2488 while ($i <= $maxkey) {
2489 if (empty($listofkey[$i])) {
2511 if ($position == count($array)) {
2512 $ret = $array + $insertArray;
2515 foreach ($array as $key => $value) {
2516 if ($position == $i++) {
2517 $ret += $insertArray;
2520 $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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
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)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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 a 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.