From b81a1a9a1d3c522809ba56dac2d6c2b67b38244f Mon Sep 17 00:00:00 2001 From: bgenere Date: Mon, 28 Nov 2016 14:23:35 +0100 Subject: [PATCH 1/7] Code was setting ISO charset as default wich was causing an issue with transnoentities as this method send back UTF-8. Result was that CSV file was generated empty (tested on Unix Ubuntu workstation). Replaced now with $conf->file->character_set_client so it works for me (using UTF-8 by default. To complete the fix my feeling is that we should not force charset till we are not writing the final result. But needs to be confirmed by a senior Dolibarr developer. --- .../modules/export/export_csv.modules.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/htdocs/core/modules/export/export_csv.modules.php b/htdocs/core/modules/export/export_csv.modules.php index 8d35ff63225..0c01ef07d89 100644 --- a/htdocs/core/modules/export/export_csv.modules.php +++ b/htdocs/core/modules/export/export_csv.modules.php @@ -177,6 +177,7 @@ class ExportCsv extends ModeleExports */ function write_header($outputlangs) { + return 0; } @@ -189,18 +190,23 @@ class ExportCsv extends ModeleExports * @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 + * + * //TODO transnoentities send back UTF-8 so using an ISO charset at this point create an issue + * (get a blank screen and an empty file) + * my feeling is that we should not force charset till we are not writing the final result. */ function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs,$array_types) { + global $conf; - + if (! empty($conf->global->EXPORT_CSV_FORCE_CHARSET)) { $outputlangs->charset_output = $conf->global->EXPORT_CSV_FORCE_CHARSET; } else { - $outputlangs->charset_output = 'ISO-8859-1'; + $outputlangs->charset_output = $conf->file->character_set_client; } foreach($array_selected_sorted as $code => $value) @@ -211,6 +217,7 @@ class ExportCsv extends ModeleExports fwrite($this->handle,$newvalue.$this->separator); } fwrite($this->handle,"\n"); + return 0; } @@ -223,6 +230,10 @@ class ExportCsv extends ModeleExports * @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 + * + * //TODO transnoentities send back UTF-8 so using an ISO charset at this point create an issue + * (get a blank screen and an empty file) + * my feeling is that we should not force charset till we are not writing the final result. */ function write_record($array_selected_sorted,$objp,$outputlangs,$array_types) { @@ -234,7 +245,7 @@ class ExportCsv extends ModeleExports } else { - $outputlangs->charset_output = 'ISO-8859-1'; + $outputlangs->charset_output = $conf->file->character_set_client; } $this->col=0; @@ -303,7 +314,7 @@ class ExportCsv extends ModeleExports { global $conf; $addquote=0; - + dol_syslog("ExportCsv::csvClean ".$newvalue); // Rule Dolibarr: No HTML //print $charset.' '.$newvalue."\n"; From a3fbe94f7ca5b84060dcfaae54d5299b14f1f40b Mon Sep 17 00:00:00 2001 From: bgenere Date: Mon, 28 Nov 2016 14:30:21 +0100 Subject: [PATCH 2/7] Cleaned-up code - removed syslog entry added for debug --- htdocs/core/modules/export/export_csv.modules.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/htdocs/core/modules/export/export_csv.modules.php b/htdocs/core/modules/export/export_csv.modules.php index 0c01ef07d89..f2455753ee6 100644 --- a/htdocs/core/modules/export/export_csv.modules.php +++ b/htdocs/core/modules/export/export_csv.modules.php @@ -177,7 +177,6 @@ class ExportCsv extends ModeleExports */ function write_header($outputlangs) { - return 0; } @@ -197,7 +196,6 @@ class ExportCsv extends ModeleExports */ function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs,$array_types) { - global $conf; if (! empty($conf->global->EXPORT_CSV_FORCE_CHARSET)) @@ -217,7 +215,7 @@ class ExportCsv extends ModeleExports fwrite($this->handle,$newvalue.$this->separator); } fwrite($this->handle,"\n"); - + return 0; } @@ -314,8 +312,7 @@ class ExportCsv extends ModeleExports { global $conf; $addquote=0; - dol_syslog("ExportCsv::csvClean ".$newvalue); - + // Rule Dolibarr: No HTML //print $charset.' '.$newvalue."\n"; //$newvalue=dol_string_nohtmltag($newvalue,0,$charset); From 093942bcd7a180194648ddfab614c4b690ae7eb9 Mon Sep 17 00:00:00 2001 From: bgenere Date: Mon, 28 Nov 2016 15:37:24 +0100 Subject: [PATCH 3/7] Fixed display issue for custom modules dictionnary not displayed properly when blank exists in dictionnary list for core modules. --- htdocs/core/lib/admin.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 5726981586a..399a77fe27e 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -975,9 +975,9 @@ function complete_dictionary_with_modules(&$taborder,&$tabname,&$tablib,&$tabsql if (! empty($objMod->dictionaries)) { - //var_dump($objMod->dictionaries['tabname']); + //var_dump($objMod->dictionaries['tabname']);var_dump(max($taborder)); $nbtabname=$nbtablib=$nbtabsql=$nbtabsqlsort=$nbtabfield=$nbtabfieldvalue=$nbtabfieldinsert=$nbtabrowid=$nbtabcond=$nbtabfieldcheck=$nbtabhelp=0; - foreach($objMod->dictionaries['tabname'] as $val) { $nbtabname++; $taborder[] = count($tabname)+1; $tabname[] = $val; } + foreach($objMod->dictionaries['tabname'] as $val) { $nbtabname++; $taborder[] = max($taborder)+1; $tabname[] = $val; } foreach($objMod->dictionaries['tablib'] as $val) { $nbtablib++; $tablib[] = $val; } foreach($objMod->dictionaries['tabsql'] as $val) { $nbtabsql++; $tabsql[] = $val; } foreach($objMod->dictionaries['tabsqlsort'] as $val) { $nbtabsqlsort++; $tabsqlsort[] = $val; } From 71434d84dd5dfbb2ea4e7c71b9095165d8606401 Mon Sep 17 00:00:00 2001 From: bgenere Date: Mon, 28 Nov 2016 16:44:58 +0100 Subject: [PATCH 4/7] Fixed display issue on import step 4 screen when import_entities_array is empty. also fixed an extra -> displayed. --- htdocs/imports/import.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index c4c14ff8d5f..3b93c40e5ef 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -868,13 +868,13 @@ if ($step == 4 && $datatoimport) $i++; - $entity=(! empty($objimport->array_import_entities[0][$code])?$objimport->array_import_entities[0][$code]:$objimport->array_import_icon[0]); + $entity=(! empty($objimport->array_import_entities[0][$code])?$objimport->array_import_entities[0][$code]:$objimport->array_import_label[0]); $tablealias=preg_replace('/(\..*)$/i','',$code); $tablename=$objimport->array_import_tables[0][$tablealias]; $entityicon=$entitytoicon[$entity]?$entitytoicon[$entity]:$entity; $entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$entity; - print '=>'.img_object('',$entityicon).' '.$langs->trans($entitylang).''; + print ''.img_object('',$entityicon).' '.$langs->trans($entitylang).''; print ''; $newlabel=preg_replace('/\*$/','',$label); $text=$langs->trans($newlabel); From 18c6bb141d4778a9bb1a497fe8a5b5cd57abd983 Mon Sep 17 00:00:00 2001 From: bgenere Date: Wed, 30 Nov 2016 17:12:17 +0100 Subject: [PATCH 5/7] going back to current version and use EXPORT_CSV_FORCE_CHARSET as a workaround for my dev environment. --- .../core/modules/export/export_csv.modules.php | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/htdocs/core/modules/export/export_csv.modules.php b/htdocs/core/modules/export/export_csv.modules.php index f2455753ee6..8d35ff63225 100644 --- a/htdocs/core/modules/export/export_csv.modules.php +++ b/htdocs/core/modules/export/export_csv.modules.php @@ -189,22 +189,18 @@ class ExportCsv extends ModeleExports * @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 - * - * //TODO transnoentities send back UTF-8 so using an ISO charset at this point create an issue - * (get a blank screen and an empty file) - * my feeling is that we should not force charset till we are not writing the final result. */ function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs,$array_types) { global $conf; - + if (! empty($conf->global->EXPORT_CSV_FORCE_CHARSET)) { $outputlangs->charset_output = $conf->global->EXPORT_CSV_FORCE_CHARSET; } else { - $outputlangs->charset_output = $conf->file->character_set_client; + $outputlangs->charset_output = 'ISO-8859-1'; } foreach($array_selected_sorted as $code => $value) @@ -215,7 +211,6 @@ class ExportCsv extends ModeleExports fwrite($this->handle,$newvalue.$this->separator); } fwrite($this->handle,"\n"); - return 0; } @@ -228,10 +223,6 @@ class ExportCsv extends ModeleExports * @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 - * - * //TODO transnoentities send back UTF-8 so using an ISO charset at this point create an issue - * (get a blank screen and an empty file) - * my feeling is that we should not force charset till we are not writing the final result. */ function write_record($array_selected_sorted,$objp,$outputlangs,$array_types) { @@ -243,7 +234,7 @@ class ExportCsv extends ModeleExports } else { - $outputlangs->charset_output = $conf->file->character_set_client; + $outputlangs->charset_output = 'ISO-8859-1'; } $this->col=0; @@ -313,6 +304,7 @@ class ExportCsv extends ModeleExports global $conf; $addquote=0; + // Rule Dolibarr: No HTML //print $charset.' '.$newvalue."\n"; //$newvalue=dol_string_nohtmltag($newvalue,0,$charset); From 9c62adb81125aedd68e9c85f416b8c870a700daa Mon Sep 17 00:00:00 2001 From: bgenere Date: Wed, 30 Nov 2016 17:46:53 +0100 Subject: [PATCH 6/7] removed a vardump that was used for debug. --- htdocs/core/lib/admin.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 399a77fe27e..d79e65f766f 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -975,7 +975,7 @@ function complete_dictionary_with_modules(&$taborder,&$tabname,&$tablib,&$tabsql if (! empty($objMod->dictionaries)) { - //var_dump($objMod->dictionaries['tabname']);var_dump(max($taborder)); + //var_dump($objMod->dictionaries['tabname']); $nbtabname=$nbtablib=$nbtabsql=$nbtabsqlsort=$nbtabfield=$nbtabfieldvalue=$nbtabfieldinsert=$nbtabrowid=$nbtabcond=$nbtabfieldcheck=$nbtabhelp=0; foreach($objMod->dictionaries['tabname'] as $val) { $nbtabname++; $taborder[] = max($taborder)+1; $tabname[] = $val; } foreach($objMod->dictionaries['tablib'] as $val) { $nbtablib++; $tablib[] = $val; } From 09baab1076e0d427c8575ec915458a41b599c540 Mon Sep 17 00:00:00 2001 From: bgenere Date: Sat, 3 Dec 2016 18:46:12 +0100 Subject: [PATCH 7/7] Fix display issue on step 4 of import in import.php. The issue was only for custom module import as the entity was initialised with the icone name i.e. filename@modulename. Then the arrays entitytoicon and entitytolang where used. But by definition custom modules do not have entries in these arrays. So changed the assignement to proper object property when $entity is not in these 2 tables. This is not changing behaviour of default object. I have tested both with my custom objet and product object. So it should be fine now. --- htdocs/imports/import.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index 3b93c40e5ef..f86197b82a8 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -867,14 +867,14 @@ if ($step == 4 && $datatoimport) print ''; $i++; - - $entity=(! empty($objimport->array_import_entities[0][$code])?$objimport->array_import_entities[0][$code]:$objimport->array_import_label[0]); + + $entity=(! empty($objimport->array_import_entities[0][$code])?$objimport->array_import_entities[0][$code]:$objimport->array_import_icon[0]); $tablealias=preg_replace('/(\..*)$/i','',$code); $tablename=$objimport->array_import_tables[0][$tablealias]; - $entityicon=$entitytoicon[$entity]?$entitytoicon[$entity]:$entity; - $entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$entity; + $entityicon=$entitytoicon[$entity]?$entitytoicon[$entity]:$objimport->array_import_icon[0]; + $entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$objimport->array_import_label[0]; - print ''.img_object('',$entityicon).' '.$langs->trans($entitylang).''; + print '=>'.img_object('',$entityicon).' '.$langs->trans($entitylang).''; print ''; $newlabel=preg_replace('/\*$/','',$label); $text=$langs->trans($newlabel);