305 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
308 global $langs, $conf, $user;
309 global $thirdparty_static;
310 global $tablewithentity_cache;
314 $this->errors = array();
315 $this->warnings = array();
322 $array_match_database_to_file = array_flip($array_match_file_to_database);
323 $sort_array_match_file_to_database = $array_match_file_to_database;
324 ksort($sort_array_match_file_to_database);
328 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0][
'val']))) {
330 $this->warnings[$warning][
'lib'] = $langs->trans(
'EmptyLine');
331 $this->warnings[$warning][
'type'] =
'EMPTY';
334 $last_insert_id_array = array();
338 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
341 $listfields = array();
342 $listvalues = array();
344 $errorforthistable = 0;
347 if (!isset($tablewithentity_cache[$tablename])) {
348 dol_syslog(
"Check if table ".$tablename.
" has an entity field");
349 $resql = $this->db->DDLDescTable($tablename,
'entity');
351 $obj = $this->db->fetch_object($resql);
353 $tablewithentity_cache[$tablename] = 1;
355 $tablewithentity_cache[$tablename] = 0;
365 $arrayfield = array();
366 foreach ($sort_array_match_file_to_database as $key => $val) {
367 $arrayfield[$val] = ($key - 1);
374 foreach ($sort_array_match_file_to_database as $key => $val) {
375 $fieldalias = preg_replace(
'/\..*$/i',
'', $val);
376 $fieldname = preg_replace(
'/^.*\./i',
'', $val);
378 if ($alias != $fieldalias) {
382 if ($key <= $maxfields) {
385 if ($arrayrecord[($key - 1)][
'type'] > 0) {
386 $newval = $arrayrecord[($key - 1)][
'val'];
395 if (preg_match(
'/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval ==
'')) {
396 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMissingMandatoryValue', $key);
397 $this->errors[$error][
'type'] =
'NOTNULL';
398 $errorforthistable++;
403 if (!empty($objimport->array_import_convertvalue[0][$val])) {
405 if ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeid'
406 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromref'
407 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel'
411 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
415 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
418 if ($isidorref ==
'ref') {
419 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
420 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
421 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
422 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval] !=
'') {
423 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval];
426 if (empty($resultload)) {
427 dol_print_error(
'',
'Error trying to call file='.$file.
', class='.$class.
', method='.$method);
430 $classinstance =
new $class($this->db);
431 if ($class ==
'CGenericDic') {
432 $classinstance->element = $objimport->array_import_convertvalue[0][$val][
'element'];
433 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val][
'table_element'];
437 $param_array = array(
'', $newval);
438 if ($class ==
'AccountingAccount') {
451 $param_array = array(
'', $newval, 0, $arrayrecord[0][
'val']);
454 $result = call_user_func_array(array($classinstance, $method), $param_array);
457 if (!($classinstance->id !=
'') && $result == -2) {
458 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMultipleRecordFoundFromRef', $newval);
459 $this->errors[$error][
'type'] =
'FOREIGNKEY';
460 $errorforthistable++;
465 if (!($classinstance->id !=
'') && $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel') {
466 $param_array = array(
'',
'', $newval);
467 call_user_func_array(array($classinstance, $method), $param_array);
469 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval] = $classinstance->id;
472 if ($classinstance->id !=
'') {
473 $newval = $classinstance->id;
474 } elseif (! $error) {
475 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
476 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
477 } elseif (!empty($objimport->array_import_convertvalue[0][$val][
'element'])) {
478 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldRefNotIn',
num2Alpha($key - 1), $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'element']));
480 $this->errors[$error][
'lib'] =
'ErrorBadDefinitionOfImportProfile';
482 $this->errors[$error][
'type'] =
'FOREIGNKEY';
483 $errorforthistable++;
488 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeandlabel') {
490 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
493 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
495 if ($isidorref ==
'ref') {
496 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
497 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
498 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
499 $codefromfield = $objimport->array_import_convertvalue[0][$val][
'codefromfield'];
500 $code = $arrayrecord[$arrayfield[$codefromfield]][
'val'];
501 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval] !=
'') {
502 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval];
505 if (empty($resultload)) {
506 dol_print_error(
'',
'Error trying to call file='.$file.
', class='.$class.
', method='.$method.
', code='.$code);
509 $classinstance =
new $class($this->db);
511 $param_array = array(
'', $newval, $code);
512 call_user_func_array(array($classinstance, $method), $param_array);
513 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval] = $classinstance->id;
514 if ($classinstance->id > 0) {
515 $newval = $classinstance->id;
517 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
518 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
520 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
522 $this->errors[$error][
'type'] =
'FOREIGNKEY';
523 $errorforthistable++;
528 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'zeroifnull') {
529 if (empty($newval)) {
532 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchscalefromcodeunits') {
533 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
534 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
535 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
536 $units = $objimport->array_import_convertvalue[0][$val][
'units'];
537 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval] !=
'') {
538 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval];
541 if (empty($resultload)) {
542 dol_print_error(
'',
'Error trying to call file='.$file.
', class='.$class.
', method='.$method.
', units='.$units);
545 $classinstance =
new $class($this->db);
547 call_user_func_array(array($classinstance, $method), array(
'',
'', $newval, $units));
548 $scaleorid = (($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
549 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval] = $scaleorid;
551 if ($classinstance->id > 0) {
552 $newval = $scaleorid ? $scaleorid : 0;
554 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
555 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
557 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
559 $this->errors[$error][
'type'] =
'FOREIGNKEY';
560 $errorforthistable++;
564 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomercodeifauto') {
565 if (strtolower($newval) ==
'auto') {
566 $this->thirdpartyobject->get_codeclient(0, 0);
567 $newval = $this->thirdpartyobject->code_client;
570 if (empty($newval)) {
571 $arrayrecord[($key - 1)][
'type'] = -1;
573 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsuppliercodeifauto') {
574 if (strtolower($newval) ==
'auto') {
575 $this->thirdpartyobject->get_codefournisseur(0, 1);
576 $newval = $this->thirdpartyobject->code_fournisseur;
579 if (empty($newval)) {
580 $arrayrecord[($key - 1)][
'type'] = -1;
582 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomeraccountancycodeifauto') {
583 if (strtolower($newval) ==
'auto') {
584 $this->thirdpartyobject->get_codecompta(
'customer');
585 $newval = $this->thirdpartyobject->code_compta;
588 if (empty($newval)) {
589 $arrayrecord[($key - 1)][
'type'] = -1;
591 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsupplieraccountancycodeifauto') {
592 if (strtolower($newval) ==
'auto') {
593 $this->thirdpartyobject->get_codecompta(
'supplier');
594 $newval = $this->thirdpartyobject->code_compta_fournisseur;
595 if (empty($newval)) {
596 $arrayrecord[($key - 1)][
'type'] = -1;
600 if (empty($newval)) {
601 $arrayrecord[($key - 1)][
'type'] = -1;
603 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getrefifauto') {
604 if (strtolower($newval) ==
'auto') {
607 $classModForNumber = $objimport->array_import_convertvalue[0][$val][
'class'];
608 $pathModForNumber = $objimport->array_import_convertvalue[0][$val][
'path'];
610 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
611 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
612 $modForNumber =
new $classModForNumber();
616 if (!empty($objimport->array_import_convertvalue[0][$val][
'classobject'])) {
617 $pathForObject = $objimport->array_import_convertvalue[0][$val][
'pathobject'];
618 require_once DOL_DOCUMENT_ROOT.$pathForObject;
619 $tmpclassobject = $objimport->array_import_convertvalue[0][$val][
'classobject'];
620 $tmpobject =
new $tmpclassobject($this->db);
621 foreach ($arrayfield as $tmpkey => $tmpval) {
622 if (in_array($tmpkey, array(
't.date',
'c.date_commande'))) {
623 $tmpobject->date =
dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]][
'val'], 1);
628 $defaultref = $modForNumber->getNextValue(
null, $tmpobject);
630 if (is_numeric($defaultref) && $defaultref <= 0) {
633 $newval = $defaultref;
635 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'compute') {
636 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
637 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
638 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
640 if (empty($resultload)) {
641 dol_print_error(
'',
'Error trying to call file='.$file.
', class='.$class.
', method='.$method);
644 $classinstance =
new $class($this->db);
645 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, ($key - 1)));
646 if (empty($classinstance->error) && empty($classinstance->errors)) {
649 $this->errors[$error][
'type'] =
'CLASSERROR';
650 $this->errors[$error][
'lib'] = implode(
652 array_merge([$classinstance->error], $classinstance->errors)
654 $errorforthistable++;
657 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'numeric') {
659 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'accountingaccount') {
661 $newval = rtrim(trim($newval),
"0");
663 $newval = trim($newval);
671 if (!empty($objimport->array_import_regex[0][$val]) && ($newval !=
'')) {
674 if (preg_match(
'/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
677 $filter = !empty($reg[3]) ? substr($reg[3], 1) :
'';
679 $cachekey = $field.
'@'.$table;
680 if (!empty($filter)) {
681 $cachekey .=
':'.$filter;
685 if (!is_array($this->cachefieldtable[$cachekey])) {
686 $sql =
"SELECT ".$field.
" as aliasfield FROM ".$table;
687 if (!empty($filter)) {
688 $sql .=
' WHERE '.$filter;
691 $resql = $this->db->query($sql);
693 $num = $this->db->num_rows($resql);
696 $obj = $this->db->fetch_object($resql);
698 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
708 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
709 $tableforerror = $table;
710 if (!empty($filter)) {
711 $tableforerror .=
':'.$filter;
713 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval, $field, $tableforerror);
714 $this->errors[$error][
'type'] =
'FOREIGNKEY';
715 $errorforthistable++;
718 } elseif (!preg_match(
'/'.$objimport->array_import_regex[0][$val].
'/i', $newval)) {
721 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorWrongValueForField',
num2Alpha($key - 1), $newval, $objimport->array_import_regex[0][$val]);
722 $this->errors[$error][
'type'] =
'REGEX';
723 $errorforthistable++;
731 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorHtmlInjectionForField',
num2Alpha($key - 1),
dol_trunc($newval, 100));
732 $this->errors[$error][
'type'] =
'HTMLINJECTION';
733 $errorforthistable++;
742 if (isModEnabled(
"socialnetworks") && strpos($fieldname,
"socialnetworks") !==
false) {
743 if (!in_array(
"socialnetworks", $listfields)) {
744 $listfields[] =
"socialnetworks";
745 $socialkey = array_search(
"socialnetworks", $listfields);
746 $listvalues[$socialkey] =
'';
749 if (!empty($newval) && $arrayrecord[($key - 1)][
'type'] > 0) {
750 $socialkey = array_search(
"socialnetworks", $listfields);
752 $socialnetwork = explode(
"_", $fieldname)[1];
753 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] ==
"null") {
755 $json->$socialnetwork = $newval;
756 $listvalues[$socialkey] = json_encode($json);
758 $jsondata = $listvalues[$socialkey];
759 $json = json_decode($jsondata);
760 $json->$socialnetwork = $newval;
761 $listvalues[$socialkey] = json_encode($json);
765 $listfields[] = $fieldname;
767 if (empty($newval) && $arrayrecord[($key - 1)][
'type'] < 0) {
768 $listvalues[] = ($newval ==
'0' ? (int) $newval :
"null");
769 } elseif (empty($newval) && $arrayrecord[($key - 1)][
'type'] == 0) {
770 $listvalues[] =
"''";
772 $listvalues[] =
"'".$this->db->escape($newval).
"'";
782 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
784 foreach ($objimport->array_import_fieldshidden[0] as $tmpkey => $tmpval) {
785 if (!preg_match(
'/^'.preg_quote($alias,
'/').
'\./', $tmpkey)) {
788 if ($tmpval ==
'user->id') {
789 $listfields[] = preg_replace(
'/^'.preg_quote($alias,
'/').
'\./',
'', $tmpkey);
790 $listvalues[] = ((int) $user->id);
791 } elseif (preg_match(
'/^lastrowid-/', $tmpval)) {
792 $tmp = explode(
'-', $tmpval);
793 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
794 $keyfield = preg_replace(
'/^'.preg_quote($alias,
'/').
'\./',
'', $tmpkey);
795 $listfields[] = $keyfield;
796 $listvalues[] = (int) $lastinsertid;
798 } elseif (preg_match(
'/^const-/', $tmpval)) {
799 $tmp = explode(
'-', $tmpval, 2);
800 $listfields[] = preg_replace(
'/^'.preg_quote($alias,
'/').
'\./',
'', $tmpkey);
801 $listvalues[] =
"'".$this->db->escape($tmp[1]).
"'";
802 } elseif (preg_match(
'/^rule-/', $tmpval)) {
803 $fieldname = $tmpkey;
804 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
805 if ($objimport->array_import_convertvalue[0][$fieldname][
'rule'] ==
'compute') {
806 $file = (empty($objimport->array_import_convertvalue[0][$fieldname][
'classfile']) ? $objimport->array_import_convertvalue[0][$fieldname][
'file'] : $objimport->array_import_convertvalue[0][$fieldname][
'classfile']);
807 $class = $objimport->array_import_convertvalue[0][$fieldname][
'class'];
808 $method = $objimport->array_import_convertvalue[0][$fieldname][
'method'];
809 $type = $objimport->array_import_convertvalue[0][$fieldname][
'type'];
811 if (empty($resultload)) {
812 dol_print_error(
'',
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
815 $classinstance =
new $class($this->db);
816 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, ($key - 1)));
817 if (empty($classinstance->error) && empty($classinstance->errors)) {
818 $fieldArr = explode(
'.', $fieldname);
819 if (count($fieldArr) > 0) {
820 $fieldname = $fieldArr[1];
824 $listfields[] = $fieldname;
825 if ($type ==
'int') {
826 $listvalues[] = (int) $res;
827 } elseif ($type ==
'double') {
828 $listvalues[] = (float) $res;
830 $listvalues[] =
"'".$this->db->escape($res).
"'";
833 $this->errors[$error][
'type'] =
'CLASSERROR';
834 $this->errors[$error][
'lib'] = implode(
836 array_merge([$classinstance->error], $classinstance->errors)
838 $errorforthistable++;
844 $this->errors[$error][
'lib'] =
'Bad value of profile setup '.$tmpval.
' for array_import_fieldshidden';
845 $this->errors[$error][
'type'] =
'Import profile setup';
854 if (!$errorforthistable) {
856 if (!empty($listfields)) {
860 $is_table_category_link =
false;
862 if (strpos($tablename,
'_categorie_') !==
false) {
863 $is_table_category_link =
true;
867 if (!empty($updatekeys)) {
870 if (empty($lastinsertid)) {
871 $sqlSelect =
"SELECT ".$fname.
" FROM ".$tablename;
872 $data = array_combine($listfields, $listvalues);
875 foreach ($updatekeys as $key) {
876 $col = $objimport->array_import_updatekeys[0][$key];
877 $key = preg_replace(
'/^.*\./i',
'', $key);
878 if (isModEnabled(
"socialnetworks") && strpos($key,
"socialnetworks") !==
false) {
879 $tmp = explode(
"_", $key);
881 $socialnetwork = $tmp[1];
882 $jsondata = $data[$key];
883 $json = json_decode($jsondata);
884 $stringtosearch = json_encode($socialnetwork).
':'.json_encode($json->$socialnetwork);
887 $where[] = $key.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
888 $filters[] = $col.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
891 $where[] = $key.
' = '.$data[$key];
892 $filters[] = $col.
' = '.$data[$key];
895 if (!empty($tablewithentity_cache[$tablename])) {
899 $sqlSelect .=
" WHERE ".implode(
' AND ', $where);
901 $resql = $this->db->query($sqlSelect);
903 $num_rows = $this->db->num_rows($resql);
904 if ($num_rows == 1) {
905 $res = $this->db->fetch_object($resql);
906 $lastinsertid = $res->rowid;
907 if ($is_table_category_link) {
908 $lastinsertid =
'linktable';
910 $last_insert_id_array[$tablename] = $lastinsertid;
911 } elseif ($num_rows > 1) {
912 $this->errors[$error][
'lib'] = $langs->trans(
'MultipleRecordFoundWithTheseFilters', implode(
', ', $filters));
913 $this->errors[$error][
'type'] =
'SQL';
920 $this->errors[$error][
'lib'] = $this->db->lasterror();
921 $this->errors[$error][
'type'] =
'SQL';
930 $sqlSelect =
"SELECT rowid FROM ".$tablename;
932 if (empty($keyfield)) {
935 $sqlSelect .=
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
937 if (!empty($tablewithentity_cache[$tablename])) {
941 $resql = $this->db->query($sqlSelect);
943 $res = $this->db->fetch_object($resql);
944 if ($this->db->num_rows($resql) == 1) {
953 $this->errors[$error][
'lib'] = $this->db->lasterror();
954 $this->errors[$error][
'type'] =
'SQL';
959 if (!empty($lastinsertid)) {
961 if (in_array(
"socialnetworks", $listfields)) {
962 $socialkey = array_search(
"socialnetworks", $listfields);
963 $tmpsql = $listvalues[$socialkey];
964 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
968 $sqlstart =
"UPDATE ".$tablename;
970 $data = array_combine($listfields, $listvalues);
972 foreach ($data as $key => $val) {
973 $set[] = $key.
" = ".$val;
975 $sqlstart .=
" SET ".implode(
', ', $set).
", import_key = '".$this->db->escape($importid).
"'";
977 if (empty($keyfield)) {
980 $sqlend =
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
982 if ($is_table_category_link) {
983 $sqlend =
" WHERE " . implode(
' AND ', $where);
986 if (!empty($tablewithentity_cache[$tablename])) {
990 $sql = $sqlstart.$sqlend;
993 $resql = $this->db->query($sql);
999 $this->errors[$error][
'lib'] = $this->db->lasterror();
1000 $this->errors[$error][
'type'] =
'SQL';
1007 if (!$error && !$updatedone) {
1009 if (in_array(
"socialnetworks", $listfields)) {
1010 $socialkey = array_search(
"socialnetworks", $listfields);
1011 $tmpsql = $listvalues[$socialkey];
1012 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1016 $sqlstart =
"INSERT INTO ".$tablename.
"(".implode(
", ", $listfields).
", import_key";
1017 $sqlend =
") VALUES(".implode(
', ', $listvalues).
", '".$this->db->escape($importid).
"'";
1018 if (!empty($tablewithentity_cache[$tablename])) {
1019 $sqlstart .=
", entity";
1020 $sqlend .=
", ".$conf->entity;
1022 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
1023 $sqlstart .=
", ".$objimport->array_import_tables_creator[0][$alias];
1024 $sqlend .=
", ".$user->id;
1026 $sql = $sqlstart.$sqlend.
")";
1031 $resql = $this->db->query($sql);
1033 if (!$is_table_category_link) {
1034 $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename);
1039 $this->errors[$error][
'lib'] = $this->db->lasterror();
1040 $this->errors[$error][
'type'] =
'SQL';