45 $this->filename=$p_filename;
46 $this->element=array();
50 $this->sep_field=$a_field[$_SESSION[SESSION_KEY.
'csv_fieldsep']];
52 $this->sep_dec=$a_field[$_SESSION[SESSION_KEY.
'csv_decimal']];
53 $this->encoding=$_SESSION[SESSION_KEY.
'csv_encoding'];
64 if (trim(strlen($this->filename))==0) {
65 record_log(
'CSV->correct_name filename is empty');
66 throw new Exception(
'CSV-CORRECT_NAME');
68 $this->filename.=
"-".date(
"ymd-Hi");
69 $this->filename.=
".csv";
76 $this->filename=strtolower($this->filename);
85 header(
'Pragma: public');
86 header(
'Content-type: application/csv');
87 header(
"Content-Disposition: attachment;filename=\"{$this->filename}\"",
89 header(
'Cache-Control: no-store, no-cache, must-revalidate');
90 header(
'Expires: Sun, 1 Jan 2000 12:00:00 GMT');
91 header(
'Last-Modified: '.gmdate(
'D, d M Y H:i:s').
'GMT');
103 for (
$i=0;
$i<$size_array;
$i++)
120 if ( ! in_array(
$p_type, array(
"text",
"number"))) {
121 throw new Exception(
"NOALYSS_CSV::ADD");
136 if ($this->
size == 0 )
return;
140 if ($this->element[
$i][
'type'] ==
'number' )
142 printf(
$sep.
'%s', $this->nb($this->element[
$i][
'value']));
146 $export=($this->element[
$i][
'value']==
null)?
"":$this->element[
$i][
'value'];
164 $this->element=array();
171 protected function nb($p_number)
174 if ($p_number==
"") {
return $p_number;}
176 $r=number_format($p_number, 4, $this->sep_dec,
'');
184 if ($this->encoding==
"utf8")
return $str;
185 if ($this->encoding==
"latin1")
return mb_convert_encoding(
$str,
'ISO-8859-1',
'UTF-8');
186 throw new Exception(_(
"Encodage invalide"));
noalyss_str_replace($search, $replace, $string)
record_log($p_message)
Record an error message into the log file of the server.
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
Manage the CSV : manage files and write CSV record.
set_sep_field($sep_field)
add($p_item, $p_type="text")
nb($p_number)
format the number for the CSV export