dolibarr  20.0.0-beta
export_csvutf8.modules.php
1 <?php
2 /* Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 require_once DOL_DOCUMENT_ROOT.'/core/modules/export/exportcsv.class.php';
26 
27 // avoid timeout for big export
28 set_time_limit(0);
29 
33 class ExportCsvUtf8 extends ExportCsv
34 {
40  public function __construct($db)
41  {
42  global $conf, $langs;
43  $this->db = $db;
44 
45  $this->separator = ',';
46  if (getDolGlobalString('EXPORT_CSV_SEPARATOR_TO_USE')) {
47  $this->separator = getDolGlobalString('EXPORT_CSV_SEPARATOR_TO_USE');
48  }
49 
50  $this->escape = '"';
51  $this->enclosure = '"';
52  $this->id = 'csvutf8'; // Same value then xxx in file name export_xxx.modules.php
53  $this->label = 'CSV UTF-8'; // Label of driver
54  $this->desc = $langs->trans("CSVFormatDesc", $this->separator, $this->enclosure, $this->escape);
55  $this->extension = 'csv'; // Extension for generated file by this driver
56  $this->picto = 'mime/other'; // Picto
57  $this->version = '1.32'; // Driver version
58 
59  // If driver use an external library, put its name here
60  $this->label_lib = 'Dolibarr';
61  $this->version_lib = DOL_VERSION;
62  }
63 
64  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
74  public function write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
75  {
76  global $conf;
77  $conf->global->EXPORT_CSV_FORCE_CHARSET = 'UTF-8';
78 
79  return parent::write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types);
80  }
81 
82  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
92  public function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
93  {
94  global $conf;
95 
96  $conf->global->EXPORT_CSV_FORCE_CHARSET = 'UTF-8';
97  return parent::write_record($array_selected_sorted, $objp, $outputlangs, $array_types);
98  }
99 }
Class to build export files with format CSV.
Class to build export files with format CSV utf-8.
write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
Output record line into file.
write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types)
Output title line into file.
__construct($db)
Constructor.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.