25require_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 $selectlabel = array();
209 foreach ($array_selected_sorted as $code => $value) {
210 $newvalue = $outputlangs->transnoentities($array_export_fields_label[$code]);
211 $newvalue = $this->
tsv_clean($newvalue, $outputlangs->charset_output);
213 fwrite($this->handle, $newvalue.$this->separator);
214 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
216 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
217 $selectlabel[$code.
"_label"] = $newvalue.
"_label";
220 foreach ($selectlabel as $key => $value) {
221 fwrite($this->handle, $value.$this->separator);
223 fwrite($this->handle,
"\n");
238 public function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
244 $selectlabelvalues = array();
245 foreach ($array_selected_sorted as $code => $value) {
246 if (strpos($code,
' as ') == 0) {
247 $alias = str_replace(array(
'.',
'-',
'(',
')'),
'_', $code);
249 $alias = substr($code, strpos($code,
' as ') + 4);
252 dol_print_error(
null,
'Bad value for field with code='.$code.
'. Try to redefine export.');
255 $newvalue = $outputlangs->convToOutputCharset($objp->$alias);
256 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
259 if (preg_match(
'/^\((.*)\)$/i', $newvalue, $reg)) {
260 $newvalue = $outputlangs->transnoentities($reg[1]);
263 $newvalue = $this->
tsv_clean($newvalue, $outputlangs->charset_output);
265 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
267 if (is_array($array) && !empty($newvalue)) {
268 $array = $array[
'options'];
269 $selectlabelvalues[$code.
"_label"] = $array[$newvalue];
271 $selectlabelvalues[$code.
"_label"] =
"";
275 fwrite($this->handle, $newvalue.$this->separator);
278 foreach ($selectlabelvalues as $key => $value) {
279 fwrite($this->handle, $value.$this->separator);
282 fwrite($this->handle,
"\n");
308 fclose($this->handle);
327 $newvalue = str_replace(
"\r",
'', $newvalue);
328 $newvalue = str_replace(
"\n",
'\n', $newvalue);
331 if (preg_match(
'/'.$this->separator.
'/', $newvalue)) {
332 $newvalue = str_replace(
"\t",
" ", $newvalue);
Class to build export files with format TSV.
write_header($outputlangs)
Output header into file.
getDriverExtension()
getDriverExtension
getDriverLabel()
getDriverLabel
close_file()
Close file handle.
write_footer($outputlangs)
Output footer into file.
getDriverVersion()
getDriverVersion
write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
Output title line into file.
getDriverDesc()
getDriverDesc
getLibVersion()
getLibVersion
open_file($file, $outputlangs)
Open output file.
__construct($db)
Constructor.
tsv_clean($newvalue, $charset)
Clean a cell to respect rules of TSV file cells.
write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
Output record 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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
jsonOrUnserialize($stringtodecode)
Decode an encode string.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.