361 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
364 global $langs, $conf, $user;
365 global $thirdparty_static;
366 global $tablewithentity_cache;
370 $this->errors = array();
371 $this->warnings = array();
378 $array_match_database_to_file = array_flip($array_match_file_to_database);
379 $sort_array_match_file_to_database = $array_match_file_to_database;
380 ksort($sort_array_match_file_to_database);
384 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[1][
'val']))) {
386 $this->warnings[$warning][
'lib'] = $langs->trans(
'EmptyLine');
387 $this->warnings[$warning][
'type'] =
'EMPTY';
390 $last_insert_id_array = array();
394 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
397 $listfields = array();
398 $listvalues = array();
400 $errorforthistable = 0;
403 if (!isset($tablewithentity_cache[$tablename])) {
404 dol_syslog(
"Check if table " . $tablename .
" has an entity field");
405 $resql = $this->db->DDLDescTable($tablename,
'entity');
407 $obj = $this->db->fetch_object($resql);
409 $tablewithentity_cache[$tablename] = 1;
411 $tablewithentity_cache[$tablename] = 0;
421 $arrayfield = array();
422 foreach ($sort_array_match_file_to_database as $key => $val) {
423 $arrayfield[$val] = ($key);
430 foreach ($sort_array_match_file_to_database as $key => $val) {
431 $fieldalias = preg_replace(
'/\..*$/i',
'', $val);
432 $fieldname = preg_replace(
'/^.*\./i',
'', $val);
434 if ($alias != $fieldalias) {
438 if ($key <= $maxfields) {
441 if ($arrayrecord[($key)][
'type'] > 0) {
442 $newval = $arrayrecord[($key)][
'val'];
451 if (preg_match(
'/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval ==
'')) {
452 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMissingMandatoryValue',
num2Alpha($key - 1));
453 $this->errors[$error][
'type'] =
'NOTNULL';
454 $errorforthistable++;
459 if (!empty($objimport->array_import_convertvalue[0][$val])) {
461 if ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeid'
462 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromref'
463 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel'
467 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
470 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
473 if ($isidorref ==
'ref') {
474 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
475 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
476 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
477 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval] !=
'') {
478 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval];
481 if (empty($resultload)) {
482 dol_print_error(
'',
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
485 $classinstance =
new $class($this->db);
486 if ($class ==
'CGenericDic') {
487 $classinstance->element = $objimport->array_import_convertvalue[0][$val][
'element'];
488 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val][
'table_element'];
492 $param_array = array(
'', $newval);
493 if ($class ==
'AccountingAccount') {
506 $param_array = array(
'', $newval, 0, $arrayrecord[0][
'val']);
509 $result = call_user_func_array(array($classinstance, $method), $param_array);
512 if (!($classinstance->id !=
'') && $result == -2) {
513 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMultipleRecordFoundFromRef', $newval);
514 $this->errors[$error][
'type'] =
'FOREIGNKEY';
515 $errorforthistable++;
520 if (!($classinstance->id !=
'') && $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel') {
521 $param_array = array(
'',
'', $newval);
522 call_user_func_array(array($classinstance, $method), $param_array);
524 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval] = $classinstance->id;
527 if ($classinstance->id !=
'') {
528 $newval = $classinstance->id;
529 } elseif (! $error) {
530 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
531 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
532 } elseif (!empty($objimport->array_import_convertvalue[0][$val][
'element'])) {
533 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldRefNotIn', $key, $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'element']));
535 $this->errors[$error][
'lib'] =
'ErrorBadDefinitionOfImportProfile';
537 $this->errors[$error][
'type'] =
'FOREIGNKEY';
538 $errorforthistable++;
543 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeandlabel') {
545 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
548 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
550 if ($isidorref ==
'ref') {
551 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
552 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
553 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
554 $codefromfield = $objimport->array_import_convertvalue[0][$val][
'codefromfield'];
555 $code = $arrayrecord[$arrayfield[$codefromfield]][
'val'];
556 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval] !=
'') {
557 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval];
560 if (empty($resultload)) {
561 dol_print_error(
'',
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method .
', code=' . $code);
564 $classinstance =
new $class($this->db);
566 $param_array = array(
'', $newval, $code);
567 call_user_func_array(array($classinstance, $method), $param_array);
568 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval] = $classinstance->id;
569 if ($classinstance->id > 0) {
570 $newval = $classinstance->id;
572 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
573 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
575 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
577 $this->errors[$error][
'type'] =
'FOREIGNKEY';
578 $errorforthistable++;
583 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'zeroifnull') {
584 if (empty($newval)) {
587 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchscalefromcodeunits') {
588 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
589 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
590 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
591 $units = $objimport->array_import_convertvalue[0][$val][
'units'];
592 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval] !=
'') {
593 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval];
596 if (empty($resultload)) {
597 dol_print_error(
'',
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method .
', units=' . $units);
600 $classinstance =
new $class($this->db);
602 call_user_func_array(array($classinstance, $method), array(
'',
'', $newval, $units));
603 $scaleorid = (($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
604 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval] = $scaleorid;
606 if ($classinstance->id > 0) {
607 $newval = $scaleorid ? $scaleorid : 0;
609 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
610 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
612 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
614 $this->errors[$error][
'type'] =
'FOREIGNKEY';
615 $errorforthistable++;
619 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomercodeifauto') {
620 if (strtolower($newval) ==
'auto') {
621 $this->thirdpartyobject->get_codeclient(0, 0);
622 $newval = $this->thirdpartyobject->code_client;
625 if (empty($newval)) {
626 $arrayrecord[($key)][
'type'] = -1;
628 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsuppliercodeifauto') {
629 if (strtolower($newval) ==
'auto') {
630 $this->thirdpartyobject->get_codefournisseur(0, 1);
631 $newval = $this->thirdpartyobject->code_fournisseur;
634 if (empty($newval)) {
635 $arrayrecord[($key)][
'type'] = -1;
637 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomeraccountancycodeifauto') {
638 if (strtolower($newval) ==
'auto') {
639 $this->thirdpartyobject->get_codecompta(
'customer');
640 $newval = $this->thirdpartyobject->code_compta;
643 if (empty($newval)) {
644 $arrayrecord[($key)][
'type'] = -1;
646 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsupplieraccountancycodeifauto') {
647 if (strtolower($newval) ==
'auto') {
648 $this->thirdpartyobject->get_codecompta(
'supplier');
649 $newval = $this->thirdpartyobject->code_compta_fournisseur;
650 if (empty($newval)) {
651 $arrayrecord[($key)][
'type'] = -1;
655 if (empty($newval)) {
656 $arrayrecord[($key)][
'type'] = -1;
658 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getrefifauto') {
659 if (strtolower($newval) ==
'auto') {
662 $classModForNumber = $objimport->array_import_convertvalue[0][$val][
'class'];
663 $pathModForNumber = $objimport->array_import_convertvalue[0][$val][
'path'];
665 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
666 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
667 $modForNumber =
new $classModForNumber;
671 if (!empty($objimport->array_import_convertvalue[0][$val][
'classobject'])) {
672 $pathForObject = $objimport->array_import_convertvalue[0][$val][
'pathobject'];
673 require_once DOL_DOCUMENT_ROOT.$pathForObject;
674 $tmpclassobject = $objimport->array_import_convertvalue[0][$val][
'classobject'];
675 $tmpobject =
new $tmpclassobject($this->db);
676 foreach ($arrayfield as $tmpkey => $tmpval) {
677 if (in_array($tmpkey, array(
't.date',
'c.date_commande'))) {
678 $tmpobject->date =
dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]][
'val'], 1);
683 $defaultref = $modForNumber->getNextValue(
null, $tmpobject);
685 if (is_numeric($defaultref) && $defaultref <= 0) {
688 $newval = $defaultref;
690 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'compute') {
691 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
692 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
693 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
695 if (empty($resultload)) {
696 dol_print_error(
'',
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
699 $classinstance =
new $class($this->db);
700 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
701 if (empty($classinstance->error) && empty($classinstance->errors)) {
704 $this->errors[$error][
'type'] =
'CLASSERROR';
705 $this->errors[$error][
'lib'] = implode(
707 array_merge([$classinstance->error], $classinstance->errors)
709 $errorforthistable++;
712 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'numeric') {
714 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'accountingaccount') {
715 if (empty($conf->global->ACCOUNTING_MANAGE_ZERO)) {
716 $newval = rtrim(trim($newval),
"0");
718 $newval = trim($newval);
726 if (!empty($objimport->array_import_regex[0][$val]) && ($newval !=
'')) {
729 if (preg_match(
'/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
732 $filter = !empty($reg[3]) ? substr($reg[3], 1) :
'';
734 $cachekey = $field .
'@' . $table;
735 if (!empty($filter)) {
736 $cachekey .=
':' . $filter;
740 if (!is_array($this->cachefieldtable[$cachekey])) {
741 $sql =
"SELECT " . $field .
" as aliasfield FROM " . $table;
742 if (!empty($filter)) {
743 $sql .=
' WHERE ' . $filter;
746 $resql = $this->db->query($sql);
748 $num = $this->db->num_rows($resql);
751 $obj = $this->db->fetch_object($resql);
753 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
763 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
764 $tableforerror = $table;
765 if (!empty($filter)) {
766 $tableforerror .=
':' . $filter;
768 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorFieldValueNotIn', $key, $newval, $field, $tableforerror);
769 $this->errors[$error][
'type'] =
'FOREIGNKEY';
770 $errorforthistable++;
773 } elseif (!preg_match(
'/' . $objimport->array_import_regex[0][$val] .
'/i', $newval)) {
776 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorWrongValueForField', $key, $newval, $objimport->array_import_regex[0][$val]);
777 $this->errors[$error][
'type'] =
'REGEX';
778 $errorforthistable++;
786 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorHtmlInjectionForField', $key,
dol_trunc($newval, 100));
787 $this->errors[$error][
'type'] =
'HTMLINJECTION';
788 $errorforthistable++;
797 if (isModEnabled(
"socialnetworks") && strpos($fieldname,
"socialnetworks") !==
false) {
798 if (!in_array(
"socialnetworks", $listfields)) {
799 $listfields[] =
"socialnetworks";
800 $socialkey = array_search(
"socialnetworks", $listfields);
801 $listvalues[$socialkey] =
'';
803 if (!empty($newval) && $arrayrecord[($key)][
'type'] > 0) {
804 $socialkey = array_search(
"socialnetworks", $listfields);
805 $socialnetwork = explode(
"_", $fieldname)[1];
806 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] ==
"null") {
807 $json =
new stdClass();
808 $json->$socialnetwork = $newval;
809 $listvalues[$socialkey] = json_encode($json);
811 $jsondata = $listvalues[$socialkey];
812 $json = json_decode($jsondata);
813 $json->$socialnetwork = $newval;
814 $listvalues[$socialkey] = json_encode($json);
818 $listfields[] = $fieldname;
821 if (empty($newval) && $arrayrecord[($key)][
'type'] < 0) {
822 $listvalues[] = ($newval ==
'0' ? $newval :
"null");
823 } elseif (empty($newval) && $arrayrecord[($key)][
'type'] == 0) {
824 $listvalues[] =
"''";
826 $listvalues[] =
"'".$this->db->escape($newval).
"'";
836 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
838 foreach ($objimport->array_import_fieldshidden[0] as $key => $val) {
839 if (!preg_match(
'/^'.preg_quote($alias,
'/').
'\./', $key)) {
842 if ($val ==
'user->id') {
843 $listfields[] = preg_replace(
'/^' . preg_quote($alias,
'/') .
'\./',
'', $key);
844 $listvalues[] = ((int) $user->id);
845 } elseif (preg_match(
'/^lastrowid-/', $val)) {
846 $tmp = explode(
'-', $val);
847 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
848 $keyfield = preg_replace(
'/^' . preg_quote($alias,
'/') .
'\./',
'', $key);
849 $listfields[] = $keyfield;
850 $listvalues[] = $lastinsertid;
852 } elseif (preg_match(
'/^const-/', $val)) {
853 $tmp = explode(
'-', $val, 2);
854 $listfields[] = preg_replace(
'/^' . preg_quote($alias,
'/') .
'\./',
'', $key);
855 $listvalues[] =
"'".$this->db->escape($tmp[1]).
"'";
856 } elseif (preg_match(
'/^rule-/', $val)) {
858 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
859 if ($objimport->array_import_convertvalue[0][$fieldname][
'rule'] ==
'compute') {
860 $file = (empty($objimport->array_import_convertvalue[0][$fieldname][
'classfile']) ? $objimport->array_import_convertvalue[0][$fieldname][
'file'] : $objimport->array_import_convertvalue[0][$fieldname][
'classfile']);
861 $class = $objimport->array_import_convertvalue[0][$fieldname][
'class'];
862 $method = $objimport->array_import_convertvalue[0][$fieldname][
'method'];
864 if (empty($resultload)) {
865 dol_print_error(
'',
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
868 $classinstance =
new $class($this->db);
869 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
870 $fieldArr = explode(
'.', $fieldname);
871 if (count($fieldArr) > 0) {
872 $fieldname = $fieldArr[1];
874 $listfields[] = $fieldname;
875 $listvalues[] = $res;
877 $this->errors[$error][
'type'] =
'CLASSERROR';
878 $this->errors[$error][
'lib'] = implode(
880 array_merge([$classinstance->error], $classinstance->errors)
882 $errorforthistable++;
887 $this->errors[$error][
'lib'] =
'Bad value of profile setup ' . $val .
' for array_import_fieldshidden';
888 $this->errors[$error][
'type'] =
'Import profile setup';
897 if (!$errorforthistable) {
899 if (!empty($listfields)) {
903 $is_table_category_link =
false;
905 if (strpos($tablename,
'_categorie_') !==
false) {
906 $is_table_category_link =
true;
910 if (!empty($updatekeys)) {
913 if (empty($lastinsertid)) {
914 $sqlSelect =
"SELECT ".$fname.
" FROM " . $tablename;
916 $data = array_combine($listfields, $listvalues);
920 foreach ($updatekeys as $key) {
921 $col = $objimport->array_import_updatekeys[0][$key];
922 $key = preg_replace(
'/^.*\./i',
'', $key);
923 if (isModEnabled(
"socialnetworks") && strpos($key,
"socialnetworks") !==
false) {
924 $tmp = explode(
"_", $key);
926 $socialnetwork = $tmp[1];
927 $jsondata = $data[$key];
928 $json = json_decode($jsondata);
929 $stringtosearch = json_encode($socialnetwork).
':'.json_encode($json->$socialnetwork);
932 $where[] = $key.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
933 $filters[] = $col.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
936 $where[] = $key.
' = '.$data[$key];
937 $filters[] = $col.
' = '.$data[$key];
940 if (!empty($tablewithentity_cache[$tablename])) {
944 $sqlSelect .=
" WHERE " . implode(
' AND ', $where);
946 $resql = $this->db->query($sqlSelect);
948 $num_rows = $this->db->num_rows($resql);
949 if ($num_rows == 1) {
950 $res = $this->db->fetch_object($resql);
951 $lastinsertid = $res->rowid;
952 if ($is_table_category_link) $lastinsertid =
'linktable';
953 $last_insert_id_array[$tablename] = $lastinsertid;
954 } elseif ($num_rows > 1) {
955 $this->errors[$error][
'lib'] = $langs->trans(
'MultipleRecordFoundWithTheseFilters', implode(
', ', $filters));
956 $this->errors[$error][
'type'] =
'SQL';
963 $this->errors[$error][
'lib'] = $this->db->lasterror();
964 $this->errors[$error][
'type'] =
'SQL';
973 $sqlSelect =
"SELECT rowid FROM " . $tablename;
976 if (empty($keyfield)) {
979 $sqlSelect .=
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
981 if (!empty($tablewithentity_cache[$tablename])) {
985 $resql = $this->db->query($sqlSelect);
987 $res = $this->db->fetch_object($resql);
988 if ($this->db->num_rows($resql) == 1) {
997 $this->errors[$error][
'lib'] = $this->db->lasterror();
998 $this->errors[$error][
'type'] =
'SQL';
1003 if (!empty($lastinsertid)) {
1005 if (in_array(
"socialnetworks", $listfields)) {
1006 $socialkey = array_search(
"socialnetworks", $listfields);
1007 $tmpsql = $listvalues[$socialkey];
1008 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1012 $sqlstart =
"UPDATE " . $tablename;
1014 $data = array_combine($listfields, $listvalues);
1016 foreach ($data as $key => $val) {
1017 $set[] = $key.
" = ".$val;
1019 $sqlstart .=
" SET " . implode(
', ', $set);
1021 if (empty($keyfield)) {
1022 $keyfield =
'rowid';
1024 $sqlend =
" WHERE " . $keyfield .
" = ".((int) $lastinsertid);
1026 if ($is_table_category_link) {
1027 $sqlend =
" WHERE " . implode(
' AND ', $where);
1030 if (!empty($tablewithentity_cache[$tablename])) {
1034 $sql = $sqlstart . $sqlend;
1037 $resql = $this->db->query($sql);
1043 $this->errors[$error][
'lib'] = $this->db->lasterror();
1044 $this->errors[$error][
'type'] =
'SQL';
1051 if (!$error && !$updatedone) {
1053 if (in_array(
"socialnetworks", $listfields)) {
1054 $socialkey = array_search(
"socialnetworks", $listfields);
1055 $tmpsql = $listvalues[$socialkey];
1056 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1060 $sqlstart =
"INSERT INTO " . $tablename .
"(" . implode(
", ", $listfields) .
", import_key";
1061 $sqlend =
") VALUES(" . implode(
', ', $listvalues) .
", '" . $this->db->escape($importid) .
"'";
1062 if (!empty($tablewithentity_cache[$tablename])) {
1063 $sqlstart .=
", entity";
1064 $sqlend .=
", " . $conf->entity;
1066 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
1067 $sqlstart .=
", " . $objimport->array_import_tables_creator[0][$alias];
1068 $sqlend .=
", " . $user->id;
1070 $sql = $sqlstart . $sqlend .
")";
1075 $resql = $this->db->query($sql);
1077 if (!$is_table_category_link) {
1078 $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename);
1083 $this->errors[$error][
'lib'] = $this->db->lasterror();
1084 $this->errors[$error][
'type'] =
'SQL';