28 require_once DOL_DOCUMENT_ROOT.
'/core/modules/import/modules_import.php';
51 public $errors = array();
69 public $version =
'dolibarr';
81 public $cacheconvert = array();
83 public $cachefieldtable = array();
101 $this->separator = (
GETPOST(
'separator') ?
GETPOST(
'separator') : (empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE) ?
',' : $conf->global->IMPORT_CSV_SEPARATOR_TO_USE));
102 $this->enclosure =
'"';
106 $this->label =
'Csv';
107 $this->desc = $langs->trans(
"CSVFormatDesc", $this->separator, $this->enclosure, $this->escape);
108 $this->extension =
'csv';
109 $this->picto =
'mime/other';
110 $this->version =
'1.34';
113 $this->label_lib =
'Dolibarr';
114 $this->version_lib = DOL_VERSION;
116 $this->datatoimport = $datatoimport;
117 if (preg_match(
'/^societe_/', $datatoimport)) {
118 $this->thirpartyobject =
new Societe($this->
db);
147 $s = join($this->separator, array_map(
'cleansep', $headerlinefields));
162 $s = join($this->separator, array_map(
'cleansep', $contentlinevalues));
193 dol_syslog(get_class($this).
"::open_file file=".$file);
195 ini_set(
'auto_detect_line_endings', 1);
198 if (!$this->handle) {
199 $langs->load(
"errors");
200 $this->error = $langs->trans(
"ErrorFailToOpenFile", $file);
248 $arrayres = fgetcsv($this->handle, 100000, $this->separator, $this->enclosure, $this->escape);
251 if ($arrayres ===
false) {
257 $newarrayres = array();
258 if ($arrayres && is_array($arrayres)) {
259 foreach ($arrayres as $key => $val) {
260 if (!empty($conf->global->IMPORT_CSV_FORCE_CHARSET)) {
261 if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) ==
'utf8') {
262 $newarrayres[$key][
'val'] = $val;
263 $newarrayres[$key][
'type'] = (
dol_strlen($val) ? 1 : -1);
265 $newarrayres[$key][
'val'] = utf8_encode($val);
266 $newarrayres[$key][
'type'] = (
dol_strlen($val) ? 1 : -1);
271 $newarrayres[$key][
'val'] = $val;
272 $newarrayres[$key][
'type'] = (
dol_strlen($val) ? 1 : -1);
274 $newarrayres[$key][
'val'] = utf8_encode($val);
275 $newarrayres[$key][
'type'] = (
dol_strlen($val) ? 1 : -1);
280 $this->col = count($newarrayres);
295 fclose($this->handle);
312 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
315 global $langs, $conf, $user;
316 global $thirdparty_static;
317 global $tablewithentity_cache;
321 $this->errors = array();
322 $this->warnings = array();
329 $array_match_database_to_file = array_flip($array_match_file_to_database);
330 $sort_array_match_file_to_database = $array_match_file_to_database;
331 ksort($sort_array_match_file_to_database);
335 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0][
'val']))) {
337 $this->warnings[$warning][
'lib'] = $langs->trans(
'EmptyLine');
338 $this->warnings[$warning][
'type'] =
'EMPTY';
341 $last_insert_id_array = array();
345 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
348 $listfields = array();
349 $listvalues = array();
351 $errorforthistable = 0;
354 if (!isset($tablewithentity_cache[$tablename])) {
355 dol_syslog(
"Check if table ".$tablename.
" has an entity field");
356 $resql = $this->
db->DDLDescTable($tablename,
'entity');
358 $obj = $this->
db->fetch_object(
$resql);
360 $tablewithentity_cache[$tablename] = 1;
362 $tablewithentity_cache[$tablename] = 0;
372 $arrayfield = array();
373 foreach ($sort_array_match_file_to_database as $key => $val) {
374 $arrayfield[$val] = ($key - 1);
381 foreach ($sort_array_match_file_to_database as $key => $val) {
382 $fieldalias = preg_replace(
'/\..*$/i',
'', $val);
383 $fieldname = preg_replace(
'/^.*\./i',
'', $val);
385 if ($alias != $fieldalias) {
389 if ($key <= $maxfields) {
392 if ($arrayrecord[($key - 1)][
'type'] > 0) {
393 $newval = $arrayrecord[($key - 1)][
'val'];
402 if (preg_match(
'/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval ==
'')) {
403 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMissingMandatoryValue', $key);
404 $this->errors[$error][
'type'] =
'NOTNULL';
405 $errorforthistable++;
410 if (!empty($objimport->array_import_convertvalue[0][$val])) {
412 if ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeid'
413 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromref'
414 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel'
418 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
422 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
425 if ($isidorref ==
'ref') {
426 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
427 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
428 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
429 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval] !=
'') {
430 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval];
433 if (empty($resultload)) {
434 dol_print_error(
'',
'Error trying to call file='.$file.
', class='.$class.
', method='.$method);
437 $classinstance =
new $class($this->
db);
438 if ($class ==
'CGenericDic') {
439 $classinstance->element = $objimport->array_import_convertvalue[0][$val][
'element'];
440 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val][
'table_element'];
444 $param_array = array(
'', $newval);
445 if ($class ==
'AccountingAccount') {
458 $param_array = array(
'', $newval, 0, $arrayrecord[0][
'val']);
461 call_user_func_array(array($classinstance, $method), $param_array);
463 if (!($classinstance->id !=
'') && $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel') {
464 $param_array = array(
'',
'', $newval);
465 call_user_func_array(array($classinstance, $method), $param_array);
467 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval] = $classinstance->id;
469 if ($classinstance->id !=
'') {
470 $newval = $classinstance->id;
472 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
473 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
474 } elseif (!empty($objimport->array_import_convertvalue[0][$val][
'element'])) {
475 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldRefNotIn',
num2Alpha($key - 1), $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'element']));
477 $this->errors[$error][
'lib'] =
'ErrorBadDefinitionOfImportProfile';
479 $this->errors[$error][
'type'] =
'FOREIGNKEY';
480 $errorforthistable++;
485 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeandlabel') {
487 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
490 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
492 if ($isidorref ==
'ref') {
493 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
494 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
495 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
496 $codefromfield = $objimport->array_import_convertvalue[0][$val][
'codefromfield'];
497 $code = $arrayrecord[$arrayfield[$codefromfield]][
'val'];
498 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval] !=
'') {
499 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval];
502 if (empty($resultload)) {
503 dol_print_error(
'',
'Error trying to call file='.$file.
', class='.$class.
', method='.$method.
', code='.$code);
506 $classinstance =
new $class($this->
db);
508 $param_array = array(
'', $newval, $code);
509 call_user_func_array(array($classinstance, $method), $param_array);
510 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval] = $classinstance->id;
511 if ($classinstance->id > 0) {
512 $newval = $classinstance->id;
514 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
515 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
517 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
519 $this->errors[$error][
'type'] =
'FOREIGNKEY';
520 $errorforthistable++;
525 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'zeroifnull') {
526 if (empty($newval)) {
529 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchscalefromcodeunits') {
530 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
531 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
532 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
533 $units = $objimport->array_import_convertvalue[0][$val][
'units'];
534 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval] !=
'') {
535 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval];
538 if (empty($resultload)) {
539 dol_print_error(
'',
'Error trying to call file='.$file.
', class='.$class.
', method='.$method.
', units='.$units);
542 $classinstance =
new $class($this->
db);
544 call_user_func_array(array($classinstance, $method), array(
'',
'', $newval, $units));
545 $scaleorid = (($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
546 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval] = $scaleorid;
548 if ($classinstance->id > 0) {
549 $newval = $scaleorid ? $scaleorid : 0;
551 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
552 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
554 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
556 $this->errors[$error][
'type'] =
'FOREIGNKEY';
557 $errorforthistable++;
561 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomercodeifauto') {
562 if (strtolower($newval) ==
'auto') {
563 $this->thirpartyobject->get_codeclient(0, 0);
564 $newval = $this->thirpartyobject->code_client;
567 if (empty($newval)) {
568 $arrayrecord[($key - 1)][
'type'] = -1;
570 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsuppliercodeifauto') {
571 if (strtolower($newval) ==
'auto') {
572 $newval = $this->thirpartyobject->get_codefournisseur(0, 1);
573 $newval = $this->thirpartyobject->code_fournisseur;
576 if (empty($newval)) {
577 $arrayrecord[($key - 1)][
'type'] = -1;
579 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomeraccountancycodeifauto') {
580 if (strtolower($newval) ==
'auto') {
581 $this->thirpartyobject->get_codecompta(
'customer');
582 $newval = $this->thirpartyobject->code_compta;
585 if (empty($newval)) {
586 $arrayrecord[($key - 1)][
'type'] = -1;
588 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsupplieraccountancycodeifauto') {
589 if (strtolower($newval) ==
'auto') {
590 $this->thirpartyobject->get_codecompta(
'supplier');
591 $newval = $this->thirpartyobject->code_compta_fournisseur;
592 if (empty($newval)) {
593 $arrayrecord[($key - 1)][
'type'] = -1;
597 if (empty($newval)) {
598 $arrayrecord[($key - 1)][
'type'] = -1;
600 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getrefifauto') {
601 if (strtolower($newval) ==
'auto') {
604 $classModForNumber = $objimport->array_import_convertvalue[0][$val][
'class'];
605 $pathModForNumber = $objimport->array_import_convertvalue[0][$val][
'path'];
607 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
608 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
609 $modForNumber =
new $classModForNumber;
613 if (!empty($objimport->array_import_convertvalue[0][$val][
'classobject'])) {
614 $pathForObject = $objimport->array_import_convertvalue[0][$val][
'pathobject'];
615 require_once DOL_DOCUMENT_ROOT.$pathForObject;
616 $tmpclassobject = $objimport->array_import_convertvalue[0][$val][
'classobject'];
617 $tmpobject =
new $tmpclassobject($this->
db);
618 foreach ($arrayfield as $tmpkey => $tmpval) {
619 if (in_array($tmpkey, array(
't.date',
'c.date_commande'))) {
620 $tmpobject->date =
dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]][
'val'], 1);
625 $defaultref = $modForNumber->getNextValue(null, $tmpobject);
627 if (is_numeric($defaultref) && $defaultref <= 0) {
630 $newval = $defaultref;
632 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'compute') {
633 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
634 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
635 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
637 if (empty($resultload)) {
638 dol_print_error(
'',
'Error trying to call file='.$file.
', class='.$class.
', method='.$method);
641 $classinstance =
new $class($this->
db);
642 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $listfields, ($key - 1)));
644 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'numeric') {
646 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'accountingaccount') {
647 if (empty($conf->global->ACCOUNTING_MANAGE_ZERO)) {
648 $newval = rtrim(trim($newval),
"0");
650 $newval = trim($newval);
658 if (!empty($objimport->array_import_regex[0][$val]) && ($newval !=
'')) {
661 if (preg_match(
'/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
664 $filter = !empty($reg[3]) ?substr($reg[3], 1) :
'';
666 $cachekey = $field.
'@'.$table;
667 if (!empty($filter)) {
668 $cachekey .=
':'.$filter;
672 if (!is_array($this->cachefieldtable[$cachekey])) {
673 $sql =
"SELECT ".$field.
" as aliasfield FROM ".$table;
674 if (!empty($filter)) {
675 $sql .=
' WHERE '.$filter;
683 $obj = $this->
db->fetch_object(
$resql);
685 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
695 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
696 $tableforerror = $table;
697 if (!empty($filter)) {
698 $tableforerror .=
':'.$filter;
700 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval, $field, $tableforerror);
701 $this->errors[$error][
'type'] =
'FOREIGNKEY';
702 $errorforthistable++;
705 } elseif (!preg_match(
'/'.$objimport->array_import_regex[0][$val].
'/i', $newval)) {
708 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorWrongValueForField',
num2Alpha($key - 1), $newval, $objimport->array_import_regex[0][$val]);
709 $this->errors[$error][
'type'] =
'REGEX';
710 $errorforthistable++;
718 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorHtmlInjectionForField',
num2Alpha($key - 1),
dol_trunc($newval, 100));
719 $this->errors[$error][
'type'] =
'HTMLINJECTION';
720 $errorforthistable++;
729 if ($conf->socialnetworks->enabled && strpos($fieldname,
"socialnetworks") !==
false) {
730 if (!in_array(
"socialnetworks", $listfields)) {
731 $listfields[] =
"socialnetworks";
733 if (!empty($newval) && $arrayrecord[($key - 1)][
'type'] > 0) {
734 $socialkey = array_search(
"socialnetworks", $listfields);
735 $socialnetwork = explode(
"_", $fieldname)[1];
736 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] ==
"null") {
737 $json =
new stdClass();
738 $json->$socialnetwork = $newval;
739 $listvalues[$socialkey] = json_encode($json);
741 $jsondata = $listvalues[$socialkey];
742 $json = json_decode($jsondata);
743 $json->$socialnetwork = $newval;
744 $listvalues[$socialkey] = json_encode($json);
748 $listfields[] = $fieldname;
750 if (empty($newval) && $arrayrecord[($key - 1)][
'type'] < 0) {
751 $listvalues[] = ($newval ==
'0' ? $newval :
"null");
752 } elseif (empty($newval) && $arrayrecord[($key - 1)][
'type'] == 0) {
753 $listvalues[] =
"''";
755 $listvalues[] =
"'".$this->db->escape($newval).
"'";
765 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
767 foreach ($objimport->array_import_fieldshidden[0] as $key => $val) {
768 if (!preg_match(
'/^'.preg_quote($alias,
'/').
'\./', $key)) {
771 if ($val ==
'user->id') {
772 $listfields[] = preg_replace(
'/^'.preg_quote($alias,
'/').
'\./',
'', $key);
773 $listvalues[] = ((int) $user->id);
774 } elseif (preg_match(
'/^lastrowid-/', $val)) {
775 $tmp = explode(
'-', $val);
776 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
777 $keyfield = preg_replace(
'/^'.preg_quote($alias,
'/').
'\./',
'', $key);
778 $listfields[] = $keyfield;
779 $listvalues[] = $lastinsertid;
781 } elseif (preg_match(
'/^const-/', $val)) {
782 $tmp = explode(
'-', $val, 2);
783 $listfields[] = preg_replace(
'/^'.preg_quote($alias,
'/').
'\./',
'', $key);
784 $listvalues[] =
"'".$this->db->escape($tmp[1]).
"'";
785 } elseif (preg_match(
'/^rule-/', $val)) {
787 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
788 if ($objimport->array_import_convertvalue[0][$fieldname][
'rule'] ==
'compute') {
789 $file = (empty($objimport->array_import_convertvalue[0][$fieldname][
'classfile']) ? $objimport->array_import_convertvalue[0][$fieldname][
'file'] : $objimport->array_import_convertvalue[0][$fieldname][
'classfile']);
790 $class = $objimport->array_import_convertvalue[0][$fieldname][
'class'];
791 $method = $objimport->array_import_convertvalue[0][$fieldname][
'method'];
793 if (empty($resultload)) {
794 dol_print_error(
'',
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
797 $classinstance =
new $class($this->
db);
798 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $listfields, ($key - 1)));
799 $fieldArr = explode(
'.', $fieldname);
800 if (count($fieldArr) > 0) {
801 $fieldname = $fieldArr[1];
803 $listfields[] = $fieldname;
804 $listvalues[] = $res;
808 $this->errors[$error][
'lib'] =
'Bad value of profile setup '.$val.
' for array_import_fieldshidden';
809 $this->errors[$error][
'type'] =
'Import profile setup';
818 if (!$errorforthistable) {
820 if (!empty($listfields)) {
824 $is_table_category_link =
false;
826 if (strpos($tablename,
'_categorie_') !==
false) {
827 $is_table_category_link =
true;
831 if (!empty($updatekeys)) {
834 if (empty($lastinsertid)) {
835 $sqlSelect =
"SELECT ".$fname.
" FROM ".$tablename;
837 $data = array_combine($listfields, $listvalues);
840 foreach ($updatekeys as $key) {
841 $col = $objimport->array_import_updatekeys[0][$key];
842 $key = preg_replace(
'/^.*\./i',
'', $key);
843 if ($conf->socialnetworks->enabled && strpos($key,
"socialnetworks") !==
false) {
844 $tmp = explode(
"_", $key);
846 $socialnetwork = $tmp[1];
847 $jsondata = $data[$key];
848 $json = json_decode($jsondata);
849 $stringtosearch = json_encode($socialnetwork).
':'.json_encode($json->$socialnetwork);
852 $where[] = $key.
" LIKE '%".$this->
db->escapeforlike($this->
db->escape($stringtosearch)).
"%'";
853 $filters[] = $col.
" LIKE '%".$this->
db->escapeforlike($this->
db->escape($stringtosearch)).
"%'";
856 $where[] = $key.
' = '.$data[$key];
857 $filters[] = $col.
' = '.$data[$key];
860 $sqlSelect .=
" WHERE ".implode(
' AND ', $where);
862 $resql = $this->
db->query($sqlSelect);
864 $num_rows = $this->
db->num_rows(
$resql);
865 if ($num_rows == 1) {
866 $res = $this->
db->fetch_object(
$resql);
867 $lastinsertid = $res->rowid;
868 if ($is_table_category_link) $lastinsertid =
'linktable';
869 $last_insert_id_array[$tablename] = $lastinsertid;
870 } elseif ($num_rows > 1) {
871 $this->errors[$error][
'lib'] = $langs->trans(
'MultipleRecordFoundWithTheseFilters', implode(
', ', $filters));
872 $this->errors[$error][
'type'] =
'SQL';
879 $this->errors[$error][
'lib'] = $this->
db->lasterror();
880 $this->errors[$error][
'type'] =
'SQL';
889 $sqlSelect =
"SELECT rowid FROM ".$tablename;
891 if (empty($keyfield)) {
894 $sqlSelect .=
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
896 $resql = $this->
db->query($sqlSelect);
898 $res = $this->
db->fetch_object(
$resql);
899 if ($this->
db->num_rows(
$resql) == 1) {
908 $this->errors[$error][
'lib'] = $this->
db->lasterror();
909 $this->errors[$error][
'type'] =
'SQL';
914 if (!empty($lastinsertid)) {
916 if (in_array(
"socialnetworks", $listfields)) {
917 $socialkey = array_search(
"socialnetworks", $listfields);
918 $tmpsql = $listvalues[$socialkey];
919 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
923 $sqlstart =
"UPDATE ".$tablename;
925 $data = array_combine($listfields, $listvalues);
927 foreach ($data as $key => $val) {
928 $set[] = $key.
" = ".$val;
930 $sqlstart .=
" SET ".implode(
', ', $set);
932 if (empty($keyfield)) {
935 $sqlend =
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
937 if ($is_table_category_link) {
938 $sqlend =
" WHERE " . implode(
' AND ', $where);
941 $sql = $sqlstart.$sqlend;
950 $this->errors[$error][
'lib'] = $this->
db->lasterror();
951 $this->errors[$error][
'type'] =
'SQL';
958 if (!$error && !$updatedone) {
960 if (in_array(
"socialnetworks", $listfields)) {
961 $socialkey = array_search(
"socialnetworks", $listfields);
962 $tmpsql = $listvalues[$socialkey];
963 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
967 $sqlstart =
"INSERT INTO ".$tablename.
"(".implode(
", ", $listfields).
", import_key";
968 $sqlend =
") VALUES(".implode(
', ', $listvalues).
", '".$this->
db->escape($importid).
"'";
969 if (!empty($tablewithentity_cache[$tablename])) {
970 $sqlstart .=
", entity";
971 $sqlend .=
", ".$conf->entity;
973 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
974 $sqlstart .=
", ".$objimport->array_import_tables_creator[0][$alias];
975 $sqlend .=
", ".$user->id;
977 $sql = $sqlstart.$sqlend.
")";
984 $last_insert_id_array[$tablename] = $this->
db->last_insert_id($tablename);
988 $this->errors[$error][
'lib'] = $this->
db->lasterror();
989 $this->errors[$error][
'type'] =
'SQL';
1026 return str_replace(array(
',',
';'),
'/', $value);
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
write_footer_example($outputlangs)
Output footer of an example file for this format.
import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
Insert a record into database.
cleansep($value)
Clean a string from separator.
$conf db
API class for accounts.
import_close_file()
Close file handle.
__construct($db, $datatoimport)
Constructor.
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
num2Alpha($n)
Return a numeric value into an Excel like column number.
import_get_nb_of_lines($file)
Return nb of records.
import_read_record()
Return array of next record in input file.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
utf8_check($str)
Check if a string is in UTF8.
dol_count_nb_of_line($file)
Count number of lines in a file.
Class to import CSV files.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
write_header_example($outputlangs)
Output header of an example file for this format.
Parent class for import file readers.
write_title_example($outputlangs, $headerlinefields)
Output title line of an example file for this format.
write_record_example($outputlangs, $contentlinevalues)
Output record of an example file for this format.
testSqlAndScriptInject($val, $type)
Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET...
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
import_open_file($file)
Open input file.
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. ...
import_read_header()
Input header line from file.