28 require_once
'../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/imports/class/import.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/modules/import/modules_import.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/import.lib.php';
38 $langs->loadLangs(array(
'exports',
'compta',
'errors',
'projects',
'admin'));
44 $entitytoicon = array(
46 'invoice_line' =>
'bill',
48 'order_line' =>
'order',
50 'propal_line' =>
'propal',
51 'intervention' =>
'intervention',
52 'inter_line' =>
'intervention',
54 'member_type' =>
'group',
55 'subscription' =>
'payment',
56 'payment' =>
'payment',
58 'tax_type' =>
'generic',
60 'account' =>
'account',
61 'product' =>
'product',
62 'virtualproduct' =>
'product',
63 'subproduct' =>
'product',
64 'product_supplier_ref' =>
'product',
66 'warehouse' =>
'stock',
68 'stockbatch' =>
'stock',
69 'category' =>
'category',
70 'shipment' =>
'sending',
71 'shipment_line' =>
'sending',
72 'reception' =>
'sending',
73 'reception_line' =>
'sending',
74 'expensereport' =>
'trip',
75 'expensereport_line' =>
'trip',
76 'holiday' =>
'holiday',
77 'contract_line' =>
'contract',
78 'translation' =>
'generic',
84 $entitytolang = array(
86 'company' =>
'Company',
87 'contact' =>
'Contact',
89 'invoice_line' =>
'InvoiceLine',
91 'order_line' =>
'OrderLine',
92 'propal' =>
'Proposal',
93 'propal_line' =>
'ProposalLine',
94 'intervention' =>
'Intervention',
95 'inter_line' =>
'InterLine',
97 'member_type' =>
'MemberType',
98 'subscription' =>
'Subscription',
99 'tax' =>
'SocialContribution',
100 'tax_type' =>
'DictionarySocialContributions',
101 'account' =>
'BankTransactions',
102 'payment' =>
'Payment',
103 'product' =>
'Product',
104 'virtualproduct' =>
'AssociatedProducts',
105 'subproduct' =>
'SubProduct',
106 'product_supplier_ref' =>
'SupplierPrices',
107 'service' =>
'Service',
109 'movement' =>
'StockMovement',
111 'stockbatch' =>
'StockDetailPerBatch',
112 'warehouse' =>
'Warehouse',
113 'category' =>
'Category',
115 'trip' =>
'TripsAndExpenses',
116 'shipment' =>
'Shipments',
117 'shipment_line' =>
'ShipmentLine',
118 'project' =>
'Projects',
119 'projecttask' =>
'Tasks',
120 'task_time' =>
'TaskTimeSpent',
122 'expensereport' =>
'ExpenseReport',
123 'expensereport_line' =>
'ExpenseReportLine',
124 'holiday' =>
'TitreRequestCP',
125 'contract' =>
'Contract',
126 'contract_line' =>
'ContractLine',
127 'translation' =>
'Translation',
129 'bomline' =>
'BOMLine'
132 $datatoimport =
GETPOST(
'datatoimport');
134 $filetoimport =
GETPOST(
'filetoimport');
135 $action =
GETPOST(
'action',
'alpha');
136 $confirm =
GETPOST(
'confirm',
'alpha');
138 $import_name =
GETPOST(
'import_name');
141 $excludefirstline = (
GETPOST(
'excludefirstline') ?
GETPOST(
'excludefirstline') : 2);
142 $endatlinenb = (
GETPOST(
'endatlinenb') ?
GETPOST(
'endatlinenb') :
'');
143 $updatekeys = (
GETPOST(
'updatekeys',
'array') ?
GETPOST(
'updatekeys',
'array') : array());
144 $separator = (
GETPOST(
'separator',
'nohtml') ?
GETPOST(
'separator',
'nohtml', 3) :
'');
145 $enclosure = (
GETPOST(
'enclosure',
'nohtml') ?
GETPOST(
'enclosure',
'nohtml') :
'"');
146 $charset =
GETPOST(
'charset',
'aZ09');
147 $separator_used = str_replace(
'\t',
"\t", $separator);
151 $hookmanager->initHooks(array(
'imports'));
154 $objimport =
new Import($db);
155 $objimport->load_arrays($user, ($step == 1 ?
'' : $datatoimport));
157 if (empty($updatekeys) && !empty($objimport->array_import_preselected_updatekeys[0])) {
158 $updatekeys = array_keys($objimport->array_import_preselected_updatekeys[0]);
163 $form =
new Form($db);
168 if (empty($array_match_file_to_database)) {
169 $serialized_array_match_file_to_database = isset($_SESSION[
"dol_array_match_file_to_database_select"]) ? $_SESSION[
"dol_array_match_file_to_database_select"] :
'';
170 $array_match_file_to_database = array();
171 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
172 foreach ($fieldsarray as $elem) {
173 $tabelem = explode(
'=', $elem, 2);
175 $val = (isset($tabelem[1]) ? $tabelem[1] :
'');
177 $array_match_file_to_database[$key] = $val;
187 if ($action ==
'deleteprof') {
190 $result = $objimport->delete($user);
195 if ($action ==
'add_import_model') {
199 foreach ($array_match_file_to_database as $key => $val) {
203 $hexa .= $key.
'='.$val;
206 $objimport->model_name = $import_name;
207 $objimport->datatoimport = $datatoimport;
208 $objimport->hexa = $hexa;
209 $objimport->fk_user = (
GETPOST(
'visibility',
'aZ09') ==
'all' ? 0 : $user->id);
211 $result = $objimport->create($user);
213 setEventMessages($langs->trans(
"ImportModelSaved", $objimport->model_name),
null,
'mesgs');
216 $langs->load(
"errors");
217 if ($objimport->errno ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
218 setEventMessages($langs->trans(
"ErrorImportDuplicateProfil"),
null,
'errors');
224 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"ImportModelName")),
null,
'errors');
228 if ($step == 3 && $datatoimport) {
233 $fullpath = $conf->import->dir_temp.
"/".$nowyearmonth.
'-'.$_FILES[
'userfile'][
'name'];
235 dol_syslog(
"File ".$fullpath.
" was added for import");
237 $langs->load(
"errors");
243 if ($action ==
'confirm_deletefile' && $confirm ==
'yes') {
244 $langs->load(
"other");
246 $param =
'&datatoimport='.urlencode($datatoimport).
'&format='.urlencode($format);
247 if ($excludefirstline) {
248 $param .=
'&excludefirstline='.urlencode($excludefirstline);
251 $param .=
'&endatlinenb='.urlencode($endatlinenb);
254 $file = $conf->import->dir_temp.
'/'.
GETPOST(
'urlfile');
261 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?step='.$step.$param);
266 if ($step == 4 && $action ==
'select_model') {
268 $_SESSION[
"dol_array_match_file_to_database"] =
'';
269 $serialized_array_match_file_to_database =
'';
270 $array_match_file_to_database = array();
274 $result = $objimport->fetch($importmodelid);
276 $serialized_array_match_file_to_database = $objimport->hexa;
277 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
278 foreach ($fieldsarray as $elem) {
279 $tabelem = explode(
'=', $elem);
283 $array_match_file_to_database[$key] = $val;
286 $_SESSION[
"dol_array_match_file_to_database"] = $serialized_array_match_file_to_database;
287 $_SESSION[
'dol_array_match_file_to_database_select'] = $_SESSION[
"dol_array_match_file_to_database"];
290 if ($action ==
'saveselectorder') {
292 $serialized_array_match_file_to_database =
'';
294 $selectorder = explode(
",",
GETPOST(
'selectorder'));
295 $fieldtarget = $fieldstarget = $objimport->array_import_fields[0];
296 foreach ($selectorder as $key => $code) {
297 $serialized_array_match_file_to_database .= $key.
'='.$code;
298 $serialized_array_match_file_to_database .=
',';
300 $serialized_array_match_file_to_database = substr($serialized_array_match_file_to_database, 0, -1);
301 dol_syslog(
'dol_array_match_file_to_database_select='.$serialized_array_match_file_to_database);
302 $_SESSION[
"dol_array_match_file_to_database_select"] = $serialized_array_match_file_to_database;
314 $help_url =
'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones';
318 if ($step == 1 || !$datatoimport) {
320 $serialized_array_match_file_to_database =
'';
321 $array_match_file_to_database = array();
322 $_SESSION[
"dol_array_match_file_to_database"] =
'';
323 $_SESSION[
"dol_array_match_file_to_database_select"] =
'';
326 if ($excludefirstline) {
327 $param .=
'&excludefirstline='.urlencode($excludefirstline);
330 $param .=
'&endatlinenb='.urlencode($endatlinenb);
333 $param .=
'&separator='.urlencode($separator);
336 $param .=
'&enclosure='.urlencode($enclosure);
339 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
345 print
'<div class="opacitymedium">'.$langs->trans(
"SelectImportDataSet").
'</div><br>';
348 print
'<div class="div-table-responsive-no-min">';
349 print
'<table class="noborder centpercent">';
350 print
'<tr class="liste_titre">';
351 print
'<td>'.$langs->trans(
"Module").
'</td>';
352 print
'<td>'.$langs->trans(
"ImportableDatas").
'</td>';
353 print
'<td> </td>';
356 if (count($objimport->array_import_module)) {
357 $sortedarrayofmodules =
dol_sort_array($objimport->array_import_module,
'position_of_profile',
'asc', 0, 0, 1);
358 foreach ($sortedarrayofmodules as $key => $value) {
360 print
'<tr class="oddeven"><td>';
361 $titleofmodule = $objimport->array_import_module[$key][
'module']->getName();
363 if (in_array($objimport->array_import_code[$key], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
364 $titleofmodule = $langs->trans(
"ProductOrService");
366 print $titleofmodule;
368 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[$key]);
369 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
370 print
img_object($objimport->array_import_module[$key][
'module']->getName(), $entityicon).
' ';
371 print $objimport->array_import_label[$key];
372 print
'</td><td style="text-align: right">';
373 if ($objimport->array_import_perms[$key]) {
374 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>';
376 print $langs->trans(
"NotEnoughPermissions");
381 print
'<tr><td class="oddeven" colspan="3">'.$langs->trans(
"NoImportableData").
'</td></tr>';
391 if ($step == 2 && $datatoimport) {
392 $param =
'&datatoimport='.urlencode($datatoimport);
393 if ($excludefirstline) {
394 $param .=
'&excludefirstline='.urlencode($excludefirstline);
397 $param .=
'&endatlinenb='.urlencode($endatlinenb);
400 $param .=
'&separator='.urlencode($separator);
403 $param .=
'&enclosure='.urlencode($enclosure);
406 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
412 print
'<div class="underbanner clearboth"></div>';
413 print
'<div class="fichecenter">';
415 print
'<table class="border tableforfield centpercent">';
418 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
420 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
422 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
423 $titleofmodule = $langs->trans(
"ProductOrService");
425 print $titleofmodule;
429 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
431 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
432 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
433 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
434 print $objimport->array_import_label[0];
442 print
'<form name="userfile" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" METHOD="POST">';
443 print
'<input type="hidden" name="token" value="'.newToken().
'">';
447 print
'<span class="opacitymedium">';
448 $s = $langs->trans(
"ChooseFormatOfFileToImport",
'{s1}');
449 $s = str_replace(
'{s1}',
img_picto(
'',
'next'), $s);
451 print
'</span><br><br>';
455 print
'<div class="div-table-responsive-no-min">';
456 print
'<table class="noborder centpercent" cellpadding="4">';
461 print
'<tr class="liste_titre"><td colspan="5">';
462 print $langs->trans(
"FileMustHaveOneOfFollowingFormat");
464 $list = $objmodelimport->listOfAvailableImportFormat($db);
465 foreach ($list as $key) {
466 print
'<tr class="oddeven">';
467 print
'<td width="16">'.img_picto_common($key, $objmodelimport->getPictoForKey($key)).
'</td>';
468 $text = $objmodelimport->getDriverDescForKey($key);
470 print
'<td>'.$form->textwithpicto($objmodelimport->getDriverLabelForKey($key), $text).
'</td>';
471 print
'<td style="text-align:center">';
472 $filename = $langs->transnoentitiesnoconv(
"ExampleOfImportFile").
'_'.$datatoimport.
'.'.$key;
473 print
'<a href="'.DOL_URL_ROOT.
'/imports/emptyexample.php?format='.$key.$param.
'&output=file&file='.urlencode($filename).
'" target="_blank" rel="noopener noreferrer">';
474 print
img_picto(
'',
'download',
'class="paddingright opacitymedium"');
475 print $langs->trans(
"DownloadEmptyExampleShort");
477 print $form->textwithpicto(
'', $langs->trans(
"DownloadEmptyExample").
'.<br>'.$langs->trans(
"StarAreMandatory"));
480 print
'<td style="text-align:right">';
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>';
494 if ($step == 3 && $datatoimport) {
495 $param =
'&datatoimport='.urlencode($datatoimport).
'&format='.urlencode($format);
496 if ($excludefirstline) {
497 $param .=
'&excludefirstline='.urlencode($excludefirstline);
500 $param .=
'&endatlinenb='.urlencode($endatlinenb);
503 $param .=
'&separator='.urlencode($separator);
506 $param .=
'&enclosure='.urlencode($enclosure);
509 $list = $objmodelimport->listOfAvailableImportFormat($db);
511 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
520 if ($action ==
'delete') {
521 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?urlfile='.urlencode(
GETPOST(
'urlfile')).
'&step=3'.$param, $langs->trans(
'DeleteFile'), $langs->trans(
'ConfirmDeleteFile'),
'confirm_deletefile',
'', 0, 1);
524 print
'<div class="underbanner clearboth"></div>';
525 print
'<div class="fichecenter">';
527 print
'<table class="border tableforfield centpercent">';
530 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
532 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
534 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
535 $titleofmodule = $langs->trans(
"ProductOrService");
537 print $titleofmodule;
541 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
543 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
544 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
545 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
546 print $objimport->array_import_label[0];
552 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
554 print
'<div class="underbanner clearboth"></div>';
555 print
'<div class="fichecenter">';
556 print
'<table width="100%" class="border tableforfield">';
559 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
560 print
'<td class="nowraponall">';
561 $text = $objmodelimport->getDriverDescForKey($format);
563 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
564 print
'</td><td style="text-align:right" class="nowrap">';
565 $filename = $langs->transnoentitiesnoconv(
"ExampleOfImportFile").
'_'.$datatoimport.
'.'.$format;
566 print
'<a href="'.DOL_URL_ROOT.
'/imports/emptyexample.php?format='.$format.$param.
'&output=file&file='.urlencode($filename).
'" target="_blank" rel="noopener noreferrer">';
567 print
img_picto(
'',
'download',
'class="paddingright opacitymedium"');
568 print $langs->trans(
"DownloadEmptyExampleShort");
570 print $form->textwithpicto(
'', $langs->trans(
"DownloadEmptyExample").
'.<br>'.$langs->trans(
"StarAreMandatory"));
579 if ($format ==
'xlsx' && !class_exists(
'XMLWriter')) {
580 $langs->load(
"install");
581 print
info_admin($langs->trans(
"ErrorPHPDoesNotSupport",
'php-xml'), 0, 0, 1,
'error');
587 print
'<form name="userfile" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="POST">';
588 print
'<input type="hidden" name="token" value="'.newToken().
'">';
589 print
'<input type="hidden" value="'.$step.
'" name="step">';
590 print
'<input type="hidden" value="'.dol_escape_htmltag($format).
'" name="format">';
591 print
'<input type="hidden" value="'.$excludefirstline.
'" name="excludefirstline">';
592 print
'<input type="hidden" value="'.$endatlinenb.
'" name="endatlinenb">';
593 print
'<input type="hidden" value="'.dol_escape_htmltag($separator).
'" name="separator">';
594 print
'<input type="hidden" value="'.dol_escape_htmltag($enclosure).
'" name="enclosure">';
595 print
'<input type="hidden" value="'.dol_escape_htmltag($datatoimport).
'" name="datatoimport">';
597 print
'<span class="opacitymedium">';
598 $s = $langs->trans(
"ChooseFileToImport",
'{s1}');
599 $s = str_replace(
'{s1}',
img_picto(
'',
'next'), $s);
601 print
'</span><br><br>';
606 print
'<div class="marginbottomonly">';
608 $maxmin = $maxfilesizearray[
'maxmin'];
610 print
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
612 print
'<input type="file" name="userfile" size="20" maxlength="80"> ';
614 print
'<input type="submit" class="button small" value="'.$langs->trans(
"AddFile").
'"'.$out.
' name="sendit">';
618 $maxphp = @ini_get(
'upload_max_filesize');
619 if (preg_match(
'/k$/i', $maxphp)) {
620 $maxphp = (int) substr($maxphp, 0, -1);
622 if (preg_match(
'/m$/i', $maxphp)) {
623 $maxphp = (int) substr($maxphp, 0, -1) * 1024;
625 if (preg_match(
'/g$/i', $maxphp)) {
626 $maxphp = (int) substr($maxphp, 0, -1) * 1024 * 1024;
628 if (preg_match(
'/t$/i', $maxphp)) {
629 $maxphp = (int) substr($maxphp, 0, -1) * 1024 * 1024 * 1024;
631 $maxphp2 = @ini_get(
'post_max_size');
632 if (preg_match(
'/k$/i', $maxphp2)) {
633 $maxphp2 = (int) substr($maxphp2, 0, -1);
635 if (preg_match(
'/m$/i', $maxphp2)) {
636 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024;
638 if (preg_match(
'/g$/i', $maxphp2)) {
639 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024 * 1024;
641 if (preg_match(
'/t$/i', $maxphp2)) {
642 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024 * 1024 * 1024;
646 $maxphptoshow = $maxphptoshowparam =
'';
648 $maxmin = min($max, $maxphp);
649 $maxphptoshow = $maxphp;
650 $maxphptoshowparam =
'upload_max_filesize';
653 $maxmin = min($max, $maxphp2);
654 if ($maxphp2 < $maxphp) {
655 $maxphptoshow = $maxphp2;
656 $maxphptoshowparam =
'post_max_size';
660 $langs->load(
'other');
662 $out .=
info_admin($langs->trans(
"ThisLimitIsDefinedInSetup", $max, $maxphptoshow), 1);
664 $out .=
' ('.$langs->trans(
"UploadDisabled").
')';
670 $filearray =
dol_dir_list($conf->import->dir_temp,
'files', 0,
'',
'',
'name', SORT_DESC);
671 if (count($filearray) > 0) {
672 print
'<div class="div-table-responsive-no-min">';
673 print
'<table class="noborder centpercent" width="100%" cellpadding="4">';
675 $dir = $conf->import->dir_temp;
679 foreach ($filearray as $key => $val) {
680 $file = $val[
'name'];
684 $file = mb_convert_encoding($file,
'UTF-8',
'ISO-8859-1');
687 if (preg_match(
'/^\./', $file)) {
691 $modulepart =
'import';
692 $urlsource = $_SERVER[
"PHP_SELF"].
'?step='.$step.$param.
'&filetoimport='.urlencode($filetoimport);
693 $relativepath = $file;
695 print
'<tr class="oddeven">';
697 print
img_mime($file,
'',
'pictofixedwidth');
698 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=3'.$param.
'" target="_blank" rel="noopener noreferrer">';
703 print
'<td style="text-align:right">'.dol_print_size(
dol_filesize($dir.
'/'.$file)).
'</td>';
705 print
'<td style="text-align:right">'.dol_print_date(
dol_filemtime($dir.
'/'.$file),
'dayhour').
'</td>';
707 print
'<td style="text-align:right"><a href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.
newToken().
'&step=3'.$param.
'&urlfile='.urlencode($relativepath);
708 print
'">'.img_delete().
'</a></td>';
710 print
'<td style="text-align:right">';
711 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?step=4'.$param.
'&filetoimport='.urlencode($relativepath).
'">'.
img_picto($langs->trans(
"NewImport"),
'next',
'class="fa-15"').
'</a>';
725 if ($step == 4 && $datatoimport) {
727 $serialized_array_match_file_to_database = isset($_SESSION[
"dol_array_match_file_to_database_select"]) ? $_SESSION[
"dol_array_match_file_to_database_select"] :
'';
728 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
729 $array_match_file_to_database = array();
730 foreach ($fieldsarray as $elem) {
731 $tabelem = explode(
'=', $elem, 2);
733 $val = (isset($tabelem[1]) ? $tabelem[1] :
'');
735 $array_match_file_to_database[$key] = $val;
744 $list = $objmodelimport->listOfAvailableImportFormat($db);
746 if (empty($separator)) {
747 $separator = (!
getDolGlobalString(
'IMPORT_CSV_SEPARATOR_TO_USE') ?
',' : $conf->global->IMPORT_CSV_SEPARATOR_TO_USE);
751 if ($model ==
'csv' && strlen($separator) == 1 && !
GETPOSTISSET(
'separator')) {
753 $fh = fopen($conf->import->dir_temp.
'/'.$filetoimport,
'r');
755 $sline = fgets($fh, 1000000);
757 $nboccurence = substr_count($sline, $separator);
758 $nboccurencea = substr_count($sline,
',');
759 $nboccurenceb = substr_count($sline,
';');
761 if ($nboccurence == 0) {
762 if ($nboccurencea > 2) {
764 } elseif ($nboccurenceb > 2) {
772 $separator_used = str_replace(
'\t',
"\t", $separator);
775 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
776 $file =
"import_".$model.
".modules.php";
777 $classname =
"Import".ucfirst($model);
778 require_once $dir.$file;
779 $obj =
new $classname($db, $datatoimport);
780 if ($model ==
'csv') {
781 $obj->separator = $separator_used;
782 $obj->enclosure = $enclosure;
785 if ($model ==
'xlsx') {
786 if (!preg_match(
'/\.xlsx$/i', $filetoimport)) {
787 $langs->load(
"errors");
788 $param =
'&datatoimport='.$datatoimport.
'&format='.$format;
789 setEventMessages($langs->trans(
"ErrorFileMustHaveFormat", $model),
null,
'errors');
790 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?step=3'.$param.
'&filetoimport='.urlencode($relativepath));
796 $array_match_file_to_database = array();
800 $fieldssource = array();
801 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport, $langs);
804 $arrayrecord = $obj->import_read_record();
808 foreach ($arrayrecord as $key => $val) {
809 if ($val[
"type"] != -1) {
810 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 128);
813 $fieldssource[$i][
'example1'] = $langs->trans(
'Empty');
817 $obj->import_close_file();
821 $fieldstarget = $objimport->array_import_fields[0];
822 $minpos = min(count($fieldssource), count($fieldstarget));
826 $initialloadofstep4 =
false;
827 if (empty($_SESSION[
'dol_array_match_file_to_database_select'])) {
828 $initialloadofstep4 =
true;
832 if (count($array_match_file_to_database) == 0) {
838 $num = count($fieldssource);
839 while ($pos <= $num) {
840 if ($num >= 1 && $pos <= $num) {
842 foreach ($fieldstarget as $key => $val) {
843 if ($posbis < $pos) {
848 $array_match_file_to_database[$pos] = $key;
855 $array_match_database_to_file = array_flip($array_match_file_to_database);
859 $fieldstarget_tmp = array();
860 $arraykeysfieldtarget = array_keys($fieldstarget);
862 foreach ($fieldstarget as $key => $label) {
863 $isrequired = preg_match(
'/\*$/', $label);
864 if (!empty($isrequired)) {
865 $newlabel = substr($label, 0, -1);
866 $fieldstarget_tmp[$key] = array(
"label" => $newlabel,
"required" =>
true);
868 $fieldstarget_tmp[$key] = array(
"label" => $label,
"required" =>
false);
870 if (!empty($array_match_database_to_file[$key])) {
871 $fieldstarget_tmp[$key][
"imported"] =
true;
872 $fieldstarget_tmp[$key][
"position"] = $array_match_database_to_file[$key] - 1;
874 while (!empty($array_match_database_to_file[$keytoswap])) {
875 if ($position + 1 > $array_match_database_to_file[$keytoswap]) {
876 $keytoswapwith = $array_match_database_to_file[$keytoswap] - 1;
877 $tmp = [$keytoswap => $fieldstarget_tmp[$keytoswap]];
878 unset($fieldstarget_tmp[$keytoswap]);
879 $fieldstarget_tmp =
arrayInsert($fieldstarget_tmp, $keytoswapwith, $tmp);
880 $keytoswapwith = $arraykeysfieldtarget[$array_match_database_to_file[$keytoswap] - 1];
881 $tmp = $fieldstarget_tmp[$keytoswapwith];
882 unset($fieldstarget_tmp[$keytoswapwith]);
883 $fieldstarget_tmp[$keytoswapwith] = $tmp;
884 $keytoswap = $keytoswapwith;
890 $fieldstarget_tmp[$key][
"imported"] =
false;
894 $fieldstarget = $fieldstarget_tmp;
903 $param =
'&format='.$format.
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport);
904 if ($excludefirstline) {
905 $param .=
'&excludefirstline='.urlencode($excludefirstline);
908 $param .=
'&endatlinenb='.urlencode($endatlinenb);
911 $param .=
'&separator='.urlencode($separator);
914 $param .=
'&enclosure='.urlencode($enclosure);
917 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
923 print
'<div class="underbanner clearboth"></div>';
924 print
'<div class="fichecenter">';
926 print
'<table class="centpercent border tableforfield">';
929 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
931 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
933 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
934 $titleofmodule = $langs->trans(
"ProductOrService");
936 print $titleofmodule;
940 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
942 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
943 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
944 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
945 print $objimport->array_import_label[0];
951 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
953 print
'<div class="underbanner clearboth"></div>';
954 print
'<div class="fichecenter">';
955 print
'<table width="100%" class="border tableforfield">';
958 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
960 $text = $objmodelimport->getDriverDescForKey($format);
962 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
966 if ($model ==
'csv') {
967 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
969 print
'<form method="POST">';
970 print
'<input type="hidden" name="token" value="'.newToken().
'">';
971 print
'<input type="hidden" value="'.$step.
'" name="step">';
972 print
'<input type="hidden" value="'.$format.
'" name="format">';
973 print
'<input type="hidden" value="'.$excludefirstline.
'" name="excludefirstline">';
974 print
'<input type="hidden" value="'.$endatlinenb.
'" name="endatlinenb">';
975 print
'<input type="hidden" value="'.$datatoimport.
'" name="datatoimport">';
976 print
'<input type="hidden" value="'.$filetoimport.
'" name="filetoimport">';
977 print $langs->trans(
"Separator").
' : ';
978 print
'<input type="text" class="width25 center" name="separator" value="'.dol_escape_htmltag($separator).
'"/>';
979 print
' '.$langs->trans(
"Enclosure").
' : ';
980 print
'<input type="text" class="width25 center" name="enclosure" value="'.dol_escape_htmltag($enclosure).
'"/> ';
981 print
'<input name="update" type="submit" value="'.$langs->trans(
'Update').
'" class="button smallpaddingimp" />';
987 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
989 $modulepart =
'import';
990 $relativepath =
GETPOST(
'filetoimport');
991 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
992 print
img_mime($file,
'',
'pictofixedwidth');
994 print
img_picto($langs->trans(
"Download"),
'download',
'class="paddingleft opacitymedium"');
1007 print
'<!-- List of source fields -->'.
"\n";
1008 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1009 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1010 print
'<input type="hidden" name="action" value="select_model">';
1011 print
'<input type="hidden" name="step" value="4">';
1012 print
'<input type="hidden" name="format" value="'.$format.
'">';
1013 print
'<input type="hidden" name="datatoimport" value="'.$datatoimport.
'">';
1014 print
'<input type="hidden" name="filetoimport" value="'.$filetoimport.
'">';
1015 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1016 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1017 print
'<input type="hidden" name="separator" value="'.dol_escape_htmltag($separator).
'">';
1018 print
'<input type="hidden" name="enclosure" value="'.dol_escape_htmltag($enclosure).
'">';
1021 print
'<div class="marginbottomonly">';
1022 print
'<span class="opacitymedium">';
1023 $s = $langs->trans(
"SelectImportFieldsSource",
'{s1}');
1024 $s = str_replace(
'{s1}',
img_picto(
'',
'grip_title',
'',
false, 0, 0,
'',
'', 0), $s);
1027 $htmlother->select_import_model($importmodelid,
'importmodelid', $datatoimport, 1, $user->id);
1028 print
'<input type="submit" class="button small reposition" value="'.$langs->trans(
"Select").
'">';
1033 print
'<div class="div-table-responsive-no-min">';
1034 print
'<table class="noborder centpercent">';
1035 print
'<tr class="liste_titre">';
1036 print
'<td>'.$langs->trans(
"FieldsInSourceFile").
'</td>';
1037 print
'<td>'.$langs->trans(
"FieldsInTargetDatabase").
'</td>';
1042 print
'<tr valign="top"><td width="50%" class="nopaddingleftimp">';
1044 $fieldsplaced = array();
1045 $valforsourcefieldnb = array();
1046 $listofkeys = array();
1047 foreach ($array_match_file_to_database as $key => $val) {
1048 $listofkeys[$key] = 1;
1051 print
"\n<!-- Box left container -->\n";
1052 print
'<div id="left" class="connectedSortable">'.
"\n";
1057 foreach ($fieldssource as $key => $val) {
1060 $listofkeys[$key] = 1;
1061 $fieldsplaced[$key] = 1;
1062 $valforsourcefieldnb[$lefti] = $key;
1072 print
"<!-- End box left container -->\n";
1075 print
'</td><td width="50%" class="nopaddingrightimp">';
1079 $optionsall = array();
1080 foreach ($fieldstarget as $code => $line) {
1083 $tmparray = explode(
'|', $line[
"label"]);
1085 foreach ($tmparray as $tmpkey => $tmpval) {
1086 $labeltoshow .= ($labeltoshow ?
' '.$langs->trans(
'or').
' ' :
'').$langs->transnoentities($tmpval);
1088 $optionsall[$code] = array(
'labelkey' => $line[
'label'],
'labelkeyarray' => $tmparray,
'label' => $labeltoshow,
'required' => (empty($line[
"required"]) ? 0 : 1),
'position' => !empty($line[
'position']) ? $line[
'position'] : 0);
1093 $optionsall[$code][
'picto'] = $picto;
1100 $mandatoryfieldshavesource =
true;
1113 $modetoautofillmapping =
'session';
1114 if ($initialloadofstep4) {
1115 $modetoautofillmapping =
'guess';
1119 print
'<table class="nobordernopadding centpercent tableimport">';
1120 foreach ($fieldssource as $code => $line) {
1124 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
1125 $entity = (!empty($objimport->array_import_entities[0][$code]) ? $objimport->array_import_entities[0][$code] : $objimport->array_import_icon[0]);
1127 $entityicon = !empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity;
1128 $entitylang = !empty($entitytolang[$entity]) ? $entitytolang[$entity] : $objimport->array_import_label[0];
1130 print
'<td class="nowraponall hideonsmartphone" style="font-weight: normal">=> </td>';
1131 print
'<td class="nowraponall" style="font-weight: normal">';
1136 $selectforline =
'';
1137 $selectforline .=
'<select id="selectorderimport_'.($i + 1).
'" class="targetselectchange minwidth300" name="select_'.($i + 1).
'">';
1138 if (!empty($line[
"imported"])) {
1139 $selectforline .=
'<option value="-1"> </option>';
1141 $selectforline .=
'<option selected="" value="-1"> </option>';
1145 $codeselectedarray = array();
1146 foreach ($optionsall as $tmpcode => $tmpval) {
1148 if (!empty($tmpval[
'picto'])) {
1149 $label .=
img_picto(
'', $tmpval[
'picto'],
'class="pictofixedwidth"');
1151 $label .= $tmpval[
'required'] ?
'<strong>' :
'';
1152 $label .= $tmpval[
'label'];
1153 $label .= $tmpval[
'required'] ?
'*</strong>' :
'';
1155 $tablealias = preg_replace(
'/(\..*)$/i',
'', $tmpcode);
1156 $tablename = !empty($objimport->array_import_tables[0][$tablealias]) ? $objimport->array_import_tables[0][$tablealias] :
"";
1160 $filecolumn = ($i + 1);
1162 if (empty($objimport->array_import_convertvalue[0][$tmpcode])) {
1165 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromref') {
1166 $htmltext .= $langs->trans(
"DataComeFromIdFoundFromRef", $langs->transnoentitiesnoconv($entitylang)).
'<br>';
1168 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromcodeid') {
1169 $htmltext .= $langs->trans(
"DataComeFromIdFoundFromCodeId", $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$tmpcode][
'dict'])).
'<br>';
1173 $example = !empty($objimport->array_import_examplevalues[0][$tmpcode]) ? $objimport->array_import_examplevalues[0][$tmpcode] :
"";
1175 if (empty($objimport->array_import_convertvalue[0][$tmpcode])) {
1177 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.str_replace(
'"',
'', $example).
'</b><br>';
1180 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromref') {
1181 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.$langs->transnoentitiesnoconv(
"ExampleAnyRefFoundIntoElement", $entitylang).($example ?
' ('.$langs->transnoentitiesnoconv(
"Example").
': '.str_replace(
'"',
'', $example).
')' :
'').
'</b><br>';
1182 } elseif ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromcodeid') {
1183 $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>';
1184 } elseif ($example) {
1185 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.str_replace(
'"',
'', $example).
'</b><br>';
1189 if (!empty($objimport->array_import_regex[0][$tmpcode])) {
1190 $htmltext .= $langs->trans(
"FormatControlRule").
': <b>'.str_replace(
'"',
'', $objimport->array_import_regex[0][$tmpcode]).
'</b><br>';
1194 $htmltext .= $langs->trans(
"InformationOnTargetTables").
': <b>'.$tablename.
"->".preg_replace(
'/^.*\./',
'', $tmpcode).
"</b>";
1196 $labelhtml = $label.
' '.$form->textwithpicto(
'', $htmltext, 1,
'help',
'', 1);
1198 $selectforline .=
'<option value="'.$tmpcode.
'"';
1199 if ($modetoautofillmapping ==
'orderoftargets') {
1202 $selectforline .=
' selected';
1204 } elseif ($modetoautofillmapping ==
'guess') {
1208 if (preg_match(
'/^(.+)\((.+\..+)\)$/', $line[
'example1'], $regs)) {
1209 $tmpstring1 = $regs[1];
1210 $tmpstring2 = $regs[2];
1212 $tmpstring1 = $line[
'example1'];
1215 $tmpstring1 = strtolower(str_replace(
'*',
'', trim($tmpstring1)));
1216 $tmpstring2 = strtolower(str_replace(
'*',
'', trim($tmpstring2)));
1219 foreach ($tmpval[
'labelkeyarray'] as $tmpval2) {
1220 $labeltarget = $langs->transnoentities($tmpval2);
1222 if ($tmpstring1 && ($tmpstring1 == $tmpcode || $tmpstring1 == strtolower($labeltarget)
1223 || $tmpstring1 == strtolower(
dol_string_unaccent($labeltarget)) || $tmpstring1 == strtolower($tmpval2))) {
1224 if (empty($codeselectedarray[$code])) {
1225 $selectforline .=
' selected';
1226 $codeselectedarray[$code] = 1;
1229 } elseif ($tmpstring2 && ($tmpstring2 == $tmpcode || $tmpstring2 == strtolower($labeltarget)
1230 || $tmpstring2 == strtolower(
dol_string_unaccent($labeltarget)) || $tmpstring2 == strtolower($tmpval2))) {
1231 if (empty($codeselectedarray[$code])) {
1232 $selectforline .=
' selected';
1233 $codeselectedarray[$code] = 1;
1238 } elseif ($modetoautofillmapping ==
'session' && !empty($_SESSION[
'dol_array_match_file_to_database_select'])) {
1239 $tmpselectioninsession =
dolExplodeIntoArray($_SESSION[
'dol_array_match_file_to_database_select'],
',',
'=');
1241 if (!empty($tmpselectioninsession[(
string) ($i + 1)]) && $tmpselectioninsession[(
string) ($i + 1)] == $tmpcode) {
1242 $selectforline .=
' selected';
1244 $selectforline .=
' data-debug="'.$tmpcode.
'-'.$code.
'-'.$j.
'-'.(!empty($tmpselectioninsession[(
string) ($i + 1)]) ? $tmpselectioninsession[(string) ($i + 1)] :
"").
'"';
1246 $selectforline .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
1247 $selectforline .=
'>';
1248 $selectforline .= $label;
1249 $selectforline .=
'</options>';
1252 $selectforline .=
'</select>';
1253 $selectforline .=
ajax_combobox(
'selectorderimport_'.($i + 1));
1255 print $selectforline;
1260 print
'<td class="nowraponall" style="font-weight:normal; text-align:right">';
1263 $htmltext =
'<b><u>'.$langs->trans(
"FieldSource").
'</u></b><br>';
1265 $htmltext .= $langs->trans(
"DataComeFromFileFieldNb", $filecolumntoshow).
'<br>';
1267 print $form->textwithpicto(
'', $htmltext);
1278 print
'<tr class="liste_titre"><td colspan="2">'.$langs->trans(
"Note").
'</td></tr>';
1279 print
'<tr><td colspan="2"><div id="div-mandatory-target-fields-not-mapped"></div></td></tr>';
1285 if (!empty($conf->use_javascript_ajax)) {
1286 print
'<script type="text/javascript">'.
"\n";
1287 print
'var previousselectedvalueimport = "0";'.
"\n";
1288 print
'var previousselectedlabelimport = "0";'.
"\n";
1289 print
'var arrayofselectedvalues = [];'.
"\n";
1290 print
'var arrayoftargetfields = [];'.
"\n";
1291 print
'var arrayoftargetmandatoryfields = [];'.
"\n";
1295 foreach ($fieldstarget as $key => $val) {
1296 print
"arrayoftargetfields[".$tmpi.
"] = '".
dol_escape_js($langs->trans($val[
'label'])).
"'; ";
1297 if ($val[
'required']) {
1298 print
"arrayoftargetmandatoryfields[".$tmpi.
"] = '".
dol_escape_js($key).
"'; ";
1304 print
'$(document).ready(function () {'.
"\n";
1306 print
'setOptionsToDisabled();'.
"\n";
1307 print
'saveSelection();'.
"\n";
1309 print
'$(".targetselectchange").focus(function(){'.
"\n";
1310 print
' previousselectedvalueimport = $(this).val();'.
"\n";
1311 print
' previousselectedlabelimport = $(this).children("option:selected").text();'.
"\n";
1312 print
' console.log("previousselectedvalueimport="+previousselectedvalueimport)'.
"\n";
1319 print
'function setOptionsToDisabled() {'.
"\n";
1320 print
' console.log("Remove the disabled flag everywhere");'.
"\n";
1321 print
' $("select.targetselectchange").not($( this )).find(\'option\').prop("disabled", false);'.
"\n";
1322 print
' arrayofselectedvalues = [];'.
"\n";
1324 print
' $("select.targetselectchange").each(function(){'.
"\n";
1325 print
' id = $(this).attr(\'id\')'.
"\n";
1326 print
' value = $(this).val()'.
"\n";
1327 print
' console.log("a selected value has been found for component "+id+" = "+value);'.
"\n";
1328 print
' arrayofselectedvalues.push(value);'.
"\n";
1331 print
' console.log("List of all selected values arrayofselectedvalues");'.
"\n";
1332 print
' console.log(arrayofselectedvalues);'.
"\n";
1333 print
' console.log("Set the option to disabled for every entry that is currently selected somewhere else (so into arrayofselectedvalues)");'.
"\n";
1335 print
' $.each(arrayofselectedvalues, function(key, value) {'.
"\n";
1336 print
' if (value != -1) {'.
"\n";
1337 print
' console.log("Process key="+key+" value="+value+" to disable.");'.
"\n";
1338 print
' $("select.targetselectchange").find(\'option[value="\'+value+\'"]:not(:selected)\').prop("disabled", true);'.
"\n";
1344 print
'function saveSelection() {'.
"\n";
1346 print
' arrayselectedfields = [];'.
"\n";
1347 print
' arrayselectedfields.push(0);'.
"\n";
1349 print
' $.each( arrayofselectedvalues, function( key, value ) {'.
"\n";
1350 print
' if (value != -1) {'.
"\n";
1351 print
' arrayselectedfields.push(value);'.
"\n";
1352 print
' } else {'.
"\n";
1353 print
' arrayselectedfields.push(0);'.
"\n";
1357 print
" $.ajax({\n";
1358 print
" type: 'POST',\n";
1359 print
" dataType: 'json',\n";
1360 print
" url: '".dol_escape_js($_SERVER[
"PHP_SELF"]).
"?action=saveselectorder&token=".
newToken().
"',\n";
1361 print
" data: 'selectorder='+arrayselectedfields.toString(),\n";
1362 print
" success: function(){\n";
1363 print
" console.log('The selected fields have been saved into '+arrayselectedfields.toString());\n";
1368 print
' console.log("arrayselectedfields");';
1369 print
' console.log(arrayselectedfields);';
1370 print
' console.log("arrayoftargetmandatoryfields");';
1371 print
' console.log(arrayoftargetmandatoryfields);';
1372 print
" listtoshow = '';";
1373 print
" nbelement = arrayoftargetmandatoryfields.length
1374 for (let i = 0; i < nbelement; i++) {
1375 if (arrayoftargetmandatoryfields[i] && ! arrayselectedfields.includes(arrayoftargetmandatoryfields[i])) {
1376 console.log(arrayoftargetmandatoryfields[i]+' not mapped');
1377 listtoshow = listtoshow + (listtoshow ? ', ' : '') + '<b>' + arrayoftargetfields[i] + '*</b>';
1380 console.log(listtoshow);
1382 listtoshow = '".dol_escape_js(
img_warning($langs->trans(
"MandatoryTargetFieldsNotMapped")).
' '.$langs->trans(
"MandatoryTargetFieldsNotMapped")).
": ' + listtoshow;
1383 $('#div-mandatory-target-fields-not-mapped').html(listtoshow);
1385 $('#div-mandatory-target-fields-not-mapped').html('<span class=\"opacitymedium\">".
dol_escape_js($langs->trans(
"AllTargetMandatoryFieldsAreMapped")).
"</span>');
1392 print
'$(".targetselectchange").change(function(){'.
"\n";
1393 print
' setOptionsToDisabled();'.
"\n";
1395 print
' if(previousselectedlabelimport != "" && previousselectedvalueimport != -1) {'.
"\n";
1396 print
' let valuetochange = $(this).val(); '.
"\n";
1397 print
' $(".boxtdunused").each(function(){'.
"\n";
1398 print
' if ($(this).text().includes(valuetochange)){'.
"\n";
1399 print
' arraychild = $(this)[0].childNodes'.
"\n";
1400 print
' arraytexttomodify = arraychild[0].textContent.split(" ")'.
"\n";
1401 print
' arraytexttomodify[1] = previousselectedvalueimport '.
"\n";
1402 print
' textmodified = arraytexttomodify.join(" ") '.
"\n";
1403 print
' arraychild[0].textContent = textmodified'.
"\n";
1404 print
' arraychild[1].innerHTML = previousselectedlabelimport'.
"\n";
1408 print
' $(this).blur()'.
"\n";
1410 print
' saveSelection()'.
"\n";
1414 print
'</script>'.
"\n";
1420 print
'<div class="tabsAction">';
1422 if (count($array_match_file_to_database)) {
1423 if ($mandatoryfieldshavesource) {
1424 print
'<a class="butAction saveorderselect" href="import.php?step=5'.$param.
'&filetoimport='.urlencode($filetoimport).
'">'.$langs->trans(
"NextStep").
'</a>';
1426 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"SomeMandatoryFieldHaveNoSource")).
'">'.$langs->trans(
"NextStep").
'</a>';
1434 if (count($array_match_file_to_database)) {
1436 print
'<!-- Area to add new import profile -->'.
"\n";
1437 print
'<div class="marginbottomonly"><span class="opacitymedium">'.$langs->trans(
"SaveImportModel").
'</span></div>';
1439 print
'<form class="nocellnopadd" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1440 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1441 print
'<input type="hidden" name="action" value="add_import_model">';
1442 print
'<input type="hidden" name="step" value="'.$step.
'">';
1443 print
'<input type="hidden" name="format" value="'.$format.
'">';
1444 print
'<input type="hidden" name="datatoimport" value="'.$datatoimport.
'">';
1445 print
'<input type="hidden" name="filetoimport" value="'.$filetoimport.
'">';
1446 print
'<input type="hidden" name="hexa" value="'.$hexa.
'">';
1447 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1448 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1449 print
'<input type="hidden" name="page_y" value="">';
1450 print
'<input type="hidden" value="'.dol_escape_htmltag($separator).
'" name="separator">';
1451 print
'<input type="hidden" value="'.dol_escape_htmltag($enclosure).
'" name="enclosure">';
1453 print
'<div class="div-table-responsive-no-min">';
1454 print
'<table summary="selectofimportprofil" class="noborder centpercent">';
1455 print
'<tr class="liste_titre">';
1456 print
'<td>'.$langs->trans(
"ImportModelName").
'</td>';
1457 print
'<td>'.$langs->trans(
"Visibility").
'</td>';
1461 $nameofimportprofile = str_replace(
' ',
'-', $langs->trans(
"ImportProfile").
' '.$titleofmodule.
' '.
dol_print_date(
dol_now(
'gmt'),
'dayxcard'));
1463 $nameofimportprofile = $import_name;
1466 print
'<tr class="oddeven">';
1467 print
'<td><input name="import_name" class="minwidth300" value="'.$nameofimportprofile.
'"></td>';
1469 $arrayvisibility = array(
'private' => $langs->trans(
"Private"),
'all' => $langs->trans(
"Everybody"));
1470 print $form->selectarray(
'visibility', $arrayvisibility,
'private');
1472 print
'<td class="right">';
1473 print
'<input type="submit" class="button smallpaddingimp reposition" value="'.$langs->trans(
"SaveImportProfile").
'">';
1477 $sql =
"SELECT rowid, label, fk_user, entity";
1478 $sql .=
" FROM ".MAIN_DB_PREFIX.
"import_model";
1479 $sql .=
" WHERE type = '".$db->escape($datatoimport).
"'";
1481 $sql .=
" AND fk_user IN (0, ".((int) $user->id).
")";
1483 $sql .=
" ORDER BY rowid";
1485 $resql = $db->query(
$sql);
1487 $num = $db->num_rows($resql);
1489 $tmpuser =
new User($db);
1493 $obj = $db->fetch_object($resql);
1495 print
'<tr class="oddeven"><td>';
1498 print
'<td class="tdoverflowmax150">';
1499 if (empty($obj->fk_user)) {
1500 print $langs->trans(
"Everybody");
1502 $tmpuser->fetch($obj->fk_user);
1503 print $tmpuser->getNomUrl(-1);
1506 print
'<td class="right">';
1507 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?step='.$step.$param.
'&action=deleteprof&token='.
newToken().
'&id='.$obj->rowid.
'&filetoimport='.urlencode($filetoimport).
'">';
1525 if ($step == 5 && $datatoimport) {
1526 $max_execution_time_for_importexport = (!
getDolGlobalString(
'IMPORT_MAX_EXECUTION_TIME') ? 300 : $conf->global->IMPORT_MAX_EXECUTION_TIME);
1527 $max_time = @ini_get(
"max_execution_time");
1528 if ($max_time && $max_time < $max_execution_time_for_importexport) {
1529 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.");
1530 @ini_set(
"max_execution_time", $max_execution_time_for_importexport);
1534 $list = $objmodelimport->listOfAvailableImportFormat($db);
1537 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
1538 $file =
"import_".$model.
".modules.php";
1539 $classname =
"Import".ucfirst($model);
1540 require_once $dir.$file;
1541 $obj =
new $classname($db, $datatoimport);
1542 if ($model ==
'csv') {
1543 $obj->separator = $separator_used;
1544 $obj->enclosure = $enclosure;
1548 $fieldssource = array();
1549 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport, $langs);
1553 $arrayrecord = $obj->import_read_record();
1556 foreach ($arrayrecord as $key => $val) {
1557 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 24);
1560 $obj->import_close_file();
1563 $nboflines = $obj->import_get_nb_of_lines($conf->import->dir_temp.
'/'.$filetoimport);
1565 $param =
'&leftmenu=import&format='.urlencode($format).
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport).
'&nboflines='.urlencode($nboflines).
'&separator='.urlencode($separator).
'&enclosure='.urlencode($enclosure);
1567 if ($excludefirstline) {
1568 $param .=
'&excludefirstline='.urlencode($excludefirstline);
1571 $param .=
'&endatlinenb='.urlencode($endatlinenb);
1573 if (!empty($updatekeys)) {
1574 $param .=
'&updatekeys[]='.implode(
'&updatekeys[]=', $updatekeys);
1577 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
1582 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?'.$param2.
'" method="POST">';
1583 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1584 print
'<input type="hidden" name="step" value="5">';
1585 print
'<input type="hidden" name="action" value="launchsimu">';
1589 print
'<div class="underbanner clearboth"></div>';
1590 print
'<div class="fichecenter">';
1592 print
'<table width="100%" class="border tableforfield">';
1595 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
1597 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
1599 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
1600 $titleofmodule = $langs->trans(
"ProductOrService");
1602 print $titleofmodule;
1606 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
1608 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
1609 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
1610 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
1611 print $objimport->array_import_label[0];
1617 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
1619 print
'<div class="underbanner clearboth"></div>';
1620 print
'<div class="fichecenter">';
1621 print
'<table width="100%" class="border tableforfield">';
1624 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
1626 $text = $objmodelimport->getDriverDescForKey($format);
1628 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
1632 if ($model ==
'csv') {
1633 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
1636 print
' '.$langs->trans(
"Enclosure").
' : '.
dol_escape_htmltag($enclosure);
1641 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
1643 $modulepart =
'import';
1644 $relativepath =
GETPOST(
'filetoimport');
1645 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
1646 print
img_mime($file,
'',
'pictofixedwidth');
1647 print $filetoimport;
1648 print
img_picto($langs->trans(
"Download"),
'download',
'class="paddingleft opacitymedium"');
1654 print $langs->trans(
"NbOfSourceLines");
1661 print $langs->trans(
"ImportFromToLine");
1663 if ($action ==
'launchsimu') {
1664 print
'<input type="number" class="maxwidth50 right" name="excludefirstlinebis" disabled="disabled" value="'.$excludefirstline.
'">';
1665 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1667 print
'<input type="number" class="maxwidth50 right" name="excludefirstline" value="'.$excludefirstline.
'">';
1668 print $form->textwithpicto(
"", $langs->trans(
"SetThisValueTo2ToExcludeFirstLine"));
1671 if ($action ==
'launchsimu') {
1672 print
'<input type="text" class="maxwidth50" name="endatlinenbbis" disabled="disabled" value="'.$endatlinenb.
'">';
1673 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1675 print
'<input type="text" class="maxwidth50" name="endatlinenb" value="'.$endatlinenb.
'">';
1676 print $form->textwithpicto(
"", $langs->trans(
"KeepEmptyToGoToEndOfFile"));
1678 if ($action ==
'launchsimu') {
1679 print
' <a href="'.$_SERVER[
"PHP_SELF"].
'?step=5'.$param.
'">'.$langs->trans(
"Modify").
'</a>';
1681 if ($excludefirstline == 2) {
1682 print $form->textwithpicto(
"", $langs->trans(
"WarningFirstImportedLine", $excludefirstline), 1,
'warning',
"warningexcludefirstline");
1684 $( document ).ready(function() {
1685 $("input[name=\'excludefirstline\']").on("change",function(){
1686 if($(this).val() <= 1){
1687 $(".warningexcludefirstline").hide();
1689 $(".warningexcludefirstline").show();
1699 print $form->textwithpicto($langs->trans(
"KeysToUseForUpdates"), $langs->trans(
"SelectPrimaryColumnsForUpdateAttempt"));
1701 if ($action ==
'launchsimu') {
1702 if (count($updatekeys)) {
1703 print $form->multiselectarray(
'updatekeysbis', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0,
'', 1,
'80%',
'disabled');
1705 print
'<span class="opacitymedium">'.$langs->trans(
"NoUpdateAttempt").
'</span> -';
1707 foreach ($updatekeys as $val) {
1708 print
'<input type="hidden" name="updatekeys[]" value="'.$val.
'">';
1710 print
' <a href="'.$_SERVER[
"PHP_SELF"].
'?step=5'.$param.
'">'.$langs->trans(
"Modify").
'</a>';
1712 if (is_array($objimport->array_import_updatekeys[0]) && count($objimport->array_import_updatekeys[0])) {
1713 print $form->multiselectarray(
'updatekeys', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0,
'', 1,
'80%');
1716 print
'<span class="opacitymedium">'.$langs->trans(
"UpdateNotYetSupportedForThisImport").
'</span>';
1728 print
load_fiche_titre($langs->trans(
"InformationOnTargetTables"),
'',
'file-import');
1730 print
'<div class="underbanner clearboth"></div>';
1731 print
'<div class="fichecenter">';
1733 print
'<table width="100%" class="border tableforfield">';
1736 print
'<tr><td class="titlefieldcreate">';
1737 print $langs->trans(
"TablesTarget");
1739 $listtables = array();
1740 $sort_array_match_file_to_database = $array_match_file_to_database;
1741 foreach ($array_match_file_to_database as $code => $label) {
1743 if ($code > count($fieldssource)) {
1747 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
1748 $listtables[$alias] = $objimport->array_import_tables[0][$alias];
1750 if (count($listtables)) {
1753 foreach ($listtables as $val) {
1772 print $langs->trans(
"Error");
1778 print $langs->trans(
"FieldsTarget").
'</td><td>';
1779 $listfields = array();
1782 $sort_array_match_file_to_database = $array_match_file_to_database;
1783 ksort($sort_array_match_file_to_database);
1785 foreach ($sort_array_match_file_to_database as $code => $label) {
1788 if ($code > count($fieldssource)) {
1792 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
1793 $listfields[$i] =
'<span class="nowrap">'.$langs->trans(
"Column").
' '.
num2Alpha($code - 1).
' -> '.$label.
'</span>';
1795 print count($listfields) ? (implode(
', ', $listfields)) : $langs->trans(
"Error");
1804 if ($action !=
'launchsimu') {
1806 print
'<br><span class="opacitymedium">';
1807 print $langs->trans(
"NowClickToTestTheImport", $langs->transnoentitiesnoconv(
"RunSimulateImportFile")).
'</span><br>';
1811 print
'<div class="center">';
1812 if ($user->hasRight(
'import',
'run')) {
1813 print
'<input type="submit" class="butAction" value="'.$langs->trans(
"RunSimulateImportFile").
'">';
1815 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunSimulateImportFile").
'</a>';
1820 $arrayoferrors = array();
1821 $arrayofwarnings = array();
1822 $maxnboferrors = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_ERRORS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_ERRORS;
1823 $maxnbofwarnings = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_WARNINGS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_WARNINGS;
1835 $pathfile = $conf->import->dir_temp.
'/'.$filetoimport;
1836 $result = $obj->import_open_file($pathfile, $langs);
1838 global $tablewithentity_cache;
1839 $tablewithentity_cache = array();
1844 while (($sourcelinenb < $nboflines) && !$endoffile) {
1848 $arrayrecord = $obj->import_read_record();
1849 if ($arrayrecord ===
false) {
1850 $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');
1854 if ($excludefirstline && ($sourcelinenb < $excludefirstline)) {
1857 if ($endatlinenb && ($sourcelinenb > $endatlinenb)) {
1861 $parameters = array(
1863 'datatoimport' => $datatoimport,
1865 'arrayrecord' => $arrayrecord,
1866 'array_match_file_to_database' => $array_match_file_to_database,
1867 'objimport' => $objimport,
1868 'fieldssource' => $fieldssource,
1869 'importid' => $importid,
1870 'updatekeys' => $updatekeys,
1871 'arrayoferrors' => &$arrayoferrors,
1872 'arrayofwarnings' => &$arrayofwarnings,
1876 $reshook = $hookmanager->executeHooks(
'ImportInsert', $parameters);
1878 $arrayoferrors[$sourcelinenb][] = [
1879 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
1883 if (empty($reshook)) {
1885 $result = $obj->import_insert($arrayrecord, $array_match_file_to_database, $objimport, count($fieldssource), $importid, $updatekeys);
1887 if (count($obj->errors)) {
1888 $arrayoferrors[$sourcelinenb] = $obj->errors;
1890 if (count($obj->warnings)) {
1891 $arrayofwarnings[$sourcelinenb] = $obj->warnings;
1893 if (!count($obj->errors) && !count($obj->warnings)) {
1899 $obj->import_close_file();
1901 print $langs->trans(
"ErrorFailedToOpenFile", $pathfile);
1908 if (!empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0])) {
1910 foreach ($objimport->array_import_run_sql_after[0] as $sqlafterimport) {
1912 $resqlafterimport = $db->query($sqlafterimport);
1913 if (!$resqlafterimport) {
1914 $arrayoferrors[
'none'][] = array(
'lib' => $langs->trans(
"Error running final request: ".$sqlafterimport));
1923 if (!count($arrayoferrors) && !count($arrayofwarnings)) {
1925 print
'<div class="info">';
1926 print
'<div class=""><b>'.$langs->trans(
"ResultOfSimulationNoError").
'</b></div>';
1927 print $langs->trans(
"NbInsertSim", empty($obj->nbinsert) ? 0 : $obj->nbinsert).
'<br>';
1928 print $langs->trans(
"NbUpdateSim", empty($obj->nbupdate) ? 0 : $obj->nbupdate).
'<br>';
1933 print
'<div class="warning">';
1934 print $langs->trans(
"NbOfLinesOK", $nbok).
'...<br>';
1941 if (count($arrayoferrors)) {
1942 print
img_error().
' <b>'.$langs->trans(
"ErrorsOnXLines", count($arrayoferrors)).
'</b><br>';
1943 print
'<table width="100%" class="border"><tr><td>';
1944 foreach ($arrayoferrors as $key => $val) {
1946 if ($nboferrors > $maxnboferrors) {
1947 print $langs->trans(
"TooMuchErrors", (count($arrayoferrors) - $nboferrors)).
"<br>";
1951 foreach ($val as $i => $err) {
1952 print
' > '.dol_escape_htmltag($err[
'lib']).
'<br>';
1955 print
'</td></tr></table>';
1961 if (count($arrayofwarnings)) {
1962 print
img_warning().
' <b>'.$langs->trans(
"WarningsOnXLines", count($arrayofwarnings)).
'</b><br>';
1963 print
'<table width="100%" class="border"><tr><td>';
1964 foreach ($arrayofwarnings as $key => $val) {
1966 if ($nbofwarnings > $maxnbofwarnings) {
1967 print $langs->trans(
"TooMuchWarnings", (count($arrayofwarnings) - $nbofwarnings)).
"<br>";
1971 foreach ($val as $i => $err) {
1972 print
' > '.dol_escape_htmltag($err[
'lib']).
'<br>';
1975 print
'</td></tr></table>';
1982 print
'<div class="center">';
1983 print
'<span class="opacitymedium">'.$langs->trans(
"NowClickToRunTheImport", $langs->transnoentitiesnoconv(
"RunImportFile")).
'</span><br>';
1992 print
'<div class="center">';
1993 if ($user->hasRight(
'import',
'run')) {
1994 if (empty($nboferrors)) {
1995 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/imports/import.php?leftmenu=import&step=6&importid='.$importid.$param.
'">'.$langs->trans(
"RunImportFile").
'</a>';
1999 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"CorrectErrorBeforeRunningImport")).
'">'.$langs->trans(
"RunImportFile").
'</a>';
2002 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunSimulateImportFile").
'</a>';
2004 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunImportFile").
'</a>';
2014 if ($step == 6 && $datatoimport) {
2015 $max_execution_time_for_importexport = (!
getDolGlobalString(
'IMPORT_MAX_EXECUTION_TIME') ? 300 : $conf->global->IMPORT_MAX_EXECUTION_TIME);
2016 $max_time = @ini_get(
"max_execution_time");
2017 if ($max_time && $max_time < $max_execution_time_for_importexport) {
2018 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.");
2019 @ini_set(
"max_execution_time", $max_execution_time_for_importexport);
2023 $list = $objmodelimport->listOfAvailableImportFormat($db);
2024 $importid =
GETPOST(
"importid",
'alphanohtml');
2028 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
2029 $file =
"import_".$model.
".modules.php";
2030 $classname =
"Import".ucfirst($model);
2031 require_once $dir.$file;
2032 $obj =
new $classname($db, $datatoimport);
2033 if ($model ==
'csv') {
2034 $obj->separator = $separator_used;
2035 $obj->enclosure = $enclosure;
2039 $fieldssource = array();
2040 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport, $langs);
2043 $arrayrecord = $obj->import_read_record();
2046 foreach ($arrayrecord as $key => $val) {
2047 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 24);
2050 $obj->import_close_file();
2055 $param =
'&format='.$format.
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport).
'&nboflines='.urlencode($nboflines);
2056 if ($excludefirstline) {
2057 $param .=
'&excludefirstline='.urlencode($excludefirstline);
2060 $param .=
'&endatlinenb='.urlencode($endatlinenb);
2063 $param .=
'&separator='.urlencode($separator);
2066 $param .=
'&enclosure='.urlencode($enclosure);
2069 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
2075 print
'<div class="underbanner clearboth"></div>';
2076 print
'<div class="fichecenter">';
2078 print
'<table width="100%" class="border">';
2081 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
2083 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
2085 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
2086 $titleofmodule = $langs->trans(
"ProductOrService");
2088 print $titleofmodule;
2092 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
2094 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
2095 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
2096 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
2097 print $objimport->array_import_label[0];
2103 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
2105 print
'<div class="underbanner clearboth"></div>';
2106 print
'<div class="fichecenter">';
2107 print
'<table width="100%" class="border">';
2110 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
2112 $text = $objmodelimport->getDriverDescForKey($format);
2114 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
2118 if ($model ==
'csv') {
2119 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
2121 print $langs->trans(
"Separator").
' : ';
2122 print htmlentities($separator);
2123 print
' '.$langs->trans(
"Enclosure").
' : ';
2124 print htmlentities($enclosure);
2129 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
2131 $modulepart =
'import';
2132 $relativepath =
GETPOST(
'filetoimport');
2133 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
2134 print
img_mime($file,
'',
'pictofixedwidth');
2135 print $filetoimport;
2141 print $langs->trans(
"NbOfSourceLines");
2148 print $langs->trans(
"ImportFromLine");
2150 print
'<input type="text" size="4" name="excludefirstline" disabled="disabled" value="'.$excludefirstline.
'">';
2155 print $langs->trans(
"EndAtLineNb");
2157 print
'<input type="text" size="4" name="endatlinenb" disabled="disabled" value="'.$endatlinenb.
'">';
2165 print
'<b>'.$langs->trans(
"InformationOnTargetTables").
'</b>';
2166 print
'<div class="underbanner clearboth"></div>';
2167 print
'<div class="fichecenter">';
2168 print
'<table class="border centpercent">';
2171 print
'<tr><td width="25%">';
2172 print $langs->trans(
"TablesTarget");
2174 $listtables = array();
2175 foreach ($array_match_file_to_database as $code => $label) {
2177 if ($code > count($fieldssource)) {
2181 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
2182 $listtables[$alias] = $objimport->array_import_tables[0][$alias];
2184 if (count($listtables)) {
2186 foreach ($listtables as $val) {
2205 print $langs->trans(
"Error");
2211 print $langs->trans(
"FieldsTarget").
'</td><td>';
2212 $listfields = array();
2214 $sort_array_match_file_to_database = $array_match_file_to_database;
2215 ksort($sort_array_match_file_to_database);
2217 foreach ($sort_array_match_file_to_database as $code => $label) {
2220 if ($code > count($fieldssource)) {
2224 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
2225 $listfields[$i] = $langs->trans(
"Field").
' '.$code.
'->'.$label;
2227 print count($listfields) ? (implode(
', ', $listfields)) : $langs->trans(
"Error");
2234 $arrayoferrors = array();
2235 $arrayofwarnings = array();
2236 $maxnboferrors = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_ERRORS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_ERRORS;
2237 $maxnbofwarnings = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_WARNINGS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_WARNINGS;
2249 $pathfile = $conf->import->dir_temp.
'/'.$filetoimport;
2250 $result = $obj->import_open_file($pathfile, $langs);
2252 global $tablewithentity_cache;
2253 $tablewithentity_cache = array();
2257 while ($sourcelinenb < $nboflines && !$endoffile) {
2259 $arrayrecord = $obj->import_read_record();
2260 if ($arrayrecord ===
false) {
2261 $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');
2265 if ($excludefirstline && ($sourcelinenb < $excludefirstline)) {
2268 if ($endatlinenb && ($sourcelinenb > $endatlinenb)) {
2272 $parameters = array(
2274 'datatoimport' => $datatoimport,
2276 'arrayrecord' => $arrayrecord,
2277 'array_match_file_to_database' => $array_match_file_to_database,
2278 'objimport' => $objimport,
2279 'fieldssource' => $fieldssource,
2280 'importid' => $importid,
2281 'updatekeys' => $updatekeys,
2282 'arrayoferrors' => &$arrayoferrors,
2283 'arrayofwarnings' => &$arrayofwarnings,
2287 $reshook = $hookmanager->executeHooks(
'ImportInsert', $parameters);
2289 $arrayoferrors[$sourcelinenb][] = [
2290 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
2294 if (empty($reshook)) {
2296 $result = $obj->import_insert($arrayrecord, $array_match_file_to_database, $objimport, count($fieldssource), $importid, $updatekeys);
2298 if (count($obj->errors)) {
2299 $arrayoferrors[$sourcelinenb] = $obj->errors;
2301 if (count($obj->warnings)) {
2302 $arrayofwarnings[$sourcelinenb] = $obj->warnings;
2305 if (!count($obj->errors) && !count($obj->warnings)) {
2310 $reshook = $hookmanager->executeHooks(
'AfterImportInsert', $parameters);
2312 $arrayoferrors[$sourcelinenb][] = [
2313 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
2318 $obj->import_close_file();
2320 print $langs->trans(
"ErrorFailedToOpenFile", $pathfile);
2323 if (count($arrayoferrors) > 0) {
2330 if (!empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0])) {
2332 foreach ($objimport->array_import_run_sql_after[0] as $sqlafterimport) {
2334 $resqlafterimport = $db->query($sqlafterimport);
2335 if (!$resqlafterimport) {
2336 $arrayoferrors[
'none'][] = array(
'lib' => $langs->trans(
"Error running final request: ".$sqlafterimport));
2354 print
'<div class="info">';
2355 print $langs->trans(
"NbOfLinesImported", $nbok).
'</b><br>';
2356 print $langs->trans(
"NbInsert", empty($obj->nbinsert) ? 0 : $obj->nbinsert).
'<br>';
2357 print $langs->trans(
"NbUpdate", empty($obj->nbupdate) ? 0 : $obj->nbupdate).
'<br>';
2359 print
'<div class="center">';
2360 print $langs->trans(
"FileWasImported", $importid).
'<br>';
2361 print
'<span class="opacitymedium">'.$langs->trans(
"YouCanUseImportIdToFindRecord", $importid).
'</span><br>';
2384 global $conf, $langs;
2388 if ($key ==
'none') {
2390 print
"\n\n<!-- Box_no-key start-->\n";
2391 print
'<div class="box boximport" style="padding:0;">'.
"\n";
2392 print
'<table summary="boxtable_no-key" class="centpercent nobordernopadding">'.
"\n";
2394 print
"\n\n<!-- Box ".$pos.
" start -->\n";
2395 print
'<div class="box boximport" style="padding: 0;" id="boxto_'.$pos.
'">'.
"\n";
2397 print
'<table summary="boxtable'.$pos.
'" class="nobordernopadding centpercent tableimport">'.
"\n";
2400 if (($pos && $pos > count($fieldssource)) && (!isset($fieldssource[$pos][
"imported"]))) {
2410 } elseif ($key ==
'none') {
2411 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
2412 print
'<td class="nocellnopadding" width="16" style="font-weight: normal">';
2415 print
'<td style="font-weight: normal">';
2421 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
2422 print
'<td class="nocellnopadding" width="16" style="font-weight: normal">';
2425 print
img_picto($langs->trans(
"Column").
' '.
num2Alpha($pos - 1),
'file',
'class="pictofixedwith"');
2427 if (isset($fieldssource[$pos][
'imported']) && $fieldssource[$pos][
'imported'] ==
false) {
2428 print
'<td class="nowraponall boxtdunused" style="font-weight: normal">';
2430 print
'<td class="nowraponall tdoverflowmax500" style="font-weight: normal">';
2432 print $langs->trans(
"Column").
' '.
num2Alpha($pos - 1).
' (#'.$pos.
')';
2433 if (empty($fieldssource[$pos][
'example1'])) {
2434 $example = $fieldssource[$pos][
'label'];
2436 $example = $fieldssource[$pos][
'example1'];
2440 $example = mb_convert_encoding($example,
'UTF-8',
'ISO-8859-1');
2444 print
'<i class="opacitymedium">'.dol_escape_htmltag($example).
'</i>';
2453 print
"<!-- Box end -->\n\n";
2466 $i = count($fieldssource) + 1;
2469 foreach ($listofkey as $key => $val) {
2470 $maxkey = max($maxkey, $key);
2473 while ($i <= $maxkey) {
2474 if (empty($listofkey[$i])) {
2496 if ($position == count($array)) {
2497 $ret = $array + $insertArray;
2500 foreach ($array as $key => $value) {
2501 if ($position == $i++) {
2502 $ret += $insertArray;
2505 $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.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
dol_filemtime($pathoffile)
Return time of a file.
dol_filesize($pathoffile)
Return size of a file.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Check validity of a file upload from an GUI page, and move it to its final destination.
dol_count_nb_of_line($file)
Count number of lines in a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
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.
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information in HTML 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_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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.
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.