25require_once DOL_DOCUMENT_ROOT.
'/core/modules/export/modules_export.php';
49 public $version =
'dolibarr';
108 return $this->extension;
118 return $this->version;
128 return $this->label_lib;
138 return $this->version_lib;
155 dol_syslog(
"ExportCsv::open_file file=".$file);
159 $outputlangs->load(
"exports");
160 $this->handle = fopen($file,
"wt");
161 if (!$this->handle) {
162 $langs->load(
"errors");
163 $this->error = $langs->trans(
"ErrorFailToCreateFile", $file);
194 public function write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
197 $selectlabel = array();
198 foreach ($array_selected_sorted as $code => $value) {
199 if (strpos($code,
' as ') == 0) {
200 $alias = str_replace(array(
'.',
'-',
'(',
')'),
'_', $code);
202 $alias = substr($code, strpos($code,
' as ') + 4);
205 dol_syslog(
'Bad value for field with code='.$code.
'. Try to redefine export.', LOG_WARNING);
209 $newvalue = $array_export_fields_label[$code];
211 $newvalue = $outputlangs->transnoentitiesnoconv($newvalue);
217 $decodedlabel = $newvalue;
220 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
223 fwrite($this->handle, $newvalue.$this->separator);
224 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
226 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
229 $selectlabel[$code.
"_label"] =
csvClean($decodedlabel.
"_label", $outputlangs->charset_output, $this->separator);
233 foreach ($selectlabel as $key => $value) {
234 fwrite($this->handle, $value.$this->separator);
236 fwrite($this->handle,
"\n");
251 public function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
260 $selectlabelvalues = array();
261 foreach ($array_selected_sorted as $code => $value) {
262 if (strpos($code,
' as ') == 0) {
263 $alias = str_replace(array(
'.',
'-',
'(',
')'),
'_', $code);
265 $alias = substr($code, strpos($code,
' as ') + 4);
268 dol_syslog(
'Bad value for field with code='.$code.
'. Try to redefine export.', LOG_WARNING);
272 $newvalue = $objp->$alias;
273 $typefield = isset($array_types[$code]) ? $array_types[$code] :
'';
276 if (preg_match(
'/^\((.*)\)$/i', $newvalue, $reg)) {
277 $newvalue = $outputlangs->transnoentities($reg[1]);
281 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
282 $newvalue =
csvClean($newvalue, $outputlangs->charset_output, $this->separator);
284 if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
286 if (is_array($array) && !empty($newvalue)) {
287 $array = $array[
'options'];
288 $selectlabelvalues[$code.
"_label"] = $array[$newvalue];
290 $selectlabelvalues[$code.
"_label"] =
"";
294 fwrite($this->handle, $newvalue.$this->separator);
297 foreach ($selectlabelvalues as $key => $value) {
298 fwrite($this->handle, $value.$this->separator);
302 fwrite($this->handle,
"\n");
328 fclose($this->handle);
Class to build export files with format CSV.
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.
csvClean($newvalue, $charset='', $separator='')
Clean a cell to respect rules of CSV file cells.
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, $assoc=true)
Decode an encoded 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.