1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* Copyright (C) 2005 Laurent Destailleur <[email protected]> |
4
|
|
|
* Copyright (C) 2005-2007 Regis Houssin <[email protected]> |
5
|
|
|
* Copyright (C) 2024 Rafael San José <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This program is free software; you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Dolibarr\Code\Exports\Classes; |
22
|
|
|
|
23
|
|
|
use Dolibarr\Code\Core\Classes\CommonDocGenerator; |
24
|
|
|
use DoliDB; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* \file htdocs/core/modules/export/modules_export.php |
28
|
|
|
* \ingroup export |
29
|
|
|
* \brief File of parent class for export modules |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Parent class for export modules |
34
|
|
|
*/ |
35
|
|
|
class ModeleExports extends CommonDocGenerator // This class can't be abstract as there is instance properties loaded by listOfAvailableExportFormat |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* @var string Error code (or message) |
39
|
|
|
*/ |
40
|
|
|
public $error = ''; |
41
|
|
|
|
42
|
|
|
public $driverlabel = array(); |
43
|
|
|
|
44
|
|
|
public $driverdesc = array(); |
45
|
|
|
|
46
|
|
|
public $driverversion = array(); |
47
|
|
|
|
48
|
|
|
public $liblabel = array(); |
49
|
|
|
|
50
|
|
|
public $libversion = array(); |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string picto |
54
|
|
|
*/ |
55
|
|
|
public $picto; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string description |
59
|
|
|
*/ |
60
|
|
|
public $desc; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var string escape |
64
|
|
|
*/ |
65
|
|
|
public $escape; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var string enclosure |
69
|
|
|
*/ |
70
|
|
|
public $enclosure; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var int col |
74
|
|
|
*/ |
75
|
|
|
public $col; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var int disabled |
79
|
|
|
*/ |
80
|
|
|
public $disabled; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Load into memory list of available export format |
84
|
|
|
* |
85
|
|
|
* @param DoliDB $db Database handler |
86
|
|
|
* @param integer $maxfilenamelength Max length of value to show |
87
|
|
|
* @return array List of templates (same content than array this->driverlabel) |
88
|
|
|
*/ |
89
|
|
|
public function listOfAvailableExportFormat($db, $maxfilenamelength = 0) |
90
|
|
|
{ |
91
|
|
|
global $langs; |
92
|
|
|
|
93
|
|
|
dol_syslog(get_class($this) . "::listOfAvailableExportFormat"); |
94
|
|
|
|
95
|
|
|
$dir = DOL_DOCUMENT_ROOT . "/core/modules/export/"; |
96
|
|
|
$handle = opendir($dir); |
97
|
|
|
|
98
|
|
|
// Recherche des fichiers drivers exports disponibles |
99
|
|
|
$i = 0; |
100
|
|
|
if (is_resource($handle)) { |
101
|
|
|
while (($file = readdir($handle)) !== false) { |
102
|
|
|
$reg = array(); |
103
|
|
|
if (preg_match("/^export_(.*)\.modules\.php$/i", $file, $reg)) { |
104
|
|
|
$moduleid = $reg[1]; |
105
|
|
|
if ($moduleid == 'csv') { |
106
|
|
|
continue; // This may happen if on old file export_csv.modules.php was not correctly deleted |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
// Loading Class |
110
|
|
|
$file = $dir . "export_" . $moduleid . ".modules.php"; |
111
|
|
|
$classname = "Export" . ucfirst($moduleid); |
112
|
|
|
|
113
|
|
|
require_once $file; |
114
|
|
|
if (class_exists($classname)) { |
115
|
|
|
$module = new $classname($db); |
116
|
|
|
// var_dump($classname); |
117
|
|
|
|
118
|
|
|
// Picto |
119
|
|
|
$this->picto[$module->id] = $module->picto; |
120
|
|
|
// Driver properties |
121
|
|
|
$this->driverlabel[$module->id] = $module->getDriverLabel() . (empty($module->disabled) ? '' : ' __(Disabled)__'); // '__(Disabled)__' is a key |
122
|
|
|
if (method_exists($module, 'getDriverLabelBis')) { |
123
|
|
|
if ($module->getDriverLabelBis()) { |
124
|
|
|
$this->driverlabel[$module->id] .= ' <span class="opacitymedium">(' . $module->getDriverLabelBis() . ')</span>'; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
$this->driverdesc[$module->id] = $module->getDriverDesc(); |
128
|
|
|
$this->driverversion[$module->id] = $module->getDriverVersion(); |
129
|
|
|
// If use an external lib |
130
|
|
|
$this->liblabel[$module->id] = $module->getLibLabel(); |
131
|
|
|
$this->libversion[$module->id] = $module->getLibVersion(); |
132
|
|
|
} |
133
|
|
|
$i++; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
closedir($handle); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
asort($this->driverlabel); |
140
|
|
|
|
141
|
|
|
return $this->driverlabel; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Return picto of export driver |
147
|
|
|
* |
148
|
|
|
* @param string $key Key of driver |
149
|
|
|
* @return string Picto string |
150
|
|
|
*/ |
151
|
|
|
public function getPictoForKey($key) |
152
|
|
|
{ |
153
|
|
|
return $this->picto[$key]; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Return label of driver export |
158
|
|
|
* |
159
|
|
|
* @param string $key Key of driver |
160
|
|
|
* @return string Label |
161
|
|
|
*/ |
162
|
|
|
public function getDriverLabelForKey($key) |
163
|
|
|
{ |
164
|
|
|
return $this->driverlabel[$key]; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Renvoi le descriptif d'un driver export |
169
|
|
|
* |
170
|
|
|
* @param string $key Key of driver |
171
|
|
|
* @return string Description |
172
|
|
|
*/ |
173
|
|
|
public function getDriverDescForKey($key) |
174
|
|
|
{ |
175
|
|
|
return $this->driverdesc[$key]; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Renvoi version d'un driver export |
180
|
|
|
* |
181
|
|
|
* @param string $key Key of driver |
182
|
|
|
* @return string Driver version |
183
|
|
|
*/ |
184
|
|
|
public function getDriverVersionForKey($key) |
185
|
|
|
{ |
186
|
|
|
return $this->driverversion[$key]; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Renvoi label of driver lib |
191
|
|
|
* |
192
|
|
|
* @param string $key Key of driver |
193
|
|
|
* @return string Label of library |
194
|
|
|
*/ |
195
|
|
|
public function getLibLabelForKey($key) |
196
|
|
|
{ |
197
|
|
|
return $this->liblabel[$key]; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Return version of driver lib |
202
|
|
|
* |
203
|
|
|
* @param string $key Key of driver |
204
|
|
|
* @return string Version of library |
205
|
|
|
*/ |
206
|
|
|
public function getLibVersionForKey($key) |
207
|
|
|
{ |
208
|
|
|
return $this->libversion[$key]; |
209
|
|
|
} |
210
|
|
|
} |
211
|
|
|
|