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 $selectlabel = array();
189 foreach ($array_selected_sorted as $code => $value) {
190 $newvalue = $outputlangs->transnoentities($array_export_fields_label[$code]);
191 $newvalue = $this->
csvClean($newvalue, $outputlangs->charset_output);
193 fwrite($this->handle, $newvalue.$this->separator);
194 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
196 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
197 $selectlabel[$code.
"_label"] = $newvalue.
"_label";
201 foreach ($selectlabel as $key => $value) {
202 fwrite($this->handle, $value.$this->separator);
204 fwrite($this->handle,
"\n");
219 public function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
229 $selectlabelvalues = array();
230 foreach ($array_selected_sorted as $code => $value) {
231 if (strpos($code,
' as ') == 0) {
232 $alias = str_replace(array(
'.',
'-',
'(',
')'),
'_', $code);
234 $alias = substr($code, strpos($code,
' as ') + 4);
237 dol_print_error(
null,
'Bad value for field with key='.$code.
'. Try to redefine export.');
240 $newvalue = $outputlangs->convToOutputCharset($objp->$alias);
241 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
244 if (preg_match(
'/^\((.*)\)$/i', $newvalue, $reg)) {
245 $newvalue = $outputlangs->transnoentities($reg[1]);
249 $newvalue = $this->
csvClean($newvalue, $outputlangs->charset_output);
251 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
253 if (is_array($array) && !empty($newvalue)) {
254 $array = $array[
'options'];
255 $selectlabelvalues[$code.
"_label"] = $array[$newvalue];
257 $selectlabelvalues[$code.
"_label"] =
"";
261 fwrite($this->handle, $newvalue.$this->separator);
264 foreach ($selectlabelvalues as $key => $value) {
265 fwrite($this->handle, $value.$this->separator);
269 fwrite($this->handle,
"\n");
295 fclose($this->handle);
321 $oldvalue = $newvalue;
322 $newvalue = str_replace(
"\r",
'', $newvalue);
323 $newvalue = str_replace(
"\n",
'\n', $newvalue);
328 $newvalue = $oldvalue;
334 if (preg_match(
'/"/', $newvalue)) {
336 $newvalue = str_replace(
'"',
'""', $newvalue);
340 if (preg_match(
'/'.$this->separator.
'/', $newvalue)) {
344 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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.