25require_once DOL_DOCUMENT_ROOT.
'/core/modules/export/modules_export.php';
49 public $version =
'dolibarr';
108 return $this->extension;
118 return $this->version;
128 return $this->label_lib;
138 return $this->version_lib;
155 dol_syslog(
"ExportCsv::open_file file=".$file);
159 $outputlangs->load(
"exports");
160 $this->handle = fopen($file,
"wt");
161 if (!$this->handle) {
162 $langs->load(
"errors");
163 $this->error = $langs->trans(
"ErrorFailToCreateFile", $file);
194 public function write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
199 $selectlabel = array();
200 foreach ($array_selected_sorted as $code => $value) {
201 if (strpos($code,
' as ') == 0) {
202 $alias = str_replace(array(
'.',
'-',
'(',
')'),
'_', $code);
204 $alias = substr($code, strpos($code,
' as ') + 4);
207 dol_syslog(
'Bad value for field with code='.$code.
'. Try to redefine export.', LOG_WARNING);
211 $newvalue = $outputlangs->transnoentities($array_export_fields_label[$code]);
212 $newvalue = $this->
csvClean($newvalue, $outputlangs->charset_output);
214 fwrite($this->handle, $newvalue.$this->separator);
215 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
217 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
218 $selectlabel[$code.
"_label"] = $newvalue.
"_label";
222 foreach ($selectlabel as $key => $value) {
223 fwrite($this->handle, $value.$this->separator);
225 fwrite($this->handle,
"\n");
240 public function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
249 $selectlabelvalues = array();
250 foreach ($array_selected_sorted as $code => $value) {
251 if (strpos($code,
' as ') == 0) {
252 $alias = str_replace(array(
'.',
'-',
'(',
')'),
'_', $code);
254 $alias = substr($code, strpos($code,
' as ') + 4);
257 dol_syslog(
'Bad value for field with code='.$code.
'. Try to redefine export.', LOG_WARNING);
261 $newvalue = $outputlangs->convToOutputCharset($objp->$alias);
262 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
265 if (preg_match(
'/^\((.*)\)$/i', $newvalue, $reg)) {
266 $newvalue = $outputlangs->transnoentities($reg[1]);
270 $newvalue = $this->
csvClean($newvalue, $outputlangs->charset_output);
272 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
274 if (is_array($array) && !empty($newvalue)) {
275 $array = $array[
'options'];
276 $selectlabelvalues[$code.
"_label"] = $array[$newvalue];
278 $selectlabelvalues[$code.
"_label"] =
"";
282 fwrite($this->handle, $newvalue.$this->separator);
285 foreach ($selectlabelvalues as $key => $value) {
286 fwrite($this->handle, $value.$this->separator);
290 fwrite($this->handle,
"\n");
316 fclose($this->handle);
341 $oldvalue = $newvalue;
342 $newvalue = str_replace(
"\r",
'', $newvalue);
343 $newvalue = str_replace(
"\n",
'\n', $newvalue);
348 $newvalue = $oldvalue;
354 if (preg_match(
'/"/', $newvalue)) {
356 $newvalue = str_replace(
'"',
'""', $newvalue);
360 if (preg_match(
'/'.$this->separator.
'/', $newvalue)) {
364 return ($addquote ?
'"' :
'').$newvalue.($addquote ?
'"' :
'');
Class to build export files with format CSV.
csvClean($newvalue, $charset)
Clean a cell to respect rules of CSV file cells Note: It uses $this->separator Note: We keep this fun...
open_file($file, $outputlangs)
Open output file.
getDriverExtension()
getDriverExtension
write_footer($outputlangs)
Output footer into file.
getDriverVersion()
getDriverVersion
write_header($outputlangs)
Output header into file.
getLibVersion()
getLibVersion
write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
Output title line into file.
close_file()
Close file handle.
write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
Output record line into file.
getDriverLabel()
getDriverLabel
getDriverDesc()
getDriverDesc
Parent class for export modules.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
jsonOrUnserialize($stringtodecode)
Decode an encode string.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.