dolibarr 25.0.0-alpha
modules_import.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * or see https://www.gnu.org/
20 */
21
33{
37 public $db;
38
42 public $datatoimport;
43
47 public $error = '';
48
52 public $errors = array();
53
57 public $warnings = array();
58
62 public $id;
63
67 public $label;
68
72 public $extension;
73
78 public $version = 'dolibarr';
79
84 public $phpmin = array(7, 0);
85
90 public $label_lib;
91
96 public $version_lib;
97
98 // Array of all drivers
102 public $driverlabel = array();
103
107 public $driverdesc = array();
108
112 public $driverversion = array();
113
117 public $drivererror = array();
118
122 public $liblabel = array();
123
127 public $libversion = array();
128
132 public $charset;
133
137 public $picto;
138
142 public $desc;
143
147 public $escape;
148
152 public $enclosure;
153
157 public $thirdpartyobject;
158
166 public $importtriggermode = '';
167
175 public $importissimulation = 0;
176
182 public $importtriggerinterface;
183
189 public $importbulkstats = array();
190
196 public $importtriggerobjectprototypes = array();
197
203 public $importtriggeractionshookcache = array();
204
210 public $cacheconvert = array();
211
217 public $cachefieldtable = array();
218
224 public $nbinsert = 0;
225
231 public $nbupdate = 0;
232
236 public static $mapTableToElement = MODULE_MAPPING;
237
241 public function __construct()
242 {
243 global $hookmanager;
244
245 if (is_object($hookmanager)) {
246 $hookmanager->initHooks(array('import'));
247 $parameters = array();
248 $reshook = $hookmanager->executeHooks('constructModeleImports', $parameters, $this);
249 if ($reshook >= 0 && !empty($hookmanager->resArray)) {
250 foreach ($hookmanager->resArray as $mapList) {
251 self::$mapTableToElement[$mapList['table']] = $mapList['element'];
252 }
253 }
254 }
255 }
256
262 public function getDriverId()
263 {
264 return $this->id;
265 }
266
272 public function getDriverLabel()
273 {
274 return $this->label;
275 }
276
282 public function getDriverDesc()
283 {
284 return $this->desc;
285 }
286
292 public function getDriverExtension()
293 {
294 return $this->extension;
295 }
296
302 public function getDriverVersion()
303 {
304 return $this->version;
305 }
306
312 public function getLibLabel()
313 {
314 return $this->label_lib;
315 }
316
322 public function getLibVersion()
323 {
324 return $this->version_lib;
325 }
326
327
335 public function listOfAvailableImportFormat($db, $maxfilenamelength = 0)
336 {
337 dol_syslog(get_class($this)."::listOfAvailableImportFormat");
338
339 $dir = DOL_DOCUMENT_ROOT."/core/modules/import/";
340 $handle = opendir($dir);
341
342 // Search list ov drivers available and qualified
343 if (is_resource($handle)) {
344 while (($file = readdir($handle)) !== false) {
345 $reg = array();
346 if (preg_match("/^import_(.*)\.modules\.php/i", $file, $reg)) {
347 $moduleid = $reg[1];
348
349 // Loading Class
350 $file = $dir."/import_".$moduleid.".modules.php";
351 $classname = "Import".ucfirst($moduleid);
352
353 require_once $file;
354 $module = new $classname($db, '');
355 '@phan-var-force ModeleImports $module';
356
357 // Picto
358 $this->picto[$module->id] = $module->picto;
359 // Driver properties
360 $this->driverlabel[$module->id] = $module->getDriverLabel();
361 $this->driverdesc[$module->id] = $module->getDriverDesc();
362 $this->driverversion[$module->id] = $module->getDriverVersion();
363 $this->drivererror[$module->id] = $module->error ? $module->error : '';
364 // If use an external lib
365 $this->liblabel[$module->id] = ($module->error ? '<span class="error">'.$module->error.'</span>' : $module->getLibLabel());
366 $this->libversion[$module->id] = $module->getLibVersion();
367 }
368 }
369 }
370
371 return array_keys($this->driverlabel);
372 }
373
374
381 public function getPictoForKey($key)
382 {
383 return $this->picto[$key];
384 }
385
392 public function getDriverLabelForKey($key)
393 {
394 return $this->driverlabel[$key];
395 }
396
403 public function getDriverDescForKey($key)
404 {
405 return $this->driverdesc[$key];
406 }
407
414 public function getDriverVersionForKey($key)
415 {
416 return $this->driverversion[$key];
417 }
418
425 public function getLibLabelForKey($key)
426 {
427 return $this->liblabel[$key];
428 }
429
436 public function getLibVersionForKey($key)
437 {
438 return $this->libversion[$key];
439 }
440
447 public function getElementFromTableWithPrefix($tableNameWithPrefix)
448 {
449 $tableElement = preg_replace('/^'.preg_quote($this->db->prefix(), '/').'/', '', $tableNameWithPrefix);
450 $element = $tableElement;
451
452 if (isset(self::$mapTableToElement[$tableElement])) {
453 $element = self::$mapTableToElement[$tableElement];
454 }
455
456 return $element;
457 }
458
464 protected function getImportTriggerMode()
465 {
466 $mode = trim((string) $this->importtriggermode);
467 if ($mode === '') {
468 $mode = (string) getDolGlobalString('IMPORT_TRIGGER_MODE_DEFAULT', 'strict_line');
469 }
470 if (!in_array($mode, array('strict_line', 'fast_bulk'), true)) {
471 $mode = 'strict_line';
472 }
473 return $mode;
474 }
475
483 protected function registerImportBulkEvent($tablename, $operation)
484 {
485 if (empty($this->importbulkstats)) {
486 $this->importbulkstats = array(
487 'insert' => 0,
488 'update' => 0,
489 'tables' => array(),
490 );
491 }
492
493 $operation = strtolower((string) $operation);
494 if (!isset($this->importbulkstats[$operation])) {
495 $this->importbulkstats[$operation] = 0;
496 }
497 $this->importbulkstats[$operation]++;
498
499 $tableElement = preg_replace('/^'.preg_quote($this->db->prefix(), '/').'/', '', (string) $tablename);
500 if (!isset($this->importbulkstats['tables'][$tableElement])) {
501 $this->importbulkstats['tables'][$tableElement] = array('insert' => 0, 'update' => 0);
502 }
503 if (!isset($this->importbulkstats['tables'][$tableElement][$operation])) {
504 $this->importbulkstats['tables'][$tableElement][$operation] = 0;
505 }
506 $this->importbulkstats['tables'][$tableElement][$operation]++;
507 }
508
518 public function runImportBulkTrigger($importid, $user, $langs, $conf)
519 {
520 require_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
521
522 if (!($this->importtriggerinterface instanceof Interfaces)) {
523 $this->importtriggerinterface = new Interfaces($this->db);
524 }
525
526 $object = new stdClass();
527 $object->db = $this->db;
528 $object->id = 0;
529 $object->rowid = 0;
530 $object->import_key = $importid;
531 $object->context = array(
532 'import' => 1,
533 'operation' => 'bulk',
534 'importtriggermode' => $this->getImportTriggerMode(),
535 );
536 $object->bulk_stats = (empty($this->importbulkstats) ? array('insert' => 0, 'update' => 0, 'tables' => array()) : $this->importbulkstats);
537
538 try {
539 $result = $this->importtriggerinterface->run_triggers('IMPORT_BULK_DONE', $object, $user, $langs, $conf);
540 } catch (Throwable $e) {
541 $this->errors[] = array('lib' => $e->getMessage(), 'type' => 'TRIGGER');
542 $this->error = 'ErrorFailedTriggerCall';
543 return -1;
544 }
545
546 if ($result < 0) {
547 if (!empty($this->importtriggerinterface->errors)) {
548 foreach ($this->importtriggerinterface->errors as $errormsg) {
549 $this->errors[] = array('lib' => $errormsg, 'type' => 'TRIGGER');
550 }
551 }
552 $this->error = 'ErrorFailedTriggerCall';
553 return -1;
554 }
555
556 return 1;
557 }
558
568 protected function getImportTriggerActions($tableElement, $operation, $element, $object = null)
569 {
570 $operation = strtolower((string) $operation);
571
572 $actionMap = array(
573 'societe' => array('insert' => 'COMPANY_CREATE', 'update' => 'COMPANY_MODIFY'),
574 'product' => array('insert' => 'PRODUCT_CREATE', 'update' => 'PRODUCT_MODIFY'),
575 'socpeople' => array('insert' => 'CONTACT_CREATE', 'update' => 'CONTACT_MODIFY'),
576 'commande' => array('insert' => 'ORDER_CREATE', 'update' => 'ORDER_MODIFY'),
577 'commandedet' => array('insert' => 'LINEORDER_INSERT', 'update' => 'LINEORDER_MODIFY'),
578 'propal' => array('insert' => 'PROPAL_CREATE', 'update' => 'PROPAL_MODIFY'),
579 'propaldet' => array('insert' => 'LINEPROPAL_INSERT', 'update' => 'LINEPROPAL_MODIFY'),
580 'facture' => array('insert' => 'BILL_CREATE', 'update' => 'BILL_MODIFY'),
581 'facturedet' => array('insert' => 'LINEBILL_INSERT', 'update' => 'LINEBILL_MODIFY'),
582 'facture_fourn' => array('insert' => 'BILL_SUPPLIER_CREATE', 'update' => 'BILL_SUPPLIER_MODIFY'),
583 'facture_fourn_det' => array('insert' => 'LINEBILL_SUPPLIER_CREATE', 'update' => 'LINEBILL_SUPPLIER_MODIFY'),
584 'commande_fournisseur' => array('insert' => 'ORDER_SUPPLIER_CREATE', 'update' => 'ORDER_SUPPLIER_MODIFY'),
585 'commande_fournisseurdet' => array('insert' => 'LINEORDER_SUPPLIER_CREATE', 'update' => 'LINEORDER_SUPPLIER_MODIFY'),
586 'contrat' => array('insert' => 'CONTRACT_CREATE', 'update' => 'CONTRACT_MODIFY'),
587 'contratdet' => array('insert' => 'LINECONTRACT_INSERT', 'update' => 'LINECONTRACT_MODIFY'),
588 'fichinter' => array('insert' => 'FICHINTER_CREATE', 'update' => 'FICHINTER_MODIFY'),
589 'fichinterdet' => array('insert' => 'LINEFICHINTER_CREATE', 'update' => 'LINEFICHINTER_MODIFY'),
590 'expedition' => array('insert' => 'SHIPPING_CREATE', 'update' => 'SHIPPING_MODIFY'),
591 'expeditiondet' => array('insert' => 'LINESHIPPING_INSERT', 'update' => 'LINESHIPPING_MODIFY'),
592 'supplier_proposal' => array('insert' => 'SUPPLIER_PROPOSAL_CREATE', 'update' => 'SUPPLIER_PROPOSAL_MODIFY'),
593 'supplier_proposaldet' => array('insert' => 'LINESUPPLIER_PROPOSAL_INSERT', 'update' => 'LINESUPPLIER_PROPOSAL_MODIFY'),
594 );
595
596 $actions = array();
597 if (!empty($actionMap[$tableElement][$operation])) {
598 $actions[] = $actionMap[$tableElement][$operation];
599 }
600
601 // Let external modules add explicit import trigger actions.
602 // We merge with core mapping when present.
603 $hookactions = $this->getImportTriggerActionsFromHooks($tableElement, $operation, $element, $object);
604 if (!empty($hookactions)) {
605 $actions = array_merge($actions, $hookactions);
606 }
607
608 // Dynamic fallback only for real business objects and only when
609 // no explicit mapping/hook action exists.
610 // Avoid generating trigger names from stdClass (legacy SQL context).
611 if (empty($actions) && is_object($object) && method_exists($object, 'call_trigger')) {
612 $triggerprefix = $this->getImportTriggerPrefixFromObject($object);
613 $action = $this->buildImportTriggerActionFromPrefix($triggerprefix, $operation);
614 if (!empty($action)) {
615 $actions[] = $action;
616 }
617 }
618
619 // Generic fallback for external/custom objects imported through legacy SQL path:
620 // derive a deterministic trigger prefix from element/table when no explicit mapping exists.
621 if (empty($actions)) {
622 $triggerprefix = $this->getImportGenericTriggerPrefix($element, $tableElement);
623 $action = $this->buildImportTriggerActionFromPrefix($triggerprefix, $operation);
624 if (!empty($action)) {
625 $actions[] = $action;
626 }
627 }
628
629 return array_values(array_unique(array_filter($actions)));
630 }
631
639 protected function buildImportTriggerActionFromPrefix($triggerprefix, $operation)
640 {
641 $triggerprefix = strtoupper(trim((string) $triggerprefix));
642 $operation = strtolower((string) $operation);
643 if ($triggerprefix === '') {
644 return '';
645 }
646
647 if ($operation === 'update') {
648 return $triggerprefix.'_MODIFY';
649 }
650 if ($operation === 'insert') {
651 return preg_match('/^LINE/', $triggerprefix) ? $triggerprefix.'_INSERT' : $triggerprefix.'_CREATE';
652 }
653
654 return '';
655 }
656
664 {
665 if (!empty($object->TRIGGER_PREFIX)) {
666 return (string) $object->TRIGGER_PREFIX;
667 }
668 if (!empty($object->element)) {
669 return (string) $object->element;
670 }
671 return get_class($object);
672 }
673
681 protected function getImportGenericTriggerPrefix($element, $tableElement)
682 {
683 $rawprefix = '';
684 if (!empty($element)) {
685 $rawprefix = (string) $element;
686 } elseif (!empty($tableElement)) {
687 $rawprefix = (string) $tableElement;
688 }
689
690 return trim((string) preg_replace('/[^A-Za-z0-9]+/', '_', strtoupper($rawprefix)), '_');
691 }
692
710 protected function getImportTriggerActionsFromHooks($tableElement, $operation, $element, $object = null)
711 {
712 global $hookmanager;
713
714 $actions = array();
715 $objectclass = (is_object($object) ? get_class($object) : 'none');
716 $cachekey = $tableElement.'|'.$operation.'|'.$element.'|'.$objectclass;
717 if (isset($this->importtriggeractionshookcache[$cachekey])) {
718 return $this->importtriggeractionshookcache[$cachekey];
719 }
720
721 if (!is_object($hookmanager)) {
722 $this->importtriggeractionshookcache[$cachekey] = $actions;
723 return $actions;
724 }
725
726 $hookmanager->initHooks(array('import'));
727 $parameters = array(
728 'tableelement' => (string) $tableElement,
729 'operation' => (string) $operation,
730 'element' => (string) $element,
731 );
732 $action = '';
733 $hookmanager->executeHooks('getImportTriggerActions', $parameters, $object, $action);
734
735 if (!empty($hookmanager->resArray['actions'])) {
736 if (is_array($hookmanager->resArray['actions'])) {
737 $actions = array_merge($actions, $hookmanager->resArray['actions']);
738 } else {
739 $actions = array_merge($actions, preg_split('/[\s,;|]+/', (string) $hookmanager->resArray['actions']));
740 }
741 }
742 if (!empty($hookmanager->resArray['action'])) {
743 $actions[] = (string) $hookmanager->resArray['action'];
744 }
745
746 $cleaned = array();
747 foreach ($actions as $oneaction) {
748 $oneaction = strtoupper(trim((string) $oneaction));
749 if ($oneaction !== '') {
750 $cleaned[] = $oneaction;
751 }
752 }
753
754 $cleaned = array_values(array_unique($cleaned));
755 $this->importtriggeractionshookcache[$cachekey] = $cleaned;
756 return $cleaned;
757 }
758
771 protected function triggerImportSqlOperation($tablename, $operation, $rowid, $importid, $user, $langs, $conf)
772 {
773 require_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
774
775 $tableElement = preg_replace('/^'.preg_quote($this->db->prefix(), '/').'/', '', $tablename);
776 $element = $this->getElementFromTableWithPrefix($tablename);
777 $object = null;
778 $needenrichobject = (bool) getDolGlobalInt('IMPORT_TRIGGER_ENRICH_OBJECT');
779
780 // Fast-path: for mapped tables, get action list without loading business object.
781 $actions = $this->getImportTriggerActions($tableElement, $operation, $element, null);
782
783 // Resolve business object only when needed:
784 // - dynamic action fallback requires real object,
785 // - optional richer trigger context can be enabled with IMPORT_TRIGGER_ENRICH_OBJECT.
786 if (empty($actions) || $needenrichobject) {
787 // Try to resolve a real business object for full trigger compatibility.
788 // - with rowid when available (best case),
789 // - otherwise as a prototype object based on element/table.
790 if ((int) $rowid > 0) {
791 $objecttmp = fetchObjectByElement((int) $rowid, $tableElement);
792 if (is_object($objecttmp)) {
793 $object = $objecttmp;
794 }
795 }
796 if (!is_object($object)) {
797 $objecttmp = fetchObjectByElement(0, $tableElement);
798 if (is_object($objecttmp)) {
799 $object = $objecttmp;
800 if ((int) $rowid > 0) {
801 if (method_exists($object, 'fetch')) {
802 $fetchres = $object->fetch((int) $rowid);
803 if ($fetchres <= 0) {
804 $object->id = (int) $rowid;
805 $object->rowid = (int) $rowid;
806 }
807 } else {
808 $object->id = (int) $rowid;
809 $object->rowid = (int) $rowid;
810 }
811 }
812 }
813 }
814 }
815
816 // Compatibility path for strict_line mode:
817 // for mapped actions, provide at least a business object prototype (not stdClass)
818 // so custom triggers can call object methods safely.
819 if (!is_object($object) && !empty($actions) && $this->getImportTriggerMode() === 'strict_line') {
820 if (!isset($this->importtriggerobjectprototypes[$tableElement])) {
821 $prototype = fetchObjectByElement(0, $tableElement);
822 if (is_object($prototype)) {
823 $this->importtriggerobjectprototypes[$tableElement] = $prototype;
824 }
825 }
826 if (isset($this->importtriggerobjectprototypes[$tableElement])) {
827 $object = clone $this->importtriggerobjectprototypes[$tableElement];
828 $object->id = (int) $rowid;
829 $object->rowid = (int) $rowid;
830 if ((int) $rowid > 0 && method_exists($object, 'fetch')) {
831 $fetchres = $object->fetch((int) $rowid);
832 if ($fetchres <= 0) {
833 $object->id = (int) $rowid;
834 $object->rowid = (int) $rowid;
835 }
836 }
837 }
838 }
839
840 if (!is_object($object)) {
841 $object = new stdClass();
842 $object->db = $this->db;
843 $object->id = (int) $rowid;
844 $object->rowid = (int) $rowid;
845 $object->table_element = $tableElement;
846 $object->element = $element;
847 }
848 $object->import_key = $importid;
849 $object->context = array('import' => 1, 'operation' => $operation);
850
851 if (empty($actions)) {
852 $actions = $this->getImportTriggerActions($tableElement, $operation, $element, $object);
853 }
854
855 if (empty($actions)) {
856 dol_syslog(get_class($this)."::triggerImportSqlOperation no trigger mapping for table=".$tableElement." operation=".$operation, LOG_DEBUG);
857 return 1;
858 }
859
860 // Optional enrichment: provides full row payload for stdClass context.
861 // Disabled by default for performance.
862 if ($needenrichobject && $rowid > 0 && $object instanceof stdClass) {
863 $sql = "SELECT * FROM ".$tablename." WHERE rowid = ".((int) $rowid);
864 $resql = $this->db->query($sql);
865 if ($resql) {
866 $objrow = $this->db->fetch_object($resql);
867 if ($objrow) {
868 foreach (get_object_vars($objrow) as $key => $value) {
869 $object->$key = $value;
870 }
871 if (!isset($object->id) && isset($object->rowid)) {
872 $object->id = (int) $object->rowid;
873 }
874 }
875 }
876 }
877
878 if (!($this->importtriggerinterface instanceof Interfaces)) {
879 $this->importtriggerinterface = new Interfaces($this->db);
880 }
881 $interface = $this->importtriggerinterface;
882 foreach ($actions as $action) {
883 try {
884 $result = $interface->run_triggers($action, $object, $user, $langs, $conf);
885 } catch (Throwable $e) {
886 $this->errors[] = array('lib' => $e->getMessage(), 'type' => 'TRIGGER');
887 $this->error = 'ErrorFailedTriggerCall';
888 return -1;
889 }
890 if ($result < 0) {
891 if (!empty($interface->errors)) {
892 foreach ($interface->errors as $errormsg) {
893 $this->errors[] = array('lib' => $errormsg, 'type' => 'TRIGGER');
894 }
895 }
896 $this->error = 'ErrorFailedTriggerCall';
897 return -1;
898 }
899 }
900
901 return 1;
902 }
903
904 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
911 public function import_open_file($file)
912 {
913 // phpcs:enable
914 $msg = get_class($this)."::".__FUNCTION__." not implemented";
915 dol_syslog($msg, LOG_ERR);
916 $this->errors[] = $msg;
917 $this->error = $msg;
918 return -1;
919 }
920
921
922 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
929 public function import_get_nb_of_lines($file)
930 {
931 // phpcs:enable
932 $msg = get_class($this)."::".__FUNCTION__." not implemented";
933 dol_syslog($msg, LOG_ERR);
934 $this->errors[] = $msg;
935 $this->error = $msg;
936 return -1;
937 }
938
939 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
945 public function import_read_header()
946 {
947 // phpcs:enable
948 $msg = get_class($this)."::".__FUNCTION__." not implemented";
949 dol_syslog($msg, LOG_ERR);
950 $this->errors[] = $msg;
951 $this->error = $msg;
952 return -1;
953 }
954
955
956 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
962 public function import_read_record()
963 {
964 // phpcs:enable
965 $msg = get_class($this)."::".__FUNCTION__." not implemented";
966 dol_syslog($msg, LOG_ERR);
967 $this->errors[] = $msg;
968 $this->error = $msg;
969 return array();
970 }
971
972
973 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
979 public function import_close_file()
980 {
981 // phpcs:enable
982 $msg = get_class($this)."::".__FUNCTION__." not implemented";
983 dol_syslog($msg, LOG_ERR);
984 $this->errors[] = $msg;
985 $this->error = $msg;
986 return -1;
987 }
988
1001 protected function commonImportInsert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys, $recordpositionbase = 0)
1002 {
1003 global $langs, $conf, $user;
1004 global $thirdparty_static; // Specific to thirdparty import
1005 global $tablewithentity_cache; // Cache to avoid to call entity desc at each rows on tables
1006
1007 if (is_array($arrayrecord) && !empty($recordpositionbase)) {
1008 $arrayrecord = array_values($arrayrecord);
1009 }
1010
1011 $error = 0;
1012 $warning = 0;
1013 $importtriggermode = $this->getImportTriggerMode();
1014 $importissimulation = !empty($this->importissimulation);
1015 $this->errors = array();
1016 $this->warnings = array();
1017
1018 //dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
1019
1020 //var_dump($array_match_file_to_database);
1021 //var_dump($arrayrecord); exit;
1022 $array_match_database_to_file = array_flip($array_match_file_to_database);
1023 $sort_array_match_file_to_database = $array_match_file_to_database;
1024 ksort($sort_array_match_file_to_database);
1025
1026 //var_dump($sort_array_match_file_to_database);
1027
1028 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val']))) {
1029 //print 'W';
1030 $this->warnings[$warning]['lib'] = $langs->trans('EmptyLine');
1031 $this->warnings[$warning]['type'] = 'EMPTY';
1032 $warning++;
1033 } else {
1034 $last_insert_id_array = array(); // store the last inserted auto_increment id for each table, so that dependent tables can be inserted with the appropriate id (eg: extrafields fk_object will be set with the last inserted object's id)
1035 $updatedone = false;
1036 $insertdone = false;
1037 // For each table to insert, me make a separate insert
1038 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
1039 // Build sql request
1040 $sql = '';
1041 $sql_listfields = array();
1042 $sql_listvalues = array();
1043 $i = 0;
1044 $errorforthistable = 0;
1045
1046 // Define $tablewithentity_cache[$tablename] if not already defined
1047 if (!isset($tablewithentity_cache[$tablename])) { // keep this test with "isset"
1048 dol_syslog("Check if table ".$tablename." has an entity field");
1049 $resql = $this->db->DDLDescTable($tablename, 'entity');
1050 if ($resql) {
1051 $obj = $this->db->fetch_object($resql);
1052 if ($obj) {
1053 $tablewithentity_cache[$tablename] = 1; // table contains entity field
1054 } else {
1055 $tablewithentity_cache[$tablename] = 0; // table does not contain entity field
1056 }
1057 } else {
1058 dol_print_error($this->db);
1059 }
1060 } else {
1061 //dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]);
1062 }
1063
1064 // Define an array to convert fields ('c.ref', ...) into column index (1, ...)
1065 $arrayfield = array();
1066 foreach ($sort_array_match_file_to_database as $key => $val) {
1067 $arrayfield[$val] = ($key - 1);
1068 }
1069
1070 // $arrayrecord start at key 0
1071 // $sort_array_match_file_to_database start at key 1
1072
1073 // Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom)
1074 foreach ($sort_array_match_file_to_database as $key => $val) {
1075 $fieldalias = preg_replace('/\..*$/i', '', $val);
1076 $fieldname = preg_replace('/^.*\./i', '', $val);
1077
1078 if ($alias != $fieldalias) {
1079 continue; // Not a field of current table
1080 }
1081
1082 if ($key <= $maxfields) {
1083 // Set $newval with value to insert and set $sql_listvalues with sql request part for insert
1084 $newval = '';
1085 if ($arrayrecord[($key - 1)]['type'] > 0) {
1086 $newval = $arrayrecord[($key - 1)]['val']; // If type of field into input file is not empty string (so defined into input file), we get value
1087 }
1088
1089 //var_dump($newval);var_dump($val);
1090 //var_dump($objimport->array_import_convertvalue[0][$val]);
1091
1092 // Make some tests on $newval
1093
1094 // Is it a required field ?
1095 if (preg_match('/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval == '')) {
1096 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1097 $this->errors[$error]['lib'] = $langs->trans('ErrorMissingMandatoryValue', $key);
1098 $this->errors[$error]['type'] = 'NOTNULL';
1099 $errorforthistable++;
1100 $error++;
1101 } else {
1102 // Test format only if field is not a missing mandatory field (field may be a value or empty but not mandatory)
1103 // We convert field if required
1104 if (!empty($objimport->array_import_convertvalue[0][$val])) {
1105 //print 'Must convert '.$newval.' with rule '.join(',',$objimport->array_import_convertvalue[0][$val]).'. ';
1106 if ($objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeid'
1107 || $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromref'
1108 || $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeorlabel'
1109 ) {
1110 // New val can be an id or ref. If it start with id: it is forced to id, if it start with ref: it is forced to ref. It not, we try to guess.
1111 $isidorref = 'id';
1112 if (!is_numeric($newval) && $newval != '' && !preg_match('/^id:/i', $newval)) {
1113 $isidorref = 'ref';
1114 }
1115
1116 $newval = preg_replace('/^(id|ref):/i', '', $newval); // Remove id: or ref: that was used to force if field is id or ref
1117 //print 'Newval is now "'.$newval.'" and is type '.$isidorref."<br>\n";
1118
1119 if ($isidorref == 'ref') { // If value into input import file is a ref, we apply the function defined into descriptor
1120 $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']);
1121 $class = $objimport->array_import_convertvalue[0][$val]['class'];
1122 $method = $objimport->array_import_convertvalue[0][$val]['method'];
1123 $cachekey = $file.'_'.$class.'_'.$method.'_';
1124 if (isset($this->cacheconvert[$cachekey][$newval]) && $this->cacheconvert[$cachekey][$newval] != '') {
1125 $newval = $this->cacheconvert[$cachekey][$newval];
1126 } else {
1127 $resultload = dol_include_once($file);
1128 if (empty($resultload)) {
1129 dol_print_error(null, 'Error trying to call file='.$file.', class='.$class.', method='.$method);
1130 break;
1131 }
1132 $classinstance = new $class($this->db);
1133 if ($class == 'CGenericDic') {
1134 $classinstance->element = $objimport->array_import_convertvalue[0][$val]['element'];
1135 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val]['table_element'];
1136 }
1137
1138 // Try the fetch from code or ref
1139 $param_array = array('', $newval);
1140 if ($class == 'AccountingAccount') {
1141 //var_dump($arrayrecord[0]['val']);
1142 /*include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancysystem.class.php';
1143 $tmpchartofaccount = new AccountancySystem($this->db);
1144 $tmpchartofaccount->fetch(getDolGlobalInt('CHARTOFACCOUNTS'));
1145 //var_dump($tmpchartofaccount->ref.' - '.$arrayrecord[0]['val']);
1146 if ((! (getDolGlobalInt('CHARTOFACCOUNTS') > 0)) || $tmpchartofaccount->ref != $arrayrecord[0]['val'])
1147 {
1148 $this->errors[$error]['lib']=$langs->trans('ErrorImportOfChartLimitedToCurrentChart', $tmpchartofaccount->ref);
1149 $this->errors[$error]['type']='RESTRICTONCURRENCTCHART';
1150 $errorforthistable++;
1151 $error++;
1152 }*/
1153 $param_array = array('', $newval, 0, $arrayrecord[0]['val']); // Param to fetch parent from account, in chart.
1154 }
1155 if ($class == 'CActionComm') {
1156 $param_array = array($newval); // CActionComm fetch method have same parameter for id and code
1157 }
1158 $result = call_user_func_array(array($classinstance, $method), $param_array);
1159
1160 // If duplicate record found
1161 if (!($classinstance->id != '') && $result == -2) {
1162 $langs->load('errors');
1163 $this->errors[$error]['lib'] = $langs->trans('ErrorMultipleRecordFoundFromRef', $newval);
1164 $this->errors[$error]['type'] = 'FOREIGNKEY';
1165 $errorforthistable++;
1166 $error++;
1167 }
1168
1169 // If not found, try the fetch from label
1170 if (!($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeorlabel') {
1171 $param_array = array('', '', $newval);
1172 call_user_func_array(array($classinstance, $method), $param_array);
1173 }
1174 $this->cacheconvert[$cachekey][$newval] = $classinstance->id;
1175
1176 //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. ';
1177 if ($classinstance->id != '') { // id may be 0, it is a found value
1178 $newval = $classinstance->id;
1179 } elseif (! $error) {
1180 if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) {
1181 $langs->load('errors');
1182 $this->errors[$error]['lib'] = $langs->trans('ErrorFieldValueNotIn', num2Alpha($key - 1), $newval, 'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
1183 } elseif (!empty($objimport->array_import_convertvalue[0][$val]['element'])) {
1184 $this->errors[$error]['lib'] = $langs->trans('ErrorFieldRefNotIn', num2Alpha($key - 1), $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
1185 } else {
1186 $this->errors[$error]['lib'] = 'ErrorBadDefinitionOfImportProfile';
1187 }
1188 $this->errors[$error]['type'] = 'FOREIGNKEY';
1189 $errorforthistable++;
1190 $error++;
1191 }
1192 }
1193 }
1194 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeandlabel') {
1195 $isidorref = 'id';
1196 if (!is_numeric($newval) && $newval != '' && !preg_match('/^id:/i', $newval)) {
1197 $isidorref = 'ref';
1198 }
1199 $newval = preg_replace('/^(id|ref):/i', '', $newval);
1200
1201 if ($isidorref == 'ref') {
1202 $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']);
1203 $class = $objimport->array_import_convertvalue[0][$val]['class'];
1204 $method = $objimport->array_import_convertvalue[0][$val]['method'];
1205 $codefromfield = $objimport->array_import_convertvalue[0][$val]['codefromfield'];
1206 $code = $arrayrecord[$arrayfield[$codefromfield]]['val'];
1207 $cachekey = $file.'_'.$class.'_'.$method.'_'.$code;
1208 if (isset($this->cacheconvert[$cachekey][$newval]) && $this->cacheconvert[$cachekey][$newval] != '') {
1209 $newval = $this->cacheconvert[$cachekey][$newval];
1210 } else {
1211 $resultload = dol_include_once($file);
1212 if (empty($resultload)) {
1213 dol_print_error(null, 'Error trying to call file='.$file.', class='.$class.', method='.$method.', code='.$code);
1214 break;
1215 }
1216 $classinstance = new $class($this->db);
1217 // Try the fetch from code and ref
1218 $param_array = array('', $newval, $code);
1219 call_user_func_array(array($classinstance, $method), $param_array);
1220 $this->cacheconvert[$cachekey][$newval] = $classinstance->id;
1221 if ($classinstance->id > 0) { // we found record
1222 $newval = $classinstance->id;
1223 } else {
1224 if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) {
1225 $langs->load('errors');
1226 $this->errors[$error]['lib'] = $langs->trans('ErrorFieldValueNotIn', num2Alpha($key - 1), $newval, 'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
1227 } else {
1228 $this->errors[$error]['lib'] = 'ErrorFieldValueNotIn';
1229 }
1230 $this->errors[$error]['type'] = 'FOREIGNKEY';
1231 $errorforthistable++;
1232 $error++;
1233 }
1234 }
1235 }
1236 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'zeroifnull') {
1237 if (empty($newval)) {
1238 $newval = '0';
1239 }
1240 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchscalefromcodeunits') {
1241 $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']);
1242 $class = $objimport->array_import_convertvalue[0][$val]['class'];
1243 $method = $objimport->array_import_convertvalue[0][$val]['method'];
1244 $units = $objimport->array_import_convertvalue[0][$val]['units'];
1245 $cachekey = $file.'_'.$class.'_'.$method.'_'.$units;
1246 if (isset($this->cacheconvert[$cachekey][$newval]) && $this->cacheconvert[$cachekey][$newval] != '') {
1247 $newval = $this->cacheconvert[$cachekey][$newval];
1248 } else {
1249 $resultload = dol_include_once($file);
1250 if (empty($resultload)) {
1251 dol_print_error(null, 'Error trying to call file='.$file.', class='.$class.', method='.$method.', units='.$units);
1252 break;
1253 }
1254 $classinstance = new $class($this->db);
1255 // Try the fetch from code or ref
1256 call_user_func_array(array($classinstance, $method), array('', '', $newval, $units));
1257 $scaleorid = (($objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
1258 $this->cacheconvert[$cachekey][$newval] = $scaleorid;
1259 //print 'We have made a '.$class.'->'.$method." to get a value from key '".$newval."' and we got '".$scaleorid."'.";exit;
1260 if ($classinstance->id > 0) { // we found record
1261 $newval = $scaleorid ? $scaleorid : 0;
1262 } else {
1263 if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) {
1264 $langs->load('errors');
1265 $this->errors[$error]['lib'] = $langs->trans('ErrorFieldValueNotIn', num2Alpha($key - 1), $newval, 'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
1266 } else {
1267 $this->errors[$error]['lib'] = 'ErrorFieldValueNotIn';
1268 }
1269 $this->errors[$error]['type'] = 'FOREIGNKEY';
1270 $errorforthistable++;
1271 $error++;
1272 }
1273 }
1274 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomercodeifauto') {
1275 if (strtolower($newval) == 'auto') {
1276 $this->thirdpartyobject->get_codeclient(null, 0);
1277 $newval = $this->thirdpartyobject->code_client;
1278 //print 'code_client='.$newval;
1279 }
1280 if (empty($newval)) {
1281 $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
1282 }
1283 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsuppliercodeifauto') {
1284 if (strtolower($newval) == 'auto') {
1285 $this->thirdpartyobject->get_codefournisseur(null, 1);
1286 $newval = $this->thirdpartyobject->code_fournisseur;
1287 //print 'code_fournisseur='.$newval;
1288 }
1289 if (empty($newval)) {
1290 $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
1291 }
1292 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomeraccountancycodeifauto') {
1293 if (strtolower($newval) == 'auto') {
1294 $this->thirdpartyobject->get_codecompta('customer');
1295 $newval = $this->thirdpartyobject->code_compta_client;
1296 //print 'code_compta='.$newval;
1297 }
1298 if (empty($newval)) {
1299 $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
1300 }
1301 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsupplieraccountancycodeifauto') {
1302 if (strtolower($newval) == 'auto') {
1303 $this->thirdpartyobject->get_codecompta('supplier');
1304 $newval = $this->thirdpartyobject->code_compta_fournisseur;
1305 if (empty($newval)) {
1306 $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
1307 }
1308 //print 'code_compta_fournisseur='.$newval;
1309 }
1310 if (empty($newval)) {
1311 $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
1312 }
1313 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getrefifauto') {
1314 if (strtolower($newval) == 'auto') {
1315 $defaultref = '';
1316
1317 $classModForNumber = $objimport->array_import_convertvalue[0][$val]['class'];
1318 $pathModForNumber = $objimport->array_import_convertvalue[0][$val]['path'];
1319
1320 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
1321 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
1322 $modForNumber = new $classModForNumber();
1323 '@phan-var-force ModeleNumRefMembers|ModeleNumRefCommandes|ModeleNumRefSuppliersInvoices|ModeleNumRefSuppliersOrders|ModeleNumRefProjects|ModeleNumRefTask|ModeleNumRefPropales $modForNumber';
1324
1325 $tmpobject = null;
1326 // Set the object with the date property when we can
1327 if (!empty($objimport->array_import_convertvalue[0][$val]['classobject'])) {
1328 $pathForObject = $objimport->array_import_convertvalue[0][$val]['pathobject'];
1329 require_once DOL_DOCUMENT_ROOT.$pathForObject;
1330 $tmpclassobject = $objimport->array_import_convertvalue[0][$val]['classobject'];
1331 $tmpobject = new $tmpclassobject($this->db);
1332 foreach ($arrayfield as $tmpkey => $tmpval) { // $arrayfield is array('c.ref'=>0, ...)
1333 if (in_array($tmpkey, array('t.date', 'c.date_commande'))) {
1334 $tmpobject->date = dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]]['val'], 1);
1335 }
1336 }
1337 }
1338
1339 $defaultref = $modForNumber->getNextValue(null, $tmpobject);
1340 }
1341 if (is_numeric($defaultref) && $defaultref <= 0) { // If error
1342 $defaultref = '';
1343 }
1344 $newval = $defaultref;
1345 }
1346 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'compute') {
1347 $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']);
1348 $class = $objimport->array_import_convertvalue[0][$val]['class'];
1349 $method = $objimport->array_import_convertvalue[0][$val]['method'];
1350 $resultload = dol_include_once($file);
1351 if (empty($resultload)) {
1352 dol_print_error(null, 'Error trying to call file='.$file.', class='.$class.', method='.$method);
1353 break;
1354 }
1355 $classinstance = new $class($this->db);
1356 $computedFieldPos = isset($arrayfield[$val]) ? ((int) $arrayfield[$val]) : 0;
1357 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $computedFieldPos));
1358 if (empty($classinstance->error) && empty($classinstance->errors)) {
1359 $newval = $res; // We get new value computed.
1360 } else {
1361 $this->errors[$error]['type'] = 'CLASSERROR';
1362 $this->errors[$error]['lib'] = implode(
1363 "\n",
1364 array_merge([$classinstance->error], $classinstance->errors)
1365 );
1366 $errorforthistable++;
1367 $error++;
1368 }
1369 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'numeric') {
1370 $newval = price2num($newval);
1371 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'accountingaccount') {
1372 if (!getDolGlobalString('ACCOUNTING_MANAGE_ZERO')) {
1373 $newval = rtrim(trim($newval), "0");
1374 } else {
1375 $newval = trim($newval);
1376 }
1377 }
1378
1379 //print 'Val to use as insert is '.$newval.'<br>';
1380 }
1381
1382 // Test regexp
1383 if (!empty($objimport->array_import_regex[0][$val]) && ($newval != '')) {
1384 // If test regex string is "field@table" or "field@table:..." (means must exists into table ...)
1385 $reg = array();
1386 if (preg_match('/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
1387 $field = $reg[1];
1388 $table = $reg[2];
1389 $filter = !empty($reg[3]) ? substr($reg[3], 1) : '';
1390
1391 $cachekey = $field.'@'.$table;
1392 if (!empty($filter)) {
1393 $cachekey .= ':'.$filter;
1394 }
1395
1396 // Load content of field@table into cache array
1397 if (!isset($this->cachefieldtable[$cachekey]) || !is_array($this->cachefieldtable[$cachekey])) { // If content of field@table not already loaded into cache
1398 $sql = "SELECT ".$this->db->sanitize($field)." as aliasfield FROM ".$this->db->sanitize($table);
1399 if (!empty($filter)) {
1400 $sql .= forgeSQLFromUniversalSearchCriteria($filter);
1401 }
1402
1403 $resql = $this->db->query($sql);
1404 if ($resql) {
1405 $num = $this->db->num_rows($resql);
1406 $i = 0;
1407 while ($i < $num) {
1408 $obj = $this->db->fetch_object($resql);
1409 if ($obj) {
1410 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
1411 }
1412 $i++;
1413 }
1414 } else {
1415 dol_print_error($this->db);
1416 }
1417 }
1418
1419 // Now we check cache is not empty (should not) and key is in cache
1420 if (!isset($this->cachefieldtable[$cachekey]) || !is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
1421 $tableforerror = $table;
1422 if (!empty($filter)) {
1423 $tableforerror .= ':'.$filter;
1424 }
1425 $langs->load('errors');
1426 $this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorFieldValueNotIn', num2Alpha($key - 1), $newval, $field, $tableforerror);
1427 $this->errors[$error]['type'] = 'FOREIGNKEY';
1428 $errorforthistable++;
1429 $error++;
1430 }
1431 } elseif (!preg_match('/'.$objimport->array_import_regex[0][$val].'/i', $newval)) {
1432 // If test is just a static regex
1433 //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>";
1434 $langs->load('errors');
1435 $this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorWrongValueForField', num2Alpha($key - 1), $newval, $objimport->array_import_regex[0][$val]);
1436 $this->errors[$error]['type'] = 'REGEX';
1437 $errorforthistable++;
1438 $error++;
1439 }
1440 }
1441
1442 // Check HTML injection
1443 $inj = testSqlAndScriptInject($newval, 0);
1444 if ($inj) {
1445 $langs->load('errors');
1446 $this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorHtmlInjectionForField', num2Alpha($key - 1), dol_trunc($newval, 100));
1447 $this->errors[$error]['type'] = 'HTMLINJECTION';
1448 $errorforthistable++;
1449 $error++;
1450 }
1451
1452 // Other tests
1453 // ...
1454 }
1455
1456 // Define $sql_listfields and $sql_listvalues to build the SQL request
1457 if (isModEnabled("socialnetworks") && strpos($fieldname, "socialnetworks") !== false) {
1458 if (!in_array("socialnetworks", $sql_listfields)) {
1459 $sql_listfields[] = "socialnetworks";
1460 $socialkey = array_search("socialnetworks", $sql_listfields); // Return position of 'socialnetworks' key in array
1461 $sql_listvalues[$socialkey] = '';
1462 }
1463 //var_dump($newval); var_dump($arrayrecord[($key - 1)]['type']);
1464 if (!empty($newval) && $arrayrecord[($key - 1)]['type'] > 0) {
1465 $socialkey = array_search("socialnetworks", $sql_listfields); // Return position of 'socialnetworks' key in array
1466 //var_dump('sk='.$socialkey); // socialkey=19
1467 $socialnetwork = explode("_", $fieldname)[1];
1468 if (empty($sql_listvalues[$socialkey]) || $sql_listvalues[$socialkey] == "null") {
1469 $json = new stdClass();
1470 $json->$socialnetwork = $newval;
1471 $sql_listvalues[$socialkey] = json_encode($json); // Supposed proper escape elsewhere!! @phan-suppress-current-line SqlInjection
1472 } else {
1473 $jsondata = $sql_listvalues[$socialkey];
1474 $json = json_decode($jsondata);
1475 $json->$socialnetwork = $newval;
1476 $sql_listvalues[$socialkey] = json_encode($json); // Supposed proper escape elsewhere!! @phan-suppress-current-line SqlInjection
1477 }
1478 }
1479 } else {
1480 $sql_listfields[] = $this->db->sanitize($fieldname);
1481 // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
1482 if (empty($newval) && $arrayrecord[($key - 1)]['type'] < 0) {
1483 $sql_listvalues[] = ($newval == '0' ? (int) $newval : "null");
1484 } elseif (empty($newval) && $arrayrecord[($key - 1)]['type'] == 0) {
1485 $sql_listvalues[] = "''";
1486 } else {
1487 $sql_listvalues[] = "'".$this->db->escape($newval)."'";
1488 }
1489 }
1490 }
1491 $i++;
1492 }
1493
1494 // We add hidden fields (but only if there is at least one field to add into table)
1495 // We process here all the fields that were declared into the array $this->import_fieldshidden_array of the descriptor file.
1496 // Previously we processed the ->import_fields_array.
1497 if (!empty($sql_listfields) && is_array($objimport->array_import_fieldshidden[0])) {
1498 // Loop on each hidden fields to add them into listfields/listvalues
1499 foreach ($objimport->array_import_fieldshidden[0] as $tmpkey => $tmpval) {
1500 if (!preg_match('/^' . preg_quote($alias, '/') . '\./', $tmpkey)) {
1501 continue; // Not a field of current table
1502 }
1503 $keyfieldcache = preg_replace('/^' . preg_quote($alias, '/') . '\./', '', $tmpkey);
1504
1505 if (in_array($keyfieldcache, $sql_listfields)) { // avoid duplicates in insert
1506 continue;
1507 } elseif ($tmpval == 'user->id') {
1508 $sql_listfields[] = $keyfieldcache; // @phan-suppress-current-line SqlInjection
1509 $sql_listvalues[] = ((int) $user->id);
1510 } elseif (preg_match('/^lastrowid-/', $tmpval)) {
1511 $tmp = explode('-', $tmpval);
1512 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
1513 $sql_listfields[] = $keyfieldcache; // @phan-suppress-current-line SqlInjection
1514 $sql_listvalues[] = (int) $lastinsertid;
1515 $keyfield = $keyfieldcache;
1516 //print $tmpkey."-".$tmpval."-".$sql_listfields."-".$sql_listvalues."<br>";exit;
1517 } elseif (preg_match('/^const-/', $tmpval)) {
1518 $tmp = explode('-', $tmpval, 2);
1519 $sql_listfields[] = $keyfieldcache; // @phan-suppress-current-line SqlInjection
1520 $sql_listvalues[] = "'".$this->db->escape($tmp[1])."'";
1521 } elseif (preg_match('/^rule-/', $tmpval)) { // Example: rule-computeAmount, rule-computeDirection, ...
1522 $fieldname = $tmpkey;
1523 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
1524 if ($objimport->array_import_convertvalue[0][$fieldname]['rule'] == 'compute') {
1525 $file = (empty($objimport->array_import_convertvalue[0][$fieldname]['classfile']) ? $objimport->array_import_convertvalue[0][$fieldname]['file'] : $objimport->array_import_convertvalue[0][$fieldname]['classfile']);
1526 $class = $objimport->array_import_convertvalue[0][$fieldname]['class'];
1527 $method = $objimport->array_import_convertvalue[0][$fieldname]['method'];
1528 $type = $objimport->array_import_convertvalue[0][$fieldname]['type'];
1529 $resultload = dol_include_once($file);
1530 if (empty($resultload)) {
1531 dol_print_error(null, 'Error trying to call file=' . $file . ', class=' . $class . ', method=' . $method);
1532 break;
1533 }
1534 $classinstance = new $class($this->db);
1535 $computedFieldPos = isset($arrayfield[$fieldname]) ? ((int) $arrayfield[$fieldname]) : 0;
1536 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $computedFieldPos));
1537 if (empty($classinstance->error) && empty($classinstance->errors)) {
1538 $fieldArr = explode('.', $fieldname);
1539 if (count($fieldArr) > 0) {
1540 $fieldname = $fieldArr[1];
1541 }
1542
1543 // Set $sql_listfields and $sql_listvalues
1544 $sql_listfields[] = $this->db->sanitize($fieldname);
1545 if ($type == 'int') {
1546 $sql_listvalues[] = (int) $res;
1547 } elseif ($type == 'double') {
1548 $sql_listvalues[] = (float) $res;
1549 } else {
1550 $sql_listvalues[] = "'".$this->db->escape($res)."'";
1551 }
1552 } else {
1553 $this->errors[$error]['type'] = 'CLASSERROR';
1554 $this->errors[$error]['lib'] = implode(
1555 "\n",
1556 array_merge([$classinstance->error], $classinstance->errors)
1557 );
1558 $errorforthistable++;
1559 $error++;
1560 }
1561 }
1562 }
1563 } else {
1564 $this->errors[$error]['lib'] = 'Bad value of profile setup '.$tmpval.' for array_import_fieldshidden';
1565 $this->errors[$error]['type'] = 'Import profile setup';
1566 $error++;
1567 }
1568 }
1569 }
1570 //print 'listfields='.$sql_listfields.'<br>listvalues='.$sql_listvalues.'<br>';
1571
1572 // If no error for this $alias/$tablename, we have a complete $sql_listfields and $sql_listvalues that are defined
1573 // so we can try to make the insert or update now.
1574 if (!$errorforthistable) {
1575 //print "$alias/$tablename/$sql_listfields/$sql_listvalues<br>";
1576 if (!empty($sql_listfields)) {
1577 $updatedone = false;
1578 $insertdone = false;
1579 $where = array();
1580
1581 $is_table_category_link = false;
1582 $sanitizedfname = 'rowid';
1583 if (strpos($tablename, '_categorie_') !== false) {
1584 $is_table_category_link = true;
1585 $sanitizedfname = '*';
1586 }
1587
1588 if (!empty($updatekeys)) {
1589 // We do SELECT to get the rowid, if we already have the rowid, it's to be used below for related tables (extrafields)
1590
1591 if (empty($lastinsertid)) { // No insert done yet for a parent table
1592 $sqlSelect = "SELECT ".$sanitizedfname." FROM ".$this->db->sanitize($tablename);
1593 $data = array_combine($sql_listfields, $sql_listvalues);
1594 $where = array(); // filters to forge SQL request
1595 $filters = array(); // filters to forge output error message
1596 foreach ($updatekeys as $key) {
1597 if (! array_key_exists($key, $objimport->array_import_updatekeys[0])) {
1598 $this->errors[$error]['lib'] = 'You try to search duplicates on field '.dol_string_nohtmltag($key).' that is not an allowed field.';
1599 $this->errors[$error]['type'] = 'UPDATEKEYBADCOLUMN';
1600 $error++;
1601 break;
1602 }
1603 $col = $objimport->array_import_updatekeys[0][$key]; // Label for field name
1604 $keyfordata = preg_replace('/^.*\./i', '', $key); // Keep only field name without table name
1605 $keyfordata = preg_replace('/[^a-zA-Z0-9\._]/', '', $keyfordata); // Sanitize field name
1606
1607 if (isModEnabled("socialnetworks") && strpos($keyfordata, "socialnetworks") !== false) {
1608 $tmp = explode("_", $keyfordata);
1609 $keyfordata = $tmp[0];
1610 $socialnetwork = $tmp[1];
1611 $jsondata = $data[$keyfordata];
1612 $json = json_decode($jsondata);
1613 $stringtosearch = json_encode($socialnetwork).':'.json_encode($json->$socialnetwork);
1614 //var_dump($stringtosearch);
1615 //var_dump($this->db->escape($stringtosearch)); // This provide a value for sql string (but not for a like)
1616 $where[] = $this->db->sanitize($keyfordata)." LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch))."%'";
1617 $filters[] = $col." LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch))."%'";
1618 //var_dump($where[1]); // This provide a value for sql string inside a like
1619 } else {
1620 $sanitizedvalue = $data[$keyfordata]; // @phan-suppress-current-line SqlInjection
1621 /* Not required, the value in $data[$key] seems already sanitized
1622 $type = $objimport->array_import_types[0][$key]['type'] ?? 'string';
1623 if ($type == 'int') {
1624 $sanitizedvalue = (int) $data[$key];
1625 } elseif ($type == 'double') {
1626 $sanitizedvalue = (float) $data[$key];
1627 } else {
1628 $sanitizedvalue = "'".$this->db->escape($data[$key])."'";
1629 }
1630 */
1631 if ((string) $sanitizedvalue === '') {
1632 $this->errors[$error]['lib'] = 'You request to search duplicates on field '.$keyfordata.' but no value was provided for this field on this line.';
1633 $this->errors[$error]['type'] = 'UPDATEKEYBADVALUE';
1634 $error++;
1635 } else {
1636 $where[] = $this->db->sanitize($keyfordata)." = ".$sanitizedvalue;
1637 $filters[] = $col." = ".$sanitizedvalue;
1638 }
1639 }
1640 }
1641 if (!empty($tablewithentity_cache[$tablename])) {
1642 $where[] = "entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
1643 $filters[] = "entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
1644 }
1645 $sqlSelect .= " WHERE ".implode(' AND ', $where);
1646
1647 if (!$error) {
1648 $resql = $this->db->query($sqlSelect);
1649 if ($resql) {
1650 $num_rows = $this->db->num_rows($resql);
1651 if ($num_rows == 1) {
1652 $res = $this->db->fetch_object($resql);
1653 $lastinsertid = $res->rowid;
1654 $keyfield = 'rowid';
1655 if ($is_table_category_link) {
1656 $lastinsertid = 'linktable';
1657 } // used to apply update on tables like llx_categorie_product and avoid being blocked for all file content if at least one entry already exists
1658 $last_insert_id_array[$tablename] = $lastinsertid;
1659 } elseif ($num_rows > 1) {
1660 $this->errors[$error]['lib'] = $langs->trans('MultipleRecordFoundWithTheseFilters', implode(', ', $filters));
1661 $this->errors[$error]['type'] = 'SQL';
1662 $error++;
1663 } else {
1664 // No record found with filters, insert will be tried below
1665 }
1666 } else {
1667 //print 'E';
1668 $this->errors[$error]['lib'] = $this->db->lasterror();
1669 $this->errors[$error]['type'] = 'SQL';
1670 $error++;
1671 }
1672 }
1673 } else {
1674 // We have a last INSERT ID (got by previous pass), so we check if we have a row referencing this foreign key.
1675 // This is required when updating table with some extrafields. When inserting a record in parent table, we can make
1676 // a direct insert into subtable extrafields, but when me wake an update, the insertid is defined and the child record
1677 // may already exists. So we rescan the extrafield table to know if record exists or not for the rowid.
1678 // Note: For extrafield tablename, we have in importfieldshidden_array an entry 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object'
1679 $sqlSelect = "SELECT rowid FROM ".$tablename;
1680 if (empty($keyfield)) {
1681 $keyfield = 'rowid';
1682 }
1683
1684 $sqlSelect .= " WHERE ".$this->db->sanitize($keyfield)." = ".((int) $lastinsertid);
1685
1686 if (!empty($tablewithentity_cache[$tablename])) {
1687 $sqlSelect .= " AND entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
1688 }
1689
1690 $resql = $this->db->query($sqlSelect);
1691 if ($resql) {
1692 $res = $this->db->fetch_object($resql);
1693 if ($this->db->num_rows($resql) == 1) {
1694 // We have a row referencing this last foreign key, continue with UPDATE.
1695 } else {
1696 // No record found referencing this last foreign key,
1697 // force $lastinsertid to 0 so we INSERT below.
1698 $lastinsertid = 0;
1699 }
1700 } else {
1701 //print 'E';
1702 $this->errors[$error]['lib'] = $this->db->lasterror();
1703 $this->errors[$error]['type'] = 'SQL';
1704 $error++;
1705 }
1706 }
1707
1708 if (!empty($lastinsertid)) {
1709 // We db escape social network field because he isn't in field creation
1710 if (in_array("socialnetworks", $sql_listfields)) {
1711 $socialkey = array_search("socialnetworks", $sql_listfields);
1712 $tmpsql = $sql_listvalues[$socialkey];
1713 $sql_listvalues[$socialkey] = "'".$this->db->escape($tmpsql)."'";
1714 }
1715
1716 // Build SQL UPDATE request
1717 $sqlstart = "UPDATE ".$tablename;
1718
1719 $data = array_combine($sql_listfields, $sql_listvalues);
1720 $sql_set = array();
1721 foreach ($data as $key => $val) {
1722 $sql_set[] = $key." = ".$val; // $val was escaped/sanitized previously @phan-suppress-current-line SqlInjection
1723 }
1724 $sqlstart .= " SET ".implode(', ', $sql_set).", import_key = '".$this->db->escape($importid)."'";
1725 if (empty($keyfield)) {
1726 $keyfield = 'rowid';
1727 }
1728
1729 $sqlend = " WHERE ".$this->db->sanitize($keyfield)." = ".((int) $lastinsertid);
1730
1731 if ($is_table_category_link && !empty($where)) {
1732 '@phan-var-force string[] $where';
1733 $sqlend = " WHERE " . implode(' AND ', $where);
1734 }
1735
1736 if (!empty($tablewithentity_cache[$tablename])) {
1737 $sqlend .= " AND entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
1738 }
1739
1740 $sql = $sqlstart.$sqlend;
1741
1742 // Run update request
1743 $resql = $this->db->query($sql);
1744 if ($resql) {
1745 // No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed
1746 $updatedone = true;
1747 if (!$importissimulation && $importtriggermode === 'strict_line') {
1748 $restrigger = $this->triggerImportSqlOperation($tablename, 'update', is_numeric($lastinsertid) ? (int) $lastinsertid : 0, $importid, $user, $langs, $conf);
1749 if ($restrigger < 0) {
1750 // Append: triggerImportSqlOperation() has already pushed the
1751 // messages of the trigger, indexing on $error would overwrite them.
1752 $this->errors[] = array('lib' => $langs->trans('ErrorFailedTriggerCall'), 'type' => 'TRIGGER');
1753 $error++;
1754 }
1755 } elseif (!$importissimulation) {
1756 $this->registerImportBulkEvent($tablename, 'update');
1757 }
1758 } else {
1759 //print 'E';
1760 $this->errors[$error]['lib'] = $this->db->lasterror();
1761 $this->errors[$error]['type'] = 'SQL';
1762 $error++;
1763 }
1764 }
1765 }
1766
1767 // Update not done, we do insert
1768 if (!$error && !$updatedone) {
1769 // We db escape social network field because he isn't in field creation
1770 if (in_array("socialnetworks", $sql_listfields)) {
1771 $socialkey = array_search("socialnetworks", $sql_listfields);
1772 $tmpsql = $sql_listvalues[$socialkey];
1773 $sql_listvalues[$socialkey] = "'".$this->db->escape($tmpsql)."'";
1774 }
1775
1776 // Build SQL INSERT request
1777 $sqlstart = "INSERT INTO ".$tablename."(".implode(", ", $sql_listfields).", import_key";
1778 $sqlend = ") VALUES(".implode(', ', $sql_listvalues).", '".$this->db->escape($importid)."'";
1779 if (!empty($tablewithentity_cache[$tablename])) {
1780 $sqlstart .= ", entity";
1781 $sqlend .= ", ".((int) $conf->entity);
1782 }
1783 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
1784 $sqlstart .= ", ".$this->db->sanitize($objimport->array_import_tables_creator[0][$alias]);
1785 $sqlend .= ", ".((int) $user->id);
1786 }
1787 $sql = $sqlstart.$sqlend.")";
1788 //dol_syslog("import_csv.modules", LOG_DEBUG);
1789
1790 // Run insert request
1791 $resql = $this->db->query($sql);
1792 if ($resql) {
1793 if (!$is_table_category_link) {
1794 $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename); // store the last inserted auto_increment id for each table, so that child tables can be inserted with the appropriate id. This must be done just after the INSERT request, else we risk losing the id (because another sql query will be issued somewhere in Dolibarr).
1795 }
1796 $insertdone = true;
1797 if (!$importissimulation && $importtriggermode === 'strict_line') {
1798 $triggerrowid = (!$is_table_category_link && !empty($last_insert_id_array[$tablename])) ? (int) $last_insert_id_array[$tablename] : 0;
1799 $restrigger = $this->triggerImportSqlOperation($tablename, 'insert', $triggerrowid, $importid, $user, $langs, $conf);
1800 if ($restrigger < 0) {
1801 // Append: triggerImportSqlOperation() has already pushed the
1802 // messages of the trigger, indexing on $error would overwrite them.
1803 $this->errors[] = array('lib' => $langs->trans('ErrorFailedTriggerCall'), 'type' => 'TRIGGER');
1804 $error++;
1805 }
1806 } elseif (!$importissimulation) {
1807 $this->registerImportBulkEvent($tablename, 'insert');
1808 }
1809 } else {
1810 //print 'E';
1811 $this->errors[$error]['lib'] = $this->db->lasterror();
1812 $this->errors[$error]['type'] = 'SQL';
1813 $error++;
1814 }
1815 }
1816 }
1817 /*else
1818 {
1819 dol_print_error(null,'ErrorFieldListEmptyFor '.$alias."/".$tablename);
1820 }*/
1821 }
1822
1823 if ($error) {
1824 break;
1825 }
1826 }
1827
1828 if ($updatedone) {
1829 $this->nbupdate++;
1830 }
1831 if ($insertdone) {
1832 $this->nbinsert++;
1833 }
1834 }
1835
1836 return 1;
1837 }
1838
1839 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1851 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
1852 {
1853 // phpcs:enable
1854 return $this->commonImportInsert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys, 0);
1855 }
1856
1857 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1864 public function write_header_example($outputlangs)
1865 {
1866 // phpcs:enable
1867 $msg = get_class($this)."::".__FUNCTION__." not implemented";
1868 dol_syslog($msg, LOG_ERR);
1869 $this->errors[] = $msg;
1870 $this->error = $msg;
1871 return '';
1872 }
1873
1874 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1882 public function write_title_example($outputlangs, $headerlinefields)
1883 {
1884 // phpcs:enable
1885 $msg = get_class($this)."::".__FUNCTION__." not implemented";
1886 dol_syslog($msg, LOG_ERR);
1887 $this->errors[] = $msg;
1888 $this->error = $msg;
1889 return '';
1890 }
1891
1892 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1900 public function write_record_example($outputlangs, $contentlinevalues)
1901 {
1902 // phpcs:enable
1903 $msg = get_class($this)."::".__FUNCTION__." not implemented";
1904 dol_syslog($msg, LOG_ERR);
1905 $this->errors[] = $msg;
1906 $this->error = $msg;
1907 return '';
1908 }
1909
1910 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1917 public function write_footer_example($outputlangs)
1918 {
1919 // phpcs:enable
1920 $msg = get_class($this)."::".__FUNCTION__." not implemented";
1921 dol_syslog($msg, LOG_ERR);
1922 $this->errors[] = $msg;
1923 $this->error = $msg;
1924 return '';
1925 }
1926}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage triggers.
Parent class for import file readers.
write_title_example($outputlangs, $headerlinefields)
Output title line of an example file for this format.
getLibVersionForKey($key)
Renvoi version de librairie externe du driver.
getImportTriggerActions($tableElement, $operation, $element, $object=null)
Return trigger actions to execute for an import operation done in SQL legacy mode.
getImportTriggerPrefixFromObject($object)
Return trigger prefix from a business object.
getImportTriggerActionsFromHooks($tableElement, $operation, $element, $object=null)
Resolve import trigger actions from hooks.
getDriverDescForKey($key)
Return description of import drivervoi la description d'un driver import.
getElementFromTableWithPrefix($tableNameWithPrefix)
Get element from table name with prefix.
getDriverLabelForKey($key)
Return label of driver import.
getImportGenericTriggerPrefix($element, $tableElement)
Return generic trigger prefix derived from element or table.
import_get_nb_of_lines($file)
Return nb of records.
getLibLabel()
getDriverLabel
getDriverVersionForKey($key)
Renvoi version d'un driver import.
getDriverLabel()
getDriverLabel
getPictoForKey($key)
Return picto of import driver.
getLibLabelForKey($key)
Renvoi libelle de librairie externe du driver.
buildImportTriggerActionFromPrefix($triggerprefix, $operation)
Build trigger action code from prefix and operation.
getImportTriggerMode()
Return effective trigger mode for import flow.
runImportBulkTrigger($importid, $user, $langs, $conf)
Execute one global trigger for fast_bulk mode.
write_record_example($outputlangs, $contentlinevalues)
Output record of an example file for this format.
import_read_record()
Return array of next record in input file.
import_open_file($file)
Open input file.
import_read_header()
Input header line from file.
getDriverVersion()
getDriverVersion
listOfAvailableImportFormat($db, $maxfilenamelength=0)
Load into memory list of available import format.
commonImportInsert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys, $recordpositionbase=0)
Shared implementation of import_insert for CSV/XLSX.
registerImportBulkEvent($tablename, $operation)
Register one SQL operation into bulk trigger stats.
getDriverExtension()
getDriverExtension
getLibVersion()
getLibVersion
write_header_example($outputlangs)
Output header of an example file for this format.
triggerImportSqlOperation($tablename, $operation, $rowid, $importid, $user, $langs, $conf)
Execute triggers for SQL legacy import.
write_footer_example($outputlangs)
Output footer of an example file for this format.
__construct()
Constructor.
import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
Insert a record into database.
getDriverDesc()
getDriverDesc
import_close_file()
Close file handle.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
dol_stringtotime($string, $gm=1, $processnotimeasnoon=0)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Definition date.lib.php:452
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
num2Alpha($n)
Return a numeric value into an Excel like column number.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
const MODULE_MAPPING
This mapping defines the conversion to the current internal names from the alternative allowed names ...
testSqlAndScriptInject($val, $type)
Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET,...
Definition waf.inc.php:103