dolibarr  7.0.0-beta
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@capnetworks.com>
4  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
5  * Copyright (C) 2012-2016 Juanjo Menent <jmenent@2byte.es>
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 <http://www.gnu.org/licenses/>.
19  * or see http://www.gnu.org/
20  */
21 
28 require_once DOL_DOCUMENT_ROOT .'/core/modules/import/modules_import.php';
29 
30 
34 class ImportCsv extends ModeleImports
35 {
36  var $db;
37  var $datatoimport;
38 
39  var $error='';
40  var $errors=array();
41 
42  var $id; // Id of driver
43  var $label; // Label of driver
44  var $extension; // Extension of files imported by driver
45  var $version; // Version of driver
46 
47  var $label_lib; // Label of external lib used by driver
48  var $version_lib; // Version of external lib used by driver
49 
50  var $separator;
51 
52  var $file; // Path of file
53  var $handle; // Handle fichier
54 
55  var $cacheconvert=array(); // Array to cache list of value found after a convertion
56  var $cachefieldtable=array(); // Array to cache list of value found into fields@tables
57 
58  var $nbinsert = 0; // # of insert done during the import
59  var $nbupdate = 0; // # of update done during the import
60 
61 
68  function __construct($db,$datatoimport)
69  {
70  global $conf,$langs;
71  $this->db = $db;
72 
73  $this->separator=(GETPOST('separator')?GETPOST('separator'):(empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE)?',':$conf->global->IMPORT_CSV_SEPARATOR_TO_USE));
74  $this->enclosure='"';
75  $this->escape='"';
76 
77  $this->id='csv'; // Same value then xxx in file name export_xxx.modules.php
78  $this->label='Csv'; // Label of driver
79  $this->desc=$langs->trans("CSVFormatDesc",$this->separator,$this->enclosure,$this->escape);
80  $this->extension='csv'; // Extension for generated file by this driver
81  $this->picto='mime/other'; // Picto
82  $this->version='1.34'; // Driver version
83 
84  // If driver use an external library, put its name here
85  $this->label_lib='Dolibarr';
86  $this->version_lib=DOL_VERSION;
87 
88  $this->datatoimport=$datatoimport;
89  if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db);
90  }
91 
92 
99  function write_header_example($outputlangs)
100  {
101  return '';
102  }
103 
111  function write_title_example($outputlangs,$headerlinefields)
112  {
113  $s=join($this->separator,array_map('cleansep',$headerlinefields));
114  return $s."\n";
115  }
116 
124  function write_record_example($outputlangs,$contentlinevalues)
125  {
126  $s=join($this->separator,array_map('cleansep',$contentlinevalues));
127  return $s."\n";
128  }
129 
136  function write_footer_example($outputlangs)
137  {
138  return '';
139  }
140 
141 
142 
149  function import_open_file($file)
150  {
151  global $langs;
152  $ret=1;
153 
154  dol_syslog(get_class($this)."::open_file file=".$file);
155 
156  ini_set('auto_detect_line_endings',1); // For MAC compatibility
157 
158  $this->handle = fopen(dol_osencode($file), "r");
159  if (! $this->handle)
160  {
161  $langs->load("errors");
162  $this->error=$langs->trans("ErrorFailToOpenFile",$file);
163  $ret=-1;
164  }
165  else
166  {
167  $this->file=$file;
168  }
169 
170  return $ret;
171  }
172 
173 
180  function import_get_nb_of_lines($file)
181  {
182  return dol_count_nb_of_line($file);
183  }
184 
185 
192  {
193  return 0;
194  }
195 
196 
203  {
204  global $conf;
205 
206  $arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape);
207 
208  // End of file
209  if ($arrayres === false) return false;
210 
211  //var_dump($this->handle);
212  //var_dump($arrayres);exit;
213  $newarrayres=array();
214  if ($arrayres && is_array($arrayres))
215  {
216  foreach($arrayres as $key => $val)
217  {
218  if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET)) // Forced charset
219  {
220  if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) == 'utf8')
221  {
222  $newarrayres[$key]['val']=$val;
223  $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null
224  }
225  else
226  {
227  $newarrayres[$key]['val']=utf8_encode($val);
228  $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null
229  }
230  }
231  else // Autodetect format (UTF8 or ISO)
232  {
233  if (utf8_check($val))
234  {
235  $newarrayres[$key]['val']=$val;
236  $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null
237  }
238  else
239  {
240  $newarrayres[$key]['val']=utf8_encode($val);
241  $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null
242  }
243  }
244  }
245 
246  $this->col=count($newarrayres);
247  }
248 
249  return $newarrayres;
250  }
251 
257  function import_close_file()
258  {
259  fclose($this->handle);
260  return 0;
261  }
262 
263 
275  function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid,$updatekeys)
276  {
277  global $langs,$conf,$user;
278  global $thirdparty_static; // Specific to thirdparty import
279  global $tablewithentity_cache; // Cache to avoid to call desc at each rows on tables
280 
281  $error=0;
282  $warning=0;
283  $this->errors=array();
284  $this->warnings=array();
285 
286  //dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
287 
288  //var_dump($array_match_file_to_database);
289  //var_dump($arrayrecord);
290  $array_match_database_to_file=array_flip($array_match_file_to_database);
291  $sort_array_match_file_to_database=$array_match_file_to_database;
292  ksort($sort_array_match_file_to_database);
293 
294  //var_dump($sort_array_match_file_to_database);
295 
296  if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val'])))
297  {
298  //print 'W';
299  $this->warnings[$warning]['lib']=$langs->trans('EmptyLine');
300  $this->warnings[$warning]['type']='EMPTY';
301  $warning++;
302  }
303  else
304  {
305  $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)
306  $updatedone = false;
307  $insertdone = false;
308  // For each table to insert, me make a separate insert
309  foreach($objimport->array_import_tables[0] as $alias => $tablename)
310  {
311  // Build sql request
312  $sql='';
313  $listfields=array();
314  $listvalues=array();
315  $i=0;
316  $errorforthistable=0;
317 
318  // Define $tablewithentity_cache[$tablename] if not already defined
319  if (! isset($tablewithentity_cache[$tablename])) // keep this test with "isset"
320  {
321  dol_syslog("Check if table ".$tablename." has an entity field");
322  $resql=$this->db->DDLDescTable($tablename,'entity');
323  if ($resql)
324  {
325  $obj=$this->db->fetch_object($resql);
326  if ($obj) $tablewithentity_cache[$tablename]=1; // table contains entity field
327  else $tablewithentity_cache[$tablename]=0; // table does not contains entity field
328  }
329  else dol_print_error($this->db);
330  }
331  else
332  {
333  //dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]);
334  }
335 
336 
337  // Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom)
338  foreach($sort_array_match_file_to_database as $key => $val)
339  {
340  $fieldalias=preg_replace('/\..*$/i','',$val);
341  $fieldname=preg_replace('/^.*\./i','',$val);
342 
343  if ($alias != $fieldalias) continue; // Not a field of current table
344 
345  if ($key <= $maxfields)
346  {
347  // Set $newval with value to insert and set $listvalues with sql request part for insert
348  $newval='';
349  if ($arrayrecord[($key-1)]['type'] > 0) $newval=$arrayrecord[($key-1)]['val']; // If type of field into input file is not empty string (so defined into input file), we get value
350 
351  // Make some tests on $newval
352 
353  // Is it a required field ?
354  if (preg_match('/\*/',$objimport->array_import_fields[0][$val]) && ((string) $newval==''))
355  {
356  $this->errors[$error]['lib']=$langs->trans('ErrorMissingMandatoryValue',$key);
357  $this->errors[$error]['type']='NOTNULL';
358  $errorforthistable++;
359  $error++;
360  }
361  // Test format only if field is not a missing mandatory field (field may be a value or empty but not mandatory)
362  else
363  {
364  // We convert field if required
365  if (! empty($objimport->array_import_convertvalue[0][$val]))
366  {
367  //print 'Must convert '.$newval.' with rule '.join(',',$objimport->array_import_convertvalue[0][$val]).'. ';
368  if ($objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeid'
369  || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref'
370  || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel'
371  )
372  {
373  // 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.
374  $isidorref='id';
375  if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) $isidorref='ref';
376  $newval=preg_replace('/^(id|ref):/i','',$newval); // Remove id: or ref: that was used to force if field is id or ref
377  //print 'Val is now '.$newval.' and is type '.$isidorref."<br>\n";
378 
379  if ($isidorref == 'ref') // If value into input import file is a ref, we apply the function defined into descriptor
380  {
381  $file=(empty($objimport->array_import_convertvalue[0][$val]['classfile'])?$objimport->array_import_convertvalue[0][$val]['file']:$objimport->array_import_convertvalue[0][$val]['classfile']);
382  $class=$objimport->array_import_convertvalue[0][$val]['class'];
383  $method=$objimport->array_import_convertvalue[0][$val]['method'];
384  if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '')
385  {
386  $newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
387  }
388  else
389  {
390  $resultload = dol_include_once($file);
391  if (empty($resultload))
392  {
393  dol_print_error('', 'Error trying to call file='.$file.', class='.$class.', method='.$method);
394  break;
395  }
396  $classinstance=new $class($this->db);
397  // Try the fetch from code or ref
398  call_user_func_array(array($classinstance, $method),array('', $newval));
399  // If not found, try the fetch from label
400  if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel')
401  {
402  call_user_func_array(array($classinstance, $method),array('', '', $newval));
403  }
404  $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id;
405  //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. ';
406  if ($classinstance->id != '') // id may be 0, it is a found value
407  {
408  $newval=$classinstance->id;
409  }
410  else
411  {
412  if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key,$newval,'code',$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
413  else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldRefNotIn',$key,$newval,$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
414  else $this->errors[$error]['lib']='ErrorFieldValueNotIn';
415  $this->errors[$error]['type']='FOREIGNKEY';
416  $errorforthistable++;
417  $error++;
418  }
419  }
420  }
421 
422  }
423  elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull')
424  {
425  if (empty($newval)) $newval='0';
426  }
427  elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto')
428  {
429  if (strtolower($newval) == 'auto')
430  {
431  $this->thirpartyobject->get_codeclient(0,0);
432  $newval=$this->thirpartyobject->code_client;
433  //print 'code_client='.$newval;
434  }
435  if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null"
436  }
437  elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto')
438  {
439  if (strtolower($newval) == 'auto')
440  {
441  $newval=$this->thirpartyobject->get_codefournisseur(0,1);
442  $newval=$this->thirpartyobject->code_fournisseur;
443  //print 'code_fournisseur='.$newval;
444  }
445  if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null"
446  }
447  elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto')
448  {
449  if (strtolower($newval) == 'auto')
450  {
451  $this->thirpartyobject->get_codecompta('customer');
452  $newval=$this->thirpartyobject->code_compta;
453  //print 'code_compta='.$newval;
454  }
455  if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null"
456  }
457  elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto')
458  {
459  if (strtolower($newval) == 'auto')
460  {
461  $this->thirpartyobject->get_codecompta('supplier');
462  $newval=$this->thirpartyobject->code_compta_fournisseur;
463  if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null"
464  //print 'code_compta_fournisseur='.$newval;
465  }
466  if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null"
467  }
468  elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto')
469  {
470  $defaultref='';
471  // TODO provide the $modTask (module of generation of ref) as parameter of import_insert function
472  $obj = empty($conf->global->PROJECT_TASK_ADDON)?'mod_task_simple':$conf->global->PROJECT_TASK_ADDON;
473  if (! empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php"))
474  {
475  require_once DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php';
476  $modTask = new $obj;
477  $defaultref = $modTask->getNextValue(null,null);
478  }
479  if (is_numeric($defaultref) && $defaultref <= 0) $defaultref='';
480  $newval=$defaultref;
481  }
482 
483 
484  elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric')
485  {
486  $newval = price2num($newval);
487  }
488 
489  //print 'Val to use as insert is '.$newval.'<br>';
490  }
491 
492  // Test regexp
493  if (! empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
494  {
495  // If test is "Must exist in a field@table"
496  if (preg_match('/^(.*)@(.*)$/',$objimport->array_import_regex[0][$val],$reg))
497  {
498  $field=$reg[1];
499  $table=$reg[2];
500 
501  // Load content of field@table into cache array
502  if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
503  {
504  $sql="SELECT ".$field." as aliasfield FROM ".$table;
505  $resql=$this->db->query($sql);
506  if ($resql)
507  {
508  $num=$this->db->num_rows($resql);
509  $i=0;
510  while ($i < $num)
511  {
512  $obj=$this->db->fetch_object($resql);
513  if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
514  $i++;
515  }
516  }
517  else
518  {
519  dol_print_error($this->db);
520  }
521  }
522 
523  // Now we check cache is not empty (should not) and key is into cache
524  if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval,$this->cachefieldtable[$field.'@'.$table]))
525  {
526  $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table);
527  $this->errors[$error]['type']='FOREIGNKEY';
528  $errorforthistable++;
529  $error++;
530  }
531  }
532  // If test is just a static regex
533  else if (! preg_match('/'.$objimport->array_import_regex[0][$val].'/i',$newval))
534  {
535  //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>";
536  $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]);
537  $this->errors[$error]['type']='REGEX';
538  $errorforthistable++;
539  $error++;
540  }
541  }
542 
543  // Other tests
544  // ...
545  }
546 
547  // Define $listfields and $listvalues to build SQL request
548  $listfields[] = $fieldname;
549 
550  // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
551  if (empty($newval) && $arrayrecord[($key-1)]['type'] < 0) $listvalues[] = ($newval=='0'?$newval:"null");
552  elseif (empty($newval) && $arrayrecord[($key-1)]['type'] == 0) $listvalues[] = "''";
553  else $listvalues[] = "'".$this->db->escape($newval)."'";
554  }
555  $i++;
556  }
557 
558  // We add hidden fields (but only if there is at least one field to add into table)
559  if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0]))
560  {
561  // Loop on each hidden fields to add them into listfields/listvalues
562  foreach($objimport->array_import_fieldshidden[0] as $key => $val)
563  {
564  if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue; // Not a field of current table
565  if ($val == 'user->id')
566  {
567  $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key);
568  $listvalues[] = $user->id;
569  }
570  elseif (preg_match('/^lastrowid-/',$val))
571  {
572  $tmp=explode('-',$val);
573  $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0;
574  $keyfield = preg_replace('/^'.preg_quote($alias).'\./','',$key);
575  $listfields[] = $keyfield;
576  $listvalues[] = $lastinsertid;
577  //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit;
578  }
579  }
580  }
581  //print 'listfields='.$listfields.'<br>listvalues='.$listvalues.'<br>';
582 
583  // If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined
584  if (! $errorforthistable)
585  {
586  //print "$alias/$tablename/$listfields/$listvalues<br>";
587  if (!empty($listfields))
588  {
589  $updatedone = false;
590  $insertdone = false;
591 
592  if (!empty($updatekeys)) {
593  // We do SELECT to get the rowid, if we already have the rowid, it's to be used below for related tables (extrafields)
594  if (empty($lastinsertid)) {
595  $sqlSelect = 'SELECT rowid FROM '.$tablename;
596 
597  $data = array_combine($listfields, $listvalues);
598  $where = array();
599  $filters = array();
600  foreach ($updatekeys as $key) {
601  $col = $objimport->array_import_updatekeys[0][$key];
602  $key=preg_replace('/^.*\./i','',$key);
603  $where[] = $key.' = '.$data[$key];
604  $filters[] = $col.' = '.$data[$key];
605  }
606  $sqlSelect.= ' WHERE '.implode(' AND ', $where);
607 
608  $resql=$this->db->query($sqlSelect);
609  if($resql) {
610  $res = $this->db->fetch_object($resql);
611  if($resql->num_rows == 1) {
612  $lastinsertid = $res->rowid;
613  $last_insert_id_array[$tablename] = $lastinsertid;
614  } else if($resql->num_rows > 1) {
615  $this->errors[$error]['lib']=$langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', '));
616  $this->errors[$error]['type']='SQL';
617  $error++;
618  } else {
619  // No record found with filters, insert will be tried below
620  }
621  }
622  else
623  {
624  //print 'E';
625  $this->errors[$error]['lib']=$this->db->lasterror();
626  $this->errors[$error]['type']='SQL';
627  $error++;
628  }
629  }
630 
631  if (!empty($lastinsertid)) {
632  // Build SQL UPDATE request
633  $sqlstart = 'UPDATE '.$tablename;
634 
635  $data = array_combine($listfields, $listvalues);
636  $set = array();
637  foreach ($data as $key => $val) {
638  $set[] = $key.' = '.$val;
639  }
640  $sqlstart.= ' SET '.implode(', ', $set);
641 
642  if(empty($keyfield)) $keyfield = 'rowid';
643  $sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid;
644 
645  $sql = $sqlstart.$sqlend;
646 
647  // Run update request
648  $resql=$this->db->query($sql);
649  if($resql) {
650  // No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed
651  $updatedone = true;
652  }
653  else
654  {
655  //print 'E';
656  $this->errors[$error]['lib']=$this->db->lasterror();
657  $this->errors[$error]['type']='SQL';
658  $error++;
659  }
660  }
661  }
662 
663  // Update not done, we do insert
664  if (!$error && !$updatedone) {
665  // Build SQL INSERT request
666  $sqlstart = 'INSERT INTO '.$tablename.'('.implode(', ', $listfields).', import_key';
667  $sqlend = ') VALUES('.implode(', ', $listvalues).", '".$importid."'";
668  if (! empty($tablewithentity_cache[$tablename])) {
669  $sqlstart.= ', entity';
670  $sqlend.= ', '.$conf->entity;
671  }
672  if (! empty($objimport->array_import_tables_creator[0][$alias])) {
673  $sqlstart.= ', '.$objimport->array_import_tables_creator[0][$alias];
674  $sqlend.=', '.$user->id;
675  }
676  $sql = $sqlstart.$sqlend.')';
677  dol_syslog("import_csv.modules", LOG_DEBUG);
678 
679  // Run insert request
680  if ($sql)
681  {
682  $resql=$this->db->query($sql);
683  if ($resql)
684  {
685  $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).
686  $insertdone = true;
687  }
688  else
689  {
690  //print 'E';
691  $this->errors[$error]['lib']=$this->db->lasterror();
692  $this->errors[$error]['type']='SQL';
693  $error++;
694  }
695  }
696  }
697  }
698  /*else
699  {
700  dol_print_error('','ErrorFieldListEmptyFor '.$alias."/".$tablename);
701  }*/
702  }
703 
704  if ($error) break;
705  }
706 
707  if($updatedone) $this->nbupdate++;
708  if($insertdone) $this->nbinsert++;
709  }
710 
711  return 1;
712  }
713 
714 }
715 
722 function cleansep($value)
723 {
724  return str_replace(array(',',';'),'/',$value);
725 };
726 
727 
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
write_footer_example($outputlangs)
Output footer of an example file for this format.
import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
Insert a record into database.
cleansep($value)
Clean a string from separator.
import_close_file()
Close file handle.
__construct($db, $datatoimport)
Constructor.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
import_get_nb_of_lines($file)
Return nb of records.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
import_read_record()
Return array of next record in input file.
Class to manage third parties objects (customers, suppliers, prospects...)
utf8_check($str)
Check if a string is in UTF8.
dol_count_nb_of_line($file)
Count number of lines in a file.
Definition: files.lib.php:484
Class to import CSV files.
write_header_example($outputlangs)
Output header of an example file for this format.
Parent class for import file readers.
write_title_example($outputlangs, $headerlinefields)
Output title line of an example file for this format.
write_record_example($outputlangs, $contentlinevalues)
Output record of an example file for this format.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Return a prefix to use for this Dolibarr instance, for session/cookie names or email id...
import_open_file($file)
Open input file.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
import_read_header()
Input header line from file.