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 = $array_export_fields_label[$code];
216 $decodedlabel = $newvalue;
219 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
220 $newvalue =
csvClean($newvalue, $outputlangs->charset_output, $this->separator);
222 fwrite($this->handle, $newvalue.$this->separator);
223 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
225 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
228 $selectlabel[$code.
"_label"] =
csvClean($decodedlabel.
"_label", $outputlangs->charset_output, $this->separator);
232 foreach ($selectlabel as $key => $value) {
233 fwrite($this->handle, $value.$this->separator);
235 fwrite($this->handle,
"\n");
250 public function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
259 $selectlabelvalues = array();
260 foreach ($array_selected_sorted as $code => $value) {
261 if (strpos($code,
' as ') == 0) {
262 $alias = str_replace(array(
'.',
'-',
'(',
')'),
'_', $code);
264 $alias = substr($code, strpos($code,
' as ') + 4);
267 dol_syslog(
'Bad value for field with code='.$code.
'. Try to redefine export.', LOG_WARNING);
271 $newvalue = $objp->$alias;
272 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
275 if (preg_match(
'/^\((.*)\)$/i', $newvalue, $reg)) {
276 $newvalue = $outputlangs->transnoentities($reg[1]);
280 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
281 $newvalue =
csvClean($newvalue, $outputlangs->charset_output, $this->separator);
283 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
285 if (is_array($array) && !empty($newvalue)) {
286 $array = $array[
'options'];
287 $selectlabelvalues[$code.
"_label"] = $array[$newvalue];
289 $selectlabelvalues[$code.
"_label"] =
"";
293 fwrite($this->handle, $newvalue.$this->separator);
296 foreach ($selectlabelvalues as $key => $value) {
297 fwrite($this->handle, $value.$this->separator);
301 fwrite($this->handle,
"\n");
327 fclose($this->handle);
Class to build export files with format CSV.
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.
csvClean($newvalue, $charset='', $separator='')
Clean a cell to respect rules of CSV file cells.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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.