24require_once DOL_DOCUMENT_ROOT.
'/core/modules/export/modules_export.php';
50 public $version =
'dolibarr';
97 return $this->extension;
107 return $this->version;
117 return $this->label_lib;
127 return $this->version_lib;
144 dol_syslog(
"ExportCsv::open_file file=".$file);
148 $outputlangs->load(
"exports");
149 $this->handle = fopen($file,
"wt");
150 if (!$this->handle) {
151 $langs->load(
"errors");
152 $this->error = $langs->trans(
"ErrorFailToCreateFile", $file);
183 public function write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
188 $outputlangs->charset_output = $conf->global->EXPORT_CSV_FORCE_CHARSET;
190 $selectlabel = array();
192 foreach ($array_selected_sorted as $code => $value) {
193 $newvalue = $outputlangs->transnoentities($array_export_fields_label[$code]);
194 $newvalue = $this->
csvClean($newvalue, $outputlangs->charset_output);
196 fwrite($this->handle, $newvalue.$this->separator);
197 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
199 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
200 $selectlabel[$code.
"_label"] = $newvalue.
"_label";
203 foreach ($selectlabel as $key => $value) {
204 fwrite($this->handle, $value.$this->separator);
206 fwrite($this->handle,
"\n");
221 public function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
226 $outputlangs->charset_output = $conf->global->EXPORT_CSV_FORCE_CHARSET;
231 $selectlabelvalues = array();
232 foreach ($array_selected_sorted as $code => $value) {
233 if (strpos($code,
' as ') == 0) {
234 $alias = str_replace(array(
'.',
'-',
'(',
')'),
'_', $code);
236 $alias = substr($code, strpos($code,
' as ') + 4);
239 dol_print_error(
'',
'Bad value for field with key='.$code.
'. Try to redefine export.');
242 $newvalue = $outputlangs->convToOutputCharset($objp->$alias);
243 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
246 if (preg_match(
'/^\((.*)\)$/i', $newvalue, $reg)) {
247 $newvalue = $outputlangs->transnoentities($reg[1]);
251 $newvalue = $this->
csvClean($newvalue, $outputlangs->charset_output);
253 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
255 if (is_array($array) && !empty($newvalue)) {
256 $array = $array[
'options'];
257 $selectlabelvalues[$code.
"_label"] = $array[$newvalue];
259 $selectlabelvalues[$code.
"_label"] =
"";
263 fwrite($this->handle, $newvalue.$this->separator);
266 foreach ($selectlabelvalues as $key => $value) {
267 fwrite($this->handle, $value.$this->separator);
271 fwrite($this->handle,
"\n");
297 fclose($this->handle);
323 $oldvalue = $newvalue;
324 $newvalue = str_replace(
"\r",
'', $newvalue);
325 $newvalue = str_replace(
"\n",
'\n', $newvalue);
330 $newvalue = $oldvalue;
336 if (preg_match(
'/"/', $newvalue)) {
338 $newvalue = str_replace(
'"',
'""', $newvalue);
342 if (preg_match(
'/'.$this->separator.
'/', $newvalue)) {
346 return ($addquote ?
'"' :
'').$newvalue.($addquote ?
'"' :
'');
Class to build export files with format CSV.
getLibLabel()
getLabelLabel
csvClean($newvalue, $charset)
Clean a cell to respect rules of CSV file cells Note: It uses $this->separator Note: We keep this fun...
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.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
jsonOrUnserialize($stringtodecode)
Decode an encode string.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.