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");
172 if (!$this->handle) {
173 $langs->load(
"errors");
174 $this->error = $langs->trans(
"ErrorFailToCreateFile", $file);
205 public function write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
208 foreach ($array_selected_sorted as $code => $value) {
209 $newvalue = $outputlangs->transnoentities($array_export_fields_label[$code]);
210 $newvalue = $this->
tsv_clean($newvalue, $outputlangs->charset_output);
212 fwrite($this->handle, $newvalue.$this->separator);
214 fwrite($this->handle,
"\n");
229 public function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
235 foreach ($array_selected_sorted as $code => $value) {
236 if (strpos($code,
' as ') == 0) {
237 $alias = str_replace(array(
'.',
'-',
'(',
')'),
'_', $code);
239 $alias = substr($code, strpos($code,
' as ') + 4);
242 dol_print_error(
'',
'Bad value for field with code='.$code.
'. Try to redefine export.');
245 $newvalue = $outputlangs->convToOutputCharset($objp->$alias);
246 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
249 if (preg_match(
'/^\((.*)\)$/i', $newvalue, $reg)) {
250 $newvalue = $outputlangs->transnoentities($reg[1]);
253 $newvalue = $this->
tsv_clean($newvalue, $outputlangs->charset_output);
255 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
256 $array = json_decode($typefield,
true);
257 $array = $array[
'options'];
258 $newvalue = $array[$newvalue];
261 fwrite($this->handle, $newvalue.$this->separator);
264 fwrite($this->handle,
"\n");
290 fclose($this->handle);
309 $newvalue = str_replace(
"\r",
'', $newvalue);
310 $newvalue = str_replace(
"\n",
'\n', $newvalue);
313 if (preg_match(
'/'.$this->separator.
'/', $newvalue)) {
314 $newvalue = str_replace(
"\t",
" ", $newvalue);