29require_once
'../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/imports/class/import.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/modules/import/modules_import.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/import.lib.php';
47$langs->loadLangs(array(
'exports',
'compta',
'errors',
'projects',
'admin'));
50$hookmanager->initHooks(array(
'imports'));
58 'invoice_line' =>
'bill',
60 'order_line' =>
'order',
62 'propal_line' =>
'propal',
63 'intervention' =>
'intervention',
64 'inter_line' =>
'intervention',
66 'member_type' =>
'group',
67 'subscription' =>
'payment',
68 'payment' =>
'payment',
70 'tax_type' =>
'generic',
72 'account' =>
'account',
73 'product' =>
'product',
74 'virtualproduct' =>
'product',
75 'subproduct' =>
'product',
76 'product_supplier_ref' =>
'product',
78 'warehouse' =>
'stock',
80 'stockbatch' =>
'stock',
81 'category' =>
'category',
82 'shipment' =>
'sending',
83 'shipment_line' =>
'sending',
84 'reception' =>
'sending',
85 'reception_line' =>
'sending',
86 'expensereport' =>
'trip',
87 'expensereport_line' =>
'trip',
88 'holiday' =>
'holiday',
89 'contract_line' =>
'contract',
90 'translation' =>
'generic',
98 'company' =>
'Company',
99 'contact' =>
'Contact',
101 'invoice_line' =>
'InvoiceLine',
103 'order_line' =>
'OrderLine',
104 'propal' =>
'Proposal',
105 'propal_line' =>
'ProposalLine',
106 'intervention' =>
'Intervention',
107 'inter_line' =>
'InterLine',
108 'member' =>
'Member',
109 'member_type' =>
'MemberType',
110 'subscription' =>
'Subscription',
111 'tax' =>
'SocialContribution',
112 'tax_type' =>
'DictionarySocialContributions',
113 'account' =>
'BankTransactions',
114 'payment' =>
'Payment',
115 'product' =>
'Product',
116 'virtualproduct' =>
'AssociatedProducts',
117 'subproduct' =>
'SubProduct',
118 'product_supplier_ref' =>
'SupplierPrices',
119 'service' =>
'Service',
121 'movement' =>
'StockMovement',
123 'stockbatch' =>
'StockDetailPerBatch',
124 'warehouse' =>
'Warehouse',
125 'category' =>
'Category',
127 'trip' =>
'TripsAndExpenses',
128 'shipment' =>
'Shipments',
129 'shipment_line' =>
'ShipmentLine',
130 'project' =>
'Projects',
131 'projecttask' =>
'Tasks',
132 'task_time' =>
'TaskTimeSpent',
134 'expensereport' =>
'ExpenseReport',
135 'expensereport_line' =>
'ExpenseReportLine',
136 'holiday' =>
'TitreRequestCP',
137 'contract' =>
'Contract',
138 'contract_line' =>
'ContractLine',
139 'translation' =>
'Translation',
141 'bomline' =>
'BOMLine'
144$datatoimport =
GETPOST(
'datatoimport');
146$filetoimport =
GETPOST(
'filetoimport');
147$action =
GETPOST(
'action',
'alpha');
148$confirm =
GETPOST(
'confirm',
'alpha');
150$import_name =
GETPOST(
'import_name');
153$excludefirstline = (
GETPOST(
'excludefirstline') ?
GETPOST(
'excludefirstline') : 2);
154$endatlinenb = (
GETPOST(
'endatlinenb') ?
GETPOST(
'endatlinenb') :
'');
155$updatekeys = (
GETPOST(
'updatekeys',
'array') ?
GETPOST(
'updatekeys',
'array') : array());
156$separator = (
GETPOST(
'separator',
'nohtml') ?
GETPOST(
'separator',
'nohtml', 3) :
'');
157$enclosure = (
GETPOST(
'enclosure',
'nohtml') ?
GETPOST(
'enclosure',
'nohtml') :
'"');
158$charset =
GETPOST(
'charset',
'aZ09');
159$separator_used = str_replace(
'\t',
"\t", $separator);
162$objimport =
new Import($db);
163$objimport->load_arrays($user, ($step == 1 ?
'' : $datatoimport));
165if (empty($updatekeys) && !empty($objimport->array_import_preselected_updatekeys[0])) {
166 $updatekeys = $objimport->array_import_preselected_updatekeys[0];
171$form =
new Form($db);
176if (empty($array_match_file_to_database)) {
177 $serialized_array_match_file_to_database = isset($_SESSION[
"dol_array_match_file_to_database_select"]) ? $_SESSION[
"dol_array_match_file_to_database_select"] :
'';
178 $array_match_file_to_database = array();
179 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
180 foreach ($fieldsarray as $elem) {
181 $tabelem = explode(
'=', $elem, 2);
183 $val = (isset($tabelem[1]) ? $tabelem[1] :
'');
185 $array_match_file_to_database[$key] = $val;
195if ($action ==
'deleteprof' && $user->hasRight(
'import',
'run')) {
198 $result = $objimport->delete($user);
203if ($action ==
'add_import_model' && $user->hasRight(
'import',
'run')) {
207 foreach ($array_match_file_to_database as $key => $val) {
211 $hexa .= $key.
'='.$val;
214 $objimport->model_name = $import_name;
215 $objimport->datatoimport = $datatoimport;
216 $objimport->hexa = $hexa;
217 $objimport->fk_user = (
GETPOST(
'visibility',
'aZ09') ==
'all' ? 0 : $user->id);
219 $result = $objimport->create($user);
221 setEventMessages($langs->trans(
"ImportModelSaved", $objimport->model_name),
null,
'mesgs');
224 $langs->load(
"errors");
225 if ($objimport->errno ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
226 setEventMessages($langs->trans(
"ErrorImportDuplicateProfil"),
null,
'errors');
232 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"ImportModelName")),
null,
'errors');
236if ($step == 3 && $datatoimport) {
243 dol_syslog(
"File ".$fullpath.
" was added for import");
245 $langs->load(
"errors");
251 if ($action ==
'confirm_deletefile' && $confirm ==
'yes' && $user->hasRight(
'import',
'run')) {
252 $langs->load(
"other");
254 $param =
'&datatoimport='.urlencode($datatoimport).
'&format='.urlencode($format);
255 if ($excludefirstline) {
256 $param .=
'&excludefirstline='.urlencode($excludefirstline);
259 $param .=
'&endatlinenb='.urlencode($endatlinenb);
269 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?step='.$step.$param);
274if ($step == 4 && $action ==
'select_model' && $user->hasRight(
'import',
'run')) {
276 $_SESSION[
"dol_array_match_file_to_database"] =
'';
277 $serialized_array_match_file_to_database =
'';
278 $array_match_file_to_database = array();
282 $result = $objimport->fetch($importmodelid);
284 $serialized_array_match_file_to_database = $objimport->hexa;
285 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
286 foreach ($fieldsarray as $elem) {
287 $tabelem = explode(
'=', $elem);
291 $array_match_file_to_database[$key] = $val;
294 $_SESSION[
"dol_array_match_file_to_database"] = $serialized_array_match_file_to_database;
295 $_SESSION[
'dol_array_match_file_to_database_select'] = $_SESSION[
"dol_array_match_file_to_database"];
298if ($action ==
'saveselectorder' && $user->hasRight(
'import',
'run')) {
300 $serialized_array_match_file_to_database =
'';
302 $selectorder = explode(
",",
GETPOST(
'selectorder'));
303 $fieldtarget = $fieldstarget = $objimport->array_import_fields[0];
304 foreach ($selectorder as $key => $code) {
305 $serialized_array_match_file_to_database .= $key.
'='.$code;
306 $serialized_array_match_file_to_database .=
',';
308 $serialized_array_match_file_to_database = substr($serialized_array_match_file_to_database, 0, -1);
309 dol_syslog(
'dol_array_match_file_to_database_select='.$serialized_array_match_file_to_database);
310 $_SESSION[
"dol_array_match_file_to_database_select"] = $serialized_array_match_file_to_database;
320$help_url =
'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones';
323if ($step == 1 || !$datatoimport) {
325 $serialized_array_match_file_to_database =
'';
326 $array_match_file_to_database = array();
327 $_SESSION[
"dol_array_match_file_to_database"] =
'';
328 $_SESSION[
"dol_array_match_file_to_database_select"] =
'';
331 if ($excludefirstline) {
332 $param .=
'&excludefirstline='.urlencode($excludefirstline);
335 $param .=
'&endatlinenb='.urlencode($endatlinenb);
338 $param .=
'&separator='.urlencode($separator);
341 $param .=
'&enclosure='.urlencode($enclosure);
344 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
350 print
'<div class="opacitymedium">'.$langs->trans(
"SelectImportDataSet").
'</div>';
354 $nbmodulesnotautoenabled = count(
$conf->modules);
355 $listofmodulesautoenabled = array(
'user',
'agenda',
'fckeditor',
'export',
'import');
356 foreach ($listofmodulesautoenabled as $moduleautoenable) {
357 if (in_array($moduleautoenable,
$conf->modules)) {
358 $nbmodulesnotautoenabled--;
362 if ($user->admin && $nbmodulesnotautoenabled <
getDolGlobalInt(
'MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING', 1)) {
363 print
info_admin($langs->trans(
"WarningOnlyProfilesOfActivatedModules").
' '.$langs->trans(
"YouCanEnableModulesFrom"));
369 print
'<div class="div-table-responsive-no-min">';
370 print
'<table class="noborder centpercent nomarginbottom">';
371 print
'<tr class="liste_titre">';
372 print
'<td>'.$langs->trans(
"Module").
'</td>';
373 print
'<td>'.$langs->trans(
"ImportableDatas").
'</td>';
374 print
'<td> </td>';
377 if (count($objimport->array_import_module)) {
378 $sortedarrayofmodules =
dol_sort_array($objimport->array_import_module,
'position_of_profile',
'asc', 0, 0, 1);
379 foreach ($sortedarrayofmodules as $key => $value) {
381 $titleofmodule = $objimport->array_import_module[$key][
'module']->getName();
382 print
'<tr class="oddeven"><td class="tdoverflowmax200" title="'.dolPrintHTML($titleofmodule).
'">';
384 if (in_array($objimport->array_import_code[$key], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
385 $titleofmodule = $langs->trans(
"ProductOrService");
389 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[$key]);
390 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
391 $label = $objimport->array_import_label[$key];
392 print
'<div class="twolinesmax-normallineheight minwidth200onall">';
393 print
img_object($objimport->array_import_module[$key][
'module']->getName(), $entityicon,
'class="pictofixedwidth"');
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>';
415if ($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);
430 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
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->listOfAvailableImportFormat($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 $htmltext = $objmodelimport->getDriverDescForKey($key);
493 print
'<td>'.$form->textwithpicto($objmodelimport->getDriverLabelForKey($key), $htmltext).
'</td>';
494 print
'<td style="text-align:center">';
495 if (empty($objmodelimport->drivererror[$key])) {
496 $filename = $langs->transnoentitiesnoconv(
"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"));
507 print
'<td style="text-align:right">';
508 if (empty($objmodelimport->drivererror[$key])) {
509 print
'<a href="'.DOL_URL_ROOT.
'/imports/import.php?step=3&format='.$key.$param.
'">'.
img_picto($langs->trans(
"SelectFormat"),
'next',
'class="fa-15"').
'</a>';
523if ($step == 3 && $datatoimport) {
524 $param =
'&datatoimport='.urlencode($datatoimport).
'&format='.urlencode($format);
525 if ($excludefirstline) {
526 $param .=
'&excludefirstline='.urlencode($excludefirstline);
529 $param .=
'&endatlinenb='.urlencode($endatlinenb);
532 $param .=
'&separator='.urlencode($separator);
535 $param .=
'&enclosure='.urlencode($enclosure);
538 $list = $objmodelimport->listOfAvailableImportFormat($db);
540 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
549 if ($action ==
'delete') {
550 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?urlfile='.urlencode(
GETPOST(
'urlfile')).
'&step=3'.$param, $langs->trans(
'DeleteFile'), $langs->trans(
'ConfirmDeleteFile'),
'confirm_deletefile',
'', 0, 1);
553 print
'<div class="underbanner clearboth"></div>';
554 print
'<div class="fichecenter">';
556 print
'<table class="border tableforfield centpercent">';
559 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
561 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
563 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
564 $titleofmodule = $langs->trans(
"ProductOrService");
566 print $titleofmodule;
570 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
572 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
573 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
574 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
575 print $objimport->array_import_label[0];
583 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
585 print
'<div class="underbanner clearboth"></div>';
586 print
'<div class="fichecenter">';
587 print
'<table width="100%" class="border tableforfield">';
590 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
591 print
'<td class="nowraponall">';
592 $text = $objmodelimport->getDriverDescForKey($format);
594 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
595 print
'</td><td style="text-align:right" class="nowrap">';
596 $filename = $langs->transnoentitiesnoconv(
"ExampleOfImportFile").
'_'.$datatoimport.
'.'.$format;
597 print
'<a href="'.DOL_URL_ROOT.
'/imports/emptyexample.php?format='.$format.$param.
'&output=file&file='.urlencode($filename).
'" target="_blank" rel="noopener noreferrer">';
598 print
img_picto(
'',
'download',
'class="paddingright opacitymedium"');
599 print $langs->trans(
"DownloadEmptyExampleShort");
601 print $form->textwithpicto(
'', $langs->trans(
"DownloadEmptyExample").
'.<br>'.$langs->trans(
"StarAreMandatory"));
610 if ($format ==
'xlsx' && !class_exists(
'XMLWriter')) {
611 $langs->load(
"install");
612 print
info_admin($langs->trans(
"ErrorPHPDoesNotSupport",
'php-xml'), 0, 0,
'1',
'error');
618 print
'<form name="userfile" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="POST">';
619 print
'<input type="hidden" name="token" value="'.newToken().
'">';
620 print
'<input type="hidden" value="'.$step.
'" name="step">';
621 print
'<input type="hidden" value="'.dol_escape_htmltag($format).
'" name="format">';
622 print
'<input type="hidden" value="'.$excludefirstline.
'" name="excludefirstline">';
623 print
'<input type="hidden" value="'.$endatlinenb.
'" name="endatlinenb">';
624 print
'<input type="hidden" value="'.dol_escape_htmltag($separator).
'" name="separator">';
625 print
'<input type="hidden" value="'.dol_escape_htmltag($enclosure).
'" name="enclosure">';
626 print
'<input type="hidden" value="'.dol_escape_htmltag($datatoimport).
'" name="datatoimport">';
628 print
'<span class="opacitymedium">';
629 $s = $langs->trans(
"ChooseFileToImport",
'{s1}');
630 $s = str_replace(
'{s1}',
img_picto(
'',
'next'), $s);
632 print
'</span><br><br>';
637 print
'<div class="marginbottomonly">';
639 $maxmin = $maxfilesizearray[
'maxmin'];
641 print
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
643 print
'<input type="file" name="userfile" size="20" maxlength="80"> ';
645 print
'<input type="submit" class="button small" value="'.$langs->trans(
"AddFile").
'"'.$out.
' name="sendit">';
649 $maxphp = @ini_get(
'upload_max_filesize');
650 if (preg_match(
'/k$/i', $maxphp)) {
651 $maxphp = (int) substr($maxphp, 0, -1);
653 if (preg_match(
'/m$/i', $maxphp)) {
654 $maxphp = (int) substr($maxphp, 0, -1) * 1024;
656 if (preg_match(
'/g$/i', $maxphp)) {
657 $maxphp = (int) substr($maxphp, 0, -1) * 1024 * 1024;
659 if (preg_match(
'/t$/i', $maxphp)) {
660 $maxphp = (int) substr($maxphp, 0, -1) * 1024 * 1024 * 1024;
662 $maxphp2 = @ini_get(
'post_max_size');
663 if (preg_match(
'/k$/i', $maxphp2)) {
664 $maxphp2 = (int) substr($maxphp2, 0, -1);
666 if (preg_match(
'/m$/i', $maxphp2)) {
667 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024;
669 if (preg_match(
'/g$/i', $maxphp2)) {
670 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024 * 1024;
672 if (preg_match(
'/t$/i', $maxphp2)) {
673 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024 * 1024 * 1024;
677 $maxphptoshow = $maxphptoshowparam =
'';
679 $maxmin = min($max, $maxphp);
680 $maxphptoshow = $maxphp;
681 $maxphptoshowparam =
'upload_max_filesize';
684 $maxmin = min($max, $maxphp2);
685 if ($maxphp2 < $maxphp) {
686 $maxphptoshow = $maxphp2;
687 $maxphptoshowparam =
'post_max_size';
691 $langs->load(
'other');
693 $out .=
info_admin($langs->trans(
"ThisLimitIsDefinedInSetup", $max, $maxphptoshow), 1);
695 $out .=
' ('.$langs->trans(
"UploadDisabled").
')';
701 $filearray =
dol_dir_list(
$conf->import->dir_temp,
'files', 0,
'',
'',
'name', SORT_DESC);
702 if (count($filearray) > 0) {
703 print
'<div class="div-table-responsive-no-min">';
704 print
'<table class="noborder centpercent" width="100%" cellpadding="4">';
706 $dir =
$conf->import->dir_temp;
710 foreach ($filearray as $key => $val) {
711 $file = $val[
'name'];
715 $file = mb_convert_encoding($file,
'UTF-8',
'ISO-8859-1');
718 if (preg_match(
'/^\./', $file)) {
722 $modulepart =
'import';
723 $urlsource = $_SERVER[
"PHP_SELF"].
'?step='.$step.$param.
'&filetoimport='.urlencode($filetoimport);
724 $relativepath = $file;
726 print
'<tr class="oddeven">';
728 print
img_mime($file,
'',
'pictofixedwidth');
729 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=3'.$param.
'" target="_blank" rel="noopener noreferrer">';
734 print
'<td style="text-align:right">'.dol_print_size(
dol_filesize($dir.
'/'.$file)).
'</td>';
736 print
'<td style="text-align:right">'.dol_print_date(
dol_filemtime($dir.
'/'.$file),
'dayhour').
'</td>';
738 print
'<td style="text-align:right"><a href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.
newToken().
'&step=3'.$param.
'&urlfile='.urlencode($relativepath);
739 print
'">'.img_delete().
'</a></td>';
741 print
'<td style="text-align:right">';
742 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?step=4'.$param.
'&filetoimport='.urlencode($relativepath).
'">'.
img_picto($langs->trans(
"NewImport"),
'next',
'class="fa-15"').
'</a>';
756if ($step == 4 && $datatoimport) {
758 $serialized_array_match_file_to_database = isset($_SESSION[
"dol_array_match_file_to_database_select"]) ? $_SESSION[
"dol_array_match_file_to_database_select"] :
'';
759 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
760 $array_match_file_to_database = array();
761 foreach ($fieldsarray as $elem) {
762 $tabelem = explode(
'=', $elem, 2);
764 $val = (isset($tabelem[1]) ? $tabelem[1] :
'');
766 $array_match_file_to_database[$key] = $val;
775 $list = $objmodelimport->listOfAvailableImportFormat($db);
777 if (empty($separator)) {
778 $separator = (!
getDolGlobalString(
'IMPORT_CSV_SEPARATOR_TO_USE') ?
',' :
$conf->global->IMPORT_CSV_SEPARATOR_TO_USE);
782 if ($model ==
'csv' && strlen($separator) == 1 && !GETPOSTISSET(
'separator')) {
783 '@phan-var-force ImportCsv $obj';
785 $fh = fopen(
$conf->import->dir_temp.
'/'.$filetoimport,
'r');
787 $sline = fgets($fh, 1000000);
789 $nboccurence = substr_count($sline, $separator);
790 $nboccurencea = substr_count($sline,
',');
791 $nboccurenceb = substr_count($sline,
';');
793 if ($nboccurence == 0) {
794 if ($nboccurencea > 2) {
796 } elseif ($nboccurenceb > 2) {
804 $separator_used = str_replace(
'\t',
"\t", $separator);
807 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
808 $file =
"import_".$model.
".modules.php";
809 $classname =
"Import".ucfirst($model);
810 require_once $dir.$file;
811 $obj =
new $classname($db, $datatoimport);
812 '@phan-var-force ModeleImports $obj';
814 if (!empty($obj->error)) {
815 $langs->load(
"errors");
816 $param =
'&datatoimport='.$datatoimport.
'&format='.$format;
818 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?step=3'.$param.
'&filetoimport='.urlencode($relativepath));
822 if ($model ==
'csv') {
823 '@phan-var-force ImportCsv $obj';
824 $obj->separator = $separator_used;
825 $obj->enclosure = $enclosure;
828 if ($model ==
'xlsx') {
829 '@phan-var-force ImportXlsx $obj';
830 if (!preg_match(
'/\.xlsx$/i', $filetoimport)) {
831 $langs->load(
"errors");
832 $param =
'&datatoimport='.$datatoimport.
'&format='.$format;
833 setEventMessages($langs->trans(
"ErrorFileMustHaveFormat", $model),
null,
'errors');
834 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?step=3'.$param.
'&filetoimport='.urlencode($relativepath));
840 $array_match_file_to_database = array();
844 $fieldssource = array();
846 $result = $obj->import_open_file(
$conf->import->dir_temp.
'/'.$filetoimport);
849 $arrayrecord = $obj->import_read_record();
853 foreach ($arrayrecord as $key => $val) {
854 if ($val[
"type"] != -1) {
855 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 128);
857 $fieldssource[$i][
'example1'] = $langs->trans(
'Empty');
859 $fieldssource[$i][
'imported'] =
false;
862 $obj->import_close_file();
866 $fieldstarget = $objimport->array_import_fields[0];
867 $minpos = min(count($fieldssource), count($fieldstarget));
871 $initialloadofstep4 =
false;
872 if (empty($_SESSION[
'dol_array_match_file_to_database_select'])) {
873 $initialloadofstep4 =
true;
877 if (count($array_match_file_to_database) == 0) {
883 $num = count($fieldssource);
884 while ($pos <= $num) {
885 if ($num >= 1 && $pos <= $num) {
887 foreach ($fieldstarget as $key => $val) {
888 if ($posbis < $pos) {
893 $array_match_file_to_database[$pos] = $key;
900 $array_match_database_to_file = array_flip($array_match_file_to_database);
904 $fieldstarget_tmp = array();
905 $arraykeysfieldtarget = array_keys($fieldstarget);
907 foreach ($fieldstarget as $key => $label) {
908 $isrequired = preg_match(
'/\*$/', $label);
909 if (!empty($isrequired)) {
910 $newlabel = substr($label, 0, -1);
911 $fieldstarget_tmp[$key] = array(
"label" => $newlabel,
"required" =>
true);
913 $fieldstarget_tmp[$key] = array(
"label" => $label,
"required" =>
false);
915 if (!empty($array_match_database_to_file[$key])) {
916 $fieldstarget_tmp[$key][
"imported"] =
true;
917 $fieldstarget_tmp[$key][
"position"] = (int) $array_match_database_to_file[$key] - 1;
919 while (!empty($array_match_database_to_file[$keytoswap])) {
920 if ($position + 1 > $array_match_database_to_file[$keytoswap]) {
921 $keytoswapwith = $array_match_database_to_file[$keytoswap] - 1;
922 $tmp = [$keytoswap => $fieldstarget_tmp[$keytoswap]];
923 unset($fieldstarget_tmp[$keytoswap]);
924 $fieldstarget_tmp =
arrayInsert($fieldstarget_tmp, $keytoswapwith, $tmp);
925 $keytoswapwith = $arraykeysfieldtarget[$array_match_database_to_file[$keytoswap] - 1];
926 $tmp = $fieldstarget_tmp[$keytoswapwith];
927 unset($fieldstarget_tmp[$keytoswapwith]);
928 $fieldstarget_tmp[$keytoswapwith] = $tmp;
929 $keytoswap = $keytoswapwith;
935 $fieldstarget_tmp[$key][
"imported"] =
false;
939 $fieldstarget = $fieldstarget_tmp;
948 $param =
'&format='.$format.
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport);
949 if ($excludefirstline) {
950 $param .=
'&excludefirstline='.urlencode($excludefirstline);
953 $param .=
'&endatlinenb='.urlencode($endatlinenb);
956 $param .=
'&separator='.urlencode($separator);
959 $param .=
'&enclosure='.urlencode($enclosure);
962 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
968 print
'<div class="underbanner clearboth"></div>';
969 print
'<div class="fichecenter">';
971 print
'<table class="centpercent border tableforfield">';
974 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
976 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
978 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
979 $titleofmodule = $langs->trans(
"ProductOrService");
981 print $titleofmodule;
985 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
987 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
988 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
989 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
990 print $objimport->array_import_label[0];
998 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
1000 print
'<div class="underbanner clearboth"></div>';
1001 print
'<div class="fichecenter">';
1002 print
'<table width="100%" class="border tableforfield">';
1005 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
1006 print
'<td class="nowraponall">';
1007 $text = $objmodelimport->getDriverDescForKey($format);
1009 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
1013 if ($model ==
'csv') {
1014 '@phan-var-force ImportCsv $obj';
1015 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
1017 print
'<form method="POST">';
1018 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1019 print
'<input type="hidden" value="'.$step.
'" name="step">';
1020 print
'<input type="hidden" value="'.$format.
'" name="format">';
1021 print
'<input type="hidden" value="'.$excludefirstline.
'" name="excludefirstline">';
1022 print
'<input type="hidden" value="'.$endatlinenb.
'" name="endatlinenb">';
1023 print
'<input type="hidden" value="'.$datatoimport.
'" name="datatoimport">';
1024 print
'<input type="hidden" value="'.$filetoimport.
'" name="filetoimport">';
1025 print $langs->trans(
"Separator").
' : ';
1026 print
'<input type="text" class="width25 center" name="separator" value="'.dol_escape_htmltag($separator).
'"/>';
1027 print
' '.$langs->trans(
"Enclosure").
' : ';
1028 print
'<input type="text" class="width25 center" name="enclosure" value="'.dol_escape_htmltag($enclosure).
'"/> ';
1029 print
'<input name="update" type="submit" value="'.$langs->trans(
'Update').
'" class="button smallpaddingimp" />';
1035 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
1037 $modulepart =
'import';
1038 $relativepath =
GETPOST(
'filetoimport');
1039 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
1040 print
img_mime($file,
'',
'pictofixedwidth');
1041 print $filetoimport;
1042 print
img_picto($langs->trans(
"Download"),
'download',
'class="paddingleft opacitymedium"');
1055 print
'<!-- List of source fields -->'.
"\n";
1056 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1057 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1058 print
'<input type="hidden" name="action" value="select_model">';
1059 print
'<input type="hidden" name="step" value="4">';
1060 print
'<input type="hidden" name="format" value="'.$format.
'">';
1061 print
'<input type="hidden" name="datatoimport" value="'.$datatoimport.
'">';
1062 print
'<input type="hidden" name="filetoimport" value="'.$filetoimport.
'">';
1063 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1064 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1065 print
'<input type="hidden" name="separator" value="'.dol_escape_htmltag($separator).
'">';
1066 print
'<input type="hidden" name="enclosure" value="'.dol_escape_htmltag($enclosure).
'">';
1069 print
'<div class="marginbottomonly">';
1070 print
'<span class="opacitymedium">';
1071 $s = $langs->trans(
"SelectImportFieldsSource",
'{s1}');
1072 $s = str_replace(
'{s1}',
img_picto(
'',
'grip_title',
'', 0, 0, 0,
'',
'', 0), $s);
1075 $htmlother->select_import_model((
string) $importmodelid,
'importmodelid', $datatoimport, 1, $user->id);
1076 print
'<input type="submit" class="button smallpaddingimp reposition" value="'.$langs->trans(
"Select").
'">';
1081 print
'<div class="div-table-responsive-no-min">';
1082 print
'<table class="noborder centpercent">';
1083 print
'<tr class="liste_titre">';
1084 print
'<td>'.$langs->trans(
"FieldsInSourceFile").
'</td>';
1085 print
'<td>'.$langs->trans(
"FieldsInTargetDatabase").
'</td>';
1090 print
'<tr valign="top"><td width="50%" class="nopaddingleftimp">';
1092 $fieldsplaced = array();
1093 $valforsourcefieldnb = array();
1094 $listofkeys = array();
1095 foreach ($array_match_file_to_database as $key => $val) {
1096 $listofkeys[$key] = 1;
1099 print
"\n<!-- Box left container -->\n";
1100 print
'<div id="left" class="connectedSortable">'.
"\n";
1105 foreach ($fieldssource as $key => $val) {
1106 show_elem($fieldssource, $key, (
string) $key);
1107 $listofkeys[$key] = 1;
1108 $fieldsplaced[$key] = 1;
1109 $valforsourcefieldnb[$lefti] = $key;
1119 print
"<!-- End box left container -->\n";
1122 print
'</td><td width="50%" class="nopaddingrightimp">';
1126 $optionsall = array();
1127 foreach ($fieldstarget as $code => $line) {
1128 $tmparray = explode(
'|', $line[
"label"]);
1130 foreach ($tmparray as $tmpkey => $tmpval) {
1131 $labeltoshow .= ($labeltoshow ?
' '.$langs->trans(
'or').
' ' :
'').$langs->transnoentities($tmpval);
1136 $optionsall[$code] = array(
1137 'labelkey' => $line[
'label'],
1138 'labelkeyarray' => $tmparray,
1139 'label' => $labeltoshow,
1140 'required' => (empty($line[
"required"]) ? 0 : 1),
1141 'position' => (!empty($line[
'position']) ? $line[
'position'] : 0),
1149 $mandatoryfieldshavesource =
true;
1162 $modetoautofillmapping =
'session';
1163 if ($initialloadofstep4) {
1164 $modetoautofillmapping =
'guess';
1168 print
'<table class="nobordernopadding centpercent tableimport">';
1169 foreach ($fieldssource as $code => $line) {
1174 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
1176 $entity = (!empty($objimport->array_import_entities[0][$code]) ? $objimport->array_import_entities[0][$code] : $objimport->array_import_icon[0]);
1178 $entityicon = !empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity;
1179 $entitylang = !empty($entitytolang[$entity]) ? $entitytolang[$entity] : $objimport->array_import_label[0];
1181 print
'<td class="nowraponall hideonsmartphone" style="font-weight: normal">=> </td>';
1182 print
'<td class="nowraponall" style="font-weight: normal">';
1184 $selectforline =
'';
1185 $selectforline .=
'<select id="selectorderimport_'.($i + 1).
'" class="targetselectchange minwidth300" name="select_'.($i + 1).
'">';
1186 $selectforline .=
'<option value="-1"> </option>';
1189 $codeselectedarray = array();
1190 foreach ($optionsall as $tmpcode => $tmpval) {
1192 if (!empty($tmpval[
'picto'])) {
1193 $label .=
img_picto(
'', $tmpval[
'picto'],
'class="pictofixedwidth"');
1195 $label .= $tmpval[
'required'] ?
'<strong>' :
'';
1196 $label .= $tmpval[
'label'];
1197 $label .= $tmpval[
'required'] ?
'*</strong>' :
'';
1199 $tablealias = preg_replace(
'/(\..*)$/i',
'', $tmpcode);
1200 $tablename = !empty($objimport->array_import_tables[0][$tablealias]) ? $objimport->array_import_tables[0][$tablealias] :
"";
1204 $filecolumn = ($i + 1);
1206 if (empty($objimport->array_import_convertvalue[0][$tmpcode])) {
1209 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromref') {
1210 $htmltext .= $langs->trans(
"DataComeFromIdFoundFromRef", $langs->transnoentitiesnoconv($entitylang)).
'<br>';
1212 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromcodeid') {
1213 $htmltext .= $langs->trans(
"DataComeFromIdFoundFromCodeId", $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$tmpcode][
'dict'])).
'<br>';
1217 $example = !empty($objimport->array_import_examplevalues[0][$tmpcode]) ? $objimport->array_import_examplevalues[0][$tmpcode] :
"";
1219 if (empty($objimport->array_import_convertvalue[0][$tmpcode])) {
1221 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.str_replace(
'"',
'', $example).
'</b><br>';
1224 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromref') {
1225 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.$langs->transnoentitiesnoconv(
"ExampleAnyRefFoundIntoElement", $entitylang).($example ?
' ('.$langs->transnoentitiesnoconv(
"Example").
': '.str_replace(
'"',
'', $example).
')' :
'').
'</b><br>';
1226 } elseif ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromcodeid') {
1227 $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>';
1228 } elseif ($example) {
1229 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.str_replace(
'"',
'', $example).
'</b><br>';
1233 if (!empty($objimport->array_import_regex[0][$tmpcode])) {
1234 $htmltext .= $langs->trans(
"FormatControlRule").
': <b>'.str_replace(
'"',
'', $objimport->array_import_regex[0][$tmpcode]).
'</b><br>';
1238 $htmltext .= $langs->trans(
"InformationOnTargetTables").
': <b>'.$tablename.
"->".preg_replace(
'/^.*\./',
'', $tmpcode).
"</b>";
1240 $labelhtml = $label.
' '.$form->textwithpicto(
'', $htmltext, 1,
'help',
'', 1);
1242 $selectforline .=
'<option value="'.$tmpcode.
'"';
1243 if ($modetoautofillmapping ==
'orderoftargets') {
1246 $selectforline .=
' selected';
1248 } elseif ($modetoautofillmapping ==
'guess') {
1252 if (preg_match(
'/^(.+)\((.+\..+)\)$/', $line[
'example1'], $regs)) {
1253 $tmpstring1 = $regs[1];
1254 $tmpstring2 = $regs[2];
1256 $tmpstring1 = $line[
'example1'];
1264 foreach ($tmpval[
'labelkeyarray'] as $tmpval2) {
1265 $labeltarget = $langs->transnoentities($tmpval2);
1267 if ($tmpstring1 && ($tmpstring1 == $tmpcode || $tmpstring1 == strtolower($labeltarget)
1268 || $tmpstring1 == strtolower(
dol_string_unaccent($labeltarget)) || $tmpstring1 == strtolower($tmpval2))) {
1269 if (empty($codeselectedarray[$code])) {
1270 $selectforline .=
' selected';
1271 $codeselectedarray[$code] = 1;
1274 } elseif ($tmpstring2 && ($tmpstring2 == $tmpcode || $tmpstring2 == strtolower($labeltarget)
1275 || $tmpstring2 == strtolower(
dol_string_unaccent($labeltarget)) || $tmpstring2 == strtolower($tmpval2))) {
1276 if (empty($codeselectedarray[$code])) {
1277 $selectforline .=
' selected';
1278 $codeselectedarray[$code] = 1;
1283 } elseif ($modetoautofillmapping ==
'session' && !empty($_SESSION[
'dol_array_match_file_to_database_select'])) {
1284 $tmpselectioninsession =
dolExplodeIntoArray($_SESSION[
'dol_array_match_file_to_database_select'],
',',
'=');
1286 if (!empty($tmpselectioninsession[(
string) ($i + 1)]) && $tmpselectioninsession[(
string) ($i + 1)] == $tmpcode) {
1287 $selectforline .=
' selected';
1289 $selectforline .=
' data-debug="'.$tmpcode.
'-'.$code.
'-'.$j.
'-'.(!empty($tmpselectioninsession[(
string) ($i + 1)]) ? $tmpselectioninsession[(string) ($i + 1)] :
"").
'"';
1291 $selectforline .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
1292 $selectforline .=
'>';
1293 $selectforline .= $label;
1294 $selectforline .=
'</options>';
1297 $selectforline .=
'</select>';
1298 $selectforline .=
ajax_combobox(
'selectorderimport_'.($i + 1));
1300 print $selectforline;
1305 print
'<td class="nowraponall" style="font-weight:normal; text-align:right">';
1308 $htmltext =
'<b><u>'.$langs->trans(
"FieldSource").
'</u></b><br>';
1310 $htmltext .= $langs->trans(
"DataComeFromFileFieldNb", $filecolumntoshow).
'<br>';
1312 print $form->textwithpicto(
'', $htmltext);
1323 print
'<tr class="liste_titre"><td colspan="2">'.$langs->trans(
"Note").
'</td></tr>';
1324 print
'<tr><td colspan="2"><div id="div-mandatory-target-fields-not-mapped"></div></td></tr>';
1330 if (!empty(
$conf->use_javascript_ajax)) {
1331 print
'<script type="text/javascript">'.
"\n";
1332 print
'var previousselectedvalueimport = "0";'.
"\n";
1333 print
'var previousselectedlabelimport = "0";'.
"\n";
1334 print
'var arrayofselectedvalues = [];'.
"\n";
1335 print
'var arrayoftargetfields = [];'.
"\n";
1336 print
'var arrayoftargetmandatoryfields = [];'.
"\n";
1340 foreach ($fieldstarget as $key => $val) {
1341 print
"arrayoftargetfields[".$tmpi.
"] = '".
dol_escape_js($langs->trans($val[
'label'])).
"'; ";
1342 if ($val[
'required']) {
1343 print
"arrayoftargetmandatoryfields[".$tmpi.
"] = '".
dol_escape_js($key).
"'; ";
1349 print
'$(document).ready(function () {'.
"\n";
1351 print
'setOptionsToDisabled();'.
"\n";
1352 print
'saveSelection();'.
"\n";
1354 print
'$(".targetselectchange").focus(function(){'.
"\n";
1355 print
' previousselectedvalueimport = $(this).val();'.
"\n";
1356 print
' previousselectedlabelimport = $(this).children("option:selected").text();'.
"\n";
1357 print
' console.log("previousselectedvalueimport="+previousselectedvalueimport)'.
"\n";
1364 print
'function setOptionsToDisabled() {'.
"\n";
1365 print
' console.log("Remove the disabled flag everywhere");'.
"\n";
1366 print
' $("select.targetselectchange").not($( this )).find(\'option\').prop("disabled", false);'.
"\n";
1367 print
' arrayofselectedvalues = [];'.
"\n";
1369 print
' $("select.targetselectchange").each(function(){'.
"\n";
1370 print
' id = $(this).attr(\'id\')'.
"\n";
1371 print
' value = $(this).val()'.
"\n";
1372 print
' console.log("a selected value has been found for component "+id+" = "+value);'.
"\n";
1373 print
' arrayofselectedvalues.push(value);'.
"\n";
1376 print
' console.log("List of all selected values arrayofselectedvalues");'.
"\n";
1377 print
' console.log(arrayofselectedvalues);'.
"\n";
1378 print
' console.log("Set the option to disabled for every entry that is currently selected somewhere else (so into arrayofselectedvalues)");'.
"\n";
1380 print
' $.each(arrayofselectedvalues, function(key, value) {'.
"\n";
1381 print
' if (value != -1) {'.
"\n";
1382 print
' console.log("Process key="+key+" value="+value+" to disable.");'.
"\n";
1383 print
' $("select.targetselectchange").find(\'option[value="\'+value+\'"]:not(:selected)\').prop("disabled", true);'.
"\n";
1389 print
'function saveSelection() {'.
"\n";
1391 print
' arrayselectedfields = [];'.
"\n";
1392 print
' arrayselectedfields.push(0);'.
"\n";
1394 print
' $.each( arrayofselectedvalues, function( key, value ) {'.
"\n";
1395 print
' if (value != -1) {'.
"\n";
1396 print
' arrayselectedfields.push(value);'.
"\n";
1397 print
' } else {'.
"\n";
1398 print
' arrayselectedfields.push(0);'.
"\n";
1402 print
" $.ajax({\n";
1403 print
" type: 'POST',\n";
1404 print
" dataType: 'json',\n";
1405 print
" url: '".dol_escape_js($_SERVER[
"PHP_SELF"]).
"?action=saveselectorder&token=".
newToken().
"',\n";
1406 print
" data: 'selectorder='+arrayselectedfields.toString(),\n";
1407 print
" success: function(){\n";
1408 print
" console.log('The selected fields have been saved into '+arrayselectedfields.toString());\n";
1413 print
' console.log("arrayselectedfields");';
1414 print
' console.log(arrayselectedfields);';
1415 print
' console.log("arrayoftargetmandatoryfields");';
1416 print
' console.log(arrayoftargetmandatoryfields);';
1417 print
" listtoshow = '';";
1418 print
" nbelement = arrayoftargetmandatoryfields.length
1419 for (let i = 0; i < nbelement; i++) {
1420 if (arrayoftargetmandatoryfields[i] && ! arrayselectedfields.includes(arrayoftargetmandatoryfields[i])) {
1421 console.log(arrayoftargetmandatoryfields[i]+' not mapped');
1422 listtoshow = listtoshow + (listtoshow ? ', ' : '') + '<b>' + arrayoftargetfields[i] + '*</b>';
1425 console.log(listtoshow);
1427 listtoshow = '".dol_escape_js(
img_warning($langs->trans(
"MandatoryTargetFieldsNotMapped")).
' '.$langs->trans(
"MandatoryTargetFieldsNotMapped")).
": ' + listtoshow;
1428 $('#div-mandatory-target-fields-not-mapped').html(listtoshow);
1430 $('#div-mandatory-target-fields-not-mapped').html('<span class=\"opacitymedium\">".
dol_escape_js($langs->trans(
"AllTargetMandatoryFieldsAreMapped")).
"</span>');
1437 print
'$(".targetselectchange").change(function(){'.
"\n";
1438 print
' setOptionsToDisabled();'.
"\n";
1440 print
' if(previousselectedlabelimport != "" && previousselectedvalueimport != -1) {'.
"\n";
1441 print
' let valuetochange = $(this).val(); '.
"\n";
1442 print
' $(".boxtdunused").each(function(){'.
"\n";
1443 print
' if ($(this).text().includes(valuetochange)){'.
"\n";
1444 print
' arraychild = $(this)[0].childNodes'.
"\n";
1445 print
' arraytexttomodify = arraychild[0].textContent.split(" ")'.
"\n";
1446 print
' arraytexttomodify[1] = previousselectedvalueimport '.
"\n";
1447 print
' textmodified = arraytexttomodify.join(" ") '.
"\n";
1448 print
' arraychild[0].textContent = textmodified'.
"\n";
1449 print
' arraychild[1].innerHTML = previousselectedlabelimport'.
"\n";
1453 print
' $(this).blur()'.
"\n";
1455 print
' saveSelection()'.
"\n";
1459 print
'</script>'.
"\n";
1465 print
'<div class="tabsAction">';
1467 if (count($array_match_file_to_database)) {
1468 if ($mandatoryfieldshavesource) {
1469 print
'<a class="butAction saveorderselect" href="import.php?step=5'.$param.
'&filetoimport='.urlencode($filetoimport).
'">'.$langs->trans(
"NextStep").
'</a>';
1471 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"SomeMandatoryFieldHaveNoSource")).
'">'.$langs->trans(
"NextStep").
'</a>';
1479 if (count($array_match_file_to_database)) {
1481 print
'<!-- Area to add new import profile -->'.
"\n";
1482 print
'<div class="marginbottomonly"><span class="opacitymedium">'.$langs->trans(
"SaveImportModel").
'</span></div>';
1484 print
'<form class="nocellnopadd" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1485 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1486 print
'<input type="hidden" name="action" value="add_import_model">';
1487 print
'<input type="hidden" name="step" value="'.$step.
'">';
1488 print
'<input type="hidden" name="format" value="'.$format.
'">';
1489 print
'<input type="hidden" name="datatoimport" value="'.$datatoimport.
'">';
1490 print
'<input type="hidden" name="filetoimport" value="'.$filetoimport.
'">';
1491 print
'<input type="hidden" name="hexa" value="'.$hexa.
'">';
1492 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1493 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1494 print
'<input type="hidden" name="page_y" value="">';
1495 print
'<input type="hidden" value="'.dol_escape_htmltag($separator).
'" name="separator">';
1496 print
'<input type="hidden" value="'.dol_escape_htmltag($enclosure).
'" name="enclosure">';
1498 print
'<div class="div-table-responsive-no-min">';
1499 print
'<table summary="selectofimportprofil" class="noborder centpercent">';
1500 print
'<tr class="liste_titre">';
1501 print
'<td>'.$langs->trans(
"ImportModelName").
'</td>';
1502 print
'<td>'.$langs->trans(
"Visibility").
'</td>';
1506 $nameofimportprofile = str_replace(
' ',
'-', $langs->trans(
"ImportProfile").
' '.$titleofmodule.
' '.
dol_print_date(
dol_now(
'gmt'),
'dayxcard'));
1508 $nameofimportprofile = $import_name;
1511 print
'<tr class="oddeven">';
1512 print
'<td><input name="import_name" class="minwidth300" value="'.$nameofimportprofile.
'"></td>';
1514 $arrayvisibility = array(
'private' => $langs->trans(
"Private"),
'all' => $langs->trans(
"Everybody"));
1515 print $form->selectarray(
'visibility', $arrayvisibility,
'private');
1517 print
'<td class="right">';
1518 print
'<input type="submit" class="button smallpaddingimp reposition" value="'.$langs->trans(
"SaveImportProfile").
'">';
1522 $sql =
"SELECT rowid, label, fk_user, entity";
1523 $sql .=
" FROM ".MAIN_DB_PREFIX.
"import_model";
1524 $sql .=
" WHERE type = '".$db->escape($datatoimport).
"'";
1526 $sql .=
" AND fk_user IN (0, ".((int) $user->id).
")";
1528 $sql .=
" ORDER BY rowid";
1530 $resql = $db->query($sql);
1532 $num = $db->num_rows($resql);
1534 $tmpuser =
new User($db);
1538 $obj = $db->fetch_object($resql);
1540 print
'<tr class="oddeven"><td>';
1543 print
'<td class="tdoverflowmax150">';
1544 if (empty($obj->fk_user)) {
1545 print $langs->trans(
"Everybody");
1547 $tmpuser->fetch($obj->fk_user);
1548 print $tmpuser->getNomUrl(-1);
1551 print
'<td class="right">';
1552 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?step='.$step.$param.
'&action=deleteprof&token='.
newToken().
'&id='.$obj->rowid.
'&filetoimport='.urlencode($filetoimport).
'">';
1570if ($step == 5 && $datatoimport) {
1571 $max_execution_time_for_importexport =
getDolGlobalInt(
'IMPORT_MAX_EXECUTION_TIME', 300);
1572 $max_time = @ini_get(
"max_execution_time");
1573 if ($max_time && $max_time < $max_execution_time_for_importexport) {
1574 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.");
1575 @ini_set(
"max_execution_time", $max_execution_time_for_importexport);
1579 $list = $objmodelimport->listOfAvailableImportFormat($db);
1582 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
1583 $file =
"import_".$model.
".modules.php";
1584 $classname =
"Import".ucfirst($model);
1585 require_once $dir.$file;
1586 $obj =
new $classname($db, $datatoimport);
1587 '@phan-var-force ModeleImports $obj';
1588 if ($model ==
'csv') {
1589 '@phan-var-force ImportCsv $obj';
1590 $obj->separator = $separator_used;
1591 $obj->enclosure = $enclosure;
1595 $fieldssource = array();
1596 $result = $obj->import_open_file(
$conf->import->dir_temp.
'/'.$filetoimport);
1600 $arrayrecord = $obj->import_read_record();
1603 foreach ($arrayrecord as $key => $val) {
1604 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 24);
1607 $obj->import_close_file();
1610 $nboflines = $obj->import_get_nb_of_lines(
$conf->import->dir_temp.
'/'.$filetoimport);
1612 $param =
'&leftmenu=import&format='.urlencode($format).
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport).
'&nboflines='.((int) $nboflines).
'&separator='.urlencode($separator).
'&enclosure='.urlencode($enclosure);
1614 if ($excludefirstline) {
1615 $param .=
'&excludefirstline='.urlencode($excludefirstline);
1618 $param .=
'&endatlinenb='.urlencode($endatlinenb);
1620 if (!empty($updatekeys)) {
1621 $param .=
'&updatekeys[]='.implode(
'&updatekeys[]=', $updatekeys);
1624 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
1629 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?'.$param2.
'" method="POST">';
1630 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1631 print
'<input type="hidden" name="step" value="5">';
1632 print
'<input type="hidden" name="action" value="launchsimu">';
1636 print
'<div class="underbanner clearboth"></div>';
1637 print
'<div class="fichecenter">';
1639 print
'<table width="100%" class="border tableforfield">';
1642 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
1644 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
1646 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
1647 $titleofmodule = $langs->trans(
"ProductOrService");
1649 print $titleofmodule;
1653 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
1655 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
1656 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
1657 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
1658 print $objimport->array_import_label[0];
1666 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
1668 print
'<div class="underbanner clearboth"></div>';
1669 print
'<div class="fichecenter">';
1670 print
'<table width="100%" class="border tableforfield">';
1673 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
1674 print
'<td class="nowraponall">';
1675 $text = $objmodelimport->getDriverDescForKey($format);
1677 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
1681 if ($model ==
'csv') {
1682 '@phan-var-force ImportCsv $obj';
1683 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
1686 print
' '.$langs->trans(
"Enclosure").
' : '.
dol_escape_htmltag($enclosure);
1691 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
1693 $modulepart =
'import';
1694 $relativepath =
GETPOST(
'filetoimport');
1695 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.urlencode($modulepart).
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
1696 print
img_mime($file,
'',
'pictofixedwidth');
1697 print $filetoimport;
1698 print
img_picto($langs->trans(
"Download"),
'download',
'class="paddingleft opacitymedium"');
1704 print $langs->trans(
"NbOfSourceLines");
1711 print $langs->trans(
"ImportFromToLine");
1713 if ($action ==
'launchsimu') {
1714 print
'<input type="number" class="maxwidth50 right" name="excludefirstlinebis" disabled="disabled" value="'.$excludefirstline.
'">';
1715 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1717 print
'<input type="number" class="maxwidth50 right" name="excludefirstline" value="'.$excludefirstline.
'">';
1718 print $form->textwithpicto(
"", $langs->trans(
"SetThisValueTo2ToExcludeFirstLine"));
1721 if ($action ==
'launchsimu') {
1722 print
'<input type="text" class="maxwidth50" name="endatlinenbbis" disabled="disabled" value="'.$endatlinenb.
'">';
1723 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1725 print
'<input type="text" class="maxwidth50" name="endatlinenb" value="'.$endatlinenb.
'">';
1726 print $form->textwithpicto(
"", $langs->trans(
"KeepEmptyToGoToEndOfFile"));
1728 if ($action ==
'launchsimu') {
1729 print
' <a href="'.$_SERVER[
"PHP_SELF"].
'?step=5'.$param.
'">'.$langs->trans(
"Modify").
'</a>';
1731 if ($excludefirstline == 2) {
1732 print $form->textwithpicto(
"", $langs->trans(
"WarningFirstImportedLine", $excludefirstline), 1,
'warning',
"warningexcludefirstline");
1734 $( document ).ready(function() {
1735 $("input[name=\'excludefirstline\']").on("change",function(){
1736 if($(this).val() <= 1){
1737 $(".warningexcludefirstline").hide();
1739 $(".warningexcludefirstline").show();
1749 print $form->textwithpicto($langs->trans(
"KeysToUseForUpdates"), $langs->trans(
"SelectPrimaryColumnsForUpdateAttempt"));
1751 if ($action ==
'launchsimu') {
1752 if (count($updatekeys)) {
1753 print $form->multiselectarray(
'updatekeysbis', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0,
'', 1,
'80%',
'disabled');
1755 print
'<span class="opacitymedium">'.$langs->trans(
"NoUpdateAttempt").
'</span> -';
1757 foreach ($updatekeys as $val) {
1758 print
'<input type="hidden" name="updatekeys[]" value="'.$val.
'">';
1760 print
' <a href="'.$_SERVER[
"PHP_SELF"].
'?step=5'.$param.
'">'.$langs->trans(
"Modify").
'</a>';
1762 if (is_array($objimport->array_import_updatekeys[0]) && count($objimport->array_import_updatekeys[0])) {
1763 print $form->multiselectarray(
'updatekeys', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0,
'', 1,
'80%');
1766 print
'<span class="opacitymedium">'.$langs->trans(
"UpdateNotYetSupportedForThisImport").
'</span>';
1779 print
load_fiche_titre($langs->trans(
"InformationOnTargetTables"),
'',
'file-import');
1781 print
'<div class="underbanner clearboth"></div>';
1782 print
'<div class="fichecenter">';
1784 print
'<table class="centpercent border tableforfield">';
1787 print
'<tr><td class="titlefieldcreate">';
1788 print $langs->trans(
"TablesTarget");
1790 $listtables = array();
1791 $sort_array_match_file_to_database = $array_match_file_to_database;
1792 foreach ($array_match_file_to_database as $code => $label) {
1794 if ($code > count($fieldssource)) {
1798 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
1799 $listtables[$alias] = $objimport->array_import_tables[0][$alias];
1801 if (count($listtables)) {
1804 foreach ($listtables as $val) {
1823 print $langs->trans(
"Error");
1829 print $langs->trans(
"FieldsTarget").
'</td><td class="small">';
1830 $listfields = array();
1833 $sort_array_match_file_to_database = $array_match_file_to_database;
1834 ksort($sort_array_match_file_to_database);
1836 foreach ($sort_array_match_file_to_database as $code => $label) {
1839 if ($code > count($fieldssource)) {
1843 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
1844 $listfields[$i] =
'<span class="nowrap">'.$langs->trans(
"Column").
' '.
num2Alpha((
int) $code - 1).
' -> '.$label.
'</span>';
1846 print count($listfields) ? (implode(
', ', $listfields)) : $langs->trans(
"Error");
1855 if ($action !=
'launchsimu') {
1857 print
'<br><span class="opacitymedium">';
1858 print $langs->trans(
"NowClickToTestTheImport", $langs->transnoentitiesnoconv(
"RunSimulateImportFile")).
'</span><br>';
1862 print
'<div class="center">';
1863 if ($user->hasRight(
'import',
'run')) {
1864 print
'<input type="submit" class="butAction" value="'.$langs->trans(
"RunSimulateImportFile").
'">';
1866 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunSimulateImportFile").
'</a>';
1871 $arrayoferrors = array();
1872 $arrayofwarnings = array();
1886 $pathfile =
$conf->import->dir_temp.
'/'.$filetoimport;
1887 $result = $obj->import_open_file($pathfile);
1889 global $tablewithentity_cache;
1890 $tablewithentity_cache = array();
1895 while (($sourcelinenb < $nboflines) && !$endoffile) {
1899 $arrayrecord = $obj->import_read_record();
1900 if ($arrayrecord ===
false) {
1901 $arrayofwarnings[$sourcelinenb][0] = array(
'lib' => $langs->trans(
'ErrorFileLinesReachEOF', $nboflines, $sourcelinenb),
'type' =>
'EOF_RECORD_ON_SEVERAL_LINES');
1905 if ($excludefirstline && ($sourcelinenb < $excludefirstline)) {
1908 if ($endatlinenb && ($sourcelinenb > $endatlinenb)) {
1912 $parameters = array(
1914 'datatoimport' => $datatoimport,
1916 'arrayrecord' => $arrayrecord,
1917 'array_match_file_to_database' => $array_match_file_to_database,
1918 'objimport' => $objimport,
1919 'fieldssource' => $fieldssource,
1920 'importid' => $importid,
1921 'updatekeys' => $updatekeys,
1922 'arrayoferrors' => &$arrayoferrors,
1923 'arrayofwarnings' => &$arrayofwarnings,
1927 $reshook = $hookmanager->executeHooks(
'ImportInsert', $parameters);
1929 $arrayoferrors[$sourcelinenb][] = [
1930 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
1934 if (empty($reshook)) {
1936 $result = $obj->import_insert($arrayrecord, $array_match_file_to_database, $objimport, count($fieldssource), $importid, $updatekeys);
1938 if (count($obj->errors)) {
1939 $arrayoferrors[$sourcelinenb] = $obj->errors;
1941 if (count($obj->warnings)) {
1942 $arrayofwarnings[$sourcelinenb] = $obj->warnings;
1944 if (!count($obj->errors) && !count($obj->warnings)) {
1949 $reshook = $hookmanager->executeHooks(
'AfterImportInsert', $parameters);
1951 $arrayoferrors[$sourcelinenb][] = [
1952 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
1957 $obj->import_close_file();
1959 print $langs->trans(
"ErrorFailedToOpenFile", $pathfile);
1966 if (!empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0])) {
1968 foreach ($objimport->array_import_run_sql_after[0] as $sqlafterimport) {
1970 $resqlafterimport = $db->query($sqlafterimport);
1971 if (!$resqlafterimport) {
1972 $arrayoferrors[
'none'][] = array(
'lib' => $langs->trans(
"Error running final request: ".$sqlafterimport));
1981 if (!count($arrayoferrors) && !count($arrayofwarnings)) {
1983 print
'<div class="info">';
1984 print
'<div class=""><b>'.$langs->trans(
"ResultOfSimulationNoError").
'</b></div>';
1985 print $langs->trans(
"NbInsertSim", empty($obj->nbinsert) ? 0 : $obj->nbinsert).
'<br>';
1986 print $langs->trans(
"NbUpdateSim", empty($obj->nbupdate) ? 0 : $obj->nbupdate).
'<br>';
1991 print
'<div class="warning">';
1992 print $langs->trans(
"NbOfLinesOK", $nbok).
'...<br>';
1999 if (count($arrayoferrors)) {
2000 print
img_error().
' <b>'.$langs->trans(
"ErrorsOnXLines", count($arrayoferrors)).
'</b><br>';
2001 print
'<table width="100%" class="border"><tr><td>';
2002 foreach ($arrayoferrors as $key => $val) {
2004 if ($nboferrors > $maxnboferrors) {
2005 print $langs->trans(
"TooMuchErrors", (count($arrayoferrors) - $nboferrors)).
"<br>";
2009 foreach ($val as $i => $err) {
2010 print
' > '.dol_escape_htmltag($err[
'lib']).
'<br>';
2013 print
'</td></tr></table>';
2019 if (count($arrayofwarnings)) {
2020 print
img_warning().
' <b>'.$langs->trans(
"WarningsOnXLines", count($arrayofwarnings)).
'</b><br>';
2021 print
'<table width="100%" class="border"><tr><td>';
2022 foreach ($arrayofwarnings as $key => $val) {
2024 if ($nbofwarnings > $maxnbofwarnings) {
2025 print $langs->trans(
"TooMuchWarnings", (count($arrayofwarnings) - $nbofwarnings)).
"<br>";
2029 foreach ($val as $i => $err) {
2030 print
' > '.dol_escape_htmltag($err[
'lib']).
'<br>';
2033 print
'</td></tr></table>';
2040 print
'<div class="center">';
2041 print
'<span class="opacitymedium">'.$langs->trans(
"NowClickToRunTheImport", $langs->transnoentitiesnoconv(
"RunImportFile")).
'</span><br>';
2050 print
'<div class="center">';
2051 if ($user->hasRight(
'import',
'run')) {
2052 if (empty($nboferrors)) {
2053 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/imports/import.php?leftmenu=import&step=6&importid='.$importid.$param.
'">'.$langs->trans(
"RunImportFile").
'</a>';
2057 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"CorrectErrorBeforeRunningImport")).
'">'.$langs->trans(
"RunImportFile").
'</a>';
2060 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunSimulateImportFile").
'</a>';
2062 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunImportFile").
'</a>';
2072if ($step == 6 && $datatoimport) {
2073 $max_execution_time_for_importexport =
getDolGlobalInt(
'IMPORT_MAX_EXECUTION_TIME', 300);
2074 $max_time = @ini_get(
"max_execution_time");
2075 if ($max_time && $max_time < $max_execution_time_for_importexport) {
2076 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.");
2077 @ini_set(
"max_execution_time", $max_execution_time_for_importexport);
2081 $list = $objmodelimport->listOfAvailableImportFormat($db);
2082 $importid =
GETPOST(
"importid",
'alphanohtml');
2086 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
2087 $file =
"import_".$model.
".modules.php";
2088 $classname =
"Import".ucfirst($model);
2089 require_once $dir.$file;
2090 $obj =
new $classname($db, $datatoimport);
2091 '@phan-var-force ModeleImports $obj';
2092 if ($model ==
'csv') {
2093 '@phan-var-force ImportCsv $obj';
2094 $obj->separator = $separator_used;
2095 $obj->enclosure = $enclosure;
2099 $fieldssource = array();
2100 $result = $obj->import_open_file(
$conf->import->dir_temp.
'/'.$filetoimport);
2103 $arrayrecord = $obj->import_read_record();
2106 foreach ($arrayrecord as $key => $val) {
2107 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 24);
2110 $obj->import_close_file();
2115 $param =
'&format='.$format.
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport).
'&nboflines='.((int) $nboflines);
2116 if ($excludefirstline) {
2117 $param .=
'&excludefirstline='.urlencode($excludefirstline);
2120 $param .=
'&endatlinenb='.urlencode($endatlinenb);
2123 $param .=
'&separator='.urlencode($separator);
2126 $param .=
'&enclosure='.urlencode($enclosure);
2129 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
2135 print
'<div class="underbanner clearboth"></div>';
2136 print
'<div class="fichecenter">';
2138 print
'<table width="100%" class="border">';
2141 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
2143 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
2145 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
2146 $titleofmodule = $langs->trans(
"ProductOrService");
2148 print $titleofmodule;
2152 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
2154 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
2155 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
2156 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
2157 print $objimport->array_import_label[0];
2165 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
2167 print
'<div class="underbanner clearboth"></div>';
2168 print
'<div class="fichecenter">';
2169 print
'<table width="100%" class="border tableforfield">';
2172 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
2173 print
'<td class="nowraponall">';
2174 $text = $objmodelimport->getDriverDescForKey($format);
2176 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
2180 if ($model ==
'csv') {
2181 '@phan-var-force ImportCsv $obj';
2182 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
2184 print $langs->trans(
"Separator").
' : ';
2185 print htmlentities($separator);
2186 print
' '.$langs->trans(
"Enclosure").
' : ';
2187 print htmlentities($enclosure);
2192 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
2194 $modulepart =
'import';
2195 $relativepath =
GETPOST(
'filetoimport');
2196 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
2197 print
img_mime($file,
'',
'pictofixedwidth');
2198 print $filetoimport;
2204 print $langs->trans(
"NbOfSourceLines");
2211 print $langs->trans(
"ImportFromLine");
2213 print
'<input type="text" size="4" name="excludefirstline" disabled="disabled" value="'.$excludefirstline.
'">';
2218 print $langs->trans(
"EndAtLineNb");
2220 print
'<input type="text" size="4" name="endatlinenb" disabled="disabled" value="'.$endatlinenb.
'">';
2228 print
'<b>'.$langs->trans(
"InformationOnTargetTables").
'</b>';
2229 print
'<div class="underbanner clearboth"></div>';
2230 print
'<div class="fichecenter">';
2231 print
'<table class="border centpercent">';
2234 print
'<tr><td width="25%">';
2235 print $langs->trans(
"TablesTarget");
2237 $listtables = array();
2238 foreach ($array_match_file_to_database as $code => $label) {
2240 if ($code > count($fieldssource)) {
2244 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
2245 $listtables[$alias] = $objimport->array_import_tables[0][$alias];
2247 if (count($listtables)) {
2249 foreach ($listtables as $val) {
2268 print $langs->trans(
"Error");
2274 print $langs->trans(
"FieldsTarget").
'</td><td>';
2275 $listfields = array();
2277 $sort_array_match_file_to_database = $array_match_file_to_database;
2278 ksort($sort_array_match_file_to_database);
2280 foreach ($sort_array_match_file_to_database as $code => $label) {
2283 if ($code > count($fieldssource)) {
2287 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
2288 $listfields[$i] = $langs->trans(
"Field").
' '.$code.
'->'.$label;
2290 print count($listfields) ? (implode(
', ', $listfields)) : $langs->trans(
"Error");
2297 $arrayoferrors = array();
2298 $arrayofwarnings = array();
2299 $maxnboferrors = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_ERRORS') ? 50 :
$conf->global->IMPORT_MAX_NB_OF_ERRORS;
2300 $maxnbofwarnings = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_WARNINGS') ? 50 :
$conf->global->IMPORT_MAX_NB_OF_WARNINGS;
2312 $pathfile =
$conf->import->dir_temp.
'/'.$filetoimport;
2313 $result = $obj->import_open_file($pathfile);
2315 global $tablewithentity_cache;
2316 $tablewithentity_cache = array();
2320 while ($sourcelinenb < $nboflines && !$endoffile) {
2322 $arrayrecord = $obj->import_read_record();
2323 if ($arrayrecord ===
false) {
2324 $arrayofwarnings[$sourcelinenb][0] = array(
'lib' => $langs->trans(
'ErrorFileLinesReachEOF', $nboflines, $sourcelinenb),
'type' =>
'EOF_RECORD_ON_SEVERAL_LINES');
2328 if ($excludefirstline && ($sourcelinenb < $excludefirstline)) {
2331 if ($endatlinenb && ($sourcelinenb > $endatlinenb)) {
2335 $parameters = array(
2337 'datatoimport' => $datatoimport,
2339 'arrayrecord' => $arrayrecord,
2340 'array_match_file_to_database' => $array_match_file_to_database,
2341 'objimport' => $objimport,
2342 'fieldssource' => $fieldssource,
2343 'importid' => $importid,
2344 'updatekeys' => $updatekeys,
2345 'arrayoferrors' => &$arrayoferrors,
2346 'arrayofwarnings' => &$arrayofwarnings,
2350 $reshook = $hookmanager->executeHooks(
'ImportInsert', $parameters);
2352 $arrayoferrors[$sourcelinenb][] = [
2353 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
2357 if (empty($reshook)) {
2359 $result = $obj->import_insert($arrayrecord, $array_match_file_to_database, $objimport, count($fieldssource), $importid, $updatekeys);
2361 if (count($obj->errors)) {
2362 $arrayoferrors[$sourcelinenb] = $obj->errors;
2364 if (count($obj->warnings)) {
2365 $arrayofwarnings[$sourcelinenb] = $obj->warnings;
2368 if (!count($obj->errors) && !count($obj->warnings)) {
2373 $reshook = $hookmanager->executeHooks(
'AfterImportInsert', $parameters);
2375 $arrayoferrors[$sourcelinenb][] = [
2376 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
2381 $obj->import_close_file();
2383 print $langs->trans(
"ErrorFailedToOpenFile", $pathfile);
2386 if (count($arrayoferrors) > 0) {
2393 if (!empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0])) {
2395 foreach ($objimport->array_import_run_sql_after[0] as $sqlafterimport) {
2397 $resqlafterimport = $db->query($sqlafterimport);
2398 if (!$resqlafterimport) {
2399 $arrayoferrors[
'none'][] = array(
'lib' => $langs->trans(
"Error running final request: ".$sqlafterimport));
2417 print
'<div class="info">';
2418 print $langs->trans(
"NbOfLinesImported", $nbok).
'</b><br>';
2419 print $langs->trans(
"NbInsert", empty($obj->nbinsert) ? 0 : $obj->nbinsert).
'<br>';
2420 print $langs->trans(
"NbUpdate", empty($obj->nbupdate) ? 0 : $obj->nbupdate).
'<br>';
2422 print
'<div class="center">';
2423 print $langs->trans(
"FileWasImported", $importid).
'<br>';
2424 print
'<span class="opacitymedium">'.$langs->trans(
"YouCanUseImportIdToFindRecord", $importid).
'</span><br>';
2447 global
$conf, $langs;
2451 if ($key ==
'none') {
2453 print
"\n\n<!-- Box_no-key start-->\n";
2454 print
'<div class="box boximport" style="padding:0;">'.
"\n";
2455 print
'<table summary="boxtable_no-key" class="centpercent nobordernopadding">'.
"\n";
2457 print
"\n\n<!-- Box ".$pos.
" start -->\n";
2458 print
'<div class="box boximport" style="padding: 0;" id="boxto_'.$pos.
'">'.
"\n";
2460 print
'<table summary="boxtable'.$pos.
'" class="nobordernopadding centpercent tableimport">'.
"\n";
2463 if (($pos && $pos > count($fieldssource)) && (!isset($fieldssource[$pos][
"imported"]))) {
2473 } elseif ($key ==
'none') {
2474 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
2475 print
'<td class="nocellnopadd" width="16" style="font-weight: normal">';
2478 print
'<td style="font-weight: normal">';
2484 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
2485 print
'<td class="nocellnopadd" width="16" style="font-weight: normal">';
2488 print
img_picto($langs->trans(
"Column").
' '.
num2Alpha($pos - 1),
'file',
'class="pictofixedwidth marginleftonly"');
2490 if (isset($fieldssource[$pos][
'imported']) && $fieldssource[$pos][
'imported'] ==
false) {
2491 print
'<td class="nowraponall boxtdunused" style="font-weight: normal">';
2493 print
'<td class="nowraponall tdoverflowmax500" style="font-weight: normal">';
2495 print $langs->trans(
"Column").
' '.
num2Alpha($pos - 1).
' (#'.$pos.
')';
2496 if (empty($fieldssource[$pos][
'example1'])) {
2497 $example = $fieldssource[$pos][
'label'];
2499 $example = $fieldssource[$pos][
'example1'];
2503 $example = mb_convert_encoding($example,
'UTF-8',
'ISO-8859-1');
2507 print
'<i class="opacitymedium">'.dol_escape_htmltag($example).
'</i>';
2516 print
"<!-- Box end -->\n\n";
2529 $i = count($fieldssource) + 1;
2532 foreach ($listofkey as $key => $val) {
2533 $maxkey = max($maxkey, $key);
2536 while ($i <= $maxkey) {
2537 if (empty($listofkey[$i])) {
2559 if ($position == count($array)) {
2560 $ret = $array + $insertArray;
2563 foreach ($array as $key => $value) {
2564 if ($position == $i++) {
2565 $ret += $insertArray;
2568 $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.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Parent class for import file readers.
Class to manage Dolibarr users.
dol_filemtime($pathoffile)
Return time of a file.
dol_filesize($pathoffile)
Return size of a file.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_count_nb_of_line($file)
Count number of lines in a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $keyforsourcefile='addedfile', $upload_dir='', $mode=0)
Check validity of a file upload from an GUI page, and move it to its final destination.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
num2Alpha($n)
Return a numeric value into an Excel like column number.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_error($titlealt='default')
Show error logo.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
utf8_check($str)
Check if a string is in UTF8.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
import_prepare_head($param, $maxstep=0)
Function to return list of tabs for import pages.
show_elem($fieldssource, $pos, $key)
Function to put the movable box of a source field.
getnewkey(&$fieldssource, &$listofkey)
Return not used field number.
arrayInsert($array, $position, $insertArray)
Return array with element inserted in it at position $position.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.