27require_once
'../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/imports/class/import.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/modules/import/modules_import.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/import.lib.php';
37$langs->loadLangs(array(
'exports',
'compta',
'errors'));
45 'invoice_line' =>
'bill',
47 'order_line' =>
'order',
49 'propal_line' =>
'propal',
50 'intervention' =>
'intervention',
51 'inter_line' =>
'intervention',
53 'member_type' =>
'group',
54 'subscription' =>
'payment',
55 'payment' =>
'payment',
57 'tax_type' =>
'generic',
59 'account' =>
'account',
60 'product' =>
'product',
61 'virtualproduct'=>
'product',
62 'subproduct' =>
'product',
63 'product_supplier_ref' =>
'product',
65 'warehouse' =>
'stock',
67 'stockbatch' =>
'stock',
68 'category' =>
'category',
69 'shipment' =>
'sending',
70 'shipment_line'=>
'sending',
71 'reception'=>
'sending',
72 'reception_line'=>
'sending',
73 'expensereport'=>
'trip',
74 'expensereport_line'=>
'trip',
75 'holiday' =>
'holiday',
76 'contract_line' =>
'contract',
77 'translation' =>
'generic',
85 'company' =>
'Company',
86 'contact' =>
'Contact',
88 'invoice_line' =>
'InvoiceLine',
90 'order_line' =>
'OrderLine',
91 'propal' =>
'Proposal',
92 'propal_line' =>
'ProposalLine',
93 'intervention' =>
'Intervention',
94 'inter_line' =>
'InterLine',
96 'member_type' =>
'MemberType',
97 'subscription' =>
'Subscription',
98 'tax' =>
'SocialContribution',
99 'tax_type' =>
'DictionarySocialContributions',
100 'account' =>
'BankTransactions',
101 'payment' =>
'Payment',
102 'product' =>
'Product',
103 'virtualproduct' =>
'AssociatedProducts',
104 'subproduct' =>
'SubProduct',
105 'product_supplier_ref' =>
'SupplierPrices',
106 'service' =>
'Service',
108 'movement' =>
'StockMovement',
110 'stockbatch' =>
'StockDetailPerBatch',
111 'warehouse' =>
'Warehouse',
112 'category' =>
'Category',
114 'trip' =>
'TripsAndExpenses',
115 'shipment' =>
'Shipments',
116 'shipment_line'=>
'ShipmentLine',
117 'project' =>
'Projects',
118 'projecttask' =>
'Tasks',
119 'task_time' =>
'TaskTimeSpent',
121 'expensereport'=>
'ExpenseReport',
122 'expensereport_line'=>
'ExpenseReportLine',
123 'holiday' =>
'TitreRequestCP',
124 'contract' =>
'Contract',
125 'contract_line'=>
'ContractLine',
126 'translation' =>
'Translation',
128 'bomline' =>
'BOMLine'
131$datatoimport =
GETPOST(
'datatoimport');
133$filetoimport =
GETPOST(
'filetoimport');
134$action =
GETPOST(
'action',
'alpha');
135$confirm =
GETPOST(
'confirm',
'alpha');
137$import_name =
GETPOST(
'import_name');
139$importmodelid =
GETPOST(
'importmodelid',
'int');
140$excludefirstline = (
GETPOST(
'excludefirstline') ?
GETPOST(
'excludefirstline') : 2);
141$endatlinenb = (
GETPOST(
'endatlinenb') ?
GETPOST(
'endatlinenb') :
'');
142$updatekeys = (
GETPOST(
'updatekeys',
'array') ?
GETPOST(
'updatekeys',
'array') : array());
143$separator = (
GETPOST(
'separator',
'alphanohtml') ?
GETPOST(
'separator',
'alphanohtml', 3) :
'');
144$enclosure = (
GETPOST(
'enclosure',
'nohtml') ?
GETPOST(
'enclosure',
'nohtml') :
'"');
145$charset =
GETPOST(
'charset',
'aZ09');
146$separator_used = str_replace(
'\t',
"\t", $separator);
148$objimport =
new Import($db);
149$objimport->load_arrays($user, ($step == 1 ?
'' : $datatoimport));
153$form =
new Form($db);
158if (empty($array_match_file_to_database)) {
159 $serialized_array_match_file_to_database = isset($_SESSION[
"dol_array_match_file_to_database_select"]) ? $_SESSION[
"dol_array_match_file_to_database_select"] :
'';
160 $array_match_file_to_database = array();
161 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
162 foreach ($fieldsarray as $elem) {
163 $tabelem = explode(
'=', $elem, 2);
165 $val = (isset($tabelem[1]) ? $tabelem[1] :
'');
167 $array_match_file_to_database[$key] = $val;
212if ($action ==
'deleteprof') {
214 $objimport->fetch(
GETPOST(
"id",
'int'));
215 $result = $objimport->delete($user);
220if ($action ==
'add_import_model') {
224 foreach ($array_match_file_to_database as $key => $val) {
228 $hexa .= $key.
'='.$val;
231 $objimport->model_name = $import_name;
232 $objimport->datatoimport = $datatoimport;
233 $objimport->hexa = $hexa;
234 $objimport->fk_user = (
GETPOST(
'visibility',
'aZ09') ==
'all' ? 0 : $user->id);
236 $result = $objimport->create($user);
238 setEventMessages($langs->trans(
"ImportModelSaved", $objimport->model_name),
null,
'mesgs');
241 $langs->load(
"errors");
242 if ($objimport->errno ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
243 setEventMessages($langs->trans(
"ErrorImportDuplicateProfil"),
null,
'errors');
249 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"ImportModelName")),
null,
'errors');
253if ($step == 3 && $datatoimport) {
254 if (
GETPOST(
'sendit') && !empty($conf->global->MAIN_UPLOAD_DOC)) {
258 $fullpath = $conf->import->dir_temp.
"/".$nowyearmonth.
'-'.$_FILES[
'userfile'][
'name'];
260 dol_syslog(
"File ".$fullpath.
" was added for import");
262 $langs->load(
"errors");
268 if ($action ==
'confirm_deletefile' && $confirm ==
'yes') {
269 $langs->load(
"other");
271 $param =
'&datatoimport='.urlencode($datatoimport).
'&format='.urlencode($format);
272 if ($excludefirstline) {
273 $param .=
'&excludefirstline='.urlencode($excludefirstline);
276 $param .=
'&endatlinenb='.urlencode($endatlinenb);
279 $file = $conf->import->dir_temp.
'/'.
GETPOST(
'urlfile');
286 Header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?step='.$step.$param);
291if ($step == 4 && $action ==
'select_model') {
293 $_SESSION[
"dol_array_match_file_to_database"] =
'';
294 $serialized_array_match_file_to_database =
'';
295 $array_match_file_to_database = array();
299 $result = $objimport->fetch($importmodelid);
301 $serialized_array_match_file_to_database = $objimport->hexa;
302 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
303 foreach ($fieldsarray as $elem) {
304 $tabelem = explode(
'=', $elem);
308 $array_match_file_to_database[$key] = $val;
311 $_SESSION[
"dol_array_match_file_to_database"] = $serialized_array_match_file_to_database;
312 $_SESSION[
'dol_array_match_file_to_database_select'] = $_SESSION[
"dol_array_match_file_to_database"];
315if ($action ==
'saveselectorder') {
317 $serialized_array_match_file_to_database =
'';
319 $selectorder = explode(
",",
GETPOST(
'selectorder'));
320 $fieldtarget = $fieldstarget = $objimport->array_import_fields[0];
321 foreach ($selectorder as $key => $code) {
322 $serialized_array_match_file_to_database .= $key.
'='.$code;
323 $serialized_array_match_file_to_database .=
',';
325 $serialized_array_match_file_to_database = substr($serialized_array_match_file_to_database, 0, -1);
326 dol_syslog(
'dol_array_match_file_to_database_select='.$serialized_array_match_file_to_database);
327 $_SESSION[
"dol_array_match_file_to_database_select"] = $serialized_array_match_file_to_database;
339$help_url =
'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones';
343if ($step == 1 || !$datatoimport) {
345 $serialized_array_match_file_to_database =
'';
346 $array_match_file_to_database = array();
347 $_SESSION[
"dol_array_match_file_to_database"] =
'';
348 $_SESSION[
"dol_array_match_file_to_database_select"] =
'';
351 if ($excludefirstline) {
352 $param .=
'&excludefirstline='.urlencode($excludefirstline);
355 $param .=
'&endatlinenb='.urlencode($endatlinenb);
358 $param .=
'&separator='.urlencode($separator);
361 $param .=
'&enclosure='.urlencode($enclosure);
364 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
370 print
'<div class="opacitymedium">'.$langs->trans(
"SelectImportDataSet").
'</div><br>';
373 print
'<div class="div-table-responsive-no-min">';
374 print
'<table class="noborder centpercent">';
375 print
'<tr class="liste_titre">';
376 print
'<td>'.$langs->trans(
"Module").
'</td>';
377 print
'<td>'.$langs->trans(
"ImportableDatas").
'</td>';
378 print
'<td> </td>';
381 if (count($objimport->array_import_module)) {
382 $sortedarrayofmodules =
dol_sort_array($objimport->array_import_module,
'position_of_profile',
'asc', 0, 0, 1);
383 foreach ($sortedarrayofmodules as $key => $value) {
385 print
'<tr class="oddeven"><td>';
386 $titleofmodule = $objimport->array_import_module[$key][
'module']->getName();
388 if (in_array($objimport->array_import_code[$key], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
389 $titleofmodule = $langs->trans(
"ProductOrService");
391 print $titleofmodule;
393 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[$key]);
394 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
395 print
img_object($objimport->array_import_module[$key][
'module']->getName(), $entityicon).
' ';
396 print $objimport->array_import_label[$key];
397 print
'</td><td style="text-align: right">';
398 if ($objimport->array_import_perms[$key]) {
399 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>';
401 print $langs->trans(
"NotEnoughPermissions");
406 print
'<tr><td class="oddeven" colspan="3">'.$langs->trans(
"NoImportableData").
'</td></tr>';
416if ($step == 2 && $datatoimport) {
417 $param =
'&datatoimport='.urlencode($datatoimport);
418 if ($excludefirstline) {
419 $param .=
'&excludefirstline='.urlencode($excludefirstline);
422 $param .=
'&endatlinenb='.urlencode($endatlinenb);
425 $param .=
'&separator='.urlencode($separator);
428 $param .=
'&enclosure='.urlencode($enclosure);
431 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
437 print
'<div class="underbanner clearboth"></div>';
438 print
'<div class="fichecenter">';
440 print
'<table class="border tableforfield centpercent">';
443 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
445 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
447 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
448 $titleofmodule = $langs->trans(
"ProductOrService");
450 print $titleofmodule;
454 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
456 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
457 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
458 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
459 print $objimport->array_import_label[0];
467 print
'<form name="userfile" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" METHOD="POST">';
468 print
'<input type="hidden" name="token" value="'.newToken().
'">';
472 print
'<span class="opacitymedium">';
473 $s = $langs->trans(
"ChooseFormatOfFileToImport",
'{s1}');
474 $s = str_replace(
'{s1}',
img_picto(
'',
'next'), $s);
476 print
'</span><br><br>';
480 print
'<div class="div-table-responsive-no-min">';
481 print
'<table class="noborder centpercent" cellpadding="4">';
486 print
'<tr class="liste_titre"><td colspan="5">';
487 print $langs->trans(
"FileMustHaveOneOfFollowingFormat");
489 $list = $objmodelimport->listOfAvailableImportFormat($db);
490 foreach ($list as $key) {
491 print
'<tr class="oddeven">';
492 print
'<td width="16">'.img_picto_common($key, $objmodelimport->getPictoForKey($key)).
'</td>';
493 $text = $objmodelimport->getDriverDescForKey($key);
494 print
'<td>'.$form->textwithpicto($objmodelimport->getDriverLabelForKey($key), $text).
'</td>';
495 print
'<td style="text-align:center">';
496 $filename = $langs->trans(
"ExampleOfImportFile").
'_'.$datatoimport.
'.'.$key;
497 print
'<a href="'.DOL_URL_ROOT.
'/imports/emptyexample.php?format='.$key.$param.
'&output=file&file='.urlencode($filename).
'" target="_blank" rel="noopener noreferrer">';
498 print
img_picto(
'',
'download',
'class="paddingright opacitymedium"');
499 print $langs->trans(
"DownloadEmptyExampleShort");
501 print $form->textwithpicto(
'', $langs->trans(
"DownloadEmptyExample").
'.<br>'.$langs->trans(
"StarAreMandatory"));
504 print
'<td style="text-align:right">';
505 print
'<a href="'.DOL_URL_ROOT.
'/imports/import.php?step=3&format='.$key.$param.
'">'.
img_picto($langs->trans(
"SelectFormat"),
'next',
'class="fa-15"').
'</a>';
518if ($step == 3 && $datatoimport) {
519 $param =
'&datatoimport='.urlencode($datatoimport).
'&format='.urlencode($format);
520 if ($excludefirstline) {
521 $param .=
'&excludefirstline='.urlencode($excludefirstline);
524 $param .=
'&endatlinenb='.urlencode($endatlinenb);
527 $param .=
'&separator='.urlencode($separator);
530 $param .=
'&enclosure='.urlencode($enclosure);
533 $list = $objmodelimport->listOfAvailableImportFormat($db);
535 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
544 if ($action ==
'delete') {
545 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?urlfile='.urlencode(
GETPOST(
'urlfile')).
'&step=3'.$param, $langs->trans(
'DeleteFile'), $langs->trans(
'ConfirmDeleteFile'),
'confirm_deletefile',
'', 0, 1);
548 print
'<div class="underbanner clearboth"></div>';
549 print
'<div class="fichecenter">';
551 print
'<table class="border tableforfield centpercent">';
554 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
556 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
558 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
559 $titleofmodule = $langs->trans(
"ProductOrService");
561 print $titleofmodule;
565 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
567 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
568 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
569 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
570 print $objimport->array_import_label[0];
576 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
578 print
'<div class="underbanner clearboth"></div>';
579 print
'<div class="fichecenter">';
580 print
'<table width="100%" class="border tableforfield">';
583 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
584 print
'<td class="nowraponall">';
585 $text = $objmodelimport->getDriverDescForKey($format);
586 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
587 print
'</td><td style="text-align:right" class="nowrap">';
588 $filename = $langs->trans(
"ExampleOfImportFile").
'_'.$datatoimport.
'.'.$format;
589 print
'<a href="'.DOL_URL_ROOT.
'/imports/emptyexample.php?format='.$format.$param.
'&output=file&file='.urlencode($filename).
'" target="_blank" rel="noopener noreferrer">';
590 print
img_picto(
'',
'download',
'class="paddingright opacitymedium"');
591 print $langs->trans(
"DownloadEmptyExampleShort");
593 print $form->textwithpicto(
'', $langs->trans(
"DownloadEmptyExample").
'.<br>'.$langs->trans(
"StarAreMandatory"));
602 if ($format ==
'xlsx' && !class_exists(
'XMLWriter')) {
603 $langs->load(
"install");
604 print
info_admin($langs->trans(
"ErrorPHPDoesNotSupport",
'php-xml'), 0, 0, 1,
'error');
610 print
'<form name="userfile" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="POST">';
611 print
'<input type="hidden" name="token" value="'.newToken().
'">';
612 print
'<input type="hidden" value="'.$step.
'" name="step">';
613 print
'<input type="hidden" value="'.dol_escape_htmltag($format).
'" name="format">';
614 print
'<input type="hidden" value="'.$excludefirstline.
'" name="excludefirstline">';
615 print
'<input type="hidden" value="'.$endatlinenb.
'" name="endatlinenb">';
616 print
'<input type="hidden" value="'.dol_escape_htmltag($separator).
'" name="separator">';
617 print
'<input type="hidden" value="'.dol_escape_htmltag($enclosure).
'" name="enclosure">';
618 print
'<input type="hidden" value="'.dol_escape_htmltag($datatoimport).
'" name="datatoimport">';
620 print
'<span class="opacitymedium">';
621 $s = $langs->trans(
"ChooseFileToImport",
'{s1}');
622 $s = str_replace(
'{s1}',
img_picto(
'',
'next'), $s);
624 print
'</span><br><br>';
629 print
'<div class="marginbottomonly">';
631 $maxmin = $maxfilesizearray[
'maxmin'];
633 print
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
635 print
'<input type="file" name="userfile" size="20" maxlength="80"> ';
636 $out = (empty($conf->global->MAIN_UPLOAD_DOC) ?
' disabled' :
'');
637 print
'<input type="submit" class="button small" value="'.$langs->trans(
"AddFile").
'"'.$out.
' name="sendit">';
639 if (!empty($conf->global->MAIN_UPLOAD_DOC)) {
640 $max = $conf->global->MAIN_UPLOAD_DOC;
641 $maxphp = @ini_get(
'upload_max_filesize');
642 if (preg_match(
'/k$/i', $maxphp)) {
643 $maxphp = (int) substr($maxphp, 0, -1);
645 if (preg_match(
'/m$/i', $maxphp)) {
646 $maxphp = (int) substr($maxphp, 0, -1) * 1024;
648 if (preg_match(
'/g$/i', $maxphp)) {
649 $maxphp = (int) substr($maxphp, 0, -1) * 1024 * 1024;
651 if (preg_match(
'/t$/i', $maxphp)) {
652 $maxphp = (int) substr($maxphp, 0, -1) * 1024 * 1024 * 1024;
654 $maxphp2 = @ini_get(
'post_max_size');
655 if (preg_match(
'/k$/i', $maxphp2)) {
656 $maxphp2 = (int) substr($maxphp2, 0, -1);
658 if (preg_match(
'/m$/i', $maxphp2)) {
659 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024;
661 if (preg_match(
'/g$/i', $maxphp2)) {
662 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024 * 1024;
664 if (preg_match(
'/t$/i', $maxphp2)) {
665 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024 * 1024 * 1024;
669 $maxphptoshow = $maxphptoshowparam =
'';
671 $maxmin = min($max, $maxphp);
672 $maxphptoshow = $maxphp;
673 $maxphptoshowparam =
'upload_max_filesize';
676 $maxmin = min($max, $maxphp2);
677 if ($maxphp2 < $maxphp) {
678 $maxphptoshow = $maxphp2;
679 $maxphptoshowparam =
'post_max_size';
683 $langs->load(
'other');
685 $out .=
info_admin($langs->trans(
"ThisLimitIsDefinedInSetup", $max, $maxphptoshow), 1);
687 $out .=
' ('.$langs->trans(
"UploadDisabled").
')';
693 $filearray =
dol_dir_list($conf->import->dir_temp,
'files', 0,
'',
'',
'name', SORT_DESC);
694 if (count($filearray) > 0) {
695 print
'<div class="div-table-responsive-no-min">';
696 print
'<table class="noborder centpercent" width="100%" cellpadding="4">';
698 $dir = $conf->import->dir_temp;
702 foreach ($filearray as $key => $val) {
703 $file = $val[
'name'];
707 $file = utf8_encode($file);
710 if (preg_match(
'/^\./', $file)) {
714 $modulepart =
'import';
715 $urlsource = $_SERVER[
"PHP_SELF"].
'?step='.$step.$param.
'&filetoimport='.urlencode($filetoimport);
716 $relativepath = $file;
718 print
'<tr class="oddeven">';
720 print
img_mime($file,
'',
'pictofixedwidth');
721 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=3'.$param.
'" target="_blank" rel="noopener noreferrer">';
726 print
'<td style="text-align:right">'.dol_print_size(
dol_filesize($dir.
'/'.$file)).
'</td>';
728 print
'<td style="text-align:right">'.dol_print_date(
dol_filemtime($dir.
'/'.$file),
'dayhour').
'</td>';
730 print
'<td style="text-align:right"><a href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.newToken().
'&step=3'.$param.
'&urlfile='.urlencode($relativepath);
731 print
'">'.img_delete().
'</a></td>';
733 print
'<td style="text-align:right">';
734 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?step=4'.$param.
'&filetoimport='.urlencode($relativepath).
'">'.
img_picto($langs->trans(
"NewImport"),
'next',
'class="fa-15"').
'</a>';
748if ($step == 4 && $datatoimport) {
750 $serialized_array_match_file_to_database = isset($_SESSION[
"dol_array_match_file_to_database_select"]) ? $_SESSION[
"dol_array_match_file_to_database_select"] :
'';
751 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
752 $array_match_file_to_database = array();
753 foreach ($fieldsarray as $elem) {
754 $tabelem = explode(
'=', $elem, 2);
756 $val = (isset($tabelem[1]) ? $tabelem[1] :
'');
758 $array_match_file_to_database[$key] = $val;
767 $list = $objmodelimport->listOfAvailableImportFormat($db);
769 if (empty($separator)) {
770 $separator = (empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE) ?
',' : $conf->global->IMPORT_CSV_SEPARATOR_TO_USE);
774 if ($model ==
'csv' && strlen($separator) == 1 && !GETPOSTISSET(
'separator')) {
776 $fh = fopen($conf->import->dir_temp.
'/'.$filetoimport,
'r');
778 $sline = fgets($fh, 1000000);
780 $nboccurence = substr_count($sline, $separator);
781 $nboccurencea = substr_count($sline,
',');
782 $nboccurenceb = substr_count($sline,
';');
784 if ($nboccurence == 0) {
785 if ($nboccurencea > 2) {
787 } elseif ($nboccurenceb > 2) {
795 $separator_used = str_replace(
'\t',
"\t", $separator);
798 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
799 $file =
"import_".$model.
".modules.php";
800 $classname =
"Import".ucfirst($model);
801 require_once $dir.$file;
802 $obj =
new $classname($db, $datatoimport);
803 if ($model ==
'csv') {
804 $obj->separator = $separator_used;
805 $obj->enclosure = $enclosure;
808 if ($model ==
'xlsx') {
809 if (!preg_match(
'/\.xlsx$/i', $filetoimport)) {
810 $langs->load(
"errors");
811 $param =
'&datatoimport='.$datatoimport.
'&format='.$format;
812 setEventMessages($langs->trans(
"ErrorFileMustHaveFormat", $model),
null,
'errors');
813 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?step=3'.$param.
'&filetoimport='.urlencode($relativepath));
819 $array_match_file_to_database = array();
823 $fieldssource = array();
824 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport, $langs);
827 $arrayrecord = $obj->import_read_record();
831 foreach ($arrayrecord as $key => $val) {
832 if ($val[
"type"] != -1) {
833 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 128);
836 $fieldssource[$i][
'example1'] = $langs->trans(
'Empty');
840 $obj->import_close_file();
844 $fieldstarget = $objimport->array_import_fields[0];
845 $minpos = min(count($fieldssource), count($fieldstarget));
849 $initialloadofstep4 =
false;
850 if (empty($_SESSION[
'dol_array_match_file_to_database_select'])) {
851 $initialloadofstep4 =
true;
855 if (count($array_match_file_to_database) == 0) {
861 $num = count($fieldssource);
862 while ($pos <= $num) {
863 if ($num >= 1 && $pos <= $num) {
865 foreach ($fieldstarget as $key => $val) {
866 if ($posbis < $pos) {
871 $array_match_file_to_database[$pos] = $key;
878 $array_match_database_to_file = array_flip($array_match_file_to_database);
882 $fieldstarget_tmp = array();
883 $arraykeysfieldtarget = array_keys($fieldstarget);
885 foreach ($fieldstarget as $key => $label) {
886 $isrequired = preg_match(
'/\*$/', $label);
887 if (!empty($isrequired)) {
888 $newlabel = substr($label, 0, -1);
889 $fieldstarget_tmp[$key] = array(
"label"=>$newlabel,
"required"=>
true);
891 $fieldstarget_tmp[$key] = array(
"label"=>$label,
"required"=>
false);
893 if (!empty($array_match_database_to_file[$key])) {
894 $fieldstarget_tmp[$key][
"imported"] =
true;
895 $fieldstarget_tmp[$key][
"position"] = $array_match_database_to_file[$key]-1;
897 while (!empty($array_match_database_to_file[$keytoswap])) {
898 if ($position+1 > $array_match_database_to_file[$keytoswap]) {
899 $keytoswapwith = $array_match_database_to_file[$keytoswap]-1;
900 $tmp = [$keytoswap=>$fieldstarget_tmp[$keytoswap]];
901 unset($fieldstarget_tmp[$keytoswap]);
902 $fieldstarget_tmp =
arrayInsert($fieldstarget_tmp, $keytoswapwith, $tmp);
903 $keytoswapwith = $arraykeysfieldtarget[$array_match_database_to_file[$keytoswap]-1];
904 $tmp = $fieldstarget_tmp[$keytoswapwith];
905 unset($fieldstarget_tmp[$keytoswapwith]);
906 $fieldstarget_tmp[$keytoswapwith] = $tmp;
907 $keytoswap = $keytoswapwith;
913 $fieldstarget_tmp[$key][
"imported"] =
false;
917 $fieldstarget = $fieldstarget_tmp;
926 $param =
'&format='.$format.
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport);
927 if ($excludefirstline) {
928 $param .=
'&excludefirstline='.urlencode($excludefirstline);
931 $param .=
'&endatlinenb='.urlencode($endatlinenb);
934 $param .=
'&separator='.urlencode($separator);
937 $param .=
'&enclosure='.urlencode($enclosure);
940 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
946 print
'<div class="underbanner clearboth"></div>';
947 print
'<div class="fichecenter">';
949 print
'<table class="centpercent border tableforfield">';
952 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
954 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
956 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
957 $titleofmodule = $langs->trans(
"ProductOrService");
959 print $titleofmodule;
963 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
965 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
966 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
967 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
968 print $objimport->array_import_label[0];
974 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
976 print
'<div class="underbanner clearboth"></div>';
977 print
'<div class="fichecenter">';
978 print
'<table width="100%" class="border tableforfield">';
981 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
983 $text = $objmodelimport->getDriverDescForKey($format);
984 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
988 if ($model ==
'csv') {
989 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
991 print
'<form method="POST">';
992 print
'<input type="hidden" name="token" value="'.newToken().
'">';
993 print
'<input type="hidden" value="'.$step.
'" name="step">';
994 print
'<input type="hidden" value="'.$format.
'" name="format">';
995 print
'<input type="hidden" value="'.$excludefirstline.
'" name="excludefirstline">';
996 print
'<input type="hidden" value="'.$endatlinenb.
'" name="endatlinenb">';
997 print
'<input type="hidden" value="'.$datatoimport.
'" name="datatoimport">';
998 print
'<input type="hidden" value="'.$filetoimport.
'" name="filetoimport">';
999 print $langs->trans(
"Separator").
' : ';
1000 print
'<input type="text" class="width25 center" name="separator" value="'.dol_escape_htmltag($separator).
'"/>';
1001 print
' '.$langs->trans(
"Enclosure").
' : ';
1002 print
'<input type="text" class="width25 center" name="enclosure" value="'.dol_escape_htmltag($enclosure).
'"/> ';
1003 print
'<input name="update" type="submit" value="'.$langs->trans(
'Update').
'" class="button smallpaddingimp" />';
1009 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
1011 $modulepart =
'import';
1012 $relativepath =
GETPOST(
'filetoimport');
1013 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
1014 print
img_mime($file,
'',
'pictofixedwidth');
1015 print $filetoimport;
1016 print
img_picto($langs->trans(
"Download"),
'download',
'class="paddingleft opacitymedium"');
1029 print
'<!-- List of source fields -->'.
"\n";
1030 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1031 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1032 print
'<input type="hidden" name="action" value="select_model">';
1033 print
'<input type="hidden" name="step" value="4">';
1034 print
'<input type="hidden" name="format" value="'.$format.
'">';
1035 print
'<input type="hidden" name="datatoimport" value="'.$datatoimport.
'">';
1036 print
'<input type="hidden" name="filetoimport" value="'.$filetoimport.
'">';
1037 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1038 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1039 print
'<input type="hidden" name="separator" value="'.dol_escape_htmltag($separator).
'">';
1040 print
'<input type="hidden" name="enclosure" value="'.dol_escape_htmltag($enclosure).
'">';
1043 print
'<div class="marginbottomonly">';
1044 print
'<span class="opacitymedium">';
1045 $s = $langs->trans(
"SelectImportFieldsSource",
'{s1}');
1046 $s = str_replace(
'{s1}',
img_picto(
'',
'grip_title',
'',
false, 0, 0,
'',
'', 0), $s);
1049 $htmlother->select_import_model($importmodelid,
'importmodelid', $datatoimport, 1, $user->id);
1050 print
'<input type="submit" class="button small reposition" value="'.$langs->trans(
"Select").
'">';
1055 print
'<div class="div-table-responsive-no-min">';
1056 print
'<table class="noborder centpercent">';
1057 print
'<tr class="liste_titre">';
1058 print
'<td>'.$langs->trans(
"FieldsInSourceFile").
'</td>';
1059 print
'<td>'.$langs->trans(
"FieldsInTargetDatabase").
'</td>';
1064 print
'<tr valign="top"><td width="50%" class="nopaddingleftimp">';
1066 $fieldsplaced = array();
1067 $valforsourcefieldnb = array();
1068 $listofkeys = array();
1069 foreach ($array_match_file_to_database as $key => $val) {
1070 $listofkeys[$key] = 1;
1073 print
"\n<!-- Box left container -->\n";
1074 print
'<div id="left" class="connectedSortable">'.
"\n";
1080 foreach ($fieldssource as $key => $val) {
1081 show_elem($fieldssource, $key, $val, $var);
1082 $listofkeys[$key] = 1;
1083 $fieldsplaced[$key] = 1;
1084 $valforsourcefieldnb[$lefti] = $key;
1094 print
"<!-- End box left container -->\n";
1097 print
'</td><td width="50%" class="nopaddingrightimp">';
1101 $optionsall = array();
1102 foreach ($fieldstarget as $code => $line) {
1105 $tmparray = explode(
'|', $line[
"label"]);
1107 foreach ($tmparray as $tmpkey => $tmpval) {
1108 $labeltoshow .= ($labeltoshow ?
' '.$langs->trans(
'or').
' ' :
'').$langs->transnoentities($tmpval);
1110 $optionsall[$code] = array(
'labelkey'=>$line[
'label'],
'labelkeyarray'=>$tmparray,
'label'=>$labeltoshow,
'required'=>(empty($line[
"required"]) ? 0 : 1),
'position'=>!empty($line[
'position']) ? $line[
'position'] : 0);
1115 $optionsall[$code][
'picto'] = $picto;
1122 $mandatoryfieldshavesource =
true;
1135 $modetoautofillmapping =
'session';
1136 if ($initialloadofstep4) {
1137 $modetoautofillmapping =
'guess';
1141 print
'<table class="nobordernopadding centpercent tableimport">';
1142 foreach ($fieldssource as $code => $line) {
1146 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
1147 $entity = (!empty($objimport->array_import_entities[0][$code]) ? $objimport->array_import_entities[0][$code] : $objimport->array_import_icon[0]);
1149 $entityicon = !empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity;
1150 $entitylang = !empty($entitytolang[$entity]) ? $entitytolang[$entity] : $objimport->array_import_label[0];
1152 print
'<td class="nowraponall hideonsmartphone" style="font-weight: normal">=> </td>';
1153 print
'<td class="nowraponall" style="font-weight: normal">';
1158 $selectforline =
'';
1159 $selectforline .=
'<select id="selectorderimport_'.($i+1).
'" class="targetselectchange minwidth300" name="select_'.($i+1).
'">';
1160 if (!empty($line[
"imported"])) {
1161 $selectforline .=
'<option value="-1"> </option>';
1163 $selectforline .=
'<option selected="" value="-1"> </option>';
1167 $codeselectedarray = array();
1168 foreach ($optionsall as $tmpcode => $tmpval) {
1170 if (!empty($tmpval[
'picto'])) {
1171 $label .=
img_picto(
'', $tmpval[
'picto'],
'class="pictofixedwidth"');
1173 $label .= $tmpval[
'required'] ?
'<strong>' :
'';
1174 $label .= $tmpval[
'label'];
1175 $label .= $tmpval[
'required'] ?
'*</strong>' :
'';
1177 $tablealias = preg_replace(
'/(\..*)$/i',
'', $tmpcode);
1178 $tablename = !empty($objimport->array_import_tables[0][$tablealias]) ? $objimport->array_import_tables[0][$tablealias] :
"";
1182 $filecolumn = ($i + 1);
1184 if (empty($objimport->array_import_convertvalue[0][$tmpcode])) {
1187 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromref') {
1188 $htmltext .= $langs->trans(
"DataComeFromIdFoundFromRef", $langs->transnoentitiesnoconv($entitylang)).
'<br>';
1190 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromcodeid') {
1191 $htmltext .= $langs->trans(
"DataComeFromIdFoundFromCodeId", $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$tmpcode][
'dict'])).
'<br>';
1195 $example = !empty($objimport->array_import_examplevalues[0][$tmpcode])?$objimport->array_import_examplevalues[0][$tmpcode]:
"";
1197 if (empty($objimport->array_import_convertvalue[0][$tmpcode])) {
1199 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.str_replace(
'"',
'', $example).
'</b><br>';
1202 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromref') {
1203 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.$langs->transnoentitiesnoconv(
"ExampleAnyRefFoundIntoElement", $entitylang).($example ?
' ('.$langs->transnoentitiesnoconv(
"Example").
': '.str_replace(
'"',
'', $example).
')' :
'').
'</b><br>';
1204 } elseif ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromcodeid') {
1205 $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>';
1206 } elseif ($example) {
1207 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.str_replace(
'"',
'', $example).
'</b><br>';
1211 if (!empty($objimport->array_import_regex[0][$tmpcode])) {
1212 $htmltext .= $langs->trans(
"FormatControlRule").
': <b>'.str_replace(
'"',
'', $objimport->array_import_regex[0][$tmpcode]).
'</b><br>';
1216 $htmltext .= $langs->trans(
"InformationOnTargetTables").
': <b>'.$tablename.
"->".preg_replace(
'/^.*\./',
'', $tmpcode).
"</b>";
1218 $labelhtml = $label.
' '.$form->textwithpicto(
'', $htmltext, 1,
'help',
'', 1);
1220 $selectforline .=
'<option value="'.$tmpcode.
'"';
1221 if ($modetoautofillmapping ==
'orderoftargets') {
1224 $selectforline .=
' selected';
1226 } elseif ($modetoautofillmapping ==
'guess') {
1230 if (preg_match(
'/^(.+)\((.+\..+)\)$/', $line[
'example1'], $regs)) {
1231 $tmpstring1 = $regs[1];
1232 $tmpstring2 = $regs[2];
1234 $tmpstring1 = $line[
'example1'];
1237 $tmpstring1 = strtolower(str_replace(
'*',
'', trim($tmpstring1)));
1238 $tmpstring2 = strtolower(str_replace(
'*',
'', trim($tmpstring2)));
1241 foreach ($tmpval[
'labelkeyarray'] as $tmpval2) {
1242 $labeltarget = $langs->transnoentities($tmpval2);
1244 if ($tmpstring1 && ($tmpstring1 == $tmpcode || $tmpstring1 == strtolower($labeltarget)
1245 || $tmpstring1 == strtolower(
dol_string_unaccent($labeltarget)) || $tmpstring1 == strtolower($tmpval2))) {
1246 if (empty($codeselectedarray[$code])) {
1247 $selectforline .=
' selected';
1248 $codeselectedarray[$code] = 1;
1251 } elseif ($tmpstring2 && ($tmpstring2 == $tmpcode || $tmpstring2 == strtolower($labeltarget)
1252 || $tmpstring2 == strtolower(
dol_string_unaccent($labeltarget)) || $tmpstring2 == strtolower($tmpval2))) {
1253 if (empty($codeselectedarray[$code])) {
1254 $selectforline .=
' selected';
1255 $codeselectedarray[$code] = 1;
1260 } elseif ($modetoautofillmapping ==
'session' && !empty($_SESSION[
'dol_array_match_file_to_database_select'])) {
1261 $tmpselectioninsession =
dolExplodeIntoArray($_SESSION[
'dol_array_match_file_to_database_select'],
',',
'=');
1263 if (!empty($tmpselectioninsession[($i+1)]) && $tmpselectioninsession[($i+1)] == $tmpcode) {
1264 $selectforline .=
' selected';
1266 $selectforline .=
' data-debug="'.$tmpcode.
'-'.$code.
'-'.$j.
'-'.(!empty($tmpselectioninsession[($i+1)]) ? $tmpselectioninsession[($i+1)] :
"").
'"';
1268 $selectforline .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
1269 $selectforline .=
'>';
1270 $selectforline .= $label;
1271 $selectforline .=
'</options>';
1274 $selectforline .=
'</select>';
1275 $selectforline .=
ajax_combobox(
'selectorderimport_'.($i+1));
1277 print $selectforline;
1282 print
'<td class="nowraponall" style="font-weight:normal; text-align:right">';
1285 $htmltext =
'<b><u>'.$langs->trans(
"FieldSource").
'</u></b><br>';
1287 $htmltext .= $langs->trans(
"DataComeFromFileFieldNb", $filecolumntoshow).
'<br>';
1289 print $form->textwithpicto(
'', $htmltext);
1300 print
'<tr class="liste_titre"><td colspan="2">'.$langs->trans(
"Note").
'</td></tr>';
1301 print
'<tr><td colspan="2"><div id="div-mandatory-target-fields-not-mapped"></div></td></tr>';
1307 if (!empty($conf->use_javascript_ajax)) {
1308 print
'<script type="text/javascript">'.
"\n";
1309 print
'var previousselectedvalueimport = "0";'.
"\n";
1310 print
'var previousselectedlabelimport = "0";'.
"\n";
1311 print
'var arrayofselectedvalues = [];'.
"\n";
1312 print
'var arrayoftargetfields = [];'.
"\n";
1313 print
'var arrayoftargetmandatoryfields = [];'.
"\n";
1317 foreach ($fieldstarget as $key => $val) {
1318 print
"arrayoftargetfields[".$tmpi.
"] = '".
dol_escape_js($langs->trans($val[
'label'])).
"'; ";
1319 if ($val[
'required']) {
1320 print
"arrayoftargetmandatoryfields[".$tmpi.
"] = '".
dol_escape_js($key).
"'; ";
1326 print
'$(document).ready(function () {'.
"\n";
1328 print
'setOptionsToDisabled();'.
"\n";
1329 print
'saveSelection();'.
"\n";
1331 print
'$(".targetselectchange").focus(function(){'.
"\n";
1332 print
' previousselectedvalueimport = $(this).val();'.
"\n";
1333 print
' previousselectedlabelimport = $(this).children("option:selected").text();'.
"\n";
1334 print
' console.log("previousselectedvalueimport="+previousselectedvalueimport)'.
"\n";
1341 print
'function setOptionsToDisabled() {'.
"\n";
1342 print
' console.log("Remove the disabled flag everywhere");'.
"\n";
1343 print
' $("select.targetselectchange").not($( this )).find(\'option\').prop("disabled", false);'.
"\n";
1344 print
' arrayofselectedvalues = [];'.
"\n";
1346 print
' $("select.targetselectchange").each(function(){'.
"\n";
1347 print
' id = $(this).attr(\'id\')'.
"\n";
1348 print
' value = $(this).val()'.
"\n";
1349 print
' console.log("a selected value has been found for component "+id+" = "+value);'.
"\n";
1350 print
' arrayofselectedvalues.push(value);'.
"\n";
1353 print
' console.log("List of all selected values arrayofselectedvalues");'.
"\n";
1354 print
' console.log(arrayofselectedvalues);'.
"\n";
1355 print
' console.log("Set the option to disabled for every entry that is currently selected somewhere else (so into arrayofselectedvalues)");'.
"\n";
1357 print
' $.each(arrayofselectedvalues, function(key, value) {'.
"\n";
1358 print
' if (value != -1) {'.
"\n";
1359 print
' console.log("Process key="+key+" value="+value+" to disable.");'.
"\n";
1360 print
' $("select.targetselectchange").find(\'option[value="\'+value+\'"]:not(:selected)\').prop("disabled", true);'.
"\n";
1366 print
'function saveSelection() {'.
"\n";
1368 print
' arrayselectedfields = [];'.
"\n";
1369 print
' arrayselectedfields.push(0);'.
"\n";
1371 print
' $.each( arrayofselectedvalues, function( key, value ) {'.
"\n";
1372 print
' if (value != -1) {'.
"\n";
1373 print
' arrayselectedfields.push(value);'.
"\n";
1374 print
' } else {'.
"\n";
1375 print
' arrayselectedfields.push(0);'.
"\n";
1379 print
" $.ajax({\n";
1380 print
" type: 'POST',\n";
1381 print
" dataType: 'json',\n";
1382 print
" url: '".dol_escape_js($_SERVER[
"PHP_SELF"]).
"?action=saveselectorder&token=".newToken().
"',\n";
1383 print
" data: 'selectorder='+arrayselectedfields.toString(),\n";
1384 print
" success: function(){\n";
1385 print
" console.log('The selected fields have been saved into '+arrayselectedfields.toString());\n";
1390 print
' console.log("arrayselectedfields");';
1391 print
' console.log(arrayselectedfields);';
1392 print
' console.log("arrayoftargetmandatoryfields");';
1393 print
' console.log(arrayoftargetmandatoryfields);';
1394 print
" listtoshow = '';";
1395 print
" nbelement = arrayoftargetmandatoryfields.length
1396 for (let i = 0; i < nbelement; i++) {
1397 if (arrayoftargetmandatoryfields[i] && ! arrayselectedfields.includes(arrayoftargetmandatoryfields[i])) {
1398 console.log(arrayoftargetmandatoryfields[i]+' not mapped');
1399 listtoshow = listtoshow + (listtoshow ? ', ' : '') + '<b>' + arrayoftargetfields[i] + '*</b>';
1402 console.log(listtoshow);
1404 listtoshow = '".dol_escape_js(
img_warning($langs->trans(
"MandatoryTargetFieldsNotMapped")).
' '.$langs->trans(
"MandatoryTargetFieldsNotMapped")).
": ' + listtoshow;
1405 $('#div-mandatory-target-fields-not-mapped').html(listtoshow);
1407 $('#div-mandatory-target-fields-not-mapped').html('<span class=\"opacitymedium\">".
dol_escape_js($langs->trans(
"AllTargetMandatoryFieldsAreMapped")).
"</span>');
1414 print
'$(".targetselectchange").change(function(){'.
"\n";
1415 print
' setOptionsToDisabled();'.
"\n";
1417 print
' if(previousselectedlabelimport != "" && previousselectedvalueimport != -1) {'.
"\n";
1418 print
' let valuetochange = $(this).val(); '.
"\n";
1419 print
' $(".boxtdunused").each(function(){'.
"\n";
1420 print
' if ($(this).text().includes(valuetochange)){'.
"\n";
1421 print
' arraychild = $(this)[0].childNodes'.
"\n";
1422 print
' arraytexttomodify = arraychild[0].textContent.split(" ")'.
"\n";
1423 print
' arraytexttomodify[1] = previousselectedvalueimport '.
"\n";
1424 print
' textmodified = arraytexttomodify.join(" ") '.
"\n";
1425 print
' arraychild[0].textContent = textmodified'.
"\n";
1426 print
' arraychild[1].innerHTML = previousselectedlabelimport'.
"\n";
1430 print
' $(this).blur()'.
"\n";
1432 print
' saveSelection()'.
"\n";
1436 print
'</script>'.
"\n";
1442 print
'<div class="tabsAction">';
1444 if (count($array_match_file_to_database)) {
1445 if ($mandatoryfieldshavesource) {
1446 print
'<a class="butAction saveorderselect" href="import.php?step=5'.$param.
'&filetoimport='.urlencode($filetoimport).
'">'.$langs->trans(
"NextStep").
'</a>';
1448 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"SomeMandatoryFieldHaveNoSource")).
'">'.$langs->trans(
"NextStep").
'</a>';
1456 if (count($array_match_file_to_database)) {
1458 print
'<!-- Area to add new import profile -->'.
"\n";
1459 print
'<div class="marginbottomonly"><span class="opacitymedium">'.$langs->trans(
"SaveImportModel").
'</span></div>';
1461 print
'<form class="nocellnopadd" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1462 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1463 print
'<input type="hidden" name="action" value="add_import_model">';
1464 print
'<input type="hidden" name="step" value="'.$step.
'">';
1465 print
'<input type="hidden" name="format" value="'.$format.
'">';
1466 print
'<input type="hidden" name="datatoimport" value="'.$datatoimport.
'">';
1467 print
'<input type="hidden" name="filetoimport" value="'.$filetoimport.
'">';
1468 print
'<input type="hidden" name="hexa" value="'.$hexa.
'">';
1469 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1470 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1471 print
'<input type="hidden" name="page_y" value="">';
1472 print
'<input type="hidden" value="'.dol_escape_htmltag($separator).
'" name="separator">';
1473 print
'<input type="hidden" value="'.dol_escape_htmltag($enclosure).
'" name="enclosure">';
1475 print
'<div class="div-table-responsive-no-min">';
1476 print
'<table summary="selectofimportprofil" class="noborder centpercent">';
1477 print
'<tr class="liste_titre">';
1478 print
'<td>'.$langs->trans(
"ImportModelName").
'</td>';
1479 print
'<td>'.$langs->trans(
"Visibility").
'</td>';
1483 $nameofimportprofile = str_replace(
' ',
'-', $langs->trans(
"ImportProfile").
' '.$titleofmodule.
' '.
dol_print_date(
dol_now(
'gmt'),
'dayxcard'));
1485 $nameofimportprofile = $import_name;
1488 print
'<tr class="oddeven">';
1489 print
'<td><input name="import_name" class="minwidth300" value="'.$nameofimportprofile.
'"></td>';
1491 $arrayvisibility = array(
'private'=>$langs->trans(
"Private"),
'all'=>$langs->trans(
"Everybody"));
1492 print $form->selectarray(
'visibility', $arrayvisibility,
'private');
1494 print
'<td class="right">';
1495 print
'<input type="submit" class="button smallpaddingimp reposition" value="'.$langs->trans(
"SaveImportProfile").
'">';
1499 $sql =
"SELECT rowid, label, fk_user, entity";
1500 $sql .=
" FROM ".MAIN_DB_PREFIX.
"import_model";
1501 $sql .=
" WHERE type = '".$db->escape($datatoimport).
"'";
1502 if (empty($conf->global->EXPORTS_SHARE_MODELS)) {
1503 $sql .=
" AND fk_user IN (0, ".((int) $user->id).
")";
1505 $sql .=
" ORDER BY rowid";
1507 $resql = $db->query($sql);
1509 $num = $db->num_rows($resql);
1511 $tmpuser =
new User($db);
1515 $obj = $db->fetch_object($resql);
1517 print
'<tr class="oddeven"><td>';
1520 print
'<td class="tdoverflowmax150">';
1521 if (empty($obj->fk_user)) {
1522 print $langs->trans(
"Everybody");
1524 $tmpuser->fetch($obj->fk_user);
1525 print $tmpuser->getNomUrl(-1);
1528 print
'<td class="right">';
1529 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?step='.$step.$param.
'&action=deleteprof&token='.newToken().
'&id='.$obj->rowid.
'&filetoimport='.urlencode($filetoimport).
'">';
1547if ($step == 5 && $datatoimport) {
1548 $max_execution_time_for_importexport = (empty($conf->global->IMPORT_MAX_EXECUTION_TIME) ? 300 : $conf->global->IMPORT_MAX_EXECUTION_TIME);
1549 $max_time = @ini_get(
"max_execution_time");
1550 if ($max_time && $max_time < $max_execution_time_for_importexport) {
1551 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.");
1552 @ini_set(
"max_execution_time", $max_execution_time_for_importexport);
1556 $list = $objmodelimport->listOfAvailableImportFormat($db);
1559 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
1560 $file =
"import_".$model.
".modules.php";
1561 $classname =
"Import".ucfirst($model);
1562 require_once $dir.$file;
1563 $obj =
new $classname($db, $datatoimport);
1564 if ($model ==
'csv') {
1565 $obj->separator = $separator_used;
1566 $obj->enclosure = $enclosure;
1570 $fieldssource = array();
1571 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport, $langs);
1575 $arrayrecord = $obj->import_read_record();
1578 foreach ($arrayrecord as $key => $val) {
1579 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 24);
1582 $obj->import_close_file();
1585 $nboflines = $obj->import_get_nb_of_lines($conf->import->dir_temp.
'/'.$filetoimport);
1587 $param =
'&leftmenu=import&format='.urlencode($format).
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport).
'&nboflines='.urlencode($nboflines).
'&separator='.urlencode($separator).
'&enclosure='.urlencode($enclosure);
1589 if ($excludefirstline) {
1590 $param .=
'&excludefirstline='.urlencode($excludefirstline);
1593 $param .=
'&endatlinenb='.urlencode($endatlinenb);
1595 if (!empty($updatekeys)) {
1596 $param .=
'&updatekeys[]='.implode(
'&updatekeys[]=', $updatekeys);
1599 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
1604 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?'.$param2.
'" method="POST">';
1605 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1606 print
'<input type="hidden" name="step" value="5">';
1607 print
'<input type="hidden" name="action" value="launchsimu">';
1611 print
'<div class="underbanner clearboth"></div>';
1612 print
'<div class="fichecenter">';
1614 print
'<table width="100%" class="border tableforfield">';
1617 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
1619 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
1621 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
1622 $titleofmodule = $langs->trans(
"ProductOrService");
1624 print $titleofmodule;
1628 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
1630 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
1631 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
1632 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
1633 print $objimport->array_import_label[0];
1639 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
1641 print
'<div class="underbanner clearboth"></div>';
1642 print
'<div class="fichecenter">';
1643 print
'<table width="100%" class="border tableforfield">';
1646 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
1648 $text = $objmodelimport->getDriverDescForKey($format);
1649 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
1653 if ($model ==
'csv') {
1654 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
1657 print
' '.$langs->trans(
"Enclosure").
' : '.
dol_escape_htmltag($enclosure);
1662 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
1664 $modulepart =
'import';
1665 $relativepath =
GETPOST(
'filetoimport');
1666 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
1667 print
img_mime($file,
'',
'pictofixedwidth');
1668 print $filetoimport;
1669 print
img_picto($langs->trans(
"Download"),
'download',
'class="paddingleft opacitymedium"');
1675 print $langs->trans(
"NbOfSourceLines");
1682 print $langs->trans(
"ImportFromToLine");
1684 if ($action ==
'launchsimu') {
1685 print
'<input type="number" class="maxwidth50 right" name="excludefirstlinebis" disabled="disabled" value="'.$excludefirstline.
'">';
1686 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1688 print
'<input type="number" class="maxwidth50 right" name="excludefirstline" value="'.$excludefirstline.
'">';
1689 print $form->textwithpicto(
"", $langs->trans(
"SetThisValueTo2ToExcludeFirstLine"));
1692 if ($action ==
'launchsimu') {
1693 print
'<input type="text" class="maxwidth50" name="endatlinenbbis" disabled="disabled" value="'.$endatlinenb.
'">';
1694 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1696 print
'<input type="text" class="maxwidth50" name="endatlinenb" value="'.$endatlinenb.
'">';
1697 print $form->textwithpicto(
"", $langs->trans(
"KeepEmptyToGoToEndOfFile"));
1699 if ($action ==
'launchsimu') {
1700 print
' <a href="'.$_SERVER[
"PHP_SELF"].
'?step=5'.$param.
'">'.$langs->trans(
"Modify").
'</a>';
1702 if ($excludefirstline == 2) {
1703 print $form->textwithpicto(
"", $langs->trans(
"WarningFirstImportedLine", $excludefirstline), 1,
'warning',
"warningexcludefirstline");
1705 $( document ).ready(function() {
1706 $("input[name=\'excludefirstline\']").on("change",function(){
1707 if($(this).val() <= 1){
1708 $(".warningexcludefirstline").hide();
1710 $(".warningexcludefirstline").show();
1720 print $form->textwithpicto($langs->trans(
"KeysToUseForUpdates"), $langs->trans(
"SelectPrimaryColumnsForUpdateAttempt"));
1722 if ($action ==
'launchsimu') {
1723 if (count($updatekeys)) {
1724 print $form->multiselectarray(
'updatekeysbis', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0,
'', 1,
'80%',
'disabled');
1726 print
'<span class="opacitymedium">'.$langs->trans(
"NoUpdateAttempt").
'</span> -';
1728 foreach ($updatekeys as $val) {
1729 print
'<input type="hidden" name="updatekeys[]" value="'.$val.
'">';
1731 print
' <a href="'.$_SERVER[
"PHP_SELF"].
'?step=5'.$param.
'">'.$langs->trans(
"Modify").
'</a>';
1733 if (is_array($objimport->array_import_updatekeys[0]) && count($objimport->array_import_updatekeys[0])) {
1734 print $form->multiselectarray(
'updatekeys', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0,
'', 1,
'80%');
1737 print
'<span class="opacitymedium">'.$langs->trans(
"UpdateNotYetSupportedForThisImport").
'</span>';
1749 print
load_fiche_titre($langs->trans(
"InformationOnTargetTables"),
'',
'file-import');
1751 print
'<div class="underbanner clearboth"></div>';
1752 print
'<div class="fichecenter">';
1754 print
'<table width="100%" class="border tableforfield">';
1757 print
'<tr><td class="titlefieldcreate">';
1758 print $langs->trans(
"TablesTarget");
1760 $listtables = array();
1761 $sort_array_match_file_to_database = $array_match_file_to_database;
1762 foreach ($array_match_file_to_database as $code => $label) {
1764 if ($code > count($fieldssource)) {
1768 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
1769 $listtables[$alias] = $objimport->array_import_tables[0][$alias];
1771 if (count($listtables)) {
1774 foreach ($listtables as $val) {
1793 print $langs->trans(
"Error");
1799 print $langs->trans(
"FieldsTarget").
'</td><td>';
1800 $listfields = array();
1803 $sort_array_match_file_to_database = $array_match_file_to_database;
1804 ksort($sort_array_match_file_to_database);
1806 foreach ($sort_array_match_file_to_database as $code => $label) {
1809 if ($code > count($fieldssource)) {
1813 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
1814 $listfields[$i] =
'<span class="nowrap">'.$langs->trans(
"Column").
' '.
num2Alpha($code - 1).
' -> '.$label.
'</span>';
1816 print count($listfields) ? (join(
', ', $listfields)) : $langs->trans(
"Error");
1825 if ($action !=
'launchsimu') {
1827 print
'<br><span class="opacitymedium">';
1828 print $langs->trans(
"NowClickToTestTheImport", $langs->transnoentitiesnoconv(
"RunSimulateImportFile")).
'</span><br>';
1832 print
'<div class="center">';
1833 if ($user->hasRight(
'import',
'run')) {
1834 print
'<input type="submit" class="butAction" value="'.$langs->trans(
"RunSimulateImportFile").
'">';
1836 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunSimulateImportFile").
'</a>';
1841 $arrayoferrors = array();
1842 $arrayofwarnings = array();
1843 $maxnboferrors = empty($conf->global->IMPORT_MAX_NB_OF_ERRORS) ? 50 : $conf->global->IMPORT_MAX_NB_OF_ERRORS;
1844 $maxnbofwarnings = empty($conf->global->IMPORT_MAX_NB_OF_WARNINGS) ? 50 : $conf->global->IMPORT_MAX_NB_OF_WARNINGS;
1856 $pathfile = $conf->import->dir_temp.
'/'.$filetoimport;
1857 $result = $obj->import_open_file($pathfile, $langs);
1859 global $tablewithentity_cache;
1860 $tablewithentity_cache = array();
1861 $sourcelinenb = 0; $endoffile = 0;
1864 while (($sourcelinenb < $nboflines) && !$endoffile) {
1868 $arrayrecord = $obj->import_read_record();
1869 if ($arrayrecord ===
false) {
1870 $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');
1874 if ($excludefirstline && ($sourcelinenb < $excludefirstline)) {
1877 if ($endatlinenb && ($sourcelinenb > $endatlinenb)) {
1882 $result = $obj->import_insert($arrayrecord, $array_match_file_to_database, $objimport, count($fieldssource), $importid, $updatekeys);
1884 if (count($obj->errors)) {
1885 $arrayoferrors[$sourcelinenb] = $obj->errors;
1887 if (count($obj->warnings)) {
1888 $arrayofwarnings[$sourcelinenb] = $obj->warnings;
1890 if (!count($obj->errors) && !count($obj->warnings)) {
1895 $obj->import_close_file();
1897 print $langs->trans(
"ErrorFailedToOpenFile", $pathfile);
1904 if (!empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0])) {
1906 foreach ($objimport->array_import_run_sql_after[0] as $sqlafterimport) {
1908 $resqlafterimport = $db->query($sqlafterimport);
1909 if (!$resqlafterimport) {
1910 $arrayoferrors[
'none'][] = array(
'lib'=>$langs->trans(
"Error running final request: ".$sqlafterimport));
1919 if (!count($arrayoferrors) && !count($arrayofwarnings)) {
1921 print
'<div class="info">';
1922 print
'<div class=""><b>'.$langs->trans(
"ResultOfSimulationNoError").
'</b></div>';
1923 print $langs->trans(
"NbInsertSim", empty($obj->nbinsert) ? 0 : $obj->nbinsert).
'<br>';
1924 print $langs->trans(
"NbUpdateSim", empty($obj->nbupdate) ? 0 : $obj->nbupdate).
'<br>';
1929 print
'<div class="warning">';
1930 print $langs->trans(
"NbOfLinesOK", $nbok).
'...<br>';
1937 if (count($arrayoferrors)) {
1938 print
img_error().
' <b>'.$langs->trans(
"ErrorsOnXLines", count($arrayoferrors)).
'</b><br>';
1939 print
'<table width="100%" class="border"><tr><td>';
1940 foreach ($arrayoferrors as $key => $val) {
1942 if ($nboferrors > $maxnboferrors) {
1943 print $langs->trans(
"TooMuchErrors", (count($arrayoferrors) - $nboferrors)).
"<br>";
1947 foreach ($val as $i => $err) {
1948 print
' > '.dol_escape_htmltag($err[
'lib']).
'<br>';
1951 print
'</td></tr></table>';
1957 if (count($arrayofwarnings)) {
1958 print
img_warning().
' <b>'.$langs->trans(
"WarningsOnXLines", count($arrayofwarnings)).
'</b><br>';
1959 print
'<table width="100%" class="border"><tr><td>';
1960 foreach ($arrayofwarnings as $key => $val) {
1962 if ($nbofwarnings > $maxnbofwarnings) {
1963 print $langs->trans(
"TooMuchWarnings", (count($arrayofwarnings) - $nbofwarnings)).
"<br>";
1967 foreach ($val as $i => $err) {
1968 print
' > '.dol_escape_htmltag($err[
'lib']).
'<br>';
1971 print
'</td></tr></table>';
1978 print
'<div class="center">';
1979 print
'<span class="opacitymedium">'.$langs->trans(
"NowClickToRunTheImport", $langs->transnoentitiesnoconv(
"RunImportFile")).
'</span><br>';
1988 print
'<div class="center">';
1989 if ($user->hasRight(
'import',
'run')) {
1990 if (empty($nboferrors)) {
1991 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/imports/import.php?leftmenu=import&step=6&importid='.$importid.$param.
'">'.$langs->trans(
"RunImportFile").
'</a>';
1995 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"CorrectErrorBeforeRunningImport")).
'">'.$langs->trans(
"RunImportFile").
'</a>';
1998 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunSimulateImportFile").
'</a>';
2000 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunImportFile").
'</a>';
2010if ($step == 6 && $datatoimport) {
2011 $max_execution_time_for_importexport = (empty($conf->global->IMPORT_MAX_EXECUTION_TIME) ? 300 : $conf->global->IMPORT_MAX_EXECUTION_TIME);
2012 $max_time = @ini_get(
"max_execution_time");
2013 if ($max_time && $max_time < $max_execution_time_for_importexport) {
2014 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.");
2015 @ini_set(
"max_execution_time", $max_execution_time_for_importexport);
2019 $list = $objmodelimport->listOfAvailableImportFormat($db);
2020 $importid =
GETPOST(
"importid",
'alphanohtml');
2024 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
2025 $file =
"import_".$model.
".modules.php";
2026 $classname =
"Import".ucfirst($model);
2027 require_once $dir.$file;
2028 $obj =
new $classname($db, $datatoimport);
2029 if ($model ==
'csv') {
2030 $obj->separator = $separator_used;
2031 $obj->enclosure = $enclosure;
2035 $fieldssource = array();
2036 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport, $langs);
2039 $arrayrecord = $obj->import_read_record();
2042 foreach ($arrayrecord as $key => $val) {
2043 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 24);
2046 $obj->import_close_file();
2049 $nboflines = (!empty($_GET[
"nboflines"]) ? $_GET[
"nboflines"] :
dol_count_nb_of_line($conf->import->dir_temp.
'/'.$filetoimport));
2051 $param =
'&format='.$format.
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport).
'&nboflines='.urlencode($nboflines);
2052 if ($excludefirstline) {
2053 $param .=
'&excludefirstline='.urlencode($excludefirstline);
2056 $param .=
'&endatlinenb='.urlencode($endatlinenb);
2059 $param .=
'&separator='.urlencode($separator);
2062 $param .=
'&enclosure='.urlencode($enclosure);
2065 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
2071 print
'<div class="underbanner clearboth"></div>';
2072 print
'<div class="fichecenter">';
2074 print
'<table width="100%" class="border">';
2077 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
2079 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
2081 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
2082 $titleofmodule = $langs->trans(
"ProductOrService");
2084 print $titleofmodule;
2088 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
2090 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
2091 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
2092 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
2093 print $objimport->array_import_label[0];
2099 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
2101 print
'<div class="underbanner clearboth"></div>';
2102 print
'<div class="fichecenter">';
2103 print
'<table width="100%" class="border">';
2106 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
2108 $text = $objmodelimport->getDriverDescForKey($format);
2109 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
2113 if ($model ==
'csv') {
2114 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
2116 print $langs->trans(
"Separator").
' : ';
2117 print htmlentities($separator);
2118 print
' '.$langs->trans(
"Enclosure").
' : ';
2119 print htmlentities($enclosure);
2124 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
2126 $modulepart =
'import';
2127 $relativepath =
GETPOST(
'filetoimport');
2128 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
2129 print
img_mime($file,
'',
'pictofixedwidth');
2130 print $filetoimport;
2136 print $langs->trans(
"NbOfSourceLines");
2143 print $langs->trans(
"ImportFromLine");
2145 print
'<input type="text" size="4" name="excludefirstline" disabled="disabled" value="'.$excludefirstline.
'">';
2150 print $langs->trans(
"EndAtLineNb");
2152 print
'<input type="text" size="4" name="endatlinenb" disabled="disabled" value="'.$endatlinenb.
'">';
2160 print
'<b>'.$langs->trans(
"InformationOnTargetTables").
'</b>';
2161 print
'<div class="underbanner clearboth"></div>';
2162 print
'<div class="fichecenter">';
2163 print
'<table class="border centpercent">';
2166 print
'<tr><td width="25%">';
2167 print $langs->trans(
"TablesTarget");
2169 $listtables = array();
2170 foreach ($array_match_file_to_database as $code => $label) {
2172 if ($code > count($fieldssource)) {
2176 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
2177 $listtables[$alias] = $objimport->array_import_tables[0][$alias];
2179 if (count($listtables)) {
2181 foreach ($listtables as $val) {
2200 print $langs->trans(
"Error");
2206 print $langs->trans(
"FieldsTarget").
'</td><td>';
2207 $listfields = array();
2209 $sort_array_match_file_to_database = $array_match_file_to_database;
2210 ksort($sort_array_match_file_to_database);
2212 foreach ($sort_array_match_file_to_database as $code => $label) {
2215 if ($code > count($fieldssource)) {
2219 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
2220 $listfields[$i] = $langs->trans(
"Field").
' '.$code.
'->'.$label;
2222 print count($listfields) ? (join(
', ', $listfields)) : $langs->trans(
"Error");
2229 $arrayoferrors = array();
2230 $arrayofwarnings = array();
2231 $maxnboferrors = empty($conf->global->IMPORT_MAX_NB_OF_ERRORS) ? 50 : $conf->global->IMPORT_MAX_NB_OF_ERRORS;
2232 $maxnbofwarnings = empty($conf->global->IMPORT_MAX_NB_OF_WARNINGS) ? 50 : $conf->global->IMPORT_MAX_NB_OF_WARNINGS;
2244 $pathfile = $conf->import->dir_temp.
'/'.$filetoimport;
2245 $result = $obj->import_open_file($pathfile, $langs);
2247 global $tablewithentity_cache;
2248 $tablewithentity_cache = array();
2249 $sourcelinenb = 0; $endoffile = 0;
2251 while ($sourcelinenb < $nboflines && !$endoffile) {
2253 $arrayrecord = $obj->import_read_record();
2254 if ($arrayrecord ===
false) {
2255 $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');
2259 if ($excludefirstline && ($sourcelinenb < $excludefirstline)) {
2262 if ($endatlinenb && ($sourcelinenb > $endatlinenb)) {
2267 $result = $obj->import_insert($arrayrecord, $array_match_file_to_database, $objimport, count($fieldssource), $importid, $updatekeys);
2269 if (count($obj->errors)) {
2270 $arrayoferrors[$sourcelinenb] = $obj->errors;
2272 if (count($obj->warnings)) {
2273 $arrayofwarnings[$sourcelinenb] = $obj->warnings;
2275 if (!count($obj->errors) && !count($obj->warnings)) {
2280 $obj->import_close_file();
2282 print $langs->trans(
"ErrorFailedToOpenFile", $pathfile);
2285 if (count($arrayoferrors) > 0) {
2292 if (!empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0])) {
2294 foreach ($objimport->array_import_run_sql_after[0] as $sqlafterimport) {
2296 $resqlafterimport = $db->query($sqlafterimport);
2297 if (!$resqlafterimport) {
2298 $arrayoferrors[
'none'][] = array(
'lib'=>$langs->trans(
"Error running final request: ".$sqlafterimport));
2316 print
'<div class="info">';
2317 print $langs->trans(
"NbOfLinesImported", $nbok).
'</b><br>';
2318 print $langs->trans(
"NbInsert", empty($obj->nbinsert) ? 0 : $obj->nbinsert).
'<br>';
2319 print $langs->trans(
"NbUpdate", empty($obj->nbupdate) ? 0 : $obj->nbupdate).
'<br>';
2321 print
'<div class="center">';
2322 print $langs->trans(
"FileWasImported", $importid).
'<br>';
2323 print
'<span class="opacitymedium">'.$langs->trans(
"YouCanUseImportIdToFindRecord", $importid).
'</span><br>';
2346function show_elem($fieldssource, $pos, $key, $var, $nostyle =
'')
2348 global $conf, $langs;
2352 if ($key ==
'none') {
2354 print
"\n\n<!-- Box_no-key start-->\n";
2355 print
'<div class="box boximport" style="padding:0;">'.
"\n";
2356 print
'<table summary="boxtable_no-key" class="centpercent nobordernopadding">'.
"\n";
2358 print
"\n\n<!-- Box ".$pos.
" start -->\n";
2359 print
'<div class="box boximport" style="padding: 0;" id="boxto_'.$pos.
'">'.
"\n";
2361 print
'<table summary="boxtable'.$pos.
'" class="nobordernopadding centpercent tableimport">'.
"\n";
2364 if (($pos && $pos > count($fieldssource)) && (!isset($fieldssource[$pos][
"imported"]))) {
2374 } elseif ($key ==
'none') {
2375 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
2376 print
'<td class="nocellnopadding" width="16" style="font-weight: normal">';
2379 print
'<td style="font-weight: normal">';
2385 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
2386 print
'<td class="nocellnopadding" width="16" style="font-weight: normal">';
2389 print
img_picto($langs->trans(
"Column").
' '.
num2Alpha($pos - 1),
'file',
'class="pictofixedwith"');
2391 if (isset($fieldssource[$pos][
'imported']) && $fieldssource[$pos][
'imported'] ==
false) {
2392 print
'<td class="nowraponall boxtdunused" style="font-weight: normal">';
2394 print
'<td class="nowraponall tdoverflowmax500" style="font-weight: normal">';
2396 print $langs->trans(
"Column").
' '.
num2Alpha($pos - 1).
' (#'.$pos.
')';
2397 if (empty($fieldssource[$pos][
'example1'])) {
2398 $example = $fieldssource[$pos][
'label'];
2400 $example = $fieldssource[$pos][
'example1'];
2404 $example = utf8_encode($example);
2406 if (!empty($conf->dol_optimize_smallscreen)) {
2412 print
'<i class="opacitymedium">'.dol_escape_htmltag($example).
'</i>';
2421 print
"<!-- Box end -->\n\n";
2434 $i = count($fieldssource) + 1;
2437 foreach ($listofkey as $key => $val) {
2438 $maxkey = max($maxkey, $key);
2441 while ($i <= $maxkey) {
2442 if (empty($listofkey[$i])) {
2464 if ($position == count($array)) {
2465 $ret = $array + $insertArray;
2468 foreach ($array as $key => $value) {
2469 if ($position == $i++) {
2470 $ret += $insertArray;
2473 $ret[$key] = $value;
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Parent class for import file readers.
Class to manage Dolibarr users.
dol_filemtime($pathoffile)
Return time of a file.
dol_filesize($pathoffile)
Return size of a file.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Make control on an uploaded file from an GUI page and move it to final destination.
dol_count_nb_of_line($file)
Count number of lines in a file.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
num2Alpha($n)
Return a numeric value into an Excel like column number.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
img_error($titlealt='default')
Show error logo.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
utf8_check($str)
Check if a string is in UTF8.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
import_prepare_head($param, $maxstep=0)
Function to return list of tabs for import pages.
getnewkey(&$fieldssource, &$listofkey)
Return not used field number.
arrayInsert($array, $position, $insertArray)
Return array with element inserted in it at position $position.
show_elem($fieldssource, $pos, $key, $var, $nostyle='')
Function to put the movable box of a source field.
getMaxFileSizeArray()
Return the max allowed for file upload.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.