diff --git a/ChangeLog b/ChangeLog index 55975d60898..69972372eb8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -35,6 +35,7 @@ For developers: into conf->liste_limit). - New: Add option dol_hide_topmenu and dol_hide_leftmenu onto login page. - New: dol_syslog method accept a suffix to use different log files for log. +- New: Type of fields are received by export format handlers For translators: - Update language files. diff --git a/htdocs/core/modules/export/export_csv.modules.php b/htdocs/core/modules/export/export_csv.modules.php index 20d57fda97c..ef422a4fd38 100644 --- a/htdocs/core/modules/export/export_csv.modules.php +++ b/htdocs/core/modules/export/export_csv.modules.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2006-2013 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -220,9 +220,10 @@ class ExportCsv extends ModeleExports * @param array $array_selected_sorted Array with list of field to export * @param resource $objp A record from a fetch with all fields from select * @param Translate $outputlangs Object lang to translate values + * @param array $array_types Array with types of fields * @return int <0 if KO, >0 if OK */ - function write_record($array_selected_sorted,$objp,$outputlangs) + function write_record($array_selected_sorted,$objp,$outputlangs,$array_types) { global $conf; @@ -241,8 +242,10 @@ class ExportCsv extends ModeleExports if (strpos($code,' as ') == 0) $alias=str_replace(array('.','-'),'_',$code); else $alias=substr($code, strpos($code, ' as ') + 4); if (empty($alias)) dol_print_error('','Bad value for field with key='.$code.'. Try to redefine export.'); + $newvalue=$outputlangs->convToOutputCharset($objp->$alias); - + $typefield=isset($array_types[$code])?$array_types[$code]:''; + // Translation newvalue if (preg_match('/^\((.*)\)$/i',$newvalue,$reg)) { diff --git a/htdocs/core/modules/export/export_excel.modules.php b/htdocs/core/modules/export/export_excel.modules.php index 9e489f0b3e8..51dee6a16ef 100644 --- a/htdocs/core/modules/export/export_excel.modules.php +++ b/htdocs/core/modules/export/export_excel.modules.php @@ -260,9 +260,10 @@ class ExportExcel extends ModeleExports * @param array $array_selected_sorted Array with list of field to export * @param resource $objp A record from a fetch with all fields from select * @param Translate $outputlangs Object lang to translate values + * @param array $array_types Array with types of fields * @return int <0 if KO, >0 if OK */ - function write_record($array_selected_sorted,$objp,$outputlangs) + function write_record($array_selected_sorted,$objp,$outputlangs,$array_types) { // Create a format for the column headings if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) @@ -281,7 +282,8 @@ class ExportExcel extends ModeleExports $newvalue=$objp->$alias; $newvalue=$this->excel_clean($newvalue); - + $typefield=isset($array_types[$code])?$array_types[$code]:''; + // Traduction newvalue if (preg_match('/^\((.*)\)$/i',$newvalue,$reg)) { diff --git a/htdocs/core/modules/export/export_excel2007.modules.php b/htdocs/core/modules/export/export_excel2007.modules.php index 45f6e04d054..1e3605a7d1d 100755 --- a/htdocs/core/modules/export/export_excel2007.modules.php +++ b/htdocs/core/modules/export/export_excel2007.modules.php @@ -350,8 +350,8 @@ class ExportExcel2007 extends ExportExcel //$this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, $newvalue); if ($typefield == 'Text') { - var_dump($code.' '.$alias.' '.$newvalue.' '.$typefield); - $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, $newvalue); + //var_dump($code.' '.$alias.' '.$newvalue.' '.$typefield); + //$this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, (string) $newvalue); $this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row+1)->setValueExplicit($newvalue, PHPExcel_Cell_DataType::TYPE_STRING); } else diff --git a/htdocs/core/modules/export/export_tsv.modules.php b/htdocs/core/modules/export/export_tsv.modules.php index c0b8eb5f617..090ed17bf46 100644 --- a/htdocs/core/modules/export/export_tsv.modules.php +++ b/htdocs/core/modules/export/export_tsv.modules.php @@ -204,25 +204,30 @@ class ExportTsv extends ModeleExports * @param array $array_selected_sorted Array with list of field to export * @param resource $objp A record from a fetch with all fields from select * @param Translate $outputlangs Object lang to translate values + * @param array $array_types Array with types of fields * @return int <0 if KO, >0 if OK */ - function write_record($array_selected_sorted,$objp,$outputlangs) + function write_record($array_selected_sorted,$objp,$outputlangs,$array_types) { + global $conf; + $this->col=0; foreach($array_selected_sorted as $code => $value) { if (strpos($code,' as ') == 0) $alias=str_replace(array('.','-'),'_',$code); else $alias=substr($code, strpos($code, ' as ') + 4); if (empty($alias)) dol_print_error('','Bad value for field with code='.$code.'. Try to redefine export.'); - $newvalue=$objp->$alias; - + + $newvalue=$outputlangs->convToOutputCharset($objp->$alias); + $typefield=isset($array_types[$code])?$array_types[$code]:''; + // Translation newvalue if (preg_match('/^\((.*)\)$/i',$newvalue,$reg)) { $newvalue=$outputlangs->transnoentities($reg[1]); } - $newvalue=$this->tsv_clean($newvalue); + $newvalue=$this->tsv_clean($newvalue,$outputlangs->charset_output); fwrite($this->handle,$newvalue.$this->separator); $this->col++; @@ -257,12 +262,13 @@ class ExportTsv extends ModeleExports * Clean a cell to respect rules of TSV file cells * * @param string $newvalue String to clean + * @param string $charset Output character set * @return string Value cleaned */ - function tsv_clean($newvalue) + function tsv_clean($newvalue, $charset) { // Rule Dolibarr: No HTML - $newvalue=dol_string_nohtmltag($newvalue); + $newvalue=dol_string_nohtmltag($newvalue, 1, $charset); // Rule 1 TSV: No CR, LF in cells $newvalue=str_replace("\r",'',$newvalue); diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index 0498b59ccde..7966d7deacb 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -284,6 +284,7 @@ class modSociete extends DolibarrModules $this->export_icon[$r]='contact'; $this->export_permission[$r]=array(array("societe","contact","export")); $this->export_fields_array[$r]=array('c.rowid'=>"IdContact",'c.civilite'=>"CivilityCode",'c.lastname'=>'Lastname','c.firstname'=>'Firstname','c.datec'=>"DateCreation",'c.tms'=>"DateLastModification",'c.priv'=>"ContactPrivate",'c.address'=>"Address",'c.zip'=>"Zip",'c.town'=>"Town",'c.phone'=>"Phone",'c.fax'=>"Fax",'c.email'=>"EMail",'p.libelle'=>"Country",'p.code'=>"CountryCode",'s.rowid'=>"IdCompany",'s.nom'=>"CompanyName",'s.status'=>"Status",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode"); + $this->export_TypeFields_array[$r]=array('c.lastname'=>"Text",'c.firstname'=>"Text",'s.code_client'=>"Text",'s.code_fournisseur'=>"Text"); $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>"company",'s.code_client'=>"company",'s.code_fournisseur'=>"company"); // We define here only fields that use another picto if (empty($conf->fournisseur->enabled)) {