27 require_once
'../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/imports/class/import.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/modules/import/modules_import.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/import.lib.php';
37 $langs->loadLangs(array(
'exports',
'compta',
'errors'));
43 $entitytoicon = array(
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',
83 $entitytolang = array(
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 $separator_used = str_replace(
'\t',
"\t", $separator);
147 $objimport =
new Import($db);
148 $objimport->load_arrays($user, ($step == 1 ?
'' : $datatoimport));
157 if (empty($array_match_file_to_database)) {
158 $serialized_array_match_file_to_database = isset($_SESSION[
"dol_array_match_file_to_database_select"]) ? $_SESSION[
"dol_array_match_file_to_database_select"] :
'';
159 $array_match_file_to_database = array();
160 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
161 foreach ($fieldsarray as $elem) {
162 $tabelem = explode(
'=', $elem, 2);
164 $val = (isset($tabelem[1]) ? $tabelem[1] :
'');
166 $array_match_file_to_database[$key] = $val;
201 if ($action ==
'builddoc') {
203 $result = $objimport->build_file($user,
GETPOST(
'model',
'alpha'), $datatoimport, $array_match_file_to_database);
211 if ($action ==
'deleteprof') {
213 $objimport->fetch(
GETPOST(
"id",
'int'));
214 $result = $objimport->delete($user);
219 if ($action ==
'add_import_model') {
223 foreach ($array_match_file_to_database as $key => $val) {
227 $hexa .= $key.
'='.$val;
230 $objimport->model_name = $import_name;
231 $objimport->datatoimport = $datatoimport;
232 $objimport->hexa = $hexa;
233 $objimport->fk_user = (
GETPOST(
'visibility',
'aZ09') ==
'all' ? 0 : $user->id);
235 $result = $objimport->create($user);
237 setEventMessages($langs->trans(
"ImportModelSaved", $objimport->model_name), null,
'mesgs');
240 $langs->load(
"errors");
241 if ($objimport->errno ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
242 setEventMessages($langs->trans(
"ErrorImportDuplicateProfil"), null,
'errors');
248 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"ImportModelName")), null,
'errors');
252 if ($step == 3 && $datatoimport) {
253 if (
GETPOST(
'sendit') && !empty($conf->global->MAIN_UPLOAD_DOC)) {
257 $fullpath = $conf->import->dir_temp.
"/".$nowyearmonth.
'-'.$_FILES[
'userfile'][
'name'];
259 dol_syslog(
"File ".$fullpath.
" was added for import");
261 $langs->load(
"errors");
267 if ($action ==
'confirm_deletefile' && $confirm ==
'yes') {
268 $langs->load(
"other");
270 $param =
'&datatoimport='.urlencode($datatoimport).
'&format='.urlencode($format);
271 if ($excludefirstline) {
272 $param .=
'&excludefirstline='.urlencode($excludefirstline);
275 $param .=
'&endatlinenb='.urlencode($endatlinenb);
278 $file = $conf->import->dir_temp.
'/'.
GETPOST(
'urlfile');
285 Header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?step='.$step.$param);
290 if ($step == 4 && $action ==
'select_model') {
292 $_SESSION[
"dol_array_match_file_to_database"] =
'';
293 $serialized_array_match_file_to_database =
'';
294 $array_match_file_to_database = array();
298 $result = $objimport->fetch($importmodelid);
300 $serialized_array_match_file_to_database = $objimport->hexa;
301 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
302 foreach ($fieldsarray as $elem) {
303 $tabelem = explode(
'=', $elem);
307 $array_match_file_to_database[$key] = $val;
310 $_SESSION[
"dol_array_match_file_to_database"] = $serialized_array_match_file_to_database;
311 $_SESSION[
'dol_array_match_file_to_database_select'] = $_SESSION[
"dol_array_match_file_to_database"];
314 if ($action ==
'saveselectorder') {
316 $serialized_array_match_file_to_database =
'';
318 $selectorder = explode(
",",
GETPOST(
'selectorder'));
319 $fieldtarget = $fieldstarget = $objimport->array_import_fields[0];
320 foreach ($selectorder as $key => $code) {
321 $serialized_array_match_file_to_database .= $key.
'='.$code;
322 $serialized_array_match_file_to_database .=
',';
324 $serialized_array_match_file_to_database = substr($serialized_array_match_file_to_database, 0, -1);
325 dol_syslog(
'dol_array_match_file_to_database_select='.$serialized_array_match_file_to_database);
326 $_SESSION[
"dol_array_match_file_to_database_select"] = $serialized_array_match_file_to_database;
338 $help_url =
'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones';
342 if ($step == 1 || !$datatoimport) {
344 $serialized_array_match_file_to_database =
'';
345 $array_match_file_to_database = array();
346 $_SESSION[
"dol_array_match_file_to_database"] =
'';
347 $_SESSION[
"dol_array_match_file_to_database_select"] =
'';
350 if ($excludefirstline) {
351 $param .=
'&excludefirstline='.urlencode($excludefirstline);
354 $param .=
'&endatlinenb='.urlencode($endatlinenb);
357 $param .=
'&separator='.urlencode($separator);
360 $param .=
'&enclosure='.urlencode($enclosure);
369 print
'<div class="opacitymedium">'.$langs->trans(
"SelectImportDataSet").
'</div><br>';
372 print
'<div class="div-table-responsive-no-min">';
373 print
'<table class="noborder centpercent">';
374 print
'<tr class="liste_titre">';
375 print
'<td>'.$langs->trans(
"Module").
'</td>';
376 print
'<td>'.$langs->trans(
"ImportableDatas").
'</td>';
377 print
'<td> </td>';
380 if (count($objimport->array_import_module)) {
381 $sortedarrayofmodules =
dol_sort_array($objimport->array_import_module,
'position_of_profile',
'asc', 0, 0, 1);
382 foreach ($sortedarrayofmodules as $key => $value) {
384 print
'<tr class="oddeven"><td>';
385 $titleofmodule = $objimport->array_import_module[$key][
'module']->getName();
387 if (in_array($objimport->array_import_code[$key], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
388 $titleofmodule = $langs->trans(
"ProductOrService");
390 print $titleofmodule;
392 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[$key]);
393 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
394 print
img_object($objimport->array_import_module[$key][
'module']->getName(), $entityicon).
' ';
395 print $objimport->array_import_label[$key];
396 print
'</td><td style="text-align: right">';
397 if ($objimport->array_import_perms[$key]) {
398 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>';
400 print $langs->trans(
"NotEnoughPermissions");
405 print
'<tr><td class="oddeven" colspan="3">'.$langs->trans(
"NoImportableData").
'</td></tr>';
415 if ($step == 2 && $datatoimport) {
416 $param =
'&datatoimport='.urlencode($datatoimport);
417 if ($excludefirstline) {
418 $param .=
'&excludefirstline='.urlencode($excludefirstline);
421 $param .=
'&endatlinenb='.urlencode($endatlinenb);
424 $param .=
'&separator='.urlencode($separator);
427 $param .=
'&enclosure='.urlencode($enclosure);
436 print
'<div class="underbanner clearboth"></div>';
437 print
'<div class="fichecenter">';
439 print
'<table class="border tableforfield centpercent">';
442 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
444 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
446 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
447 $titleofmodule = $langs->trans(
"ProductOrService");
449 print $titleofmodule;
453 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
455 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
456 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
457 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
458 print $objimport->array_import_label[0];
466 print
'<form name="userfile" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" METHOD="POST">';
467 print
'<input type="hidden" name="token" value="'.newToken().
'">';
471 print
'<span class="opacitymedium">';
472 $s = $langs->trans(
"ChooseFormatOfFileToImport",
'{s1}');
473 $s = str_replace(
'{s1}',
img_picto(
'',
'next'), $s);
475 print
'</span><br><br>';
479 print
'<div class="div-table-responsive-no-min">';
480 print
'<table class="noborder centpercent" cellpadding="4">';
485 print
'<tr class="liste_titre"><td colspan="5">';
486 print $langs->trans(
"FileMustHaveOneOfFollowingFormat");
488 $list = $objmodelimport->liste_modeles($db);
489 foreach ($list as $key) {
490 print
'<tr class="oddeven">';
491 print
'<td width="16">'.img_picto_common($key, $objmodelimport->getPictoForKey($key)).
'</td>';
492 $text = $objmodelimport->getDriverDescForKey($key);
493 print
'<td>'.$form->textwithpicto($objmodelimport->getDriverLabelForKey($key), $text).
'</td>';
494 print
'<td style="text-align:center">';
495 print
'<a href="'.DOL_URL_ROOT.
'/imports/emptyexample.php?format='.$key.$param.
'" target="_blank" rel="noopener noreferrer">';
496 print
img_picto(
'',
'download',
'class="paddingright opacitymedium"');
497 print $langs->trans(
"DownloadEmptyExampleShort");
499 print
$form->textwithpicto(
'', $langs->trans(
"DownloadEmptyExample").
'.<br>'.$langs->trans(
"StarAreMandatory"));
502 print
'<td style="text-align:right">';
503 print
'<a href="'.DOL_URL_ROOT.
'/imports/import.php?step=3&format='.$key.$param.
'">'.
img_picto($langs->trans(
"SelectFormat"),
'next',
'class="fa-15"').
'</a>';
516 if ($step == 3 && $datatoimport) {
517 $param =
'&datatoimport='.urlencode($datatoimport).
'&format='.urlencode($format);
518 if ($excludefirstline) {
519 $param .=
'&excludefirstline='.urlencode($excludefirstline);
522 $param .=
'&endatlinenb='.urlencode($endatlinenb);
525 $param .=
'&separator='.urlencode($separator);
528 $param .=
'&enclosure='.urlencode($enclosure);
531 $list = $objmodelimport->liste_modeles($db);
542 if ($action ==
'delete') {
543 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?urlfile='.urlencode(
GETPOST(
'urlfile')).
'&step=3'.$param, $langs->trans(
'DeleteFile'), $langs->trans(
'ConfirmDeleteFile'),
'confirm_deletefile',
'', 0, 1);
546 print
'<div class="underbanner clearboth"></div>';
547 print
'<div class="fichecenter">';
549 print
'<table class="border tableforfield centpercent">';
552 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
554 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
556 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
557 $titleofmodule = $langs->trans(
"ProductOrService");
559 print $titleofmodule;
563 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
565 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
566 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
567 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
568 print $objimport->array_import_label[0];
574 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
576 print
'<div class="underbanner clearboth"></div>';
577 print
'<div class="fichecenter">';
578 print
'<table width="100%" class="border tableforfield">';
581 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
582 print
'<td class="nowraponall">';
583 $text = $objmodelimport->getDriverDescForKey($format);
584 print
$form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
585 print
'</td><td style="text-align:right" class="nowrap">';
586 print
'<a href="'.DOL_URL_ROOT.
'/imports/emptyexample.php?format='.$format.$param.
'" target="_blank" rel="noopener noreferrer">';
587 print
img_picto(
'',
'download',
'class="paddingright opacitymedium"');
588 print $langs->trans(
"DownloadEmptyExampleShort");
590 print
$form->textwithpicto(
'', $langs->trans(
"DownloadEmptyExample").
'.<br>'.$langs->trans(
"StarAreMandatory"));
599 if ($format ==
'xlsx' && !class_exists(
'XMLWriter')) {
600 $langs->load(
"install");
601 print
info_admin($langs->trans(
"ErrorPHPDoesNotSupport",
'php-xml'), 0, 0, 1,
'error');
607 print
'<form name="userfile" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="POST">';
608 print
'<input type="hidden" name="token" value="'.newToken().
'">';
609 print
'<input type="hidden" value="'.$step.
'" name="step">';
610 print
'<input type="hidden" value="'.dol_escape_htmltag($format).
'" name="format">';
611 print
'<input type="hidden" value="'.$excludefirstline.
'" name="excludefirstline">';
612 print
'<input type="hidden" value="'.$endatlinenb.
'" name="endatlinenb">';
613 print
'<input type="hidden" value="'.dol_escape_htmltag($separator).
'" name="separator">';
614 print
'<input type="hidden" value="'.dol_escape_htmltag($enclosure).
'" name="enclosure">';
615 print
'<input type="hidden" value="'.dol_escape_htmltag($datatoimport).
'" name="datatoimport">';
617 print
'<span class="opacitymedium">';
618 $s = $langs->trans(
"ChooseFileToImport",
'{s1}');
619 $s = str_replace(
'{s1}',
img_picto(
'',
'next'), $s);
621 print
'</span><br><br>';
626 print
'<div class="marginbottomonly">';
628 $maxmin = $maxfilesizearray[
'maxmin'];
630 print
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
632 print
'<input type="file" name="userfile" size="20" maxlength="80"> ';
633 $out = (empty($conf->global->MAIN_UPLOAD_DOC) ?
' disabled' :
'');
634 print
'<input type="submit" class="button small" value="'.$langs->trans(
"AddFile").
'"'.$out.
' name="sendit">';
636 if (!empty($conf->global->MAIN_UPLOAD_DOC)) {
637 $max = $conf->global->MAIN_UPLOAD_DOC;
638 $maxphp = @ini_get(
'upload_max_filesize');
639 if (preg_match(
'/k$/i', $maxphp)) {
640 $maxphp = (int) substr($maxphp, 0, -1) * 1;
642 if (preg_match(
'/m$/i', $maxphp)) {
643 $maxphp = (int) substr($maxphp, 0, -1) * 1024;
645 if (preg_match(
'/g$/i', $maxphp)) {
646 $maxphp = (int) substr($maxphp, 0, -1) * 1024 * 1024;
648 if (preg_match(
'/t$/i', $maxphp)) {
649 $maxphp = (int) substr($maxphp, 0, -1) * 1024 * 1024 * 1024;
651 $maxphp2 = @ini_get(
'post_max_size');
652 if (preg_match(
'/k$/i', $maxphp2)) {
653 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1;
655 if (preg_match(
'/m$/i', $maxphp2)) {
656 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024;
658 if (preg_match(
'/g$/i', $maxphp2)) {
659 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024 * 1024;
661 if (preg_match(
'/t$/i', $maxphp2)) {
662 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024 * 1024 * 1024;
666 $maxphptoshow = $maxphptoshowparam =
'';
668 $maxmin = min($max, $maxphp);
669 $maxphptoshow = $maxphp;
670 $maxphptoshowparam =
'upload_max_filesize';
673 $maxmin = min($max, $maxphp2);
674 if ($maxphp2 < $maxphp) {
675 $maxphptoshow = $maxphp2;
676 $maxphptoshowparam =
'post_max_size';
680 $langs->load(
'other');
682 $out .=
info_admin($langs->trans(
"ThisLimitIsDefinedInSetup", $max, $maxphptoshow), 1);
684 $out .=
' ('.$langs->trans(
"UploadDisabled").
')';
690 $filearray =
dol_dir_list($conf->import->dir_temp,
'files', 0,
'',
'',
'name', SORT_DESC);
691 if (count($filearray) > 0) {
692 print
'<div class="div-table-responsive-no-min">';
693 print
'<table class="noborder centpercent" width="100%" cellpadding="4">';
695 $dir = $conf->import->dir_temp;
699 foreach ($filearray as $key => $val) {
700 $file = $val[
'name'];
704 $file = utf8_encode($file);
707 if (preg_match(
'/^\./', $file)) {
711 $modulepart =
'import';
712 $urlsource = $_SERVER[
"PHP_SELF"].
'?step='.$step.$param.
'&filetoimport='.urlencode($filetoimport);
713 $relativepath = $file;
715 print
'<tr class="oddeven">';
717 print
img_mime($file,
'',
'pictofixedwidth');
718 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=3'.$param.
'" target="_blank" rel="noopener noreferrer">';
723 print
'<td style="text-align:right">'.dol_print_size(
dol_filesize($dir.
'/'.$file)).
'</td>';
725 print
'<td style="text-align:right">'.dol_print_date(
dol_filemtime($dir.
'/'.$file),
'dayhour').
'</td>';
727 print
'<td style="text-align:right"><a href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.
newToken().
'&step=3'.$param.
'&urlfile='.urlencode($relativepath);
728 print
'">'.img_delete().
'</a></td>';
730 print
'<td style="text-align:right">';
731 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?step=4'.$param.
'&filetoimport='.urlencode($relativepath).
'">'.
img_picto($langs->trans(
"NewImport"),
'next',
'class="fa-15"').
'</a>';
745 if ($step == 4 && $datatoimport) {
747 $serialized_array_match_file_to_database = isset($_SESSION[
"dol_array_match_file_to_database_select"]) ? $_SESSION[
"dol_array_match_file_to_database_select"] :
'';
748 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
749 $array_match_file_to_database = array();
750 foreach ($fieldsarray as $elem) {
751 $tabelem = explode(
'=', $elem, 2);
753 $val = (isset($tabelem[1]) ? $tabelem[1] :
'');
755 $array_match_file_to_database[$key] = $val;
764 $list = $objmodelimport->liste_modeles($db);
766 if (empty($separator)) {
767 $separator = (empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE) ?
',' : $conf->global->IMPORT_CSV_SEPARATOR_TO_USE);
771 if ($model ==
'csv' && strlen($separator) == 1 && !
GETPOSTISSET(
'separator')) {
773 $fh = fopen($conf->import->dir_temp.
'/'.$filetoimport,
'r');
775 $sline = fgets($fh, 1000000);
777 $nboccurence = substr_count($sline, $separator);
778 $nboccurencea = substr_count($sline,
',');
779 $nboccurenceb = substr_count($sline,
';');
781 if ($nboccurence == 0) {
782 if ($nboccurencea > 2) {
784 } elseif ($nboccurenceb > 2) {
792 $separator_used = str_replace(
'\t',
"\t", $separator);
795 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
796 $file =
"import_".$model.
".modules.php";
797 $classname =
"Import".ucfirst($model);
798 require_once $dir.$file;
799 $obj =
new $classname($db, $datatoimport);
800 if ($model ==
'csv') {
801 $obj->separator = $separator_used;
802 $obj->enclosure = $enclosure;
804 if ($model ==
'xlsx') {
805 if (!preg_match(
'/\.xlsx$/i', $filetoimport)) {
806 $langs->load(
"errors");
807 $param =
'&datatoimport='.$datatoimport.
'&format='.$format;
808 setEventMessages($langs->trans(
"ErrorFileMustHaveFormat", $model), null,
'errors');
809 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?step=3'.$param.
'&filetoimport='.urlencode($relativepath));
815 $array_match_file_to_database = array();
819 $fieldssource = array();
820 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport, $langs);
823 $arrayrecord = $obj->import_read_record();
826 foreach ($arrayrecord as $key => $val) {
827 if ($val[
"type"] != -1) {
828 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 128);
832 $obj->import_close_file();
836 $fieldstarget = $objimport->array_import_fields[0];
837 $minpos = min(count($fieldssource), count($fieldstarget));
841 $initialloadofstep4 =
false;
842 if (empty($_SESSION[
'dol_array_match_file_to_database_select'])) {
843 $initialloadofstep4 =
true;
847 if (count($array_match_file_to_database) == 0) {
853 $num = count($fieldssource);
854 while ($pos <= $num) {
855 if ($num >= 1 && $pos <= $num) {
857 foreach ($fieldstarget as $key => $val) {
858 if ($posbis < $pos) {
863 $array_match_file_to_database[$pos] = $key;
870 $array_match_database_to_file = array_flip($array_match_file_to_database);
874 $fieldstarget_tmp = array();
875 $arraykeysfieldtarget = array_keys($fieldstarget);
877 foreach ($fieldstarget as $key => $label) {
878 $isrequired = preg_match(
'/\*$/', $label);
879 if (!empty($isrequired)) {
880 $newlabel = substr($label, 0, -1);
881 $fieldstarget_tmp[$key] = array(
"label"=>$newlabel,
"required"=>
true);
883 $fieldstarget_tmp[$key] = array(
"label"=>$label,
"required"=>
false);
885 if (!empty($array_match_database_to_file[$key])) {
886 $fieldstarget_tmp[$key][
"imported"] =
true;
887 $fieldstarget_tmp[$key][
"position"] = $array_match_database_to_file[$key]-1;
889 while (!empty($array_match_database_to_file[$keytoswap])) {
890 if ($position+1 > $array_match_database_to_file[$keytoswap]) {
891 $keytoswapwith = $array_match_database_to_file[$keytoswap]-1;
892 $tmp = [$keytoswap=>$fieldstarget_tmp[$keytoswap]];
893 unset($fieldstarget_tmp[$keytoswap]);
894 $fieldstarget_tmp =
arrayInsert($fieldstarget_tmp, $keytoswapwith, $tmp);
895 $keytoswapwith = $arraykeysfieldtarget[$array_match_database_to_file[$keytoswap]-1];
896 $tmp = $fieldstarget_tmp[$keytoswapwith];
897 unset($fieldstarget_tmp[$keytoswapwith]);
898 $fieldstarget_tmp[$keytoswapwith] = $tmp;
899 $keytoswap = $keytoswapwith;
905 $fieldstarget_tmp[$key][
"imported"] =
false;
909 $fieldstarget = $fieldstarget_tmp;
918 $param =
'&format='.$format.
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport);
919 if ($excludefirstline) {
920 $param .=
'&excludefirstline='.urlencode($excludefirstline);
923 $param .=
'&endatlinenb='.urlencode($endatlinenb);
926 $param .=
'&separator='.urlencode($separator);
929 $param .=
'&enclosure='.urlencode($enclosure);
938 print
'<div class="underbanner clearboth"></div>';
939 print
'<div class="fichecenter">';
941 print
'<table class="centpercent border tableforfield">';
944 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
946 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
948 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
949 $titleofmodule = $langs->trans(
"ProductOrService");
951 print $titleofmodule;
955 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
957 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
958 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
959 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
960 print $objimport->array_import_label[0];
966 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
968 print
'<div class="underbanner clearboth"></div>';
969 print
'<div class="fichecenter">';
970 print
'<table width="100%" class="border tableforfield">';
973 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
975 $text = $objmodelimport->getDriverDescForKey($format);
976 print
$form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
980 if ($model ==
'csv') {
981 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
983 print
'<form method="POST">';
984 print
'<input type="hidden" name="token" value="'.newToken().
'">';
985 print
'<input type="hidden" value="'.$step.
'" name="step">';
986 print
'<input type="hidden" value="'.$format.
'" name="format">';
987 print
'<input type="hidden" value="'.$excludefirstline.
'" name="excludefirstline">';
988 print
'<input type="hidden" value="'.$endatlinenb.
'" name="endatlinenb">';
989 print
'<input type="hidden" value="'.$datatoimport.
'" name="datatoimport">';
990 print
'<input type="hidden" value="'.$filetoimport.
'" name="filetoimport">';
991 print $langs->trans(
"Separator").
' : ';
992 print
'<input type="text" class="width25 center" name="separator" value="'.dol_escape_htmltag($separator).
'"/>';
993 print
' '.$langs->trans(
"Enclosure").
' : ';
994 print
'<input type="text" class="width25 center" name="enclosure" value="'.dol_escape_htmltag($enclosure).
'"/> ';
995 print
'<input name="update" type="submit" value="'.$langs->trans(
'Update').
'" class="button smallpaddingimp" />';
1001 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
1003 $modulepart =
'import';
1004 $relativepath =
GETPOST(
'filetoimport');
1005 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
1006 print
img_mime($file,
'',
'pictofixedwidth');
1007 print $filetoimport;
1008 print
img_picto($langs->trans(
"Download"),
'download',
'class="paddingleft opacitymedium"');
1021 print
'<!-- List of source fields -->'.
"\n";
1022 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1023 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1024 print
'<input type="hidden" name="action" value="select_model">';
1025 print
'<input type="hidden" name="step" value="4">';
1026 print
'<input type="hidden" name="format" value="'.$format.
'">';
1027 print
'<input type="hidden" name="datatoimport" value="'.$datatoimport.
'">';
1028 print
'<input type="hidden" name="filetoimport" value="'.$filetoimport.
'">';
1029 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1030 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1031 print
'<input type="hidden" name="separator" value="'.dol_escape_htmltag($separator).
'">';
1032 print
'<input type="hidden" name="enclosure" value="'.dol_escape_htmltag($enclosure).
'">';
1035 print
'<div class="marginbottomonly">';
1036 print
'<span class="opacitymedium">';
1037 $s = $langs->trans(
"SelectImportFieldsSource",
'{s1}');
1038 $s = str_replace(
'{s1}',
img_picto(
'',
'grip_title',
'',
false, 0, 0,
'',
'', 0), $s);
1041 $htmlother->select_import_model($importmodelid,
'importmodelid', $datatoimport, 1, $user->id);
1042 print
'<input type="submit" class="button small reposition" value="'.$langs->trans(
"Select").
'">';
1047 print
'<div class="div-table-responsive-no-min">';
1048 print
'<table class="noborder centpercent">';
1049 print
'<tr class="liste_titre">';
1050 print
'<td>'.$langs->trans(
"FieldsInSourceFile").
'</td>';
1051 print
'<td>'.$langs->trans(
"FieldsInTargetDatabase").
'</td>';
1056 print
'<tr valign="top"><td width="50%" class="nopaddingleftimp">';
1058 $fieldsplaced = array();
1059 $valforsourcefieldnb = array();
1060 $listofkeys = array();
1061 foreach ($array_match_file_to_database as $key => $val) {
1062 $listofkeys[$key] = 1;
1065 print
"\n<!-- Box left container -->\n";
1066 print
'<div id="left" class="connectedSortable">'.
"\n";
1071 foreach ($fieldssource as $key => $val) {
1072 show_elem($fieldssource, $key, $val, $var);
1073 $listofkeys[$key] = 1;
1074 $fieldsplaced[$key] = 1;
1075 $valforsourcefieldnb[$lefti] = $key;
1078 if ($lefti > count($fieldstarget)) {
1085 print
"<!-- End box left container -->\n";
1088 print
'</td><td width="50%" class="nopaddingrightimp">';
1091 $optionsall = array();
1092 foreach ($fieldstarget as $code => $line) {
1095 $tmparray = explode(
'|', $line[
"label"]);
1097 foreach ($tmparray as $tmpkey => $tmpval) {
1098 $labeltoshow .= ($labeltoshow ?
' '.$langs->trans(
'or').
' ' :
'').$langs->transnoentities($tmpval);
1100 $optionsall[$code] = array(
'labelkey'=>$line[
'label'],
'labelkeyarray'=>$tmparray,
'label'=>$labeltoshow,
'required'=>(empty($line[
"required"]) ? 0 : 1),
'position'=>!empty($line[
'position']) ? $line[
'position'] : 0);
1105 $optionsall[$code][
'picto'] = $picto;
1112 $mandatoryfieldshavesource =
true;
1125 $modetoautofillmapping =
'session';
1126 if ($initialloadofstep4) {
1127 $modetoautofillmapping =
'guess';
1131 print
'<table class="nobordernopadding centpercent tableimport">';
1132 foreach ($fieldssource as $code => $line) {
1133 if ($i == $minpos) {
1136 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
1137 $entity = (!empty($objimport->array_import_entities[0][$code]) ? $objimport->array_import_entities[0][$code] : $objimport->array_import_icon[0]);
1139 $entityicon = !empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity;
1140 $entitylang = $entitytolang[$entity] ? $entitytolang[$entity] : $objimport->array_import_label[0];
1143 print
'<td class="nowraponall" style="font-weight: normal">=> </td>';
1144 print
'<td class="nowraponall" style="font-weight: normal">';
1149 $selectforline =
'';
1150 $selectforline .=
'<select id="selectorderimport_'.($i+1).
'" class="targetselectchange minwidth300" name="select_'.($i+1).
'">';
1151 if (!empty($line[
"imported"])) {
1152 $selectforline .=
'<option value="-1"> </option>';
1154 $selectforline .=
'<option selected="" value="-1"> </option>';
1158 $codeselectedarray = array();
1159 foreach ($optionsall as $tmpcode => $tmpval) {
1161 if (!empty($tmpval[
'picto'])) {
1162 $label .=
img_picto(
'', $tmpval[
'picto'],
'class="pictofixedwidth"');
1164 $label .= $tmpval[
'required'] ?
'<strong>' :
'';
1165 $label .= $tmpval[
'label'];
1166 $label .= $tmpval[
'required'] ?
'*</strong>' :
'';
1168 $tablealias = preg_replace(
'/(\..*)$/i',
'', $tmpcode);
1169 $tablename = !empty($objimport->array_import_tables[0][$tablealias]) ? $objimport->array_import_tables[0][$tablealias] :
"";
1173 $filecolumn = ($i + 1);
1175 if (empty($objimport->array_import_convertvalue[0][$tmpcode])) {
1178 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromref') {
1179 $htmltext .= $langs->trans(
"DataComeFromIdFoundFromRef", $langs->transnoentitiesnoconv($entitylang)).
'<br>';
1181 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromcodeid') {
1182 $htmltext .= $langs->trans(
"DataComeFromIdFoundFromCodeId", $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$tmpcode][
'dict'])).
'<br>';
1186 $example = !empty($objimport->array_import_examplevalues[0][$tmpcode])?$objimport->array_import_examplevalues[0][$tmpcode]:
"";
1188 if (empty($objimport->array_import_convertvalue[0][$tmpcode])) {
1190 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.str_replace(
'"',
'', $example).
'</b><br>';
1193 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromref') {
1194 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.$langs->transnoentitiesnoconv(
"ExampleAnyRefFoundIntoElement", $entitylang).($example ?
' ('.$langs->transnoentitiesnoconv(
"Example").
': '.str_replace(
'"',
'', $example).
')' :
'').
'</b><br>';
1195 } elseif ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromcodeid') {
1196 $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>';
1197 } elseif ($example) {
1198 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.str_replace(
'"',
'', $example).
'</b><br>';
1202 if (!empty($objimport->array_import_regex[0][$tmpcode])) {
1203 $htmltext .= $langs->trans(
"FormatControlRule").
': <b>'.str_replace(
'"',
'', $objimport->array_import_regex[0][$tmpcode]).
'</b><br>';
1207 $htmltext .= $langs->trans(
"InformationOnTargetTables").
': <b>'.$tablename.
"->".preg_replace(
'/^.*\./',
'', $tmpcode).
"</b>";
1209 $labelhtml = $label.
' '.
$form->textwithpicto(
'', $htmltext, 1,
'help',
'', 1);
1211 $selectforline .=
'<option value="'.$tmpcode.
'"';
1212 if ($modetoautofillmapping ==
'orderoftargets') {
1215 $selectforline .=
' selected';
1217 } elseif ($modetoautofillmapping ==
'guess') {
1221 if (preg_match(
'/^(.+)\((.+\..+)\)$/', $line[
'example1'], $regs)) {
1222 $tmpstring1 = $regs[1];
1223 $tmpstring2 = $regs[2];
1225 $tmpstring1 = $line[
'example1'];
1228 $tmpstring1 = strtolower(str_replace(
'*',
'', trim($tmpstring1)));
1229 $tmpstring2 = strtolower(str_replace(
'*',
'', trim($tmpstring2)));
1232 foreach ($tmpval[
'labelkeyarray'] as $tmpval2) {
1233 $labeltarget = $langs->transnoentities($tmpval2);
1235 if ($tmpstring1 && ($tmpstring1 == $tmpcode || $tmpstring1 == strtolower($labeltarget)
1236 || $tmpstring1 == strtolower(
dol_string_unaccent($labeltarget)) || $tmpstring1 == strtolower($tmpval2))) {
1237 if (empty($codeselectedarray[$code])) {
1238 $selectforline .=
' selected';
1239 $codeselectedarray[$code] = 1;
1242 } elseif ($tmpstring2 && ($tmpstring2 == $tmpcode || $tmpstring2 == strtolower($labeltarget)
1243 || $tmpstring2 == strtolower(
dol_string_unaccent($labeltarget)) || $tmpstring2 == strtolower($tmpval2))) {
1244 if (empty($codeselectedarray[$code])) {
1245 $selectforline .=
' selected';
1246 $codeselectedarray[$code] = 1;
1251 } elseif ($modetoautofillmapping ==
'session' && !empty($_SESSION[
'dol_array_match_file_to_database_select'])) {
1252 $tmpselectioninsession =
dolExplodeIntoArray($_SESSION[
'dol_array_match_file_to_database_select'],
',',
'=');
1254 if (!empty($tmpselectioninsession[($i+1)]) && $tmpselectioninsession[($i+1)] == $tmpcode) {
1255 $selectforline .=
' selected';
1257 $selectforline .=
' data-debug="'.$tmpcode.
'-'.$code.
'-'.$j.
'-'.(!empty($tmpselectioninsession[($i+1)]) ? $tmpselectioninsession[($i+1)] :
"").
'"';
1259 $selectforline .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
1260 $selectforline .=
'>';
1261 $selectforline .= $label;
1262 $selectforline .=
'</options>';
1265 $selectforline .=
'</select>';
1266 $selectforline .=
ajax_combobox(
'selectorderimport_'.($i+1));
1268 print $selectforline;
1273 print
'<td class="nowraponall" style="font-weight:normal; text-align:right">';
1276 $htmltext =
'<b><u>'.$langs->trans(
"FieldSource").
'</u></b><br>';
1278 $htmltext .= $langs->trans(
"DataComeFromFileFieldNb", $filecolumntoshow).
'<br>';
1280 print
$form->textwithpicto(
'', $htmltext);
1291 print
'<tr class="liste_titre"><td colspan="2">'.$langs->trans(
"Note").
'</td></tr>';
1292 print
'<tr><td colspan="2"><div id="div-mandatory-target-fields-not-mapped"></div></td></tr>';
1298 if (!empty($conf->use_javascript_ajax)) {
1299 print
'<script type="text/javascript">'.
"\n";
1300 print
'var previousselectedvalueimport = "0";'.
"\n";
1301 print
'var previousselectedlabelimport = "0";'.
"\n";
1302 print
'var arrayofselectedvalues = [];'.
"\n";
1303 print
'var arrayoftargetfields = [];'.
"\n";
1304 print
'var arrayoftargetmandatoryfields = [];'.
"\n";
1308 foreach ($fieldstarget as $key => $val) {
1309 print
"arrayoftargetfields[".$tmpi.
"] = '".
dol_escape_js($langs->trans($val[
'label'])).
"'; ";
1310 if ($val[
'required']) {
1311 print
"arrayoftargetmandatoryfields[".$tmpi.
"] = '".
dol_escape_js($key).
"'; ";
1317 print
'$(document).ready(function () {'.
"\n";
1319 print
'setOptionsToDisabled();'.
"\n";
1320 print
'saveSelection();'.
"\n";
1322 print
'$(".targetselectchange").focus(function(){'.
"\n";
1323 print
' previousselectedvalueimport = $(this).val();'.
"\n";
1324 print
' previousselectedlabelimport = $(this).children("option:selected").text();'.
"\n";
1325 print
' console.log("previousselectedvalueimport="+previousselectedvalueimport)'.
"\n";
1332 print
'function setOptionsToDisabled() {'.
"\n";
1333 print
' console.log("Remove the disabled flag everywhere");'.
"\n";
1334 print
' $("select.targetselectchange").not($( this )).find(\'option\').prop("disabled", false);'.
"\n";
1335 print
' arrayofselectedvalues = [];'.
"\n";
1337 print
' $("select.targetselectchange").each(function(){'.
"\n";
1338 print
' id = $(this).attr(\'id\')'.
"\n";
1339 print
' value = $(this).val()'.
"\n";
1340 print
' console.log("a selected value has been found for component "+id+" = "+value);'.
"\n";
1341 print
' arrayofselectedvalues.push(value);'.
"\n";
1344 print
' console.log("List of all selected values arrayofselectedvalues");'.
"\n";
1345 print
' console.log(arrayofselectedvalues);'.
"\n";
1346 print
' console.log("Set the option to disabled for every entry that is currently selected somewhere else (so into arrayofselectedvalues)");'.
"\n";
1348 print
' $.each(arrayofselectedvalues, function(key, value) {'.
"\n";
1349 print
' if (value != -1) {'.
"\n";
1350 print
' console.log("Process key="+key+" value="+value+" to disable.");'.
"\n";
1351 print
' $("select.targetselectchange").find(\'option[value="\'+value+\'"]:not(:selected)\').prop("disabled", true);'.
"\n";
1357 print
'function saveSelection() {'.
"\n";
1359 print
' arrayselectedfields = [];'.
"\n";
1360 print
' arrayselectedfields.push(0);'.
"\n";
1362 print
' $.each( arrayofselectedvalues, function( key, value ) {'.
"\n";
1363 print
' if (value != -1) {'.
"\n";
1364 print
' arrayselectedfields.push(value);'.
"\n";
1365 print
' } else {'.
"\n";
1366 print
' arrayselectedfields.push(0);'.
"\n";
1370 print
" $.ajax({\n";
1371 print
" type: 'POST',\n";
1372 print
" dataType: 'json',\n";
1373 print
" url: '".dol_escape_js($_SERVER[
"PHP_SELF"]).
"?action=saveselectorder&token=".
newToken().
"',\n";
1374 print
" data: 'selectorder='+arrayselectedfields.toString(),\n";
1375 print
" success: function(){\n";
1376 print
" console.log('The selected fields have been saved into '+arrayselectedfields.toString());\n";
1381 print
' console.log("arrayselectedfields");';
1382 print
' console.log(arrayselectedfields);';
1383 print
' console.log("arrayoftargetmandatoryfields");';
1384 print
' console.log(arrayoftargetmandatoryfields);';
1385 print
" listtoshow = '';";
1386 print
" nbelement = arrayoftargetmandatoryfields.length
1387 for (let i = 0; i < nbelement; i++) {
1388 if (arrayoftargetmandatoryfields[i] && ! arrayselectedfields.includes(arrayoftargetmandatoryfields[i])) {
1389 console.log(arrayoftargetmandatoryfields[i]+' not mapped');
1390 listtoshow = listtoshow + (listtoshow ? ', ' : '') + '<b>' + arrayoftargetfields[i] + '*</b>';
1393 console.log(listtoshow);
1395 listtoshow = '".dol_escape_js(
img_warning($langs->trans(
"MandatoryTargetFieldsNotMapped")).
' '.$langs->trans(
"MandatoryTargetFieldsNotMapped")).
": ' + listtoshow;
1396 $('#div-mandatory-target-fields-not-mapped').html(listtoshow);
1398 $('#div-mandatory-target-fields-not-mapped').html('<span class=\"opacitymedium\">".
dol_escape_js($langs->trans(
"AllTargetMandatoryFieldsAreMapped")).
"</span>');
1405 print
'$(".targetselectchange").change(function(){'.
"\n";
1406 print
' setOptionsToDisabled();'.
"\n";
1408 print
' if(previousselectedlabelimport != "" && previousselectedvalueimport != -1) {'.
"\n";
1409 print
' let valuetochange = $(this).val(); '.
"\n";
1410 print
' $(".boxtdunused").each(function(){'.
"\n";
1411 print
' if ($(this).text().includes(valuetochange)){'.
"\n";
1412 print
' arraychild = $(this)[0].childNodes'.
"\n";
1413 print
' arraytexttomodify = arraychild[0].textContent.split(" ")'.
"\n";
1414 print
' arraytexttomodify[1] = previousselectedvalueimport '.
"\n";
1415 print
' textmodified = arraytexttomodify.join(" ") '.
"\n";
1416 print
' arraychild[0].textContent = textmodified'.
"\n";
1417 print
' arraychild[1].innerHTML = previousselectedlabelimport'.
"\n";
1421 print
' $(this).blur()'.
"\n";
1423 print
' saveSelection()'.
"\n";
1427 print
'</script>'.
"\n";
1433 print
'<div class="tabsAction">';
1435 if (count($array_match_file_to_database)) {
1436 if ($mandatoryfieldshavesource) {
1437 print
'<a class="butAction saveorderselect" href="import.php?step=5'.$param.
'&filetoimport='.urlencode($filetoimport).
'">'.$langs->trans(
"NextStep").
'</a>';
1439 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"SomeMandatoryFieldHaveNoSource")).
'">'.$langs->trans(
"NextStep").
'</a>';
1447 if (count($array_match_file_to_database)) {
1449 print
'<!-- Area to add new import profile -->'.
"\n";
1450 print
'<div class="marginbottomonly"><span class="opacitymedium">'.$langs->trans(
"SaveImportModel").
'</span></div>';
1452 print
'<form class="nocellnopadd" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1453 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1454 print
'<input type="hidden" name="action" value="add_import_model">';
1455 print
'<input type="hidden" name="step" value="'.$step.
'">';
1456 print
'<input type="hidden" name="format" value="'.$format.
'">';
1457 print
'<input type="hidden" name="datatoimport" value="'.$datatoimport.
'">';
1458 print
'<input type="hidden" name="filetoimport" value="'.$filetoimport.
'">';
1459 print
'<input type="hidden" name="hexa" value="'.$hexa.
'">';
1460 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1461 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1462 print
'<input type="hidden" name="page_y" value="">';
1463 print
'<input type="hidden" value="'.dol_escape_htmltag($separator).
'" name="separator">';
1464 print
'<input type="hidden" value="'.dol_escape_htmltag($enclosure).
'" name="enclosure">';
1466 print
'<div class="div-table-responsive-no-min">';
1467 print
'<table summary="selectofimportprofil" class="noborder centpercent">';
1468 print
'<tr class="liste_titre">';
1469 print
'<td>'.$langs->trans(
"ImportModelName").
'</td>';
1470 print
'<td>'.$langs->trans(
"Visibility").
'</td>';
1474 $nameofimportprofile = str_replace(
' ',
'-', $langs->trans(
"ImportProfile").
' '.$titleofmodule.
' '.
dol_print_date(
dol_now(
'gmt'),
'dayxcard'));
1476 $nameofimportprofile = $import_name;
1479 print
'<tr class="oddeven">';
1480 print
'<td><input name="import_name" class="minwidth300" value="'.$nameofimportprofile.
'"></td>';
1482 $arrayvisibility = array(
'private'=>$langs->trans(
"Private"),
'all'=>$langs->trans(
"Everybody"));
1483 print
$form->selectarray(
'visibility', $arrayvisibility,
'private');
1485 print
'<td class="right">';
1486 print
'<input type="submit" class="button smallpaddingimp reposition" value="'.$langs->trans(
"SaveImportProfile").
'">';
1490 $sql =
"SELECT rowid, label, fk_user, entity";
1491 $sql .=
" FROM ".MAIN_DB_PREFIX.
"import_model";
1492 $sql .=
" WHERE type = '".$db->escape($datatoimport).
"'";
1493 if (empty($conf->global->EXPORTS_SHARE_MODELS)) {
1494 $sql .=
" AND fk_user IN (0, ".((int) $user->id).
")";
1496 $sql .=
" ORDER BY rowid";
1498 $resql = $db->query($sql);
1500 $num = $db->num_rows(
$resql);
1502 $tmpuser =
new user($db);
1506 $obj = $db->fetch_object(
$resql);
1508 print
'<tr class="oddeven"><td>';
1512 if (empty($obj->fk_user)) {
1513 print $langs->trans(
"Everybody");
1515 $tmpuser->fetch($obj->fk_user);
1516 print $tmpuser->getNomUrl(-1);
1519 print
'<td class="right">';
1520 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?step='.$step.$param.
'&action=deleteprof&token='.
newToken().
'&id='.$obj->rowid.
'&filetoimport='.urlencode($filetoimport).
'">';
1538 if ($step == 5 && $datatoimport) {
1539 $max_execution_time_for_importexport = (empty($conf->global->IMPORT_MAX_EXECUTION_TIME) ? 300 : $conf->global->IMPORT_MAX_EXECUTION_TIME);
1540 $max_time = @ini_get(
"max_execution_time");
1541 if ($max_time && $max_time < $max_execution_time_for_importexport) {
1542 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.");
1543 @ini_set(
"max_execution_time", $max_execution_time_for_importexport);
1547 $list = $objmodelimport->liste_modeles($db);
1550 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
1551 $file =
"import_".$model.
".modules.php";
1552 $classname =
"Import".ucfirst($model);
1553 require_once $dir.$file;
1554 $obj =
new $classname($db, $datatoimport);
1555 if ($model ==
'csv') {
1556 $obj->separator = $separator_used;
1557 $obj->enclosure = $enclosure;
1561 $fieldssource = array();
1562 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport, $langs);
1566 $arrayrecord = $obj->import_read_record();
1569 foreach ($arrayrecord as $key => $val) {
1570 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 24);
1573 $obj->import_close_file();
1576 $nboflines = $obj->import_get_nb_of_lines($conf->import->dir_temp.
'/'.$filetoimport);
1578 $param =
'&leftmenu=import&format='.urlencode($format).
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport).
'&nboflines='.urlencode($nboflines).
'&separator='.urlencode($separator).
'&enclosure='.urlencode($enclosure);
1580 if ($excludefirstline) {
1581 $param .=
'&excludefirstline='.urlencode($excludefirstline);
1584 $param .=
'&endatlinenb='.urlencode($endatlinenb);
1586 if (!empty($updatekeys)) {
1587 $param .=
'&updatekeys[]='.implode(
'&updatekeys[]=', $updatekeys);
1590 llxHeader(
'', $langs->trans(
"NewImport"),
'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones');
1595 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?'.$param2.
'" method="POST">';
1596 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1597 print
'<input type="hidden" name="step" value="5">';
1598 print
'<input type="hidden" name="action" value="launchsimu">';
1602 print
'<div class="underbanner clearboth"></div>';
1603 print
'<div class="fichecenter">';
1605 print
'<table width="100%" class="border tableforfield">';
1608 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
1610 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
1612 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
1613 $titleofmodule = $langs->trans(
"ProductOrService");
1615 print $titleofmodule;
1619 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
1621 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
1622 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
1623 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
1624 print $objimport->array_import_label[0];
1630 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
1632 print
'<div class="underbanner clearboth"></div>';
1633 print
'<div class="fichecenter">';
1634 print
'<table width="100%" class="border tableforfield">';
1637 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
1639 $text = $objmodelimport->getDriverDescForKey($format);
1640 print
$form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
1644 if ($model ==
'csv') {
1645 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
1648 print
' '.$langs->trans(
"Enclosure").
' : '.
dol_escape_htmltag($enclosure);
1653 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
1655 $modulepart =
'import';
1656 $relativepath =
GETPOST(
'filetoimport');
1657 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
1658 print
img_mime($file,
'',
'pictofixedwidth');
1659 print $filetoimport;
1660 print
img_picto($langs->trans(
"Download"),
'download',
'class="paddingleft opacitymedium"');
1666 print $langs->trans(
"NbOfSourceLines");
1673 print $langs->trans(
"ImportFromToLine");
1675 if ($action ==
'launchsimu') {
1676 print
'<input type="number" class="maxwidth50 right" name="excludefirstlinebis" disabled="disabled" value="'.$excludefirstline.
'">';
1677 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1679 print
'<input type="number" class="maxwidth50 right" name="excludefirstline" value="'.$excludefirstline.
'">';
1680 print
$form->textwithpicto(
"", $langs->trans(
"SetThisValueTo2ToExcludeFirstLine"));
1683 if ($action ==
'launchsimu') {
1684 print
'<input type="text" class="maxwidth50" name="endatlinenbbis" disabled="disabled" value="'.$endatlinenb.
'">';
1685 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1687 print
'<input type="text" class="maxwidth50" name="endatlinenb" value="'.$endatlinenb.
'">';
1688 print
$form->textwithpicto(
"", $langs->trans(
"KeepEmptyToGoToEndOfFile"));
1690 if ($action ==
'launchsimu') {
1691 print
' <a href="'.$_SERVER[
"PHP_SELF"].
'?step=5'.$param.
'">'.$langs->trans(
"Modify").
'</a>';
1693 if ($excludefirstline == 2) {
1694 print
$form->textwithpicto(
"", $langs->trans(
"WarningFirstImportedLine", $excludefirstline), 1,
'warning',
"warningexcludefirstline");
1696 $( document ).ready(function() {
1697 $("input[name=\'excludefirstline\']").on("change",function(){
1698 if($(this).val() <= 1){
1699 $(".warningexcludefirstline").hide();
1701 $(".warningexcludefirstline").show();
1711 print
$form->textwithpicto($langs->trans(
"KeysToUseForUpdates"), $langs->trans(
"SelectPrimaryColumnsForUpdateAttempt"));
1713 if ($action ==
'launchsimu') {
1714 if (count($updatekeys)) {
1715 print
$form->multiselectarray(
'updatekeysbis', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0,
'', 1,
'80%',
'disabled');
1717 print
'<span class="opacitymedium">'.$langs->trans(
"NoUpdateAttempt").
'</span> -';
1719 foreach ($updatekeys as $val) {
1720 print
'<input type="hidden" name="updatekeys[]" value="'.$val.
'">';
1722 print
' <a href="'.$_SERVER[
"PHP_SELF"].
'?step=5'.$param.
'">'.$langs->trans(
"Modify").
'</a>';
1724 if (is_array($objimport->array_import_updatekeys[0]) && count($objimport->array_import_updatekeys[0])) {
1725 print
$form->multiselectarray(
'updatekeys', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0,
'', 1,
'80%');
1728 print
'<span class="opacitymedium">'.$langs->trans(
"UpdateNotYetSupportedForThisImport").
'</span>';
1740 print
load_fiche_titre($langs->trans(
"InformationOnTargetTables"),
'',
'file-import');
1742 print
'<div class="underbanner clearboth"></div>';
1743 print
'<div class="fichecenter">';
1745 print
'<table width="100%" class="border tableforfield">';
1748 print
'<tr><td class="titlefieldcreate">';
1749 print $langs->trans(
"TablesTarget");
1751 $listtables = array();
1752 $sort_array_match_file_to_database = $array_match_file_to_database;
1753 foreach ($array_match_file_to_database as $code => $label) {
1755 if ($code > count($fieldssource)) {
1759 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
1760 $listtables[$alias] = $objimport->array_import_tables[0][$alias];
1762 if (count($listtables)) {
1765 foreach ($listtables as $val) {
1784 print $langs->trans(
"Error");
1790 print $langs->trans(
"FieldsTarget").
'</td><td>';
1791 $listfields = array();
1794 $sort_array_match_file_to_database = $array_match_file_to_database;
1795 ksort($sort_array_match_file_to_database);
1797 foreach ($sort_array_match_file_to_database as $code => $label) {
1800 if ($code > count($fieldssource)) {
1804 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
1805 $listfields[$i] =
'<span class="nowrap">'.$langs->trans(
"Column").
' '.
num2Alpha($code - 1).
' -> '.$label.
'</span>';
1807 print count($listfields) ? (join(
', ', $listfields)) : $langs->trans(
"Error");
1816 if ($action !=
'launchsimu') {
1818 print
'<br><span class="opacitymedium">';
1819 print $langs->trans(
"NowClickToTestTheImport", $langs->transnoentitiesnoconv(
"RunSimulateImportFile")).
'</span><br>';
1823 print
'<div class="center">';
1824 if ($user->rights->import->run) {
1825 print
'<input type="submit" class="butAction" value="'.$langs->trans(
"RunSimulateImportFile").
'">';
1827 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunSimulateImportFile").
'</a>';
1832 $arrayoferrors = array();
1833 $arrayofwarnings = array();
1834 $maxnboferrors = empty($conf->global->IMPORT_MAX_NB_OF_ERRORS) ? 50 : $conf->global->IMPORT_MAX_NB_OF_ERRORS;
1835 $maxnbofwarnings = empty($conf->global->IMPORT_MAX_NB_OF_WARNINGS) ? 50 : $conf->global->IMPORT_MAX_NB_OF_WARNINGS;
1847 $pathfile = $conf->import->dir_temp.
'/'.$filetoimport;
1848 $result = $obj->import_open_file($pathfile, $langs);
1850 global $tablewithentity_cache;
1851 $tablewithentity_cache = array();
1852 $sourcelinenb = 0; $endoffile = 0;
1855 while (($sourcelinenb < $nboflines) && !$endoffile) {
1859 $arrayrecord = $obj->import_read_record();
1860 if ($arrayrecord ===
false) {
1861 $arrayofwarnings[$sourcelinenb][0] = array(
'lib'=>
'File has '.$nboflines.
' lines. However we reach end of file after record '.$sourcelinenb.
'. This may occurs when some records are split onto several lines. Ensure the complete string is delimited correctly when there is a separator character in the text string.',
'type'=>
'EOF_RECORD_ON_SEVERAL_LINES');
1865 if ($excludefirstline && ($sourcelinenb < $excludefirstline)) {
1868 if ($endatlinenb && ($sourcelinenb > $endatlinenb)) {
1873 $result = $obj->import_insert($arrayrecord, $array_match_file_to_database, $objimport, count($fieldssource), $importid, $updatekeys);
1875 if (count($obj->errors)) {
1876 $arrayoferrors[$sourcelinenb] = $obj->errors;
1878 if (count($obj->warnings)) {
1879 $arrayofwarnings[$sourcelinenb] = $obj->warnings;
1881 if (!count($obj->errors) && !count($obj->warnings)) {
1886 $obj->import_close_file();
1888 print $langs->trans(
"ErrorFailedToOpenFile", $pathfile);
1895 if (!empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0])) {
1897 foreach ($objimport->array_import_run_sql_after[0] as $sqlafterimport) {
1899 $resqlafterimport = $db->query($sqlafterimport);
1900 if (!$resqlafterimport) {
1901 $arrayoferrors[
'none'][] = array(
'lib'=>$langs->trans(
"Error running final request: ".$sqlafterimport));
1910 if (!count($arrayoferrors) && !count($arrayofwarnings)) {
1912 print
'<div class="info">';
1913 print
'<div class=""><b>'.$langs->trans(
"ResultOfSimulationNoError").
'</b></div>';
1914 print $langs->trans(
"NbInsert", empty($obj->nbinsert) ? 0 : $obj->nbinsert).
'<br>';
1915 print $langs->trans(
"NbUpdate", empty($obj->nbupdate) ? 0 : $obj->nbupdate).
'<br>';
1920 print
'<div class="warning">';
1921 print $langs->trans(
"NbOfLinesOK", $nbok).
'...<br>';
1928 if (count($arrayoferrors)) {
1929 print
img_error().
' <b>'.$langs->trans(
"ErrorsOnXLines", count($arrayoferrors)).
'</b><br>';
1930 print
'<table width="100%" class="border"><tr><td>';
1931 foreach ($arrayoferrors as $key => $val) {
1933 if ($nboferrors > $maxnboferrors) {
1934 print $langs->trans(
"TooMuchErrors", (count($arrayoferrors) - $nboferrors)).
"<br>";
1938 foreach ($val as $i => $err) {
1939 print
' > '.dol_escape_htmltag($err[
'lib']).
'<br>';
1942 print
'</td></tr></table>';
1948 if (count($arrayofwarnings)) {
1949 print
img_warning().
' <b>'.$langs->trans(
"WarningsOnXLines", count($arrayofwarnings)).
'</b><br>';
1950 print
'<table width="100%" class="border"><tr><td>';
1951 foreach ($arrayofwarnings as $key => $val) {
1953 if ($nbofwarnings > $maxnbofwarnings) {
1954 print $langs->trans(
"TooMuchWarnings", (count($arrayofwarnings) - $nbofwarnings)).
"<br>";
1958 foreach ($val as $i => $err) {
1959 print
' > '.dol_escape_htmltag($err[
'lib']).
'<br>';
1962 print
'</td></tr></table>';
1969 print
'<div class="center">';
1970 print
'<span class="opacitymedium">'.$langs->trans(
"NowClickToRunTheImport", $langs->transnoentitiesnoconv(
"RunImportFile")).
'</span><br>';
1979 print
'<div class="center">';
1980 if ($user->rights->import->run) {
1981 if (empty($nboferrors)) {
1982 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/imports/import.php?leftmenu=import&step=6&importid='.$importid.$param.
'">'.$langs->trans(
"RunImportFile").
'</a>';
1986 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"CorrectErrorBeforeRunningImport")).
'">'.$langs->trans(
"RunImportFile").
'</a>';
1989 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunSimulateImportFile").
'</a>';
1991 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunImportFile").
'</a>';
2001 if ($step == 6 && $datatoimport) {
2002 $max_execution_time_for_importexport = (empty($conf->global->IMPORT_MAX_EXECUTION_TIME) ? 300 : $conf->global->IMPORT_MAX_EXECUTION_TIME);
2003 $max_time = @ini_get(
"max_execution_time");
2004 if ($max_time && $max_time < $max_execution_time_for_importexport) {
2005 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.");
2006 @ini_set(
"max_execution_time", $max_execution_time_for_importexport);
2010 $list = $objmodelimport->liste_modeles($db);
2011 $importid =
GETPOST(
"importid",
'alphanohtml');
2015 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
2016 $file =
"import_".$model.
".modules.php";
2017 $classname =
"Import".ucfirst($model);
2018 require_once $dir.$file;
2019 $obj =
new $classname($db, $datatoimport);
2020 if ($model ==
'csv') {
2021 $obj->separator = $separator_used;
2022 $obj->enclosure = $enclosure;
2026 $fieldssource = array();
2027 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport, $langs);
2030 $arrayrecord = $obj->import_read_record();
2033 foreach ($arrayrecord as $key => $val) {
2034 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 24);
2037 $obj->import_close_file();
2040 $nboflines = (!empty($_GET[
"nboflines"]) ? $_GET[
"nboflines"] :
dol_count_nb_of_line($conf->import->dir_temp.
'/'.$filetoimport));
2042 $param =
'&format='.$format.
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport).
'&nboflines='.urlencode($nboflines);
2043 if ($excludefirstline) {
2044 $param .=
'&excludefirstline='.urlencode($excludefirstline);
2047 $param .=
'&endatlinenb='.urlencode($endatlinenb);
2050 $param .=
'&separator='.urlencode($separator);
2053 $param .=
'&enclosure='.urlencode($enclosure);
2056 llxHeader(
'', $langs->trans(
"NewImport"),
'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones');
2062 print
'<div class="underbanner clearboth"></div>';
2063 print
'<div class="fichecenter">';
2065 print
'<table width="100%" class="border">';
2068 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
2070 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
2072 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
2073 $titleofmodule = $langs->trans(
"ProductOrService");
2075 print $titleofmodule;
2079 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
2081 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
2082 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
2083 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
2084 print $objimport->array_import_label[0];
2090 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
2092 print
'<div class="underbanner clearboth"></div>';
2093 print
'<div class="fichecenter">';
2094 print
'<table width="100%" class="border">';
2097 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
2099 $text = $objmodelimport->getDriverDescForKey($format);
2100 print
$form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
2104 if ($model ==
'csv') {
2105 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
2107 print $langs->trans(
"Separator").
' : ';
2108 print htmlentities($separator);
2109 print
' '.$langs->trans(
"Enclosure").
' : ';
2110 print htmlentities($enclosure);
2115 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
2117 $modulepart =
'import';
2118 $relativepath =
GETPOST(
'filetoimport');
2119 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
2120 print
img_mime($file,
'',
'pictofixedwidth');
2121 print $filetoimport;
2127 print $langs->trans(
"NbOfSourceLines");
2134 print $langs->trans(
"ImportFromLine");
2136 print
'<input type="text" size="4" name="excludefirstline" disabled="disabled" value="'.$excludefirstline.
'">';
2141 print $langs->trans(
"EndAtLineNb");
2143 print
'<input type="text" size="4" name="endatlinenb" disabled="disabled" value="'.$endatlinenb.
'">';
2151 print
'<b>'.$langs->trans(
"InformationOnTargetTables").
'</b>';
2152 print
'<div class="underbanner clearboth"></div>';
2153 print
'<div class="fichecenter">';
2154 print
'<table class="border centpercent">';
2157 print
'<tr><td width="25%">';
2158 print $langs->trans(
"TablesTarget");
2160 $listtables = array();
2161 foreach ($array_match_file_to_database as $code => $label) {
2163 if ($code > count($fieldssource)) {
2167 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
2168 $listtables[$alias] = $objimport->array_import_tables[0][$alias];
2170 if (count($listtables)) {
2172 foreach ($listtables as $val) {
2191 print $langs->trans(
"Error");
2197 print $langs->trans(
"FieldsTarget").
'</td><td>';
2198 $listfields = array();
2200 $sort_array_match_file_to_database = $array_match_file_to_database;
2201 ksort($sort_array_match_file_to_database);
2203 foreach ($sort_array_match_file_to_database as $code => $label) {
2206 if ($code > count($fieldssource)) {
2210 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
2211 $listfields[$i] = $langs->trans(
"Field").
' '.$code.
'->'.$label;
2213 print count($listfields) ? (join(
', ', $listfields)) : $langs->trans(
"Error");
2220 $arrayoferrors = array();
2221 $arrayofwarnings = array();
2222 $maxnboferrors = empty($conf->global->IMPORT_MAX_NB_OF_ERRORS) ? 50 : $conf->global->IMPORT_MAX_NB_OF_ERRORS;
2223 $maxnbofwarnings = empty($conf->global->IMPORT_MAX_NB_OF_WARNINGS) ? 50 : $conf->global->IMPORT_MAX_NB_OF_WARNINGS;
2235 $pathfile = $conf->import->dir_temp.
'/'.$filetoimport;
2236 $result = $obj->import_open_file($pathfile, $langs);
2238 global $tablewithentity_cache;
2239 $tablewithentity_cache = array();
2240 $sourcelinenb = 0; $endoffile = 0;
2242 while ($sourcelinenb < $nboflines && !$endoffile) {
2244 $arrayrecord = $obj->import_read_record();
2245 if ($arrayrecord ===
false) {
2246 $arrayofwarnings[$sourcelinenb][0] = array(
'lib'=>
'File has '.$nboflines.
' lines. However we reach end of file after record '.$sourcelinenb.
'. This may occurs when some records are split onto several lines.',
'type'=>
'EOF_RECORD_ON_SEVERAL_LINES');
2250 if ($excludefirstline && ($sourcelinenb < $excludefirstline)) {
2253 if ($endatlinenb && ($sourcelinenb > $endatlinenb)) {
2258 $result = $obj->import_insert($arrayrecord, $array_match_file_to_database, $objimport, count($fieldssource), $importid, $updatekeys);
2260 if (count($obj->errors)) {
2261 $arrayoferrors[$sourcelinenb] = $obj->errors;
2263 if (count($obj->warnings)) {
2264 $arrayofwarnings[$sourcelinenb] = $obj->warnings;
2266 if (!count($obj->errors) && !count($obj->warnings)) {
2271 $obj->import_close_file();
2273 print $langs->trans(
"ErrorFailedToOpenFile", $pathfile);
2276 if (count($arrayoferrors) > 0) {
2283 if (!empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0])) {
2285 foreach ($objimport->array_import_run_sql_after[0] as $sqlafterimport) {
2287 $resqlafterimport = $db->query($sqlafterimport);
2288 if (!$resqlafterimport) {
2289 $arrayoferrors[
'none'][] = array(
'lib'=>$langs->trans(
"Error running final request: ".$sqlafterimport));
2307 print
'<div class="info">';
2308 print $langs->trans(
"NbOfLinesImported", $nbok).
'</b><br>';
2309 print $langs->trans(
"NbInsert", empty($obj->nbinsert) ? 0 : $obj->nbinsert).
'<br>';
2310 print $langs->trans(
"NbUpdate", empty($obj->nbupdate) ? 0 : $obj->nbupdate).
'<br>';
2312 print
'<div class="center">';
2313 print $langs->trans(
"FileWasImported", $importid).
'<br>';
2314 print
'<span class="opacitymedium">'.$langs->trans(
"YouCanUseImportIdToFindRecord", $importid).
'</span><br>';
2337 function show_elem($fieldssource, $pos, $key, $var, $nostyle =
'')
2343 if ($key ==
'none') {
2345 print
"\n\n<!-- Box_no-key start-->\n";
2346 print
'<div class="box boximport" style="padding:0;">'.
"\n";
2347 print
'<table summary="boxtable_no-key" class="centpercent nobordernopadding">'.
"\n";
2349 print
"\n\n<!-- Box ".$pos.
" start -->\n";
2350 print
'<div class="box boximport" style="padding: 0;" id="boxto_'.$pos.
'">'.
"\n";
2352 print
'<table summary="boxtable'.$pos.
'" class="nobordernopadding centpercent tableimport">'.
"\n";
2355 if (($pos && $pos > count($fieldssource)) && (!isset($fieldssource[$pos][
"imported"]))) {
2365 } elseif ($key ==
'none') {
2366 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
2367 print
'<td class="nocellnopadding" width="16" style="font-weight: normal">';
2370 print
'<td style="font-weight: normal">';
2376 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
2377 print
'<td class="nocellnopadding" width="16" style="font-weight: normal">';
2380 print
img_picto($langs->trans(
"Column").
' '.
num2Alpha($pos - 1),
'file',
'class="pictofixedwith"');
2382 if (isset($fieldssource[$pos][
'imported']) && $fieldssource[$pos][
'imported'] ==
false) {
2383 print
'<td class="nowraponall boxtdunused" style="font-weight: normal">';
2385 print
'<td class="nowraponall" style="font-weight: normal">';
2387 print $langs->trans(
"Column").
' '.
num2Alpha($pos - 1).
' (#'.$pos.
')';
2388 if (empty($fieldssource[$pos][
'example1'])) {
2389 $example = $fieldssource[$pos][
'label'];
2391 $example = $fieldssource[$pos][
'example1'];
2395 $example = utf8_encode($example);
2399 print
'<i class="opacitymedium">'.$example.
'</i>';
2408 print
"<!-- Box end -->\n\n";
2421 $i = count($fieldssource) + 1;
2424 foreach ($listofkey as $key => $val) {
2425 $maxkey = max($maxkey, $key);
2428 while ($i <= $maxkey) {
2429 if (empty($listofkey[$i])) {
2451 if ($position == count($array)) {
2452 $ret = $array + $insertArray;
2455 foreach ($array as $key => $value) {
2456 if ($position == $i++) {
2457 $ret += $insertArray;
2460 $ret[$key] = $value;
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getMaxFileSizeArray()
Return the max allowed for file upload.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
dol_mkdir($dir, $dataroot= '', $newmask= '')
Creation of a directory (this can create recursive subdir)
getnewkey(&$fieldssource, &$listofkey)
Return not used field number.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_now($mode= 'auto')
Return date for now.
arrayInsert($array, $position, $insertArray)
Return array with element inserted in it at position $position.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
import_prepare_head($param, $maxstep=0)
Function to return list of tabs for import pages.
dol_filesize($pathoffile)
Return size of a file.
num2Alpha($n)
Return a numeric value into an Excel like column number.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
show_elem($fieldssource, $pos, $key, $var, $nostyle= '')
Function to put the movable box of a source field.
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save"&&empty($cancel)) $help_url
View.
img_mime($file, $titlealt= '', $morecss= '')
Show MIME img of a file.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
img_error($titlealt= 'default')
Show error logo.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form...
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= 'hideonsmartphone', $textfordropdown= '')
Show information for admin users or standard users.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
utf8_check($str)
Check if a string is in UTF8.
dol_count_nb_of_line($file)
Count number of lines in a file.
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.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete= 'resolve', $idforemptyvalue= '-1')
Convert a html select field into an ajax combobox.
restrictedArea($user, $features, $objectid=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.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dolExplodeIntoArray($string, $delimiter= ';', $kv= '=')
Split a string with 2 keys into key array.
Parent class for import file readers.
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_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
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_filemtime($pathoffile)
Return time of a file.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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. ...
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
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.