@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | */ |
31 | 31 | class ModeleImports |
32 | 32 | { |
33 | - public $db; |
|
34 | - public $datatoimport; |
|
33 | + public $db; |
|
34 | + public $datatoimport; |
|
35 | 35 | |
36 | - public $error=''; |
|
36 | + public $error=''; |
|
37 | 37 | |
38 | - public $id; // Id of driver |
|
38 | + public $id; // Id of driver |
|
39 | 39 | public $label; // Label of driver |
40 | 40 | public $extension; // Extension of files imported by driver |
41 | 41 | public $version; // Version of driver |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | |
55 | 55 | /** |
56 | - * Constructor |
|
56 | + * Constructor |
|
57 | 57 | */ |
58 | 58 | function __construct() |
59 | 59 | { |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | function getDriverId() |
69 | 69 | { |
70 | - return $this->id; |
|
70 | + return $this->id; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | function getDriverLabel() |
79 | 79 | { |
80 | - return $this->label; |
|
80 | + return $this->label; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | function getDriverDesc() |
89 | 89 | { |
90 | - return $this->desc; |
|
90 | + return $this->desc; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | function getDriverExtension() |
99 | 99 | { |
100 | - return $this->extension; |
|
100 | + return $this->extension; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | function getDriverVersion() |
109 | 109 | { |
110 | - return $this->version; |
|
110 | + return $this->version; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | function getLibLabel() |
119 | 119 | { |
120 | - return $this->label_lib; |
|
120 | + return $this->label_lib; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -127,16 +127,16 @@ discard block |
||
127 | 127 | */ |
128 | 128 | function getLibVersion() |
129 | 129 | { |
130 | - return $this->version_lib; |
|
130 | + return $this->version_lib; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | |
134 | 134 | /** |
135 | 135 | * Charge en memoire et renvoie la liste des modeles actifs |
136 | 136 | * |
137 | - * @param DoliDB $db Database handler |
|
138 | - * @param integer $maxfilenamelength Max length of value to show |
|
139 | - * @return array List of templates |
|
137 | + * @param DoliDB $db Database handler |
|
138 | + * @param integer $maxfilenamelength Max length of value to show |
|
139 | + * @return array List of templates |
|
140 | 140 | */ |
141 | 141 | function liste_modeles($db,$maxfilenamelength=0) |
142 | 142 | { |
@@ -148,35 +148,35 @@ discard block |
||
148 | 148 | // Recherche des fichiers drivers imports disponibles |
149 | 149 | $var=True; |
150 | 150 | $i=0; |
151 | - if (is_resource($handle)) |
|
152 | - { |
|
153 | - while (($file = readdir($handle))!==false) |
|
154 | - { |
|
155 | - if (preg_match("/^import_(.*)\.modules\.php/i",$file,$reg)) |
|
156 | - { |
|
157 | - $moduleid=$reg[1]; |
|
158 | - |
|
159 | - // Loading Class |
|
160 | - $file = $dir."/import_".$moduleid.".modules.php"; |
|
161 | - $classname = "Import".ucfirst($moduleid); |
|
162 | - |
|
163 | - require_once $file; |
|
164 | - $module = new $classname($db,''); |
|
165 | - |
|
166 | - // Picto |
|
167 | - $this->picto[$module->id]=$module->picto; |
|
168 | - // Driver properties |
|
169 | - $this->driverlabel[$module->id]=$module->getDriverLabel(''); |
|
170 | - $this->driverdesc[$module->id]=$module->getDriverDesc(''); |
|
171 | - $this->driverversion[$module->id]=$module->getDriverVersion(''); |
|
172 | - // If use an external lib |
|
173 | - $this->liblabel[$module->id]=$module->getLibLabel(''); |
|
174 | - $this->libversion[$module->id]=$module->getLibVersion(''); |
|
175 | - |
|
176 | - $i++; |
|
177 | - } |
|
178 | - } |
|
179 | - } |
|
151 | + if (is_resource($handle)) |
|
152 | + { |
|
153 | + while (($file = readdir($handle))!==false) |
|
154 | + { |
|
155 | + if (preg_match("/^import_(.*)\.modules\.php/i",$file,$reg)) |
|
156 | + { |
|
157 | + $moduleid=$reg[1]; |
|
158 | + |
|
159 | + // Loading Class |
|
160 | + $file = $dir."/import_".$moduleid.".modules.php"; |
|
161 | + $classname = "Import".ucfirst($moduleid); |
|
162 | + |
|
163 | + require_once $file; |
|
164 | + $module = new $classname($db,''); |
|
165 | + |
|
166 | + // Picto |
|
167 | + $this->picto[$module->id]=$module->picto; |
|
168 | + // Driver properties |
|
169 | + $this->driverlabel[$module->id]=$module->getDriverLabel(''); |
|
170 | + $this->driverdesc[$module->id]=$module->getDriverDesc(''); |
|
171 | + $this->driverversion[$module->id]=$module->getDriverVersion(''); |
|
172 | + // If use an external lib |
|
173 | + $this->liblabel[$module->id]=$module->getLibLabel(''); |
|
174 | + $this->libversion[$module->id]=$module->getLibVersion(''); |
|
175 | + |
|
176 | + $i++; |
|
177 | + } |
|
178 | + } |
|
179 | + } |
|
180 | 180 | |
181 | 181 | return array_keys($this->driverlabel); |
182 | 182 | } |
@@ -33,23 +33,23 @@ discard block |
||
33 | 33 | public $db; |
34 | 34 | public $datatoimport; |
35 | 35 | |
36 | - public $error=''; |
|
36 | + public $error = ''; |
|
37 | 37 | |
38 | - public $id; // Id of driver |
|
39 | - public $label; // Label of driver |
|
40 | - public $extension; // Extension of files imported by driver |
|
41 | - public $version; // Version of driver |
|
38 | + public $id; // Id of driver |
|
39 | + public $label; // Label of driver |
|
40 | + public $extension; // Extension of files imported by driver |
|
41 | + public $version; // Version of driver |
|
42 | 42 | |
43 | - public $label_lib; // Label of external lib used by driver |
|
44 | - public $version_lib; // Version of external lib used by driver |
|
43 | + public $label_lib; // Label of external lib used by driver |
|
44 | + public $version_lib; // Version of external lib used by driver |
|
45 | 45 | |
46 | 46 | // Array of all drivers |
47 | - public $driverlabel=array(); |
|
48 | - public $driverdesc=array(); |
|
49 | - public $driverversion=array(); |
|
47 | + public $driverlabel = array(); |
|
48 | + public $driverdesc = array(); |
|
49 | + public $driverversion = array(); |
|
50 | 50 | |
51 | - public $liblabel=array(); |
|
52 | - public $libversion=array(); |
|
51 | + public $liblabel = array(); |
|
52 | + public $libversion = array(); |
|
53 | 53 | |
54 | 54 | |
55 | 55 | /** |
@@ -138,40 +138,40 @@ discard block |
||
138 | 138 | * @param integer $maxfilenamelength Max length of value to show |
139 | 139 | * @return array List of templates |
140 | 140 | */ |
141 | - function liste_modeles($db,$maxfilenamelength=0) |
|
141 | + function liste_modeles($db, $maxfilenamelength = 0) |
|
142 | 142 | { |
143 | 143 | dol_syslog(get_class($this)."::liste_modeles"); |
144 | 144 | |
145 | - $dir=DOL_DOCUMENT_ROOT."/core/modules/import/"; |
|
146 | - $handle=opendir($dir); |
|
145 | + $dir = DOL_DOCUMENT_ROOT."/core/modules/import/"; |
|
146 | + $handle = opendir($dir); |
|
147 | 147 | |
148 | 148 | // Recherche des fichiers drivers imports disponibles |
149 | - $var=True; |
|
150 | - $i=0; |
|
149 | + $var = True; |
|
150 | + $i = 0; |
|
151 | 151 | if (is_resource($handle)) |
152 | 152 | { |
153 | - while (($file = readdir($handle))!==false) |
|
153 | + while (($file = readdir($handle)) !== false) |
|
154 | 154 | { |
155 | - if (preg_match("/^import_(.*)\.modules\.php/i",$file,$reg)) |
|
155 | + if (preg_match("/^import_(.*)\.modules\.php/i", $file, $reg)) |
|
156 | 156 | { |
157 | - $moduleid=$reg[1]; |
|
157 | + $moduleid = $reg[1]; |
|
158 | 158 | |
159 | 159 | // Loading Class |
160 | 160 | $file = $dir."/import_".$moduleid.".modules.php"; |
161 | 161 | $classname = "Import".ucfirst($moduleid); |
162 | 162 | |
163 | 163 | require_once $file; |
164 | - $module = new $classname($db,''); |
|
164 | + $module = new $classname($db, ''); |
|
165 | 165 | |
166 | 166 | // Picto |
167 | - $this->picto[$module->id]=$module->picto; |
|
167 | + $this->picto[$module->id] = $module->picto; |
|
168 | 168 | // Driver properties |
169 | - $this->driverlabel[$module->id]=$module->getDriverLabel(''); |
|
170 | - $this->driverdesc[$module->id]=$module->getDriverDesc(''); |
|
171 | - $this->driverversion[$module->id]=$module->getDriverVersion(''); |
|
169 | + $this->driverlabel[$module->id] = $module->getDriverLabel(''); |
|
170 | + $this->driverdesc[$module->id] = $module->getDriverDesc(''); |
|
171 | + $this->driverversion[$module->id] = $module->getDriverVersion(''); |
|
172 | 172 | // If use an external lib |
173 | - $this->liblabel[$module->id]=$module->getLibLabel(''); |
|
174 | - $this->libversion[$module->id]=$module->getLibVersion(''); |
|
173 | + $this->liblabel[$module->id] = $module->getLibLabel(''); |
|
174 | + $this->libversion[$module->id] = $module->getLibVersion(''); |
|
175 | 175 | |
176 | 176 | $i++; |
177 | 177 | } |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | */ |
34 | 34 | class ImportCsv extends ModeleImports |
35 | 35 | { |
36 | - var $db; |
|
37 | - var $datatoimport; |
|
36 | + var $db; |
|
37 | + var $datatoimport; |
|
38 | 38 | |
39 | 39 | var $error=''; |
40 | 40 | var $errors=array(); |
41 | 41 | |
42 | - var $id; // Id of driver |
|
42 | + var $id; // Id of driver |
|
43 | 43 | var $label; // Label of driver |
44 | 44 | var $extension; // Extension of files imported by driver |
45 | 45 | var $version; // Version of driver |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | function import_get_nb_of_lines($file) |
181 | 181 | { |
182 | 182 | return dol_count_nb_of_line($file); |
183 | - } |
|
183 | + } |
|
184 | 184 | |
185 | 185 | |
186 | 186 | /** |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid,$updatekeys) |
276 | 276 | { |
277 | 277 | global $langs,$conf,$user; |
278 | - global $thirdparty_static; // Specific to thirdparty import |
|
278 | + global $thirdparty_static; // Specific to thirdparty import |
|
279 | 279 | global $tablewithentity_cache; // Cache to avoid to call desc at each rows on tables |
280 | 280 | |
281 | 281 | $error=0; |
@@ -337,10 +337,10 @@ discard block |
||
337 | 337 | // Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom) |
338 | 338 | foreach($sort_array_match_file_to_database as $key => $val) |
339 | 339 | { |
340 | - $fieldalias=preg_replace('/\..*$/i','',$val); |
|
341 | - $fieldname=preg_replace('/^.*\./i','',$val); |
|
340 | + $fieldalias=preg_replace('/\..*$/i','',$val); |
|
341 | + $fieldname=preg_replace('/^.*\./i','',$val); |
|
342 | 342 | |
343 | - if ($alias != $fieldalias) continue; // Not a field of current table |
|
343 | + if ($alias != $fieldalias) continue; // Not a field of current table |
|
344 | 344 | |
345 | 345 | if ($key <= $maxfields) |
346 | 346 | { |
@@ -361,135 +361,135 @@ discard block |
||
361 | 361 | // Test format only if field is not a missing mandatory field (field may be a value or empty but not mandatory) |
362 | 362 | else |
363 | 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"; |
|
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 | 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 |
|
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 | 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 | - { |
|
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 | 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 | - } |
|
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 | 482 | |
483 | 483 | |
484 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric') |
|
485 | - { |
|
486 | - $newval = price2num($newval); |
|
487 | - } |
|
484 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric') |
|
485 | + { |
|
486 | + $newval = price2num($newval); |
|
487 | + } |
|
488 | 488 | |
489 | - //print 'Val to use as insert is '.$newval.'<br>'; |
|
490 | - } |
|
489 | + //print 'Val to use as insert is '.$newval.'<br>'; |
|
490 | + } |
|
491 | 491 | |
492 | - // Test regexp |
|
492 | + // Test regexp |
|
493 | 493 | if (! empty($objimport->array_import_regex[0][$val]) && ($newval != '')) |
494 | 494 | { |
495 | 495 | // If test is "Must exist in a field@table" |
@@ -525,14 +525,14 @@ discard block |
||
525 | 525 | { |
526 | 526 | $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table); |
527 | 527 | $this->errors[$error]['type']='FOREIGNKEY'; |
528 | - $errorforthistable++; |
|
528 | + $errorforthistable++; |
|
529 | 529 | $error++; |
530 | 530 | } |
531 | 531 | } |
532 | 532 | // If test is just a static regex |
533 | 533 | else if (! preg_match('/'.$objimport->array_import_regex[0][$val].'/i',$newval)) |
534 | 534 | { |
535 | - //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>"; |
|
535 | + //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>"; |
|
536 | 536 | $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]); |
537 | 537 | $this->errors[$error]['type']='REGEX'; |
538 | 538 | $errorforthistable++; |
@@ -558,25 +558,25 @@ discard block |
||
558 | 558 | // We add hidden fields (but only if there is at least one field to add into table) |
559 | 559 | if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) |
560 | 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; |
|
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 | 574 | $keyfield = preg_replace('/^'.preg_quote($alias).'\./','',$key); |
575 | - $listfields[] = $keyfield; |
|
576 | - $listvalues[] = $lastinsertid; |
|
577 | - //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit; |
|
578 | - } |
|
579 | - } |
|
575 | + $listfields[] = $keyfield; |
|
576 | + $listvalues[] = $lastinsertid; |
|
577 | + //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit; |
|
578 | + } |
|
579 | + } |
|
580 | 580 | } |
581 | 581 | //print 'listfields='.$listfields.'<br>listvalues='.$listvalues.'<br>'; |
582 | 582 | |
@@ -681,8 +681,8 @@ discard block |
||
681 | 681 | $resql=$this->db->query($sql); |
682 | 682 | if ($resql) |
683 | 683 | { |
684 | - $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). |
|
685 | - $insertdone = true; |
|
684 | + $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). |
|
685 | + $insertdone = true; |
|
686 | 686 | } |
687 | 687 | else |
688 | 688 | { |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | }*/ |
701 | 701 | } |
702 | 702 | |
703 | - if ($error) break; |
|
703 | + if ($error) break; |
|
704 | 704 | } |
705 | 705 | |
706 | 706 | if($updatedone) $this->nbupdate++; |
@@ -86,7 +86,9 @@ discard block |
||
86 | 86 | $this->version_lib=DOL_VERSION; |
87 | 87 | |
88 | 88 | $this->datatoimport=$datatoimport; |
89 | - if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db); |
|
89 | + if (preg_match('/^societe_/',$datatoimport)) { |
|
90 | + $this->thirpartyobject=new Societe($this->db); |
|
91 | + } |
|
90 | 92 | } |
91 | 93 | |
92 | 94 | |
@@ -161,8 +163,7 @@ discard block |
||
161 | 163 | $langs->load("errors"); |
162 | 164 | $this->error=$langs->trans("ErrorFailToOpenFile",$file); |
163 | 165 | $ret=-1; |
164 | - } |
|
165 | - else |
|
166 | + } else |
|
166 | 167 | { |
167 | 168 | $this->file=$file; |
168 | 169 | } |
@@ -206,7 +207,9 @@ discard block |
||
206 | 207 | $arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape); |
207 | 208 | |
208 | 209 | // End of file |
209 | - if ($arrayres === false) return false; |
|
210 | + if ($arrayres === false) { |
|
211 | + return false; |
|
212 | + } |
|
210 | 213 | |
211 | 214 | //var_dump($this->handle); |
212 | 215 | //var_dump($arrayres);exit; |
@@ -215,27 +218,26 @@ discard block |
||
215 | 218 | { |
216 | 219 | foreach($arrayres as $key => $val) |
217 | 220 | { |
218 | - if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET)) // Forced charset |
|
221 | + if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET)) { |
|
222 | + // Forced charset |
|
219 | 223 | { |
220 | 224 | if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) == 'utf8') |
221 | 225 | { |
222 | 226 | $newarrayres[$key]['val']=$val; |
227 | + } |
|
223 | 228 | $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null |
224 | - } |
|
225 | - else |
|
229 | + } else |
|
226 | 230 | { |
227 | 231 | $newarrayres[$key]['val']=utf8_encode($val); |
228 | 232 | $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null |
229 | 233 | } |
230 | - } |
|
231 | - else // Autodetect format (UTF8 or ISO) |
|
234 | + } else // Autodetect format (UTF8 or ISO) |
|
232 | 235 | { |
233 | 236 | if (utf8_check($val)) |
234 | 237 | { |
235 | 238 | $newarrayres[$key]['val']=$val; |
236 | 239 | $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null |
237 | - } |
|
238 | - else |
|
240 | + } else |
|
239 | 241 | { |
240 | 242 | $newarrayres[$key]['val']=utf8_encode($val); |
241 | 243 | $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null |
@@ -299,8 +301,7 @@ discard block |
||
299 | 301 | $this->warnings[$warning]['lib']=$langs->trans('EmptyLine'); |
300 | 302 | $this->warnings[$warning]['type']='EMPTY'; |
301 | 303 | $warning++; |
302 | - } |
|
303 | - else |
|
304 | + } else |
|
304 | 305 | { |
305 | 306 | $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 | 307 | $updatedone = false; |
@@ -316,19 +317,27 @@ discard block |
||
316 | 317 | $errorforthistable=0; |
317 | 318 | |
318 | 319 | // Define $tablewithentity_cache[$tablename] if not already defined |
319 | - if (! isset($tablewithentity_cache[$tablename])) // keep this test with "isset" |
|
320 | + if (! isset($tablewithentity_cache[$tablename])) { |
|
321 | + // keep this test with "isset" |
|
320 | 322 | { |
321 | 323 | dol_syslog("Check if table ".$tablename." has an entity field"); |
324 | + } |
|
322 | 325 | $resql=$this->db->DDLDescTable($tablename,'entity'); |
323 | 326 | if ($resql) |
324 | 327 | { |
325 | 328 | $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 |
|
329 | + if ($obj) { |
|
330 | + $tablewithentity_cache[$tablename]=1; |
|
331 | + } |
|
332 | + // table contains entity field |
|
333 | + else { |
|
334 | + $tablewithentity_cache[$tablename]=0; |
|
335 | + } |
|
336 | + // table does not contains entity field |
|
337 | + } else { |
|
338 | + dol_print_error($this->db); |
|
328 | 339 | } |
329 | - else dol_print_error($this->db); |
|
330 | - } |
|
331 | - else |
|
340 | + } else |
|
332 | 341 | { |
333 | 342 | //dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]); |
334 | 343 | } |
@@ -340,13 +349,19 @@ discard block |
||
340 | 349 | $fieldalias=preg_replace('/\..*$/i','',$val); |
341 | 350 | $fieldname=preg_replace('/^.*\./i','',$val); |
342 | 351 | |
343 | - if ($alias != $fieldalias) continue; // Not a field of current table |
|
352 | + if ($alias != $fieldalias) { |
|
353 | + continue; |
|
354 | + } |
|
355 | + // Not a field of current table |
|
344 | 356 | |
345 | 357 | if ($key <= $maxfields) |
346 | 358 | { |
347 | 359 | // Set $newval with value to insert and set $listvalues with sql request part for insert |
348 | 360 | $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 |
|
361 | + if ($arrayrecord[($key-1)]['type'] > 0) { |
|
362 | + $newval=$arrayrecord[($key-1)]['val']; |
|
363 | + } |
|
364 | + // If type of field into input file is not empty string (so defined into input file), we get value |
|
350 | 365 | |
351 | 366 | // Make some tests on $newval |
352 | 367 | |
@@ -372,20 +387,23 @@ discard block |
||
372 | 387 | { |
373 | 388 | // 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 | 389 | $isidorref='id'; |
375 | - if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) $isidorref='ref'; |
|
390 | + if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) { |
|
391 | + $isidorref='ref'; |
|
392 | + } |
|
376 | 393 | $newval=preg_replace('/^(id|ref):/i','',$newval); // Remove id: or ref: that was used to force if field is id or ref |
377 | 394 | //print 'Val is now '.$newval.' and is type '.$isidorref."<br>\n"; |
378 | 395 | |
379 | - if ($isidorref == 'ref') // If value into input import file is a ref, we apply the function defined into descriptor |
|
396 | + if ($isidorref == 'ref') { |
|
397 | + // If value into input import file is a ref, we apply the function defined into descriptor |
|
380 | 398 | { |
381 | 399 | $file=(empty($objimport->array_import_convertvalue[0][$val]['classfile'])?$objimport->array_import_convertvalue[0][$val]['file']:$objimport->array_import_convertvalue[0][$val]['classfile']); |
400 | + } |
|
382 | 401 | $class=$objimport->array_import_convertvalue[0][$val]['class']; |
383 | 402 | $method=$objimport->array_import_convertvalue[0][$val]['method']; |
384 | 403 | if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '') |
385 | 404 | { |
386 | 405 | $newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]; |
387 | - } |
|
388 | - else |
|
406 | + } else |
|
389 | 407 | { |
390 | 408 | $resultload = dol_include_once($file); |
391 | 409 | if (empty($resultload)) |
@@ -403,15 +421,20 @@ discard block |
||
403 | 421 | } |
404 | 422 | $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id; |
405 | 423 | //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 |
|
424 | + if ($classinstance->id != '') { |
|
425 | + // id may be 0, it is a found value |
|
407 | 426 | { |
408 | 427 | $newval=$classinstance->id; |
409 | 428 | } |
410 | - else |
|
429 | + } else |
|
411 | 430 | { |
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'; |
|
431 | + if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) { |
|
432 | + $this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key,$newval,'code',$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict'])); |
|
433 | + } else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) { |
|
434 | + $this->errors[$error]['lib']=$langs->trans('ErrorFieldRefNotIn',$key,$newval,$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element'])); |
|
435 | + } else { |
|
436 | + $this->errors[$error]['lib']='ErrorFieldValueNotIn'; |
|
437 | + } |
|
415 | 438 | $this->errors[$error]['type']='FOREIGNKEY'; |
416 | 439 | $errorforthistable++; |
417 | 440 | $error++; |
@@ -419,12 +442,12 @@ discard block |
||
419 | 442 | } |
420 | 443 | } |
421 | 444 | |
422 | - } |
|
423 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull') |
|
445 | + } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull') |
|
424 | 446 | { |
425 | - if (empty($newval)) $newval='0'; |
|
426 | - } |
|
427 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto') |
|
447 | + if (empty($newval)) { |
|
448 | + $newval='0'; |
|
449 | + } |
|
450 | + } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto') |
|
428 | 451 | { |
429 | 452 | if (strtolower($newval) == 'auto') |
430 | 453 | { |
@@ -432,9 +455,11 @@ discard block |
||
432 | 455 | $newval=$this->thirpartyobject->code_client; |
433 | 456 | //print 'code_client='.$newval; |
434 | 457 | } |
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') |
|
458 | + if (empty($newval)) { |
|
459 | + $arrayrecord[($key-1)]['type']=-1; |
|
460 | + } |
|
461 | + // If we get empty value, we will use "null" |
|
462 | + } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto') |
|
438 | 463 | { |
439 | 464 | if (strtolower($newval) == 'auto') |
440 | 465 | { |
@@ -442,9 +467,11 @@ discard block |
||
442 | 467 | $newval=$this->thirpartyobject->code_fournisseur; |
443 | 468 | //print 'code_fournisseur='.$newval; |
444 | 469 | } |
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') |
|
470 | + if (empty($newval)) { |
|
471 | + $arrayrecord[($key-1)]['type']=-1; |
|
472 | + } |
|
473 | + // If we get empty value, we will use "null" |
|
474 | + } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto') |
|
448 | 475 | { |
449 | 476 | if (strtolower($newval) == 'auto') |
450 | 477 | { |
@@ -452,20 +479,27 @@ discard block |
||
452 | 479 | $newval=$this->thirpartyobject->code_compta; |
453 | 480 | //print 'code_compta='.$newval; |
454 | 481 | } |
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') |
|
482 | + if (empty($newval)) { |
|
483 | + $arrayrecord[($key-1)]['type']=-1; |
|
484 | + } |
|
485 | + // If we get empty value, we will use "null" |
|
486 | + } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto') |
|
458 | 487 | { |
459 | 488 | if (strtolower($newval) == 'auto') |
460 | 489 | { |
461 | 490 | $this->thirpartyobject->get_codecompta('supplier'); |
462 | 491 | $newval=$this->thirpartyobject->code_compta_fournisseur; |
463 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
492 | + if (empty($newval)) { |
|
493 | + $arrayrecord[($key-1)]['type']=-1; |
|
494 | + } |
|
495 | + // If we get empty value, we will use "null" |
|
464 | 496 | //print 'code_compta_fournisseur='.$newval; |
465 | 497 | } |
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') |
|
498 | + if (empty($newval)) { |
|
499 | + $arrayrecord[($key-1)]['type']=-1; |
|
500 | + } |
|
501 | + // If we get empty value, we will use "null" |
|
502 | + } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto') |
|
469 | 503 | { |
470 | 504 | $defaultref=''; |
471 | 505 | // TODO provide the $modTask (module of generation of ref) as parameter of import_insert function |
@@ -476,12 +510,11 @@ discard block |
||
476 | 510 | $modTask = new $obj; |
477 | 511 | $defaultref = $modTask->getNextValue(null,null); |
478 | 512 | } |
479 | - if (is_numeric($defaultref) && $defaultref <= 0) $defaultref=''; |
|
513 | + if (is_numeric($defaultref) && $defaultref <= 0) { |
|
514 | + $defaultref=''; |
|
515 | + } |
|
480 | 516 | $newval=$defaultref; |
481 | - } |
|
482 | - |
|
483 | - |
|
484 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric') |
|
517 | + } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric') |
|
485 | 518 | { |
486 | 519 | $newval = price2num($newval); |
487 | 520 | } |
@@ -499,9 +532,11 @@ discard block |
||
499 | 532 | $table=$reg[2]; |
500 | 533 | |
501 | 534 | // 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 |
|
535 | + if (! is_array($this->cachefieldtable[$field.'@'.$table])) { |
|
536 | + // If content of field@table not already loaded into cache |
|
503 | 537 | { |
504 | 538 | $sql="SELECT ".$field." as aliasfield FROM ".$table; |
539 | + } |
|
505 | 540 | $resql=$this->db->query($sql); |
506 | 541 | if ($resql) |
507 | 542 | { |
@@ -510,11 +545,12 @@ discard block |
||
510 | 545 | while ($i < $num) |
511 | 546 | { |
512 | 547 | $obj=$this->db->fetch_object($resql); |
513 | - if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield; |
|
548 | + if ($obj) { |
|
549 | + $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield; |
|
550 | + } |
|
514 | 551 | $i++; |
515 | 552 | } |
516 | - } |
|
517 | - else |
|
553 | + } else |
|
518 | 554 | { |
519 | 555 | dol_print_error($this->db); |
520 | 556 | } |
@@ -548,9 +584,13 @@ discard block |
||
548 | 584 | $listfields[] = $fieldname; |
549 | 585 | |
550 | 586 | // 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)."'"; |
|
587 | + if (empty($newval) && $arrayrecord[($key-1)]['type'] < 0) { |
|
588 | + $listvalues[] = ($newval=='0'?$newval:"null"); |
|
589 | + } elseif (empty($newval) && $arrayrecord[($key-1)]['type'] == 0) { |
|
590 | + $listvalues[] = "''"; |
|
591 | + } else { |
|
592 | + $listvalues[] = "'".$this->db->escape($newval)."'"; |
|
593 | + } |
|
554 | 594 | } |
555 | 595 | $i++; |
556 | 596 | } |
@@ -561,13 +601,15 @@ discard block |
||
561 | 601 | // Loop on each hidden fields to add them into listfields/listvalues |
562 | 602 | foreach($objimport->array_import_fieldshidden[0] as $key => $val) |
563 | 603 | { |
564 | - if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue; // Not a field of current table |
|
604 | + if (! preg_match('/^'.preg_quote($alias).'\./', $key)) { |
|
605 | + continue; |
|
606 | + } |
|
607 | + // Not a field of current table |
|
565 | 608 | if ($val == 'user->id') |
566 | 609 | { |
567 | 610 | $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key); |
568 | 611 | $listvalues[] = $user->id; |
569 | - } |
|
570 | - elseif (preg_match('/^lastrowid-/',$val)) |
|
612 | + } elseif (preg_match('/^lastrowid-/',$val)) |
|
571 | 613 | { |
572 | 614 | $tmp=explode('-',$val); |
573 | 615 | $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0; |
@@ -617,8 +659,7 @@ discard block |
||
617 | 659 | } else { |
618 | 660 | // No record found with filters, insert will be tried below |
619 | 661 | } |
620 | - } |
|
621 | - else |
|
662 | + } else |
|
622 | 663 | { |
623 | 664 | //print 'E'; |
624 | 665 | $this->errors[$error]['lib']=$this->db->lasterror(); |
@@ -638,7 +679,9 @@ discard block |
||
638 | 679 | } |
639 | 680 | $sqlstart.= ' SET '.implode(', ', $set); |
640 | 681 | |
641 | - if(empty($keyfield)) $keyfield = 'rowid'; |
|
682 | + if(empty($keyfield)) { |
|
683 | + $keyfield = 'rowid'; |
|
684 | + } |
|
642 | 685 | $sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid; |
643 | 686 | |
644 | 687 | $sql = $sqlstart.$sqlend; |
@@ -648,8 +691,7 @@ discard block |
||
648 | 691 | if($resql) { |
649 | 692 | // No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed |
650 | 693 | $updatedone = true; |
651 | - } |
|
652 | - else |
|
694 | + } else |
|
653 | 695 | { |
654 | 696 | //print 'E'; |
655 | 697 | $this->errors[$error]['lib']=$this->db->lasterror(); |
@@ -683,8 +725,7 @@ discard block |
||
683 | 725 | { |
684 | 726 | $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). |
685 | 727 | $insertdone = true; |
686 | - } |
|
687 | - else |
|
728 | + } else |
|
688 | 729 | { |
689 | 730 | //print 'E'; |
690 | 731 | $this->errors[$error]['lib']=$this->db->lasterror(); |
@@ -700,11 +741,17 @@ discard block |
||
700 | 741 | }*/ |
701 | 742 | } |
702 | 743 | |
703 | - if ($error) break; |
|
744 | + if ($error) { |
|
745 | + break; |
|
746 | + } |
|
704 | 747 | } |
705 | 748 | |
706 | - if($updatedone) $this->nbupdate++; |
|
707 | - if($insertdone) $this->nbinsert++; |
|
749 | + if($updatedone) { |
|
750 | + $this->nbupdate++; |
|
751 | + } |
|
752 | + if($insertdone) { |
|
753 | + $this->nbinsert++; |
|
754 | + } |
|
708 | 755 | } |
709 | 756 | |
710 | 757 | return 1; |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * \brief File to load import files with CSV format |
26 | 26 | */ |
27 | 27 | |
28 | -require_once DOL_DOCUMENT_ROOT .'/core/modules/import/modules_import.php'; |
|
28 | +require_once DOL_DOCUMENT_ROOT.'/core/modules/import/modules_import.php'; |
|
29 | 29 | |
30 | 30 | |
31 | 31 | /** |
@@ -36,24 +36,24 @@ discard block |
||
36 | 36 | var $db; |
37 | 37 | var $datatoimport; |
38 | 38 | |
39 | - var $error=''; |
|
40 | - var $errors=array(); |
|
39 | + var $error = ''; |
|
40 | + var $errors = array(); |
|
41 | 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 |
|
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 | 46 | |
47 | - var $label_lib; // Label of external lib used by driver |
|
48 | - var $version_lib; // Version of external lib used by driver |
|
47 | + var $label_lib; // Label of external lib used by driver |
|
48 | + var $version_lib; // Version of external lib used by driver |
|
49 | 49 | |
50 | 50 | var $separator; |
51 | 51 | |
52 | - var $file; // Path of file |
|
53 | - var $handle; // Handle fichier |
|
52 | + var $file; // Path of file |
|
53 | + var $handle; // Handle fichier |
|
54 | 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 |
|
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 | 57 | |
58 | 58 | var $nbinsert = 0; // # of insert done during the import |
59 | 59 | var $nbupdate = 0; // # of update done during the import |
@@ -65,28 +65,28 @@ discard block |
||
65 | 65 | * @param DoliDB $db Database handler |
66 | 66 | * @param string $datatoimport String code describing import set (ex: 'societe_1') |
67 | 67 | */ |
68 | - function __construct($db,$datatoimport) |
|
68 | + function __construct($db, $datatoimport) |
|
69 | 69 | { |
70 | - global $conf,$langs; |
|
70 | + global $conf, $langs; |
|
71 | 71 | $this->db = $db; |
72 | 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='"'; |
|
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 | 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 |
|
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 | 83 | |
84 | 84 | // If driver use an external library, put its name here |
85 | - $this->label_lib='Dolibarr'; |
|
86 | - $this->version_lib=DOL_VERSION; |
|
85 | + $this->label_lib = 'Dolibarr'; |
|
86 | + $this->version_lib = DOL_VERSION; |
|
87 | 87 | |
88 | - $this->datatoimport=$datatoimport; |
|
89 | - if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db); |
|
88 | + $this->datatoimport = $datatoimport; |
|
89 | + if (preg_match('/^societe_/', $datatoimport)) $this->thirpartyobject = new Societe($this->db); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | |
@@ -108,9 +108,9 @@ discard block |
||
108 | 108 | * @param array $headerlinefields Array of fields name |
109 | 109 | * @return string |
110 | 110 | */ |
111 | - function write_title_example($outputlangs,$headerlinefields) |
|
111 | + function write_title_example($outputlangs, $headerlinefields) |
|
112 | 112 | { |
113 | - $s=join($this->separator,array_map('cleansep',$headerlinefields)); |
|
113 | + $s = join($this->separator, array_map('cleansep', $headerlinefields)); |
|
114 | 114 | return $s."\n"; |
115 | 115 | } |
116 | 116 | |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | * @param array $contentlinevalues Array of lines |
122 | 122 | * @return string |
123 | 123 | */ |
124 | - function write_record_example($outputlangs,$contentlinevalues) |
|
124 | + function write_record_example($outputlangs, $contentlinevalues) |
|
125 | 125 | { |
126 | - $s=join($this->separator,array_map('cleansep',$contentlinevalues)); |
|
126 | + $s = join($this->separator, array_map('cleansep', $contentlinevalues)); |
|
127 | 127 | return $s."\n"; |
128 | 128 | } |
129 | 129 | |
@@ -149,22 +149,22 @@ discard block |
||
149 | 149 | function import_open_file($file) |
150 | 150 | { |
151 | 151 | global $langs; |
152 | - $ret=1; |
|
152 | + $ret = 1; |
|
153 | 153 | |
154 | 154 | dol_syslog(get_class($this)."::open_file file=".$file); |
155 | 155 | |
156 | - ini_set('auto_detect_line_endings',1); // For MAC compatibility |
|
156 | + ini_set('auto_detect_line_endings', 1); // For MAC compatibility |
|
157 | 157 | |
158 | 158 | $this->handle = fopen(dol_osencode($file), "r"); |
159 | - if (! $this->handle) |
|
159 | + if (!$this->handle) |
|
160 | 160 | { |
161 | 161 | $langs->load("errors"); |
162 | - $this->error=$langs->trans("ErrorFailToOpenFile",$file); |
|
163 | - $ret=-1; |
|
162 | + $this->error = $langs->trans("ErrorFailToOpenFile", $file); |
|
163 | + $ret = -1; |
|
164 | 164 | } |
165 | 165 | else |
166 | 166 | { |
167 | - $this->file=$file; |
|
167 | + $this->file = $file; |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | return $ret; |
@@ -203,47 +203,47 @@ discard block |
||
203 | 203 | { |
204 | 204 | global $conf; |
205 | 205 | |
206 | - $arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape); |
|
206 | + $arrayres = fgetcsv($this->handle, 100000, $this->separator, $this->enclosure, $this->escape); |
|
207 | 207 | |
208 | 208 | // End of file |
209 | 209 | if ($arrayres === false) return false; |
210 | 210 | |
211 | 211 | //var_dump($this->handle); |
212 | 212 | //var_dump($arrayres);exit; |
213 | - $newarrayres=array(); |
|
213 | + $newarrayres = array(); |
|
214 | 214 | if ($arrayres && is_array($arrayres)) |
215 | 215 | { |
216 | - foreach($arrayres as $key => $val) |
|
216 | + foreach ($arrayres as $key => $val) |
|
217 | 217 | { |
218 | - if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET)) // Forced charset |
|
218 | + if (!empty($conf->global->IMPORT_CSV_FORCE_CHARSET)) // Forced charset |
|
219 | 219 | { |
220 | 220 | if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) == 'utf8') |
221 | 221 | { |
222 | - $newarrayres[$key]['val']=$val; |
|
223 | - $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null |
|
222 | + $newarrayres[$key]['val'] = $val; |
|
223 | + $newarrayres[$key]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we considere it's null |
|
224 | 224 | } |
225 | 225 | else |
226 | 226 | { |
227 | - $newarrayres[$key]['val']=utf8_encode($val); |
|
228 | - $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null |
|
227 | + $newarrayres[$key]['val'] = utf8_encode($val); |
|
228 | + $newarrayres[$key]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we considere it's null |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | else // Autodetect format (UTF8 or ISO) |
232 | 232 | { |
233 | 233 | if (utf8_check($val)) |
234 | 234 | { |
235 | - $newarrayres[$key]['val']=$val; |
|
236 | - $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null |
|
235 | + $newarrayres[$key]['val'] = $val; |
|
236 | + $newarrayres[$key]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we considere it's null |
|
237 | 237 | } |
238 | 238 | else |
239 | 239 | { |
240 | - $newarrayres[$key]['val']=utf8_encode($val); |
|
241 | - $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null |
|
240 | + $newarrayres[$key]['val'] = utf8_encode($val); |
|
241 | + $newarrayres[$key]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we considere it's null |
|
242 | 242 | } |
243 | 243 | } |
244 | 244 | } |
245 | 245 | |
246 | - $this->col=count($newarrayres); |
|
246 | + $this->col = count($newarrayres); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | return $newarrayres; |
@@ -272,23 +272,23 @@ discard block |
||
272 | 272 | * @param array $updatekeys Array of keys to use to try to do update |
273 | 273 | * @return int <0 if KO, >0 if OK |
274 | 274 | */ |
275 | - function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid,$updatekeys) |
|
275 | + function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys) |
|
276 | 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 |
|
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 | 280 | |
281 | - $error=0; |
|
282 | - $warning=0; |
|
283 | - $this->errors=array(); |
|
284 | - $this->warnings=array(); |
|
281 | + $error = 0; |
|
282 | + $warning = 0; |
|
283 | + $this->errors = array(); |
|
284 | + $this->warnings = array(); |
|
285 | 285 | |
286 | 286 | //dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid); |
287 | 287 | |
288 | 288 | //var_dump($array_match_file_to_database); |
289 | 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; |
|
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 | 292 | ksort($sort_array_match_file_to_database); |
293 | 293 | |
294 | 294 | //var_dump($sort_array_match_file_to_database); |
@@ -296,8 +296,8 @@ discard block |
||
296 | 296 | if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val']))) |
297 | 297 | { |
298 | 298 | //print 'W'; |
299 | - $this->warnings[$warning]['lib']=$langs->trans('EmptyLine'); |
|
300 | - $this->warnings[$warning]['type']='EMPTY'; |
|
299 | + $this->warnings[$warning]['lib'] = $langs->trans('EmptyLine'); |
|
300 | + $this->warnings[$warning]['type'] = 'EMPTY'; |
|
301 | 301 | $warning++; |
302 | 302 | } |
303 | 303 | else |
@@ -306,25 +306,25 @@ discard block |
||
306 | 306 | $updatedone = false; |
307 | 307 | $insertdone = false; |
308 | 308 | // For each table to insert, me make a separate insert |
309 | - foreach($objimport->array_import_tables[0] as $alias => $tablename) |
|
309 | + foreach ($objimport->array_import_tables[0] as $alias => $tablename) |
|
310 | 310 | { |
311 | 311 | // Build sql request |
312 | - $sql=''; |
|
313 | - $listfields=array(); |
|
314 | - $listvalues=array(); |
|
315 | - $i=0; |
|
316 | - $errorforthistable=0; |
|
312 | + $sql = ''; |
|
313 | + $listfields = array(); |
|
314 | + $listvalues = array(); |
|
315 | + $i = 0; |
|
316 | + $errorforthistable = 0; |
|
317 | 317 | |
318 | 318 | // Define $tablewithentity_cache[$tablename] if not already defined |
319 | - if (! isset($tablewithentity_cache[$tablename])) // keep this test with "isset" |
|
319 | + if (!isset($tablewithentity_cache[$tablename])) // keep this test with "isset" |
|
320 | 320 | { |
321 | 321 | dol_syslog("Check if table ".$tablename." has an entity field"); |
322 | - $resql=$this->db->DDLDescTable($tablename,'entity'); |
|
322 | + $resql = $this->db->DDLDescTable($tablename, 'entity'); |
|
323 | 323 | if ($resql) |
324 | 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 |
|
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 | 328 | } |
329 | 329 | else dol_print_error($this->db); |
330 | 330 | } |
@@ -335,26 +335,26 @@ discard block |
||
335 | 335 | |
336 | 336 | |
337 | 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) |
|
338 | + foreach ($sort_array_match_file_to_database as $key => $val) |
|
339 | 339 | { |
340 | - $fieldalias=preg_replace('/\..*$/i','',$val); |
|
341 | - $fieldname=preg_replace('/^.*\./i','',$val); |
|
340 | + $fieldalias = preg_replace('/\..*$/i', '', $val); |
|
341 | + $fieldname = preg_replace('/^.*\./i', '', $val); |
|
342 | 342 | |
343 | - if ($alias != $fieldalias) continue; // Not a field of current table |
|
343 | + if ($alias != $fieldalias) continue; // Not a field of current table |
|
344 | 344 | |
345 | 345 | if ($key <= $maxfields) |
346 | 346 | { |
347 | 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 |
|
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 | 350 | |
351 | 351 | // Make some tests on $newval |
352 | 352 | |
353 | 353 | // Is it a required field ? |
354 | - if (preg_match('/\*/',$objimport->array_import_fields[0][$val]) && ((string) $newval=='')) |
|
354 | + if (preg_match('/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval == '')) |
|
355 | 355 | { |
356 | - $this->errors[$error]['lib']=$langs->trans('ErrorMissingMandatoryValue',$key); |
|
357 | - $this->errors[$error]['type']='NOTNULL'; |
|
356 | + $this->errors[$error]['lib'] = $langs->trans('ErrorMissingMandatoryValue', $key); |
|
357 | + $this->errors[$error]['type'] = 'NOTNULL'; |
|
358 | 358 | $errorforthistable++; |
359 | 359 | $error++; |
360 | 360 | } |
@@ -362,28 +362,28 @@ discard block |
||
362 | 362 | else |
363 | 363 | { |
364 | 364 | // We convert field if required |
365 | - if (! empty($objimport->array_import_convertvalue[0][$val])) |
|
365 | + if (!empty($objimport->array_import_convertvalue[0][$val])) |
|
366 | 366 | { |
367 | 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' |
|
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 | 371 | ) |
372 | 372 | { |
373 | 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 |
|
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 | 377 | //print 'Val is now '.$newval.' and is type '.$isidorref."<br>\n"; |
378 | 378 | |
379 | 379 | if ($isidorref == 'ref') // If value into input import file is a ref, we apply the function defined into descriptor |
380 | 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']; |
|
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 | 384 | if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '') |
385 | 385 | { |
386 | - $newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]; |
|
386 | + $newval = $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]; |
|
387 | 387 | } |
388 | 388 | else |
389 | 389 | { |
@@ -393,26 +393,26 @@ discard block |
||
393 | 393 | dol_print_error('', 'Error trying to call file='.$file.', class='.$class.', method='.$method); |
394 | 394 | break; |
395 | 395 | } |
396 | - $classinstance=new $class($this->db); |
|
396 | + $classinstance = new $class($this->db); |
|
397 | 397 | // Try the fetch from code or ref |
398 | - call_user_func_array(array($classinstance, $method),array('', $newval)); |
|
398 | + call_user_func_array(array($classinstance, $method), array('', $newval)); |
|
399 | 399 | // If not found, try the fetch from label |
400 | - if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel') |
|
400 | + if (!($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeorlabel') |
|
401 | 401 | { |
402 | - call_user_func_array(array($classinstance, $method),array('', '', $newval)); |
|
402 | + call_user_func_array(array($classinstance, $method), array('', '', $newval)); |
|
403 | 403 | } |
404 | - $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id; |
|
404 | + $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] = $classinstance->id; |
|
405 | 405 | //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. '; |
406 | 406 | if ($classinstance->id != '') // id may be 0, it is a found value |
407 | 407 | { |
408 | - $newval=$classinstance->id; |
|
408 | + $newval = $classinstance->id; |
|
409 | 409 | } |
410 | 410 | else |
411 | 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'; |
|
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 | 416 | $errorforthistable++; |
417 | 417 | $error++; |
418 | 418 | } |
@@ -420,68 +420,68 @@ discard block |
||
420 | 420 | } |
421 | 421 | |
422 | 422 | } |
423 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull') |
|
423 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'zeroifnull') |
|
424 | 424 | { |
425 | - if (empty($newval)) $newval='0'; |
|
425 | + if (empty($newval)) $newval = '0'; |
|
426 | 426 | } |
427 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto') |
|
427 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomercodeifauto') |
|
428 | 428 | { |
429 | 429 | if (strtolower($newval) == 'auto') |
430 | 430 | { |
431 | - $this->thirpartyobject->get_codeclient(0,0); |
|
432 | - $newval=$this->thirpartyobject->code_client; |
|
431 | + $this->thirpartyobject->get_codeclient(0, 0); |
|
432 | + $newval = $this->thirpartyobject->code_client; |
|
433 | 433 | //print 'code_client='.$newval; |
434 | 434 | } |
435 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
435 | + if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null" |
|
436 | 436 | } |
437 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto') |
|
437 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsuppliercodeifauto') |
|
438 | 438 | { |
439 | 439 | if (strtolower($newval) == 'auto') |
440 | 440 | { |
441 | - $newval=$this->thirpartyobject->get_codefournisseur(0,1); |
|
442 | - $newval=$this->thirpartyobject->code_fournisseur; |
|
441 | + $newval = $this->thirpartyobject->get_codefournisseur(0, 1); |
|
442 | + $newval = $this->thirpartyobject->code_fournisseur; |
|
443 | 443 | //print 'code_fournisseur='.$newval; |
444 | 444 | } |
445 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
445 | + if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null" |
|
446 | 446 | } |
447 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto') |
|
447 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomeraccountancycodeifauto') |
|
448 | 448 | { |
449 | 449 | if (strtolower($newval) == 'auto') |
450 | 450 | { |
451 | 451 | $this->thirpartyobject->get_codecompta('customer'); |
452 | - $newval=$this->thirpartyobject->code_compta; |
|
452 | + $newval = $this->thirpartyobject->code_compta; |
|
453 | 453 | //print 'code_compta='.$newval; |
454 | 454 | } |
455 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
455 | + if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null" |
|
456 | 456 | } |
457 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto') |
|
457 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsupplieraccountancycodeifauto') |
|
458 | 458 | { |
459 | 459 | if (strtolower($newval) == 'auto') |
460 | 460 | { |
461 | 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" |
|
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 | 464 | //print 'code_compta_fournisseur='.$newval; |
465 | 465 | } |
466 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
466 | + if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null" |
|
467 | 467 | } |
468 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto') |
|
468 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getrefifauto') |
|
469 | 469 | { |
470 | - $defaultref=''; |
|
470 | + $defaultref = ''; |
|
471 | 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")) |
|
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 | 474 | { |
475 | - require_once DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php'; |
|
475 | + require_once DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php'; |
|
476 | 476 | $modTask = new $obj; |
477 | - $defaultref = $modTask->getNextValue(null,null); |
|
477 | + $defaultref = $modTask->getNextValue(null, null); |
|
478 | 478 | } |
479 | - if (is_numeric($defaultref) && $defaultref <= 0) $defaultref=''; |
|
480 | - $newval=$defaultref; |
|
479 | + if (is_numeric($defaultref) && $defaultref <= 0) $defaultref = ''; |
|
480 | + $newval = $defaultref; |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | |
484 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric') |
|
484 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'numeric') |
|
485 | 485 | { |
486 | 486 | $newval = price2num($newval); |
487 | 487 | } |
@@ -490,27 +490,27 @@ discard block |
||
490 | 490 | } |
491 | 491 | |
492 | 492 | // Test regexp |
493 | - if (! empty($objimport->array_import_regex[0][$val]) && ($newval != '')) |
|
493 | + if (!empty($objimport->array_import_regex[0][$val]) && ($newval != '')) |
|
494 | 494 | { |
495 | 495 | // If test is "Must exist in a field@table" |
496 | - if (preg_match('/^(.*)@(.*)$/',$objimport->array_import_regex[0][$val],$reg)) |
|
496 | + if (preg_match('/^(.*)@(.*)$/', $objimport->array_import_regex[0][$val], $reg)) |
|
497 | 497 | { |
498 | - $field=$reg[1]; |
|
499 | - $table=$reg[2]; |
|
498 | + $field = $reg[1]; |
|
499 | + $table = $reg[2]; |
|
500 | 500 | |
501 | 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 |
|
502 | + if (!is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache |
|
503 | 503 | { |
504 | - $sql="SELECT ".$field." as aliasfield FROM ".$table; |
|
505 | - $resql=$this->db->query($sql); |
|
504 | + $sql = "SELECT ".$field." as aliasfield FROM ".$table; |
|
505 | + $resql = $this->db->query($sql); |
|
506 | 506 | if ($resql) |
507 | 507 | { |
508 | - $num=$this->db->num_rows($resql); |
|
509 | - $i=0; |
|
508 | + $num = $this->db->num_rows($resql); |
|
509 | + $i = 0; |
|
510 | 510 | while ($i < $num) |
511 | 511 | { |
512 | - $obj=$this->db->fetch_object($resql); |
|
513 | - if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield; |
|
512 | + $obj = $this->db->fetch_object($resql); |
|
513 | + if ($obj) $this->cachefieldtable[$field.'@'.$table][] = $obj->aliasfield; |
|
514 | 514 | $i++; |
515 | 515 | } |
516 | 516 | } |
@@ -521,20 +521,20 @@ discard block |
||
521 | 521 | } |
522 | 522 | |
523 | 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])) |
|
524 | + if (!is_array($this->cachefieldtable[$field.'@'.$table]) || !in_array($newval, $this->cachefieldtable[$field.'@'.$table])) |
|
525 | 525 | { |
526 | - $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table); |
|
527 | - $this->errors[$error]['type']='FOREIGNKEY'; |
|
526 | + $this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorFieldValueNotIn', $key, $newval, $field, $table); |
|
527 | + $this->errors[$error]['type'] = 'FOREIGNKEY'; |
|
528 | 528 | $errorforthistable++; |
529 | 529 | $error++; |
530 | 530 | } |
531 | 531 | } |
532 | 532 | // If test is just a static regex |
533 | - else if (! preg_match('/'.$objimport->array_import_regex[0][$val].'/i',$newval)) |
|
533 | + else if (!preg_match('/'.$objimport->array_import_regex[0][$val].'/i', $newval)) |
|
534 | 534 | { |
535 | 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'; |
|
536 | + $this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorWrongValueForField', $key, $newval, $objimport->array_import_regex[0][$val]); |
|
537 | + $this->errors[$error]['type'] = 'REGEX'; |
|
538 | 538 | $errorforthistable++; |
539 | 539 | $error++; |
540 | 540 | } |
@@ -548,8 +548,8 @@ discard block |
||
548 | 548 | $listfields[] = $fieldname; |
549 | 549 | |
550 | 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[] = "''"; |
|
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 | 553 | else $listvalues[] = "'".$this->db->escape($newval)."'"; |
554 | 554 | } |
555 | 555 | $i++; |
@@ -559,19 +559,19 @@ discard block |
||
559 | 559 | if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) |
560 | 560 | { |
561 | 561 | // Loop on each hidden fields to add them into listfields/listvalues |
562 | - foreach($objimport->array_import_fieldshidden[0] as $key => $val) |
|
562 | + foreach ($objimport->array_import_fieldshidden[0] as $key => $val) |
|
563 | 563 | { |
564 | - if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue; // Not a field of current table |
|
564 | + if (!preg_match('/^'.preg_quote($alias).'\./', $key)) continue; // Not a field of current table |
|
565 | 565 | if ($val == 'user->id') |
566 | 566 | { |
567 | - $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key); |
|
567 | + $listfields[] = preg_replace('/^'.preg_quote($alias).'\./', '', $key); |
|
568 | 568 | $listvalues[] = $user->id; |
569 | 569 | } |
570 | - elseif (preg_match('/^lastrowid-/',$val)) |
|
570 | + elseif (preg_match('/^lastrowid-/', $val)) |
|
571 | 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); |
|
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 | 575 | $listfields[] = $keyfield; |
576 | 576 | $listvalues[] = $lastinsertid; |
577 | 577 | //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit; |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | //print 'listfields='.$listfields.'<br>listvalues='.$listvalues.'<br>'; |
582 | 582 | |
583 | 583 | // If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined |
584 | - if (! $errorforthistable) |
|
584 | + if (!$errorforthistable) |
|
585 | 585 | { |
586 | 586 | //print "$alias/$tablename/$listfields/$listvalues<br>"; |
587 | 587 | if (!empty($listfields)) |
@@ -598,21 +598,21 @@ discard block |
||
598 | 598 | $filters = array(); |
599 | 599 | foreach ($updatekeys as $key) { |
600 | 600 | $col = $objimport->array_import_updatekeys[0][$key]; |
601 | - $key=preg_replace('/^.*\./i','',$key); |
|
601 | + $key = preg_replace('/^.*\./i', '', $key); |
|
602 | 602 | $where[] = $key.' = '.$data[$key]; |
603 | 603 | $filters[] = $col.' = '.$data[$key]; |
604 | 604 | } |
605 | - $sqlSelect.= ' WHERE '.implode(' AND ', $where); |
|
605 | + $sqlSelect .= ' WHERE '.implode(' AND ', $where); |
|
606 | 606 | |
607 | - $resql=$this->db->query($sqlSelect); |
|
608 | - if($resql) { |
|
607 | + $resql = $this->db->query($sqlSelect); |
|
608 | + if ($resql) { |
|
609 | 609 | $res = $this->db->fetch_object($resql); |
610 | - if($resql->num_rows == 1) { |
|
610 | + if ($resql->num_rows == 1) { |
|
611 | 611 | $lastinsertid = $res->rowid; |
612 | 612 | $last_insert_id_array[$tablename] = $lastinsertid; |
613 | - } else if($resql->num_rows > 1) { |
|
614 | - $this->errors[$error]['lib']=$langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', ')); |
|
615 | - $this->errors[$error]['type']='SQL'; |
|
613 | + } else if ($resql->num_rows > 1) { |
|
614 | + $this->errors[$error]['lib'] = $langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', ')); |
|
615 | + $this->errors[$error]['type'] = 'SQL'; |
|
616 | 616 | $error++; |
617 | 617 | } else { |
618 | 618 | // No record found with filters, insert will be tried below |
@@ -621,8 +621,8 @@ discard block |
||
621 | 621 | else |
622 | 622 | { |
623 | 623 | //print 'E'; |
624 | - $this->errors[$error]['lib']=$this->db->lasterror(); |
|
625 | - $this->errors[$error]['type']='SQL'; |
|
624 | + $this->errors[$error]['lib'] = $this->db->lasterror(); |
|
625 | + $this->errors[$error]['type'] = 'SQL'; |
|
626 | 626 | $error++; |
627 | 627 | } |
628 | 628 | } |
@@ -636,24 +636,24 @@ discard block |
||
636 | 636 | foreach ($data as $key => $val) { |
637 | 637 | $set[] = $key.' = '.$val; |
638 | 638 | } |
639 | - $sqlstart.= ' SET '.implode(', ', $set); |
|
639 | + $sqlstart .= ' SET '.implode(', ', $set); |
|
640 | 640 | |
641 | - if(empty($keyfield)) $keyfield = 'rowid'; |
|
641 | + if (empty($keyfield)) $keyfield = 'rowid'; |
|
642 | 642 | $sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid; |
643 | 643 | |
644 | 644 | $sql = $sqlstart.$sqlend; |
645 | 645 | |
646 | 646 | // Run update request |
647 | - $resql=$this->db->query($sql); |
|
648 | - if($resql) { |
|
647 | + $resql = $this->db->query($sql); |
|
648 | + if ($resql) { |
|
649 | 649 | // No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed |
650 | 650 | $updatedone = true; |
651 | 651 | } |
652 | 652 | else |
653 | 653 | { |
654 | 654 | //print 'E'; |
655 | - $this->errors[$error]['lib']=$this->db->lasterror(); |
|
656 | - $this->errors[$error]['type']='SQL'; |
|
655 | + $this->errors[$error]['lib'] = $this->db->lasterror(); |
|
656 | + $this->errors[$error]['type'] = 'SQL'; |
|
657 | 657 | $error++; |
658 | 658 | } |
659 | 659 | } |
@@ -664,13 +664,13 @@ discard block |
||
664 | 664 | // Build SQL INSERT request |
665 | 665 | $sqlstart = 'INSERT INTO '.$tablename.'('.implode(', ', $listfields).', import_key'; |
666 | 666 | $sqlend = ') VALUES('.implode(', ', $listvalues).", '".$importid."'"; |
667 | - if (! empty($tablewithentity_cache[$tablename])) { |
|
668 | - $sqlstart.= ', entity'; |
|
669 | - $sqlend.= ', '.$conf->entity; |
|
667 | + if (!empty($tablewithentity_cache[$tablename])) { |
|
668 | + $sqlstart .= ', entity'; |
|
669 | + $sqlend .= ', '.$conf->entity; |
|
670 | 670 | } |
671 | - if (! empty($objimport->array_import_tables_creator[0][$alias])) { |
|
672 | - $sqlstart.= ', '.$objimport->array_import_tables_creator[0][$alias]; |
|
673 | - $sqlend.=', '.$user->id; |
|
671 | + if (!empty($objimport->array_import_tables_creator[0][$alias])) { |
|
672 | + $sqlstart .= ', '.$objimport->array_import_tables_creator[0][$alias]; |
|
673 | + $sqlend .= ', '.$user->id; |
|
674 | 674 | } |
675 | 675 | $sql = $sqlstart.$sqlend.')'; |
676 | 676 | dol_syslog("import_csv.modules", LOG_DEBUG); |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | // Run insert request |
679 | 679 | if ($sql) |
680 | 680 | { |
681 | - $resql=$this->db->query($sql); |
|
681 | + $resql = $this->db->query($sql); |
|
682 | 682 | if ($resql) |
683 | 683 | { |
684 | 684 | $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). |
@@ -687,8 +687,8 @@ discard block |
||
687 | 687 | else |
688 | 688 | { |
689 | 689 | //print 'E'; |
690 | - $this->errors[$error]['lib']=$this->db->lasterror(); |
|
691 | - $this->errors[$error]['type']='SQL'; |
|
690 | + $this->errors[$error]['lib'] = $this->db->lasterror(); |
|
691 | + $this->errors[$error]['type'] = 'SQL'; |
|
692 | 692 | $error++; |
693 | 693 | } |
694 | 694 | } |
@@ -703,8 +703,8 @@ discard block |
||
703 | 703 | if ($error) break; |
704 | 704 | } |
705 | 705 | |
706 | - if($updatedone) $this->nbupdate++; |
|
707 | - if($insertdone) $this->nbinsert++; |
|
706 | + if ($updatedone) $this->nbupdate++; |
|
707 | + if ($insertdone) $this->nbinsert++; |
|
708 | 708 | } |
709 | 709 | |
710 | 710 | return 1; |
@@ -720,7 +720,7 @@ discard block |
||
720 | 720 | */ |
721 | 721 | function cleansep($value) |
722 | 722 | { |
723 | - return str_replace(array(',',';'),'/',$value); |
|
723 | + return str_replace(array(',', ';'), '/', $value); |
|
724 | 724 | }; |
725 | 725 | |
726 | 726 |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | */ |
34 | 34 | class ImportXlsx extends ModeleImports |
35 | 35 | { |
36 | - var $db; |
|
37 | - var $datatoimport; |
|
36 | + var $db; |
|
37 | + var $datatoimport; |
|
38 | 38 | |
39 | 39 | var $error=''; |
40 | 40 | var $errors=array(); |
41 | 41 | |
42 | - var $id; // Id of driver |
|
42 | + var $id; // Id of driver |
|
43 | 43 | var $label; // Label of driver |
44 | 44 | var $extension; // Extension of files imported by driver |
45 | 45 | var $version; // Version of driver |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | |
50 | 50 | var $separator; |
51 | 51 | |
52 | - var $file; // Path of file |
|
52 | + var $file; // Path of file |
|
53 | 53 | var $handle; // Handle fichier |
54 | 54 | |
55 | 55 | var $cacheconvert=array(); // Array to cache list of value found after a convertion |
@@ -80,16 +80,16 @@ discard block |
||
80 | 80 | $this->version='1.0'; // Driver version |
81 | 81 | |
82 | 82 | // If driver use an external library, put its name here |
83 | - require_once PHPEXCEL_PATH.'PHPExcel.php'; |
|
83 | + require_once PHPEXCEL_PATH.'PHPExcel.php'; |
|
84 | 84 | require_once PHPEXCEL_PATH.'PHPExcel/Style/Alignment.php'; |
85 | - if (! class_exists('ZipArchive')) // For Excel2007, PHPExcel need ZipArchive |
|
86 | - { |
|
87 | - $langs->load("errors"); |
|
88 | - $this->error=$langs->trans('ErrorPHPNeedModule','zip'); |
|
89 | - return -1; |
|
90 | - } |
|
91 | - $this->label_lib='PhpExcel'; |
|
92 | - $this->version_lib='1.8.0'; |
|
85 | + if (! class_exists('ZipArchive')) // For Excel2007, PHPExcel need ZipArchive |
|
86 | + { |
|
87 | + $langs->load("errors"); |
|
88 | + $this->error=$langs->trans('ErrorPHPNeedModule','zip'); |
|
89 | + return -1; |
|
90 | + } |
|
91 | + $this->label_lib='PhpExcel'; |
|
92 | + $this->version_lib='1.8.0'; |
|
93 | 93 | |
94 | 94 | $this->datatoimport=$datatoimport; |
95 | 95 | if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db); |
@@ -106,25 +106,25 @@ discard block |
||
106 | 106 | { |
107 | 107 | global $user,$conf,$langs; |
108 | 108 | // create a temporary object, the final output will be generated in footer |
109 | - if (!empty($conf->global->MAIN_USE_FILECACHE_EXPORT_EXCEL_DIR)) { |
|
110 | - $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_discISAM; |
|
111 | - $cacheSettings = array ( |
|
112 | - 'dir' => $conf->global->MAIN_USE_FILECACHE_EXPORT_EXCEL_DIR |
|
113 | - ); |
|
114 | - PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings); |
|
115 | - } |
|
116 | - |
|
117 | - $this->workbook = new PHPExcel(); |
|
118 | - $this->workbook->getProperties()->setCreator($user->getFullName($outputlangs).' - Dolibarr '.DOL_VERSION); |
|
119 | - $this->workbook->getProperties()->setTitle($outputlangs->trans("Import").' - '.$file); |
|
120 | - $this->workbook->getProperties()->setSubject($outputlangs->trans("Import").' - '.$file); |
|
121 | - $this->workbook->getProperties()->setDescription($outputlangs->trans("Import").' - '.$file); |
|
122 | - |
|
123 | - $this->workbook->setActiveSheetIndex(0); |
|
124 | - $this->workbook->getActiveSheet()->setTitle($outputlangs->trans("Sheet")); |
|
125 | - $this->workbook->getActiveSheet()->getDefaultRowDimension()->setRowHeight(16); |
|
126 | - |
|
127 | - return ''; |
|
109 | + if (!empty($conf->global->MAIN_USE_FILECACHE_EXPORT_EXCEL_DIR)) { |
|
110 | + $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_discISAM; |
|
111 | + $cacheSettings = array ( |
|
112 | + 'dir' => $conf->global->MAIN_USE_FILECACHE_EXPORT_EXCEL_DIR |
|
113 | + ); |
|
114 | + PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings); |
|
115 | + } |
|
116 | + |
|
117 | + $this->workbook = new PHPExcel(); |
|
118 | + $this->workbook->getProperties()->setCreator($user->getFullName($outputlangs).' - Dolibarr '.DOL_VERSION); |
|
119 | + $this->workbook->getProperties()->setTitle($outputlangs->trans("Import").' - '.$file); |
|
120 | + $this->workbook->getProperties()->setSubject($outputlangs->trans("Import").' - '.$file); |
|
121 | + $this->workbook->getProperties()->setDescription($outputlangs->trans("Import").' - '.$file); |
|
122 | + |
|
123 | + $this->workbook->setActiveSheetIndex(0); |
|
124 | + $this->workbook->getActiveSheet()->setTitle($outputlangs->trans("Sheet")); |
|
125 | + $this->workbook->getActiveSheet()->getDefaultRowDimension()->setRowHeight(16); |
|
126 | + |
|
127 | + return ''; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -136,17 +136,17 @@ discard block |
||
136 | 136 | */ |
137 | 137 | function write_title_example($outputlangs,$headerlinefields) |
138 | 138 | { |
139 | - global $conf; |
|
140 | - $this->workbook->getActiveSheet()->getStyle('1')->getFont()->setBold(true); |
|
141 | - $this->workbook->getActiveSheet()->getStyle('1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); |
|
142 | - |
|
143 | - $col = 0; |
|
144 | - foreach($headerlinefields as $field) { |
|
145 | - $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($col, 1, $outputlangs->transnoentities($field)); |
|
146 | - // set autowidth |
|
147 | - //$this->workbook->getActiveSheet()->getColumnDimension($this->column2Letter($col + 1))->setAutoSize(true); |
|
148 | - $col++; |
|
149 | - } |
|
139 | + global $conf; |
|
140 | + $this->workbook->getActiveSheet()->getStyle('1')->getFont()->setBold(true); |
|
141 | + $this->workbook->getActiveSheet()->getStyle('1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); |
|
142 | + |
|
143 | + $col = 0; |
|
144 | + foreach($headerlinefields as $field) { |
|
145 | + $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($col, 1, $outputlangs->transnoentities($field)); |
|
146 | + // set autowidth |
|
147 | + //$this->workbook->getActiveSheet()->getColumnDimension($this->column2Letter($col + 1))->setAutoSize(true); |
|
148 | + $col++; |
|
149 | + } |
|
150 | 150 | return ''; // final output will be generated in footer |
151 | 151 | } |
152 | 152 | |
@@ -159,13 +159,13 @@ discard block |
||
159 | 159 | */ |
160 | 160 | function write_record_example($outputlangs,$contentlinevalues) |
161 | 161 | { |
162 | - $col = 0; |
|
163 | - $row = 2; |
|
164 | - foreach($contentlinevalues as $cell) { |
|
165 | - $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($col, $row, $cell); |
|
166 | - $col++; |
|
167 | - } |
|
168 | - return ''; // final output will be generated in footer |
|
162 | + $col = 0; |
|
163 | + $row = 2; |
|
164 | + foreach($contentlinevalues as $cell) { |
|
165 | + $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($col, $row, $cell); |
|
166 | + $col++; |
|
167 | + } |
|
168 | + return ''; // final output will be generated in footer |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -177,15 +177,15 @@ discard block |
||
177 | 177 | function write_footer_example($outputlangs) |
178 | 178 | { |
179 | 179 | // return te file content as a string |
180 | - $tempfile = tempnam(sys_get_temp_dir(), 'dol'); |
|
181 | - $objWriter = new PHPExcel_Writer_Excel2007($this->workbook); |
|
182 | - $objWriter->save($tempfile); |
|
183 | - $this->workbook->disconnectWorksheets(); |
|
184 | - unset($this->workbook); |
|
185 | - |
|
186 | - $content = file_get_contents($tempfile); |
|
187 | - unlink($tempfile); |
|
188 | - return $content; |
|
180 | + $tempfile = tempnam(sys_get_temp_dir(), 'dol'); |
|
181 | + $objWriter = new PHPExcel_Writer_Excel2007($this->workbook); |
|
182 | + $objWriter->save($tempfile); |
|
183 | + $this->workbook->disconnectWorksheets(); |
|
184 | + unset($this->workbook); |
|
185 | + |
|
186 | + $content = file_get_contents($tempfile); |
|
187 | + unlink($tempfile); |
|
188 | + return $content; |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | |
@@ -223,13 +223,13 @@ discard block |
||
223 | 223 | $reader = new PHPExcel_Reader_Excel2007(); |
224 | 224 | $this->workbook = $reader->load($file); |
225 | 225 | |
226 | - $rowcount = $this->workbook->getActiveSheet()->getHighestDataRow(); |
|
226 | + $rowcount = $this->workbook->getActiveSheet()->getHighestDataRow(); |
|
227 | 227 | |
228 | - $this->workbook->disconnectWorksheets(); |
|
229 | - unset($this->workbook); |
|
228 | + $this->workbook->disconnectWorksheets(); |
|
229 | + unset($this->workbook); |
|
230 | 230 | |
231 | 231 | return $rowcount; |
232 | - } |
|
232 | + } |
|
233 | 233 | |
234 | 234 | |
235 | 235 | /** |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid,$updatekeys) |
300 | 300 | { |
301 | 301 | global $langs,$conf,$user; |
302 | - global $thirdparty_static; // Specific to thirdparty import |
|
302 | + global $thirdparty_static; // Specific to thirdparty import |
|
303 | 303 | global $tablewithentity_cache; // Cache to avoid to call desc at each rows on tables |
304 | 304 | |
305 | 305 | $error=0; |
@@ -361,10 +361,10 @@ discard block |
||
361 | 361 | // Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom) |
362 | 362 | foreach($sort_array_match_file_to_database as $key => $val) |
363 | 363 | { |
364 | - $fieldalias=preg_replace('/\..*$/i','',$val); |
|
365 | - $fieldname=preg_replace('/^.*\./i','',$val); |
|
364 | + $fieldalias=preg_replace('/\..*$/i','',$val); |
|
365 | + $fieldname=preg_replace('/^.*\./i','',$val); |
|
366 | 366 | |
367 | - if ($alias != $fieldalias) continue; // Not a field of current table |
|
367 | + if ($alias != $fieldalias) continue; // Not a field of current table |
|
368 | 368 | |
369 | 369 | if ($key <= $maxfields) |
370 | 370 | { |
@@ -385,135 +385,135 @@ discard block |
||
385 | 385 | // Test format only if field is not a missing mandatory field (field may be a value or empty but not mandatory) |
386 | 386 | else |
387 | 387 | { |
388 | - // We convert field if required |
|
389 | - if (! empty($objimport->array_import_convertvalue[0][$val])) |
|
390 | - { |
|
391 | - //print 'Must convert '.$newval.' with rule '.join(',',$objimport->array_import_convertvalue[0][$val]).'. '; |
|
392 | - if ($objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeid' |
|
393 | - || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref' |
|
394 | - || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel' |
|
395 | - ) |
|
396 | - { |
|
397 | - // 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. |
|
398 | - $isidorref='id'; |
|
399 | - if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) $isidorref='ref'; |
|
400 | - $newval=preg_replace('/^(id|ref):/i','',$newval); // Remove id: or ref: that was used to force if field is id or ref |
|
401 | - //print 'Val is now '.$newval.' and is type '.$isidorref."<br>\n"; |
|
388 | + // We convert field if required |
|
389 | + if (! empty($objimport->array_import_convertvalue[0][$val])) |
|
390 | + { |
|
391 | + //print 'Must convert '.$newval.' with rule '.join(',',$objimport->array_import_convertvalue[0][$val]).'. '; |
|
392 | + if ($objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeid' |
|
393 | + || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref' |
|
394 | + || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel' |
|
395 | + ) |
|
396 | + { |
|
397 | + // 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. |
|
398 | + $isidorref='id'; |
|
399 | + if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) $isidorref='ref'; |
|
400 | + $newval=preg_replace('/^(id|ref):/i','',$newval); // Remove id: or ref: that was used to force if field is id or ref |
|
401 | + //print 'Val is now '.$newval.' and is type '.$isidorref."<br>\n"; |
|
402 | 402 | |
403 | - if ($isidorref == 'ref') // If value into input import file is a ref, we apply the function defined into descriptor |
|
404 | - { |
|
405 | - $file=(empty($objimport->array_import_convertvalue[0][$val]['classfile'])?$objimport->array_import_convertvalue[0][$val]['file']:$objimport->array_import_convertvalue[0][$val]['classfile']); |
|
406 | - $class=$objimport->array_import_convertvalue[0][$val]['class']; |
|
407 | - $method=$objimport->array_import_convertvalue[0][$val]['method']; |
|
408 | - if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '') |
|
409 | - { |
|
410 | - $newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]; |
|
411 | - } |
|
412 | - else |
|
403 | + if ($isidorref == 'ref') // If value into input import file is a ref, we apply the function defined into descriptor |
|
404 | + { |
|
405 | + $file=(empty($objimport->array_import_convertvalue[0][$val]['classfile'])?$objimport->array_import_convertvalue[0][$val]['file']:$objimport->array_import_convertvalue[0][$val]['classfile']); |
|
406 | + $class=$objimport->array_import_convertvalue[0][$val]['class']; |
|
407 | + $method=$objimport->array_import_convertvalue[0][$val]['method']; |
|
408 | + if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '') |
|
413 | 409 | { |
414 | - $resultload = dol_include_once($file); |
|
415 | - if (empty($resultload)) |
|
416 | - { |
|
417 | - dol_print_error('', 'Error trying to call file='.$file.', class='.$class.', method='.$method); |
|
418 | - break; |
|
419 | - } |
|
420 | - $classinstance=new $class($this->db); |
|
421 | - // Try the fetch from code or ref |
|
422 | - call_user_func_array(array($classinstance, $method),array('', $newval)); |
|
423 | - // If not found, try the fetch from label |
|
424 | - if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel') |
|
425 | - { |
|
410 | + $newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]; |
|
411 | + } |
|
412 | + else |
|
413 | + { |
|
414 | + $resultload = dol_include_once($file); |
|
415 | + if (empty($resultload)) |
|
416 | + { |
|
417 | + dol_print_error('', 'Error trying to call file='.$file.', class='.$class.', method='.$method); |
|
418 | + break; |
|
419 | + } |
|
420 | + $classinstance=new $class($this->db); |
|
421 | + // Try the fetch from code or ref |
|
422 | + call_user_func_array(array($classinstance, $method),array('', $newval)); |
|
423 | + // If not found, try the fetch from label |
|
424 | + if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel') |
|
425 | + { |
|
426 | 426 | call_user_func_array(array($classinstance, $method),array('', '', $newval)); |
427 | - } |
|
428 | - $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id; |
|
429 | - //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. '; |
|
430 | - if ($classinstance->id != '') // id may be 0, it is a found value |
|
431 | - { |
|
432 | - $newval=$classinstance->id; |
|
433 | - } |
|
434 | - else |
|
435 | - { |
|
436 | - 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'])); |
|
437 | - 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'])); |
|
438 | - else $this->errors[$error]['lib']='ErrorFieldValueNotIn'; |
|
439 | - $this->errors[$error]['type']='FOREIGNKEY'; |
|
440 | - $errorforthistable++; |
|
441 | - $error++; |
|
442 | - } |
|
443 | - } |
|
444 | - } |
|
445 | - |
|
446 | - } |
|
447 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull') |
|
448 | - { |
|
449 | - if (empty($newval)) $newval='0'; |
|
450 | - } |
|
451 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto') |
|
452 | - { |
|
453 | - if (strtolower($newval) == 'auto') |
|
454 | - { |
|
455 | - $this->thirpartyobject->get_codeclient(0,0); |
|
456 | - $newval=$this->thirpartyobject->code_client; |
|
457 | - //print 'code_client='.$newval; |
|
458 | - } |
|
459 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
460 | - } |
|
461 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto') |
|
462 | - { |
|
463 | - if (strtolower($newval) == 'auto') |
|
464 | - { |
|
465 | - $newval=$this->thirpartyobject->get_codefournisseur(0,1); |
|
466 | - $newval=$this->thirpartyobject->code_fournisseur; |
|
467 | - //print 'code_fournisseur='.$newval; |
|
468 | - } |
|
469 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
470 | - } |
|
471 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto') |
|
472 | - { |
|
473 | - if (strtolower($newval) == 'auto') |
|
474 | - { |
|
475 | - $this->thirpartyobject->get_codecompta('customer'); |
|
476 | - $newval=$this->thirpartyobject->code_compta; |
|
477 | - //print 'code_compta='.$newval; |
|
478 | - } |
|
479 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
480 | - } |
|
481 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto') |
|
482 | - { |
|
483 | - if (strtolower($newval) == 'auto') |
|
484 | - { |
|
485 | - $this->thirpartyobject->get_codecompta('supplier'); |
|
486 | - $newval=$this->thirpartyobject->code_compta_fournisseur; |
|
487 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
488 | - //print 'code_compta_fournisseur='.$newval; |
|
489 | - } |
|
490 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
491 | - } |
|
492 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto') |
|
493 | - { |
|
494 | - $defaultref=''; |
|
495 | - // TODO provide the $modTask (module of generation of ref) as parameter of import_insert function |
|
496 | - $obj = empty($conf->global->PROJECT_TASK_ADDON)?'mod_task_simple':$conf->global->PROJECT_TASK_ADDON; |
|
497 | - if (! empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php")) |
|
498 | - { |
|
499 | - require_once DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php'; |
|
500 | - $modTask = new $obj; |
|
501 | - $defaultref = $modTask->getNextValue(null,null); |
|
502 | - } |
|
503 | - if (is_numeric($defaultref) && $defaultref <= 0) $defaultref=''; |
|
504 | - $newval=$defaultref; |
|
505 | - } |
|
427 | + } |
|
428 | + $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id; |
|
429 | + //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. '; |
|
430 | + if ($classinstance->id != '') // id may be 0, it is a found value |
|
431 | + { |
|
432 | + $newval=$classinstance->id; |
|
433 | + } |
|
434 | + else |
|
435 | + { |
|
436 | + 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'])); |
|
437 | + 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'])); |
|
438 | + else $this->errors[$error]['lib']='ErrorFieldValueNotIn'; |
|
439 | + $this->errors[$error]['type']='FOREIGNKEY'; |
|
440 | + $errorforthistable++; |
|
441 | + $error++; |
|
442 | + } |
|
443 | + } |
|
444 | + } |
|
445 | + |
|
446 | + } |
|
447 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull') |
|
448 | + { |
|
449 | + if (empty($newval)) $newval='0'; |
|
450 | + } |
|
451 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto') |
|
452 | + { |
|
453 | + if (strtolower($newval) == 'auto') |
|
454 | + { |
|
455 | + $this->thirpartyobject->get_codeclient(0,0); |
|
456 | + $newval=$this->thirpartyobject->code_client; |
|
457 | + //print 'code_client='.$newval; |
|
458 | + } |
|
459 | + if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
460 | + } |
|
461 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto') |
|
462 | + { |
|
463 | + if (strtolower($newval) == 'auto') |
|
464 | + { |
|
465 | + $newval=$this->thirpartyobject->get_codefournisseur(0,1); |
|
466 | + $newval=$this->thirpartyobject->code_fournisseur; |
|
467 | + //print 'code_fournisseur='.$newval; |
|
468 | + } |
|
469 | + if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
470 | + } |
|
471 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto') |
|
472 | + { |
|
473 | + if (strtolower($newval) == 'auto') |
|
474 | + { |
|
475 | + $this->thirpartyobject->get_codecompta('customer'); |
|
476 | + $newval=$this->thirpartyobject->code_compta; |
|
477 | + //print 'code_compta='.$newval; |
|
478 | + } |
|
479 | + if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
480 | + } |
|
481 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto') |
|
482 | + { |
|
483 | + if (strtolower($newval) == 'auto') |
|
484 | + { |
|
485 | + $this->thirpartyobject->get_codecompta('supplier'); |
|
486 | + $newval=$this->thirpartyobject->code_compta_fournisseur; |
|
487 | + if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
488 | + //print 'code_compta_fournisseur='.$newval; |
|
489 | + } |
|
490 | + if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
491 | + } |
|
492 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto') |
|
493 | + { |
|
494 | + $defaultref=''; |
|
495 | + // TODO provide the $modTask (module of generation of ref) as parameter of import_insert function |
|
496 | + $obj = empty($conf->global->PROJECT_TASK_ADDON)?'mod_task_simple':$conf->global->PROJECT_TASK_ADDON; |
|
497 | + if (! empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php")) |
|
498 | + { |
|
499 | + require_once DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php'; |
|
500 | + $modTask = new $obj; |
|
501 | + $defaultref = $modTask->getNextValue(null,null); |
|
502 | + } |
|
503 | + if (is_numeric($defaultref) && $defaultref <= 0) $defaultref=''; |
|
504 | + $newval=$defaultref; |
|
505 | + } |
|
506 | 506 | |
507 | 507 | |
508 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric') |
|
509 | - { |
|
510 | - $newval = price2num($newval); |
|
511 | - } |
|
508 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric') |
|
509 | + { |
|
510 | + $newval = price2num($newval); |
|
511 | + } |
|
512 | 512 | |
513 | - //print 'Val to use as insert is '.$newval.'<br>'; |
|
514 | - } |
|
513 | + //print 'Val to use as insert is '.$newval.'<br>'; |
|
514 | + } |
|
515 | 515 | |
516 | - // Test regexp |
|
516 | + // Test regexp |
|
517 | 517 | if (! empty($objimport->array_import_regex[0][$val]) && ($newval != '')) |
518 | 518 | { |
519 | 519 | // If test is "Must exist in a field@table" |
@@ -549,14 +549,14 @@ discard block |
||
549 | 549 | { |
550 | 550 | $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table); |
551 | 551 | $this->errors[$error]['type']='FOREIGNKEY'; |
552 | - $errorforthistable++; |
|
552 | + $errorforthistable++; |
|
553 | 553 | $error++; |
554 | 554 | } |
555 | 555 | } |
556 | 556 | // If test is just a static regex |
557 | 557 | else if (! preg_match('/'.$objimport->array_import_regex[0][$val].'/i',$newval)) |
558 | 558 | { |
559 | - //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>"; |
|
559 | + //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>"; |
|
560 | 560 | $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]); |
561 | 561 | $this->errors[$error]['type']='REGEX'; |
562 | 562 | $errorforthistable++; |
@@ -582,25 +582,25 @@ discard block |
||
582 | 582 | // We add hidden fields (but only if there is at least one field to add into table) |
583 | 583 | if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) |
584 | 584 | { |
585 | - // Loop on each hidden fields to add them into listfields/listvalues |
|
586 | - foreach($objimport->array_import_fieldshidden[0] as $key => $val) |
|
587 | - { |
|
588 | - if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue; // Not a field of current table |
|
589 | - if ($val == 'user->id') |
|
590 | - { |
|
591 | - $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key); |
|
592 | - $listvalues[] = $user->id; |
|
593 | - } |
|
594 | - elseif (preg_match('/^lastrowid-/',$val)) |
|
595 | - { |
|
596 | - $tmp=explode('-',$val); |
|
597 | - $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0; |
|
585 | + // Loop on each hidden fields to add them into listfields/listvalues |
|
586 | + foreach($objimport->array_import_fieldshidden[0] as $key => $val) |
|
587 | + { |
|
588 | + if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue; // Not a field of current table |
|
589 | + if ($val == 'user->id') |
|
590 | + { |
|
591 | + $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key); |
|
592 | + $listvalues[] = $user->id; |
|
593 | + } |
|
594 | + elseif (preg_match('/^lastrowid-/',$val)) |
|
595 | + { |
|
596 | + $tmp=explode('-',$val); |
|
597 | + $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0; |
|
598 | 598 | $keyfield = preg_replace('/^'.preg_quote($alias).'\./','',$key); |
599 | - $listfields[] = $keyfield; |
|
600 | - $listvalues[] = $lastinsertid; |
|
601 | - //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit; |
|
602 | - } |
|
603 | - } |
|
599 | + $listfields[] = $keyfield; |
|
600 | + $listvalues[] = $lastinsertid; |
|
601 | + //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit; |
|
602 | + } |
|
603 | + } |
|
604 | 604 | } |
605 | 605 | //print 'listfields='.$listfields.'<br>listvalues='.$listvalues.'<br>'; |
606 | 606 | |
@@ -705,8 +705,8 @@ discard block |
||
705 | 705 | $resql=$this->db->query($sql); |
706 | 706 | if ($resql) |
707 | 707 | { |
708 | - $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). |
|
709 | - $insertdone = true; |
|
708 | + $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). |
|
709 | + $insertdone = true; |
|
710 | 710 | } |
711 | 711 | else |
712 | 712 | { |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | }*/ |
725 | 725 | } |
726 | 726 | |
727 | - if ($error) break; |
|
727 | + if ($error) break; |
|
728 | 728 | } |
729 | 729 | |
730 | 730 | if($updatedone) $this->nbupdate++; |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * \brief File to load import files with CSV format |
26 | 26 | */ |
27 | 27 | |
28 | -require_once DOL_DOCUMENT_ROOT .'/core/modules/import/modules_import.php'; |
|
28 | +require_once DOL_DOCUMENT_ROOT.'/core/modules/import/modules_import.php'; |
|
29 | 29 | |
30 | 30 | |
31 | 31 | /** |
@@ -36,24 +36,24 @@ discard block |
||
36 | 36 | var $db; |
37 | 37 | var $datatoimport; |
38 | 38 | |
39 | - var $error=''; |
|
40 | - var $errors=array(); |
|
39 | + var $error = ''; |
|
40 | + var $errors = array(); |
|
41 | 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 |
|
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 | 46 | |
47 | - var $label_lib; // Label of external lib used by driver |
|
48 | - var $version_lib; // Version of external lib used by driver |
|
47 | + var $label_lib; // Label of external lib used by driver |
|
48 | + var $version_lib; // Version of external lib used by driver |
|
49 | 49 | |
50 | 50 | var $separator; |
51 | 51 | |
52 | - var $file; // Path of file |
|
53 | - var $handle; // Handle fichier |
|
52 | + var $file; // Path of file |
|
53 | + var $handle; // Handle fichier |
|
54 | 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 |
|
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 | 57 | |
58 | 58 | var $workbook; // temporary import file |
59 | 59 | var $record; // current record |
@@ -66,33 +66,33 @@ discard block |
||
66 | 66 | * @param DoliDB $db Database handler |
67 | 67 | * @param string $datatoimport String code describing import set (ex: 'societe_1') |
68 | 68 | */ |
69 | - function __construct($db,$datatoimport) |
|
69 | + function __construct($db, $datatoimport) |
|
70 | 70 | { |
71 | - global $conf,$langs; |
|
71 | + global $conf, $langs; |
|
72 | 72 | $this->db = $db; |
73 | 73 | |
74 | 74 | // this is used as an extension from the example file code, so we have to put xlsx here !!! |
75 | - $this->id='xlsx'; // Same value as xxx in file name export_xxx.modules.php |
|
76 | - $this->label='Excel 2007'; // Label of driver |
|
77 | - $this->desc=$langs->trans("Excel2007FormatDesc"); |
|
78 | - $this->extension='xlsx'; // Extension for generated file by this driver |
|
79 | - $this->picto='mime/xls'; // Picto (This is not used by the example file code as Mime type, too bad ...) |
|
80 | - $this->version='1.0'; // Driver version |
|
75 | + $this->id = 'xlsx'; // Same value as xxx in file name export_xxx.modules.php |
|
76 | + $this->label = 'Excel 2007'; // Label of driver |
|
77 | + $this->desc = $langs->trans("Excel2007FormatDesc"); |
|
78 | + $this->extension = 'xlsx'; // Extension for generated file by this driver |
|
79 | + $this->picto = 'mime/xls'; // Picto (This is not used by the example file code as Mime type, too bad ...) |
|
80 | + $this->version = '1.0'; // Driver version |
|
81 | 81 | |
82 | 82 | // If driver use an external library, put its name here |
83 | 83 | require_once PHPEXCEL_PATH.'PHPExcel.php'; |
84 | 84 | require_once PHPEXCEL_PATH.'PHPExcel/Style/Alignment.php'; |
85 | - if (! class_exists('ZipArchive')) // For Excel2007, PHPExcel need ZipArchive |
|
85 | + if (!class_exists('ZipArchive')) // For Excel2007, PHPExcel need ZipArchive |
|
86 | 86 | { |
87 | 87 | $langs->load("errors"); |
88 | - $this->error=$langs->trans('ErrorPHPNeedModule','zip'); |
|
88 | + $this->error = $langs->trans('ErrorPHPNeedModule', 'zip'); |
|
89 | 89 | return -1; |
90 | 90 | } |
91 | - $this->label_lib='PhpExcel'; |
|
92 | - $this->version_lib='1.8.0'; |
|
91 | + $this->label_lib = 'PhpExcel'; |
|
92 | + $this->version_lib = '1.8.0'; |
|
93 | 93 | |
94 | - $this->datatoimport=$datatoimport; |
|
95 | - if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db); |
|
94 | + $this->datatoimport = $datatoimport; |
|
95 | + if (preg_match('/^societe_/', $datatoimport)) $this->thirpartyobject = new Societe($this->db); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | |
@@ -104,11 +104,11 @@ discard block |
||
104 | 104 | */ |
105 | 105 | function write_header_example($outputlangs) |
106 | 106 | { |
107 | - global $user,$conf,$langs; |
|
107 | + global $user, $conf, $langs; |
|
108 | 108 | // create a temporary object, the final output will be generated in footer |
109 | 109 | if (!empty($conf->global->MAIN_USE_FILECACHE_EXPORT_EXCEL_DIR)) { |
110 | 110 | $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_discISAM; |
111 | - $cacheSettings = array ( |
|
111 | + $cacheSettings = array( |
|
112 | 112 | 'dir' => $conf->global->MAIN_USE_FILECACHE_EXPORT_EXCEL_DIR |
113 | 113 | ); |
114 | 114 | PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings); |
@@ -134,14 +134,14 @@ discard block |
||
134 | 134 | * @param array $headerlinefields Array of fields name |
135 | 135 | * @return string |
136 | 136 | */ |
137 | - function write_title_example($outputlangs,$headerlinefields) |
|
137 | + function write_title_example($outputlangs, $headerlinefields) |
|
138 | 138 | { |
139 | 139 | global $conf; |
140 | 140 | $this->workbook->getActiveSheet()->getStyle('1')->getFont()->setBold(true); |
141 | 141 | $this->workbook->getActiveSheet()->getStyle('1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); |
142 | 142 | |
143 | 143 | $col = 0; |
144 | - foreach($headerlinefields as $field) { |
|
144 | + foreach ($headerlinefields as $field) { |
|
145 | 145 | $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($col, 1, $outputlangs->transnoentities($field)); |
146 | 146 | // set autowidth |
147 | 147 | //$this->workbook->getActiveSheet()->getColumnDimension($this->column2Letter($col + 1))->setAutoSize(true); |
@@ -157,11 +157,11 @@ discard block |
||
157 | 157 | * @param array $contentlinevalues Array of lines |
158 | 158 | * @return string |
159 | 159 | */ |
160 | - function write_record_example($outputlangs,$contentlinevalues) |
|
160 | + function write_record_example($outputlangs, $contentlinevalues) |
|
161 | 161 | { |
162 | 162 | $col = 0; |
163 | 163 | $row = 2; |
164 | - foreach($contentlinevalues as $cell) { |
|
164 | + foreach ($contentlinevalues as $cell) { |
|
165 | 165 | $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($col, $row, $cell); |
166 | 166 | $col++; |
167 | 167 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | function import_open_file($file) |
200 | 200 | { |
201 | 201 | global $langs; |
202 | - $ret=1; |
|
202 | + $ret = 1; |
|
203 | 203 | |
204 | 204 | dol_syslog(get_class($this)."::open_file file=".$file); |
205 | 205 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | // This is not called by the import code !!! |
243 | 243 | $this->headers = array(); |
244 | 244 | $colcount = PHPExcel_Cell::columnIndexFromString($this->workbook->getActiveSheet()->getHighestDataColumn()); |
245 | - for($col=0;$col<$colcount;$col++) { |
|
245 | + for ($col = 0; $col < $colcount; $col++) { |
|
246 | 246 | $this->headers[$col] = $this->workbook->getActiveSheet()->getCellByColumnAndRow($col, 1)->getValue(); |
247 | 247 | } |
248 | 248 | return 0; |
@@ -259,14 +259,14 @@ discard block |
||
259 | 259 | global $conf; |
260 | 260 | |
261 | 261 | $rowcount = $this->workbook->getActiveSheet()->getHighestDataRow(); |
262 | - if($this->record > $rowcount) |
|
262 | + if ($this->record > $rowcount) |
|
263 | 263 | return false; |
264 | 264 | $array = array(); |
265 | 265 | $colcount = PHPExcel_Cell::columnIndexFromString($this->workbook->getActiveSheet()->getHighestDataColumn(0)); |
266 | - for($col=0;$col<$colcount;$col++) { |
|
266 | + for ($col = 0; $col < $colcount; $col++) { |
|
267 | 267 | $val = $this->workbook->getActiveSheet()->getCellByColumnAndRow($col, $this->record)->getValue(); |
268 | 268 | $array[$col]['val'] = $val; |
269 | - $array[$col]['type'] = (dol_strlen($val)?1:-1); // If empty we consider it null |
|
269 | + $array[$col]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we consider it null |
|
270 | 270 | } |
271 | 271 | $this->record++; |
272 | 272 | return $array; |
@@ -296,23 +296,23 @@ discard block |
||
296 | 296 | * @return int <0 if KO, >0 if OK |
297 | 297 | */ |
298 | 298 | // What is this doing here ? it is common to all imports, is should be in the parent class |
299 | - function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid,$updatekeys) |
|
299 | + function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys) |
|
300 | 300 | { |
301 | - global $langs,$conf,$user; |
|
302 | - global $thirdparty_static; // Specific to thirdparty import |
|
303 | - global $tablewithentity_cache; // Cache to avoid to call desc at each rows on tables |
|
301 | + global $langs, $conf, $user; |
|
302 | + global $thirdparty_static; // Specific to thirdparty import |
|
303 | + global $tablewithentity_cache; // Cache to avoid to call desc at each rows on tables |
|
304 | 304 | |
305 | - $error=0; |
|
306 | - $warning=0; |
|
307 | - $this->errors=array(); |
|
308 | - $this->warnings=array(); |
|
305 | + $error = 0; |
|
306 | + $warning = 0; |
|
307 | + $this->errors = array(); |
|
308 | + $this->warnings = array(); |
|
309 | 309 | |
310 | 310 | //dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid); |
311 | 311 | |
312 | 312 | //var_dump($array_match_file_to_database); |
313 | 313 | //var_dump($arrayrecord); |
314 | - $array_match_database_to_file=array_flip($array_match_file_to_database); |
|
315 | - $sort_array_match_file_to_database=$array_match_file_to_database; |
|
314 | + $array_match_database_to_file = array_flip($array_match_file_to_database); |
|
315 | + $sort_array_match_file_to_database = $array_match_file_to_database; |
|
316 | 316 | ksort($sort_array_match_file_to_database); |
317 | 317 | |
318 | 318 | //var_dump($sort_array_match_file_to_database); |
@@ -320,8 +320,8 @@ discard block |
||
320 | 320 | if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val']))) |
321 | 321 | { |
322 | 322 | //print 'W'; |
323 | - $this->warnings[$warning]['lib']=$langs->trans('EmptyLine'); |
|
324 | - $this->warnings[$warning]['type']='EMPTY'; |
|
323 | + $this->warnings[$warning]['lib'] = $langs->trans('EmptyLine'); |
|
324 | + $this->warnings[$warning]['type'] = 'EMPTY'; |
|
325 | 325 | $warning++; |
326 | 326 | } |
327 | 327 | else |
@@ -330,25 +330,25 @@ discard block |
||
330 | 330 | $updatedone = false; |
331 | 331 | $insertdone = false; |
332 | 332 | // For each table to insert, me make a separate insert |
333 | - foreach($objimport->array_import_tables[0] as $alias => $tablename) |
|
333 | + foreach ($objimport->array_import_tables[0] as $alias => $tablename) |
|
334 | 334 | { |
335 | 335 | // Build sql request |
336 | - $sql=''; |
|
337 | - $listfields=array(); |
|
338 | - $listvalues=array(); |
|
339 | - $i=0; |
|
340 | - $errorforthistable=0; |
|
336 | + $sql = ''; |
|
337 | + $listfields = array(); |
|
338 | + $listvalues = array(); |
|
339 | + $i = 0; |
|
340 | + $errorforthistable = 0; |
|
341 | 341 | |
342 | 342 | // Define $tablewithentity_cache[$tablename] if not already defined |
343 | - if (! isset($tablewithentity_cache[$tablename])) // keep this test with "isset" |
|
343 | + if (!isset($tablewithentity_cache[$tablename])) // keep this test with "isset" |
|
344 | 344 | { |
345 | 345 | dol_syslog("Check if table ".$tablename." has an entity field"); |
346 | - $resql=$this->db->DDLDescTable($tablename,'entity'); |
|
346 | + $resql = $this->db->DDLDescTable($tablename, 'entity'); |
|
347 | 347 | if ($resql) |
348 | 348 | { |
349 | - $obj=$this->db->fetch_object($resql); |
|
350 | - if ($obj) $tablewithentity_cache[$tablename]=1; // table contains entity field |
|
351 | - else $tablewithentity_cache[$tablename]=0; // table does not contains entity field |
|
349 | + $obj = $this->db->fetch_object($resql); |
|
350 | + if ($obj) $tablewithentity_cache[$tablename] = 1; // table contains entity field |
|
351 | + else $tablewithentity_cache[$tablename] = 0; // table does not contains entity field |
|
352 | 352 | } |
353 | 353 | else dol_print_error($this->db); |
354 | 354 | } |
@@ -359,26 +359,26 @@ discard block |
||
359 | 359 | |
360 | 360 | |
361 | 361 | // Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom) |
362 | - foreach($sort_array_match_file_to_database as $key => $val) |
|
362 | + foreach ($sort_array_match_file_to_database as $key => $val) |
|
363 | 363 | { |
364 | - $fieldalias=preg_replace('/\..*$/i','',$val); |
|
365 | - $fieldname=preg_replace('/^.*\./i','',$val); |
|
364 | + $fieldalias = preg_replace('/\..*$/i', '', $val); |
|
365 | + $fieldname = preg_replace('/^.*\./i', '', $val); |
|
366 | 366 | |
367 | - if ($alias != $fieldalias) continue; // Not a field of current table |
|
367 | + if ($alias != $fieldalias) continue; // Not a field of current table |
|
368 | 368 | |
369 | 369 | if ($key <= $maxfields) |
370 | 370 | { |
371 | 371 | // Set $newval with value to insert and set $listvalues with sql request part for insert |
372 | - $newval=''; |
|
373 | - 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 |
|
372 | + $newval = ''; |
|
373 | + 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 |
|
374 | 374 | |
375 | 375 | // Make some tests on $newval |
376 | 376 | |
377 | 377 | // Is it a required field ? |
378 | - if (preg_match('/\*/',$objimport->array_import_fields[0][$val]) && ((string) $newval=='')) |
|
378 | + if (preg_match('/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval == '')) |
|
379 | 379 | { |
380 | - $this->errors[$error]['lib']=$langs->trans('ErrorMissingMandatoryValue',$key); |
|
381 | - $this->errors[$error]['type']='NOTNULL'; |
|
380 | + $this->errors[$error]['lib'] = $langs->trans('ErrorMissingMandatoryValue', $key); |
|
381 | + $this->errors[$error]['type'] = 'NOTNULL'; |
|
382 | 382 | $errorforthistable++; |
383 | 383 | $error++; |
384 | 384 | } |
@@ -386,28 +386,28 @@ discard block |
||
386 | 386 | else |
387 | 387 | { |
388 | 388 | // We convert field if required |
389 | - if (! empty($objimport->array_import_convertvalue[0][$val])) |
|
389 | + if (!empty($objimport->array_import_convertvalue[0][$val])) |
|
390 | 390 | { |
391 | 391 | //print 'Must convert '.$newval.' with rule '.join(',',$objimport->array_import_convertvalue[0][$val]).'. '; |
392 | - if ($objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeid' |
|
393 | - || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref' |
|
394 | - || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel' |
|
392 | + if ($objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeid' |
|
393 | + || $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromref' |
|
394 | + || $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeorlabel' |
|
395 | 395 | ) |
396 | 396 | { |
397 | 397 | // 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. |
398 | - $isidorref='id'; |
|
399 | - if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) $isidorref='ref'; |
|
400 | - $newval=preg_replace('/^(id|ref):/i','',$newval); // Remove id: or ref: that was used to force if field is id or ref |
|
398 | + $isidorref = 'id'; |
|
399 | + if (!is_numeric($newval) && $newval != '' && !preg_match('/^id:/i', $newval)) $isidorref = 'ref'; |
|
400 | + $newval = preg_replace('/^(id|ref):/i', '', $newval); // Remove id: or ref: that was used to force if field is id or ref |
|
401 | 401 | //print 'Val is now '.$newval.' and is type '.$isidorref."<br>\n"; |
402 | 402 | |
403 | 403 | if ($isidorref == 'ref') // If value into input import file is a ref, we apply the function defined into descriptor |
404 | 404 | { |
405 | - $file=(empty($objimport->array_import_convertvalue[0][$val]['classfile'])?$objimport->array_import_convertvalue[0][$val]['file']:$objimport->array_import_convertvalue[0][$val]['classfile']); |
|
406 | - $class=$objimport->array_import_convertvalue[0][$val]['class']; |
|
407 | - $method=$objimport->array_import_convertvalue[0][$val]['method']; |
|
405 | + $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']); |
|
406 | + $class = $objimport->array_import_convertvalue[0][$val]['class']; |
|
407 | + $method = $objimport->array_import_convertvalue[0][$val]['method']; |
|
408 | 408 | if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '') |
409 | 409 | { |
410 | - $newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]; |
|
410 | + $newval = $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]; |
|
411 | 411 | } |
412 | 412 | else |
413 | 413 | { |
@@ -417,26 +417,26 @@ discard block |
||
417 | 417 | dol_print_error('', 'Error trying to call file='.$file.', class='.$class.', method='.$method); |
418 | 418 | break; |
419 | 419 | } |
420 | - $classinstance=new $class($this->db); |
|
420 | + $classinstance = new $class($this->db); |
|
421 | 421 | // Try the fetch from code or ref |
422 | - call_user_func_array(array($classinstance, $method),array('', $newval)); |
|
422 | + call_user_func_array(array($classinstance, $method), array('', $newval)); |
|
423 | 423 | // If not found, try the fetch from label |
424 | - if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel') |
|
424 | + if (!($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeorlabel') |
|
425 | 425 | { |
426 | - call_user_func_array(array($classinstance, $method),array('', '', $newval)); |
|
426 | + call_user_func_array(array($classinstance, $method), array('', '', $newval)); |
|
427 | 427 | } |
428 | - $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id; |
|
428 | + $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] = $classinstance->id; |
|
429 | 429 | //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. '; |
430 | 430 | if ($classinstance->id != '') // id may be 0, it is a found value |
431 | 431 | { |
432 | - $newval=$classinstance->id; |
|
432 | + $newval = $classinstance->id; |
|
433 | 433 | } |
434 | 434 | else |
435 | 435 | { |
436 | - 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'])); |
|
437 | - 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'])); |
|
438 | - else $this->errors[$error]['lib']='ErrorFieldValueNotIn'; |
|
439 | - $this->errors[$error]['type']='FOREIGNKEY'; |
|
436 | + 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'])); |
|
437 | + 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'])); |
|
438 | + else $this->errors[$error]['lib'] = 'ErrorFieldValueNotIn'; |
|
439 | + $this->errors[$error]['type'] = 'FOREIGNKEY'; |
|
440 | 440 | $errorforthistable++; |
441 | 441 | $error++; |
442 | 442 | } |
@@ -444,68 +444,68 @@ discard block |
||
444 | 444 | } |
445 | 445 | |
446 | 446 | } |
447 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull') |
|
447 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'zeroifnull') |
|
448 | 448 | { |
449 | - if (empty($newval)) $newval='0'; |
|
449 | + if (empty($newval)) $newval = '0'; |
|
450 | 450 | } |
451 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto') |
|
451 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomercodeifauto') |
|
452 | 452 | { |
453 | 453 | if (strtolower($newval) == 'auto') |
454 | 454 | { |
455 | - $this->thirpartyobject->get_codeclient(0,0); |
|
456 | - $newval=$this->thirpartyobject->code_client; |
|
455 | + $this->thirpartyobject->get_codeclient(0, 0); |
|
456 | + $newval = $this->thirpartyobject->code_client; |
|
457 | 457 | //print 'code_client='.$newval; |
458 | 458 | } |
459 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
459 | + if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null" |
|
460 | 460 | } |
461 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto') |
|
461 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsuppliercodeifauto') |
|
462 | 462 | { |
463 | 463 | if (strtolower($newval) == 'auto') |
464 | 464 | { |
465 | - $newval=$this->thirpartyobject->get_codefournisseur(0,1); |
|
466 | - $newval=$this->thirpartyobject->code_fournisseur; |
|
465 | + $newval = $this->thirpartyobject->get_codefournisseur(0, 1); |
|
466 | + $newval = $this->thirpartyobject->code_fournisseur; |
|
467 | 467 | //print 'code_fournisseur='.$newval; |
468 | 468 | } |
469 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
469 | + if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null" |
|
470 | 470 | } |
471 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto') |
|
471 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomeraccountancycodeifauto') |
|
472 | 472 | { |
473 | 473 | if (strtolower($newval) == 'auto') |
474 | 474 | { |
475 | 475 | $this->thirpartyobject->get_codecompta('customer'); |
476 | - $newval=$this->thirpartyobject->code_compta; |
|
476 | + $newval = $this->thirpartyobject->code_compta; |
|
477 | 477 | //print 'code_compta='.$newval; |
478 | 478 | } |
479 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
479 | + if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null" |
|
480 | 480 | } |
481 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto') |
|
481 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsupplieraccountancycodeifauto') |
|
482 | 482 | { |
483 | 483 | if (strtolower($newval) == 'auto') |
484 | 484 | { |
485 | 485 | $this->thirpartyobject->get_codecompta('supplier'); |
486 | - $newval=$this->thirpartyobject->code_compta_fournisseur; |
|
487 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
486 | + $newval = $this->thirpartyobject->code_compta_fournisseur; |
|
487 | + if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null" |
|
488 | 488 | //print 'code_compta_fournisseur='.$newval; |
489 | 489 | } |
490 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
490 | + if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null" |
|
491 | 491 | } |
492 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto') |
|
492 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getrefifauto') |
|
493 | 493 | { |
494 | - $defaultref=''; |
|
494 | + $defaultref = ''; |
|
495 | 495 | // TODO provide the $modTask (module of generation of ref) as parameter of import_insert function |
496 | - $obj = empty($conf->global->PROJECT_TASK_ADDON)?'mod_task_simple':$conf->global->PROJECT_TASK_ADDON; |
|
497 | - if (! empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php")) |
|
496 | + $obj = empty($conf->global->PROJECT_TASK_ADDON) ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON; |
|
497 | + if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php")) |
|
498 | 498 | { |
499 | - require_once DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php'; |
|
499 | + require_once DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php'; |
|
500 | 500 | $modTask = new $obj; |
501 | - $defaultref = $modTask->getNextValue(null,null); |
|
501 | + $defaultref = $modTask->getNextValue(null, null); |
|
502 | 502 | } |
503 | - if (is_numeric($defaultref) && $defaultref <= 0) $defaultref=''; |
|
504 | - $newval=$defaultref; |
|
503 | + if (is_numeric($defaultref) && $defaultref <= 0) $defaultref = ''; |
|
504 | + $newval = $defaultref; |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | |
508 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric') |
|
508 | + elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'numeric') |
|
509 | 509 | { |
510 | 510 | $newval = price2num($newval); |
511 | 511 | } |
@@ -514,27 +514,27 @@ discard block |
||
514 | 514 | } |
515 | 515 | |
516 | 516 | // Test regexp |
517 | - if (! empty($objimport->array_import_regex[0][$val]) && ($newval != '')) |
|
517 | + if (!empty($objimport->array_import_regex[0][$val]) && ($newval != '')) |
|
518 | 518 | { |
519 | 519 | // If test is "Must exist in a field@table" |
520 | - if (preg_match('/^(.*)@(.*)$/',$objimport->array_import_regex[0][$val],$reg)) |
|
520 | + if (preg_match('/^(.*)@(.*)$/', $objimport->array_import_regex[0][$val], $reg)) |
|
521 | 521 | { |
522 | - $field=$reg[1]; |
|
523 | - $table=$reg[2]; |
|
522 | + $field = $reg[1]; |
|
523 | + $table = $reg[2]; |
|
524 | 524 | |
525 | 525 | // Load content of field@table into cache array |
526 | - if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache |
|
526 | + if (!is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache |
|
527 | 527 | { |
528 | - $sql="SELECT ".$field." as aliasfield FROM ".$table; |
|
529 | - $resql=$this->db->query($sql); |
|
528 | + $sql = "SELECT ".$field." as aliasfield FROM ".$table; |
|
529 | + $resql = $this->db->query($sql); |
|
530 | 530 | if ($resql) |
531 | 531 | { |
532 | - $num=$this->db->num_rows($resql); |
|
533 | - $i=0; |
|
532 | + $num = $this->db->num_rows($resql); |
|
533 | + $i = 0; |
|
534 | 534 | while ($i < $num) |
535 | 535 | { |
536 | - $obj=$this->db->fetch_object($resql); |
|
537 | - if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield; |
|
536 | + $obj = $this->db->fetch_object($resql); |
|
537 | + if ($obj) $this->cachefieldtable[$field.'@'.$table][] = $obj->aliasfield; |
|
538 | 538 | $i++; |
539 | 539 | } |
540 | 540 | } |
@@ -545,20 +545,20 @@ discard block |
||
545 | 545 | } |
546 | 546 | |
547 | 547 | // Now we check cache is not empty (should not) and key is into cache |
548 | - if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval,$this->cachefieldtable[$field.'@'.$table])) |
|
548 | + if (!is_array($this->cachefieldtable[$field.'@'.$table]) || !in_array($newval, $this->cachefieldtable[$field.'@'.$table])) |
|
549 | 549 | { |
550 | - $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table); |
|
551 | - $this->errors[$error]['type']='FOREIGNKEY'; |
|
550 | + $this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorFieldValueNotIn', $key, $newval, $field, $table); |
|
551 | + $this->errors[$error]['type'] = 'FOREIGNKEY'; |
|
552 | 552 | $errorforthistable++; |
553 | 553 | $error++; |
554 | 554 | } |
555 | 555 | } |
556 | 556 | // If test is just a static regex |
557 | - else if (! preg_match('/'.$objimport->array_import_regex[0][$val].'/i',$newval)) |
|
557 | + else if (!preg_match('/'.$objimport->array_import_regex[0][$val].'/i', $newval)) |
|
558 | 558 | { |
559 | 559 | //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>"; |
560 | - $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]); |
|
561 | - $this->errors[$error]['type']='REGEX'; |
|
560 | + $this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorWrongValueForField', $key, $newval, $objimport->array_import_regex[0][$val]); |
|
561 | + $this->errors[$error]['type'] = 'REGEX'; |
|
562 | 562 | $errorforthistable++; |
563 | 563 | $error++; |
564 | 564 | } |
@@ -572,8 +572,8 @@ discard block |
||
572 | 572 | $listfields[] = $fieldname; |
573 | 573 | |
574 | 574 | // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert |
575 | - if (empty($newval) && $arrayrecord[($key-1)]['type'] < 0) $listvalues[] = ($newval=='0'?$newval:"null"); |
|
576 | - elseif (empty($newval) && $arrayrecord[($key-1)]['type'] == 0) $listvalues[] = "''"; |
|
575 | + if (empty($newval) && $arrayrecord[($key - 1)]['type'] < 0) $listvalues[] = ($newval == '0' ? $newval : "null"); |
|
576 | + elseif (empty($newval) && $arrayrecord[($key - 1)]['type'] == 0) $listvalues[] = "''"; |
|
577 | 577 | else $listvalues[] = "'".$this->db->escape($newval)."'"; |
578 | 578 | } |
579 | 579 | $i++; |
@@ -583,19 +583,19 @@ discard block |
||
583 | 583 | if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) |
584 | 584 | { |
585 | 585 | // Loop on each hidden fields to add them into listfields/listvalues |
586 | - foreach($objimport->array_import_fieldshidden[0] as $key => $val) |
|
586 | + foreach ($objimport->array_import_fieldshidden[0] as $key => $val) |
|
587 | 587 | { |
588 | - if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue; // Not a field of current table |
|
588 | + if (!preg_match('/^'.preg_quote($alias).'\./', $key)) continue; // Not a field of current table |
|
589 | 589 | if ($val == 'user->id') |
590 | 590 | { |
591 | - $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key); |
|
591 | + $listfields[] = preg_replace('/^'.preg_quote($alias).'\./', '', $key); |
|
592 | 592 | $listvalues[] = $user->id; |
593 | 593 | } |
594 | - elseif (preg_match('/^lastrowid-/',$val)) |
|
594 | + elseif (preg_match('/^lastrowid-/', $val)) |
|
595 | 595 | { |
596 | - $tmp=explode('-',$val); |
|
597 | - $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0; |
|
598 | - $keyfield = preg_replace('/^'.preg_quote($alias).'\./','',$key); |
|
596 | + $tmp = explode('-', $val); |
|
597 | + $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0; |
|
598 | + $keyfield = preg_replace('/^'.preg_quote($alias).'\./', '', $key); |
|
599 | 599 | $listfields[] = $keyfield; |
600 | 600 | $listvalues[] = $lastinsertid; |
601 | 601 | //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit; |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | //print 'listfields='.$listfields.'<br>listvalues='.$listvalues.'<br>'; |
606 | 606 | |
607 | 607 | // If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined |
608 | - if (! $errorforthistable) |
|
608 | + if (!$errorforthistable) |
|
609 | 609 | { |
610 | 610 | //print "$alias/$tablename/$listfields/$listvalues<br>"; |
611 | 611 | if (!empty($listfields)) |
@@ -622,21 +622,21 @@ discard block |
||
622 | 622 | $filters = array(); |
623 | 623 | foreach ($updatekeys as $key) { |
624 | 624 | $col = $objimport->array_import_updatekeys[0][$key]; |
625 | - $key=preg_replace('/^.*\./i','',$key); |
|
625 | + $key = preg_replace('/^.*\./i', '', $key); |
|
626 | 626 | $where[] = $key.' = '.$data[$key]; |
627 | 627 | $filters[] = $col.' = '.$data[$key]; |
628 | 628 | } |
629 | - $sqlSelect.= ' WHERE '.implode(' AND ', $where); |
|
629 | + $sqlSelect .= ' WHERE '.implode(' AND ', $where); |
|
630 | 630 | |
631 | - $resql=$this->db->query($sqlSelect); |
|
632 | - if($resql) { |
|
631 | + $resql = $this->db->query($sqlSelect); |
|
632 | + if ($resql) { |
|
633 | 633 | $res = $this->db->fetch_object($resql); |
634 | - if($resql->num_rows == 1) { |
|
634 | + if ($resql->num_rows == 1) { |
|
635 | 635 | $lastinsertid = $res->rowid; |
636 | 636 | $last_insert_id_array[$tablename] = $lastinsertid; |
637 | - } else if($resql->num_rows > 1) { |
|
638 | - $this->errors[$error]['lib']=$langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', ')); |
|
639 | - $this->errors[$error]['type']='SQL'; |
|
637 | + } else if ($resql->num_rows > 1) { |
|
638 | + $this->errors[$error]['lib'] = $langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', ')); |
|
639 | + $this->errors[$error]['type'] = 'SQL'; |
|
640 | 640 | $error++; |
641 | 641 | } else { |
642 | 642 | // No record found with filters, insert will be tried below |
@@ -645,8 +645,8 @@ discard block |
||
645 | 645 | else |
646 | 646 | { |
647 | 647 | //print 'E'; |
648 | - $this->errors[$error]['lib']=$this->db->lasterror(); |
|
649 | - $this->errors[$error]['type']='SQL'; |
|
648 | + $this->errors[$error]['lib'] = $this->db->lasterror(); |
|
649 | + $this->errors[$error]['type'] = 'SQL'; |
|
650 | 650 | $error++; |
651 | 651 | } |
652 | 652 | } |
@@ -660,24 +660,24 @@ discard block |
||
660 | 660 | foreach ($data as $key => $val) { |
661 | 661 | $set[] = $key.' = '.$val; |
662 | 662 | } |
663 | - $sqlstart.= ' SET '.implode(', ', $set); |
|
663 | + $sqlstart .= ' SET '.implode(', ', $set); |
|
664 | 664 | |
665 | - if(empty($keyfield)) $keyfield = 'rowid'; |
|
665 | + if (empty($keyfield)) $keyfield = 'rowid'; |
|
666 | 666 | $sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid; |
667 | 667 | |
668 | 668 | $sql = $sqlstart.$sqlend; |
669 | 669 | |
670 | 670 | // Run update request |
671 | - $resql=$this->db->query($sql); |
|
672 | - if($resql) { |
|
671 | + $resql = $this->db->query($sql); |
|
672 | + if ($resql) { |
|
673 | 673 | // No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed |
674 | 674 | $updatedone = true; |
675 | 675 | } |
676 | 676 | else |
677 | 677 | { |
678 | 678 | //print 'E'; |
679 | - $this->errors[$error]['lib']=$this->db->lasterror(); |
|
680 | - $this->errors[$error]['type']='SQL'; |
|
679 | + $this->errors[$error]['lib'] = $this->db->lasterror(); |
|
680 | + $this->errors[$error]['type'] = 'SQL'; |
|
681 | 681 | $error++; |
682 | 682 | } |
683 | 683 | } |
@@ -688,13 +688,13 @@ discard block |
||
688 | 688 | // Build SQL INSERT request |
689 | 689 | $sqlstart = 'INSERT INTO '.$tablename.'('.implode(', ', $listfields).', import_key'; |
690 | 690 | $sqlend = ') VALUES('.implode(', ', $listvalues).", '".$importid."'"; |
691 | - if (! empty($tablewithentity_cache[$tablename])) { |
|
692 | - $sqlstart.= ', entity'; |
|
693 | - $sqlend.= ', '.$conf->entity; |
|
691 | + if (!empty($tablewithentity_cache[$tablename])) { |
|
692 | + $sqlstart .= ', entity'; |
|
693 | + $sqlend .= ', '.$conf->entity; |
|
694 | 694 | } |
695 | - if (! empty($objimport->array_import_tables_creator[0][$alias])) { |
|
696 | - $sqlstart.= ', '.$objimport->array_import_tables_creator[0][$alias]; |
|
697 | - $sqlend.=', '.$user->id; |
|
695 | + if (!empty($objimport->array_import_tables_creator[0][$alias])) { |
|
696 | + $sqlstart .= ', '.$objimport->array_import_tables_creator[0][$alias]; |
|
697 | + $sqlend .= ', '.$user->id; |
|
698 | 698 | } |
699 | 699 | $sql = $sqlstart.$sqlend.')'; |
700 | 700 | dol_syslog("import_xlsx.modules", LOG_DEBUG); |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | // Run insert request |
703 | 703 | if ($sql) |
704 | 704 | { |
705 | - $resql=$this->db->query($sql); |
|
705 | + $resql = $this->db->query($sql); |
|
706 | 706 | if ($resql) |
707 | 707 | { |
708 | 708 | $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). |
@@ -711,8 +711,8 @@ discard block |
||
711 | 711 | else |
712 | 712 | { |
713 | 713 | //print 'E'; |
714 | - $this->errors[$error]['lib']=$this->db->lasterror(); |
|
715 | - $this->errors[$error]['type']='SQL'; |
|
714 | + $this->errors[$error]['lib'] = $this->db->lasterror(); |
|
715 | + $this->errors[$error]['type'] = 'SQL'; |
|
716 | 716 | $error++; |
717 | 717 | } |
718 | 718 | } |
@@ -727,8 +727,8 @@ discard block |
||
727 | 727 | if ($error) break; |
728 | 728 | } |
729 | 729 | |
730 | - if($updatedone) $this->nbupdate++; |
|
731 | - if($insertdone) $this->nbinsert++; |
|
730 | + if ($updatedone) $this->nbupdate++; |
|
731 | + if ($insertdone) $this->nbinsert++; |
|
732 | 732 | } |
733 | 733 | |
734 | 734 | return 1; |
@@ -82,9 +82,11 @@ discard block |
||
82 | 82 | // If driver use an external library, put its name here |
83 | 83 | require_once PHPEXCEL_PATH.'PHPExcel.php'; |
84 | 84 | require_once PHPEXCEL_PATH.'PHPExcel/Style/Alignment.php'; |
85 | - if (! class_exists('ZipArchive')) // For Excel2007, PHPExcel need ZipArchive |
|
85 | + if (! class_exists('ZipArchive')) { |
|
86 | + // For Excel2007, PHPExcel need ZipArchive |
|
86 | 87 | { |
87 | 88 | $langs->load("errors"); |
89 | + } |
|
88 | 90 | $this->error=$langs->trans('ErrorPHPNeedModule','zip'); |
89 | 91 | return -1; |
90 | 92 | } |
@@ -92,7 +94,9 @@ discard block |
||
92 | 94 | $this->version_lib='1.8.0'; |
93 | 95 | |
94 | 96 | $this->datatoimport=$datatoimport; |
95 | - if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db); |
|
97 | + if (preg_match('/^societe_/',$datatoimport)) { |
|
98 | + $this->thirpartyobject=new Societe($this->db); |
|
99 | + } |
|
96 | 100 | } |
97 | 101 | |
98 | 102 | |
@@ -259,8 +263,9 @@ discard block |
||
259 | 263 | global $conf; |
260 | 264 | |
261 | 265 | $rowcount = $this->workbook->getActiveSheet()->getHighestDataRow(); |
262 | - if($this->record > $rowcount) |
|
263 | - return false; |
|
266 | + if($this->record > $rowcount) { |
|
267 | + return false; |
|
268 | + } |
|
264 | 269 | $array = array(); |
265 | 270 | $colcount = PHPExcel_Cell::columnIndexFromString($this->workbook->getActiveSheet()->getHighestDataColumn(0)); |
266 | 271 | for($col=0;$col<$colcount;$col++) { |
@@ -323,8 +328,7 @@ discard block |
||
323 | 328 | $this->warnings[$warning]['lib']=$langs->trans('EmptyLine'); |
324 | 329 | $this->warnings[$warning]['type']='EMPTY'; |
325 | 330 | $warning++; |
326 | - } |
|
327 | - else |
|
331 | + } else |
|
328 | 332 | { |
329 | 333 | $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) |
330 | 334 | $updatedone = false; |
@@ -340,19 +344,27 @@ discard block |
||
340 | 344 | $errorforthistable=0; |
341 | 345 | |
342 | 346 | // Define $tablewithentity_cache[$tablename] if not already defined |
343 | - if (! isset($tablewithentity_cache[$tablename])) // keep this test with "isset" |
|
347 | + if (! isset($tablewithentity_cache[$tablename])) { |
|
348 | + // keep this test with "isset" |
|
344 | 349 | { |
345 | 350 | dol_syslog("Check if table ".$tablename." has an entity field"); |
351 | + } |
|
346 | 352 | $resql=$this->db->DDLDescTable($tablename,'entity'); |
347 | 353 | if ($resql) |
348 | 354 | { |
349 | 355 | $obj=$this->db->fetch_object($resql); |
350 | - if ($obj) $tablewithentity_cache[$tablename]=1; // table contains entity field |
|
351 | - else $tablewithentity_cache[$tablename]=0; // table does not contains entity field |
|
356 | + if ($obj) { |
|
357 | + $tablewithentity_cache[$tablename]=1; |
|
358 | + } |
|
359 | + // table contains entity field |
|
360 | + else { |
|
361 | + $tablewithentity_cache[$tablename]=0; |
|
362 | + } |
|
363 | + // table does not contains entity field |
|
364 | + } else { |
|
365 | + dol_print_error($this->db); |
|
352 | 366 | } |
353 | - else dol_print_error($this->db); |
|
354 | - } |
|
355 | - else |
|
367 | + } else |
|
356 | 368 | { |
357 | 369 | //dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]); |
358 | 370 | } |
@@ -364,13 +376,19 @@ discard block |
||
364 | 376 | $fieldalias=preg_replace('/\..*$/i','',$val); |
365 | 377 | $fieldname=preg_replace('/^.*\./i','',$val); |
366 | 378 | |
367 | - if ($alias != $fieldalias) continue; // Not a field of current table |
|
379 | + if ($alias != $fieldalias) { |
|
380 | + continue; |
|
381 | + } |
|
382 | + // Not a field of current table |
|
368 | 383 | |
369 | 384 | if ($key <= $maxfields) |
370 | 385 | { |
371 | 386 | // Set $newval with value to insert and set $listvalues with sql request part for insert |
372 | 387 | $newval=''; |
373 | - 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 |
|
388 | + if ($arrayrecord[($key-1)]['type'] > 0) { |
|
389 | + $newval=$arrayrecord[($key-1)]['val']; |
|
390 | + } |
|
391 | + // If type of field into input file is not empty string (so defined into input file), we get value |
|
374 | 392 | |
375 | 393 | // Make some tests on $newval |
376 | 394 | |
@@ -396,20 +414,23 @@ discard block |
||
396 | 414 | { |
397 | 415 | // 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. |
398 | 416 | $isidorref='id'; |
399 | - if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) $isidorref='ref'; |
|
417 | + if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) { |
|
418 | + $isidorref='ref'; |
|
419 | + } |
|
400 | 420 | $newval=preg_replace('/^(id|ref):/i','',$newval); // Remove id: or ref: that was used to force if field is id or ref |
401 | 421 | //print 'Val is now '.$newval.' and is type '.$isidorref."<br>\n"; |
402 | 422 | |
403 | - if ($isidorref == 'ref') // If value into input import file is a ref, we apply the function defined into descriptor |
|
423 | + if ($isidorref == 'ref') { |
|
424 | + // If value into input import file is a ref, we apply the function defined into descriptor |
|
404 | 425 | { |
405 | 426 | $file=(empty($objimport->array_import_convertvalue[0][$val]['classfile'])?$objimport->array_import_convertvalue[0][$val]['file']:$objimport->array_import_convertvalue[0][$val]['classfile']); |
427 | + } |
|
406 | 428 | $class=$objimport->array_import_convertvalue[0][$val]['class']; |
407 | 429 | $method=$objimport->array_import_convertvalue[0][$val]['method']; |
408 | 430 | if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '') |
409 | 431 | { |
410 | 432 | $newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]; |
411 | - } |
|
412 | - else |
|
433 | + } else |
|
413 | 434 | { |
414 | 435 | $resultload = dol_include_once($file); |
415 | 436 | if (empty($resultload)) |
@@ -427,15 +448,20 @@ discard block |
||
427 | 448 | } |
428 | 449 | $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id; |
429 | 450 | //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. '; |
430 | - if ($classinstance->id != '') // id may be 0, it is a found value |
|
451 | + if ($classinstance->id != '') { |
|
452 | + // id may be 0, it is a found value |
|
431 | 453 | { |
432 | 454 | $newval=$classinstance->id; |
433 | 455 | } |
434 | - else |
|
456 | + } else |
|
435 | 457 | { |
436 | - 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'])); |
|
437 | - 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'])); |
|
438 | - else $this->errors[$error]['lib']='ErrorFieldValueNotIn'; |
|
458 | + if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) { |
|
459 | + $this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key,$newval,'code',$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict'])); |
|
460 | + } else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) { |
|
461 | + $this->errors[$error]['lib']=$langs->trans('ErrorFieldRefNotIn',$key,$newval,$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element'])); |
|
462 | + } else { |
|
463 | + $this->errors[$error]['lib']='ErrorFieldValueNotIn'; |
|
464 | + } |
|
439 | 465 | $this->errors[$error]['type']='FOREIGNKEY'; |
440 | 466 | $errorforthistable++; |
441 | 467 | $error++; |
@@ -443,12 +469,12 @@ discard block |
||
443 | 469 | } |
444 | 470 | } |
445 | 471 | |
446 | - } |
|
447 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull') |
|
472 | + } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull') |
|
448 | 473 | { |
449 | - if (empty($newval)) $newval='0'; |
|
450 | - } |
|
451 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto') |
|
474 | + if (empty($newval)) { |
|
475 | + $newval='0'; |
|
476 | + } |
|
477 | + } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto') |
|
452 | 478 | { |
453 | 479 | if (strtolower($newval) == 'auto') |
454 | 480 | { |
@@ -456,9 +482,11 @@ discard block |
||
456 | 482 | $newval=$this->thirpartyobject->code_client; |
457 | 483 | //print 'code_client='.$newval; |
458 | 484 | } |
459 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
460 | - } |
|
461 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto') |
|
485 | + if (empty($newval)) { |
|
486 | + $arrayrecord[($key-1)]['type']=-1; |
|
487 | + } |
|
488 | + // If we get empty value, we will use "null" |
|
489 | + } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto') |
|
462 | 490 | { |
463 | 491 | if (strtolower($newval) == 'auto') |
464 | 492 | { |
@@ -466,9 +494,11 @@ discard block |
||
466 | 494 | $newval=$this->thirpartyobject->code_fournisseur; |
467 | 495 | //print 'code_fournisseur='.$newval; |
468 | 496 | } |
469 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
470 | - } |
|
471 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto') |
|
497 | + if (empty($newval)) { |
|
498 | + $arrayrecord[($key-1)]['type']=-1; |
|
499 | + } |
|
500 | + // If we get empty value, we will use "null" |
|
501 | + } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto') |
|
472 | 502 | { |
473 | 503 | if (strtolower($newval) == 'auto') |
474 | 504 | { |
@@ -476,20 +506,27 @@ discard block |
||
476 | 506 | $newval=$this->thirpartyobject->code_compta; |
477 | 507 | //print 'code_compta='.$newval; |
478 | 508 | } |
479 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
480 | - } |
|
481 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto') |
|
509 | + if (empty($newval)) { |
|
510 | + $arrayrecord[($key-1)]['type']=-1; |
|
511 | + } |
|
512 | + // If we get empty value, we will use "null" |
|
513 | + } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto') |
|
482 | 514 | { |
483 | 515 | if (strtolower($newval) == 'auto') |
484 | 516 | { |
485 | 517 | $this->thirpartyobject->get_codecompta('supplier'); |
486 | 518 | $newval=$this->thirpartyobject->code_compta_fournisseur; |
487 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
519 | + if (empty($newval)) { |
|
520 | + $arrayrecord[($key-1)]['type']=-1; |
|
521 | + } |
|
522 | + // If we get empty value, we will use "null" |
|
488 | 523 | //print 'code_compta_fournisseur='.$newval; |
489 | 524 | } |
490 | - if (empty($newval)) $arrayrecord[($key-1)]['type']=-1; // If we get empty value, we will use "null" |
|
491 | - } |
|
492 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto') |
|
525 | + if (empty($newval)) { |
|
526 | + $arrayrecord[($key-1)]['type']=-1; |
|
527 | + } |
|
528 | + // If we get empty value, we will use "null" |
|
529 | + } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto') |
|
493 | 530 | { |
494 | 531 | $defaultref=''; |
495 | 532 | // TODO provide the $modTask (module of generation of ref) as parameter of import_insert function |
@@ -500,12 +537,11 @@ discard block |
||
500 | 537 | $modTask = new $obj; |
501 | 538 | $defaultref = $modTask->getNextValue(null,null); |
502 | 539 | } |
503 | - if (is_numeric($defaultref) && $defaultref <= 0) $defaultref=''; |
|
540 | + if (is_numeric($defaultref) && $defaultref <= 0) { |
|
541 | + $defaultref=''; |
|
542 | + } |
|
504 | 543 | $newval=$defaultref; |
505 | - } |
|
506 | - |
|
507 | - |
|
508 | - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric') |
|
544 | + } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric') |
|
509 | 545 | { |
510 | 546 | $newval = price2num($newval); |
511 | 547 | } |
@@ -523,9 +559,11 @@ discard block |
||
523 | 559 | $table=$reg[2]; |
524 | 560 | |
525 | 561 | // Load content of field@table into cache array |
526 | - if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache |
|
562 | + if (! is_array($this->cachefieldtable[$field.'@'.$table])) { |
|
563 | + // If content of field@table not already loaded into cache |
|
527 | 564 | { |
528 | 565 | $sql="SELECT ".$field." as aliasfield FROM ".$table; |
566 | + } |
|
529 | 567 | $resql=$this->db->query($sql); |
530 | 568 | if ($resql) |
531 | 569 | { |
@@ -534,11 +572,12 @@ discard block |
||
534 | 572 | while ($i < $num) |
535 | 573 | { |
536 | 574 | $obj=$this->db->fetch_object($resql); |
537 | - if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield; |
|
575 | + if ($obj) { |
|
576 | + $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield; |
|
577 | + } |
|
538 | 578 | $i++; |
539 | 579 | } |
540 | - } |
|
541 | - else |
|
580 | + } else |
|
542 | 581 | { |
543 | 582 | dol_print_error($this->db); |
544 | 583 | } |
@@ -572,9 +611,13 @@ discard block |
||
572 | 611 | $listfields[] = $fieldname; |
573 | 612 | |
574 | 613 | // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert |
575 | - if (empty($newval) && $arrayrecord[($key-1)]['type'] < 0) $listvalues[] = ($newval=='0'?$newval:"null"); |
|
576 | - elseif (empty($newval) && $arrayrecord[($key-1)]['type'] == 0) $listvalues[] = "''"; |
|
577 | - else $listvalues[] = "'".$this->db->escape($newval)."'"; |
|
614 | + if (empty($newval) && $arrayrecord[($key-1)]['type'] < 0) { |
|
615 | + $listvalues[] = ($newval=='0'?$newval:"null"); |
|
616 | + } elseif (empty($newval) && $arrayrecord[($key-1)]['type'] == 0) { |
|
617 | + $listvalues[] = "''"; |
|
618 | + } else { |
|
619 | + $listvalues[] = "'".$this->db->escape($newval)."'"; |
|
620 | + } |
|
578 | 621 | } |
579 | 622 | $i++; |
580 | 623 | } |
@@ -585,13 +628,15 @@ discard block |
||
585 | 628 | // Loop on each hidden fields to add them into listfields/listvalues |
586 | 629 | foreach($objimport->array_import_fieldshidden[0] as $key => $val) |
587 | 630 | { |
588 | - if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue; // Not a field of current table |
|
631 | + if (! preg_match('/^'.preg_quote($alias).'\./', $key)) { |
|
632 | + continue; |
|
633 | + } |
|
634 | + // Not a field of current table |
|
589 | 635 | if ($val == 'user->id') |
590 | 636 | { |
591 | 637 | $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key); |
592 | 638 | $listvalues[] = $user->id; |
593 | - } |
|
594 | - elseif (preg_match('/^lastrowid-/',$val)) |
|
639 | + } elseif (preg_match('/^lastrowid-/',$val)) |
|
595 | 640 | { |
596 | 641 | $tmp=explode('-',$val); |
597 | 642 | $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0; |
@@ -641,8 +686,7 @@ discard block |
||
641 | 686 | } else { |
642 | 687 | // No record found with filters, insert will be tried below |
643 | 688 | } |
644 | - } |
|
645 | - else |
|
689 | + } else |
|
646 | 690 | { |
647 | 691 | //print 'E'; |
648 | 692 | $this->errors[$error]['lib']=$this->db->lasterror(); |
@@ -662,7 +706,9 @@ discard block |
||
662 | 706 | } |
663 | 707 | $sqlstart.= ' SET '.implode(', ', $set); |
664 | 708 | |
665 | - if(empty($keyfield)) $keyfield = 'rowid'; |
|
709 | + if(empty($keyfield)) { |
|
710 | + $keyfield = 'rowid'; |
|
711 | + } |
|
666 | 712 | $sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid; |
667 | 713 | |
668 | 714 | $sql = $sqlstart.$sqlend; |
@@ -672,8 +718,7 @@ discard block |
||
672 | 718 | if($resql) { |
673 | 719 | // No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed |
674 | 720 | $updatedone = true; |
675 | - } |
|
676 | - else |
|
721 | + } else |
|
677 | 722 | { |
678 | 723 | //print 'E'; |
679 | 724 | $this->errors[$error]['lib']=$this->db->lasterror(); |
@@ -707,8 +752,7 @@ discard block |
||
707 | 752 | { |
708 | 753 | $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). |
709 | 754 | $insertdone = true; |
710 | - } |
|
711 | - else |
|
755 | + } else |
|
712 | 756 | { |
713 | 757 | //print 'E'; |
714 | 758 | $this->errors[$error]['lib']=$this->db->lasterror(); |
@@ -724,11 +768,17 @@ discard block |
||
724 | 768 | }*/ |
725 | 769 | } |
726 | 770 | |
727 | - if ($error) break; |
|
771 | + if ($error) { |
|
772 | + break; |
|
773 | + } |
|
728 | 774 | } |
729 | 775 | |
730 | - if($updatedone) $this->nbupdate++; |
|
731 | - if($insertdone) $this->nbinsert++; |
|
776 | + if($updatedone) { |
|
777 | + $this->nbupdate++; |
|
778 | + } |
|
779 | + if($insertdone) { |
|
780 | + $this->nbinsert++; |
|
781 | + } |
|
732 | 782 | } |
733 | 783 | |
734 | 784 | return 1; |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | */ |
41 | 41 | function __construct($db) |
42 | 42 | { |
43 | - global $langs,$conf; |
|
43 | + global $langs,$conf; |
|
44 | 44 | |
45 | - $this->db = $db; |
|
45 | + $this->db = $db; |
|
46 | 46 | $this->numero = 39000; |
47 | 47 | |
48 | 48 | $this->family = "products"; |
@@ -78,18 +78,18 @@ discard block |
||
78 | 78 | // Constants |
79 | 79 | $this->const = array(); |
80 | 80 | |
81 | - $this->tabs = array(); |
|
81 | + $this->tabs = array(); |
|
82 | 82 | |
83 | - // Dictionaries |
|
84 | - if (! isset($conf->productbatch->enabled)) |
|
85 | - { |
|
86 | - $conf->productbatch=new stdClass(); |
|
87 | - $conf->productbatch->enabled=0; |
|
88 | - } |
|
83 | + // Dictionaries |
|
84 | + if (! isset($conf->productbatch->enabled)) |
|
85 | + { |
|
86 | + $conf->productbatch=new stdClass(); |
|
87 | + $conf->productbatch->enabled=0; |
|
88 | + } |
|
89 | 89 | $this->dictionaries=array(); |
90 | 90 | |
91 | - // Boxes |
|
92 | - $this->boxes = array(); // List of boxes |
|
91 | + // Boxes |
|
92 | + $this->boxes = array(); // List of boxes |
|
93 | 93 | |
94 | 94 | // Permissions |
95 | 95 | $this->rights = array(); // Permission array used by this module |
@@ -111,20 +111,20 @@ discard block |
||
111 | 111 | * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. |
112 | 112 | * It also creates data directories |
113 | 113 | * |
114 | - * @param string $options Options when enabling module ('', 'noboxes') |
|
114 | + * @param string $options Options when enabling module ('', 'noboxes') |
|
115 | 115 | * @return int 1 if OK, 0 if KO |
116 | 116 | */ |
117 | 117 | function init($options='') |
118 | 118 | { |
119 | - global $db,$conf; |
|
119 | + global $db,$conf; |
|
120 | 120 | |
121 | 121 | $sql = array(); |
122 | 122 | |
123 | 123 | if (! empty($conf->cashdesk->enabled)) { |
124 | - if (empty($conf->global->CASHDESK_NO_DECREASE_STOCK)) { |
|
125 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; |
|
126 | - $res = dolibarr_set_const($db,"CASHDESK_NO_DECREASE_STOCK",1,'chaine',0,'',$conf->entity); |
|
127 | - } |
|
124 | + if (empty($conf->global->CASHDESK_NO_DECREASE_STOCK)) { |
|
125 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; |
|
126 | + $res = dolibarr_set_const($db,"CASHDESK_NO_DECREASE_STOCK",1,'chaine',0,'',$conf->entity); |
|
127 | + } |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | return $this->_init($sql, $options); |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * \ingroup productbatch |
26 | 26 | * \brief Description and activation file for module productbatch |
27 | 27 | */ |
28 | -include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php'; |
|
28 | +include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php'; |
|
29 | 29 | |
30 | 30 | |
31 | 31 | /** |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | */ |
41 | 41 | function __construct($db) |
42 | 42 | { |
43 | - global $langs,$conf; |
|
43 | + global $langs, $conf; |
|
44 | 44 | |
45 | 45 | $this->db = $db; |
46 | 46 | $this->numero = 39000; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | $this->family = "products"; |
49 | 49 | $this->module_position = 45; |
50 | 50 | |
51 | - $this->name = preg_replace('/^mod/i','',get_class($this)); |
|
51 | + $this->name = preg_replace('/^mod/i', '', get_class($this)); |
|
52 | 52 | $this->description = "Batch number, eat-by and sell-by date management module"; |
53 | 53 | |
54 | 54 | $this->rights_class = 'productbatch'; |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); |
59 | 59 | $this->special = 0; |
60 | 60 | |
61 | - $this->picto='stock'; |
|
61 | + $this->picto = 'stock'; |
|
62 | 62 | |
63 | 63 | $this->module_parts = array(); |
64 | 64 | |
@@ -69,10 +69,10 @@ discard block |
||
69 | 69 | $this->config_page_url = array("product_lot_extrafields.php@product"); |
70 | 70 | |
71 | 71 | // Dependencies |
72 | - $this->depends = array("modProduct","modStock","modExpedition","modFournisseur"); // List of modules id that must be enabled if this module is enabled. modExpedition is required to manage batch exit (by manual stock decrease on shipment), modSupplier to manage batch entry (after supplier order). |
|
73 | - $this->requiredby = array(); // List of modules id to disable if this one is disabled |
|
74 | - $this->phpmin = array(5,0); // Minimum version of PHP required by module |
|
75 | - $this->need_dolibarr_version = array(3,0); // Minimum version of Dolibarr required by module |
|
72 | + $this->depends = array("modProduct", "modStock", "modExpedition", "modFournisseur"); // List of modules id that must be enabled if this module is enabled. modExpedition is required to manage batch exit (by manual stock decrease on shipment), modSupplier to manage batch entry (after supplier order). |
|
73 | + $this->requiredby = array(); // List of modules id to disable if this one is disabled |
|
74 | + $this->phpmin = array(5, 0); // Minimum version of PHP required by module |
|
75 | + $this->need_dolibarr_version = array(3, 0); // Minimum version of Dolibarr required by module |
|
76 | 76 | $this->langfiles = array("productbatch"); |
77 | 77 | |
78 | 78 | // Constants |
@@ -81,28 +81,28 @@ discard block |
||
81 | 81 | $this->tabs = array(); |
82 | 82 | |
83 | 83 | // Dictionaries |
84 | - if (! isset($conf->productbatch->enabled)) |
|
84 | + if (!isset($conf->productbatch->enabled)) |
|
85 | 85 | { |
86 | - $conf->productbatch=new stdClass(); |
|
87 | - $conf->productbatch->enabled=0; |
|
86 | + $conf->productbatch = new stdClass(); |
|
87 | + $conf->productbatch->enabled = 0; |
|
88 | 88 | } |
89 | - $this->dictionaries=array(); |
|
89 | + $this->dictionaries = array(); |
|
90 | 90 | |
91 | 91 | // Boxes |
92 | - $this->boxes = array(); // List of boxes |
|
92 | + $this->boxes = array(); // List of boxes |
|
93 | 93 | |
94 | 94 | // Permissions |
95 | - $this->rights = array(); // Permission array used by this module |
|
96 | - $r=0; |
|
95 | + $this->rights = array(); // Permission array used by this module |
|
96 | + $r = 0; |
|
97 | 97 | |
98 | 98 | |
99 | 99 | // Menus |
100 | 100 | //------- |
101 | - $this->menu = 1; // This module add menu entries. They are coded into menu manager. |
|
101 | + $this->menu = 1; // This module add menu entries. They are coded into menu manager. |
|
102 | 102 | |
103 | 103 | |
104 | 104 | // Exports |
105 | - $r=0; |
|
105 | + $r = 0; |
|
106 | 106 | |
107 | 107 | } |
108 | 108 | |
@@ -114,16 +114,16 @@ discard block |
||
114 | 114 | * @param string $options Options when enabling module ('', 'noboxes') |
115 | 115 | * @return int 1 if OK, 0 if KO |
116 | 116 | */ |
117 | - function init($options='') |
|
117 | + function init($options = '') |
|
118 | 118 | { |
119 | - global $db,$conf; |
|
119 | + global $db, $conf; |
|
120 | 120 | |
121 | 121 | $sql = array(); |
122 | 122 | |
123 | - if (! empty($conf->cashdesk->enabled)) { |
|
123 | + if (!empty($conf->cashdesk->enabled)) { |
|
124 | 124 | if (empty($conf->global->CASHDESK_NO_DECREASE_STOCK)) { |
125 | 125 | include_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; |
126 | - $res = dolibarr_set_const($db,"CASHDESK_NO_DECREASE_STOCK",1,'chaine',0,'',$conf->entity); |
|
126 | + $res = dolibarr_set_const($db, "CASHDESK_NO_DECREASE_STOCK", 1, 'chaine', 0, '', $conf->entity); |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 |
@@ -34,27 +34,27 @@ discard block |
||
34 | 34 | */ |
35 | 35 | abstract class ModeleDon extends CommonDocGenerator |
36 | 36 | { |
37 | - var $error=''; |
|
38 | - |
|
39 | - /** |
|
40 | - * Return list of active generation modules |
|
41 | - * |
|
42 | - * @param DoliDB $db Database handler |
|
43 | - * @param integer $maxfilenamelength Max length of value to show |
|
44 | - * @return array List of templates |
|
45 | - */ |
|
46 | - static function liste_modeles($db,$maxfilenamelength=0) |
|
47 | - { |
|
48 | - global $conf; |
|
49 | - |
|
50 | - $type='donation'; |
|
51 | - $liste=array(); |
|
52 | - |
|
53 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
|
54 | - $liste=getListOfModels($db,$type,$maxfilenamelength); |
|
55 | - |
|
56 | - return $liste; |
|
57 | - } |
|
37 | + var $error=''; |
|
38 | + |
|
39 | + /** |
|
40 | + * Return list of active generation modules |
|
41 | + * |
|
42 | + * @param DoliDB $db Database handler |
|
43 | + * @param integer $maxfilenamelength Max length of value to show |
|
44 | + * @return array List of templates |
|
45 | + */ |
|
46 | + static function liste_modeles($db,$maxfilenamelength=0) |
|
47 | + { |
|
48 | + global $conf; |
|
49 | + |
|
50 | + $type='donation'; |
|
51 | + $liste=array(); |
|
52 | + |
|
53 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
|
54 | + $liste=getListOfModels($db,$type,$maxfilenamelength); |
|
55 | + |
|
56 | + return $liste; |
|
57 | + } |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | |
@@ -63,80 +63,80 @@ discard block |
||
63 | 63 | */ |
64 | 64 | abstract class ModeleNumRefDons |
65 | 65 | { |
66 | - var $error=''; |
|
67 | - |
|
68 | - /** |
|
69 | - * Return if a module can be used or not |
|
70 | - * |
|
71 | - * @return boolean true if module can be used |
|
72 | - */ |
|
73 | - function isEnabled() |
|
74 | - { |
|
75 | - return true; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Renvoi la description par defaut du modele de numerotation |
|
80 | - * |
|
81 | - * @return string Texte descripif |
|
82 | - */ |
|
83 | - function info() |
|
84 | - { |
|
85 | - global $langs; |
|
86 | - $langs->load("bills"); |
|
87 | - return $langs->trans("NoDescription"); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Renvoi un exemple de numerotation |
|
92 | - * |
|
93 | - * @return string Example |
|
94 | - */ |
|
95 | - function getExample() |
|
96 | - { |
|
97 | - global $langs; |
|
98 | - $langs->load("bills"); |
|
99 | - return $langs->trans("NoExample"); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Test si les numeros deja en vigueur dans la base ne provoquent pas d |
|
104 | - * de conflits qui empechera cette numerotation de fonctionner. |
|
105 | - * |
|
106 | - * @return boolean false si conflit, true si ok |
|
107 | - */ |
|
108 | - function canBeActivated() |
|
109 | - { |
|
110 | - return true; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Renvoi prochaine valeur attribuee |
|
115 | - * |
|
116 | - * @return string Valeur |
|
117 | - */ |
|
118 | - function getNextValue() |
|
119 | - { |
|
120 | - global $langs; |
|
121 | - return $langs->trans("NotAvailable"); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Renvoi version du module numerotation |
|
126 | - * |
|
127 | - * @return string Valeur |
|
128 | - */ |
|
129 | - function getVersion() |
|
130 | - { |
|
131 | - global $langs; |
|
132 | - $langs->load("admin"); |
|
133 | - |
|
134 | - if ($this->version == 'development') return $langs->trans("VersionDevelopment"); |
|
135 | - if ($this->version == 'experimental') return $langs->trans("VersionExperimental"); |
|
136 | - if ($this->version == 'dolibarr') return DOL_VERSION; |
|
137 | - if ($this->version) return $this->version; |
|
138 | - return $langs->trans("NotAvailable"); |
|
139 | - } |
|
66 | + var $error=''; |
|
67 | + |
|
68 | + /** |
|
69 | + * Return if a module can be used or not |
|
70 | + * |
|
71 | + * @return boolean true if module can be used |
|
72 | + */ |
|
73 | + function isEnabled() |
|
74 | + { |
|
75 | + return true; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Renvoi la description par defaut du modele de numerotation |
|
80 | + * |
|
81 | + * @return string Texte descripif |
|
82 | + */ |
|
83 | + function info() |
|
84 | + { |
|
85 | + global $langs; |
|
86 | + $langs->load("bills"); |
|
87 | + return $langs->trans("NoDescription"); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Renvoi un exemple de numerotation |
|
92 | + * |
|
93 | + * @return string Example |
|
94 | + */ |
|
95 | + function getExample() |
|
96 | + { |
|
97 | + global $langs; |
|
98 | + $langs->load("bills"); |
|
99 | + return $langs->trans("NoExample"); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Test si les numeros deja en vigueur dans la base ne provoquent pas d |
|
104 | + * de conflits qui empechera cette numerotation de fonctionner. |
|
105 | + * |
|
106 | + * @return boolean false si conflit, true si ok |
|
107 | + */ |
|
108 | + function canBeActivated() |
|
109 | + { |
|
110 | + return true; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Renvoi prochaine valeur attribuee |
|
115 | + * |
|
116 | + * @return string Valeur |
|
117 | + */ |
|
118 | + function getNextValue() |
|
119 | + { |
|
120 | + global $langs; |
|
121 | + return $langs->trans("NotAvailable"); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Renvoi version du module numerotation |
|
126 | + * |
|
127 | + * @return string Valeur |
|
128 | + */ |
|
129 | + function getVersion() |
|
130 | + { |
|
131 | + global $langs; |
|
132 | + $langs->load("admin"); |
|
133 | + |
|
134 | + if ($this->version == 'development') return $langs->trans("VersionDevelopment"); |
|
135 | + if ($this->version == 'experimental') return $langs->trans("VersionExperimental"); |
|
136 | + if ($this->version == 'dolibarr') return DOL_VERSION; |
|
137 | + if ($this->version) return $this->version; |
|
138 | + return $langs->trans("NotAvailable"); |
|
139 | + } |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | |
@@ -155,98 +155,98 @@ discard block |
||
155 | 155 | */ |
156 | 156 | function don_create($db, $id, $message, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) |
157 | 157 | { |
158 | - global $conf, $langs; |
|
159 | - $langs->load("bills"); |
|
160 | - |
|
161 | - $eror=0; |
|
162 | - |
|
163 | - // Increase limit for PDF build |
|
164 | - $err=error_reporting(); |
|
165 | - error_reporting(0); |
|
166 | - @set_time_limit(120); |
|
167 | - error_reporting($err); |
|
168 | - |
|
169 | - $srctemplatepath=''; |
|
170 | - |
|
171 | - // Set template to use |
|
172 | - if (! dol_strlen($modele)) |
|
173 | - { |
|
174 | - if (! empty($conf->global->DON_ADDON_MODEL)) |
|
175 | - { |
|
176 | - $modele = $conf->global->DON_ADDON_MODEL; |
|
177 | - } |
|
178 | - else |
|
179 | - { |
|
180 | - print $langs->trans("Error")." ".$langs->trans("Error_DON_ADDON_MODEL_NotDefined"); |
|
181 | - return 0; |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - // If selected modele is a filename template (then $modele="modelname:filename") |
|
186 | - $tmp=explode(':',$modele,2); |
|
187 | - if (! empty($tmp[1])) |
|
188 | - { |
|
189 | - $modele=$tmp[0]; |
|
190 | - $srctemplatepath=$tmp[1]; |
|
191 | - } |
|
192 | - |
|
193 | - // Search template files |
|
194 | - $file=''; $classname=''; $filefound=0; |
|
195 | - $dirmodels=array('/'); |
|
196 | - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
197 | - foreach($dirmodels as $reldir) |
|
198 | - { |
|
199 | - foreach(array('html','doc','pdf') as $prefix) |
|
200 | - { |
|
201 | - $file = $prefix."_".preg_replace('/^html_/','',$modele).".modules.php"; |
|
202 | - |
|
203 | - // On verifie l'emplacement du modele |
|
204 | - $file=dol_buildpath($reldir."core/modules/dons/".$file,0); |
|
205 | - if (file_exists($file)) |
|
206 | - { |
|
207 | - $filefound=1; |
|
208 | - $classname=$prefix.'_'.$modele; |
|
209 | - break; |
|
210 | - } |
|
211 | - } |
|
212 | - if ($filefound) break; |
|
213 | - } |
|
214 | - |
|
215 | - // Charge le modele |
|
158 | + global $conf, $langs; |
|
159 | + $langs->load("bills"); |
|
160 | + |
|
161 | + $eror=0; |
|
162 | + |
|
163 | + // Increase limit for PDF build |
|
164 | + $err=error_reporting(); |
|
165 | + error_reporting(0); |
|
166 | + @set_time_limit(120); |
|
167 | + error_reporting($err); |
|
168 | + |
|
169 | + $srctemplatepath=''; |
|
170 | + |
|
171 | + // Set template to use |
|
172 | + if (! dol_strlen($modele)) |
|
173 | + { |
|
174 | + if (! empty($conf->global->DON_ADDON_MODEL)) |
|
175 | + { |
|
176 | + $modele = $conf->global->DON_ADDON_MODEL; |
|
177 | + } |
|
178 | + else |
|
179 | + { |
|
180 | + print $langs->trans("Error")." ".$langs->trans("Error_DON_ADDON_MODEL_NotDefined"); |
|
181 | + return 0; |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + // If selected modele is a filename template (then $modele="modelname:filename") |
|
186 | + $tmp=explode(':',$modele,2); |
|
187 | + if (! empty($tmp[1])) |
|
188 | + { |
|
189 | + $modele=$tmp[0]; |
|
190 | + $srctemplatepath=$tmp[1]; |
|
191 | + } |
|
192 | + |
|
193 | + // Search template files |
|
194 | + $file=''; $classname=''; $filefound=0; |
|
195 | + $dirmodels=array('/'); |
|
196 | + if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
197 | + foreach($dirmodels as $reldir) |
|
198 | + { |
|
199 | + foreach(array('html','doc','pdf') as $prefix) |
|
200 | + { |
|
201 | + $file = $prefix."_".preg_replace('/^html_/','',$modele).".modules.php"; |
|
202 | + |
|
203 | + // On verifie l'emplacement du modele |
|
204 | + $file=dol_buildpath($reldir."core/modules/dons/".$file,0); |
|
205 | + if (file_exists($file)) |
|
206 | + { |
|
207 | + $filefound=1; |
|
208 | + $classname=$prefix.'_'.$modele; |
|
209 | + break; |
|
210 | + } |
|
211 | + } |
|
212 | + if ($filefound) break; |
|
213 | + } |
|
214 | + |
|
215 | + // Charge le modele |
|
216 | 216 | if ($filefound) |
217 | 217 | { |
218 | - require_once $file; |
|
218 | + require_once $file; |
|
219 | 219 | |
220 | - $object=new Don($db); |
|
221 | - $object->fetch($id); |
|
220 | + $object=new Don($db); |
|
221 | + $object->fetch($id); |
|
222 | 222 | |
223 | - $classname = $modele; |
|
224 | - $obj = new $classname($db); |
|
223 | + $classname = $modele; |
|
224 | + $obj = new $classname($db); |
|
225 | 225 | |
226 | - // We save charset_output to restore it because write_file can change it if needed for |
|
227 | - // output format that does not support UTF8. |
|
228 | - $sav_charset_output=$outputlangs->charset_output; |
|
229 | - if ($obj->write_file($object,$outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) |
|
230 | - { |
|
231 | - $outputlangs->charset_output=$sav_charset_output; |
|
226 | + // We save charset_output to restore it because write_file can change it if needed for |
|
227 | + // output format that does not support UTF8. |
|
228 | + $sav_charset_output=$outputlangs->charset_output; |
|
229 | + if ($obj->write_file($object,$outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) |
|
230 | + { |
|
231 | + $outputlangs->charset_output=$sav_charset_output; |
|
232 | 232 | |
233 | 233 | // we delete preview files |
234 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
235 | - dol_delete_preview($object); |
|
236 | - return 1; |
|
237 | - } |
|
238 | - else |
|
239 | - { |
|
240 | - $outputlangs->charset_output=$sav_charset_output; |
|
241 | - dol_syslog("Erreur dans don_create"); |
|
242 | - dol_print_error($db,$obj->error); |
|
243 | - return 0; |
|
244 | - } |
|
245 | - } |
|
246 | - else |
|
247 | - { |
|
248 | - print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); |
|
249 | - return 0; |
|
250 | - } |
|
234 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
235 | + dol_delete_preview($object); |
|
236 | + return 1; |
|
237 | + } |
|
238 | + else |
|
239 | + { |
|
240 | + $outputlangs->charset_output=$sav_charset_output; |
|
241 | + dol_syslog("Erreur dans don_create"); |
|
242 | + dol_print_error($db,$obj->error); |
|
243 | + return 0; |
|
244 | + } |
|
245 | + } |
|
246 | + else |
|
247 | + { |
|
248 | + print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); |
|
249 | + return 0; |
|
250 | + } |
|
251 | 251 | } |
252 | 252 |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | abstract class ModeleDon extends CommonDocGenerator |
36 | 36 | { |
37 | - var $error=''; |
|
37 | + var $error = ''; |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Return list of active generation modules |
@@ -43,15 +43,15 @@ discard block |
||
43 | 43 | * @param integer $maxfilenamelength Max length of value to show |
44 | 44 | * @return array List of templates |
45 | 45 | */ |
46 | - static function liste_modeles($db,$maxfilenamelength=0) |
|
46 | + static function liste_modeles($db, $maxfilenamelength = 0) |
|
47 | 47 | { |
48 | 48 | global $conf; |
49 | 49 | |
50 | - $type='donation'; |
|
51 | - $liste=array(); |
|
50 | + $type = 'donation'; |
|
51 | + $liste = array(); |
|
52 | 52 | |
53 | 53 | include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
54 | - $liste=getListOfModels($db,$type,$maxfilenamelength); |
|
54 | + $liste = getListOfModels($db, $type, $maxfilenamelength); |
|
55 | 55 | |
56 | 56 | return $liste; |
57 | 57 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | abstract class ModeleNumRefDons |
65 | 65 | { |
66 | - var $error=''; |
|
66 | + var $error = ''; |
|
67 | 67 | |
68 | 68 | /** |
69 | 69 | * Return if a module can be used or not |
@@ -153,25 +153,25 @@ discard block |
||
153 | 153 | * @param int $hideref Hide ref |
154 | 154 | * @return int 0 if KO, 1 if OK |
155 | 155 | */ |
156 | -function don_create($db, $id, $message, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) |
|
156 | +function don_create($db, $id, $message, $modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0) |
|
157 | 157 | { |
158 | 158 | global $conf, $langs; |
159 | 159 | $langs->load("bills"); |
160 | 160 | |
161 | - $eror=0; |
|
161 | + $eror = 0; |
|
162 | 162 | |
163 | 163 | // Increase limit for PDF build |
164 | - $err=error_reporting(); |
|
164 | + $err = error_reporting(); |
|
165 | 165 | error_reporting(0); |
166 | 166 | @set_time_limit(120); |
167 | 167 | error_reporting($err); |
168 | 168 | |
169 | - $srctemplatepath=''; |
|
169 | + $srctemplatepath = ''; |
|
170 | 170 | |
171 | 171 | // Set template to use |
172 | - if (! dol_strlen($modele)) |
|
172 | + if (!dol_strlen($modele)) |
|
173 | 173 | { |
174 | - if (! empty($conf->global->DON_ADDON_MODEL)) |
|
174 | + if (!empty($conf->global->DON_ADDON_MODEL)) |
|
175 | 175 | { |
176 | 176 | $modele = $conf->global->DON_ADDON_MODEL; |
177 | 177 | } |
@@ -183,29 +183,29 @@ discard block |
||
183 | 183 | } |
184 | 184 | |
185 | 185 | // If selected modele is a filename template (then $modele="modelname:filename") |
186 | - $tmp=explode(':',$modele,2); |
|
187 | - if (! empty($tmp[1])) |
|
186 | + $tmp = explode(':', $modele, 2); |
|
187 | + if (!empty($tmp[1])) |
|
188 | 188 | { |
189 | - $modele=$tmp[0]; |
|
190 | - $srctemplatepath=$tmp[1]; |
|
189 | + $modele = $tmp[0]; |
|
190 | + $srctemplatepath = $tmp[1]; |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | // Search template files |
194 | - $file=''; $classname=''; $filefound=0; |
|
195 | - $dirmodels=array('/'); |
|
196 | - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
197 | - foreach($dirmodels as $reldir) |
|
194 | + $file = ''; $classname = ''; $filefound = 0; |
|
195 | + $dirmodels = array('/'); |
|
196 | + if (is_array($conf->modules_parts['models'])) $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']); |
|
197 | + foreach ($dirmodels as $reldir) |
|
198 | 198 | { |
199 | - foreach(array('html','doc','pdf') as $prefix) |
|
199 | + foreach (array('html', 'doc', 'pdf') as $prefix) |
|
200 | 200 | { |
201 | - $file = $prefix."_".preg_replace('/^html_/','',$modele).".modules.php"; |
|
201 | + $file = $prefix."_".preg_replace('/^html_/', '', $modele).".modules.php"; |
|
202 | 202 | |
203 | 203 | // On verifie l'emplacement du modele |
204 | - $file=dol_buildpath($reldir."core/modules/dons/".$file,0); |
|
204 | + $file = dol_buildpath($reldir."core/modules/dons/".$file, 0); |
|
205 | 205 | if (file_exists($file)) |
206 | 206 | { |
207 | - $filefound=1; |
|
208 | - $classname=$prefix.'_'.$modele; |
|
207 | + $filefound = 1; |
|
208 | + $classname = $prefix.'_'.$modele; |
|
209 | 209 | break; |
210 | 210 | } |
211 | 211 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | { |
218 | 218 | require_once $file; |
219 | 219 | |
220 | - $object=new Don($db); |
|
220 | + $object = new Don($db); |
|
221 | 221 | $object->fetch($id); |
222 | 222 | |
223 | 223 | $classname = $modele; |
@@ -225,10 +225,10 @@ discard block |
||
225 | 225 | |
226 | 226 | // We save charset_output to restore it because write_file can change it if needed for |
227 | 227 | // output format that does not support UTF8. |
228 | - $sav_charset_output=$outputlangs->charset_output; |
|
229 | - if ($obj->write_file($object,$outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) |
|
228 | + $sav_charset_output = $outputlangs->charset_output; |
|
229 | + if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) |
|
230 | 230 | { |
231 | - $outputlangs->charset_output=$sav_charset_output; |
|
231 | + $outputlangs->charset_output = $sav_charset_output; |
|
232 | 232 | |
233 | 233 | // we delete preview files |
234 | 234 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
@@ -237,15 +237,15 @@ discard block |
||
237 | 237 | } |
238 | 238 | else |
239 | 239 | { |
240 | - $outputlangs->charset_output=$sav_charset_output; |
|
240 | + $outputlangs->charset_output = $sav_charset_output; |
|
241 | 241 | dol_syslog("Erreur dans don_create"); |
242 | - dol_print_error($db,$obj->error); |
|
242 | + dol_print_error($db, $obj->error); |
|
243 | 243 | return 0; |
244 | 244 | } |
245 | 245 | } |
246 | 246 | else |
247 | 247 | { |
248 | - print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); |
|
248 | + print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file); |
|
249 | 249 | return 0; |
250 | 250 | } |
251 | 251 | } |
@@ -131,10 +131,18 @@ discard block |
||
131 | 131 | global $langs; |
132 | 132 | $langs->load("admin"); |
133 | 133 | |
134 | - if ($this->version == 'development') return $langs->trans("VersionDevelopment"); |
|
135 | - if ($this->version == 'experimental') return $langs->trans("VersionExperimental"); |
|
136 | - if ($this->version == 'dolibarr') return DOL_VERSION; |
|
137 | - if ($this->version) return $this->version; |
|
134 | + if ($this->version == 'development') { |
|
135 | + return $langs->trans("VersionDevelopment"); |
|
136 | + } |
|
137 | + if ($this->version == 'experimental') { |
|
138 | + return $langs->trans("VersionExperimental"); |
|
139 | + } |
|
140 | + if ($this->version == 'dolibarr') { |
|
141 | + return DOL_VERSION; |
|
142 | + } |
|
143 | + if ($this->version) { |
|
144 | + return $this->version; |
|
145 | + } |
|
138 | 146 | return $langs->trans("NotAvailable"); |
139 | 147 | } |
140 | 148 | } |
@@ -174,8 +182,7 @@ discard block |
||
174 | 182 | if (! empty($conf->global->DON_ADDON_MODEL)) |
175 | 183 | { |
176 | 184 | $modele = $conf->global->DON_ADDON_MODEL; |
177 | - } |
|
178 | - else |
|
185 | + } else |
|
179 | 186 | { |
180 | 187 | print $langs->trans("Error")." ".$langs->trans("Error_DON_ADDON_MODEL_NotDefined"); |
181 | 188 | return 0; |
@@ -193,7 +200,9 @@ discard block |
||
193 | 200 | // Search template files |
194 | 201 | $file=''; $classname=''; $filefound=0; |
195 | 202 | $dirmodels=array('/'); |
196 | - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
203 | + if (is_array($conf->modules_parts['models'])) { |
|
204 | + $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
205 | + } |
|
197 | 206 | foreach($dirmodels as $reldir) |
198 | 207 | { |
199 | 208 | foreach(array('html','doc','pdf') as $prefix) |
@@ -209,7 +218,9 @@ discard block |
||
209 | 218 | break; |
210 | 219 | } |
211 | 220 | } |
212 | - if ($filefound) break; |
|
221 | + if ($filefound) { |
|
222 | + break; |
|
223 | + } |
|
213 | 224 | } |
214 | 225 | |
215 | 226 | // Charge le modele |
@@ -234,16 +245,14 @@ discard block |
||
234 | 245 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
235 | 246 | dol_delete_preview($object); |
236 | 247 | return 1; |
237 | - } |
|
238 | - else |
|
248 | + } else |
|
239 | 249 | { |
240 | 250 | $outputlangs->charset_output=$sav_charset_output; |
241 | 251 | dol_syslog("Erreur dans don_create"); |
242 | 252 | dol_print_error($db,$obj->error); |
243 | 253 | return 0; |
244 | 254 | } |
245 | - } |
|
246 | - else |
|
255 | + } else |
|
247 | 256 | { |
248 | 257 | print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); |
249 | 258 | return 0; |
@@ -101,7 +101,7 @@ |
||
101 | 101 | * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. |
102 | 102 | * It also creates data directories |
103 | 103 | * |
104 | - * @param string $options Options when enabling module ('', 'noboxes') |
|
104 | + * @param string $options Options when enabling module ('', 'noboxes') |
|
105 | 105 | * @return int 1 if OK, 0 if KO |
106 | 106 | */ |
107 | 107 | function init($options='') |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * \brief Fichier de description et activation du module Generation document |
26 | 26 | */ |
27 | 27 | |
28 | -include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php'; |
|
28 | +include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php'; |
|
29 | 29 | |
30 | 30 | |
31 | 31 | /** |
@@ -47,14 +47,14 @@ discard block |
||
47 | 47 | $this->family = "technic"; |
48 | 48 | $this->module_position = 80; |
49 | 49 | // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) |
50 | - $this->name = preg_replace('/^mod/i','',get_class($this)); |
|
50 | + $this->name = preg_replace('/^mod/i', '', get_class($this)); |
|
51 | 51 | $this->description = "Direct mail document generation"; |
52 | 52 | // Possible values for version are: 'development', 'experimental', 'dolibarr' or version |
53 | 53 | $this->version = 'development'; |
54 | 54 | |
55 | 55 | $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); |
56 | 56 | $this->special = 0; |
57 | - $this->picto='email'; |
|
57 | + $this->picto = 'email'; |
|
58 | 58 | |
59 | 59 | // Data directories to create when module is enabled |
60 | 60 | $this->dirs = array("/documentgeneration/temp"); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $this->depends = array(); |
67 | 67 | $this->requiredby = array(); |
68 | 68 | $this->conflictwith = array(); |
69 | - $this->langfiles = array("orders","bills","companies","mails"); |
|
69 | + $this->langfiles = array("orders", "bills", "companies", "mails"); |
|
70 | 70 | |
71 | 71 | // Constants |
72 | 72 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $this->rights = array(); |
80 | 80 | $this->rights_class = 'document'; |
81 | 81 | |
82 | - $r=0; |
|
82 | + $r = 0; |
|
83 | 83 | |
84 | 84 | $this->rights[$r][0] = 1521; |
85 | 85 | $this->rights[$r][1] = 'Lire les documents'; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @param string $options Options when enabling module ('', 'noboxes') |
105 | 105 | * @return int 1 if OK, 0 if KO |
106 | 106 | */ |
107 | - function init($options='') |
|
107 | + function init($options = '') |
|
108 | 108 | { |
109 | 109 | global $conf; |
110 | 110 | |
@@ -113,6 +113,6 @@ discard block |
||
113 | 113 | |
114 | 114 | $sql = array(); |
115 | 115 | |
116 | - return $this->_init($sql,$options); |
|
116 | + return $this->_init($sql, $options); |
|
117 | 117 | } |
118 | 118 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $this->rights[$r][2] = 'd'; |
146 | 146 | $this->rights[$r][3] = 0; |
147 | 147 | $this->rights[$r][4] = 'order_advance'; |
148 | - $this->rights[$r][5] = 'send'; |
|
148 | + $this->rights[$r][5] = 'send'; |
|
149 | 149 | |
150 | 150 | $r++; |
151 | 151 | $this->rights[$r][0] = 87; |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. |
228 | 228 | * It also creates data directories |
229 | 229 | * |
230 | - * @param string $options Options when enabling module ('', 'newboxdefonly', 'noboxes') |
|
230 | + * @param string $options Options when enabling module ('', 'newboxdefonly', 'noboxes') |
|
231 | 231 | * @return int 1 if OK, 0 if KO |
232 | 232 | */ |
233 | 233 | function init($options='') |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * \brief Fichier de description et activation du module Commande |
30 | 30 | */ |
31 | 31 | |
32 | -include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php'; |
|
32 | +include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php'; |
|
33 | 33 | |
34 | 34 | |
35 | 35 | /** |
@@ -53,14 +53,14 @@ discard block |
||
53 | 53 | $this->family = "crm"; |
54 | 54 | $this->module_position = 30; |
55 | 55 | // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) |
56 | - $this->name = preg_replace('/^mod/i','',get_class($this)); |
|
56 | + $this->name = preg_replace('/^mod/i', '', get_class($this)); |
|
57 | 57 | $this->description = "Gestion des commandes clients"; |
58 | 58 | // Possible values for version are: 'development', 'experimental', 'dolibarr' or version |
59 | 59 | $this->version = 'dolibarr'; |
60 | 60 | |
61 | 61 | $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); |
62 | 62 | $this->special = 0; |
63 | - $this->picto='order'; |
|
63 | + $this->picto = 'order'; |
|
64 | 64 | |
65 | 65 | // Data directories to create when module is enabled |
66 | 66 | $this->dirs = array("/commande/temp"); |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | $this->depends = array("modSociete"); |
73 | 73 | $this->requiredby = array("modExpedition"); |
74 | 74 | $this->conflictwith = array(); |
75 | - $this->langfiles = array('orders', 'bills', 'companies','products', 'deliveries'); |
|
75 | + $this->langfiles = array('orders', 'bills', 'companies', 'products', 'deliveries'); |
|
76 | 76 | |
77 | 77 | // Constants |
78 | 78 | $this->const = array(); |
79 | - $r=0; |
|
79 | + $r = 0; |
|
80 | 80 | |
81 | 81 | $this->const[$r][0] = "COMMANDE_ADDON_PDF"; |
82 | 82 | $this->const[$r][1] = "chaine"; |
@@ -107,15 +107,15 @@ discard block |
||
107 | 107 | |
108 | 108 | // Boxes |
109 | 109 | $this->boxes = array( |
110 | - 0=>array('file'=>'box_commandes.php','enabledbydefaulton'=>'Home'), |
|
111 | - 2=>array('file'=>'box_graph_orders_permonth.php','enabledbydefaulton'=>'Home') |
|
110 | + 0=>array('file'=>'box_commandes.php', 'enabledbydefaulton'=>'Home'), |
|
111 | + 2=>array('file'=>'box_graph_orders_permonth.php', 'enabledbydefaulton'=>'Home') |
|
112 | 112 | ); |
113 | 113 | |
114 | 114 | // Permissions |
115 | 115 | $this->rights = array(); |
116 | 116 | $this->rights_class = 'commande'; |
117 | 117 | |
118 | - $r=0; |
|
118 | + $r = 0; |
|
119 | 119 | |
120 | 120 | $r++; |
121 | 121 | $this->rights[$r][0] = 81; |
@@ -180,45 +180,45 @@ discard block |
||
180 | 180 | |
181 | 181 | // Menus |
182 | 182 | //------- |
183 | - $this->menu = 1; // This module add menu entries. They are coded into menu manager. |
|
183 | + $this->menu = 1; // This module add menu entries. They are coded into menu manager. |
|
184 | 184 | |
185 | 185 | |
186 | 186 | // Exports |
187 | 187 | //-------- |
188 | - $r=0; |
|
188 | + $r = 0; |
|
189 | 189 | |
190 | 190 | $r++; |
191 | - $this->export_code[$r]=$this->rights_class.'_'.$r; |
|
192 | - $this->export_label[$r]='CustomersOrdersAndOrdersLines'; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
193 | - $this->export_permission[$r]=array(array("commande","commande","export")); |
|
194 | - $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','d.nom'=>'State','co.label'=>'Country','co.code'=>"CountryCode",'s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','c.rowid'=>"Id",'c.ref'=>"Ref",'c.ref_client'=>"RefCustomer",'c.fk_soc'=>"IdCompany",'c.date_creation'=>"DateCreation",'c.date_commande'=>"OrderDate",'c.amount_ht'=>"Amount",'c.remise_percent'=>"GlobalDiscount",'c.total_ht'=>"TotalHT",'c.total_ttc'=>"TotalTTC",'c.facture'=>"Billed",'c.fk_statut'=>'Status','c.note_public'=>"Note",'c.date_livraison'=>'DeliveryDate','c.fk_user_author'=>'CreatedById','uc.login'=>'CreatedByLogin','c.fk_user_valid'=>'ValidatedById','uv.login'=>'ValidatedByLogin','pj.ref'=>'ProjectRef','cd.rowid'=>'LineId','cd.label'=>"Label",'cd.description'=>"LineDescription",'cd.product_type'=>'TypeOfLineServiceOrProduct','cd.tva_tx'=>"LineVATRate",'cd.qty'=>"LineQty",'cd.total_ht'=>"LineTotalHT",'cd.total_tva'=>"LineTotalVAT",'cd.total_ttc'=>"LineTotalTTC",'p.rowid'=>'ProductId','p.ref'=>'ProductRef','p.label'=>'ProductLabel'); |
|
191 | + $this->export_code[$r] = $this->rights_class.'_'.$r; |
|
192 | + $this->export_label[$r] = 'CustomersOrdersAndOrdersLines'; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
193 | + $this->export_permission[$r] = array(array("commande", "commande", "export")); |
|
194 | + $this->export_fields_array[$r] = array('s.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'd.nom'=>'State', 'co.label'=>'Country', 'co.code'=>"CountryCode", 's.phone'=>'Phone', 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 'c.rowid'=>"Id", 'c.ref'=>"Ref", 'c.ref_client'=>"RefCustomer", 'c.fk_soc'=>"IdCompany", 'c.date_creation'=>"DateCreation", 'c.date_commande'=>"OrderDate", 'c.amount_ht'=>"Amount", 'c.remise_percent'=>"GlobalDiscount", 'c.total_ht'=>"TotalHT", 'c.total_ttc'=>"TotalTTC", 'c.facture'=>"Billed", 'c.fk_statut'=>'Status', 'c.note_public'=>"Note", 'c.date_livraison'=>'DeliveryDate', 'c.fk_user_author'=>'CreatedById', 'uc.login'=>'CreatedByLogin', 'c.fk_user_valid'=>'ValidatedById', 'uv.login'=>'ValidatedByLogin', 'pj.ref'=>'ProjectRef', 'cd.rowid'=>'LineId', 'cd.label'=>"Label", 'cd.description'=>"LineDescription", 'cd.product_type'=>'TypeOfLineServiceOrProduct', 'cd.tva_tx'=>"LineVATRate", 'cd.qty'=>"LineQty", 'cd.total_ht'=>"LineTotalHT", 'cd.total_tva'=>"LineTotalVAT", 'cd.total_ttc'=>"LineTotalTTC", 'p.rowid'=>'ProductId', 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel'); |
|
195 | 195 | //$this->export_TypeFields_array[$r]=array('s.rowid'=>"List:societe:nom",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','co.label'=>'List:c_country:label:label','co.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','c.ref'=>"Text",'c.ref_client'=>"Text",'c.date_creation'=>"Date",'c.date_commande'=>"Date",'c.amount_ht'=>"Numeric",'c.remise_percent'=>"Numeric",'c.total_ht'=>"Numeric",'c.total_ttc'=>"Numeric",'c.facture'=>"Boolean",'c.fk_statut'=>'Status','c.note_public'=>"Text",'c.date_livraison'=>'Date','cd.description'=>"Text",'cd.product_type'=>'Boolean','cd.tva_tx'=>"Numeric",'cd.qty'=>"Numeric",'cd.total_ht'=>"Numeric",'cd.total_tva'=>"Numeric",'cd.total_ttc'=>"Numeric",'p.rowid'=>'List:product:ref','p.ref'=>'Text','p.label'=>'Text'); |
196 | - $this->export_TypeFields_array[$r]=array('s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','co.label'=>'List:c_country:label:label','co.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','c.ref'=>"Text",'c.ref_client'=>"Text",'c.date_creation'=>"Date",'c.date_commande'=>"Date",'c.amount_ht'=>"Numeric",'c.remise_percent'=>"Numeric",'c.total_ht'=>"Numeric",'c.total_ttc'=>"Numeric",'c.facture'=>"Boolean",'c.fk_statut'=>'Status','c.note_public'=>"Text",'c.date_livraison'=>'Date','pj.ref'=>'Text','cd.description'=>"Text",'cd.product_type'=>'Boolean','cd.tva_tx'=>"Numeric",'cd.qty'=>"Numeric",'cd.total_ht'=>"Numeric",'cd.total_tva'=>"Numeric",'cd.total_ttc'=>"Numeric",'p.rowid'=>'List:product:ref','p.ref'=>'Text','p.label'=>'Text','d.nom'=>'Text'); |
|
197 | - $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','d.nom'=>'company','co.label'=>'company','co.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.siret'=>'company','c.rowid'=>"order",'c.ref'=>"order",'c.ref_client'=>"order",'c.fk_soc'=>"order",'c.date_creation'=>"order",'c.date_commande'=>"order",'c.amount_ht'=>"order",'c.remise_percent'=>"order",'c.total_ht'=>"order",'c.total_ttc'=>"order",'c.facture'=>"order",'c.fk_statut'=>"order",'c.note'=>"order",'c.date_livraison'=>"order",'pj.ref'=>'project','cd.rowid'=>'order_line','cd.label'=>"order_line",'cd.description'=>"order_line",'cd.product_type'=>'order_line','cd.tva_tx'=>"order_line",'cd.qty'=>"order_line",'cd.total_ht'=>"order_line",'cd.total_tva'=>"order_line",'cd.total_ttc'=>"order_line",'p.rowid'=>'product','p.ref'=>'product','p.label'=>'product'); |
|
198 | - $this->export_dependencies_array[$r]=array('order_line'=>'cd.rowid','product'=>'cd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them |
|
199 | - $keyforselect='commande'; $keyforelement='order'; $keyforaliasextra='extra'; |
|
196 | + $this->export_TypeFields_array[$r] = array('s.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'co.label'=>'List:c_country:label:label', 'co.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 'c.ref'=>"Text", 'c.ref_client'=>"Text", 'c.date_creation'=>"Date", 'c.date_commande'=>"Date", 'c.amount_ht'=>"Numeric", 'c.remise_percent'=>"Numeric", 'c.total_ht'=>"Numeric", 'c.total_ttc'=>"Numeric", 'c.facture'=>"Boolean", 'c.fk_statut'=>'Status', 'c.note_public'=>"Text", 'c.date_livraison'=>'Date', 'pj.ref'=>'Text', 'cd.description'=>"Text", 'cd.product_type'=>'Boolean', 'cd.tva_tx'=>"Numeric", 'cd.qty'=>"Numeric", 'cd.total_ht'=>"Numeric", 'cd.total_tva'=>"Numeric", 'cd.total_ttc'=>"Numeric", 'p.rowid'=>'List:product:ref', 'p.ref'=>'Text', 'p.label'=>'Text', 'd.nom'=>'Text'); |
|
197 | + $this->export_entities_array[$r] = array('s.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'd.nom'=>'company', 'co.label'=>'company', 'co.code'=>'company', 's.phone'=>'company', 's.siren'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.siret'=>'company', 'c.rowid'=>"order", 'c.ref'=>"order", 'c.ref_client'=>"order", 'c.fk_soc'=>"order", 'c.date_creation'=>"order", 'c.date_commande'=>"order", 'c.amount_ht'=>"order", 'c.remise_percent'=>"order", 'c.total_ht'=>"order", 'c.total_ttc'=>"order", 'c.facture'=>"order", 'c.fk_statut'=>"order", 'c.note'=>"order", 'c.date_livraison'=>"order", 'pj.ref'=>'project', 'cd.rowid'=>'order_line', 'cd.label'=>"order_line", 'cd.description'=>"order_line", 'cd.product_type'=>'order_line', 'cd.tva_tx'=>"order_line", 'cd.qty'=>"order_line", 'cd.total_ht'=>"order_line", 'cd.total_tva'=>"order_line", 'cd.total_ttc'=>"order_line", 'p.rowid'=>'product', 'p.ref'=>'product', 'p.label'=>'product'); |
|
198 | + $this->export_dependencies_array[$r] = array('order_line'=>'cd.rowid', 'product'=>'cd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them |
|
199 | + $keyforselect = 'commande'; $keyforelement = 'order'; $keyforaliasextra = 'extra'; |
|
200 | 200 | include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
201 | - $keyforselect='commandedet'; $keyforelement='order_line'; $keyforaliasextra='extra2'; |
|
201 | + $keyforselect = 'commandedet'; $keyforelement = 'order_line'; $keyforaliasextra = 'extra2'; |
|
202 | 202 | include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
203 | - $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra3'; |
|
203 | + $keyforselect = 'product'; $keyforelement = 'product'; $keyforaliasextra = 'extra3'; |
|
204 | 204 | include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
205 | - $this->export_sql_start[$r]='SELECT DISTINCT '; |
|
206 | - $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; |
|
207 | - if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; |
|
208 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; |
|
209 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,'; |
|
210 | - $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande as c'; |
|
211 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON c.fk_projet = pj.rowid'; |
|
212 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON c.fk_user_author = uc.rowid'; |
|
213 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON c.fk_user_valid = uv.rowid'; |
|
214 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'commande_extrafields as extra ON c.rowid = extra.fk_object'; |
|
215 | - $this->export_sql_end[$r] .=' , '.MAIN_DB_PREFIX.'commandedet as cd'; |
|
216 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet_extrafields as extra2 on cd.rowid = extra2.fk_object'; |
|
217 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on cd.fk_product = p.rowid'; |
|
218 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object'; |
|
219 | - $this->export_sql_end[$r] .=' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_commande'; |
|
220 | - $this->export_sql_end[$r] .=' AND c.entity IN ('.getEntity('commande').')'; |
|
221 | - if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.(empty($user)?0:$user->id); |
|
205 | + $this->export_sql_start[$r] = 'SELECT DISTINCT '; |
|
206 | + $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s'; |
|
207 | + if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; |
|
208 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; |
|
209 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,'; |
|
210 | + $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'commande as c'; |
|
211 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON c.fk_projet = pj.rowid'; |
|
212 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON c.fk_user_author = uc.rowid'; |
|
213 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON c.fk_user_valid = uv.rowid'; |
|
214 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_extrafields as extra ON c.rowid = extra.fk_object'; |
|
215 | + $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'commandedet as cd'; |
|
216 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet_extrafields as extra2 on cd.rowid = extra2.fk_object'; |
|
217 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on cd.fk_product = p.rowid'; |
|
218 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object'; |
|
219 | + $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_commande'; |
|
220 | + $this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('commande').')'; |
|
221 | + if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | |
@@ -230,27 +230,27 @@ discard block |
||
230 | 230 | * @param string $options Options when enabling module ('', 'newboxdefonly', 'noboxes') |
231 | 231 | * @return int 1 if OK, 0 if KO |
232 | 232 | */ |
233 | - function init($options='') |
|
233 | + function init($options = '') |
|
234 | 234 | { |
235 | - global $conf,$langs; |
|
235 | + global $conf, $langs; |
|
236 | 236 | |
237 | 237 | // Permissions |
238 | 238 | $this->remove($options); |
239 | 239 | |
240 | 240 | //ODT template |
241 | - $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/orders/template_order.odt'; |
|
242 | - $dirodt=DOL_DATA_ROOT.'/doctemplates/orders'; |
|
243 | - $dest=$dirodt.'/template_order.odt'; |
|
241 | + $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/orders/template_order.odt'; |
|
242 | + $dirodt = DOL_DATA_ROOT.'/doctemplates/orders'; |
|
243 | + $dest = $dirodt.'/template_order.odt'; |
|
244 | 244 | |
245 | - if (file_exists($src) && ! file_exists($dest)) |
|
245 | + if (file_exists($src) && !file_exists($dest)) |
|
246 | 246 | { |
247 | 247 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
248 | 248 | dol_mkdir($dirodt); |
249 | - $result=dol_copy($src,$dest,0,0); |
|
249 | + $result = dol_copy($src, $dest, 0, 0); |
|
250 | 250 | if ($result < 0) |
251 | 251 | { |
252 | 252 | $langs->load("errors"); |
253 | - $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest); |
|
253 | + $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest); |
|
254 | 254 | return 0; |
255 | 255 | } |
256 | 256 | } |
@@ -260,6 +260,6 @@ discard block |
||
260 | 260 | "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','order',".$conf->entity.")" |
261 | 261 | ); |
262 | 262 | |
263 | - return $this->_init($sql,$options); |
|
263 | + return $this->_init($sql, $options); |
|
264 | 264 | } |
265 | 265 | } |
@@ -204,7 +204,9 @@ discard block |
||
204 | 204 | include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
205 | 205 | $this->export_sql_start[$r]='SELECT DISTINCT '; |
206 | 206 | $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; |
207 | - if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; |
|
207 | + if (empty($user->rights->societe->client->voir)) { |
|
208 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; |
|
209 | + } |
|
208 | 210 | $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; |
209 | 211 | $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,'; |
210 | 212 | $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande as c'; |
@@ -218,7 +220,9 @@ discard block |
||
218 | 220 | $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object'; |
219 | 221 | $this->export_sql_end[$r] .=' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_commande'; |
220 | 222 | $this->export_sql_end[$r] .=' AND c.entity IN ('.getEntity('commande').')'; |
221 | - if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.(empty($user)?0:$user->id); |
|
223 | + if (empty($user->rights->societe->client->voir)) { |
|
224 | + $this->export_sql_end[$r] .=' AND sc.fk_user = '.(empty($user)?0:$user->id); |
|
225 | + } |
|
222 | 226 | } |
223 | 227 | |
224 | 228 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * \ingroup produit |
27 | 27 | * \brief File to describe module to manage catalog of predefined products |
28 | 28 | */ |
29 | -include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php'; |
|
29 | +include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php'; |
|
30 | 30 | |
31 | 31 | |
32 | 32 | /** |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function __construct($db) |
43 | 43 | { |
44 | - global $langs,$conf; |
|
44 | + global $langs, $conf; |
|
45 | 45 | |
46 | 46 | $this->db = $db; |
47 | 47 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | // It is used to group modules in module setup page |
56 | 56 | $this->family = "products"; |
57 | 57 | // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) |
58 | - $this->name = preg_replace('/^mod/i','',get_class($this)); |
|
58 | + $this->name = preg_replace('/^mod/i', '', get_class($this)); |
|
59 | 59 | // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module) |
60 | 60 | $this->description = 'Allows creating products variant based on new attributes'; |
61 | 61 | // Possible values for version are: 'development', 'experimental', 'dolibarr' or version |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | // Name of image file used for this module. |
68 | 68 | // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' |
69 | 69 | // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module' |
70 | - $this->picto='product'; |
|
70 | + $this->picto = 'product'; |
|
71 | 71 | |
72 | 72 | // Defined all module parts (triggers, login, substitutions, menus, css, etc...) |
73 | 73 | $this->module_parts = array(); |
@@ -82,14 +82,14 @@ discard block |
||
82 | 82 | ); |
83 | 83 | |
84 | 84 | // Dependencies |
85 | - $this->hidden = false; // A condition to hide module |
|
85 | + $this->hidden = false; // A condition to hide module |
|
86 | 86 | $this->depends = array( |
87 | 87 | 'modProduct' |
88 | - ); // List of modules id that must be enabled if this module is enabled |
|
89 | - $this->requiredby = array(); // List of modules id to disable if this one is disabled |
|
90 | - $this->conflictwith = array(); // List of modules id this module is in conflict with |
|
91 | - $this->phpmin = array(5,0); // Minimum version of PHP required by module |
|
92 | - $this->need_dolibarr_version = array(3,0); // Minimum version of Dolibarr required by module |
|
88 | + ); // List of modules id that must be enabled if this module is enabled |
|
89 | + $this->requiredby = array(); // List of modules id to disable if this one is disabled |
|
90 | + $this->conflictwith = array(); // List of modules id this module is in conflict with |
|
91 | + $this->phpmin = array(5, 0); // Minimum version of PHP required by module |
|
92 | + $this->need_dolibarr_version = array(3, 0); // Minimum version of Dolibarr required by module |
|
93 | 93 | $this->langfiles = array("products"); |
94 | 94 | |
95 | 95 | // Constants |
@@ -101,19 +101,19 @@ discard block |
||
101 | 101 | ); |
102 | 102 | |
103 | 103 | // Dictionaries |
104 | - if (! isset($conf->mymodule->enabled)) |
|
104 | + if (!isset($conf->mymodule->enabled)) |
|
105 | 105 | { |
106 | - $conf->mymodule=new stdClass(); |
|
107 | - $conf->mymodule->enabled=0; |
|
106 | + $conf->mymodule = new stdClass(); |
|
107 | + $conf->mymodule->enabled = 0; |
|
108 | 108 | } |
109 | - $this->dictionaries=array(); |
|
109 | + $this->dictionaries = array(); |
|
110 | 110 | |
111 | 111 | // Boxes |
112 | 112 | // Add here list of php file(s) stored in core/boxes that contains class to show a box. |
113 | - $this->boxes = array(); // List of boxes |
|
113 | + $this->boxes = array(); // List of boxes |
|
114 | 114 | |
115 | 115 | // Permissions |
116 | - $this->rights = array(); // Permission array used by this module |
|
116 | + $this->rights = array(); // Permission array used by this module |
|
117 | 117 | |
118 | 118 | // Main menu entries |
119 | 119 | $this->menu = array( |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | 'target' => '', |
132 | 132 | 'user' => 0 |
133 | 133 | ) |
134 | - ); // List of menus to add |
|
134 | + ); // List of menus to add |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 |
@@ -109,18 +109,18 @@ discard block |
||
109 | 109 | { |
110 | 110 | //$nblignes = count($object->lines); // This is set later with array of tasks |
111 | 111 | |
112 | - // Definition of $dir and $file |
|
113 | - if ($object->specimen) |
|
114 | - { |
|
115 | - $dir = $conf->bank->dir_output; |
|
116 | - $file = $dir . "/SPECIMEN.pdf"; |
|
117 | - } |
|
118 | - else |
|
119 | - { |
|
120 | - $objectref = dol_sanitizeFileName($object->ref); |
|
121 | - $dir = $conf->bank->dir_output . "/" . $objectref; |
|
122 | - $file = $dir . "/" . $objectref . ".pdf"; |
|
123 | - } |
|
112 | + // Definition of $dir and $file |
|
113 | + if ($object->specimen) |
|
114 | + { |
|
115 | + $dir = $conf->bank->dir_output; |
|
116 | + $file = $dir . "/SPECIMEN.pdf"; |
|
117 | + } |
|
118 | + else |
|
119 | + { |
|
120 | + $objectref = dol_sanitizeFileName($object->ref); |
|
121 | + $dir = $conf->bank->dir_output . "/" . $objectref; |
|
122 | + $file = $dir . "/" . $objectref . ".pdf"; |
|
123 | + } |
|
124 | 124 | |
125 | 125 | if (! file_exists($dir)) |
126 | 126 | { |
@@ -144,19 +144,19 @@ discard block |
||
144 | 144 | global $action; |
145 | 145 | $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
146 | 146 | |
147 | - $pdf=pdf_getInstance($this->format); |
|
148 | - $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance |
|
149 | - $heightforinfotot = 50; // Height reserved to output the info and total part |
|
150 | - $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5); // Height reserved to output the free text on last page |
|
151 | - $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) |
|
152 | - $pdf->SetAutoPageBreak(1,0); |
|
147 | + $pdf=pdf_getInstance($this->format); |
|
148 | + $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance |
|
149 | + $heightforinfotot = 50; // Height reserved to output the info and total part |
|
150 | + $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5); // Height reserved to output the free text on last page |
|
151 | + $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) |
|
152 | + $pdf->SetAutoPageBreak(1,0); |
|
153 | 153 | |
154 | - if (class_exists('TCPDF')) |
|
155 | - { |
|
156 | - $pdf->setPrintHeader(false); |
|
157 | - $pdf->setPrintFooter(false); |
|
158 | - } |
|
159 | - $pdf->SetFont(pdf_getPDFFont($outputlangs)); |
|
154 | + if (class_exists('TCPDF')) |
|
155 | + { |
|
156 | + $pdf->setPrintHeader(false); |
|
157 | + $pdf->setPrintFooter(false); |
|
158 | + } |
|
159 | + $pdf->SetFont(pdf_getPDFFont($outputlangs)); |
|
160 | 160 | |
161 | 161 | $pdf->Open(); |
162 | 162 | $pagenb=0; |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | $tab_top = 50; |
183 | 183 | $tab_height = 200; |
184 | 184 | $tab_top_newpage = 40; |
185 | - $tab_height_newpage = 210; |
|
185 | + $tab_height_newpage = 210; |
|
186 | 186 | |
187 | 187 | // Affiche notes |
188 | 188 | if (! empty($object->note_public)) |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | { |
280 | 280 | global $conf,$mysoc; |
281 | 281 | |
282 | - $default_font_size = pdf_getPDFFontSize($outputlangs); |
|
282 | + $default_font_size = pdf_getPDFFontSize($outputlangs); |
|
283 | 283 | |
284 | 284 | |
285 | 285 | } |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | $pdf->SetTextColor(0,0,60); |
305 | 305 | $pdf->SetFont('','B', $default_font_size + 3); |
306 | 306 | |
307 | - $posx=$this->page_largeur-$this->marge_droite-100; |
|
307 | + $posx=$this->page_largeur-$this->marge_droite-100; |
|
308 | 308 | $posy=$this->marge_haute; |
309 | 309 | |
310 | 310 | $pdf->SetXY($this->marge_gauche,$posy); |
@@ -315,8 +315,8 @@ discard block |
||
315 | 315 | { |
316 | 316 | if (is_readable($logo)) |
317 | 317 | { |
318 | - $height=pdf_getHeightForLogo($logo); |
|
319 | - $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) |
|
318 | + $height=pdf_getHeightForLogo($logo); |
|
319 | + $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) |
|
320 | 320 | } |
321 | 321 | else |
322 | 322 | { |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | |
374 | 374 | /** |
375 | 375 | * Show footer of page. Need this->emetteur object |
376 | - * |
|
376 | + * |
|
377 | 377 | * @param PDF $pdf PDF |
378 | 378 | * @param Project $object Object to show |
379 | 379 | * @param Translate $outputlangs Object lang for output |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | class pdf_ban extends ModeleBankAccountDoc |
37 | 37 | { |
38 | - var $emetteur; // Objet societe qui emet |
|
38 | + var $emetteur; // Objet societe qui emet |
|
39 | 39 | var $version = 'development'; |
40 | 40 | |
41 | 41 | /** |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | function __construct($db) |
47 | 47 | { |
48 | - global $conf,$langs,$mysoc; |
|
48 | + global $conf, $langs, $mysoc; |
|
49 | 49 | |
50 | 50 | $langs->load("main"); |
51 | 51 | $langs->load("bank"); |
@@ -58,30 +58,30 @@ discard block |
||
58 | 58 | |
59 | 59 | // Dimension page pour format A4 |
60 | 60 | $this->type = 'pdf'; |
61 | - $formatarray=pdf_getFormat(); |
|
61 | + $formatarray = pdf_getFormat(); |
|
62 | 62 | $this->page_largeur = $formatarray['width']; |
63 | 63 | $this->page_hauteur = $formatarray['height']; |
64 | - $this->format = array($this->page_largeur,$this->page_hauteur); |
|
65 | - $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10; |
|
66 | - $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10; |
|
67 | - $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10; |
|
68 | - $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10; |
|
64 | + $this->format = array($this->page_largeur, $this->page_hauteur); |
|
65 | + $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10; |
|
66 | + $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10; |
|
67 | + $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10; |
|
68 | + $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10; |
|
69 | 69 | |
70 | - $this->option_logo = 1; // Affiche logo FAC_PDF_LOGO |
|
71 | - $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION |
|
72 | - $this->option_codeproduitservice = 1; // Affiche code produit-service |
|
70 | + $this->option_logo = 1; // Affiche logo FAC_PDF_LOGO |
|
71 | + $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION |
|
72 | + $this->option_codeproduitservice = 1; // Affiche code produit-service |
|
73 | 73 | |
74 | 74 | // Recupere emmetteur |
75 | - $this->emetteur=$mysoc; |
|
76 | - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined |
|
75 | + $this->emetteur = $mysoc; |
|
76 | + if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined |
|
77 | 77 | |
78 | 78 | // Defini position des colonnes |
79 | - $this->posxref=$this->marge_gauche+1; |
|
80 | - $this->posxlabel=$this->marge_gauche+25; |
|
81 | - $this->posxworkload=$this->marge_gauche+100; |
|
82 | - $this->posxprogress=$this->marge_gauche+130; |
|
83 | - $this->posxdatestart=$this->marge_gauche+150; |
|
84 | - $this->posxdateend=$this->marge_gauche+170; |
|
79 | + $this->posxref = $this->marge_gauche + 1; |
|
80 | + $this->posxlabel = $this->marge_gauche + 25; |
|
81 | + $this->posxworkload = $this->marge_gauche + 100; |
|
82 | + $this->posxprogress = $this->marge_gauche + 130; |
|
83 | + $this->posxdatestart = $this->marge_gauche + 150; |
|
84 | + $this->posxdateend = $this->marge_gauche + 170; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | |
@@ -92,13 +92,13 @@ discard block |
||
92 | 92 | * @param Translate $outputlangs Lang output object |
93 | 93 | * @return int 1 if OK, <=0 if KO |
94 | 94 | */ |
95 | - function write_file($object,$outputlangs) |
|
95 | + function write_file($object, $outputlangs) |
|
96 | 96 | { |
97 | 97 | global $conf, $hookmanager, $langs, $user; |
98 | 98 | |
99 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
99 | + if (!is_object($outputlangs)) $outputlangs = $langs; |
|
100 | 100 | // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO |
101 | - if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; |
|
101 | + if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1'; |
|
102 | 102 | |
103 | 103 | $outputlangs->load("main"); |
104 | 104 | $outputlangs->load("dict"); |
@@ -113,20 +113,20 @@ discard block |
||
113 | 113 | if ($object->specimen) |
114 | 114 | { |
115 | 115 | $dir = $conf->bank->dir_output; |
116 | - $file = $dir . "/SPECIMEN.pdf"; |
|
116 | + $file = $dir."/SPECIMEN.pdf"; |
|
117 | 117 | } |
118 | 118 | else |
119 | 119 | { |
120 | 120 | $objectref = dol_sanitizeFileName($object->ref); |
121 | - $dir = $conf->bank->dir_output . "/" . $objectref; |
|
122 | - $file = $dir . "/" . $objectref . ".pdf"; |
|
121 | + $dir = $conf->bank->dir_output."/".$objectref; |
|
122 | + $file = $dir."/".$objectref.".pdf"; |
|
123 | 123 | } |
124 | 124 | |
125 | - if (! file_exists($dir)) |
|
125 | + if (!file_exists($dir)) |
|
126 | 126 | { |
127 | 127 | if (dol_mkdir($dir) < 0) |
128 | 128 | { |
129 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
129 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
130 | 130 | return 0; |
131 | 131 | } |
132 | 132 | } |
@@ -134,22 +134,22 @@ discard block |
||
134 | 134 | if (file_exists($dir)) |
135 | 135 | { |
136 | 136 | // Add pdfgeneration hook |
137 | - if (! is_object($hookmanager)) |
|
137 | + if (!is_object($hookmanager)) |
|
138 | 138 | { |
139 | 139 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
140 | - $hookmanager=new HookManager($this->db); |
|
140 | + $hookmanager = new HookManager($this->db); |
|
141 | 141 | } |
142 | 142 | $hookmanager->initHooks(array('pdfgeneration')); |
143 | - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); |
|
143 | + $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs); |
|
144 | 144 | global $action; |
145 | - $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
145 | + $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
|
146 | 146 | |
147 | - $pdf=pdf_getInstance($this->format); |
|
148 | - $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance |
|
149 | - $heightforinfotot = 50; // Height reserved to output the info and total part |
|
150 | - $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5); // Height reserved to output the free text on last page |
|
151 | - $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) |
|
152 | - $pdf->SetAutoPageBreak(1,0); |
|
147 | + $pdf = pdf_getInstance($this->format); |
|
148 | + $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance |
|
149 | + $heightforinfotot = 50; // Height reserved to output the info and total part |
|
150 | + $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page |
|
151 | + $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) |
|
152 | + $pdf->SetAutoPageBreak(1, 0); |
|
153 | 153 | |
154 | 154 | if (class_exists('TCPDF')) |
155 | 155 | { |
@@ -159,25 +159,25 @@ discard block |
||
159 | 159 | $pdf->SetFont(pdf_getPDFFont($outputlangs)); |
160 | 160 | |
161 | 161 | $pdf->Open(); |
162 | - $pagenb=0; |
|
163 | - $pdf->SetDrawColor(128,128,128); |
|
162 | + $pagenb = 0; |
|
163 | + $pdf->SetDrawColor(128, 128, 128); |
|
164 | 164 | |
165 | 165 | $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); |
166 | 166 | $pdf->SetSubject($outputlangs->transnoentities("BAN")); |
167 | 167 | $pdf->SetCreator("Dolibarr ".DOL_VERSION); |
168 | 168 | $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); |
169 | 169 | $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("BAN")); |
170 | - if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); |
|
170 | + if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); |
|
171 | 171 | |
172 | - $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right |
|
172 | + $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right |
|
173 | 173 | |
174 | 174 | // New page |
175 | 175 | $pdf->AddPage(); |
176 | 176 | $pagenb++; |
177 | 177 | $this->_pagehead($pdf, $object, 1, $outputlangs); |
178 | - $pdf->SetFont('','', $default_font_size - 1); |
|
179 | - $pdf->MultiCell(0, 3, ''); // Set interline to 3 |
|
180 | - $pdf->SetTextColor(0,0,0); |
|
178 | + $pdf->SetFont('', '', $default_font_size - 1); |
|
179 | + $pdf->MultiCell(0, 3, ''); // Set interline to 3 |
|
180 | + $pdf->SetTextColor(0, 0, 0); |
|
181 | 181 | |
182 | 182 | $tab_top = 50; |
183 | 183 | $tab_height = 200; |
@@ -185,23 +185,23 @@ discard block |
||
185 | 185 | $tab_height_newpage = 210; |
186 | 186 | |
187 | 187 | // Affiche notes |
188 | - if (! empty($object->note_public)) |
|
188 | + if (!empty($object->note_public)) |
|
189 | 189 | { |
190 | - $pdf->SetFont('','', $default_font_size - 1); |
|
191 | - $pdf->writeHTMLCell(190, 3, $this->posxref-1, $tab_top-2, dol_htmlentitiesbr($object->note_public), 0, 1); |
|
190 | + $pdf->SetFont('', '', $default_font_size - 1); |
|
191 | + $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2, dol_htmlentitiesbr($object->note_public), 0, 1); |
|
192 | 192 | $nexY = $pdf->GetY(); |
193 | - $height_note=$nexY-($tab_top-2); |
|
193 | + $height_note = $nexY - ($tab_top - 2); |
|
194 | 194 | |
195 | 195 | // Rect prend une longueur en 3eme param |
196 | - $pdf->SetDrawColor(192,192,192); |
|
197 | - $pdf->Rect($this->marge_gauche, $tab_top-3, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1); |
|
196 | + $pdf->SetDrawColor(192, 192, 192); |
|
197 | + $pdf->Rect($this->marge_gauche, $tab_top - 3, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1); |
|
198 | 198 | |
199 | 199 | $tab_height = $tab_height - $height_note; |
200 | - $tab_top = $nexY+6; |
|
200 | + $tab_top = $nexY + 6; |
|
201 | 201 | } |
202 | 202 | else |
203 | 203 | { |
204 | - $height_note=0; |
|
204 | + $height_note = 0; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | $iniY = $tab_top + 7; |
@@ -217,50 +217,50 @@ discard block |
||
217 | 217 | if ($pagenb == 1) |
218 | 218 | { |
219 | 219 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); |
220 | - $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
|
220 | + $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
|
221 | 221 | } |
222 | 222 | else |
223 | 223 | { |
224 | 224 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); |
225 | - $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
|
225 | + $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /* |
229 | 229 | * Pied de page |
230 | 230 | */ |
231 | - $this->_pagefoot($pdf,$object,$outputlangs); |
|
232 | - if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); |
|
231 | + $this->_pagefoot($pdf, $object, $outputlangs); |
|
232 | + if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages(); |
|
233 | 233 | |
234 | 234 | $pdf->Close(); |
235 | 235 | |
236 | - $pdf->Output($file,'F'); |
|
236 | + $pdf->Output($file, 'F'); |
|
237 | 237 | |
238 | 238 | // Add pdfgeneration hook |
239 | - if (! is_object($hookmanager)) |
|
239 | + if (!is_object($hookmanager)) |
|
240 | 240 | { |
241 | 241 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
242 | - $hookmanager=new HookManager($this->db); |
|
242 | + $hookmanager = new HookManager($this->db); |
|
243 | 243 | } |
244 | 244 | $hookmanager->initHooks(array('pdfgeneration')); |
245 | - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); |
|
245 | + $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs); |
|
246 | 246 | global $action; |
247 | - $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
247 | + $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
248 | 248 | |
249 | - if (! empty($conf->global->MAIN_UMASK)) |
|
249 | + if (!empty($conf->global->MAIN_UMASK)) |
|
250 | 250 | @chmod($file, octdec($conf->global->MAIN_UMASK)); |
251 | 251 | |
252 | 252 | $this->result = array('fullpath'=>$file); |
253 | 253 | |
254 | - return 1; // Pas d'erreur |
|
254 | + return 1; // Pas d'erreur |
|
255 | 255 | } |
256 | 256 | else |
257 | 257 | { |
258 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
258 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
259 | 259 | return 0; |
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
263 | - $this->error=$langs->transnoentities("ErrorConstantNotDefined","LIVRAISON_OUTPUTDIR"); |
|
263 | + $this->error = $langs->transnoentities("ErrorConstantNotDefined", "LIVRAISON_OUTPUTDIR"); |
|
264 | 264 | return 0; |
265 | 265 | } |
266 | 266 | |
@@ -277,9 +277,9 @@ discard block |
||
277 | 277 | * @param int $hidebottom Hide bottom bar of array |
278 | 278 | * @return void |
279 | 279 | */ |
280 | - function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0) |
|
280 | + function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0) |
|
281 | 281 | { |
282 | - global $conf,$mysoc; |
|
282 | + global $conf, $mysoc; |
|
283 | 283 | |
284 | 284 | $default_font_size = pdf_getPDFFontSize($outputlangs); |
285 | 285 | |
@@ -297,55 +297,55 @@ discard block |
||
297 | 297 | */ |
298 | 298 | function _pagehead(&$pdf, $object, $showaddress, $outputlangs) |
299 | 299 | { |
300 | - global $langs,$conf,$mysoc; |
|
300 | + global $langs, $conf, $mysoc; |
|
301 | 301 | |
302 | 302 | $default_font_size = pdf_getPDFFontSize($outputlangs); |
303 | 303 | |
304 | - pdf_pagehead($pdf,$outputlangs,$this->page_hauteur); |
|
304 | + pdf_pagehead($pdf, $outputlangs, $this->page_hauteur); |
|
305 | 305 | |
306 | - $pdf->SetTextColor(0,0,60); |
|
307 | - $pdf->SetFont('','B', $default_font_size + 3); |
|
306 | + $pdf->SetTextColor(0, 0, 60); |
|
307 | + $pdf->SetFont('', 'B', $default_font_size + 3); |
|
308 | 308 | |
309 | - $posx=$this->page_largeur-$this->marge_droite-100; |
|
310 | - $posy=$this->marge_haute; |
|
309 | + $posx = $this->page_largeur - $this->marge_droite - 100; |
|
310 | + $posy = $this->marge_haute; |
|
311 | 311 | |
312 | - $pdf->SetXY($this->marge_gauche,$posy); |
|
312 | + $pdf->SetXY($this->marge_gauche, $posy); |
|
313 | 313 | |
314 | 314 | // Logo |
315 | - $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo; |
|
315 | + $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo; |
|
316 | 316 | if ($mysoc->logo) |
317 | 317 | { |
318 | 318 | if (is_readable($logo)) |
319 | 319 | { |
320 | - $height=pdf_getHeightForLogo($logo); |
|
321 | - $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) |
|
320 | + $height = pdf_getHeightForLogo($logo); |
|
321 | + $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) |
|
322 | 322 | } |
323 | 323 | else |
324 | 324 | { |
325 | - $pdf->SetTextColor(200,0,0); |
|
326 | - $pdf->SetFont('','B', $default_font_size - 2); |
|
327 | - $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L'); |
|
325 | + $pdf->SetTextColor(200, 0, 0); |
|
326 | + $pdf->SetFont('', 'B', $default_font_size - 2); |
|
327 | + $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L'); |
|
328 | 328 | $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L'); |
329 | 329 | } |
330 | 330 | } |
331 | 331 | else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L'); |
332 | 332 | |
333 | - $pdf->SetFont('','B', $default_font_size + 3); |
|
334 | - $pdf->SetXY($posx,$posy); |
|
335 | - $pdf->SetTextColor(0,0,60); |
|
333 | + $pdf->SetFont('', 'B', $default_font_size + 3); |
|
334 | + $pdf->SetXY($posx, $posy); |
|
335 | + $pdf->SetTextColor(0, 0, 60); |
|
336 | 336 | $pdf->MultiCell(100, 4, $outputlangs->transnoentities("BAN")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R'); |
337 | - $pdf->SetFont('','', $default_font_size + 2); |
|
337 | + $pdf->SetFont('', '', $default_font_size + 2); |
|
338 | 338 | |
339 | - $posy+=6; |
|
340 | - $pdf->SetXY($posx,$posy); |
|
341 | - $pdf->SetTextColor(0,0,60); |
|
342 | - $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : " . dol_print_date(dol_now(),'day',false,$outputlangs,true), '', 'R'); |
|
339 | + $posy += 6; |
|
340 | + $pdf->SetXY($posx, $posy); |
|
341 | + $pdf->SetTextColor(0, 0, 60); |
|
342 | + $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : ".dol_print_date(dol_now(), 'day', false, $outputlangs, true), '', 'R'); |
|
343 | 343 | /*$posy+=6; |
344 | 344 | $pdf->SetXY($posx,$posy); |
345 | 345 | $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd")." : " . dol_print_date($object->date_end,'day',false,$outputlangs,true), '', 'R'); |
346 | 346 | */ |
347 | 347 | |
348 | - $pdf->SetTextColor(0,0,60); |
|
348 | + $pdf->SetTextColor(0, 0, 60); |
|
349 | 349 | |
350 | 350 | // Add list of linked objects |
351 | 351 | /* Removed: A project can have more than thousands linked objects (orders, invoices, proposals, etc.... |
@@ -382,10 +382,10 @@ discard block |
||
382 | 382 | * @param int $hidefreetext 1=Hide free text |
383 | 383 | * @return integer |
384 | 384 | */ |
385 | - function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0) |
|
385 | + function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0) |
|
386 | 386 | { |
387 | 387 | global $conf; |
388 | - $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS; |
|
388 | + $showdetails = $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS; |
|
389 | 389 | //return pdf_pagefoot($pdf,$outputlangs,'BANK_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext); |
390 | 390 | } |
391 | 391 |
@@ -73,7 +73,10 @@ discard block |
||
73 | 73 | |
74 | 74 | // Recupere emmetteur |
75 | 75 | $this->emetteur=$mysoc; |
76 | - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined |
|
76 | + if (! $this->emetteur->country_code) { |
|
77 | + $this->emetteur->country_code=substr($langs->defaultlang,-2); |
|
78 | + } |
|
79 | + // By default if not defined |
|
77 | 80 | |
78 | 81 | // Defini position des colonnes |
79 | 82 | $this->posxref=$this->marge_gauche+1; |
@@ -96,9 +99,13 @@ discard block |
||
96 | 99 | { |
97 | 100 | global $conf, $hookmanager, $langs, $user; |
98 | 101 | |
99 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
102 | + if (! is_object($outputlangs)) { |
|
103 | + $outputlangs=$langs; |
|
104 | + } |
|
100 | 105 | // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO |
101 | - if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; |
|
106 | + if (! empty($conf->global->MAIN_USE_FPDF)) { |
|
107 | + $outputlangs->charset_output='ISO-8859-1'; |
|
108 | + } |
|
102 | 109 | |
103 | 110 | $outputlangs->load("main"); |
104 | 111 | $outputlangs->load("dict"); |
@@ -114,8 +121,7 @@ discard block |
||
114 | 121 | { |
115 | 122 | $dir = $conf->bank->dir_output; |
116 | 123 | $file = $dir . "/SPECIMEN.pdf"; |
117 | - } |
|
118 | - else |
|
124 | + } else |
|
119 | 125 | { |
120 | 126 | $objectref = dol_sanitizeFileName($object->ref); |
121 | 127 | $dir = $conf->bank->dir_output . "/" . $objectref; |
@@ -167,7 +173,9 @@ discard block |
||
167 | 173 | $pdf->SetCreator("Dolibarr ".DOL_VERSION); |
168 | 174 | $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); |
169 | 175 | $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("BAN")); |
170 | - if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); |
|
176 | + if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) { |
|
177 | + $pdf->SetCompression(false); |
|
178 | + } |
|
171 | 179 | |
172 | 180 | $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right |
173 | 181 | |
@@ -198,8 +206,7 @@ discard block |
||
198 | 206 | |
199 | 207 | $tab_height = $tab_height - $height_note; |
200 | 208 | $tab_top = $nexY+6; |
201 | - } |
|
202 | - else |
|
209 | + } else |
|
203 | 210 | { |
204 | 211 | $height_note=0; |
205 | 212 | } |
@@ -218,8 +225,7 @@ discard block |
||
218 | 225 | { |
219 | 226 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); |
220 | 227 | $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
221 | - } |
|
222 | - else |
|
228 | + } else |
|
223 | 229 | { |
224 | 230 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); |
225 | 231 | $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
@@ -229,7 +235,9 @@ discard block |
||
229 | 235 | * Pied de page |
230 | 236 | */ |
231 | 237 | $this->_pagefoot($pdf,$object,$outputlangs); |
232 | - if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); |
|
238 | + if (method_exists($pdf,'AliasNbPages')) { |
|
239 | + $pdf->AliasNbPages(); |
|
240 | + } |
|
233 | 241 | |
234 | 242 | $pdf->Close(); |
235 | 243 | |
@@ -246,14 +254,14 @@ discard block |
||
246 | 254 | global $action; |
247 | 255 | $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
248 | 256 | |
249 | - if (! empty($conf->global->MAIN_UMASK)) |
|
250 | - @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
257 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
258 | + @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
259 | + } |
|
251 | 260 | |
252 | 261 | $this->result = array('fullpath'=>$file); |
253 | 262 | |
254 | 263 | return 1; // Pas d'erreur |
255 | - } |
|
256 | - else |
|
264 | + } else |
|
257 | 265 | { |
258 | 266 | $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
259 | 267 | return 0; |
@@ -319,16 +327,16 @@ discard block |
||
319 | 327 | { |
320 | 328 | $height=pdf_getHeightForLogo($logo); |
321 | 329 | $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) |
322 | - } |
|
323 | - else |
|
330 | + } else |
|
324 | 331 | { |
325 | 332 | $pdf->SetTextColor(200,0,0); |
326 | 333 | $pdf->SetFont('','B', $default_font_size - 2); |
327 | 334 | $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L'); |
328 | 335 | $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L'); |
329 | 336 | } |
337 | + } else { |
|
338 | + $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L'); |
|
330 | 339 | } |
331 | - else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L'); |
|
332 | 340 | |
333 | 341 | $pdf->SetFont('','B', $default_font_size + 3); |
334 | 342 | $pdf->SetXY($posx,$posy); |