dolibarr 21.0.0-alpha
import_xlsx.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 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 * or see https://www.gnu.org/
22 */
23
30use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
31use PhpOffice\PhpSpreadsheet\Spreadsheet;
32use PhpOffice\PhpSpreadsheet\Style\Alignment;
33use PhpOffice\PhpSpreadsheet\Shared\Date;
34
35require_once DOL_DOCUMENT_ROOT . '/core/modules/import/modules_import.php';
36
37
42{
46 public $db;
47
51 public $id;
52
57 public $version = 'dolibarr';
58
62 public $label_lib; // Label of external lib used by driver
63
67 public $version_lib; // Version of external lib used by driver
68
72 public $separator;
73
77 public $file; // Path of file
78
82 public $handle; // Handle fichier
83
84 public $cacheconvert = array(); // Array to cache list of value found after a conversion
85
86 public $cachefieldtable = array(); // Array to cache list of value found into fields@tables
87
88 public $nbinsert = 0; // # of insert done during the import
89
90 public $nbupdate = 0; // # of update done during the import
91
95 public $workbook; // temporary import file
96
100 public $record; // current record
101
105 public $headers;
106
107
114 public function __construct($db, $datatoimport)
115 {
116 global $langs;
117
118 parent::__construct();
119 $this->db = $db;
120
121 // this is used as an extension from the example file code, so we have to put xlsx here !!!
122 $this->id = 'xlsx'; // Same value as xxx in file name export_xxx.modules.php
123 $this->label = 'Excel 2007'; // Label of driver
124 $this->desc = $langs->trans("Excel2007FormatDesc");
125 $this->extension = 'xlsx'; // Extension for generated file by this driver
126 $this->picto = 'mime/xls'; // Picto (This is not used by the example file code as Mime type, too bad ...)
127 $this->version = '1.0'; // Driver version
128 $this->phpmin = array(7, 1); // Minimum version of PHP required by module
129
130 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
131 if (versioncompare($this->phpmin, versionphparray()) > 0) {
132 dol_syslog("Module need a higher PHP version");
133 $this->error = "Module need a higher PHP version";
134 return;
135 }
136
137 // If driver use an external library, put its name here
138 require_once DOL_DOCUMENT_ROOT.'/includes/phpoffice/phpspreadsheet/src/autoloader.php';
139 require_once DOL_DOCUMENT_ROOT.'/includes/Psr/autoloader.php';
140 require_once PHPEXCELNEW_PATH.'Spreadsheet.php';
141 $this->workbook = new Spreadsheet();
142
143 // If driver use an external library, put its name here
144 if (!class_exists('ZipArchive')) { // For Excel2007
145 $langs->load("errors");
146 $this->error = $langs->trans('ErrorPHPNeedModule', 'zip');
147 return;
148 }
149 $this->label_lib = 'PhpSpreadSheet';
150 $this->version_lib = '1.8.0';
151
152 $this->datatoimport = $datatoimport;
153 if (preg_match('/^societe_/', $datatoimport)) {
154 $this->thirdpartyobject = new Societe($this->db);
155 }
156 }
157
158
159 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
166 public function write_header_example($outputlangs)
167 {
168 // phpcs:enable
169 global $user, $conf, $langs, $file;
170 // create a temporary object, the final output will be generated in footer
171 $this->workbook->getProperties()->setCreator($user->getFullName($outputlangs) . ' - Dolibarr ' . DOL_VERSION);
172 $this->workbook->getProperties()->setTitle($outputlangs->trans("Import") . ' - ' . $file);
173 $this->workbook->getProperties()->setSubject($outputlangs->trans("Import") . ' - ' . $file);
174 $this->workbook->getProperties()->setDescription($outputlangs->trans("Import") . ' - ' . $file);
175
176 $this->workbook->setActiveSheetIndex(0);
177 $this->workbook->getActiveSheet()->setTitle($outputlangs->trans("Sheet"));
178 $this->workbook->getActiveSheet()->getDefaultRowDimension()->setRowHeight(16);
179
180 return '';
181 }
182
183 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
191 public function write_title_example($outputlangs, $headerlinefields)
192 {
193 // phpcs:enable
194 global $conf;
195 $this->workbook->getActiveSheet()->getStyle('1')->getFont()->setBold(true);
196 $this->workbook->getActiveSheet()->getStyle('1')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
197
198 $col = 1;
199 foreach ($headerlinefields as $field) {
200 $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($col, 1, $outputlangs->transnoentities($field));
201 // set autowidth
202 //$this->workbook->getActiveSheet()->getColumnDimension($this->column2Letter($col + 1))->setAutoSize(true);
203 $col++;
204 }
205
206 return ''; // final output will be generated in footer
207 }
208
209 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
217 public function write_record_example($outputlangs, $contentlinevalues)
218 {
219 // phpcs:enable
220 $col = 1;
221 $row = 2;
222 foreach ($contentlinevalues as $cell) {
223 $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($col, $row, $cell);
224 $col++;
225 }
226
227 return ''; // final output will be generated in footer
228 }
229
230 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
237 public function write_footer_example($outputlangs)
238 {
239 // phpcs:enable
240 // return the file content as a string
241 $tempfile = tempnam(sys_get_temp_dir(), 'dol');
242 $objWriter = new PhpOffice\PhpSpreadsheet\Writer\Xlsx($this->workbook);
243 $objWriter->save($tempfile);
244 $this->workbook->disconnectWorksheets();
245 unset($this->workbook);
246
247 $content = file_get_contents($tempfile);
248 unlink($tempfile);
249 return $content;
250 }
251
252
253
254 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
261 public function import_open_file($file)
262 {
263 // phpcs:enable
264 global $langs;
265 $ret = 1;
266
267 dol_syslog(get_class($this) . "::open_file file=" . $file);
268
269 $reader = new Xlsx();
270 $this->workbook = $reader->load($file);
271 $this->record = 1;
272 $this->file = $file;
273
274 return $ret;
275 }
276
277
278 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
285 public function import_get_nb_of_lines($file)
286 {
287 // phpcs:enable
288 $reader = new Xlsx();
289 $this->workbook = $reader->load($file);
290
291 $rowcount = $this->workbook->getActiveSheet()->getHighestDataRow();
292
293 $this->workbook->disconnectWorksheets();
294 unset($this->workbook);
295
296 return $rowcount;
297 }
298
299
300 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
306 public function import_read_header()
307 {
308 // phpcs:enable
309 // This is not called by the import code !!!
310 $this->headers = array();
311 $xlsx = new Xlsx();
312 $info = $xlsx->listWorksheetinfo($this->file);
313 $countcolumns = $info[0]['totalColumns'];
314 for ($col = 1; $col <= $countcolumns; $col++) {
315 $this->headers[$col] = $this->workbook->getActiveSheet()->getCellByColumnAndRow($col, 1)->getValue();
316 }
317 return 0;
318 }
319
320
321 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
327 public function import_read_record()
328 {
329 // phpcs:enable
330 $rowcount = $this->workbook->getActiveSheet()->getHighestDataRow();
331 if ($this->record > $rowcount) {
332 return false;
333 }
334 $array = array();
335
336 $xlsx = new Xlsx();
337 $info = $xlsx->listWorksheetinfo($this->file);
338 $countcolumns = $info[0]['totalColumns'];
339
340 for ($col = 1; $col <= $countcolumns; $col++) {
341 $tmpcell = $this->workbook->getActiveSheet()->getCellByColumnAndRow($col, $this->record);
342
343 $val = $tmpcell->getValue();
344
345 if (Date::isDateTime($tmpcell)) {
346 // For date field, we use the standard date format string.
347 $dateValue = Date::excelToDateTimeObject($val);
348 $val = $dateValue->format('Y-m-d H:i:s');
349 }
350
351 $array[$col]['val'] = $val;
352 $array[$col]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we consider it null
353 }
354 $this->record++;
355
356 unset($xlsx);
357
358 return $array;
359 }
360
361 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
367 public function import_close_file()
368 {
369 // phpcs:enable
370 $this->workbook->disconnectWorksheets();
371 unset($this->workbook);
372 return 0;
373 }
374
375
376 // What is this doing here ? it is common to all imports, is should be in the parent class
377 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
389 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
390 {
391 // phpcs:enable
392 global $langs, $conf, $user;
393 global $thirdparty_static; // Specific to thirdparty import
394 global $tablewithentity_cache; // Cache to avoid to call desc at each rows on tables
395
396 $error = 0;
397 $warning = 0;
398 $this->errors = array();
399 $this->warnings = array();
400
401 //dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
402
403 //var_dump($array_match_file_to_database);
404 //var_dump($arrayrecord); exit;
405
406 $array_match_database_to_file = array_flip($array_match_file_to_database);
407 $sort_array_match_file_to_database = $array_match_file_to_database;
408 ksort($sort_array_match_file_to_database);
409
410 //var_dump($sort_array_match_file_to_database);
411
412 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[1]['val']))) {
413 //print 'W';
414 $this->warnings[$warning]['lib'] = $langs->trans('EmptyLine');
415 $this->warnings[$warning]['type'] = 'EMPTY';
416 $warning++;
417 } else {
418 $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)
419 $updatedone = false;
420 $insertdone = false;
421 // For each table to insert, me make a separate insert
422 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
423 // Build sql request
424 $sql = '';
425 $listfields = array();
426 $listvalues = array();
427 $i = 0;
428 $errorforthistable = 0;
429
430 // Define $tablewithentity_cache[$tablename] if not already defined
431 if (!isset($tablewithentity_cache[$tablename])) { // keep this test with "isset"
432 dol_syslog("Check if table " . $tablename . " has an entity field");
433 $resql = $this->db->DDLDescTable($tablename, 'entity');
434 if ($resql) {
435 $obj = $this->db->fetch_object($resql);
436 if ($obj) {
437 $tablewithentity_cache[$tablename] = 1; // table contains entity field
438 } else {
439 $tablewithentity_cache[$tablename] = 0; // table does not contain entity field
440 }
441 } else {
442 dol_print_error($this->db);
443 }
444 } else {
445 //dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]);
446 }
447
448 // Define an array to convert fields ('c.ref', ...) into column index (1, ...)
449 $arrayfield = array();
450 foreach ($sort_array_match_file_to_database as $key => $val) {
451 $arrayfield[$val] = ($key);
452 }
453
454 // $arrayrecord start at key 1
455 // $sort_array_match_file_to_database start at key 1
456
457 // Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom)
458 foreach ($sort_array_match_file_to_database as $key => $val) {
459 $fieldalias = preg_replace('/\..*$/i', '', $val);
460 $fieldname = preg_replace('/^.*\./i', '', $val);
461
462 if ($alias != $fieldalias) {
463 continue; // Not a field of current table
464 }
465
466 if ($key <= $maxfields) {
467 // Set $newval with value to insert and set $listvalues with sql request part for insert
468 $newval = '';
469 if ($arrayrecord[($key)]['type'] > 0) {
470 $newval = $arrayrecord[($key)]['val']; // If type of field into input file is not empty string (so defined into input file), we get value
471 }
472
473 //var_dump($newval);var_dump($val);
474 //var_dump($objimport->array_import_convertvalue[0][$val]);
475
476 // Make some tests on $newval
477
478 // Is it a required field ?
479 if (preg_match('/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval == '')) {
480 $this->errors[$error]['lib'] = $langs->trans('ErrorMissingMandatoryValue', num2Alpha($key - 1));
481 $this->errors[$error]['type'] = 'NOTNULL';
482 $errorforthistable++;
483 $error++;
484 } else {
485 // Test format only if field is not a missing mandatory field (field may be a value or empty but not mandatory)
486 // We convert field if required
487 if (!empty($objimport->array_import_convertvalue[0][$val])) {
488 //print 'Must convert '.$newval.' with rule '.join(',',$objimport->array_import_convertvalue[0][$val]).'. ';
489 if ($objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeid'
490 || $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromref'
491 || $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeorlabel'
492 ) {
493 // 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.
494 $isidorref = 'id';
495 if (!is_numeric($newval) && $newval != '' && !preg_match('/^id:/i', $newval)) {
496 $isidorref = 'ref';
497 }
498 $newval = preg_replace('/^(id|ref):/i', '', $newval); // Remove id: or ref: that was used to force if field is id or ref
499 //print 'Newval is now "'.$newval.'" and is type '.$isidorref."<br>\n";
500
501 if ($isidorref == 'ref') { // If value into input import file is a ref, we apply the function defined into descriptor
502 $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']);
503 $class = $objimport->array_import_convertvalue[0][$val]['class'];
504 $method = $objimport->array_import_convertvalue[0][$val]['method'];
505 if ($this->cacheconvert[$file . '_' . $class . '_' . $method . '_'][$newval] != '') {
506 $newval = $this->cacheconvert[$file . '_' . $class . '_' . $method . '_'][$newval];
507 } else {
508 $resultload = dol_include_once($file);
509 if (empty($resultload)) {
510 dol_print_error(null, 'Error trying to call file=' . $file . ', class=' . $class . ', method=' . $method);
511 break;
512 }
513 $classinstance = new $class($this->db);
514 if ($class == 'CGenericDic') {
515 $classinstance->element = $objimport->array_import_convertvalue[0][$val]['element'];
516 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val]['table_element'];
517 }
518
519 // Try the fetch from code or ref
520 $param_array = array('', $newval);
521 if ($class == 'AccountingAccount') {
522 //var_dump($arrayrecord[0]['val']);
523 /*include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancysystem.class.php';
524 $tmpchartofaccount = new AccountancySystem($this->db);
525 $tmpchartofaccount->fetch(getDolGlobalInt('CHARTOFACCOUNTS'));
526 //var_dump($tmpchartofaccount->ref.' - '.$arrayrecord[0]['val']);
527 if ((! (getDolGlobalInt('CHARTOFACCOUNTS') > 0)) || $tmpchartofaccount->ref != $arrayrecord[0]['val'])
528 {
529 $this->errors[$error]['lib']=$langs->trans('ErrorImportOfChartLimitedToCurrentChart', $tmpchartofaccount->ref);
530 $this->errors[$error]['type']='RESTRICTONCURRENCTCHART';
531 $errorforthistable++;
532 $error++;
533 }*/
534 $param_array = array('', $newval, 0, $arrayrecord[0]['val']); // Param to fetch parent from account, in chart.
535 }
536
537 $result = call_user_func_array(array($classinstance, $method), $param_array);
538
539 // If duplicate record found
540 if (!($classinstance->id != '') && $result == -2) {
541 $this->errors[$error]['lib'] = $langs->trans('ErrorMultipleRecordFoundFromRef', $newval);
542 $this->errors[$error]['type'] = 'FOREIGNKEY';
543 $errorforthistable++;
544 $error++;
545 }
546
547 // If not found, try the fetch from label
548 if (!($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeorlabel') {
549 $param_array = array('', '', $newval);
550 call_user_func_array(array($classinstance, $method), $param_array);
551 }
552 $this->cacheconvert[$file . '_' . $class . '_' . $method . '_'][$newval] = $classinstance->id;
553
554 //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. ';
555 if ($classinstance->id != '') { // id may be 0, it is a found value
556 $newval = $classinstance->id;
557 } elseif (! $error) {
558 if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) {
559 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
560 $this->errors[$error]['lib'] = $langs->trans('ErrorFieldValueNotIn', $key, $newval, 'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
561 } elseif (!empty($objimport->array_import_convertvalue[0][$val]['element'])) {
562 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
563 $this->errors[$error]['lib'] = $langs->trans('ErrorFieldRefNotIn', $key, $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
564 } else {
565 $this->errors[$error]['lib'] = 'ErrorBadDefinitionOfImportProfile';
566 }
567 $this->errors[$error]['type'] = 'FOREIGNKEY';
568 $errorforthistable++;
569 $error++;
570 }
571 }
572 }
573 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeandlabel') {
574 $isidorref = 'id';
575 if (!is_numeric($newval) && $newval != '' && !preg_match('/^id:/i', $newval)) {
576 $isidorref = 'ref';
577 }
578 $newval = preg_replace('/^(id|ref):/i', '', $newval);
579
580 if ($isidorref == 'ref') {
581 $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']);
582 $class = $objimport->array_import_convertvalue[0][$val]['class'];
583 $method = $objimport->array_import_convertvalue[0][$val]['method'];
584 $codefromfield = $objimport->array_import_convertvalue[0][$val]['codefromfield'];
585 $code = $arrayrecord[$arrayfield[$codefromfield]]['val'];
586 if ($this->cacheconvert[$file . '_' . $class . '_' . $method . '_' . $code][$newval] != '') {
587 $newval = $this->cacheconvert[$file . '_' . $class . '_' . $method . '_' . $code][$newval];
588 } else {
589 $resultload = dol_include_once($file);
590 if (empty($resultload)) {
591 dol_print_error(null, 'Error trying to call file=' . $file . ', class=' . $class . ', method=' . $method . ', code=' . $code);
592 break;
593 }
594 $classinstance = new $class($this->db);
595 // Try the fetch from code and ref
596 $param_array = array('', $newval, $code);
597 call_user_func_array(array($classinstance, $method), $param_array);
598 $this->cacheconvert[$file . '_' . $class . '_' . $method . '_' . $code][$newval] = $classinstance->id;
599 if ($classinstance->id > 0) { // we found record
600 $newval = $classinstance->id;
601 } else {
602 if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) {
603 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
604 $this->errors[$error]['lib'] = $langs->trans('ErrorFieldValueNotIn', $key, $newval, 'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
605 } else {
606 $this->errors[$error]['lib'] = 'ErrorFieldValueNotIn';
607 }
608 $this->errors[$error]['type'] = 'FOREIGNKEY';
609 $errorforthistable++;
610 $error++;
611 }
612 }
613 }
614 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'zeroifnull') {
615 if (empty($newval)) {
616 $newval = '0';
617 }
618 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchscalefromcodeunits') {
619 $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']);
620 $class = $objimport->array_import_convertvalue[0][$val]['class'];
621 $method = $objimport->array_import_convertvalue[0][$val]['method'];
622 $units = $objimport->array_import_convertvalue[0][$val]['units'];
623 if ($this->cacheconvert[$file . '_' . $class . '_' . $method . '_' . $units][$newval] != '') {
624 $newval = $this->cacheconvert[$file . '_' . $class . '_' . $method . '_' . $units][$newval];
625 } else {
626 $resultload = dol_include_once($file);
627 if (empty($resultload)) {
628 dol_print_error(null, 'Error trying to call file=' . $file . ', class=' . $class . ', method=' . $method . ', units=' . $units);
629 break;
630 }
631 $classinstance = new $class($this->db);
632 // Try the fetch from code or ref
633 call_user_func_array(array($classinstance, $method), array('', '', $newval, $units));
634 $scaleorid = (($objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
635 $this->cacheconvert[$file . '_' . $class . '_' . $method . '_' . $units][$newval] = $scaleorid;
636 //print 'We have made a '.$class.'->'.$method." to get a value from key '".$newval."' and we got '".$scaleorid."'.";exit;
637 if ($classinstance->id > 0) { // we found record
638 $newval = $scaleorid ? $scaleorid : 0;
639 } else {
640 if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) {
641 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
642 $this->errors[$error]['lib'] = $langs->trans('ErrorFieldValueNotIn', $key, $newval, 'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
643 } else {
644 $this->errors[$error]['lib'] = 'ErrorFieldValueNotIn';
645 }
646 $this->errors[$error]['type'] = 'FOREIGNKEY';
647 $errorforthistable++;
648 $error++;
649 }
650 }
651 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomercodeifauto') {
652 if (strtolower($newval) == 'auto') {
653 $this->thirdpartyobject->get_codeclient(null, 0);
654 $newval = $this->thirdpartyobject->code_client;
655 //print 'code_client='.$newval;
656 }
657 if (empty($newval)) {
658 $arrayrecord[($key)]['type'] = -1; // If we get empty value, we will use "null"
659 }
660 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsuppliercodeifauto') {
661 if (strtolower($newval) == 'auto') {
662 $this->thirdpartyobject->get_codefournisseur(null, 1);
663 $newval = $this->thirdpartyobject->code_fournisseur;
664 //print 'code_fournisseur='.$newval;
665 }
666 if (empty($newval)) {
667 $arrayrecord[($key)]['type'] = -1; // If we get empty value, we will use "null"
668 }
669 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomeraccountancycodeifauto') {
670 if (strtolower($newval) == 'auto') {
671 $this->thirdpartyobject->get_codecompta('customer');
672 $newval = $this->thirdpartyobject->code_compta_client;
673 //print 'code_compta='.$newval;
674 }
675 if (empty($newval)) {
676 $arrayrecord[($key)]['type'] = -1; // If we get empty value, we will use "null"
677 }
678 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsupplieraccountancycodeifauto') {
679 if (strtolower($newval) == 'auto') {
680 $this->thirdpartyobject->get_codecompta('supplier');
681 $newval = $this->thirdpartyobject->code_compta_fournisseur;
682 if (empty($newval)) {
683 $arrayrecord[($key)]['type'] = -1; // If we get empty value, we will use "null"
684 }
685 //print 'code_compta_fournisseur='.$newval;
686 }
687 if (empty($newval)) {
688 $arrayrecord[($key)]['type'] = -1; // If we get empty value, we will use "null"
689 }
690 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getrefifauto') {
691 if (strtolower($newval) == 'auto') {
692 $defaultref = '';
693
694 $classModForNumber = $objimport->array_import_convertvalue[0][$val]['class'];
695 $pathModForNumber = $objimport->array_import_convertvalue[0][$val]['path'];
696
697 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
698 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
699 $modForNumber = new $classModForNumber();
700 '@phan-var-force ModeleNumRefMembers|ModeleNumRefCommandes|ModeleNumRefSuppliersInvoices|ModeleNumRefSuppliersOrders|ModeleNumRefProjects|ModeleNumRefTask|ModeleNumRefPropales $modForNumber';
701
702 $tmpobject = null;
703 // Set the object with the date property when we can
704 if (!empty($objimport->array_import_convertvalue[0][$val]['classobject'])) {
705 $pathForObject = $objimport->array_import_convertvalue[0][$val]['pathobject'];
706 require_once DOL_DOCUMENT_ROOT.$pathForObject;
707 $tmpclassobject = $objimport->array_import_convertvalue[0][$val]['classobject'];
708 $tmpobject = new $tmpclassobject($this->db);
709 foreach ($arrayfield as $tmpkey => $tmpval) { // $arrayfield is array('c.ref'=>1, ...)
710 if (in_array($tmpkey, array('t.date', 'c.date_commande'))) {
711 $tmpobject->date = dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]]['val'], 1);
712 }
713 }
714 }
715
716 $defaultref = $modForNumber->getNextValue(null, $tmpobject);
717 }
718 if (is_numeric($defaultref) && $defaultref <= 0) { // If error
719 $defaultref = '';
720 }
721 $newval = $defaultref;
722 }
723 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'compute') {
724 $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']);
725 $class = $objimport->array_import_convertvalue[0][$val]['class'];
726 $method = $objimport->array_import_convertvalue[0][$val]['method'];
727 $resultload = dol_include_once($file);
728 if (empty($resultload)) {
729 dol_print_error(null, 'Error trying to call file=' . $file . ', class=' . $class . ', method=' . $method);
730 break;
731 }
732 $classinstance = new $class($this->db);
733 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
734 if (empty($classinstance->error) && empty($classinstance->errors)) {
735 $newval = $res; // We get new value computed.
736 } else {
737 $this->errors[$error]['type'] = 'CLASSERROR';
738 $this->errors[$error]['lib'] = implode(
739 "\n",
740 array_merge([$classinstance->error], $classinstance->errors)
741 );
742 $errorforthistable++;
743 $error++;
744 }
745 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'numeric') {
746 $newval = price2num($newval);
747 } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'accountingaccount') {
748 if (!getDolGlobalString('ACCOUNTING_MANAGE_ZERO')) {
749 $newval = rtrim(trim($newval), "0");
750 } else {
751 $newval = trim($newval);
752 }
753 }
754
755 //print 'Val to use as insert is '.$newval.'<br>';
756 }
757
758 // Test regexp
759 if (!empty($objimport->array_import_regex[0][$val]) && ($newval != '')) {
760 // If test is "Must exist in a field@table or field@table:..."
761 $reg = array();
762 if (preg_match('/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
763 $field = $reg[1];
764 $table = $reg[2];
765 $filter = !empty($reg[3]) ? substr($reg[3], 1) : '';
766
767 $cachekey = $field . '@' . $table;
768 if (!empty($filter)) {
769 $cachekey .= ':' . $filter;
770 }
771
772 // Load content of field@table into cache array
773 if (!is_array($this->cachefieldtable[$cachekey])) { // If content of field@table not already loaded into cache
774 $sql = "SELECT " . $field . " as aliasfield FROM " . $table;
775 if (!empty($filter)) {
776 $sql .= ' WHERE ' . $filter;
777 }
778
779 $resql = $this->db->query($sql);
780 if ($resql) {
781 $num = $this->db->num_rows($resql);
782 $i = 0;
783 while ($i < $num) {
784 $obj = $this->db->fetch_object($resql);
785 if ($obj) {
786 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
787 }
788 $i++;
789 }
790 } else {
791 dol_print_error($this->db);
792 }
793 }
794
795 // Now we check cache is not empty (should not) and key is into cache
796 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
797 $tableforerror = $table;
798 if (!empty($filter)) {
799 $tableforerror .= ':' . $filter;
800 }
801 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
802 $this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorFieldValueNotIn', $key, $newval, $field, $tableforerror);
803 $this->errors[$error]['type'] = 'FOREIGNKEY';
804 $errorforthistable++;
805 $error++;
806 }
807 } elseif (!preg_match('/' . $objimport->array_import_regex[0][$val] . '/i', $newval)) {
808 // If test is just a static regex
809 //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>";
810 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
811 $this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorWrongValueForField', $key, $newval, $objimport->array_import_regex[0][$val]);
812 $this->errors[$error]['type'] = 'REGEX';
813 $errorforthistable++;
814 $error++;
815 }
816 }
817
818 // Check HTML injection
819 $inj = testSqlAndScriptInject($newval, 0);
820 if ($inj) {
821 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
822 $this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorHtmlInjectionForField', $key, dol_trunc($newval, 100));
823 $this->errors[$error]['type'] = 'HTMLINJECTION';
824 $errorforthistable++;
825 $error++;
826 }
827
828 // Other tests
829 // ...
830 }
831
832 // Define $listfields and $listvalues to build the SQL request
833 if (isModEnabled("socialnetworks") && strpos($fieldname, "socialnetworks") !== false) {
834 if (!in_array("socialnetworks", $listfields)) {
835 $listfields[] = "socialnetworks";
836 $socialkey = array_search("socialnetworks", $listfields); // Return position of 'socialnetworks' key in array. Example socialkey=19
837 $listvalues[$socialkey] = '';
838 }
839 if (!empty($newval) && $arrayrecord[($key)]['type'] > 0) {
840 $socialkey = array_search("socialnetworks", $listfields); // Return position of 'socialnetworks' key in array. Example socialkey=19
841 $socialnetwork = explode("_", $fieldname)[1];
842 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] == "null") {
843 $json = new stdClass();
844 $json->$socialnetwork = $newval;
845 $listvalues[$socialkey] = json_encode($json);
846 } else {
847 $jsondata = $listvalues[$socialkey];
848 $json = json_decode($jsondata);
849 $json->$socialnetwork = $newval;
850 $listvalues[$socialkey] = json_encode($json);
851 }
852 }
853 } else {
854 $listfields[] = $fieldname;
855
856 // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
857 if (empty($newval) && $arrayrecord[($key)]['type'] < 0) {
858 $listvalues[] = ($newval == '0' ? (int) $newval : "null");
859 } elseif (empty($newval) && $arrayrecord[($key)]['type'] == 0) {
860 $listvalues[] = "''";
861 } else {
862 $listvalues[] = "'".$this->db->escape($newval)."'";
863 }
864 }
865 }
866 $i++;
867 }
868
869 // We add hidden fields (but only if there is at least one field to add into table)
870 // We process here all the fields that were declared into the array $this->import_fieldshidden_array of the descriptor file.
871 // Previously we processed the ->import_fields_array.
872 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
873 // Loop on each hidden fields to add them into listfields/listvalues
874 foreach ($objimport->array_import_fieldshidden[0] as $key => $val) {
875 if (!preg_match('/^' . preg_quote($alias, '/') . '\./', $key)) {
876 continue; // Not a field of current table
877 }
878 $keyfield = preg_replace('/^' . preg_quote($alias, '/') . '\./', '', $key);
879
880 if (in_array($keyfield, $listfields)) { // avoid duplicates in insert
881 continue;
882 } elseif ($val == 'user->id') {
883 $listfields[] = $keyfield;
884 $listvalues[] = ((int) $user->id);
885 } elseif (preg_match('/^lastrowid-/', $val)) {
886 $tmp = explode('-', $val);
887 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
888 $listfields[] = $keyfield;
889 $listvalues[] = (int) $lastinsertid;
890 //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit;
891 } elseif (preg_match('/^const-/', $val)) {
892 $tmp = explode('-', $val, 2);
893 $listfields[] = $keyfield;
894 $listvalues[] = "'".$this->db->escape($tmp[1])."'";
895 } elseif (preg_match('/^rule-/', $val)) {
896 $fieldname = $key;
897 $classinstance = null;
898 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
899 if ($objimport->array_import_convertvalue[0][$fieldname]['rule'] == 'compute') {
900 $file = (empty($objimport->array_import_convertvalue[0][$fieldname]['classfile']) ? $objimport->array_import_convertvalue[0][$fieldname]['file'] : $objimport->array_import_convertvalue[0][$fieldname]['classfile']);
901 $class = $objimport->array_import_convertvalue[0][$fieldname]['class'];
902 $method = $objimport->array_import_convertvalue[0][$fieldname]['method'];
903 $type = $objimport->array_import_convertvalue[0][$fieldname]['type'];
904 $resultload = dol_include_once($file);
905 if (empty($resultload)) {
906 dol_print_error(null, 'Error trying to call file=' . $file . ', class=' . $class . ', method=' . $method);
907 break;
908 }
909 $classinstance = new $class($this->db);
910 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
911 $fieldArr = explode('.', $fieldname);
912 if (count($fieldArr) > 0) {
913 $fieldname = $fieldArr[1];
914 }
915
916 // Set $listfields and $listvalues
917 $listfields[] = $fieldname;
918 if ($type == 'int') {
919 $listvalues[] = (int) $res;
920 } elseif ($type == 'double') {
921 $listvalues[] = (float) $res;
922 } else {
923 $listvalues[] = "'".$this->db->escape($res)."'";
924 }
925 } else {
926 $this->errors[$error]['type'] = 'CLASSERROR';
927 if (is_object($classinstance)) { // @phpstan-ignore-line
928 $this->errors[$error]['lib'] = implode(
929 "\n",
930 array_merge([$classinstance->error], $classinstance->errors)
931 );
932 } else {
933 $this->errors[$error]['lib']
934 = "Unexpected rule ".$objimport->array_import_convertvalue[0][$fieldname]['rule'];
935 }
936
937 $errorforthistable++;
938 $error++;
939 }
940 }
941 } else {
942 $this->errors[$error]['lib'] = 'Bad value of profile setup ' . $val . ' for array_import_fieldshidden';
943 $this->errors[$error]['type'] = 'Import profile setup';
944 $error++;
945 }
946 }
947 }
948 //print 'listfields='.$listfields.'<br>listvalues='.$listvalues.'<br>';
949
950 // If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined
951 // so we can try to make the insert or update now.
952 if (!$errorforthistable) {
953 //print "$alias/$tablename/$listfields/$listvalues<br>";
954 if (!empty($listfields)) {
955 $updatedone = false;
956 $insertdone = false;
957
958 $is_table_category_link = false;
959 $fname = 'rowid';
960 if (strpos($tablename, '_categorie_') !== false) {
961 $is_table_category_link = true;
962 $fname = '*';
963 }
964
965 if (!empty($updatekeys)) {
966 // We do SELECT to get the rowid, if we already have the rowid, it's to be used below for related tables (extrafields)
967
968 if (empty($lastinsertid)) { // No insert done yet for a parent table
969 $sqlSelect = "SELECT ".$fname." FROM " . $tablename;
970
971 $data = array_combine($listfields, $listvalues);
972
973 $where = array(); // filters to forge SQL request
974 // @phpstan-ignore-next-line
975 '@phan-var string[] $where';
976 $filters = array(); // filters to forge output error message
977 foreach ($updatekeys as $key) {
978 $col = $objimport->array_import_updatekeys[0][$key];
979 $key = preg_replace('/^.*\./i', '', $key);
980 if (isModEnabled("socialnetworks") && strpos($key, "socialnetworks") !== false) {
981 $tmp = explode("_", $key);
982 $key = $tmp[0];
983 $socialnetwork = $tmp[1];
984 $jsondata = $data[$key];
985 $json = json_decode($jsondata);
986 $stringtosearch = json_encode($socialnetwork).':'.json_encode($json->$socialnetwork);
987 //var_dump($stringtosearch);
988 //var_dump($this->db->escape($stringtosearch)); // This provide a value for sql string (but not for a like)
989 $where[] = $key." LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch))."%'";
990 $filters[] = $col." LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch))."%'";
991 //var_dump($where[1]); // This provide a value for sql string inside a like
992 } else {
993 $where[] = $key.' = '.$data[$key];
994 $filters[] = $col.' = '.$data[$key];
995 }
996 }
997 if (!empty($tablewithentity_cache[$tablename])) {
998 $where[] = "entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
999 $filters[] = "entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
1000 }
1001 $sqlSelect .= " WHERE " . implode(' AND ', $where);
1002
1003 $resql = $this->db->query($sqlSelect);
1004 if ($resql) {
1005 $num_rows = $this->db->num_rows($resql);
1006 if ($num_rows == 1) {
1007 $res = $this->db->fetch_object($resql);
1008 $lastinsertid = $res->rowid;
1009 if ($is_table_category_link) {
1010 $lastinsertid = 'linktable';
1011 } // 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
1012 $last_insert_id_array[$tablename] = $lastinsertid;
1013 } elseif ($num_rows > 1) {
1014 $this->errors[$error]['lib'] = $langs->trans('MultipleRecordFoundWithTheseFilters', implode(', ', $filters));
1015 $this->errors[$error]['type'] = 'SQL';
1016 $error++;
1017 } else {
1018 // No record found with filters, insert will be tried below
1019 }
1020 } else {
1021 //print 'E';
1022 $this->errors[$error]['lib'] = $this->db->lasterror();
1023 $this->errors[$error]['type'] = 'SQL';
1024 $error++;
1025 }
1026 } else {
1027 // We have a last INSERT ID (got by previous pass), so we check if we have a row referencing this foreign key.
1028 // This is required when updating table with some extrafields. When inserting a record in parent table, we can make
1029 // a direct insert into subtable extrafields, but when me wake an update, the insertid is defined and the child record
1030 // may already exists. So we rescan the extrafield table to know if record exists or not for the rowid.
1031 // Note: For extrafield tablename, we have in importfieldshidden_array an entry 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object'
1032 $sqlSelect = "SELECT rowid FROM " . $tablename;
1033
1034
1035 if (empty($keyfield)) {
1036 $keyfield = 'rowid';
1037 }
1038 $sqlSelect .= " WHERE ".$keyfield." = ".((int) $lastinsertid);
1039
1040 if (!empty($tablewithentity_cache[$tablename])) {
1041 $sqlSelect .= " AND entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
1042 }
1043
1044 $resql = $this->db->query($sqlSelect);
1045 if ($resql) {
1046 $res = $this->db->fetch_object($resql);
1047 if ($this->db->num_rows($resql) == 1) {
1048 // We have a row referencing this last foreign key, continue with UPDATE.
1049 } else {
1050 // No record found referencing this last foreign key,
1051 // force $lastinsertid to 0 so we INSERT below.
1052 $lastinsertid = 0;
1053 }
1054 } else {
1055 //print 'E';
1056 $this->errors[$error]['lib'] = $this->db->lasterror();
1057 $this->errors[$error]['type'] = 'SQL';
1058 $error++;
1059 }
1060 }
1061
1062 if (!empty($lastinsertid)) {
1063 // We db escape social network field because he isn't in field creation
1064 if (in_array("socialnetworks", $listfields)) {
1065 $socialkey = array_search("socialnetworks", $listfields);
1066 $tmpsql = $listvalues[$socialkey];
1067 $listvalues[$socialkey] = "'".$this->db->escape($tmpsql)."'";
1068 }
1069
1070 // Build SQL UPDATE request
1071 $sqlstart = "UPDATE " . $tablename;
1072
1073 $data = array_combine($listfields, $listvalues);
1074 $set = array();
1075 foreach ($data as $key => $val) {
1076 $set[] = $key." = ".$val; // $val was escaped/sanitized previously
1077 }
1078 $sqlstart .= " SET " . implode(', ', $set) . ", import_key = '" . $this->db->escape($importid) . "'";
1079
1080 if (empty($keyfield)) {
1081 $keyfield = 'rowid';
1082 }
1083 $sqlend = " WHERE " . $keyfield . " = ".((int) $lastinsertid);
1084
1085 if ($is_table_category_link) {
1086 '@phan-var-force string[] $where';
1087 $sqlend = " WHERE " . implode(' AND ', $where);
1088 }
1089
1090 if (!empty($tablewithentity_cache[$tablename])) {
1091 $sqlend .= " AND entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
1092 }
1093
1094 $sql = $sqlstart . $sqlend;
1095
1096 // Run update request
1097 $resql = $this->db->query($sql);
1098 if ($resql) {
1099 // No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed
1100 $updatedone = true;
1101 } else {
1102 //print 'E';
1103 $this->errors[$error]['lib'] = $this->db->lasterror();
1104 $this->errors[$error]['type'] = 'SQL';
1105 $error++;
1106 }
1107 }
1108 }
1109
1110 // Update not done, we do insert
1111 if (!$error && !$updatedone) {
1112 // We db escape social network field because he isn't in field creation
1113 if (in_array("socialnetworks", $listfields)) {
1114 $socialkey = array_search("socialnetworks", $listfields);
1115 $tmpsql = $listvalues[$socialkey];
1116 $listvalues[$socialkey] = "'".$this->db->escape($tmpsql)."'";
1117 }
1118
1119 // Build SQL INSERT request
1120 $sqlstart = "INSERT INTO " . $tablename . "(" . implode(", ", $listfields) . ", import_key";
1121 $sqlend = ") VALUES(" . implode(', ', $listvalues) . ", '" . $this->db->escape($importid) . "'";
1122 if (!empty($tablewithentity_cache[$tablename])) {
1123 $sqlstart .= ", entity";
1124 $sqlend .= ", " . $conf->entity;
1125 }
1126 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
1127 $sqlstart .= ", " . $objimport->array_import_tables_creator[0][$alias];
1128 $sqlend .= ", " . $user->id;
1129 }
1130 $sql = $sqlstart . $sqlend . ")";
1131 //dol_syslog("import_xlsx.modules", LOG_DEBUG);
1132
1133 // Run insert request
1134 if ($sql) {
1135 $resql = $this->db->query($sql);
1136 if ($resql) {
1137 if (!$is_table_category_link) {
1138 $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).
1139 }
1140 $insertdone = true;
1141 } else {
1142 //print 'E';
1143 $this->errors[$error]['lib'] = $this->db->lasterror();
1144 $this->errors[$error]['type'] = 'SQL';
1145 $error++;
1146 }
1147 }
1148 }
1149 }
1150 /*else
1151 {
1152 dol_print_error(null,'ErrorFieldListEmptyFor '.$alias."/".$tablename);
1153 }*/
1154 }
1155
1156 if ($error) {
1157 break;
1158 }
1159 }
1160
1161 if ($updatedone) {
1162 $this->nbupdate++;
1163 }
1164 if ($insertdone) {
1165 $this->nbinsert++;
1166 }
1167 }
1168
1169 return 1;
1170 }
1171}
versionphparray()
Return version PHP.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
Definition admin.lib.php:69
Class to import Excel files.
__construct($db, $datatoimport)
Constructor.
write_record_example($outputlangs, $contentlinevalues)
Output record of an example file for this format.
import_open_file($file)
Open input file.
import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
Insert a record into database.
write_footer_example($outputlangs)
Output footer of an example file for this format.
import_read_header()
Input header line from file.
write_header_example($outputlangs)
Output header of an example file for this format.
import_read_record()
Return array of next record in input file.
write_title_example($outputlangs, $headerlinefields)
Output title line of an example file for this format.
import_get_nb_of_lines($file)
Return nb of records.
import_close_file()
Close file handle.
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:427
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.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
testSqlAndScriptInject($val, $type)
Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET,...
Definition main.inc.php:123