26require_once DOL_DOCUMENT_ROOT.
'/core/modules/export/modules_export.php';
50 public $version =
'dolibarr';
65 public $separator =
"\t";
85 $this->desc = $langs->trans(
'TsvFormatDesc');
86 $this->extension =
'tsv';
87 $this->picto =
'mime/other';
88 $this->version =
'1.15';
91 $this->label_lib =
'Dolibarr';
92 $this->version_lib = DOL_VERSION;
132 return $this->extension;
142 return $this->version;
152 return $this->label_lib;
162 return $this->version_lib;
179 dol_syslog(
"ExportTsv::open_file file=".$file);
183 $outputlangs->load(
"exports");
184 $this->handle = fopen($file,
"wt");
185 if (!$this->handle) {
186 $langs->load(
"errors");
187 $this->error = $langs->trans(
"ErrorFailToCreateFile", $file);
218 public function write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
223 $selectlabel = array();
224 foreach ($array_selected_sorted as $code => $value) {
225 if (strpos($code,
' as ') == 0) {
226 $alias = str_replace(array(
'.',
'-',
'(',
')'),
'_', $code);
228 $alias = substr($code, strpos($code,
' as ') + 4);
231 dol_syslog(
'Bad value for field with code='.$code.
'. Try to redefine export.', LOG_WARNING);
235 $newvalue = $outputlangs->transnoentities($array_export_fields_label[$code]);
236 $newvalue = $this->
tsv_clean($newvalue, $outputlangs->charset_output);
238 fwrite($this->handle, $newvalue.$this->separator);
239 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
241 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
242 $selectlabel[$code.
"_label"] = $newvalue.
"_label";
245 foreach ($selectlabel as $key => $value) {
246 fwrite($this->handle, $value.$this->separator);
248 fwrite($this->handle,
"\n");
263 public function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
272 $selectlabelvalues = array();
273 foreach ($array_selected_sorted as $code => $value) {
274 if (strpos($code,
' as ') == 0) {
275 $alias = str_replace(array(
'.',
'-',
'(',
')'),
'_', $code);
277 $alias = substr($code, strpos($code,
' as ') + 4);
280 dol_syslog(
'Bad value for field with code='.$code.
'. Try to redefine export.', LOG_WARNING);
284 $newvalue = $outputlangs->convToOutputCharset($objp->$alias);
285 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
288 if (preg_match(
'/^\((.*)\)$/i', $newvalue, $reg)) {
289 $newvalue = $outputlangs->transnoentities($reg[1]);
292 $newvalue = $this->
tsv_clean($newvalue, $outputlangs->charset_output);
294 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
296 if (is_array($array) && !empty($newvalue)) {
297 $array = $array[
'options'];
298 $selectlabelvalues[$code.
"_label"] = $array[$newvalue];
300 $selectlabelvalues[$code.
"_label"] =
"";
304 fwrite($this->handle, $newvalue.$this->separator);
307 foreach ($selectlabelvalues as $key => $value) {
308 fwrite($this->handle, $value.$this->separator);
312 fwrite($this->handle,
"\n");
338 fclose($this->handle);
358 $newvalue = str_replace(
"\r",
'', $newvalue);
359 $newvalue = str_replace(
"\n",
'\n', $newvalue);
362 if (preg_match(
'/'.$this->separator.
'/', $newvalue)) {
363 $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.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...