1 |
softime |
10067 |
<?php |
2 |
|
|
/** |
3 |
|
|
* Contient la définition des classes 'electronicsignature' et 'electronicsignature_base'. |
4 |
|
|
*/ |
5 |
|
|
|
6 |
|
|
/** |
7 |
|
|
* Abstracteur du parapheur |
8 |
|
|
*/ |
9 |
|
|
class electronicsignature { |
10 |
|
|
|
11 |
|
|
/** |
12 |
|
|
* [$conf description] |
13 |
|
|
* @var null |
14 |
|
|
*/ |
15 |
|
|
var $conf = null; |
16 |
|
|
|
17 |
|
|
/** |
18 |
|
|
* [$electronicsignature description] |
19 |
|
|
* @var null |
20 |
|
|
*/ |
21 |
|
|
var $electronicsignature = null; |
22 |
|
|
|
23 |
|
|
/** |
24 |
|
|
* [__construct description] |
25 |
|
|
* @param array $params [description] |
26 |
|
|
*/ |
27 |
|
|
public function __construct(array $params) { |
28 |
|
|
// |
29 |
|
|
if (file_exists("../dyn/electronicsignature.inc.php") === false) { |
30 |
|
|
throw new electronicsignature_configuration_exception(__("Aucun fichier de configuration pour la signature électronique."), false); |
31 |
|
|
} |
32 |
|
|
include("../dyn/electronicsignature.inc.php"); |
33 |
|
|
if (isset($conf) === false) { |
34 |
|
|
throw new electronicsignature_configuration_exception(__("Aucune configuration pour la signature électronique."), false); |
35 |
|
|
} |
36 |
|
|
$this->conf = $conf; |
37 |
|
|
// |
38 |
|
|
if (isset($params['conf_name']) === true) { |
39 |
|
|
$this->conf = $this->conf[$params['conf_name']]; |
40 |
|
|
} else { |
41 |
|
|
$this->conf = $this->conf['electronicsignature-default']; |
42 |
|
|
} |
43 |
|
|
// |
44 |
|
|
if (isset($params['collectivite_idx']) === true |
45 |
|
|
&& $this->get_conf('unexpected_collectivite') !== null |
46 |
|
|
&& in_array($params['collectivite_idx'], $this->get_conf('unexpected_collectivite')) === true) { |
47 |
|
|
// |
48 |
|
|
throw new electronicsignature_configuration_exception(__("Aucun parapheur configuré pour la collectivité."), false); |
49 |
|
|
} |
50 |
|
|
// |
51 |
|
|
if (isset($params['collectivite_idx']) === true |
52 |
|
|
&& $this->get_conf($params['collectivite_idx']) !== null) { |
53 |
|
|
// |
54 |
|
|
$this->conf = $this->conf[$params['collectivite_idx']]; |
55 |
|
|
} |
56 |
|
|
elseif (isset($params['collectivite_multi_idx']) === true |
57 |
|
|
&& $this->get_conf($params['collectivite_multi_idx']) !== null) { |
58 |
|
|
// |
59 |
|
|
$this->conf = $this->conf[$params['collectivite_multi_idx']]; |
60 |
|
|
} else { |
61 |
|
|
throw new electronicsignature_configuration_exception(__("Aucun parapheur configuré pour la collectivité."), false); |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
// |
65 |
|
|
if ($this->get_conf('path') === null) { |
66 |
|
|
throw new electronicsignature_configuration_exception(__("Le chemin vers le connecteur du parapheur n'est pas configuré.")); |
67 |
|
|
} |
68 |
|
|
// |
69 |
|
|
if ($this->get_conf('connector') === null) { |
70 |
|
|
throw new electronicsignature_configuration_exception(__("Le nom du connecteur du parapheur n'est pas configuré.")); |
71 |
|
|
} |
72 |
|
|
// |
73 |
|
|
$connector = sprintf( |
74 |
|
|
'%s_%s', |
75 |
|
|
get_class($this), |
76 |
|
|
$this->get_conf('connector') |
77 |
|
|
); |
78 |
|
|
require_once $this->conf['path'].$connector.'.class.php'; |
79 |
|
|
$this->electronicsignature = new $connector($this->get_conf()); |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
/** |
83 |
|
|
* [__destruct description] |
84 |
|
|
*/ |
85 |
|
|
public function __destruct() { |
86 |
|
|
// |
87 |
|
|
if (is_null($this->electronicsignature) === false) { |
88 |
|
|
unset($this->electronicsignature); |
89 |
|
|
} |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
/** |
93 |
|
|
* [get_conf description] |
94 |
|
|
* @param [type] $params [description] |
95 |
|
|
* @return [type] [description] |
96 |
|
|
*/ |
97 |
|
|
public function get_conf($params = null) { |
98 |
|
|
if ($params === null) { |
99 |
|
|
return $this->conf; |
100 |
|
|
} |
101 |
|
|
if (is_string($params) === true |
102 |
|
|
&& is_array($this->conf) === true) { |
103 |
|
|
// |
104 |
|
|
if (array_key_exists($params, $this->conf) === true) { |
105 |
|
|
return $this->conf[$params]; |
106 |
|
|
} |
107 |
|
|
} |
108 |
|
|
if (is_array($params) === true |
109 |
|
|
&& is_array($this->conf) === true |
110 |
|
|
&& count($params) === 2 |
111 |
|
|
&& array_key_exists($params[0], $this->conf) === true |
112 |
|
|
&& is_array($this->conf[$params[0]]) === true |
113 |
|
|
&& array_key_exists($params[1], $this->conf[$params[0]]) === true) { |
114 |
|
|
// |
115 |
|
|
return $this->conf[$params[0]][$params[1]]; |
116 |
|
|
} |
117 |
|
|
return null; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
/** |
121 |
|
|
* [send_for_signature description] |
122 |
|
|
* @param array $data [description] |
123 |
|
|
* @param string $file_content [description] |
124 |
|
|
* @return [type] [description] |
125 |
|
|
*/ |
126 |
|
|
public function send_for_signature(array $data, string $file_content) { |
127 |
|
|
// |
128 |
|
|
if (is_array($data) === false |
129 |
|
|
|| empty($data) === true) { |
130 |
|
|
// |
131 |
|
|
throw new electronicsignature_parameter_exception(); |
132 |
|
|
} |
133 |
|
|
if (empty($file_content) === true) { |
134 |
|
|
// |
135 |
|
|
throw new electronicsignature_parameter_exception(__("Aucun contenu de document transmis.")); |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
// |
139 |
|
|
$es = $this->electronicsignature; |
140 |
|
|
if (is_null($es) === true) { |
141 |
|
|
return false; |
142 |
|
|
} |
143 |
|
|
// |
144 |
|
|
return $es->send_for_signature($data, $file_content); |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
/** |
148 |
|
|
* [get_signature_status description] |
149 |
|
|
* @param array $data [description] |
150 |
|
|
* @return [type] [description] |
151 |
|
|
*/ |
152 |
|
|
public function get_signature_status(array $data) { |
153 |
|
|
// |
154 |
|
|
if (is_array($data) === false |
155 |
|
|
|| empty($data) === true) { |
156 |
|
|
// |
157 |
|
|
throw new electronicsignature_parameter_exception(); |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
// |
161 |
|
|
$es = $this->electronicsignature; |
162 |
|
|
if (is_null($es) === true) { |
163 |
|
|
return false; |
164 |
|
|
} |
165 |
|
|
// |
166 |
|
|
return $es->get_signature_status($data); |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
/** |
170 |
|
|
* [get_signed_document description] |
171 |
|
|
* @param array $data [description] |
172 |
|
|
* @return [type] [description] |
173 |
|
|
*/ |
174 |
|
|
public function get_signed_document(array $data) { |
175 |
|
|
// |
176 |
|
|
if (is_array($data) === false |
177 |
|
|
|| empty($data) === true) { |
178 |
|
|
// |
179 |
|
|
throw new electronicsignature_parameter_exception(); |
180 |
|
|
} |
181 |
|
|
|
182 |
|
|
// |
183 |
|
|
$es = $this->electronicsignature; |
184 |
|
|
if (is_null($es) === true) { |
185 |
|
|
return false; |
186 |
|
|
} |
187 |
|
|
// |
188 |
|
|
return $es->get_signed_document($data); |
189 |
|
|
} |
190 |
|
|
|
191 |
|
|
} |
192 |
|
|
|
193 |
|
|
/** |
194 |
|
|
* Classe parente de tous les connecteurs parapheur |
195 |
|
|
*/ |
196 |
|
|
class electronicsignature_base { |
197 |
|
|
|
198 |
|
|
protected function send_for_signature(array $data, string $file_content) { |
199 |
|
|
// |
200 |
|
|
throw new electronicsignature_connector_method_not_implemented_exception(); |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
protected function get_signature_status(array $data) { |
204 |
|
|
// |
205 |
|
|
throw new electronicsignature_connector_method_not_implemented_exception(); |
206 |
|
|
} |
207 |
|
|
|
208 |
|
|
protected function get_signed_document(array $data) { |
209 |
|
|
// |
210 |
|
|
throw new electronicsignature_connector_method_not_implemented_exception(); |
211 |
|
|
} |
212 |
|
|
|
213 |
|
|
} |
214 |
|
|
|
215 |
|
|
/** |
216 |
|
|
* Classe gérant les erreurs |
217 |
|
|
*/ |
218 |
|
|
class electronicsignature_exception extends Exception { |
219 |
|
|
|
220 |
|
|
public function __construct($message = "", $write_log = true, $code = 0, Exception $previous = null) { |
221 |
|
|
parent::__construct($message, $code, $previous); |
222 |
|
|
if ($write_log === true) { |
223 |
|
|
logger::instance()->writeErrorLogToFile(); |
224 |
|
|
} |
225 |
|
|
} |
226 |
|
|
} |
227 |
|
|
|
228 |
|
|
class electronicsignature_configuration_exception extends electronicsignature_exception { |
229 |
|
|
|
230 |
|
|
public function __construct($message = null, $write_log = true) { |
231 |
|
|
$ret = trim(sprintf( |
232 |
|
|
'%s %s %s', |
233 |
|
|
__('Erreur de configuration du parapheur.'), |
234 |
|
|
__('Veuillez contacter votre administrateur.'), |
235 |
|
|
$message |
236 |
|
|
)); |
237 |
|
|
parent::__construct($ret, $write_log); |
238 |
|
|
} |
239 |
|
|
} |
240 |
|
|
|
241 |
|
|
class electronicsignature_parameter_exception extends electronicsignature_exception { |
242 |
|
|
|
243 |
|
|
public function __construct($message = null, $write_log = true) { |
244 |
|
|
$ret = trim(sprintf( |
245 |
|
|
'%s %s %s', |
246 |
|
|
__("Les paramètres d'appel au parapheur ne sont pas valides."), |
247 |
|
|
__('Veuillez contacter votre administrateur.'), |
248 |
|
|
$message |
249 |
|
|
)); |
250 |
|
|
parent::__construct($ret, $write_log); |
251 |
|
|
} |
252 |
|
|
} |
253 |
|
|
|
254 |
|
|
class electronicsignature_connector_exception extends electronicsignature_exception { |
255 |
|
|
|
256 |
|
|
public function __construct($message = null, $write_log = true) { |
257 |
|
|
$ret = trim(sprintf( |
258 |
|
|
'%s %s %s', |
259 |
|
|
__('Erreur du parapheur.'), |
260 |
|
|
__('Veuillez contacter votre administrateur.'), |
261 |
|
|
$message |
262 |
|
|
)); |
263 |
|
|
parent::__construct($ret, $write_log); |
264 |
|
|
} |
265 |
|
|
} |
266 |
|
|
|
267 |
|
|
class electronicsignature_connector_method_not_implemented_exception extends electronicsignature_exception { |
268 |
|
|
|
269 |
|
|
public function __construct($message = null, $write_log = true) { |
270 |
|
|
$ret = trim(sprintf( |
271 |
|
|
'%s %s %s', |
272 |
|
|
__("La méthode n'est pas implémentée dans le connecteur."), |
273 |
|
|
__('Veuillez contacter votre administrateur.'), |
274 |
|
|
$message |
275 |
|
|
)); |
276 |
|
|
parent::__construct($ret, $write_log); |
277 |
|
|
} |
278 |
|
|
} |