dolibarr 23.0.4
import_csv.modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
5 * Copyright (C) 2012-2016 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 * Copyright (C) 2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 * or see https://www.gnu.org/
23 */
24
31require_once DOL_DOCUMENT_ROOT.'/core/modules/import/modules_import.php';
32
33
38{
42 public $db;
43
47 public $id;
48
53 public $version = 'dolibarr';
54
58 public $label_lib;
59
63 public $version_lib;
64
68 public $separator;
69
73 public $file; // Path of file
74
78 public $handle; // File handle
79
80 public $cacheconvert = array(); // Array to cache list of value found after a conversion
81
82 public $cachefieldtable = array(); // Array to cache list of value found into fields@tables
83
84 public $nbinsert = 0; // # of insert done during the import
85
86 public $nbupdate = 0; // # of update done during the import
87
88 public $charset = '';
89
93 public $col;
94
95
102 public function __construct($db, $datatoimport)
103 {
104 global $langs;
105
106 parent::__construct();
107 $this->db = $db;
108
109 $this->separator = (GETPOST('separator') ? GETPOST('separator') : getDolGlobalString('IMPORT_CSV_SEPARATOR_TO_USE', ','));
110 $this->enclosure = '"';
111 $this->escape = '"';
112
113 $this->id = 'csv'; // Same value then xxx in file name export_xxx.modules.php
114 $this->label = 'Csv'; // Label of driver
115 $this->desc = $langs->trans("CSVFormatDesc", $this->separator, $this->enclosure, $this->escape);
116 $this->extension = 'csv'; // Extension for generated file by this driver
117 $this->picto = 'mime/other'; // Picto
118 $this->version = '1.34'; // Driver version
119 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
120
121 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
122 if (versioncompare($this->phpmin, versionphparray()) > 0) {
123 dol_syslog("Module need a higher PHP version");
124 $this->error = "Module need a higher PHP version";
125 return;
126 }
127
128 // If driver use an external library, put its name here
129 $this->label_lib = 'Dolibarr';
130 $this->version_lib = DOL_VERSION;
131
132 $this->datatoimport = $datatoimport;
133 if (preg_match('/^societe_/', $datatoimport)) {
134 $this->thirdpartyobject = new Societe($this->db);
135 }
136 }
137
138
139 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
146 public function write_header_example($outputlangs)
147 {
148 // phpcs:enable
149 return '';
150 }
151
152 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
160 public function write_title_example($outputlangs, $headerlinefields)
161 {
162 // phpcs:enable
163 $s = implode($this->separator, array_map('cleansep', $headerlinefields));
164 return $s."\n";
165 }
166
167 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
175 public function write_record_example($outputlangs, $contentlinevalues)
176 {
177 // phpcs:enable
178 $s = implode($this->separator, array_map('cleansep', $contentlinevalues));
179 return $s."\n";
180 }
181
182 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
189 public function write_footer_example($outputlangs)
190 {
191 // phpcs:enable
192 return '';
193 }
194
195
196 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
203 public function import_open_file($file)
204 {
205 // phpcs:enable
206 global $langs;
207 $ret = 1;
208
209 dol_syslog(get_class($this)."::open_file file=".$file);
210
211 // fgetcsv() only accepts one byte for the separator and for the enclosure (it throws a ValueError otherwise)
212 foreach (array('separator' => $this->separator, 'enclosure' => $this->enclosure) as $name => $value) {
213 if (strlen((string) $value) != 1) {
214 $langs->load("errors");
215 $this->error = $langs->trans("ErrorBadValueForParameter", (string) $value, $name);
216 return -1;
217 }
218 }
219
220 $handle = fopen(dol_osencode($file), "r");
221 if (!$handle) {
222 $langs->load("errors");
223 $this->error = $langs->trans("ErrorFailToOpenFile", $file);
224 $ret = -1;
225 } else {
226 $this->handle = $handle;
227 // Skip the UTF-8 BOM that Excel adds at the beginning of a file, or it would be part of the first value
228 if (fread($this->handle, 3) !== "\xEF\xBB\xBF") {
229 rewind($this->handle);
230 }
231 $this->file = $file;
232 }
233
234 return $ret;
235 }
236
237
238 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
245 public function import_get_nb_of_lines($file)
246 {
247 // phpcs:enable
248 return dol_count_nb_of_line($file);
249 }
250
251
252 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
258 public function import_read_header()
259 {
260 // phpcs:enable
261 return 0;
262 }
263
264
265 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
271 public function import_read_record()
272 {
273 // phpcs:enable
274 global $conf;
275
276 $arrayres = fgetcsv($this->handle, 0, $this->separator, $this->enclosure, $this->escape);
277
278 // End of file
279 if ($arrayres === false) {
280 return false;
281 }
282
283 //var_dump($this->handle);
284 //var_dump($arrayres);exit;
285 $newarrayres = array();
286 $key = 1; // Default value to ensure $key is declared
287
288 if ($arrayres && is_array($arrayres)) {
289 foreach ($arrayres as $key => $val) {
290 if (getDolGlobalString('IMPORT_CSV_FORCE_CHARSET')) { // Forced charset
291 if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) == 'utf8') {
292 $newarrayres[$key]['val'] = $val;
293 $newarrayres[$key]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we consider it's null
294 } else {
295 $newarrayres[$key]['val'] = mb_convert_encoding($val, 'UTF-8', 'ISO-8859-1');
296 $newarrayres[$key]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we consider it's null
297 }
298 } else { // Autodetect format (UTF8 or ISO)
299 if (utf8_check($val)) {
300 $newarrayres[$key]['val'] = $val;
301 $newarrayres[$key]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we consider it's null
302 } else {
303 $newarrayres[$key]['val'] = mb_convert_encoding($val, 'UTF-8', 'ISO-8859-1');
304 $newarrayres[$key]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we consider it's null
305 }
306 }
307 }
308
309 $this->col = count($newarrayres);
310 }
311
312 return $newarrayres;
313 }
314
315 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
321 public function import_close_file()
322 {
323 // phpcs:enable
324 fclose($this->handle);
325 return 0;
326 }
327
328
329 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
341 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
342 {
343 // phpcs:enable
344 global $langs, $conf, $user;
345 global $thirdparty_static; // Specific to thirdparty import
346 global $tablewithentity_cache; // Cache to avoid to call desc at each rows on tables
347
348 $error = 0;
349 $warning = 0;
350 $this->errors = array();
351 $this->warnings = array();
352
353 //dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
354
355 //var_dump($array_match_file_to_database);
356 //var_dump($arrayrecord); exit;
357
358 $array_match_database_to_file = array_flip($array_match_file_to_database);
359 $sort_array_match_file_to_database = $array_match_file_to_database;
360 ksort($sort_array_match_file_to_database);
361
362 //var_dump($sort_array_match_file_to_database);
363
364 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val']))) {
365 //print 'W';
366 $this->warnings[$warning]['lib'] = $langs->trans('EmptyLine');
367 $this->warnings[$warning]['type'] = 'EMPTY';
368 $warning++;
369 } else {
370 $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)
371 $updatedone = false;
372 $insertdone = false;
373 // For each table to insert, me make a separate insert
374 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
375 // Build sql request
376 $sql = '';
377 $listfields = array();
378 $listvalues = array();
379 $i = 0;
380 $errorforthistable = 0;
381
382 // Define $tablewithentity_cache[$tablename] if not already defined
383 if (!isset($tablewithentity_cache[$tablename])) { // keep this test with "isset"
384 dol_syslog("Check if table ".$tablename." has an entity field");
385 $resql = $this->db->DDLDescTable($tablename, 'entity');
386 if ($resql) {
387 $obj = $this->db->fetch_object($resql);
388 if ($obj) {
389 $tablewithentity_cache[$tablename] = 1; // table contains entity field
390 } else {
391 $tablewithentity_cache[$tablename] = 0; // table does not contain entity field
392 }
393 } else {
394 dol_print_error($this->db);
395 }
396 } else {
397 //dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]);
398 }
399
400 // Define an array to convert fields ('c.ref', ...) into column index (1, ...)
401 $arrayfield = array();
402 foreach ($sort_array_match_file_to_database as $key => $val) {
403 $arrayfield[$val] = ($key - 1);
404 }
405
406 // $arrayrecord start at key 0
407 // $sort_array_match_file_to_database start at key 1
408
409 // Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom)
410 foreach ($sort_array_match_file_to_database as $key => $val) {
411 $fieldalias = preg_replace('/\..*$/i', '', $val);
412 $fieldname = preg_replace('/^.*\./i', '', $val);
413
414 if ($alias != $fieldalias) {
415 continue; // Not a field of current table
416 }
417
418 if ($key <= $maxfields) {
419 // Set $newval with value to insert and set $listvalues with sql request part for insert
420 $newval = '';
421 if ($arrayrecord[($key - 1)]['type'] > 0) {
422 $newval = $arrayrecord[($key - 1)]['val']; // If type of field into input file is not empty string (so defined into input file), we get value
423 }
424
425 //var_dump($newval);var_dump($val);
426 //var_dump($objimport->array_import_convertvalue[0][$val]);
427
428 // Make some tests on $newval
429
430 // Is it a required field ?
431 if (preg_match('/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval == '')) {
432 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
433 $this->errors[$error]['lib'] = $langs->trans('ErrorMissingMandatoryValue', $key);
434 $this->errors[$error]['type'] = 'NOTNULL';
435 $errorforthistable++;
436 $error++;
437 } else {
438 // Test format only if field is not a missing mandatory field (field may be a value or empty but not mandatory)
439 // We convert field if required
440 if (!empty($objimport->array_import_convertvalue[0][$val])) {
441 //print 'Must convert '.$newval.' with rule '.join(',',$objimport->array_import_convertvalue[0][$val]).'. ';
442 if ($objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeid'
443 || $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromref'
444 || $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeorlabel'
445 ) {
446 // 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.
447 $isidorref = 'id';
448 if (!is_numeric($newval) && $newval != '' && !preg_match('/^id:/i', $newval)) {
449 $isidorref = 'ref';
450 }
451
452 $newval = preg_replace('/^(id|ref):/i', '', $newval); // Remove id: or ref: that was used to force if field is id or ref
453 //print 'Newval is now "'.$newval.'" and is type '.$isidorref."<br>\n";
454
455 if ($isidorref == 'ref') { // If value into input import file is a ref, we apply the function defined into descriptor
456 $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']);
457 $class = $objimport->array_import_convertvalue[0][$val]['class'];
458 $method = $objimport->array_import_convertvalue[0][$val]['method'];
459 if (isset($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]) && $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != $newval) {
460 $newval = $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
461 } else {
462 $resultload = dol_include_once($file);
463 if (empty($resultload)) {
464 dol_print_error(null, 'Error trying to call file='.$file.', class='.$class.', method='.$method);
465 break;
466 }
467 $classinstance = new $class($this->db);
468 if ($class == 'CGenericDic') {
469 $classinstance->element = $objimport->array_import_convertvalue[0][$val]['element'];
470 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val]['table_element'];
471 }
472
473 // Try the fetch from code or ref
474 $param_array = array('', $newval);
475 if ($class == 'AccountingAccount') {
476 //var_dump($arrayrecord[0]['val']);
477 /*include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancysystem.class.php';
478 $tmpchartofaccount = new AccountancySystem($this->db);
479 $tmpchartofaccount->fetch(getDolGlobalInt('CHARTOFACCOUNTS'));
480 //var_dump($tmpchartofaccount->ref.' - '.$arrayrecord[0]['val']);
481 if ((! (getDolGlobalInt('CHARTOFACCOUNTS') > 0)) || $tmpchartofaccount->ref != $arrayrecord[0]['val'])
482 {
483 $this->errors[$error]['lib']=$langs->trans('ErrorImportOfChartLimitedToCurrentChart', $tmpchartofaccount->ref);
484 $this->errors[$error]['type']='RESTRICTONCURRENCTCHART';
485 $errorforthistable++;
486 $error++;
487 }*/
488 $param_array = array('', $newval, 0, $arrayrecord[0]['val']); // Param to fetch parent from account, in chart.
489 }
490 if ($class == 'CActionComm') {
491 $param_array = array($newval); // CActionComm fetch method have same parameter for id and code
492 }
493 $result = call_user_func_array(array($classinstance, $method), $param_array);
494
495 // If duplicate record found
496 if (!($classinstance->id != '') && $result == -2) {
497 $this->errors[$error]['lib'] = $langs->trans('ErrorMultipleRecordFoundFromRef', $newval);
498 $this->errors[$error]['type'] = 'FOREIGNKEY';
499 $errorforthistable++;
500 $error++;
501 }
502
503 // If not found, try the fetch from label
504 if (!($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeorlabel') {
505 $param_array = array('', '', $newval);
506 call_user_func_array(array($classinstance, $method), $param_array);
507 }
508 $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] = $classinstance->id;
509
510 //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. ';
511 if ($classinstance->id != '') { // id may be 0, it is a found value
512 $newval = $classinstance->id;
513 } elseif (! $error) {
514 if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) {
515 $this->errors[$error]['lib'] = $langs->trans('ErrorFieldValueNotIn', num2Alpha($key - 1), $newval, 'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
516 } elseif (!empty($objimport->array_import_convertvalue[0][$val]['element'])) {
517 $this->errors[$error]['lib'] = $langs->trans('ErrorFieldRefNotIn', num2Alpha($key - 1), $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
518 } else {
519 $this->errors[$error]['lib'] = 'ErrorBadDefinitionOfImportProfile';
520 }
521 $this->errors[$error]['type'] = 'FOREIGNKEY';
522 $errorforthistable++;
523 $error++;
524 }
525 }
526 }
527 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeandlabel') {
528 $isidorref = 'id';
529 if (!is_numeric($newval) && $newval != '' && !preg_match('/^id:/i', $newval)) {
530 $isidorref = 'ref';
531 }
532 $newval = preg_replace('/^(id|ref):/i', '', $newval);
533
534 if ($isidorref == 'ref') {
535 $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']);
536 $class = $objimport->array_import_convertvalue[0][$val]['class'];
537 $method = $objimport->array_import_convertvalue[0][$val]['method'];
538 $codefromfield = $objimport->array_import_convertvalue[0][$val]['codefromfield'];
539 $code = $arrayrecord[$arrayfield[$codefromfield]]['val'];
540 if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'.$code][$newval] != '') {
541 $newval = $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'.$code][$newval];
542 } else {
543 $resultload = dol_include_once($file);
544 if (empty($resultload)) {
545 dol_print_error(null, 'Error trying to call file='.$file.', class='.$class.', method='.$method.', code='.$code);
546 break;
547 }
548 $classinstance = new $class($this->db);
549 // Try the fetch from code and ref
550 $param_array = array('', $newval, $code);
551 call_user_func_array(array($classinstance, $method), $param_array);
552 $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'.$code][$newval] = $classinstance->id;
553 if ($classinstance->id > 0) { // we found record
554 $newval = $classinstance->id;
555 } else {
556 if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) {
557 $this->errors[$error]['lib'] = $langs->trans('ErrorFieldValueNotIn', num2Alpha($key - 1), $newval, 'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
558 } else {
559 $this->errors[$error]['lib'] = 'ErrorFieldValueNotIn';
560 }
561 $this->errors[$error]['type'] = 'FOREIGNKEY';
562 $errorforthistable++;
563 $error++;
564 }
565 }
566 }
567 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'zeroifnull') {
568 if (empty($newval)) {
569 $newval = '0';
570 }
571 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchscalefromcodeunits') {
572 $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']);
573 $class = $objimport->array_import_convertvalue[0][$val]['class'];
574 $method = $objimport->array_import_convertvalue[0][$val]['method'];
575 $units = $objimport->array_import_convertvalue[0][$val]['units'];
576 if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'.$units][$newval] != '') {
577 $newval = $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'.$units][$newval];
578 } else {
579 $resultload = dol_include_once($file);
580 if (empty($resultload)) {
581 dol_print_error(null, 'Error trying to call file='.$file.', class='.$class.', method='.$method.', units='.$units);
582 break;
583 }
584 $classinstance = new $class($this->db);
585 // Try the fetch from code or ref
586 call_user_func_array(array($classinstance, $method), array('', '', $newval, $units));
587 $scaleorid = (($objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
588 $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'.$units][$newval] = $scaleorid;
589 //print 'We have made a '.$class.'->'.$method." to get a value from key '".$newval."' and we got '".$scaleorid."'.";exit;
590 if ($classinstance->id > 0) { // we found record
591 $newval = $scaleorid ? $scaleorid : 0;
592 } else {
593 if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) {
594 $this->errors[$error]['lib'] = $langs->trans('ErrorFieldValueNotIn', num2Alpha($key - 1), $newval, 'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
595 } else {
596 $this->errors[$error]['lib'] = 'ErrorFieldValueNotIn';
597 }
598 $this->errors[$error]['type'] = 'FOREIGNKEY';
599 $errorforthistable++;
600 $error++;
601 }
602 }
603 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomercodeifauto') {
604 if (strtolower($newval) == 'auto') {
605 $this->thirdpartyobject->get_codeclient(null, 0);
606 $newval = $this->thirdpartyobject->code_client;
607 //print 'code_client='.$newval;
608 }
609 if (empty($newval)) {
610 $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
611 }
612 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsuppliercodeifauto') {
613 if (strtolower($newval) == 'auto') {
614 $this->thirdpartyobject->get_codefournisseur(null, 1);
615 $newval = $this->thirdpartyobject->code_fournisseur;
616 //print 'code_fournisseur='.$newval;
617 }
618 if (empty($newval)) {
619 $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
620 }
621 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomeraccountancycodeifauto') {
622 if (strtolower($newval) == 'auto') {
623 $this->thirdpartyobject->get_codecompta('customer');
624 $newval = $this->thirdpartyobject->code_compta_client;
625 //print 'code_compta='.$newval;
626 }
627 if (empty($newval)) {
628 $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
629 }
630 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsupplieraccountancycodeifauto') {
631 if (strtolower($newval) == 'auto') {
632 $this->thirdpartyobject->get_codecompta('supplier');
633 $newval = $this->thirdpartyobject->code_compta_fournisseur;
634 if (empty($newval)) {
635 $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
636 }
637 //print 'code_compta_fournisseur='.$newval;
638 }
639 if (empty($newval)) {
640 $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
641 }
642 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getrefifauto') {
643 if (strtolower($newval) == 'auto') {
644 $defaultref = '';
645
646 $classModForNumber = $objimport->array_import_convertvalue[0][$val]['class'];
647 $pathModForNumber = $objimport->array_import_convertvalue[0][$val]['path'];
648
649 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
650 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
651 $modForNumber = new $classModForNumber();
652 '@phan-var-force ModeleNumRefMembers|ModeleNumRefCommandes|ModeleNumRefSuppliersInvoices|ModeleNumRefSuppliersOrders|ModeleNumRefProjects|ModeleNumRefTask|ModeleNumRefPropales $modForNumber';
653
654 $tmpobject = null;
655 // Set the object with the date property when we can
656 if (!empty($objimport->array_import_convertvalue[0][$val]['classobject'])) {
657 $pathForObject = $objimport->array_import_convertvalue[0][$val]['pathobject'];
658 require_once DOL_DOCUMENT_ROOT.$pathForObject;
659 $tmpclassobject = $objimport->array_import_convertvalue[0][$val]['classobject'];
660 $tmpobject = new $tmpclassobject($this->db);
661 foreach ($arrayfield as $tmpkey => $tmpval) { // $arrayfield is array('c.ref'=>0, ...)
662 if (in_array($tmpkey, array('t.date', 'c.date_commande'))) {
663 $tmpobject->date = dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]]['val'], 1);
664 }
665 }
666 }
667
668 $defaultref = $modForNumber->getNextValue(null, $tmpobject);
669 }
670 if (is_numeric($defaultref) && $defaultref <= 0) { // If error
671 $defaultref = '';
672 }
673 $newval = $defaultref;
674 }
675 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'compute') {
676 $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']);
677 $class = $objimport->array_import_convertvalue[0][$val]['class'];
678 $method = $objimport->array_import_convertvalue[0][$val]['method'];
679 $resultload = dol_include_once($file);
680 if (empty($resultload)) {
681 dol_print_error(null, 'Error trying to call file='.$file.', class='.$class.', method='.$method);
682 break;
683 }
684 $classinstance = new $class($this->db);
685 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, ($key - 1)));
686 if (empty($classinstance->error) && empty($classinstance->errors)) {
687 $newval = $res; // We get new value computed.
688 } else {
689 $this->errors[$error]['type'] = 'CLASSERROR';
690 $this->errors[$error]['lib'] = implode(
691 "\n",
692 array_merge([$classinstance->error], $classinstance->errors)
693 );
694 $errorforthistable++;
695 $error++;
696 }
697 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'numeric') {
698 $newval = price2num($newval);
699 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'accountingaccount') {
700 if (!getDolGlobalString('ACCOUNTING_MANAGE_ZERO')) {
701 $newval = rtrim(trim($newval), "0");
702 } else {
703 $newval = trim($newval);
704 }
705 }
706
707 //print 'Val to use as insert is '.$newval.'<br>';
708 }
709
710 // Test regexp
711 if (!empty($objimport->array_import_regex[0][$val]) && ($newval != '')) {
712 // If test regex string is "field@table" or "field@table:..." (means must exists into table ...)
713 $reg = array();
714 if (preg_match('/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
715 $field = $reg[1];
716 $table = $reg[2];
717 $filter = !empty($reg[3]) ? substr($reg[3], 1) : '';
718
719 $cachekey = $field.'@'.$table;
720 if (!empty($filter)) {
721 $cachekey .= ':'.$filter;
722 }
723
724 // Load content of field@table into cache array
725 if (!is_array($this->cachefieldtable[$cachekey])) { // If content of field@table not already loaded into cache
726 $sql = "SELECT ".$field." as aliasfield FROM ".$table;
727 if (!empty($filter)) {
728 $sql .= ' WHERE '.$filter;
729 }
730
731 $resql = $this->db->query($sql);
732 if ($resql) {
733 $num = $this->db->num_rows($resql);
734 $i = 0;
735 while ($i < $num) {
736 $obj = $this->db->fetch_object($resql);
737 if ($obj) {
738 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
739 }
740 $i++;
741 }
742 } else {
743 dol_print_error($this->db);
744 }
745 }
746
747 // Now we check cache is not empty (should not) and key is in cache
748 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
749 $tableforerror = $table;
750 if (!empty($filter)) {
751 $tableforerror .= ':'.$filter;
752 }
753 $this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorFieldValueNotIn', num2Alpha($key - 1), $newval, $field, $tableforerror);
754 $this->errors[$error]['type'] = 'FOREIGNKEY';
755 $errorforthistable++;
756 $error++;
757 }
758 } elseif (!preg_match('/'.$objimport->array_import_regex[0][$val].'/i', $newval)) {
759 // If test is just a static regex
760 //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>";
761 $this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorWrongValueForField', num2Alpha($key - 1), $newval, $objimport->array_import_regex[0][$val]);
762 $this->errors[$error]['type'] = 'REGEX';
763 $errorforthistable++;
764 $error++;
765 }
766 }
767
768 // Check HTML injection
769 $inj = testSqlAndScriptInject($newval, 0);
770 if ($inj) {
771 $this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorHtmlInjectionForField', num2Alpha($key - 1), dol_trunc($newval, 100));
772 $this->errors[$error]['type'] = 'HTMLINJECTION';
773 $errorforthistable++;
774 $error++;
775 }
776
777 // Other tests
778 // ...
779 }
780
781 // Define $listfields and $listvalues to build the SQL request
782 if (isModEnabled("socialnetworks") && strpos($fieldname, "socialnetworks") !== false) {
783 if (!in_array("socialnetworks", $listfields)) {
784 $listfields[] = "socialnetworks";
785 $socialkey = array_search("socialnetworks", $listfields); // Return position of 'socialnetworks' key in array
786 $listvalues[$socialkey] = '';
787 }
788 //var_dump($newval); var_dump($arrayrecord[($key - 1)]['type']);
789 if (!empty($newval) && $arrayrecord[($key - 1)]['type'] > 0) {
790 $socialkey = array_search("socialnetworks", $listfields); // Return position of 'socialnetworks' key in array
791 //var_dump('sk='.$socialkey); // socialkey=19
792 $socialnetwork = explode("_", $fieldname)[1];
793 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] == "null") {
794 $json = new stdClass();
795 $json->$socialnetwork = $newval;
796 $listvalues[$socialkey] = json_encode($json);
797 } else {
798 $jsondata = $listvalues[$socialkey];
799 $json = json_decode($jsondata);
800 $json->$socialnetwork = $newval;
801 $listvalues[$socialkey] = json_encode($json);
802 }
803 }
804 } else {
805 $listfields[] = $fieldname;
806 // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
807 if (empty($newval) && $arrayrecord[($key - 1)]['type'] < 0) {
808 $listvalues[] = ($newval == '0' ? (int) $newval : "null");
809 } elseif (empty($newval) && $arrayrecord[($key - 1)]['type'] == 0) {
810 $listvalues[] = "''";
811 } else {
812 $listvalues[] = "'".$this->db->escape($newval)."'";
813 }
814 }
815 }
816 $i++;
817 }
818
819 // We add hidden fields (but only if there is at least one field to add into table)
820 // We process here all the fields that were declared into the array $this->import_fieldshidden_array of the descriptor file.
821 // Previously we processed the ->import_fields_array.
822 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
823 // Loop on each hidden fields to add them into listfields/listvalues
824 foreach ($objimport->array_import_fieldshidden[0] as $tmpkey => $tmpval) {
825 if (!preg_match('/^' . preg_quote($alias, '/') . '\./', $tmpkey)) {
826 continue; // Not a field of current table
827 }
828 $keyfieldcache = preg_replace('/^' . preg_quote($alias, '/') . '\./', '', $tmpkey);
829
830 if (in_array($keyfieldcache, $listfields)) { // avoid duplicates in insert
831 continue;
832 } elseif ($tmpval == 'user->id') {
833 $listfields[] = $keyfieldcache;
834 $listvalues[] = ((int) $user->id);
835 } elseif (preg_match('/^lastrowid-/', $tmpval)) {
836 $tmp = explode('-', $tmpval);
837 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
838 $listfields[] = $keyfieldcache;
839 $listvalues[] = (int) $lastinsertid;
840 $keyfield = $keyfieldcache;
841 //print $tmpkey."-".$tmpval."-".$listfields."-".$listvalues."<br>";exit;
842 } elseif (preg_match('/^const-/', $tmpval)) {
843 $tmp = explode('-', $tmpval, 2);
844 $listfields[] = $keyfieldcache;
845 $listvalues[] = "'".$this->db->escape($tmp[1])."'";
846 } elseif (preg_match('/^rule-/', $tmpval)) { // Example: rule-computeAmount, rule-computeDirection, ...
847 $fieldname = $tmpkey;
848 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
849 if ($objimport->array_import_convertvalue[0][$fieldname]['rule'] == 'compute') {
850 $file = (empty($objimport->array_import_convertvalue[0][$fieldname]['classfile']) ? $objimport->array_import_convertvalue[0][$fieldname]['file'] : $objimport->array_import_convertvalue[0][$fieldname]['classfile']);
851 $class = $objimport->array_import_convertvalue[0][$fieldname]['class'];
852 $method = $objimport->array_import_convertvalue[0][$fieldname]['method'];
853 $type = $objimport->array_import_convertvalue[0][$fieldname]['type'];
854 $resultload = dol_include_once($file);
855 if (empty($resultload)) {
856 dol_print_error(null, 'Error trying to call file=' . $file . ', class=' . $class . ', method=' . $method);
857 break;
858 }
859 $classinstance = new $class($this->db);
860 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, ($key - 1)));
861 if (empty($classinstance->error) && empty($classinstance->errors)) {
862 $fieldArr = explode('.', $fieldname);
863 if (count($fieldArr) > 0) {
864 $fieldname = $fieldArr[1];
865 }
866
867 // Set $listfields and $listvalues
868 $listfields[] = $fieldname;
869 if ($type == 'int') {
870 $listvalues[] = (int) $res;
871 } elseif ($type == 'double') {
872 $listvalues[] = (float) $res;
873 } else {
874 $listvalues[] = "'".$this->db->escape($res)."'";
875 }
876 } else {
877 $this->errors[$error]['type'] = 'CLASSERROR';
878 $this->errors[$error]['lib'] = implode(
879 "\n",
880 array_merge([$classinstance->error], $classinstance->errors)
881 );
882 $errorforthistable++;
883 $error++;
884 }
885 }
886 }
887 } else {
888 $this->errors[$error]['lib'] = 'Bad value of profile setup '.$tmpval.' for array_import_fieldshidden';
889 $this->errors[$error]['type'] = 'Import profile setup';
890 $error++;
891 }
892 }
893 }
894 //print 'listfields='.$listfields.'<br>listvalues='.$listvalues.'<br>';
895
896 // If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined
897 // so we can try to make the insert or update now.
898 if (!$errorforthistable) {
899 //print "$alias/$tablename/$listfields/$listvalues<br>";
900 if (!empty($listfields)) {
901 $updatedone = false;
902 $insertdone = false;
903
904 $is_table_category_link = false;
905 $fname = 'rowid';
906 if (strpos($tablename, '_categorie_') !== false) {
907 $is_table_category_link = true;
908 $fname = '*';
909 }
910
911 if (!empty($updatekeys)) {
912 // We do SELECT to get the rowid, if we already have the rowid, it's to be used below for related tables (extrafields)
913
914 if (empty($lastinsertid)) { // No insert done yet for a parent table
915 $sqlSelect = "SELECT ".$fname." FROM ".$tablename;
916 $data = array_combine($listfields, $listvalues);
917 $where = array(); // filters to forge SQL request
918 $filters = array(); // filters to forge output error message
919 foreach ($updatekeys as $key) {
920 $col = $objimport->array_import_updatekeys[0][$key];
921 $key = preg_replace('/^.*\./i', '', $key);
922 if (isModEnabled("socialnetworks") && strpos($key, "socialnetworks") !== false) {
923 $tmp = explode("_", $key);
924 $key = $tmp[0];
925 $socialnetwork = $tmp[1];
926 $jsondata = $data[$key];
927 $json = json_decode($jsondata);
928 $stringtosearch = json_encode($socialnetwork).':'.json_encode($json->$socialnetwork);
929 //var_dump($stringtosearch);
930 //var_dump($this->db->escape($stringtosearch)); // This provide a value for sql string (but not for a like)
931 $where[] = $key." LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch))."%'";
932 $filters[] = $col." LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch))."%'";
933 //var_dump($where[1]); // This provide a value for sql string inside a like
934 } else {
935 $where[] = $key.' = '.$data[$key];
936 $filters[] = $col.' = '.$data[$key];
937 }
938 }
939 if (!empty($tablewithentity_cache[$tablename])) {
940 $where[] = "entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
941 $filters[] = "entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
942 }
943 $sqlSelect .= " WHERE ".implode(' AND ', $where);
944
945 $resql = $this->db->query($sqlSelect);
946 if ($resql) {
947 $num_rows = $this->db->num_rows($resql);
948 if ($num_rows == 1) {
949 $res = $this->db->fetch_object($resql);
950 $lastinsertid = $res->rowid;
951 $keyfield = 'rowid';
952 if ($is_table_category_link) {
953 $lastinsertid = 'linktable';
954 } // 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
955 $last_insert_id_array[$tablename] = $lastinsertid;
956 } elseif ($num_rows > 1) {
957 $this->errors[$error]['lib'] = $langs->trans('MultipleRecordFoundWithTheseFilters', implode(', ', $filters));
958 $this->errors[$error]['type'] = 'SQL';
959 $error++;
960 } else {
961 // No record found with filters, insert will be tried below
962 }
963 } else {
964 //print 'E';
965 $this->errors[$error]['lib'] = $this->db->lasterror();
966 $this->errors[$error]['type'] = 'SQL';
967 $error++;
968 }
969 } else {
970 // We have a last INSERT ID (got by previous pass), so we check if we have a row referencing this foreign key.
971 // This is required when updating table with some extrafields. When inserting a record in parent table, we can make
972 // a direct insert into subtable extrafields, but when me wake an update, the insertid is defined and the child record
973 // may already exists. So we rescan the extrafield table to know if record exists or not for the rowid.
974 // Note: For extrafield tablename, we have in importfieldshidden_array an entry 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object'
975 $sqlSelect = "SELECT rowid FROM ".$tablename;
976 if (empty($keyfield)) {
977 $keyfield = 'rowid';
978 }
979
980 $sqlSelect .= " WHERE ".$keyfield." = ".((int) $lastinsertid);
981
982 if (!empty($tablewithentity_cache[$tablename])) {
983 $sqlSelect .= " AND entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
984 }
985
986 $resql = $this->db->query($sqlSelect);
987 if ($resql) {
988 $res = $this->db->fetch_object($resql);
989 if ($this->db->num_rows($resql) == 1) {
990 // We have a row referencing this last foreign key, continue with UPDATE.
991 } else {
992 // No record found referencing this last foreign key,
993 // force $lastinsertid to 0 so we INSERT below.
994 $lastinsertid = 0;
995 }
996 } else {
997 //print 'E';
998 $this->errors[$error]['lib'] = $this->db->lasterror();
999 $this->errors[$error]['type'] = 'SQL';
1000 $error++;
1001 }
1002 }
1003
1004 if (!empty($lastinsertid)) {
1005 // We db escape social network field because he isn't in field creation
1006 if (in_array("socialnetworks", $listfields)) {
1007 $socialkey = array_search("socialnetworks", $listfields);
1008 $tmpsql = $listvalues[$socialkey];
1009 $listvalues[$socialkey] = "'".$this->db->escape($tmpsql)."'";
1010 }
1011
1012 // Build SQL UPDATE request
1013 $sqlstart = "UPDATE ".$tablename;
1014
1015 $data = array_combine($listfields, $listvalues);
1016 $set = array();
1017 foreach ($data as $key => $val) {
1018 $set[] = $key." = ".$val; // $val was escaped/sanitized previously
1019 }
1020 $sqlstart .= " SET ".implode(', ', $set).", import_key = '".$this->db->escape($importid)."'";
1021 if (empty($keyfield)) {
1022 $keyfield = 'rowid';
1023 }
1024
1025 $sqlend = " WHERE ".$keyfield." = ".((int) $lastinsertid);
1026
1027 if ($is_table_category_link) {
1028 '@phan-var-force string[] $where';
1029 $sqlend = " WHERE " . implode(' AND ', $where);
1030 }
1031
1032 if (!empty($tablewithentity_cache[$tablename])) {
1033 $sqlend .= " AND entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
1034 }
1035
1036 $sql = $sqlstart.$sqlend;
1037
1038 // Run update request
1039 $resql = $this->db->query($sql);
1040 if ($resql) {
1041 // No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed
1042 $updatedone = true;
1043 } else {
1044 //print 'E';
1045 $this->errors[$error]['lib'] = $this->db->lasterror();
1046 $this->errors[$error]['type'] = 'SQL';
1047 $error++;
1048 }
1049 }
1050 }
1051
1052 // Update not done, we do insert
1053 if (!$error && !$updatedone) {
1054 // We db escape social network field because he isn't in field creation
1055 if (in_array("socialnetworks", $listfields)) {
1056 $socialkey = array_search("socialnetworks", $listfields);
1057 $tmpsql = $listvalues[$socialkey];
1058 $listvalues[$socialkey] = "'".$this->db->escape($tmpsql)."'";
1059 }
1060
1061 // Build SQL INSERT request
1062 $sqlstart = "INSERT INTO ".$tablename."(".implode(", ", $listfields).", import_key";
1063 $sqlend = ") VALUES(".implode(', ', $listvalues).", '".$this->db->escape($importid)."'";
1064 if (!empty($tablewithentity_cache[$tablename])) {
1065 $sqlstart .= ", entity";
1066 $sqlend .= ", ".$conf->entity;
1067 }
1068 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
1069 $sqlstart .= ", ".$objimport->array_import_tables_creator[0][$alias];
1070 $sqlend .= ", ".$user->id;
1071 }
1072 $sql = $sqlstart.$sqlend.")";
1073 //dol_syslog("import_csv.modules", LOG_DEBUG);
1074
1075 // Run insert request
1076 if ($sql) {
1077 $resql = $this->db->query($sql);
1078 if ($resql) {
1079 if (!$is_table_category_link) {
1080 $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).
1081 }
1082 $insertdone = true;
1083 } else {
1084 //print 'E';
1085 $this->errors[$error]['lib'] = $this->db->lasterror();
1086 $this->errors[$error]['type'] = 'SQL';
1087 $error++;
1088 }
1089 }
1090 }
1091 }
1092 /*else
1093 {
1094 dol_print_error(null,'ErrorFieldListEmptyFor '.$alias."/".$tablename);
1095 }*/
1096 }
1097
1098 if ($error) {
1099 break;
1100 }
1101 }
1102
1103 if ($updatedone) {
1104 $this->nbupdate++;
1105 }
1106 if ($insertdone) {
1107 $this->nbinsert++;
1108 }
1109 }
1110
1111 return 1;
1112 }
1113}
1114
1121function cleansep($value)
1122{
1123 return str_replace(array(',', ';'), '/', $value);
1124}
versionphparray()
Return version PHP.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays), to know if a version (a,b,c) is lower than (x,...
Definition admin.lib.php:71
Class to import CSV files.
write_header_example($outputlangs)
Output header of an example file for this format.
import_get_nb_of_lines($file)
Return nb of records.
import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
Insert a record into database.
__construct($db, $datatoimport)
Constructor.
import_read_record()
Return array of next record in input file.
write_record_example($outputlangs, $contentlinevalues)
Output record of an example file for this format.
write_footer_example($outputlangs)
Output footer of an example file for this format.
import_close_file()
Close file handle.
import_read_header()
Input header line from file.
write_title_example($outputlangs, $headerlinefields)
Output title line of an example file for this format.
import_open_file($file)
Open input file.
Parent class for import file readers.
getElementFromTableWithPrefix($tableNameWithPrefix)
Get element from table name with prefix.
Class to manage third parties objects (customers, suppliers, prospects...)
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...
Definition date.lib.php:449
dol_count_nb_of_line($file)
Count number of lines in a file.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
num2Alpha($n)
Return a numeric value into an Excel like column number.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
utf8_check($str)
Check if a string is in UTF8.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
cleansep($value)
Clean a string from separator.
testSqlAndScriptInject($val, $type)
Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET,...
Definition waf.inc.php:103