24 require_once DOL_DOCUMENT_ROOT.
'/core/modules/export/modules_export.php';
50 public $version =
'dolibarr';
71 $this->separator =
',';
72 if (!empty($conf->global->EXPORT_CSV_SEPARATOR_TO_USE)) $this->separator = $conf->global->EXPORT_CSV_SEPARATOR_TO_USE;
74 $this->enclosure =
'"';
78 $this->desc = $langs->trans(
"CSVFormatDesc", $this->separator, $this->enclosure, $this->escape);
79 $this->extension =
'csv';
80 $this->picto =
'mime/other';
81 $this->version =
'1.32';
84 $this->label_lib =
'Dolibarr';
85 $this->version_lib = DOL_VERSION;
125 return $this->extension;
135 return $this->version;
145 return $this->label_lib;
155 return $this->version_lib;
172 dol_syslog(
"ExportCsv::open_file file=".$file);
176 $outputlangs->load(
"exports");
177 $this->handle = fopen($file,
"wt");
180 $langs->load(
"errors");
181 $this->error = $langs->trans(
"ErrorFailToCreateFile", $file);
212 public function write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
217 if (!empty($conf->global->EXPORT_CSV_FORCE_CHARSET))
219 $outputlangs->charset_output = $conf->global->EXPORT_CSV_FORCE_CHARSET;
221 $outputlangs->charset_output =
'ISO-8859-1';
224 foreach ($array_selected_sorted as $code => $value)
226 $newvalue = $outputlangs->transnoentities($array_export_fields_label[$code]);
227 $newvalue = $this->
csvClean($newvalue, $outputlangs->charset_output);
229 fwrite($this->handle, $newvalue.$this->separator);
231 fwrite($this->handle,
"\n");
246 public function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
251 if (!empty($conf->global->EXPORT_CSV_FORCE_CHARSET))
253 $outputlangs->charset_output = $conf->global->EXPORT_CSV_FORCE_CHARSET;
255 $outputlangs->charset_output =
'ISO-8859-1';
262 foreach ($array_selected_sorted as $code => $value)
264 if (strpos($code,
' as ') == 0) $alias = str_replace(array(
'.',
'-',
'(',
')'),
'_', $code);
265 else $alias = substr($code, strpos($code,
' as ') + 4);
266 if (empty($alias))
dol_print_error(
'',
'Bad value for field with key='.$code.
'. Try to redefine export.');
268 $newvalue = $outputlangs->convToOutputCharset($objp->$alias);
269 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
272 if (preg_match(
'/^\((.*)\)$/i', $newvalue, $reg)) $newvalue = $outputlangs->transnoentities($reg[1]);
274 $newvalue = $this->
csvClean($newvalue, $outputlangs->charset_output);
276 if (preg_match(
'/^Select:/i', $typefield, $reg) && $typefield = substr($typefield, 7))
278 $array = unserialize($typefield);
279 $array = $array[
'options'];
280 $newvalue = $array[$newvalue];
283 fwrite($this->handle, $newvalue.$this->separator);
287 fwrite($this->handle,
"\n");
313 fclose($this->handle);
339 $oldvalue = $newvalue;
340 $newvalue = str_replace(
"\r",
'', $newvalue);
341 $newvalue = str_replace(
"\n",
'\n', $newvalue);
342 if (!empty($conf->global->USE_STRICT_CSV_RULES) && $oldvalue != $newvalue)
345 $newvalue = $oldvalue;
350 if (preg_match(
'/"/', $newvalue))
353 $newvalue = str_replace(
'"',
'""', $newvalue);
357 if (preg_match(
'/'.$this->separator.
'/', $newvalue))
362 return ($addquote ?
'"' :
'').$newvalue.($addquote ?
'"' :
'');
Parent class for export modules.
write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
Output title line into file.
write_header($outputlangs)
Output header into file.
getLibLabel()
getLabelLabel
getLibVersion()
getLibVersion
open_file($file, $outputlangs)
Open output file.
$conf db
API class for accounts.
csvClean($newvalue, $charset)
Clean a cell to respect rules of CSV file cells Note: It uses $this->separator Note: We keep this fun...
getDriverVersion()
getDriverVersion
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
__construct($db)
Constructor.
Class to build export files with format CSV.
getDriverLabel()
getDriverLabel
write_footer($outputlangs)
Output footer into file.
close_file()
Close file handle.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDriverExtension()
getDriverExtension
write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
Output record line into file.
getDriverDesc()
getDriverDesc