29require_once
'../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/imports/class/import.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/modules/import/modules_import.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/lib/import.lib.php';
46$langs->loadLangs(array(
'exports',
'compta',
'errors',
'projects',
'admin'));
49$hookmanager->initHooks(array(
'imports'));
57 'invoice_line' =>
'bill',
59 'order_line' =>
'order',
61 'propal_line' =>
'propal',
62 'intervention' =>
'intervention',
63 'inter_line' =>
'intervention',
65 'member_type' =>
'group',
66 'subscription' =>
'payment',
67 'payment' =>
'payment',
69 'tax_type' =>
'generic',
71 'account' =>
'account',
72 'product' =>
'product',
73 'virtualproduct' =>
'product',
74 'subproduct' =>
'product',
75 'product_supplier_ref' =>
'product',
77 'warehouse' =>
'stock',
79 'stockbatch' =>
'stock',
80 'category' =>
'category',
81 'shipment' =>
'sending',
82 'shipment_line' =>
'sending',
83 'project' =>
'project',
85 'reception' =>
'sending',
86 'reception_line' =>
'sending',
87 'expensereport' =>
'trip',
88 'expensereport_line' =>
'trip',
89 'holiday' =>
'holiday',
90 'contract_line' =>
'contract',
91 'translation' =>
'generic',
99 'company' =>
'Company',
100 'contact' =>
'Contact',
102 'invoice_line' =>
'InvoiceLine',
104 'order_line' =>
'OrderLine',
105 'propal' =>
'Proposal',
106 'propal_line' =>
'ProposalLine',
107 'intervention' =>
'Intervention',
108 'inter_line' =>
'InterLine',
109 'member' =>
'Member',
110 'member_type' =>
'MemberType',
111 'subscription' =>
'Subscription',
112 'tax' =>
'SocialContribution',
113 'tax_type' =>
'DictionarySocialContributions',
114 'account' =>
'BankTransactions',
115 'payment' =>
'Payment',
116 'product' =>
'Product',
117 'virtualproduct' =>
'AssociatedProducts',
118 'subproduct' =>
'SubProduct',
119 'product_supplier_ref' =>
'SupplierPrices',
120 'service' =>
'Service',
122 'movement' =>
'StockMovement',
124 'stockbatch' =>
'StockDetailPerBatch',
125 'warehouse' =>
'Warehouse',
126 'category' =>
'Category',
128 'trip' =>
'TripsAndExpenses',
129 'shipment' =>
'Shipments',
130 'shipment_line' =>
'ShipmentLine',
131 'project' =>
'Projects',
132 'projecttask' =>
'Tasks',
133 'task_time' =>
'TaskTimeSpent',
135 'expensereport' =>
'ExpenseReport',
136 'expensereport_line' =>
'ExpenseReportLine',
137 'holiday' =>
'TitreRequestCP',
138 'contract' =>
'Contract',
139 'contract_line' =>
'ContractLine',
140 'translation' =>
'Translation',
142 'bomline' =>
'BOMLine'
145$datatoimport =
GETPOST(
'datatoimport');
147$filetoimport =
GETPOST(
'filetoimport');
148$action =
GETPOST(
'action',
'alpha');
149$confirm =
GETPOST(
'confirm',
'alpha');
151$import_name =
GETPOST(
'import_name');
154$excludefirstline = (
GETPOST(
'excludefirstline') ?
GETPOST(
'excludefirstline') : 2);
155$endatlinenb = (
GETPOST(
'endatlinenb') ?
GETPOST(
'endatlinenb') :
'');
156$updatekeys = (
GETPOST(
'updatekeys',
'array') ?
GETPOST(
'updatekeys',
'array') : array());
157$separator = (
GETPOST(
'separator',
'nohtml') ?
GETPOST(
'separator',
'nohtml', 3) :
'');
158$enclosure = (
GETPOST(
'enclosure',
'nohtml') ?
GETPOST(
'enclosure',
'nohtml') :
'"');
159$charset =
GETPOST(
'charset',
'aZ09');
160$separator_used = str_replace(
'\t',
"\t", $separator);
163$objimport =
new Import($db);
164$objimport->load_arrays($user, ($step == 1 ?
'' : $datatoimport));
166if (empty($updatekeys) && !empty($objimport->array_import_preselected_updatekeys[0])) {
167 $updatekeys = $objimport->array_import_preselected_updatekeys[0];
172$form =
new Form($db);
177if (empty($array_match_file_to_database)) {
178 $serialized_array_match_file_to_database = isset($_SESSION[
"dol_array_match_file_to_database_select"]) ? $_SESSION[
"dol_array_match_file_to_database_select"] :
'';
179 $array_match_file_to_database = array();
180 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
181 foreach ($fieldsarray as $elem) {
182 $tabelem = explode(
'=', $elem, 2);
184 $val = (isset($tabelem[1]) ? $tabelem[1] :
'');
186 $array_match_file_to_database[$key] = $val;
196if ($action ==
'deleteprof' && $user->hasRight(
'import',
'run')) {
199 $result = $objimport->delete($user);
204if ($action ==
'add_import_model' && $user->hasRight(
'import',
'run')) {
208 foreach ($array_match_file_to_database as $key => $val) {
212 $hexa .= $key.
'='.$val;
215 $objimport->model_name = $import_name;
216 $objimport->datatoimport = $datatoimport;
217 $objimport->hexa = $hexa;
218 $objimport->fk_user = (
GETPOST(
'visibility',
'aZ09') ==
'all' ? 0 : $user->id);
220 $result = $objimport->create($user);
222 setEventMessages($langs->trans(
"ImportModelSaved", $objimport->model_name),
null,
'mesgs');
225 $langs->load(
"errors");
226 if ($objimport->errno ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
227 setEventMessages($langs->trans(
"ErrorImportDuplicateProfil"),
null,
'errors');
233 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"ImportModelName")),
null,
'errors');
237if ($step == 3 && $datatoimport) {
244 dol_syslog(
"File ".$fullpath.
" was added for import");
246 $langs->load(
"errors");
252 if ($action ==
'confirm_deletefile' && $confirm ==
'yes' && $user->hasRight(
'import',
'run')) {
253 $langs->load(
"other");
255 $param =
'&datatoimport='.urlencode($datatoimport).
'&format='.urlencode($format);
256 if ($excludefirstline) {
257 $param .=
'&excludefirstline='.urlencode($excludefirstline);
260 $param .=
'&endatlinenb='.urlencode($endatlinenb);
263 $file = $conf->import->dir_temp.
'/'.
GETPOST(
'urlfile');
270 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?step='.$step.$param);
275if ($step == 4 && $action ==
'select_model' && $user->hasRight(
'import',
'run')) {
277 $_SESSION[
"dol_array_match_file_to_database"] =
'';
278 $serialized_array_match_file_to_database =
'';
279 $array_match_file_to_database = array();
283 $result = $objimport->fetch($importmodelid);
285 $serialized_array_match_file_to_database = $objimport->hexa;
286 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
287 foreach ($fieldsarray as $elem) {
288 $tabelem = explode(
'=', $elem);
292 $array_match_file_to_database[$key] = $val;
295 $_SESSION[
"dol_array_match_file_to_database"] = $serialized_array_match_file_to_database;
296 $_SESSION[
'dol_array_match_file_to_database_select'] = $_SESSION[
"dol_array_match_file_to_database"];
299if ($action ==
'saveselectorder' && $user->hasRight(
'import',
'run')) {
301 $serialized_array_match_file_to_database =
'';
303 $selectorder = explode(
",",
GETPOST(
'selectorder'));
304 $fieldtarget = $fieldstarget = $objimport->array_import_fields[0];
305 foreach ($selectorder as $key => $code) {
306 $serialized_array_match_file_to_database .= $key.
'='.$code;
307 $serialized_array_match_file_to_database .=
',';
309 $serialized_array_match_file_to_database = substr($serialized_array_match_file_to_database, 0, -1);
310 dol_syslog(
'dol_array_match_file_to_database_select='.$serialized_array_match_file_to_database);
311 $_SESSION[
"dol_array_match_file_to_database_select"] = $serialized_array_match_file_to_database;
321$help_url =
'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones';
324if ($step == 1 || !$datatoimport) {
326 $serialized_array_match_file_to_database =
'';
327 $array_match_file_to_database = array();
328 $_SESSION[
"dol_array_match_file_to_database"] =
'';
329 $_SESSION[
"dol_array_match_file_to_database_select"] =
'';
332 if ($excludefirstline) {
333 $param .=
'&excludefirstline='.urlencode($excludefirstline);
336 $param .=
'&endatlinenb='.urlencode($endatlinenb);
339 $param .=
'&separator='.urlencode($separator);
342 $param .=
'&enclosure='.urlencode($enclosure);
345 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
351 print
'<div class="opacitymedium">'.$langs->trans(
"SelectImportDataSet").
'</div>';
355 $nbmodulesnotautoenabled = count($conf->modules);
356 $listofmodulesautoenabled = array(
'user',
'agenda',
'fckeditor',
'export',
'import');
357 foreach ($listofmodulesautoenabled as $moduleautoenable) {
358 if (in_array($moduleautoenable, $conf->modules)) {
359 $nbmodulesnotautoenabled--;
363 if ($user->admin && $nbmodulesnotautoenabled <
getDolGlobalInt(
'MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING', 1)) {
364 print
info_admin($langs->trans(
"WarningOnlyProfilesOfActivatedModules").
' '.$langs->trans(
"YouCanEnableModulesFrom"));
370 print
'<div class="div-table-responsive-no-min">';
371 print
'<table class="noborder centpercent nomarginbottom">';
372 print
'<tr class="liste_titre">';
373 print
'<td>'.$langs->trans(
"Module").
'</td>';
374 print
'<td>'.$langs->trans(
"ImportableDatas").
'</td>';
375 print
'<td> </td>';
378 if (count($objimport->array_import_module)) {
379 $sortedarrayofmodules =
dol_sort_array($objimport->array_import_module,
'position_of_profile',
'asc', 0, 0, 1);
380 foreach ($sortedarrayofmodules as $key => $value) {
382 $titleofmodule = $objimport->array_import_module[$key][
'module']->getName();
383 print
'<tr class="oddeven"><td class="tdoverflowmax200" title="'.dolPrintHTML($titleofmodule).
'">';
385 if (in_array($objimport->array_import_code[$key], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
386 $titleofmodule = $langs->trans(
"ProductOrService");
390 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[$key]);
391 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
392 $label = $objimport->array_import_label[$key];
393 print
'<div class="twolinesmax-normallineheight minwidth200onall">';
394 print
img_object($objimport->array_import_module[$key][
'module']->getName(), $entityicon,
'class="pictofixedwidth"');
397 print
'</td><td style="text-align: right">';
398 if ($objimport->array_import_perms[$key]) {
399 print
'<a href="'.DOL_URL_ROOT.
'/imports/import.php?step=2&datatoimport='.$objimport->array_import_code[$key].$param.
'">'.
img_picto($langs->trans(
"NewImport"),
'next',
'class="fa-15"').
'</a>';
401 print $langs->trans(
"NotEnoughPermissions");
406 print
'<tr><td class="oddeven" colspan="3">'.$langs->trans(
"NoImportableData").
'</td></tr>';
416if ($step == 2 && $datatoimport) {
417 $param =
'&datatoimport='.urlencode($datatoimport);
418 if ($excludefirstline) {
419 $param .=
'&excludefirstline='.urlencode($excludefirstline);
422 $param .=
'&endatlinenb='.urlencode($endatlinenb);
425 $param .=
'&separator='.urlencode($separator);
428 $param .=
'&enclosure='.urlencode($enclosure);
431 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
437 print
'<div class="underbanner clearboth"></div>';
438 print
'<div class="fichecenter">';
440 print
'<table class="border tableforfield centpercent">';
443 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
445 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
447 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
448 $titleofmodule = $langs->trans(
"ProductOrService");
450 print $titleofmodule;
454 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
456 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
457 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
458 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
459 print $objimport->array_import_label[0];
467 print
'<form name="userfile" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" METHOD="POST">';
468 print
'<input type="hidden" name="token" value="'.newToken().
'">';
472 print
'<span class="opacitymedium">';
473 $s = $langs->trans(
"ChooseFormatOfFileToImport",
'{s1}');
474 $s = str_replace(
'{s1}',
img_picto(
'',
'next'), $s);
476 print
'</span><br><br>';
480 print
'<div class="div-table-responsive-no-min">';
481 print
'<table class="noborder centpercent" cellpadding="4">';
486 print
'<tr class="liste_titre"><td colspan="5">';
487 print $langs->trans(
"FileMustHaveOneOfFollowingFormat");
489 $list = $objmodelimport->listOfAvailableImportFormat($db);
490 foreach ($list as $key) {
491 print
'<tr class="oddeven">';
492 print
'<td width="16">'.img_picto_common($key, $objmodelimport->getPictoForKey($key)).
'</td>';
493 $htmltext = $objmodelimport->getDriverDescForKey($key);
494 print
'<td>'.$form->textwithpicto($objmodelimport->getDriverLabelForKey($key), $htmltext).
'</td>';
495 print
'<td style="text-align:center">';
496 if (empty($objmodelimport->drivererror[$key])) {
497 $filename = $langs->transnoentitiesnoconv(
"ExampleOfImportFile").
'_'.$datatoimport.
'.'.$key;
498 print
'<a href="'.DOL_URL_ROOT.
'/imports/emptyexample.php?format='.$key.$param.
'&output=file&file='.urlencode($filename).
'" target="_blank" rel="noopener noreferrer">';
499 print
img_picto(
'',
'download',
'class="paddingright opacitymedium"');
500 print $langs->trans(
"DownloadEmptyExampleShort");
502 print $form->textwithpicto(
'', $langs->trans(
"DownloadEmptyExample").
'.<br>'.$langs->trans(
"StarAreMandatory"));
508 print
'<td style="text-align:right">';
509 if (empty($objmodelimport->drivererror[$key])) {
510 print
'<a href="'.DOL_URL_ROOT.
'/imports/import.php?step=3&format='.$key.$param.
'">'.
img_picto($langs->trans(
"SelectFormat"),
'next',
'class="fa-15"').
'</a>';
524if ($step == 3 && $datatoimport) {
525 $param =
'&datatoimport='.urlencode($datatoimport).
'&format='.urlencode($format);
526 if ($excludefirstline) {
527 $param .=
'&excludefirstline='.urlencode($excludefirstline);
530 $param .=
'&endatlinenb='.urlencode($endatlinenb);
533 $param .=
'&separator='.urlencode($separator);
536 $param .=
'&enclosure='.urlencode($enclosure);
539 $list = $objmodelimport->listOfAvailableImportFormat($db);
541 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
550 if ($action ==
'delete') {
551 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?urlfile='.urlencode(
GETPOST(
'urlfile')).
'&step=3'.$param, $langs->trans(
'DeleteFile'), $langs->trans(
'ConfirmDeleteFile'),
'confirm_deletefile',
'', 0, 1);
554 print
'<div class="underbanner clearboth"></div>';
555 print
'<div class="fichecenter">';
557 print
'<table class="border tableforfield centpercent">';
560 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
562 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
564 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
565 $titleofmodule = $langs->trans(
"ProductOrService");
567 print $titleofmodule;
571 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
573 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
574 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
575 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
576 print $objimport->array_import_label[0];
584 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
586 print
'<div class="underbanner clearboth"></div>';
587 print
'<div class="fichecenter">';
588 print
'<table width="100%" class="border tableforfield">';
591 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
592 print
'<td class="nowraponall">';
593 $text = $objmodelimport->getDriverDescForKey($format);
595 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
596 print
'</td><td style="text-align:right" class="nowrap">';
597 $filename = $langs->transnoentitiesnoconv(
"ExampleOfImportFile").
'_'.$datatoimport.
'.'.$format;
598 print
'<a href="'.DOL_URL_ROOT.
'/imports/emptyexample.php?format='.$format.$param.
'&output=file&file='.urlencode($filename).
'" target="_blank" rel="noopener noreferrer">';
599 print
img_picto(
'',
'download',
'class="paddingright opacitymedium"');
600 print $langs->trans(
"DownloadEmptyExampleShort");
602 print $form->textwithpicto(
'', $langs->trans(
"DownloadEmptyExample").
'.<br>'.$langs->trans(
"StarAreMandatory"));
611 if ($format ==
'xlsx' && !class_exists(
'XMLWriter')) {
612 $langs->load(
"install");
613 print
info_admin($langs->trans(
"ErrorPHPDoesNotSupport",
'php-xml'), 0, 0,
'1',
'error');
619 print
'<form name="userfile" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="POST">';
620 print
'<input type="hidden" name="token" value="'.newToken().
'">';
621 print
'<input type="hidden" value="'.$step.
'" name="step">';
622 print
'<input type="hidden" value="'.dol_escape_htmltag($format).
'" name="format">';
623 print
'<input type="hidden" value="'.$excludefirstline.
'" name="excludefirstline">';
624 print
'<input type="hidden" value="'.$endatlinenb.
'" name="endatlinenb">';
625 print
'<input type="hidden" value="'.dol_escape_htmltag($separator).
'" name="separator">';
626 print
'<input type="hidden" value="'.dol_escape_htmltag($enclosure).
'" name="enclosure">';
627 print
'<input type="hidden" value="'.dol_escape_htmltag($datatoimport).
'" name="datatoimport">';
629 print
'<span class="opacitymedium">';
630 $s = $langs->trans(
"ChooseFileToImport",
'{s1}');
631 $s = str_replace(
'{s1}',
img_picto(
'',
'next'), $s);
633 print
'</span><br><br>';
638 print
'<div class="marginbottomonly">';
640 $maxmin = $maxfilesizearray[
'maxmin'];
642 print
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
644 print
'<input type="file" name="userfile" size="20" maxlength="80"> ';
646 print
'<input type="submit" class="button small" value="'.$langs->trans(
"AddFile").
'"'.$out.
' name="sendit">';
650 $maxphp = @ini_get(
'upload_max_filesize');
651 if (preg_match(
'/k$/i', $maxphp)) {
652 $maxphp = (int) substr($maxphp, 0, -1);
654 if (preg_match(
'/m$/i', $maxphp)) {
655 $maxphp = (int) substr($maxphp, 0, -1) * 1024;
657 if (preg_match(
'/g$/i', $maxphp)) {
658 $maxphp = (int) substr($maxphp, 0, -1) * 1024 * 1024;
660 if (preg_match(
'/t$/i', $maxphp)) {
661 $maxphp = (int) substr($maxphp, 0, -1) * 1024 * 1024 * 1024;
663 $maxphp2 = @ini_get(
'post_max_size');
664 if (preg_match(
'/k$/i', $maxphp2)) {
665 $maxphp2 = (int) substr($maxphp2, 0, -1);
667 if (preg_match(
'/m$/i', $maxphp2)) {
668 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024;
670 if (preg_match(
'/g$/i', $maxphp2)) {
671 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024 * 1024;
673 if (preg_match(
'/t$/i', $maxphp2)) {
674 $maxphp2 = (int) substr($maxphp2, 0, -1) * 1024 * 1024 * 1024;
678 $maxphptoshow = $maxphptoshowparam =
'';
680 $maxmin = min($max, $maxphp);
681 $maxphptoshow = $maxphp;
682 $maxphptoshowparam =
'upload_max_filesize';
685 $maxmin = min($max, $maxphp2);
686 if ($maxphp2 < $maxphp) {
687 $maxphptoshow = $maxphp2;
688 $maxphptoshowparam =
'post_max_size';
692 $langs->load(
'other');
694 $out .=
info_admin($langs->trans(
"ThisLimitIsDefinedInSetup", $max, $maxphptoshow), 1);
696 $out .=
' ('.$langs->trans(
"UploadDisabled").
')';
702 $filearray =
dol_dir_list($conf->import->dir_temp,
'files', 0,
'',
'',
'name', SORT_DESC);
703 if (count($filearray) > 0) {
704 print
'<div class="div-table-responsive-no-min">';
705 print
'<table class="noborder centpercent" width="100%" cellpadding="4">';
707 $dir = $conf->import->dir_temp;
711 foreach ($filearray as $key => $val) {
712 $file = $val[
'name'];
716 $file = mb_convert_encoding($file,
'UTF-8',
'ISO-8859-1');
719 if (preg_match(
'/^\./', $file)) {
723 $modulepart =
'import';
724 $urlsource = $_SERVER[
"PHP_SELF"].
'?step='.$step.$param.
'&filetoimport='.urlencode($filetoimport);
725 $relativepath = $file;
727 print
'<tr class="oddeven">';
729 print
img_mime($file,
'',
'pictofixedwidth');
730 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=3'.$param.
'" target="_blank" rel="noopener noreferrer">';
735 print
'<td style="text-align:right">'.dol_print_size(
dol_filesize($dir.
'/'.$file)).
'</td>';
737 print
'<td style="text-align:right">'.dol_print_date(
dol_filemtime($dir.
'/'.$file),
'dayhour').
'</td>';
739 print
'<td style="text-align:right"><a href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.
newToken().
'&step=3'.$param.
'&urlfile='.urlencode($relativepath);
740 print
'">'.img_delete().
'</a></td>';
742 print
'<td style="text-align:right">';
743 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?step=4'.$param.
'&filetoimport='.urlencode($relativepath).
'">'.
img_picto($langs->trans(
"NewImport"),
'next',
'class="fa-15"').
'</a>';
757if ($step == 4 && $datatoimport) {
759 $serialized_array_match_file_to_database = isset($_SESSION[
"dol_array_match_file_to_database_select"]) ? $_SESSION[
"dol_array_match_file_to_database_select"] :
'';
760 $fieldsarray = explode(
',', $serialized_array_match_file_to_database);
761 $array_match_file_to_database = array();
762 foreach ($fieldsarray as $elem) {
763 $tabelem = explode(
'=', $elem, 2);
765 $val = (isset($tabelem[1]) ? $tabelem[1] :
'');
767 $array_match_file_to_database[$key] = $val;
776 $list = $objmodelimport->listOfAvailableImportFormat($db);
778 if (empty($separator)) {
779 $separator = (!
getDolGlobalString(
'IMPORT_CSV_SEPARATOR_TO_USE') ?
',' : $conf->global->IMPORT_CSV_SEPARATOR_TO_USE);
783 if ($model ==
'csv' && strlen($separator) == 1 && !GETPOSTISSET(
'separator')) {
784 '@phan-var-force ImportCsv $obj';
786 $fh = fopen($conf->import->dir_temp.
'/'.$filetoimport,
'r');
788 $sline = fgets($fh, 1000000);
790 $nboccurence = substr_count($sline, $separator);
791 $nboccurencea = substr_count($sline,
',');
792 $nboccurenceb = substr_count($sline,
';');
794 if ($nboccurence == 0) {
795 if ($nboccurencea > 2) {
797 } elseif ($nboccurenceb > 2) {
805 $separator_used = str_replace(
'\t',
"\t", $separator);
808 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
809 $file =
"import_".$model.
".modules.php";
810 $classname =
"Import".ucfirst($model);
811 require_once $dir.$file;
812 $obj =
new $classname($db, $datatoimport);
813 '@phan-var-force ModeleImports $obj';
815 if (!empty($obj->error)) {
816 $langs->load(
"errors");
817 $param =
'&datatoimport='.$datatoimport.
'&format='.$format;
819 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?step=3'.$param.
'&filetoimport='.urlencode($relativepath));
823 if ($model ==
'csv') {
824 '@phan-var-force ImportCsv $obj';
825 $obj->separator = $separator_used;
826 $obj->enclosure = $enclosure;
829 if ($model ==
'xlsx') {
830 '@phan-var-force ImportXlsx $obj';
831 if (!preg_match(
'/\.xlsx$/i', $filetoimport)) {
832 $langs->load(
"errors");
833 $param =
'&datatoimport='.$datatoimport.
'&format='.$format;
834 setEventMessages($langs->trans(
"ErrorFileMustHaveFormat", $model),
null,
'errors');
835 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?step=3'.$param.
'&filetoimport='.urlencode($relativepath));
841 $array_match_file_to_database = array();
845 $fieldssource = array();
847 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport);
850 $arrayrecord = $obj->import_read_record();
854 foreach ($arrayrecord as $key => $val) {
855 if ($val[
"type"] != -1) {
856 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 128);
858 $fieldssource[$i][
'example1'] = $langs->trans(
'Empty');
860 $fieldssource[$i][
'imported'] =
false;
863 $obj->import_close_file();
867 $fieldstarget = $objimport->array_import_fields[0];
868 $minpos = min(count($fieldssource), count($fieldstarget));
872 $initialloadofstep4 =
false;
873 if (empty($_SESSION[
'dol_array_match_file_to_database_select'])) {
874 $initialloadofstep4 =
true;
878 if (count($array_match_file_to_database) == 0) {
884 $num = count($fieldssource);
885 while ($pos <= $num) {
886 if ($num >= 1 && $pos <= $num) {
888 foreach ($fieldstarget as $key => $val) {
889 if ($posbis < $pos) {
894 $array_match_file_to_database[$pos] = $key;
901 $array_match_database_to_file = array_flip($array_match_file_to_database);
905 $fieldstarget_tmp = array();
906 $arraykeysfieldtarget = array_keys($fieldstarget);
908 foreach ($fieldstarget as $key => $label) {
909 $isrequired = preg_match(
'/\*$/', $label);
910 if (!empty($isrequired)) {
911 $newlabel = substr($label, 0, -1);
912 $fieldstarget_tmp[$key] = array(
"label" => $newlabel,
"required" =>
true);
914 $fieldstarget_tmp[$key] = array(
"label" => $label,
"required" =>
false);
916 if (!empty($array_match_database_to_file[$key])) {
917 $fieldstarget_tmp[$key][
"imported"] =
true;
918 $fieldstarget_tmp[$key][
"position"] = (int) $array_match_database_to_file[$key] - 1;
920 while (!empty($array_match_database_to_file[$keytoswap])) {
921 if ($position + 1 > $array_match_database_to_file[$keytoswap]) {
922 $keytoswapwith = $array_match_database_to_file[$keytoswap] - 1;
923 $tmp = [$keytoswap => $fieldstarget_tmp[$keytoswap]];
924 unset($fieldstarget_tmp[$keytoswap]);
925 $fieldstarget_tmp =
arrayInsert($fieldstarget_tmp, $keytoswapwith, $tmp);
926 $keytoswapwith = $arraykeysfieldtarget[$array_match_database_to_file[$keytoswap] - 1];
927 $tmp = $fieldstarget_tmp[$keytoswapwith];
928 unset($fieldstarget_tmp[$keytoswapwith]);
929 $fieldstarget_tmp[$keytoswapwith] = $tmp;
930 $keytoswap = $keytoswapwith;
936 $fieldstarget_tmp[$key][
"imported"] =
false;
940 $fieldstarget = $fieldstarget_tmp;
949 $param =
'&format='.$format.
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport);
950 if ($excludefirstline) {
951 $param .=
'&excludefirstline='.urlencode($excludefirstline);
954 $param .=
'&endatlinenb='.urlencode($endatlinenb);
957 $param .=
'&separator='.urlencode($separator);
960 $param .=
'&enclosure='.urlencode($enclosure);
963 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
969 print
'<div class="underbanner clearboth"></div>';
970 print
'<div class="fichecenter">';
972 print
'<table class="centpercent border tableforfield">';
975 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
977 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
979 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
980 $titleofmodule = $langs->trans(
"ProductOrService");
982 print $titleofmodule;
986 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
988 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
989 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
990 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
991 print $objimport->array_import_label[0];
999 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
1001 print
'<div class="underbanner clearboth"></div>';
1002 print
'<div class="fichecenter">';
1003 print
'<table width="100%" class="border tableforfield">';
1006 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
1007 print
'<td class="nowraponall">';
1008 $text = $objmodelimport->getDriverDescForKey($format);
1010 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
1014 if ($model ==
'csv') {
1015 '@phan-var-force ImportCsv $obj';
1016 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
1018 print
'<form method="POST">';
1019 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1020 print
'<input type="hidden" value="'.$step.
'" name="step">';
1021 print
'<input type="hidden" value="'.$format.
'" name="format">';
1022 print
'<input type="hidden" value="'.$excludefirstline.
'" name="excludefirstline">';
1023 print
'<input type="hidden" value="'.$endatlinenb.
'" name="endatlinenb">';
1024 print
'<input type="hidden" value="'.$datatoimport.
'" name="datatoimport">';
1025 print
'<input type="hidden" value="'.$filetoimport.
'" name="filetoimport">';
1026 print $langs->trans(
"Separator").
' : ';
1027 print
'<input type="text" class="width25 center" name="separator" value="'.dol_escape_htmltag($separator).
'"/>';
1028 print
' '.$langs->trans(
"Enclosure").
' : ';
1029 print
'<input type="text" class="width25 center" name="enclosure" value="'.dol_escape_htmltag($enclosure).
'"/> ';
1030 print
'<input name="update" type="submit" value="'.$langs->trans(
'Update').
'" class="button smallpaddingimp" />';
1036 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
1038 $modulepart =
'import';
1039 $relativepath =
GETPOST(
'filetoimport');
1040 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
1041 print
img_mime($file,
'',
'pictofixedwidth');
1042 print $filetoimport;
1043 print
img_picto($langs->trans(
"Download"),
'download',
'class="paddingleft opacitymedium"');
1056 print
'<!-- List of source fields -->'.
"\n";
1057 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1058 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1059 print
'<input type="hidden" name="action" value="select_model">';
1060 print
'<input type="hidden" name="step" value="4">';
1061 print
'<input type="hidden" name="format" value="'.$format.
'">';
1062 print
'<input type="hidden" name="datatoimport" value="'.$datatoimport.
'">';
1063 print
'<input type="hidden" name="filetoimport" value="'.$filetoimport.
'">';
1064 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1065 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1066 print
'<input type="hidden" name="separator" value="'.dol_escape_htmltag($separator).
'">';
1067 print
'<input type="hidden" name="enclosure" value="'.dol_escape_htmltag($enclosure).
'">';
1070 print
'<div class="marginbottomonly">';
1071 print
'<span class="opacitymedium">';
1072 $s = $langs->trans(
"SelectImportFieldsSource",
'{s1}');
1073 $s = str_replace(
'{s1}',
img_picto(
'',
'grip_title',
'', 0, 0, 0,
'',
'', 0), $s);
1076 $htmlother->select_import_model((
string) $importmodelid,
'importmodelid', $datatoimport, 1, $user->id);
1077 print
'<input type="submit" class="button smallpaddingimp reposition" value="'.$langs->trans(
"Select").
'">';
1082 print
'<div class="div-table-responsive-no-min">';
1083 print
'<table class="noborder centpercent">';
1084 print
'<tr class="liste_titre">';
1085 print
'<td>'.$langs->trans(
"FieldsInSourceFile").
'</td>';
1086 print
'<td>'.$langs->trans(
"FieldsInTargetDatabase").
'</td>';
1091 print
'<tr valign="top"><td width="50%" class="nopaddingleftimp">';
1093 $fieldsplaced = array();
1094 $valforsourcefieldnb = array();
1095 $listofkeys = array();
1096 foreach ($array_match_file_to_database as $key => $val) {
1097 $listofkeys[$key] = 1;
1100 print
"\n<!-- Box left container -->\n";
1101 print
'<div id="left" class="connectedSortable">'.
"\n";
1106 foreach ($fieldssource as $key => $val) {
1107 show_elem($fieldssource, $key, (
string) $key);
1108 $listofkeys[$key] = 1;
1109 $fieldsplaced[$key] = 1;
1110 $valforsourcefieldnb[$lefti] = $key;
1120 print
"<!-- End box left container -->\n";
1123 print
'</td><td width="50%" class="nopaddingrightimp">';
1127 $optionsall = array();
1128 foreach ($fieldstarget as $code => $line) {
1129 $tmparray = explode(
'|', $line[
"label"]);
1131 foreach ($tmparray as $tmpkey => $tmpval) {
1132 $labeltoshow .= ($labeltoshow ?
' '.$langs->trans(
'or').
' ' :
'').$langs->transnoentities($tmpval);
1137 $optionsall[$code] = array(
1138 'labelkey' => $line[
'label'],
1139 'labelkeyarray' => $tmparray,
1140 'label' => $labeltoshow,
1141 'required' => (empty($line[
"required"]) ? 0 : 1),
1142 'position' => (!empty($line[
'position']) ? $line[
'position'] : 0),
1150 $mandatoryfieldshavesource =
true;
1163 $modetoautofillmapping =
'session';
1164 if ($initialloadofstep4) {
1165 $modetoautofillmapping =
'guess';
1169 print
'<table class="nobordernopadding centpercent tableimport">';
1170 foreach ($fieldssource as $code => $line) {
1175 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
1177 $entity = (!empty($objimport->array_import_entities[0][$code]) ? $objimport->array_import_entities[0][$code] : $objimport->array_import_icon[0]);
1179 $entityicon = !empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity;
1180 $entitylang = !empty($entitytolang[$entity]) ? $entitytolang[$entity] : $objimport->array_import_label[0];
1182 print
'<td class="nowraponall hideonsmartphone" style="font-weight: normal">=> </td>';
1183 print
'<td class="nowraponall" style="font-weight: normal">';
1185 $selectforline =
'';
1186 $selectforline .=
'<select id="selectorderimport_'.($i + 1).
'" class="targetselectchange minwidth300" name="select_'.($i + 1).
'">';
1187 $selectforline .=
'<option value="-1"> </option>';
1190 $codeselectedarray = array();
1191 foreach ($optionsall as $tmpcode => $tmpval) {
1193 if (!empty($tmpval[
'picto'])) {
1194 $label .=
img_picto(
'', $tmpval[
'picto'],
'class="pictofixedwidth"');
1196 $label .= $tmpval[
'required'] ?
'<strong>' :
'';
1197 $label .= $tmpval[
'label'];
1198 $label .= $tmpval[
'required'] ?
'*</strong>' :
'';
1200 $tablealias = preg_replace(
'/(\..*)$/i',
'', $tmpcode);
1201 $tablename = !empty($objimport->array_import_tables[0][$tablealias]) ? $objimport->array_import_tables[0][$tablealias] :
"";
1205 $filecolumn = ($i + 1);
1207 if (empty($objimport->array_import_convertvalue[0][$tmpcode])) {
1210 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromref') {
1211 $htmltext .= $langs->trans(
"DataComeFromIdFoundFromRef", $langs->transnoentitiesnoconv($entitylang)).
'<br>';
1213 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromcodeid') {
1214 $htmltext .= $langs->trans(
"DataComeFromIdFoundFromCodeId", $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$tmpcode][
'dict'])).
'<br>';
1218 $example = !empty($objimport->array_import_examplevalues[0][$tmpcode]) ? $objimport->array_import_examplevalues[0][$tmpcode] :
"";
1220 if (empty($objimport->array_import_convertvalue[0][$tmpcode])) {
1222 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.str_replace(
'"',
'', $example).
'</b><br>';
1225 if ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromref') {
1226 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.$langs->transnoentitiesnoconv(
"ExampleAnyRefFoundIntoElement", $entitylang).($example ?
' ('.$langs->transnoentitiesnoconv(
"Example").
': '.str_replace(
'"',
'', $example).
')' :
'').
'</b><br>';
1227 } elseif ($objimport->array_import_convertvalue[0][$tmpcode][
'rule'] ==
'fetchidfromcodeid') {
1228 $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>';
1229 } elseif ($example) {
1230 $htmltext .= $langs->trans(
"SourceExample").
': <b>'.str_replace(
'"',
'', $example).
'</b><br>';
1234 if (!empty($objimport->array_import_regex[0][$tmpcode])) {
1235 $htmltext .= $langs->trans(
"FormatControlRule").
': <b>'.str_replace(
'"',
'', $objimport->array_import_regex[0][$tmpcode]).
'</b><br>';
1239 $htmltext .= $langs->trans(
"InformationOnTargetTables").
': <b>'.$tablename.
"->".preg_replace(
'/^.*\./',
'', $tmpcode).
"</b>";
1241 $labelhtml = $label.
' '.$form->textwithpicto(
'', $htmltext, 1,
'help',
'', 1);
1244 $selectforline .=
'<option value="'.$tmpcode.
'"';
1245 if ($modetoautofillmapping ==
'orderoftargets') {
1248 $selectforline .=
' selected';
1250 } elseif ($modetoautofillmapping ==
'guess') {
1254 if (preg_match(
'/^(.+)\((.+\..+)\)$/', $line[
'example1'], $regs)) {
1255 $tmpstring1 = $regs[1];
1256 $tmpstring2 = $regs[2];
1258 $tmpstring1 = $line[
'example1'];
1266 foreach ($tmpval[
'labelkeyarray'] as $tmpval2) {
1267 $labeltarget = $langs->transnoentities($tmpval2);
1269 if ($tmpstring1 && ($tmpstring1 == $tmpcode || $tmpstring1 == strtolower($labeltarget)
1270 || $tmpstring1 == strtolower(
dol_string_unaccent($labeltarget)) || $tmpstring1 == strtolower($tmpval2))) {
1271 if (empty($codeselectedarray[$code])) {
1272 $selectforline .=
' selected';
1273 $codeselectedarray[$code] = 1;
1276 } elseif ($tmpstring2 && ($tmpstring2 == $tmpcode || $tmpstring2 == strtolower($labeltarget)
1277 || $tmpstring2 == strtolower(
dol_string_unaccent($labeltarget)) || $tmpstring2 == strtolower($tmpval2))) {
1278 if (empty($codeselectedarray[$code])) {
1279 $selectforline .=
' selected';
1280 $codeselectedarray[$code] = 1;
1285 } elseif ($modetoautofillmapping ==
'session' && !empty($_SESSION[
'dol_array_match_file_to_database_select'])) {
1286 $tmpselectioninsession =
dolExplodeIntoArray($_SESSION[
'dol_array_match_file_to_database_select'],
',',
'=');
1288 if (!empty($tmpselectioninsession[(
string) ($i + 1)]) && $tmpselectioninsession[(
string) ($i + 1)] == $tmpcode) {
1289 $selectforline .=
' selected';
1291 $selectforline .=
' data-debug="'.$tmpcode.
'-'.$code.
'-'.$j.
'-'.(!empty($tmpselectioninsession[(
string) ($i + 1)]) ? $tmpselectioninsession[(string) ($i + 1)] :
"").
'"';
1293 $selectforline .=
' data-html="'.dol_escape_htmltag($labelhtml).
'"';
1294 $selectforline .=
'>';
1295 $selectforline .= $label;
1296 $selectforline .=
'</options>';
1299 $selectforline .=
'</select>';
1300 $selectforline .=
ajax_combobox(
'selectorderimport_'.($i + 1));
1302 print $selectforline;
1307 print
'<td class="nowraponall" style="font-weight:normal; text-align:right">';
1310 $htmltext =
'<b><u>'.$langs->trans(
"FieldSource").
'</u></b><br>';
1312 $htmltext .= $langs->trans(
"DataComeFromFileFieldNb", $filecolumntoshow).
'<br>';
1314 print $form->textwithpicto(
'', $htmltext);
1325 print
'<tr class="liste_titre"><td colspan="2">'.$langs->trans(
"Note").
'</td></tr>';
1326 print
'<tr><td colspan="2"><div id="div-mandatory-target-fields-not-mapped"></div></td></tr>';
1332 if (!empty($conf->use_javascript_ajax)) {
1333 print
'<script type="text/javascript">'.
"\n";
1334 print
'var previousselectedvalueimport = "0";'.
"\n";
1335 print
'var previousselectedlabelimport = "0";'.
"\n";
1336 print
'var arrayofselectedvalues = [];'.
"\n";
1337 print
'var arrayoftargetfields = [];'.
"\n";
1338 print
'var arrayoftargetmandatoryfields = [];'.
"\n";
1342 foreach ($fieldstarget as $key => $val) {
1343 print
"arrayoftargetfields[".$tmpi.
"] = '".
dol_escape_js($langs->trans($val[
'label'])).
"'; ";
1344 if ($val[
'required']) {
1345 print
"arrayoftargetmandatoryfields[".$tmpi.
"] = '".
dol_escape_js($key).
"'; ";
1351 print
'$(document).ready(function () {'.
"\n";
1353 print
'setOptionsToDisabled();'.
"\n";
1354 print
'saveSelection();'.
"\n";
1356 print
'$(".targetselectchange").focus(function(){'.
"\n";
1357 print
' previousselectedvalueimport = $(this).val();'.
"\n";
1358 print
' previousselectedlabelimport = $(this).children("option:selected").text();'.
"\n";
1359 print
' console.log("previousselectedvalueimport="+previousselectedvalueimport)'.
"\n";
1366 print
'function setOptionsToDisabled() {'.
"\n";
1367 print
' console.log("Remove the disabled flag everywhere");'.
"\n";
1368 print
' $("select.targetselectchange").not($( this )).find(\'option\').prop("disabled", false);'.
"\n";
1369 print
' arrayofselectedvalues = [];'.
"\n";
1371 print
' $("select.targetselectchange").each(function(){'.
"\n";
1372 print
' id = $(this).attr(\'id\')'.
"\n";
1373 print
' value = $(this).val()'.
"\n";
1374 print
' console.log("a selected value has been found for component "+id+" = "+value);'.
"\n";
1375 print
' arrayofselectedvalues.push(value);'.
"\n";
1378 print
' console.log("List of all selected values arrayofselectedvalues");'.
"\n";
1379 print
' console.log(arrayofselectedvalues);'.
"\n";
1380 print
' console.log("Set the option to disabled for every entry that is currently selected somewhere else (so into arrayofselectedvalues)");'.
"\n";
1382 print
' $.each(arrayofselectedvalues, function(key, value) {'.
"\n";
1383 print
' if (value != -1) {'.
"\n";
1384 print
' console.log("Process key="+key+" value="+value+" to disable.");'.
"\n";
1385 print
' $("select.targetselectchange").find(\'option[value="\'+value+\'"]:not(:selected)\').prop("disabled", true);'.
"\n";
1391 print
'function saveSelection() {'.
"\n";
1393 print
' arrayselectedfields = [];'.
"\n";
1394 print
' arrayselectedfields.push(0);'.
"\n";
1396 print
' $.each( arrayofselectedvalues, function( key, value ) {'.
"\n";
1397 print
' if (value != -1) {'.
"\n";
1398 print
' arrayselectedfields.push(value);'.
"\n";
1399 print
' } else {'.
"\n";
1400 print
' arrayselectedfields.push(0);'.
"\n";
1404 print
" $.ajax({\n";
1405 print
" type: 'POST',\n";
1406 print
" dataType: 'json',\n";
1407 print
" url: '".dol_escape_js($_SERVER[
"PHP_SELF"]).
"?action=saveselectorder&token=".
newToken().
"',\n";
1408 print
" data: 'selectorder='+arrayselectedfields.toString(),\n";
1409 print
" success: function(){\n";
1410 print
" console.log('The selected fields have been saved into '+arrayselectedfields.toString());\n";
1415 print
' console.log("arrayselectedfields");';
1416 print
' console.log(arrayselectedfields);';
1417 print
' console.log("arrayoftargetmandatoryfields");';
1418 print
' console.log(arrayoftargetmandatoryfields);';
1419 print
" listtoshow = '';";
1420 print
" nbelement = arrayoftargetmandatoryfields.length
1421 for (let i = 0; i < nbelement; i++) {
1422 if (arrayoftargetmandatoryfields[i] && ! arrayselectedfields.includes(arrayoftargetmandatoryfields[i])) {
1423 console.log(arrayoftargetmandatoryfields[i]+' not mapped');
1424 listtoshow = listtoshow + (listtoshow ? ', ' : '') + '<b>' + arrayoftargetfields[i] + '*</b>';
1427 console.log(listtoshow);
1429 listtoshow = '".dol_escape_js(
img_warning($langs->trans(
"MandatoryTargetFieldsNotMapped")).
' '.$langs->trans(
"MandatoryTargetFieldsNotMapped")).
": ' + listtoshow;
1430 $('#div-mandatory-target-fields-not-mapped').html(listtoshow);
1432 $('#div-mandatory-target-fields-not-mapped').html('<span class=\"opacitymedium\">".
dol_escape_js($langs->trans(
"AllTargetMandatoryFieldsAreMapped")).
"</span>');
1439 print
'$(".targetselectchange").change(function(){'.
"\n";
1440 print
' setOptionsToDisabled();'.
"\n";
1442 print
' if(previousselectedlabelimport != "" && previousselectedvalueimport != -1) {'.
"\n";
1443 print
' let valuetochange = $(this).val(); '.
"\n";
1444 print
' $(".boxtdunused").each(function(){'.
"\n";
1445 print
' if ($(this).text().includes(valuetochange)){'.
"\n";
1446 print
' arraychild = $(this)[0].childNodes'.
"\n";
1447 print
' arraytexttomodify = arraychild[0].textContent.split(" ")'.
"\n";
1448 print
' arraytexttomodify[1] = previousselectedvalueimport '.
"\n";
1449 print
' textmodified = arraytexttomodify.join(" ") '.
"\n";
1450 print
' arraychild[0].textContent = textmodified'.
"\n";
1451 print
' arraychild[1].innerHTML = previousselectedlabelimport'.
"\n";
1455 print
' $(this).blur()'.
"\n";
1457 print
' saveSelection()'.
"\n";
1461 print
'</script>'.
"\n";
1467 print
'<div class="tabsAction">';
1469 if (count($array_match_file_to_database)) {
1470 if ($mandatoryfieldshavesource) {
1471 print
'<a class="butAction saveorderselect" href="import.php?step=5'.$param.
'&filetoimport='.urlencode($filetoimport).
'">'.$langs->trans(
"NextStep").
'</a>';
1473 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"SomeMandatoryFieldHaveNoSource")).
'">'.$langs->trans(
"NextStep").
'</a>';
1481 if (count($array_match_file_to_database)) {
1483 print
'<!-- Area to add new import profile -->'.
"\n";
1484 print
'<div class="marginbottomonly"><span class="opacitymedium">'.$langs->trans(
"SaveImportModel").
'</span></div>';
1486 print
'<form class="nocellnopadd" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1487 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1488 print
'<input type="hidden" name="action" value="add_import_model">';
1489 print
'<input type="hidden" name="step" value="'.$step.
'">';
1490 print
'<input type="hidden" name="format" value="'.$format.
'">';
1491 print
'<input type="hidden" name="datatoimport" value="'.$datatoimport.
'">';
1492 print
'<input type="hidden" name="filetoimport" value="'.$filetoimport.
'">';
1493 print
'<input type="hidden" name="hexa" value="'.$hexa.
'">';
1494 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1495 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1496 print
'<input type="hidden" name="page_y" value="">';
1497 print
'<input type="hidden" value="'.dol_escape_htmltag($separator).
'" name="separator">';
1498 print
'<input type="hidden" value="'.dol_escape_htmltag($enclosure).
'" name="enclosure">';
1500 print
'<div class="div-table-responsive-no-min">';
1501 print
'<table summary="selectofimportprofil" class="noborder centpercent">';
1502 print
'<tr class="liste_titre">';
1503 print
'<td>'.$langs->trans(
"ImportModelName").
'</td>';
1504 print
'<td>'.$langs->trans(
"Visibility").
'</td>';
1508 $nameofimportprofile = str_replace(
' ',
'-', $langs->trans(
"ImportProfile").
' '.$titleofmodule.
' '.
dol_print_date(
dol_now(
'gmt'),
'dayxcard'));
1510 $nameofimportprofile = $import_name;
1513 print
'<tr class="oddeven">';
1514 print
'<td><input name="import_name" class="minwidth300" value="'.$nameofimportprofile.
'"></td>';
1516 $arrayvisibility = array(
'private' => $langs->trans(
"Private"),
'all' => $langs->trans(
"Everybody"));
1517 print $form->selectarray(
'visibility', $arrayvisibility,
'private');
1519 print
'<td class="right">';
1520 print
'<input type="submit" class="button smallpaddingimp reposition" value="'.$langs->trans(
"SaveImportProfile").
'">';
1524 $sql =
"SELECT rowid, label, fk_user, entity";
1525 $sql .=
" FROM ".MAIN_DB_PREFIX.
"import_model";
1526 $sql .=
" WHERE type = '".$db->escape($datatoimport).
"'";
1528 $sql .=
" AND fk_user IN (0, ".((int) $user->id).
")";
1530 $sql .=
" ORDER BY rowid";
1532 $resql = $db->query($sql);
1534 $num = $db->num_rows($resql);
1536 $tmpuser =
new User($db);
1540 $obj = $db->fetch_object($resql);
1542 print
'<tr class="oddeven"><td>';
1545 print
'<td class="tdoverflowmax150">';
1546 if (empty($obj->fk_user)) {
1547 print $langs->trans(
"Everybody");
1549 $tmpuser->fetch($obj->fk_user);
1550 print $tmpuser->getNomUrl(-1);
1553 print
'<td class="right">';
1554 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?step='.$step.$param.
'&action=deleteprof&token='.
newToken().
'&id='.$obj->rowid.
'&filetoimport='.urlencode($filetoimport).
'">';
1572if ($step == 5 && $datatoimport) {
1573 $max_execution_time_for_importexport =
getDolGlobalInt(
'IMPORT_MAX_EXECUTION_TIME', 300);
1574 $max_time = @ini_get(
"max_execution_time");
1575 if ($max_time && $max_time < $max_execution_time_for_importexport) {
1576 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.");
1577 @ini_set(
"max_execution_time", $max_execution_time_for_importexport);
1581 $list = $objmodelimport->listOfAvailableImportFormat($db);
1584 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
1585 $file =
"import_".$model.
".modules.php";
1586 $classname =
"Import".ucfirst($model);
1587 require_once $dir.$file;
1588 $obj =
new $classname($db, $datatoimport);
1589 '@phan-var-force ModeleImports $obj';
1590 if ($model ==
'csv') {
1591 '@phan-var-force ImportCsv $obj';
1592 $obj->separator = $separator_used;
1593 $obj->enclosure = $enclosure;
1597 $fieldssource = array();
1598 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport);
1602 $arrayrecord = $obj->import_read_record();
1605 foreach ($arrayrecord as $key => $val) {
1606 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 24);
1609 $obj->import_close_file();
1612 $nboflines = $obj->import_get_nb_of_lines($conf->import->dir_temp.
'/'.$filetoimport);
1614 $param =
'&leftmenu=import&format='.urlencode($format).
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport).
'&nboflines='.((int) $nboflines).
'&separator='.urlencode($separator).
'&enclosure='.urlencode($enclosure);
1616 if ($excludefirstline) {
1617 $param .=
'&excludefirstline='.urlencode($excludefirstline);
1620 $param .=
'&endatlinenb='.urlencode($endatlinenb);
1622 if (!empty($updatekeys)) {
1623 $param .=
'&updatekeys[]='.implode(
'&updatekeys[]=', $updatekeys);
1626 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
1631 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?'.$param2.
'" method="POST">';
1632 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1633 print
'<input type="hidden" name="step" value="5">';
1634 print
'<input type="hidden" name="action" value="launchsimu">';
1638 print
'<div class="underbanner clearboth"></div>';
1639 print
'<div class="fichecenter">';
1641 print
'<table width="100%" class="border tableforfield">';
1644 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
1646 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
1648 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
1649 $titleofmodule = $langs->trans(
"ProductOrService");
1651 print $titleofmodule;
1655 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
1657 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
1658 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
1659 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
1660 print $objimport->array_import_label[0];
1668 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
1670 print
'<div class="underbanner clearboth"></div>';
1671 print
'<div class="fichecenter">';
1672 print
'<table width="100%" class="border tableforfield">';
1675 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
1676 print
'<td class="nowraponall">';
1677 $text = $objmodelimport->getDriverDescForKey($format);
1679 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
1683 if ($model ==
'csv') {
1684 '@phan-var-force ImportCsv $obj';
1685 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
1688 print
' '.$langs->trans(
"Enclosure").
' : '.
dol_escape_htmltag($enclosure);
1693 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
1695 $modulepart =
'import';
1696 $relativepath =
GETPOST(
'filetoimport');
1697 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">';
1698 print
img_mime($file,
'',
'pictofixedwidth');
1699 print $filetoimport;
1700 print
img_picto($langs->trans(
"Download"),
'download',
'class="paddingleft opacitymedium"');
1706 print $langs->trans(
"NbOfSourceLines");
1713 print $langs->trans(
"ImportFromToLine");
1715 if ($action ==
'launchsimu') {
1716 print
'<input type="number" class="maxwidth50 right" name="excludefirstlinebis" disabled="disabled" value="'.$excludefirstline.
'">';
1717 print
'<input type="hidden" name="excludefirstline" value="'.$excludefirstline.
'">';
1719 print
'<input type="number" class="maxwidth50 right" name="excludefirstline" value="'.$excludefirstline.
'">';
1720 print $form->textwithpicto(
"", $langs->trans(
"SetThisValueTo2ToExcludeFirstLine"));
1723 if ($action ==
'launchsimu') {
1724 print
'<input type="text" class="maxwidth50" name="endatlinenbbis" disabled="disabled" value="'.$endatlinenb.
'">';
1725 print
'<input type="hidden" name="endatlinenb" value="'.$endatlinenb.
'">';
1727 print
'<input type="text" class="maxwidth50" name="endatlinenb" value="'.$endatlinenb.
'">';
1728 print $form->textwithpicto(
"", $langs->trans(
"KeepEmptyToGoToEndOfFile"));
1730 if ($action ==
'launchsimu') {
1731 print
' <a href="'.$_SERVER[
"PHP_SELF"].
'?step=5'.$param.
'">'.$langs->trans(
"Modify").
'</a>';
1733 if ($excludefirstline == 2) {
1734 print $form->textwithpicto(
"", $langs->trans(
"WarningFirstImportedLine", $excludefirstline), 1,
'warning',
"warningexcludefirstline");
1736 $( document ).ready(function() {
1737 $("input[name=\'excludefirstline\']").on("change",function(){
1738 if($(this).val() <= 1){
1739 $(".warningexcludefirstline").hide();
1741 $(".warningexcludefirstline").show();
1751 print $form->textwithpicto($langs->trans(
"KeysToUseForUpdates"), $langs->trans(
"SelectPrimaryColumnsForUpdateAttempt"));
1753 if ($action ==
'launchsimu') {
1754 if (count($updatekeys)) {
1755 print $form->multiselectarray(
'updatekeysbis', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0,
'', 1,
'80%',
'disabled');
1757 print
'<span class="opacitymedium">'.$langs->trans(
"NoUpdateAttempt").
'</span> -';
1759 foreach ($updatekeys as $val) {
1760 print
'<input type="hidden" name="updatekeys[]" value="'.$val.
'">';
1762 print
' <a href="'.$_SERVER[
"PHP_SELF"].
'?step=5'.$param.
'">'.$langs->trans(
"Modify").
'</a>';
1764 if (is_array($objimport->array_import_updatekeys[0]) && count($objimport->array_import_updatekeys[0])) {
1765 print $form->multiselectarray(
'updatekeys', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0,
'', 1,
'80%');
1768 print
'<span class="opacitymedium">'.$langs->trans(
"UpdateNotYetSupportedForThisImport").
'</span>';
1781 print
load_fiche_titre($langs->trans(
"InformationOnTargetTables"),
'',
'file-import');
1783 print
'<div class="underbanner clearboth"></div>';
1784 print
'<div class="fichecenter">';
1786 print
'<table class="centpercent border tableforfield">';
1789 print
'<tr><td class="titlefieldcreate">';
1790 print $langs->trans(
"TablesTarget");
1792 $listtables = array();
1793 $sort_array_match_file_to_database = $array_match_file_to_database;
1794 foreach ($array_match_file_to_database as $code => $label) {
1796 if ($code > count($fieldssource)) {
1800 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
1801 $listtables[$alias] = $objimport->array_import_tables[0][$alias];
1803 if (count($listtables)) {
1806 foreach ($listtables as $val) {
1825 print $langs->trans(
"Error");
1831 print $langs->trans(
"FieldsTarget").
'</td><td class="small">';
1832 $listfields = array();
1835 $sort_array_match_file_to_database = $array_match_file_to_database;
1836 ksort($sort_array_match_file_to_database);
1838 foreach ($sort_array_match_file_to_database as $code => $label) {
1841 if ($code > count($fieldssource)) {
1845 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
1846 $listfields[$i] =
'<span class="nowrap">'.$langs->trans(
"Column").
' '.
num2Alpha((
int) $code - 1).
' -> '.$label.
'</span>';
1848 print count($listfields) ? (implode(
', ', $listfields)) : $langs->trans(
"Error");
1857 if ($action !=
'launchsimu') {
1859 print
'<br><span class="opacitymedium">';
1860 print $langs->trans(
"NowClickToTestTheImport", $langs->transnoentitiesnoconv(
"RunSimulateImportFile")).
'</span><br>';
1864 print
'<div class="center">';
1865 if ($user->hasRight(
'import',
'run')) {
1866 print
'<input type="submit" class="butAction" value="'.$langs->trans(
"RunSimulateImportFile").
'">';
1868 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunSimulateImportFile").
'</a>';
1873 $arrayoferrors = array();
1874 $arrayofwarnings = array();
1888 $pathfile = $conf->import->dir_temp.
'/'.$filetoimport;
1889 $result = $obj->import_open_file($pathfile);
1891 global $tablewithentity_cache;
1892 $tablewithentity_cache = array();
1897 while (($sourcelinenb < $nboflines) && !$endoffile) {
1901 $arrayrecord = $obj->import_read_record();
1902 if ($arrayrecord ===
false) {
1903 $arrayofwarnings[$sourcelinenb][0] = array(
'lib' => $langs->trans(
'ErrorFileLinesReachEOF', $nboflines, $sourcelinenb),
'type' =>
'EOF_RECORD_ON_SEVERAL_LINES');
1907 if ($excludefirstline && ($sourcelinenb < $excludefirstline)) {
1910 if ($endatlinenb && ($sourcelinenb > $endatlinenb)) {
1914 $parameters = array(
1916 'datatoimport' => $datatoimport,
1918 'arrayrecord' => $arrayrecord,
1919 'array_match_file_to_database' => $array_match_file_to_database,
1920 'objimport' => $objimport,
1921 'fieldssource' => $fieldssource,
1922 'importid' => $importid,
1923 'updatekeys' => $updatekeys,
1924 'arrayoferrors' => &$arrayoferrors,
1925 'arrayofwarnings' => &$arrayofwarnings,
1929 $reshook = $hookmanager->executeHooks(
'ImportInsert', $parameters);
1931 $arrayoferrors[$sourcelinenb][] = [
1932 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
1936 if (empty($reshook)) {
1938 $result = $obj->import_insert($arrayrecord, $array_match_file_to_database, $objimport, count($fieldssource), $importid, $updatekeys);
1940 if (count($obj->errors)) {
1941 $arrayoferrors[$sourcelinenb] = $obj->errors;
1943 if (count($obj->warnings)) {
1944 $arrayofwarnings[$sourcelinenb] = $obj->warnings;
1946 if (!count($obj->errors) && !count($obj->warnings)) {
1951 $reshook = $hookmanager->executeHooks(
'AfterImportInsert', $parameters);
1953 $arrayoferrors[$sourcelinenb][] = [
1954 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
1959 $obj->import_close_file();
1961 print $langs->trans(
"ErrorFailedToOpenFile", $pathfile);
1968 if (!empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0])) {
1970 foreach ($objimport->array_import_run_sql_after[0] as $sqlafterimport) {
1972 $resqlafterimport = $db->query($sqlafterimport);
1973 if (!$resqlafterimport) {
1974 $arrayoferrors[
'none'][] = array(
'lib' => $langs->trans(
"Error running final request: ".$sqlafterimport));
1983 if (!count($arrayoferrors) && !count($arrayofwarnings)) {
1985 print
'<div class="info">';
1986 print
'<div class=""><b>'.$langs->trans(
"ResultOfSimulationNoError").
'</b></div>';
1987 print $langs->trans(
"NbInsertSim", empty($obj->nbinsert) ? 0 : $obj->nbinsert).
'<br>';
1988 print $langs->trans(
"NbUpdateSim", empty($obj->nbupdate) ? 0 : $obj->nbupdate).
'<br>';
1993 print
'<div class="warning">';
1994 print $langs->trans(
"NbOfLinesOK", $nbok).
'...<br>';
2001 if (count($arrayoferrors)) {
2002 print
img_error().
' <b>'.$langs->trans(
"ErrorsOnXLines", count($arrayoferrors)).
'</b><br>';
2003 print
'<table width="100%" class="border"><tr><td>';
2004 foreach ($arrayoferrors as $key => $val) {
2006 if ($nboferrors > $maxnboferrors) {
2007 print $langs->trans(
"TooMuchErrors", (count($arrayoferrors) - $nboferrors)).
"<br>";
2011 foreach ($val as $i => $err) {
2012 print
' > '.dol_escape_htmltag($err[
'lib']).
'<br>';
2015 print
'</td></tr></table>';
2021 if (count($arrayofwarnings)) {
2022 print
img_warning().
' <b>'.$langs->trans(
"WarningsOnXLines", count($arrayofwarnings)).
'</b><br>';
2023 print
'<table width="100%" class="border"><tr><td>';
2024 foreach ($arrayofwarnings as $key => $val) {
2026 if ($nbofwarnings > $maxnbofwarnings) {
2027 print $langs->trans(
"TooMuchWarnings", (count($arrayofwarnings) - $nbofwarnings)).
"<br>";
2031 foreach ($val as $i => $err) {
2032 print
' > '.dol_escape_htmltag($err[
'lib']).
'<br>';
2035 print
'</td></tr></table>';
2042 print
'<div class="center">';
2043 print
'<span class="opacitymedium">'.$langs->trans(
"NowClickToRunTheImport", $langs->transnoentitiesnoconv(
"RunImportFile")).
'</span><br>';
2052 print
'<div class="center">';
2053 if ($user->hasRight(
'import',
'run')) {
2054 if (empty($nboferrors)) {
2055 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/imports/import.php?leftmenu=import&step=6&importid='.$importid.$param.
'">'.$langs->trans(
"RunImportFile").
'</a>';
2059 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"CorrectErrorBeforeRunningImport")).
'">'.$langs->trans(
"RunImportFile").
'</a>';
2062 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunSimulateImportFile").
'</a>';
2064 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions")).
'">'.$langs->trans(
"RunImportFile").
'</a>';
2074if ($step == 6 && $datatoimport) {
2075 $max_execution_time_for_importexport =
getDolGlobalInt(
'IMPORT_MAX_EXECUTION_TIME', 300);
2076 $max_time = @ini_get(
"max_execution_time");
2077 if ($max_time && $max_time < $max_execution_time_for_importexport) {
2078 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.");
2079 @ini_set(
"max_execution_time", $max_execution_time_for_importexport);
2083 $list = $objmodelimport->listOfAvailableImportFormat($db);
2084 $importid =
GETPOST(
"importid",
'alphanohtml');
2088 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
2089 $file =
"import_".$model.
".modules.php";
2090 $classname =
"Import".ucfirst($model);
2091 require_once $dir.$file;
2092 $obj =
new $classname($db, $datatoimport);
2093 '@phan-var-force ModeleImports $obj';
2094 if ($model ==
'csv') {
2095 '@phan-var-force ImportCsv $obj';
2096 $obj->separator = $separator_used;
2097 $obj->enclosure = $enclosure;
2101 $fieldssource = array();
2102 $result = $obj->import_open_file($conf->import->dir_temp.
'/'.$filetoimport);
2105 $arrayrecord = $obj->import_read_record();
2108 foreach ($arrayrecord as $key => $val) {
2109 $fieldssource[$i][
'example1'] =
dol_trunc($val[
'val'], 24);
2112 $obj->import_close_file();
2117 $param =
'&format='.$format.
'&datatoimport='.urlencode($datatoimport).
'&filetoimport='.urlencode($filetoimport).
'&nboflines='.((int) $nboflines);
2118 if ($excludefirstline) {
2119 $param .=
'&excludefirstline='.urlencode($excludefirstline);
2122 $param .=
'&endatlinenb='.urlencode($endatlinenb);
2125 $param .=
'&separator='.urlencode($separator);
2128 $param .=
'&enclosure='.urlencode($enclosure);
2131 llxHeader(
'', $langs->trans(
"NewImport"), $help_url);
2137 print
'<div class="underbanner clearboth"></div>';
2138 print
'<div class="fichecenter">';
2140 print
'<table width="100%" class="border">';
2143 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Module").
'</td>';
2145 $titleofmodule = $objimport->array_import_module[0][
'module']->getName();
2147 if (in_array($objimport->array_import_code[0], array(
'produit_supplierprices',
'produit_multiprice',
'produit_languages'))) {
2148 $titleofmodule = $langs->trans(
"ProductOrService");
2150 print $titleofmodule;
2154 print
'<tr><td>'.$langs->trans(
"DatasetToImport").
'</td>';
2156 $entity = preg_replace(
'/:.*$/',
'', $objimport->array_import_icon[0]);
2157 $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
2158 print
img_object($objimport->array_import_module[0][
'module']->getName(), $entityicon).
' ';
2159 print $objimport->array_import_label[0];
2167 print
load_fiche_titre($langs->trans(
"InformationOnSourceFile"),
'',
'file-export');
2169 print
'<div class="underbanner clearboth"></div>';
2170 print
'<div class="fichecenter">';
2171 print
'<table width="100%" class="border tableforfield">';
2174 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"SourceFileFormat").
'</td>';
2175 print
'<td class="nowraponall">';
2176 $text = $objmodelimport->getDriverDescForKey($format);
2178 print $form->textwithpicto($objmodelimport->getDriverLabelForKey($format), $text);
2182 if ($model ==
'csv') {
2183 '@phan-var-force ImportCsv $obj';
2184 print
'<tr><td>'.$langs->trans(
"CsvOptions").
'</td>';
2186 print $langs->trans(
"Separator").
' : ';
2187 print htmlentities($separator);
2188 print
' '.$langs->trans(
"Enclosure").
' : ';
2189 print htmlentities($enclosure);
2194 print
'<tr><td>'.$langs->trans(
"FileToImport").
'</td>';
2196 $modulepart =
'import';
2197 $relativepath =
GETPOST(
'filetoimport');
2198 print
'<a data-ajax="false" href="'.DOL_URL_ROOT.
'/document.php?modulepart='.$modulepart.
'&file='.urlencode($relativepath).
'&step=4'.$param.
'" target="_blank" rel="noopener noreferrer">';
2199 print
img_mime($file,
'',
'pictofixedwidth');
2200 print $filetoimport;
2206 print $langs->trans(
"NbOfSourceLines");
2213 print $langs->trans(
"ImportFromLine");
2215 print
'<input type="text" size="4" name="excludefirstline" disabled="disabled" value="'.$excludefirstline.
'">';
2220 print $langs->trans(
"EndAtLineNb");
2222 print
'<input type="text" size="4" name="endatlinenb" disabled="disabled" value="'.$endatlinenb.
'">';
2230 print
'<b>'.$langs->trans(
"InformationOnTargetTables").
'</b>';
2231 print
'<div class="underbanner clearboth"></div>';
2232 print
'<div class="fichecenter">';
2233 print
'<table class="border centpercent">';
2236 print
'<tr><td width="25%">';
2237 print $langs->trans(
"TablesTarget");
2239 $listtables = array();
2240 foreach ($array_match_file_to_database as $code => $label) {
2242 if ($code > count($fieldssource)) {
2246 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
2247 $listtables[$alias] = $objimport->array_import_tables[0][$alias];
2249 if (count($listtables)) {
2251 foreach ($listtables as $val) {
2270 print $langs->trans(
"Error");
2276 print $langs->trans(
"FieldsTarget").
'</td><td>';
2277 $listfields = array();
2279 $sort_array_match_file_to_database = $array_match_file_to_database;
2280 ksort($sort_array_match_file_to_database);
2282 foreach ($sort_array_match_file_to_database as $code => $label) {
2285 if ($code > count($fieldssource)) {
2289 $alias = preg_replace(
'/(\..*)$/i',
'', $label);
2290 $listfields[$i] = $langs->trans(
"Field").
' '.$code.
'->'.$label;
2292 print count($listfields) ? (implode(
', ', $listfields)) : $langs->trans(
"Error");
2299 $arrayoferrors = array();
2300 $arrayofwarnings = array();
2301 $maxnboferrors = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_ERRORS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_ERRORS;
2302 $maxnbofwarnings = !
getDolGlobalString(
'IMPORT_MAX_NB_OF_WARNINGS') ? 50 : $conf->global->IMPORT_MAX_NB_OF_WARNINGS;
2314 $pathfile = $conf->import->dir_temp.
'/'.$filetoimport;
2315 $result = $obj->import_open_file($pathfile);
2317 global $tablewithentity_cache;
2318 $tablewithentity_cache = array();
2322 while ($sourcelinenb < $nboflines && !$endoffile) {
2324 $arrayrecord = $obj->import_read_record();
2325 if ($arrayrecord ===
false) {
2326 $arrayofwarnings[$sourcelinenb][0] = array(
'lib' => $langs->trans(
'ErrorFileLinesReachEOF', $nboflines, $sourcelinenb),
'type' =>
'EOF_RECORD_ON_SEVERAL_LINES');
2330 if ($excludefirstline && ($sourcelinenb < $excludefirstline)) {
2333 if ($endatlinenb && ($sourcelinenb > $endatlinenb)) {
2337 $parameters = array(
2339 'datatoimport' => $datatoimport,
2341 'arrayrecord' => $arrayrecord,
2342 'array_match_file_to_database' => $array_match_file_to_database,
2343 'objimport' => $objimport,
2344 'fieldssource' => $fieldssource,
2345 'importid' => $importid,
2346 'updatekeys' => $updatekeys,
2347 'arrayoferrors' => &$arrayoferrors,
2348 'arrayofwarnings' => &$arrayofwarnings,
2352 $reshook = $hookmanager->executeHooks(
'ImportInsert', $parameters);
2354 $arrayoferrors[$sourcelinenb][] = [
2355 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
2359 if (empty($reshook)) {
2361 $result = $obj->import_insert($arrayrecord, $array_match_file_to_database, $objimport, count($fieldssource), $importid, $updatekeys);
2363 if (count($obj->errors)) {
2364 $arrayoferrors[$sourcelinenb] = $obj->errors;
2366 if (count($obj->warnings)) {
2367 $arrayofwarnings[$sourcelinenb] = $obj->warnings;
2370 if (!count($obj->errors) && !count($obj->warnings)) {
2375 $reshook = $hookmanager->executeHooks(
'AfterImportInsert', $parameters);
2377 $arrayoferrors[$sourcelinenb][] = [
2378 'lib' => implode(
"<br>", array_merge([$hookmanager->error], $hookmanager->errors))
2383 $obj->import_close_file();
2385 print $langs->trans(
"ErrorFailedToOpenFile", $pathfile);
2388 if (count($arrayoferrors) > 0) {
2395 if (!empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0])) {
2397 foreach ($objimport->array_import_run_sql_after[0] as $sqlafterimport) {
2399 $resqlafterimport = $db->query($sqlafterimport);
2400 if (!$resqlafterimport) {
2401 $arrayoferrors[
'none'][] = array(
'lib' => $langs->trans(
"Error running final request: ".$sqlafterimport));
2419 print
'<div class="info">';
2420 print $langs->trans(
"NbOfLinesImported", $nbok).
'</b><br>';
2421 print $langs->trans(
"NbInsert", empty($obj->nbinsert) ? 0 : $obj->nbinsert).
'<br>';
2422 print $langs->trans(
"NbUpdate", empty($obj->nbupdate) ? 0 : $obj->nbupdate).
'<br>';
2424 print
'<div class="center">';
2425 print $langs->trans(
"FileWasImported", $importid).
'<br>';
2426 print
'<span class="opacitymedium">'.$langs->trans(
"YouCanUseImportIdToFindRecord", $importid).
'</span><br>';
2449 global $conf, $langs;
2453 if ($key ==
'none') {
2455 print
"\n\n<!-- Box_no-key start-->\n";
2456 print
'<div class="box boximport" style="padding:0;">'.
"\n";
2457 print
'<table summary="boxtable_no-key" class="centpercent nobordernopadding">'.
"\n";
2459 print
"\n\n<!-- Box ".$pos.
" start -->\n";
2460 print
'<div class="box boximport" style="padding: 0;" id="boxto_'.$pos.
'">'.
"\n";
2462 print
'<table summary="boxtable'.$pos.
'" class="nobordernopadding centpercent tableimport">'.
"\n";
2465 if (($pos && $pos > count($fieldssource)) && (!isset($fieldssource[$pos][
"imported"]))) {
2475 } elseif ($key ==
'none') {
2476 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
2477 print
'<td class="nocellnopadd" width="16" style="font-weight: normal">';
2480 print
'<td style="font-weight: normal">';
2486 print
'<tr style="height:'.$height.
'" class="trimport oddevenimport">';
2487 print
'<td class="nocellnopadd" width="16" style="font-weight: normal">';
2490 print
img_picto($langs->trans(
"Column").
' '.
num2Alpha($pos - 1),
'file',
'class="pictofixedwidth marginleftonly"');
2492 if (isset($fieldssource[$pos][
'imported']) && $fieldssource[$pos][
'imported'] ==
false) {
2493 print
'<td class="nowraponall boxtdunused" style="font-weight: normal">';
2495 print
'<td class="nowraponall tdoverflowmax500" style="font-weight: normal">';
2497 print $langs->trans(
"Column").
' '.
num2Alpha($pos - 1).
' (#'.$pos.
')';
2498 if (empty($fieldssource[$pos][
'example1'])) {
2499 $example = $fieldssource[$pos][
'label'];
2501 $example = $fieldssource[$pos][
'example1'];
2505 $example = mb_convert_encoding($example,
'UTF-8',
'ISO-8859-1');
2509 print
'<i class="opacitymedium">'.dol_escape_htmltag($example).
'</i>';
2518 print
"<!-- Box end -->\n\n";
2531 $i = count($fieldssource) + 1;
2534 foreach ($listofkey as $key => $val) {
2535 $maxkey = max($maxkey, $key);
2538 while ($i <= $maxkey) {
2539 if (empty($listofkey[$i])) {
2561 if ($position == count($array)) {
2562 $ret = $array + $insertArray;
2565 foreach ($array as $key => $value) {
2566 if ($position == $i++) {
2567 $ret += $insertArray;
2570 $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.
dol_now($mode='gmt')
Return date for now.
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_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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_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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
utf8_check($str)
Check if a string is in UTF8.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
import_prepare_head($param, $maxstep=0)
Function to return list of tabs for import pages.
show_elem($fieldssource, $pos, $key)
Function to put the movable box of a source field.
getnewkey(&$fieldssource, &$listofkey)
Return not used field number.
arrayInsert($array, $position, $insertArray)
Return array with element inserted in it at position $position.
getMaxFileSizeArray()
Return the max allowed for file upload.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.