diff --git a/html/do.php b/html/do.php index 1bd08fb08..54959adf3 100644 --- a/html/do.php +++ b/html/do.php @@ -81,6 +81,9 @@ if ( isset ($_POST['set_preference'])) { $p_email=$http->post("p_email","string",""); $minirap=$http->post("minirap","number",0); $period=$http->post("period","number"); + $csv_fieldsep=$http->post("csv_fieldsep","number"); + $csv_decimal=$http->post("csv_decimal","number"); + $csv_encoding=$http->post("csv_encoding"); if (strlen(trim($pass_1)) != 0 && strlen(trim($pass_2)) != 0) { @@ -91,6 +94,10 @@ if ( isset ($_POST['set_preference'])) { $g_user->save_global_preference('THEME', $style_user); $g_user->save_global_preference('LANG', $lang); $g_user->save_global_preference('PAGESIZE', $p_size); + $g_user->save_global_preference('csv_fieldsep', $csv_fieldsep); + $g_user->save_global_preference('csv_decimal', $csv_decimal); + $g_user->save_global_preference('csv_encoding', $csv_encoding); + $g_user->set_mini_report($minirap); $_SESSION['g_theme']=$style_user; $_SESSION['g_pagesize']=$p_size; diff --git a/include/ajax/ajax_preference.php b/include/ajax/ajax_preference.php index 4505aaa31..1b92a860f 100644 --- a/include/ajax/ajax_preference.php +++ b/include/ajax/ajax_preference.php @@ -100,7 +100,7 @@ if (isset($_REQUEST['gDossier']) && $_REQUEST['gDossier']<>0) if ($l_user_per == "") $l_user_per = $cn->get_value("select min(p_id) from parm_periode where p_closed='f'"); -// if periode is closed then warns the users + // if periode is closed then warns the users $period = new Periode($cn, $l_user_per); $period->p_id = $l_user_per; @@ -148,6 +148,68 @@ if (isset($_REQUEST['gDossier']) && $_REQUEST['gDossier']<>0) ?> +
+ +

+ +

+ + + + + + + + + + + + + +
+ + + value=[ + ["label"=>_("Point-virgule"),"value"=>0], + ["label"=>_("virgule"),"value"=>1] + ]; + $csv_fieldsep->selected=$_SESSION['csv_fieldsep']; + echo $csv_fieldsep->input(); + ?> +
+ + + value=[ + ["label"=>_("point"),"value"=>0], + ["label"=>_("virgule"),"value"=>1] + ]; + $csv_decimal->selected=$_SESSION['csv_decimal']; + echo $csv_decimal->input(); + ?> +
+ + + value=[ + ["label"=>_("utf8"),"value"=>'utf8'], + ["label"=>_("latin1"),"value"=>'latin1'] + ]; + $csv_encoding->selected=$_SESSION['csv_encoding']; + echo $csv_encoding->input(); + ?> +
+ +
'THEME', 'g_pagesize' => 'PAGESIZE', 'g_topmenu' => 'TOPMENU', 'g_lang' => 'LANG'); + $array_pref = array('g_theme' => 'THEME', + 'g_pagesize' => 'PAGESIZE', + 'g_topmenu' => 'TOPMENU', + 'g_lang' => 'LANG', + 'csv_fieldsep'=>'csv_fieldsep', + 'csv_decimal'=>'csv_decimal' , + 'csv_encoding'=>'csv_encoding'); + foreach ($array_pref as $name => $parameter) { if (!isset($line[$parameter])) @@ -659,7 +666,11 @@ class User $default_parameter = array("THEME" => "classic", "PAGESIZE" => "50", 'TOPMENU' => 'TEXT', - 'LANG' => 'fr_FR.utf8'); + 'LANG' => 'fr_FR.utf8', + 'csv_fieldsep'=>'0', + 'csv_decimal'=>'0', + 'csv_encoding'=>'utf8' + ); $cn = new Database(); $Sql = "insert into user_global_pref(user_id,parameter_type,parameter_value) values ('%s','%s','%s')"; @@ -692,7 +703,11 @@ class User $default_parameter = array("THEME" => "classic", "PAGESIZE" => "50", "LANG" => 'fr_FR.utf8', - 'TOPMENU' => 'SELECT'); + 'TOPMENU' => 'SELECT', + 'csv_fieldsep'=>'0', + 'csv_decimal'=>'0', + 'csv_encoding'=>'utf8' + ); $cn = new Database(); $Sql = "update user_global_pref set parameter_value=$1 where parameter_type=$2 and diff --git a/include/export/export_histo_csv.php b/include/export/export_histo_csv.php index 4e954f42a..847ceaebe 100644 --- a/include/export/export_histo_csv.php +++ b/include/export/export_histo_csv.php @@ -24,8 +24,9 @@ */ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis'); require_once NOALYSS_INCLUDE.'/lib/noalyss_csv.class.php'; +require_once NOALYSS_INCLUDE.'/class/acc_ledger_search.class.php'; -$ledger=new Acc_Ledger($cn,0); +$ledger=new Acc_Ledger_Search($cn,0); list($sql,$where)=$ledger->build_search_sql($_GET); $order=" order by jr_date_order asc,substring(jr_pj_number,'[0-9]+$')::numeric asc "; diff --git a/include/lib/database.class.php b/include/lib/database.class.php index 035199552..393b6dc04 100644 --- a/include/lib/database.class.php +++ b/include/lib/database.class.php @@ -1085,32 +1085,31 @@ class Database */ function query_to_csv($ret, $aheader) { - $seq=""; + $csv=new Noalyss_Csv("db-query"); + $a_header=[]; for ($i=0; $iwrite_header($a_header); + // fetch all the rows for ($i=0; $iadd($row[$e],"number"); break; default: - echo $sep2.'"'.$row[$e].'"'; + $csv->add($row[$e]); } - $sep2=";"; } - printf("\n\r"); + $csv->write(); } } /** diff --git a/include/lib/noalyss_csv.class.php b/include/lib/noalyss_csv.class.php index 86bf593c9..11df7606f 100644 --- a/include/lib/noalyss_csv.class.php +++ b/include/lib/noalyss_csv.class.php @@ -35,12 +35,22 @@ class Noalyss_Csv private $filename; private $element; + private $sep_field; + private $sep_dec; + private $encoding; function __construct($p_filename) { $this->filename=$p_filename; $this->element=array(); $this->size=0; + + $a_field=[';',',']; + $this->sep_field=$a_field[$_SESSION['csv_fieldsep']]; + $a_field=['.',',']; + $this->sep_dec=$a_field[$_SESSION['csv_decimal']]; + $this->encoding=$_SESSION['csv_encoding']; + } /*** @@ -91,8 +101,9 @@ class Noalyss_Csv $sep=""; for ($i=0; $i<$size_array; $i++) { - printf($sep.'"%s"', $p_array[$i]); - $sep=";"; + + printf($sep.'"%s"', $this->encode($p_array[$i])); + $sep=$this->sep_field; } printf("\r\n"); } @@ -127,7 +138,7 @@ class Noalyss_Csv { if ($this->element[$i]['type'] == 'number' ) { - printf($sep.'%s', nb($this->element[$i]['value'])); + printf($sep.'%s', $this->nb($this->element[$i]['value'])); } else { @@ -136,9 +147,9 @@ class Noalyss_Csv $export=str_replace("\r"," ", $export); // remove double quote $export=str_replace('"',"", $export); - printf($sep.'"%s"', $export); + printf($sep.'"%s"', $this->encode($export)); } - $sep=";"; + $sep=$this->sep_field; } printf("\r\n"); $this->clean(); @@ -151,5 +162,23 @@ class Noalyss_Csv $this->element=array(); $this->size=0; } + /** + * format the number for the CSV export + * @param $p_number number + */ + private function nb($p_number) + { + $p_number=trim($p_number); + if ($p_number=="") {return $p_number;} + $r=number_format($p_number, 4, $this->sep_dec,''); + return $r; + } + private function encode($str) + { + if ($this->encoding=="utf8") return $str; + if ($this->encoding=="latin1") return utf8_decode ($str); + throw new Exception(_("Encodage invalide")); + } + }