316 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
319 global $langs, $conf, $user;
320 global $thirdparty_static;
321 global $tablewithentity_cache;
325 $this->errors = array();
326 $this->warnings = array();
333 $array_match_database_to_file = array_flip($array_match_file_to_database);
334 $sort_array_match_file_to_database = $array_match_file_to_database;
335 ksort($sort_array_match_file_to_database);
339 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0][
'val']))) {
341 $this->warnings[$warning][
'lib'] = $langs->trans(
'EmptyLine');
342 $this->warnings[$warning][
'type'] =
'EMPTY';
345 $last_insert_id_array = array();
349 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
352 $listfields = array();
353 $listvalues = array();
355 $errorforthistable = 0;
358 if (!isset($tablewithentity_cache[$tablename])) {
359 dol_syslog(
"Check if table ".$tablename.
" has an entity field");
360 $resql = $this->db->DDLDescTable($tablename,
'entity');
362 $obj = $this->db->fetch_object($resql);
364 $tablewithentity_cache[$tablename] = 1;
366 $tablewithentity_cache[$tablename] = 0;
376 $arrayfield = array();
377 foreach ($sort_array_match_file_to_database as $key => $val) {
378 $arrayfield[$val] = ($key - 1);
385 foreach ($sort_array_match_file_to_database as $key => $val) {
386 $fieldalias = preg_replace(
'/\..*$/i',
'', $val);
387 $fieldname = preg_replace(
'/^.*\./i',
'', $val);
389 if ($alias != $fieldalias) {
393 if ($key <= $maxfields) {
396 if ($arrayrecord[($key - 1)][
'type'] > 0) {
397 $newval = $arrayrecord[($key - 1)][
'val'];
406 if (preg_match(
'/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval ==
'')) {
407 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMissingMandatoryValue', $key);
408 $this->errors[$error][
'type'] =
'NOTNULL';
409 $errorforthistable++;
414 if (!empty($objimport->array_import_convertvalue[0][$val])) {
416 if ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeid'
417 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromref'
418 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel'
422 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
426 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
429 if ($isidorref ==
'ref') {
430 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
431 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
432 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
433 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval] !=
'') {
434 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval];
437 if (empty($resultload)) {
438 dol_print_error(
'',
'Error trying to call file='.$file.
', class='.$class.
', method='.$method);
441 $classinstance =
new $class($this->db);
442 if ($class ==
'CGenericDic') {
443 $classinstance->element = $objimport->array_import_convertvalue[0][$val][
'element'];
444 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val][
'table_element'];
448 $param_array = array(
'', $newval);
449 if ($class ==
'AccountingAccount') {
462 $param_array = array(
'', $newval, 0, $arrayrecord[0][
'val']);
465 $result = call_user_func_array(array($classinstance, $method), $param_array);
468 if (!($classinstance->id !=
'') && $result == -2) {
469 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMultipleRecordFoundFromRef', $newval);
470 $this->errors[$error][
'type'] =
'FOREIGNKEY';
471 $errorforthistable++;
476 if (!($classinstance->id !=
'') && $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel') {
477 $param_array = array(
'',
'', $newval);
478 call_user_func_array(array($classinstance, $method), $param_array);
480 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval] = $classinstance->id;
483 if ($classinstance->id !=
'') {
484 $newval = $classinstance->id;
485 } elseif (! $error) {
486 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
487 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
488 } elseif (!empty($objimport->array_import_convertvalue[0][$val][
'element'])) {
489 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldRefNotIn',
num2Alpha($key - 1), $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'element']));
491 $this->errors[$error][
'lib'] =
'ErrorBadDefinitionOfImportProfile';
493 $this->errors[$error][
'type'] =
'FOREIGNKEY';
494 $errorforthistable++;
499 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeandlabel') {
501 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
504 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
506 if ($isidorref ==
'ref') {
507 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
508 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
509 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
510 $codefromfield = $objimport->array_import_convertvalue[0][$val][
'codefromfield'];
511 $code = $arrayrecord[$arrayfield[$codefromfield]][
'val'];
512 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval] !=
'') {
513 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval];
516 if (empty($resultload)) {
517 dol_print_error(
'',
'Error trying to call file='.$file.
', class='.$class.
', method='.$method.
', code='.$code);
520 $classinstance =
new $class($this->db);
522 $param_array = array(
'', $newval, $code);
523 call_user_func_array(array($classinstance, $method), $param_array);
524 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval] = $classinstance->id;
525 if ($classinstance->id > 0) {
526 $newval = $classinstance->id;
528 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
529 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
531 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
533 $this->errors[$error][
'type'] =
'FOREIGNKEY';
534 $errorforthistable++;
539 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'zeroifnull') {
540 if (empty($newval)) {
543 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchscalefromcodeunits') {
544 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
545 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
546 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
547 $units = $objimport->array_import_convertvalue[0][$val][
'units'];
548 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval] !=
'') {
549 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval];
552 if (empty($resultload)) {
553 dol_print_error(
'',
'Error trying to call file='.$file.
', class='.$class.
', method='.$method.
', units='.$units);
556 $classinstance =
new $class($this->db);
558 call_user_func_array(array($classinstance, $method), array(
'',
'', $newval, $units));
559 $scaleorid = (($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
560 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval] = $scaleorid;
562 if ($classinstance->id > 0) {
563 $newval = $scaleorid ? $scaleorid : 0;
565 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
566 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
568 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
570 $this->errors[$error][
'type'] =
'FOREIGNKEY';
571 $errorforthistable++;
575 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomercodeifauto') {
576 if (strtolower($newval) ==
'auto') {
577 $this->thirdpartyobject->get_codeclient(0, 0);
578 $newval = $this->thirdpartyobject->code_client;
581 if (empty($newval)) {
582 $arrayrecord[($key - 1)][
'type'] = -1;
584 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsuppliercodeifauto') {
585 if (strtolower($newval) ==
'auto') {
586 $this->thirdpartyobject->get_codefournisseur(0, 1);
587 $newval = $this->thirdpartyobject->code_fournisseur;
590 if (empty($newval)) {
591 $arrayrecord[($key - 1)][
'type'] = -1;
593 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomeraccountancycodeifauto') {
594 if (strtolower($newval) ==
'auto') {
595 $this->thirdpartyobject->get_codecompta(
'customer');
596 $newval = $this->thirdpartyobject->code_compta;
599 if (empty($newval)) {
600 $arrayrecord[($key - 1)][
'type'] = -1;
602 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsupplieraccountancycodeifauto') {
603 if (strtolower($newval) ==
'auto') {
604 $this->thirdpartyobject->get_codecompta(
'supplier');
605 $newval = $this->thirdpartyobject->code_compta_fournisseur;
606 if (empty($newval)) {
607 $arrayrecord[($key - 1)][
'type'] = -1;
611 if (empty($newval)) {
612 $arrayrecord[($key - 1)][
'type'] = -1;
614 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getrefifauto') {
615 if (strtolower($newval) ==
'auto') {
618 $classModForNumber = $objimport->array_import_convertvalue[0][$val][
'class'];
619 $pathModForNumber = $objimport->array_import_convertvalue[0][$val][
'path'];
621 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
622 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
623 $modForNumber =
new $classModForNumber;
627 if (!empty($objimport->array_import_convertvalue[0][$val][
'classobject'])) {
628 $pathForObject = $objimport->array_import_convertvalue[0][$val][
'pathobject'];
629 require_once DOL_DOCUMENT_ROOT.$pathForObject;
630 $tmpclassobject = $objimport->array_import_convertvalue[0][$val][
'classobject'];
631 $tmpobject =
new $tmpclassobject($this->db);
632 foreach ($arrayfield as $tmpkey => $tmpval) {
633 if (in_array($tmpkey, array(
't.date',
'c.date_commande'))) {
634 $tmpobject->date =
dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]][
'val'], 1);
639 $defaultref = $modForNumber->getNextValue(
null, $tmpobject);
641 if (is_numeric($defaultref) && $defaultref <= 0) {
644 $newval = $defaultref;
646 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'compute') {
647 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
648 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
649 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
651 if (empty($resultload)) {
652 dol_print_error(
'',
'Error trying to call file='.$file.
', class='.$class.
', method='.$method);
655 $classinstance =
new $class($this->db);
656 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, ($key - 1)));
657 if (empty($classinstance->error) && empty($classinstance->errors)) {
660 $this->errors[$error][
'type'] =
'CLASSERROR';
661 $this->errors[$error][
'lib'] = implode(
663 array_merge([$classinstance->error], $classinstance->errors)
665 $errorforthistable++;
668 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'numeric') {
670 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'accountingaccount') {
671 if (empty($conf->global->ACCOUNTING_MANAGE_ZERO)) {
672 $newval = rtrim(trim($newval),
"0");
674 $newval = trim($newval);
682 if (!empty($objimport->array_import_regex[0][$val]) && ($newval !=
'')) {
685 if (preg_match(
'/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
688 $filter = !empty($reg[3]) ?substr($reg[3], 1) :
'';
690 $cachekey = $field.
'@'.$table;
691 if (!empty($filter)) {
692 $cachekey .=
':'.$filter;
696 if (!is_array($this->cachefieldtable[$cachekey])) {
697 $sql =
"SELECT ".$field.
" as aliasfield FROM ".$table;
698 if (!empty($filter)) {
699 $sql .=
' WHERE '.$filter;
702 $resql = $this->db->query($sql);
704 $num = $this->db->num_rows($resql);
707 $obj = $this->db->fetch_object($resql);
709 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
719 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
720 $tableforerror = $table;
721 if (!empty($filter)) {
722 $tableforerror .=
':'.$filter;
724 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval, $field, $tableforerror);
725 $this->errors[$error][
'type'] =
'FOREIGNKEY';
726 $errorforthistable++;
729 } elseif (!preg_match(
'/'.$objimport->array_import_regex[0][$val].
'/i', $newval)) {
732 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorWrongValueForField',
num2Alpha($key - 1), $newval, $objimport->array_import_regex[0][$val]);
733 $this->errors[$error][
'type'] =
'REGEX';
734 $errorforthistable++;
742 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorHtmlInjectionForField',
num2Alpha($key - 1),
dol_trunc($newval, 100));
743 $this->errors[$error][
'type'] =
'HTMLINJECTION';
744 $errorforthistable++;
753 if (isModEnabled(
"socialnetworks") && strpos($fieldname,
"socialnetworks") !==
false) {
754 if (!in_array(
"socialnetworks", $listfields)) {
755 $listfields[] =
"socialnetworks";
756 $socialkey = array_search(
"socialnetworks", $listfields);
757 $listvalues[$socialkey] =
'';
760 if (!empty($newval) && $arrayrecord[($key - 1)][
'type'] > 0) {
761 $socialkey = array_search(
"socialnetworks", $listfields);
763 $socialnetwork = explode(
"_", $fieldname)[1];
764 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] ==
"null") {
765 $json =
new stdClass();
766 $json->$socialnetwork = $newval;
767 $listvalues[$socialkey] = json_encode($json);
769 $jsondata = $listvalues[$socialkey];
770 $json = json_decode($jsondata);
771 $json->$socialnetwork = $newval;
772 $listvalues[$socialkey] = json_encode($json);
776 $listfields[] = $fieldname;
778 if (empty($newval) && $arrayrecord[($key - 1)][
'type'] < 0) {
779 $listvalues[] = ($newval ==
'0' ? $newval :
"null");
780 } elseif (empty($newval) && $arrayrecord[($key - 1)][
'type'] == 0) {
781 $listvalues[] =
"''";
783 $listvalues[] =
"'".$this->db->escape($newval).
"'";
793 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
795 foreach ($objimport->array_import_fieldshidden[0] as $tmpkey => $tmpval) {
796 if (!preg_match(
'/^'.preg_quote($alias,
'/').
'\./', $tmpkey)) {
799 if ($tmpval ==
'user->id') {
800 $listfields[] = preg_replace(
'/^'.preg_quote($alias,
'/').
'\./',
'', $tmpkey);
801 $listvalues[] = ((int) $user->id);
802 } elseif (preg_match(
'/^lastrowid-/', $tmpval)) {
803 $tmp = explode(
'-', $tmpval);
804 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
805 $keyfield = preg_replace(
'/^'.preg_quote($alias,
'/').
'\./',
'', $tmpkey);
806 $listfields[] = $keyfield;
807 $listvalues[] = $lastinsertid;
809 } elseif (preg_match(
'/^const-/', $tmpval)) {
810 $tmp = explode(
'-', $tmpval, 2);
811 $listfields[] = preg_replace(
'/^'.preg_quote($alias,
'/').
'\./',
'', $tmpkey);
812 $listvalues[] =
"'".$this->db->escape($tmp[1]).
"'";
813 } elseif (preg_match(
'/^rule-/', $tmpval)) {
814 $fieldname = $tmpkey;
815 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
816 if ($objimport->array_import_convertvalue[0][$fieldname][
'rule'] ==
'compute') {
817 $file = (empty($objimport->array_import_convertvalue[0][$fieldname][
'classfile']) ? $objimport->array_import_convertvalue[0][$fieldname][
'file'] : $objimport->array_import_convertvalue[0][$fieldname][
'classfile']);
818 $class = $objimport->array_import_convertvalue[0][$fieldname][
'class'];
819 $method = $objimport->array_import_convertvalue[0][$fieldname][
'method'];
821 if (empty($resultload)) {
822 dol_print_error(
'',
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
825 $classinstance =
new $class($this->db);
826 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, ($key - 1)));
827 if (empty($classinstance->error) && empty($classinstance->errors)) {
828 $fieldArr = explode(
'.', $fieldname);
829 if (count($fieldArr) > 0) {
830 $fieldname = $fieldArr[1];
832 $listfields[] = $fieldname;
833 $listvalues[] = $res;
835 $this->errors[$error][
'type'] =
'CLASSERROR';
836 $this->errors[$error][
'lib'] = implode(
838 array_merge([$classinstance->error], $classinstance->errors)
840 $errorforthistable++;
846 $this->errors[$error][
'lib'] =
'Bad value of profile setup '.$tmpval.
' for array_import_fieldshidden';
847 $this->errors[$error][
'type'] =
'Import profile setup';
856 if (!$errorforthistable) {
858 if (!empty($listfields)) {
862 $is_table_category_link =
false;
864 if (strpos($tablename,
'_categorie_') !==
false) {
865 $is_table_category_link =
true;
869 if (!empty($updatekeys)) {
872 if (empty($lastinsertid)) {
873 $sqlSelect =
"SELECT ".$fname.
" FROM ".$tablename;
874 $data = array_combine($listfields, $listvalues);
877 foreach ($updatekeys as $key) {
878 $col = $objimport->array_import_updatekeys[0][$key];
879 $key = preg_replace(
'/^.*\./i',
'', $key);
880 if (isModEnabled(
"socialnetworks") && strpos($key,
"socialnetworks") !==
false) {
881 $tmp = explode(
"_", $key);
883 $socialnetwork = $tmp[1];
884 $jsondata = $data[$key];
885 $json = json_decode($jsondata);
886 $stringtosearch = json_encode($socialnetwork).
':'.json_encode($json->$socialnetwork);
889 $where[] = $key.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
890 $filters[] = $col.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
893 $where[] = $key.
' = '.$data[$key];
894 $filters[] = $col.
' = '.$data[$key];
897 if (!empty($tablewithentity_cache[$tablename])) {
901 $sqlSelect .=
" WHERE ".implode(
' AND ', $where);
903 $resql = $this->db->query($sqlSelect);
905 $num_rows = $this->db->num_rows($resql);
906 if ($num_rows == 1) {
907 $res = $this->db->fetch_object($resql);
908 $lastinsertid = $res->rowid;
909 if ($is_table_category_link) $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);
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';