25 require_once DOL_DOCUMENT_ROOT.
'/core/modules/export/modules_export.php';
49 public $version =
'dolibarr';
55 public $separator =
"\t";
72 $this->desc = $langs->trans(
'TsvFormatDesc');
73 $this->extension =
'tsv';
74 $this->picto =
'mime/other';
75 $this->version =
'1.15';
78 $this->label_lib =
'Dolibarr';
79 $this->version_lib = DOL_VERSION;
119 return $this->extension;
129 return $this->version;
139 return $this->label_lib;
149 return $this->version_lib;
166 dol_syslog(
"ExportTsv::open_file file=".$file);
170 $outputlangs->load(
"exports");
171 $this->handle = fopen($file,
"wt");
174 $langs->load(
"errors");
175 $this->error = $langs->trans(
"ErrorFailToCreateFile", $file);
206 public function write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
209 foreach ($array_selected_sorted as $code => $value)
211 $newvalue = $outputlangs->transnoentities($array_export_fields_label[$code]);
212 $newvalue = $this->
tsv_clean($newvalue, $outputlangs->charset_output);
214 fwrite($this->handle, $newvalue.$this->separator);
216 fwrite($this->handle,
"\n");
231 public function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
237 foreach ($array_selected_sorted as $code => $value)
239 if (strpos($code,
' as ') == 0) $alias = str_replace(array(
'.',
'-',
'(',
')'),
'_', $code);
240 else $alias = substr($code, strpos($code,
' as ') + 4);
241 if (empty($alias))
dol_print_error(
'',
'Bad value for field with code='.$code.
'. Try to redefine export.');
243 $newvalue = $outputlangs->convToOutputCharset($objp->$alias);
244 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
247 if (preg_match(
'/^\((.*)\)$/i', $newvalue, $reg)) $newvalue = $outputlangs->transnoentities($reg[1]);
249 $newvalue = $this->
tsv_clean($newvalue, $outputlangs->charset_output);
251 if (preg_match(
'/^Select:/i', $typefield, $reg) && $typefield = substr($typefield, 7))
253 $array = unserialize($typefield);
254 $array = $array[
'options'];
255 $newvalue = $array[$newvalue];
258 fwrite($this->handle, $newvalue.$this->separator);
261 fwrite($this->handle,
"\n");
287 fclose($this->handle);
306 $newvalue = str_replace(
"\r",
'', $newvalue);
307 $newvalue = str_replace(
"\n",
'\n', $newvalue);
310 if (preg_match(
'/'.$this->separator.
'/', $newvalue)) {
311 $newvalue = str_replace(
"\t",
" ", $newvalue);
write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
Output title line into file.
Parent class for export modules.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
write_header($outputlangs)
Output header into file.
write_footer($outputlangs)
Output footer into file.
tsv_clean($newvalue, $charset)
Clean a cell to respect rules of TSV file cells.
$conf db
API class for accounts.
write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
Output record line into file.
open_file($file, $outputlangs)
Open output file.
getDriverLabel()
getDriverLabel
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
close_file()
Close file handle.
Class to build export files with format TSV.
__construct($db)
Constructor.
getLibVersion()
getLibVersion
getDriverDesc()
getDriverDesc
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDriverExtension()
getDriverExtension
getDriverVersion()
getDriverVersion