diff --git a/htdocs/exports/export.class.php b/htdocs/exports/export.class.php index cfd28b86c91..ce0a3540187 100644 --- a/htdocs/exports/export.class.php +++ b/htdocs/exports/export.class.php @@ -187,16 +187,6 @@ class Export else $i++; $newfield=$key.' as '.$value; - // Cas particulier -/* if ($this->array_export_module[$indice]->name == 'Banque') - { - // Cas special du debit et credit - if ($value=='credit' || $value=='debit') - { - $newfield='IF('.$key.'>0,'.$key.',NULL) as '.$value; - } - } -*/ $sql.=$newfield; } $sql.=$this->array_export_sql_end[$indice]; @@ -213,49 +203,57 @@ class Export // Open file create_exdir($dirname); - $objmodel->open_file($dirname."/".$filename); + $result=$objmodel->open_file($dirname."/".$filename); - // Genere en-tete - $objmodel->write_header($langs); - - // Genere ligne de titre - $objmodel->write_title($this->array_export_fields[$indice],$array_selected,$langs); - - while ($objp = $this->db->fetch_object($resql)) + if ($result >= 0) { - $var=!$var; - - // Process special operations - if (! empty($this->array_export_special[$indice])) + // Genere en-tete + $objmodel->write_header($langs); + + // Genere ligne de titre + $objmodel->write_title($this->array_export_fields[$indice],$array_selected,$langs); + + while ($objp = $this->db->fetch_object($resql)) { - foreach ($this->array_export_special[$indice] as $key => $value) - { - if (! array_key_exists($key, $array_selected)) continue; // Field not selected - // Operation NULLIFNEG - if ($this->array_export_special[$indice][$key]=='NULLIFNEG') - { - $alias=$this->array_export_alias[$indice][$key]; - if ($objp->$alias < 0) $objp->$alias=''; - } - // Operation ZEROIFNEG - if ($this->array_export_special[$indice][$key]=='ZEROIFNEG') - { - $alias=$this->array_export_alias[$indice][$key]; - if ($objp->$alias < 0) $objp->$alias='0'; + $var=!$var; + + // Process special operations + if (! empty($this->array_export_special[$indice])) + { + foreach ($this->array_export_special[$indice] as $key => $value) + { + if (! array_key_exists($key, $array_selected)) continue; // Field not selected + // Operation NULLIFNEG + if ($this->array_export_special[$indice][$key]=='NULLIFNEG') + { + $alias=$this->array_export_alias[$indice][$key]; + if ($objp->$alias < 0) $objp->$alias=''; + } + // Operation ZEROIFNEG + if ($this->array_export_special[$indice][$key]=='ZEROIFNEG') + { + $alias=$this->array_export_alias[$indice][$key]; + if ($objp->$alias < 0) $objp->$alias='0'; + } } } - } - // end of special operation processing - - $objmodel->write_record($this->array_export_alias[$indice],$array_selected,$objp); - } - - // Genere en-tete - $objmodel->write_footer($langs); - - // Close file - $objmodel->close_file(); - + // end of special operation processing + + $objmodel->write_record($this->array_export_alias[$indice],$array_selected,$objp); + } + + // Genere en-tete + $objmodel->write_footer($langs); + + // Close file + $objmodel->close_file(); + } + else + { + $this->error=$objmodel->error; + dolibarr_syslog("Error: ".$this->error); + return -1; + } } else { diff --git a/htdocs/includes/modules/export/export_csv.modules.php b/htdocs/includes/modules/export/export_csv.modules.php index b81b3edcbe7..ce628acfd90 100644 --- a/htdocs/includes/modules/export/export_csv.modules.php +++ b/htdocs/includes/modules/export/export_csv.modules.php @@ -97,11 +97,28 @@ class ExportCsv extends ModeleExports } - function open_file($file) + /** + * \brief Open output file + * \param file Path of filename + * \return int <0 if KO, >=0 if OK + */ + function open_file($file) { - dolibarr_syslog("ExportCsv::open_file file=$file"); - $this->handle = fopen($file, "wt"); - return 0; + global $langs; + dolibarr_syslog("ExportCsv::open_file file=".$file); + + $ret=1; + + $langs->load("exports"); + $this->handle = fopen($file, "wt"); + if (! $this->handle) + { + $langs->load("errors"); + $this->error=$langs->trans("ErrorFailToCreateFile",$file); + $ret=-1; + } + + return $ret; } diff --git a/htdocs/includes/modules/export/export_excel.modules.php b/htdocs/includes/modules/export/export_excel.modules.php index 152635f3b00..ac0a31bd956 100644 --- a/htdocs/includes/modules/export/export_excel.modules.php +++ b/htdocs/includes/modules/export/export_excel.modules.php @@ -104,18 +104,26 @@ class ExportExcel extends ModeleExports } + /** + * \brief Open output file + * \param file Path of filename + * \return int <0 if KO, >=0 if OK + */ function open_file($file) { global $langs; + dolibarr_syslog("ExportExcel::open_file file=".$file); + + $ret=1; + $langs->load("exports"); - dolibarr_syslog("ExportExcel::open_file file=$file"); $this->workbook = &new writeexcel_workbookbig($file); $this->workbook->set_sheetname($langs->trans("Sheet")); $this->worksheet = &$this->workbook->addworksheet(); // $this->worksheet->set_column(0, 50, 18); - return 0; + return $ret; } diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index db93329a5f4..a78e5e5f59e 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -1,6 +1,7 @@ # Dolibarr language file - en_US - errors ErrorDuplicateTrigger=A trigger file with class nam '%s' is present sevaral times. Remove duplicate trigger file in directory '%s'. ErrorFailToDeleteFile=Failed to remove file '%s'. +ErrorFailToCreateFile=Failed to create file '%s'. ErrorThisContactIsAlreadyDefinedAsThisType=This contact is already defined as contact for this type. ErrorCashAccountAcceptsOnlyCashMoney=This bank account is a cash account, so it accepts payments of type cash only. ErrorFromToAccountsMustDiffers=Source and targets bank accounts must be different. diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang index 249b3989728..a9d2a8ac707 100644 --- a/htdocs/langs/fr_FR/errors.lang +++ b/htdocs/langs/fr_FR/errors.lang @@ -1,5 +1,6 @@ # Dolibarr language file - fr_FR - errors ErrorDuplicateTrigger=Un fichier trigger de classe '%s' est present plusieurs fois. Supprimer le doublon du répertoire '%s'. +ErrorFailToCreateFile=Echec de la création du fichier '%s'. ErrorFailToDeleteFile=Echec de l'effacement du fichier '%s'. ErrorThisContactIsAlreadyDefinedAsThisType=Ce contact est déjà défini comme contact pour ce type. ErrorCashAccountAcceptsOnlyCashMoney=Ce compte bancaire est de type caisse et n'accepte que les mode de réglement de type espèce.