24 require_once DOL_DOCUMENT_ROOT.
'/core/modules/export/modules_export.php';
 
   50   public $version = 
'dolibarr';
 
   71     $this->separator = 
',';
 
   72     if (!empty($conf->global->EXPORT_CSV_SEPARATOR_TO_USE)) {
 
   73       $this->separator = $conf->global->EXPORT_CSV_SEPARATOR_TO_USE;
 
   76     $this->enclosure = 
'"';
 
   80     $this->desc = $langs->trans(
"CSVFormatDesc", $this->separator, $this->enclosure, $this->escape);
 
   81     $this->extension = 
'csv'; 
 
   82     $this->picto = 
'mime/other'; 
 
   83     $this->version = 
'1.32'; 
 
   86     $this->label_lib = 
'Dolibarr';
 
   87     $this->version_lib = DOL_VERSION;
 
  127     return $this->extension;
 
  137     return $this->version;
 
  147     return $this->label_lib;
 
  157     return $this->version_lib;
 
  174     dol_syslog(
"ExportCsv::open_file file=".$file);
 
  178     $outputlangs->load(
"exports");
 
  179     $this->handle = fopen($file, 
"wt");
 
  180     if (!$this->handle) {
 
  181       $langs->load(
"errors");
 
  182       $this->error = $langs->trans(
"ErrorFailToCreateFile", $file);
 
  213   public function write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
 
  218     if (!empty($conf->global->EXPORT_CSV_FORCE_CHARSET)) {
 
  219       $outputlangs->charset_output = $conf->global->EXPORT_CSV_FORCE_CHARSET;
 
  221       $outputlangs->charset_output = 
'ISO-8859-1';
 
  223     $selectlabel = array();
 
  225     foreach ($array_selected_sorted as $code => $value) {
 
  226       $newvalue = $outputlangs->transnoentities($array_export_fields_label[$code]); 
 
  227       $newvalue = $this->
csvClean($newvalue, $outputlangs->charset_output);
 
  229       fwrite($this->handle, $newvalue.$this->separator);
 
  230       $typefield = isset($array_types[$code]) ? $array_types[$code] : 
'';
 
  232       if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
 
  233         $selectlabel[$code.
"_label"] = $newvalue.
"_label";
 
  236     foreach ($selectlabel as $key => $value) {
 
  237       fwrite($this->handle, $value.$this->separator);
 
  239     fwrite($this->handle, 
"\n");
 
  254   public function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
 
  259     if (!empty($conf->global->EXPORT_CSV_FORCE_CHARSET)) {
 
  260       $outputlangs->charset_output = $conf->global->EXPORT_CSV_FORCE_CHARSET;
 
  262       $outputlangs->charset_output = 
'ISO-8859-1';
 
  268     $selectlabelvalues = array();
 
  269     foreach ($array_selected_sorted as $code => $value) {
 
  270       if (strpos($code, 
' as ') == 0) {
 
  271         $alias = str_replace(array(
'.', 
'-', 
'(', 
')'), 
'_', $code);
 
  273         $alias = substr($code, strpos($code, 
' as ') + 4);
 
  276         dol_print_error(
'', 
'Bad value for field with key='.$code.
'. Try to redefine export.');
 
  279       $newvalue = $outputlangs->convToOutputCharset($objp->$alias); 
 
  280       $typefield = isset($array_types[$code]) ? $array_types[$code] : 
'';
 
  283       if (preg_match(
'/^\((.*)\)$/i', $newvalue, $reg)) {
 
  284         $newvalue = $outputlangs->transnoentities($reg[1]);
 
  288       $newvalue = $this->
csvClean($newvalue, $outputlangs->charset_output);
 
  290       if (preg_match(
'/^Select:/i', $typefield) && $typefield = substr($typefield, 7)) {
 
  292         if (is_array($array) && !empty($newvalue)) {
 
  293           $array = $array[
'options'];
 
  294           $selectlabelvalues[$code.
"_label"] = $array[$newvalue];
 
  296           $selectlabelvalues[$code.
"_label"] = 
"";
 
  300       fwrite($this->handle, $newvalue.$this->separator);
 
  303     foreach ($selectlabelvalues as $key => $value) {
 
  304       fwrite($this->handle, $value.$this->separator);
 
  308     fwrite($this->handle, 
"\n");
 
  334     fclose($this->handle);
 
  360     $oldvalue = $newvalue;
 
  361     $newvalue = str_replace(
"\r", 
'', $newvalue);
 
  362     $newvalue = str_replace(
"\n", 
'\n', $newvalue);
 
  363     if (!empty($conf->global->USE_STRICT_CSV_RULES) && $oldvalue != $newvalue) {
 
  365       if ($conf->global->USE_STRICT_CSV_RULES == 1) {
 
  367         $newvalue = $oldvalue;
 
  373     if (preg_match(
'/"/', $newvalue)) {
 
  375       $newvalue = str_replace(
'"', 
'""', $newvalue);
 
  379     if (preg_match(
'/'.$this->separator.
'/', $newvalue)) {
 
  383     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.
 
__construct($db)
Constructor.
 
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...
 
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending   and br at end.
 
jsonOrUnserialize($stringtodecode)
Decode an encode string.
 
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
 
$conf db
API class for accounts.