Task #1520 : Préférence : pouvoir changer les préférence pour les exports CSV
This commit is contained in:
parent
cbcb09cb79
commit
1e7bb6e6a4
6 changed files with 132 additions and 19 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
|||
?>
|
||||
</table>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend><?=_("Format Export CSV")?></legend>
|
||||
<p>
|
||||
<?php
|
||||
if ( $_SESSION['csv_fieldsep']==1 && $_SESSION['csv_decimal']==1)
|
||||
{
|
||||
echo_warning(_("N'utilisez pas le même séparateur pour les champs et les décimales"));
|
||||
}
|
||||
?>
|
||||
</p>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<?=_("Séparateur de champs")?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$csv_fieldsep=new ISelect('csv_fieldsep');
|
||||
$csv_fieldsep->value=[
|
||||
["label"=>_("Point-virgule"),"value"=>0],
|
||||
["label"=>_("virgule"),"value"=>1]
|
||||
];
|
||||
$csv_fieldsep->selected=$_SESSION['csv_fieldsep'];
|
||||
echo $csv_fieldsep->input();
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<?=_("Séparateur Décimale")?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$csv_decimal=new ISelect('csv_decimal');
|
||||
$csv_decimal->value=[
|
||||
["label"=>_("point"),"value"=>0],
|
||||
["label"=>_("virgule"),"value"=>1]
|
||||
];
|
||||
$csv_decimal->selected=$_SESSION['csv_decimal'];
|
||||
echo $csv_decimal->input();
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<?=_("Encodage")?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$csv_encoding=new ISelect('csv_encoding');
|
||||
$csv_encoding->value=[
|
||||
["label"=>_("utf8"),"value"=>'utf8'],
|
||||
["label"=>_("latin1"),"value"=>'latin1']
|
||||
];
|
||||
$csv_encoding->selected=$_SESSION['csv_encoding'];
|
||||
echo $csv_encoding->input();
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</fieldset>
|
||||
<?php
|
||||
if ($inside_dossier)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -631,7 +631,14 @@ class User
|
|||
;
|
||||
}
|
||||
// save array into g_ variable
|
||||
$array_pref = array('g_theme' => '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
|
||||
|
|
|
|||
|
|
@ -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 ";
|
||||
|
|
|
|||
|
|
@ -1085,32 +1085,31 @@ class Database
|
|||
*/
|
||||
function query_to_csv($ret, $aheader)
|
||||
{
|
||||
$seq="";
|
||||
$csv=new Noalyss_Csv("db-query");
|
||||
$a_header=[];
|
||||
for ($i=0; $i<count($aheader); $i++)
|
||||
{
|
||||
echo $seq.'"'.$aheader[$i]['title'].'"';
|
||||
$seq=";";
|
||||
$a_header[]=$aheader[$i]['title'];
|
||||
}
|
||||
printf("\n\r");
|
||||
$csv->write_header($a_header);
|
||||
|
||||
// fetch all the rows
|
||||
for ($i=0; $i<Database::num_row($ret); $i++)
|
||||
{
|
||||
$row=Database::fetch_array($ret, $i);
|
||||
$sep2="";
|
||||
// for each rows, for each value
|
||||
for ($e=0; $e<count($row)/2; $e++)
|
||||
{
|
||||
switch ($aheader[$e]['type'])
|
||||
{
|
||||
case 'num':
|
||||
echo $sep2.nb($row[$e]);
|
||||
$csv->add($row[$e],"number");
|
||||
break;
|
||||
default:
|
||||
echo $sep2.'"'.$row[$e].'"';
|
||||
$csv->add($row[$e]);
|
||||
}
|
||||
$sep2=";";
|
||||
}
|
||||
printf("\n\r");
|
||||
$csv->write();
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue