25require_once DOL_DOCUMENT_ROOT.
'/core/modules/export/modules_export.php';
51 public $version =
'dolibarr';
98 return $this->extension;
108 return $this->version;
118 return $this->label_lib;
128 return $this->version_lib;
145 dol_syslog(
"ExportCsv::open_file file=".$file);
149 $outputlangs->load(
"exports");
150 $this->handle = fopen($file,
"wt");
151 if (!$this->handle) {
152 $langs->load(
"errors");
153 $this->error = $langs->trans(
"ErrorFailToCreateFile", $file);
184 public function write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
189 $selectlabel = array();
190 foreach ($array_selected_sorted as $code => $value) {
191 $newvalue = $outputlangs->transnoentities($array_export_fields_label[$code]);
192 $newvalue = $this->
csvClean($newvalue, $outputlangs->charset_output);
194 fwrite($this->handle, $newvalue.$this->separator);
195 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
197 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
198 $selectlabel[$code.
"_label"] = $newvalue.
"_label";
202 foreach ($selectlabel as $key => $value) {
203 fwrite($this->handle, $value.$this->separator);
205 fwrite($this->handle,
"\n");
220 public function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
230 $selectlabelvalues = array();
231 foreach ($array_selected_sorted as $code => $value) {
232 if (strpos($code,
' as ') == 0) {
233 $alias = str_replace(array(
'.',
'-',
'(',
')'),
'_', $code);
235 $alias = substr($code, strpos($code,
' as ') + 4);
238 dol_print_error(
null,
'Bad value for field with key='.$code.
'. Try to redefine export.');
241 $newvalue = $outputlangs->convToOutputCharset($objp->$alias);
242 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
245 if (preg_match(
'/^\((.*)\)$/i', $newvalue, $reg)) {
246 $newvalue = $outputlangs->transnoentities($reg[1]);
250 $newvalue = $this->
csvClean($newvalue, $outputlangs->charset_output);
252 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
254 if (is_array($array) && !empty($newvalue)) {
255 $array = $array[
'options'];
256 $selectlabelvalues[$code.
"_label"] = $array[$newvalue];
258 $selectlabelvalues[$code.
"_label"] =
"";
262 fwrite($this->handle, $newvalue.$this->separator);
265 foreach ($selectlabelvalues as $key => $value) {
266 fwrite($this->handle, $value.$this->separator);
270 fwrite($this->handle,
"\n");
296 fclose($this->handle);
322 $oldvalue = $newvalue;
323 $newvalue = str_replace(
"\r",
'', $newvalue);
324 $newvalue = str_replace(
"\n",
'\n', $newvalue);
329 $newvalue = $oldvalue;
335 if (preg_match(
'/"/', $newvalue)) {
337 $newvalue = str_replace(
'"',
'""', $newvalue);
341 if (preg_match(
'/'.$this->separator.
'/', $newvalue)) {
345 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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
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.
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.