1 |
<?php |
2 |
//$Id$ |
3 |
//gen openMairie le 14/04/2020 14:11 |
4 |
|
5 |
require_once "../gen/obj/task.class.php"; |
6 |
|
7 |
class task extends task_gen { |
8 |
|
9 |
const STATUS_DRAFT = 'draft'; |
10 |
const STATUS_NEW = 'new'; |
11 |
const STATUS_PENDING = 'pending'; |
12 |
const STATUS_DONE = 'done'; |
13 |
const STATUS_ERROR = 'error'; |
14 |
const STATUS_DEBUG = 'debug'; |
15 |
const STATUS_ARCHIVED = 'archived'; |
16 |
|
17 |
/** |
18 |
* Définition des actions disponibles sur la classe. |
19 |
* |
20 |
* @return void |
21 |
*/ |
22 |
public function init_class_actions() { |
23 |
parent::init_class_actions(); |
24 |
// |
25 |
$this->class_actions[998] = array( |
26 |
"identifier" => "json_data", |
27 |
"view" => "view_json_data", |
28 |
"permission_suffix" => "consulter", |
29 |
); |
30 |
$this->class_actions[997] = array( |
31 |
"identifier" => "json_data", |
32 |
"view" => "post_update_task", |
33 |
"permission_suffix" => "modifier", |
34 |
); |
35 |
$this->class_actions[996] = array( |
36 |
"identifier" => "json_data", |
37 |
"view" => "post_add_task", |
38 |
"permission_suffix" => "ajouter", |
39 |
); |
40 |
} |
41 |
|
42 |
public function setvalF($val = array()) { |
43 |
|
44 |
// // les guillets doubles sont remplacés automatiquement par des simples |
45 |
// // dans core/om_formulaire.clasS.php::recupererPostvar() |
46 |
// // voir le ticket https://dev.atreal.fr/projets/openmairie/tracker/209 |
47 |
// // ceci est un hack sale temporaire en attendant résolution du ticket |
48 |
// foreach(array('json_payload', 'timestamp_log') as $key) { |
49 |
// if (isset($val[$key]) && ! empty($val[$key]) && |
50 |
// isset($_POST[$key]) && ! empty($_POST[$key])) { |
51 |
// $submited_payload = $_POST[$key]; |
52 |
// if (! empty($submited_payload)) { |
53 |
// $new_payload = str_replace("'", '"', $val[$key]); |
54 |
// if ($new_payload == $submited_payload || |
55 |
// strpos($submited_payload, '"') === false) { |
56 |
// $val[$key] = $new_payload; |
57 |
// } |
58 |
// else { |
59 |
// $error_msg = sprintf( |
60 |
// __("La convertion des guillemets de la payload JSON '%s' ". |
61 |
// "n'est pas idempotente (courante: %s, postée: %s, convertie: %s)"), |
62 |
// $key, var_export($val[$key], true), var_export($submited_payload, true), |
63 |
// var_export($new_payload, true)); |
64 |
// $this->correct = false; |
65 |
// $this->addToMessage($error_msg); |
66 |
// $this->addToLog(__METHOD__."() erreur : $error_msg", DEBUG_MODE); |
67 |
// return false; |
68 |
// } |
69 |
// } |
70 |
// } |
71 |
// } |
72 |
|
73 |
parent::setvalF($val); |
74 |
|
75 |
// XXX Ancien code : permet de ne pas avoir d'erreru lors de la modification d'une task |
76 |
if (array_key_exists('timestamp_log', $val) === true) { |
77 |
$this->valF['timestamp_log'] = str_replace("'", '"', $val['timestamp_log']); |
78 |
} |
79 |
|
80 |
// récupération de l'ID de l'objet existant |
81 |
$id = property_exists($this, 'id') ? $this->id : null; |
82 |
if(isset($val[$this->clePrimaire])) { |
83 |
$id = $val[$this->clePrimaire]; |
84 |
} elseif(isset($this->valF[$this->clePrimaire])) { |
85 |
$id = $this->valF[$this->clePrimaire]; |
86 |
} |
87 |
|
88 |
// MODE MODIFIER |
89 |
if (! empty($id)) { |
90 |
|
91 |
// si aucune payload n'est fourni (devrait toujours être le cas) |
92 |
if (! isset($val['json_payload']) || empty($val['json_payload'])) { |
93 |
|
94 |
// récupère l'objet existant |
95 |
$existing = $this->f->findObjectById(get_class($this), $id); |
96 |
if (! empty($existing)) { |
97 |
|
98 |
// récupère la payload de l'objet |
99 |
$val['json_payload'] = $existing->getVal('json_payload'); |
100 |
$this->valF['json_payload'] = $existing->getVal('json_payload'); |
101 |
$this->f->addToLog(__METHOD__."() récupère la payload de la tâche existante ". |
102 |
"'$id': ".$existing->getVal('json_payload'), EXTRA_VERBOSE_MODE); |
103 |
} |
104 |
} |
105 |
} |
106 |
} |
107 |
|
108 |
/** |
109 |
* |
110 |
* @return array |
111 |
*/ |
112 |
function get_var_sql_forminc__champs() { |
113 |
return array( |
114 |
"task", |
115 |
"type", |
116 |
"state", |
117 |
"object_id", |
118 |
"dossier", |
119 |
"stream", |
120 |
"json_payload", |
121 |
"timestamp_log", |
122 |
); |
123 |
} |
124 |
|
125 |
function setType(&$form, $maj) { |
126 |
parent::setType($form, $maj); |
127 |
|
128 |
// Récupération du mode de l'action |
129 |
$crud = $this->get_action_crud($maj); |
130 |
|
131 |
// MODE CREER |
132 |
if ($maj == 0 || $crud == 'create') { |
133 |
$form->setType("state", "select"); |
134 |
$form->setType("stream", "select"); |
135 |
$form->setType("json_payload", "textarea"); |
136 |
} |
137 |
// MDOE MODIFIER |
138 |
if ($maj == 1 || $crud == 'update') { |
139 |
$form->setType("state", "select"); |
140 |
$form->setType("stream", "select"); |
141 |
$form->setType("json_payload", "jsonprettyprint"); |
142 |
} |
143 |
// MODE CONSULTER |
144 |
if ($maj == 3 || $crud == 'read') { |
145 |
$form->setType('dossier', 'link'); |
146 |
$form->setType('json_payload', 'jsonprettyprint'); |
147 |
} |
148 |
|
149 |
} |
150 |
|
151 |
/** |
152 |
* |
153 |
*/ |
154 |
function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) { |
155 |
if($maj < 2) { |
156 |
|
157 |
$contenu = array(); |
158 |
foreach(array('DRAFT', 'NEW', 'PENDING', 'DONE', 'ERROR', 'DEBUG') as $key) { |
159 |
$const_name = 'STATUS_'.$key; |
160 |
$const_value = constant("self::$const_name"); |
161 |
$contenu[0][] = $const_value; |
162 |
$contenu[1][] = __($const_value); |
163 |
} |
164 |
|
165 |
$form->setSelect("state", $contenu); |
166 |
|
167 |
$contenu_stream =array(); |
168 |
$contenu_stream[0][0]="input"; |
169 |
$contenu_stream[1][0]=_('input'); |
170 |
$contenu_stream[0][1]="output"; |
171 |
$contenu_stream[1][1]=_('output'); |
172 |
$form->setSelect("stream", $contenu_stream); |
173 |
|
174 |
} |
175 |
|
176 |
if ($maj == 3) { |
177 |
if ($this->getVal('stream') == 'output') { |
178 |
$inst_dossier = $this->f->get_inst__om_dbform(array( |
179 |
"obj" => "dossier", |
180 |
"idx" => $form->val['dossier'], |
181 |
)); |
182 |
|
183 |
if($form->val['type'] == "creation_DA"){ |
184 |
$obj_link = 'dossier_autorisation'; |
185 |
} else { |
186 |
$obj_link = 'dossier_instruction'; |
187 |
} |
188 |
|
189 |
$params = array(); |
190 |
$params['obj'] = $obj_link; |
191 |
$params['libelle'] = $inst_dossier->getVal('dossier'); |
192 |
$params['title'] = "Consulter le dossier"; |
193 |
$params['idx'] = $form->val['dossier']; |
194 |
$form->setSelect("dossier", $params); |
195 |
} |
196 |
} |
197 |
} |
198 |
|
199 |
/** |
200 |
* SETTER_FORM - setVal (setVal). |
201 |
* |
202 |
* @return void |
203 |
*/ |
204 |
function setVal(&$form, $maj, $validation, &$dnu1 = null, $dnu2 = null) { |
205 |
// parent::setVal($form, $maj, $validation); |
206 |
// |
207 |
if ($this->getVal('stream') == "output") { |
208 |
$form->setVal('json_payload', $this->view_form_json(true)); |
209 |
} else { |
210 |
$form->setVal('json_payload', htmlentities($this->getVal('json_payload'))); |
211 |
} |
212 |
} |
213 |
|
214 |
function setLib(&$form, $maj) { |
215 |
parent::setLib($form, $maj); |
216 |
|
217 |
// Récupération du mode de l'action |
218 |
$crud = $this->get_action_crud($maj); |
219 |
|
220 |
// MODE different de CREER |
221 |
if ($maj != 0 || $crud != 'create') { |
222 |
$form->setLib('json_payload', ''); |
223 |
} |
224 |
} |
225 |
|
226 |
public function verifier($val = array(), &$dnu1 = null, $dnu2 = null) { |
227 |
$ret = parent::verifier($val, $dnu1, $dnu2); |
228 |
|
229 |
// une tâche entrante doit avoir un type et une payload non-vide |
230 |
if (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') { |
231 |
if (isset($this->valF['type']) === false) { |
232 |
$this->correct = false; |
233 |
$this->addToMessage(sprintf( |
234 |
__("Le champ %s est obligatoire pour une tâche entrante."), |
235 |
sprintf('<span class="bold">%s</span>', $this->getLibFromField('type')) |
236 |
)); |
237 |
$this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE); |
238 |
} |
239 |
if (isset($this->valF['json_payload']) === false) { |
240 |
$this->correct = false; |
241 |
$this->addToMessage(sprintf( |
242 |
__("Le champ %s est obligatoire pour une tâche entrante."), |
243 |
sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload')) |
244 |
)); |
245 |
$this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE); |
246 |
} |
247 |
} |
248 |
|
249 |
// les JSONs doivent être décodables |
250 |
foreach(array('json_payload', 'timestamp_log') as $key) { |
251 |
if (isset($this->valF[$key]) && ! empty($this->valF[$key]) && ( |
252 |
is_array(json_decode($this->valF[$key], true)) === false |
253 |
|| json_last_error() !== JSON_ERROR_NONE)) { |
254 |
$this->correct = false; |
255 |
$champ_text = sprintf('<span class="bold">%s</span>', $this->getLibFromField($key)); |
256 |
$this->addToMessage(sprintf( |
257 |
__("Le champ %s doit être dans un format JSON valide (erreur: %s).". |
258 |
"<p>%s valF:</br><pre>%s</pre></p>". |
259 |
"<p>%s val:</br><pre>%s</pre></p>". |
260 |
"<p>%s POST:</br><pre>%s</pre></p>". |
261 |
"<p>%s submitted POST value:</br><pre>%s</pre></p>"), |
262 |
$champ_text, |
263 |
json_last_error() !== JSON_ERROR_NONE ? json_last_error_msg() : __('invalide'), |
264 |
$champ_text, |
265 |
$this->valF[$key], |
266 |
$champ_text, |
267 |
$val[$key], |
268 |
$champ_text, |
269 |
isset($_POST[$key]) ? $_POST[$key] : '', |
270 |
$champ_text, |
271 |
$this->f->get_submitted_post_value($key) |
272 |
)); |
273 |
$this->addToLog(__METHOD__.'(): erreur JSON: '.$this->msg, DEBUG_MODE); |
274 |
} |
275 |
} |
276 |
|
277 |
// une tâche entrante doit avoir une payload avec les clés requises |
278 |
if ($this->correct && (isset($this->valF['stream']) === false || |
279 |
$this->valF['stream'] == 'input')) { |
280 |
|
281 |
// décode la payload JSON |
282 |
$json_payload = json_decode($this->valF['json_payload'], true); |
283 |
|
284 |
// défini une liste de chemin de clés requises |
285 |
$paths = array( |
286 |
'external_uids/dossier' |
287 |
); |
288 |
|
289 |
// tâche de type création de DI/DA |
290 |
if (isset($this->valF['type']) !== false && $this->valF['type'] == 'create_DI_for_consultation') { |
291 |
|
292 |
$paths = array_merge($paths, array( |
293 |
'dossier/dossier', |
294 |
'dossier/dossier_autorisation_type_detaille_code', |
295 |
'dossier/date_demande', |
296 |
'dossier/depot_electronique', |
297 |
)); |
298 |
|
299 |
// si l'option commune est activée (mode MC) |
300 |
if ($this->f->is_option_dossier_commune_enabled()) { |
301 |
$paths[] = 'dossier/insee'; |
302 |
} |
303 |
|
304 |
// présence d'un moyen d'identifier la collectivité/le service |
305 |
if (! isset($json_payload['external_uids']['acteur']) && |
306 |
! isset($json_payload['dossier']['om_collectivite'])) { |
307 |
$this->correct = false; |
308 |
$this->addToMessage(sprintf( |
309 |
__("L'une des clés %s ou %s est obligatoire dans le contenu du champ %s pour une tâche entrante."), |
310 |
sprintf('<span class="bold">%s</span>', 'external_uids/acteur'), |
311 |
sprintf('<span class="bold">%s</span>', 'dossier/om_collectivite'), |
312 |
sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload')) |
313 |
)); |
314 |
$this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE); |
315 |
} |
316 |
} |
317 |
|
318 |
// pas d'erreur déjà trouvée |
319 |
if($this->correct) { |
320 |
|
321 |
// pour chaque chemin |
322 |
foreach($paths as $path) { |
323 |
|
324 |
// décompose le chemin |
325 |
$tokens = explode('/', $path); |
326 |
$cur_depth = $json_payload; |
327 |
|
328 |
// descend au et à mesure dans l'arborescence du chemin |
329 |
foreach($tokens as $token) { |
330 |
|
331 |
// en vérifiant que chaque élément du chemin est défini et non-nul |
332 |
if (isset($cur_depth[$token]) === false) { |
333 |
|
334 |
// sinon on produit une erreur |
335 |
$this->correct = false; |
336 |
$this->addToMessage(sprintf( |
337 |
__("La clé %s est obligatoire dans le contenu du champ %s pour une tâche entrante."), |
338 |
sprintf('<span class="bold">%s</span>', $path), |
339 |
sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload')) |
340 |
)); |
341 |
$this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE); |
342 |
break 2; |
343 |
} |
344 |
$cur_depth = $cur_depth[$token]; |
345 |
} |
346 |
} |
347 |
} |
348 |
} |
349 |
|
350 |
return $ret && $this->correct; |
351 |
} |
352 |
|
353 |
protected function task_exists(string $type, string $object_id) { |
354 |
$query = sprintf(' |
355 |
SELECT task |
356 |
FROM %1$stask |
357 |
WHERE state != \'%2$s\' |
358 |
AND type = \'%3$s\' |
359 |
AND object_id = \'%4$s\' |
360 |
', |
361 |
DB_PREFIXE, |
362 |
self::STATUS_DONE, |
363 |
$type, |
364 |
$object_id |
365 |
); |
366 |
$res = $this->f->get_one_result_from_db_query($query); |
367 |
if ($res['result'] !== null && $res['result'] !== '') { |
368 |
return $res['result']; |
369 |
} |
370 |
return false; |
371 |
} |
372 |
|
373 |
/** |
374 |
* TRIGGER - triggerajouter. |
375 |
* |
376 |
* @param string $id |
377 |
* @param null &$dnu1 @deprecated Ne pas utiliser. |
378 |
* @param array $val Tableau des valeurs brutes. |
379 |
* @param null $dnu2 @deprecated Ne pas utiliser. |
380 |
* |
381 |
* @return boolean |
382 |
*/ |
383 |
function triggerajouter($id, &$dnu1 = null, $val = array(), $dnu2 = null) { |
384 |
|
385 |
// tâche entrante |
386 |
if (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') { |
387 |
|
388 |
// décode la paylod JSON pour extraire les données métiers à ajouter |
389 |
// en tant que métadonnées de la tâche |
390 |
$json_payload = json_decode($this->valF['json_payload'], true); |
391 |
|
392 |
// si la tâche possède déjà une clé dossier |
393 |
if (isset($json_payload['dossier']['dossier']) && |
394 |
! empty($json_payload['dossier']['dossier'])) { |
395 |
$this->valF["dossier"] = $json_payload['dossier']['dossier']; |
396 |
} |
397 |
} |
398 |
} |
399 |
|
400 |
/** |
401 |
* TREATMENT - add_task |
402 |
* Ajoute un enregistrement. |
403 |
* |
404 |
* @param array $params Tableau des paramètres |
405 |
* @return boolean |
406 |
*/ |
407 |
public function add_task($params = array()) { |
408 |
$this->begin_treatment(__METHOD__); |
409 |
|
410 |
// Vérifie si la task doit être ajoutée en fonction du mode de l'application, |
411 |
// seulement pour les tasks output |
412 |
$task_types_si = array( |
413 |
'creation_DA', |
414 |
'creation_DI', |
415 |
'depot_DI', |
416 |
'modification_DI', |
417 |
'qualification_DI', |
418 |
'decision_DI', |
419 |
'incompletude_DI', |
420 |
'completude_DI', |
421 |
'ajout_piece', |
422 |
'add_piece', |
423 |
'creation_consultation', |
424 |
); |
425 |
$task_types_sc = array( |
426 |
'create_DI_for_consultation', |
427 |
'avis_consultation', |
428 |
'pec_metier_consultation', |
429 |
); |
430 |
$stream = isset($params['val']['stream']) === true ? $params['val']['stream'] : 'output'; |
431 |
if ($stream === 'output' |
432 |
&& isset($params['val']['type']) === true |
433 |
&& $this->f->is_option_mode_service_consulte_enabled() === true |
434 |
&& in_array($params['val']['type'], $task_types_sc) === false) { |
435 |
// |
436 |
return $this->end_treatment(__METHOD__, true); |
437 |
} |
438 |
if ($stream === 'output' |
439 |
&& isset($params['val']['type']) === true |
440 |
&& $this->f->is_option_mode_service_consulte_enabled() === false |
441 |
&& in_array($params['val']['type'], $task_types_si) === false) { |
442 |
// |
443 |
return $this->end_treatment(__METHOD__, true); |
444 |
} |
445 |
|
446 |
$timestamp_log = json_encode(array( |
447 |
'creation_date' => date('Y-m-d H:i:s'), |
448 |
)); |
449 |
|
450 |
// Si la tâche est de type ajout_piece et de stream input alors on ajoute le fichier |
451 |
// et on ajoute l'uid dans le champ json_payload avant l'ajout de la tâche |
452 |
if (isset($params['val']['type']) |
453 |
&& $params['val']['type'] == "add_piece" |
454 |
&& isset($params['val']['stream']) |
455 |
&& $params['val']['stream'] == "input" ) { |
456 |
// |
457 |
$json_payload = json_decode($params['val']['json_payload'], true); |
458 |
if (json_last_error() !== JSON_ERROR_NONE) { |
459 |
$this->addToMessage(__("Le contenu JSON de la tâche n'est pas valide.")); |
460 |
return $this->end_treatment(__METHOD__, false); |
461 |
} |
462 |
$document_numerise = $json_payload['document_numerise']; |
463 |
$file_content = base64_decode($document_numerise["file_content"]); |
464 |
if ($file_content === false){ |
465 |
$this->addToMessage(__("Le contenu du fichier lié à la tâche n'a pas pu etre recupere.")); |
466 |
return $this->end_treatment(__METHOD__, false); |
467 |
} |
468 |
$metadata = array( |
469 |
"filename" => $document_numerise['nom_fichier'], |
470 |
"size" => strlen($file_content), |
471 |
"mimetype" => $document_numerise['file_content_type'], |
472 |
"date_creation" => $document_numerise['date_creation'], |
473 |
); |
474 |
$uid_fichier = $this->f->storage->create($file_content, $metadata, "from_content"); |
475 |
if ($uid_fichier === OP_FAILURE) { |
476 |
$this->addToMessage(__("Erreur lors de la creation du fichier lié à la tâche.")); |
477 |
return $this->end_treatment(__METHOD__, false); |
478 |
} |
479 |
$json_payload["document_numerise"]["uid"] = $uid_fichier; |
480 |
// Le fichier a été ajouté nous n'avons plus besoin du champ file_content dans la payload |
481 |
unset($json_payload["document_numerise"]["file_content"]); |
482 |
$params['val']['json_payload'] = json_encode($json_payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
483 |
} |
484 |
|
485 |
// Mise à jour du DI |
486 |
$valF = array( |
487 |
'task' => '', |
488 |
'type' => $params['val']['type'], |
489 |
'timestamp_log' => $timestamp_log, |
490 |
'state' => isset($params['val']['state']) === true ? $params['val']['state'] : self::STATUS_NEW, |
491 |
'object_id' => isset($params['val']['object_id']) ? $params['val']['object_id'] : '', |
492 |
'dossier' => isset($params['val']['dossier']) ? $params['val']['dossier'] : '', |
493 |
'stream' => $stream, |
494 |
'json_payload' => isset($params['val']['json_payload']) === true ? $params['val']['json_payload'] : '{}', |
495 |
); |
496 |
|
497 |
// tâche sortante |
498 |
if($valF["stream"] == "output"){ |
499 |
|
500 |
// TODO expliquer ce code |
501 |
$task_exists = $this->task_exists($valF['type'], $valF['object_id']); |
502 |
if ($valF['type'] === 'modification_DI' && $task_exists === false) { |
503 |
$task_exists = $this->task_exists('creation_DI', $valF['object_id']); |
504 |
} |
505 |
if ($task_exists !== false) { |
506 |
$inst_task = $this->f->get_inst__om_dbform(array( |
507 |
"obj" => "task", |
508 |
"idx" => $task_exists, |
509 |
)); |
510 |
$update_state = $inst_task->getVal('state'); |
511 |
if (isset($params['update_val']['state']) === true) { |
512 |
$update_state = $params['update_val']['state']; |
513 |
} |
514 |
$update_params = array( |
515 |
'val' => array( |
516 |
'state' => $update_state, |
517 |
), |
518 |
); |
519 |
return $inst_task->update_task($update_params); |
520 |
} |
521 |
} |
522 |
|
523 |
$add = $this->ajouter($valF); |
524 |
$this->addToLog(__METHOD__."(): retour de l'ajout de tâche: ".var_export($add, true), VERBOSE_MODE); |
525 |
if ($add === false) { |
526 |
$this->addToLog(__METHOD__."(): ".$this->msg, DEBUG_MODE); |
527 |
return $this->end_treatment(__METHOD__, false); |
528 |
} |
529 |
return $this->end_treatment(__METHOD__, true); |
530 |
} |
531 |
|
532 |
/** |
533 |
* TREATMENT - update_task |
534 |
* Met à jour l'enregistrement instancié. |
535 |
* |
536 |
* @param array $params Tableau des paramètres |
537 |
* @return boolean |
538 |
*/ |
539 |
public function update_task($params = array()) { |
540 |
$this->begin_treatment(__METHOD__); |
541 |
$timestamp_log = $this->get_timestamp_log(); |
542 |
if ($timestamp_log === false) { |
543 |
$this->addToLog(__METHOD__."(): erreur timestamp log", DEBUG_MODE); |
544 |
return $this->end_treatment(__METHOD__, false); |
545 |
} |
546 |
array_push($timestamp_log, array( |
547 |
'modification_date' => date('Y-m-d H:i:s'), |
548 |
'state' => $params['val']['state'], |
549 |
'prev_state' => $this->getVal('state'), |
550 |
)); |
551 |
$timestamp_log = json_encode($timestamp_log); |
552 |
$valF = array( |
553 |
'task' => $this->getVal($this->clePrimaire), |
554 |
'type' => $this->getVal('type'), |
555 |
'timestamp_log' => $timestamp_log, |
556 |
'state' => $params['val']['state'], |
557 |
'object_id' => $this->getVal('object_id'), |
558 |
'stream' => $this->getVal('stream'), |
559 |
'dossier' => $this->getVal('dossier'), |
560 |
'json_payload' => $this->getVal('json_payload'), |
561 |
); |
562 |
$update = $this->modifier($valF); |
563 |
if ($update === false) { |
564 |
$this->addToLog($this->msg, DEBUG_MODE); |
565 |
return $this->end_treatment(__METHOD__, false); |
566 |
} |
567 |
return $this->end_treatment(__METHOD__, true); |
568 |
} |
569 |
|
570 |
/** |
571 |
* Récupère le journal d'horodatage dans le champ timestamp_log de |
572 |
* l'enregistrement instancié. |
573 |
* |
574 |
* @param array $params Tableau des paramètres |
575 |
* @return array sinon false en cas d'erreur |
576 |
*/ |
577 |
protected function get_timestamp_log($params = array()) { |
578 |
$val = $this->getVal('timestamp_log'); |
579 |
if ($val === '') { |
580 |
$val = json_encode(array()); |
581 |
} |
582 |
if($this->isJson($val) === false) { |
583 |
return false; |
584 |
} |
585 |
return json_decode($val, true); |
586 |
} |
587 |
|
588 |
/** |
589 |
* VIEW - view_json_data |
590 |
* Affiche l'enregistrement dans le format JSON. |
591 |
* |
592 |
* @return void |
593 |
*/ |
594 |
public function view_json_data() { |
595 |
$this->checkAccessibility(); |
596 |
$this->f->disableLog(); |
597 |
if ($this->getParameter('idx') !== ']' |
598 |
&& $this->getParameter('idx') !== '0') { |
599 |
// |
600 |
$this->view_form_json(); |
601 |
} |
602 |
else { |
603 |
$this->view_tab_json(); |
604 |
} |
605 |
} |
606 |
|
607 |
protected function view_tab_json() { |
608 |
$where = ''; |
609 |
if ($this->f->get_submitted_get_value('state') !== null |
610 |
&& $this->f->get_submitted_get_value('state') !== '') { |
611 |
// |
612 |
$where = sprintf(' WHERE state = \'%s\' ', $this->f->get_submitted_get_value('state')); |
613 |
} |
614 |
$query = sprintf(' |
615 |
SELECT |
616 |
* |
617 |
FROM %1$stask |
618 |
%2$s |
619 |
ORDER BY task ASC |
620 |
', |
621 |
DB_PREFIXE, |
622 |
$where |
623 |
); |
624 |
$res = $this->f->get_all_results_from_db_query($query, true); |
625 |
if ($res['code'] === 'KO') { |
626 |
return false; |
627 |
} |
628 |
$list_tasks = array(); |
629 |
foreach ($res['result'] as $task) { |
630 |
$task['timestamp_log'] = json_decode($task['timestamp_log'], true); |
631 |
$task['dossier'] = $task['dossier']; |
632 |
if ($task['type'] === 'ajout_piece') { |
633 |
$val_dn = $this->get_document_numerise_data($task['object_id']); |
634 |
} |
635 |
if ($task['stream'] === 'output') { |
636 |
$task['external_uids'] = $this->get_all_external_uids($task['dossier']); |
637 |
} |
638 |
$list_tasks[$task['task']] = $task; |
639 |
} |
640 |
printf(json_encode($list_tasks)); |
641 |
} |
642 |
|
643 |
protected function get_dossier_data(string $dossier) { |
644 |
$val_di = array(); |
645 |
$inst_di = $this->f->get_inst__om_dbform(array( |
646 |
"obj" => "dossier", |
647 |
"idx" => $dossier, |
648 |
)); |
649 |
$val_di = $inst_di->get_json_data(); |
650 |
if ($val_di['dossier_instruction_type_code'] === 'T') { |
651 |
$val_di['date_decision_transfert'] = $val_di['date_decision']; |
652 |
} |
653 |
unset($val_di['initial_dt']); |
654 |
unset($val_di['log_instructions']); |
655 |
return $val_di; |
656 |
} |
657 |
|
658 |
protected function get_dossier_autorisation_data(string $da) { |
659 |
$val_da = array(); |
660 |
$inst_da = $this->f->get_inst__om_dbform(array( |
661 |
"obj" => "dossier_autorisation", |
662 |
"idx" => $da, |
663 |
)); |
664 |
$val_da = $inst_da->get_json_data(); |
665 |
return $val_da; |
666 |
} |
667 |
|
668 |
protected function get_donnees_techniques_data(string $fk_idx, string $fk_field) { |
669 |
$val_dt = array(); |
670 |
$inst_dt = $this->f->get_inst__by_other_idx(array( |
671 |
"obj" => "donnees_techniques", |
672 |
"fk_field" => $fk_field, |
673 |
"fk_idx" => $fk_idx, |
674 |
)); |
675 |
$val_dt = array( |
676 |
'donnees_techniques' => $inst_dt->getVal($inst_dt->clePrimaire), |
677 |
'cerfa' => $inst_dt->getVal('cerfa'), |
678 |
); |
679 |
$val_dt = array_merge($val_dt, $inst_dt->get_donnees_techniques_applicables()); |
680 |
if (isset($val_dt['am_exist_date']) === true) { |
681 |
$val_dt['am_exist_date_num'] = ''; |
682 |
if (is_numeric($val_dt['am_exist_date']) === true) { |
683 |
$val_dt['am_exist_date_num'] = $val_dt['am_exist_date']; |
684 |
} |
685 |
} |
686 |
// Correspond à la nomenclature de Plat'AU STATUT_INFO |
687 |
$val_dt['tax_statut_info'] = 'Déclaré'; |
688 |
// |
689 |
if ($inst_dt->is_tab_surf_ssdest_enabled() === true) { |
690 |
$fields_tab_surf_dest = $inst_dt->get_fields_tab_surf_dest(); |
691 |
foreach ($fields_tab_surf_dest as $field) { |
692 |
if (isset($val_dt[$field]) === true) { |
693 |
unset($val_dt[$field]); |
694 |
} |
695 |
} |
696 |
} else { |
697 |
$fields_tab_surf_ssdest = $inst_dt->get_fields_tab_surf_ssdest(); |
698 |
foreach ($fields_tab_surf_ssdest as $field) { |
699 |
if (isset($val_dt[$field]) === true) { |
700 |
unset($val_dt[$field]); |
701 |
} |
702 |
} |
703 |
} |
704 |
// Correspond à la nouvelle ligne CERFA v7 dans le DENSI imposition 1.2.3 |
705 |
if (isset($val_dt['tax_su_non_habit_surf2']) === true |
706 |
&& isset($val_dt['tax_su_non_habit_surf3']) === true |
707 |
&& (($val_dt['tax_su_non_habit_surf2'] !== null |
708 |
&& $val_dt['tax_su_non_habit_surf2'] !== '') |
709 |
|| ($val_dt['tax_su_non_habit_surf3'] !== null |
710 |
&& $val_dt['tax_su_non_habit_surf3'] !== ''))) { |
711 |
// |
712 |
$val_dt['tax_su_non_habit_surf8'] = intval($val_dt['tax_su_non_habit_surf2']) + intval($val_dt['tax_su_non_habit_surf3']); |
713 |
} |
714 |
if (isset($val_dt['tax_su_non_habit_surf_stat2']) === true |
715 |
&& isset($val_dt['tax_su_non_habit_surf_stat3']) === true |
716 |
&& (($val_dt['tax_su_non_habit_surf_stat2'] !== null |
717 |
&& $val_dt['tax_su_non_habit_surf_stat2'] !== '') |
718 |
|| ($val_dt['tax_su_non_habit_surf_stat3'] !== null |
719 |
&& $val_dt['tax_su_non_habit_surf_stat3'] !== ''))) { |
720 |
// |
721 |
$val_dt['tax_su_non_habit_surf_stat8'] = intval($val_dt['tax_su_non_habit_surf_stat2']) + intval($val_dt['tax_su_non_habit_surf_stat3']); |
722 |
} |
723 |
// Cas particulier d'un projet réduit à l'extension d'une habitation existante |
724 |
$particular_case = false; |
725 |
$fields_tab_crea_loc_hab = $inst_dt->get_fields_tab_crea_loc_hab(); |
726 |
foreach ($fields_tab_crea_loc_hab as $field) { |
727 |
if (isset($val_dt[$field]) === false |
728 |
|| (isset($val_dt[$field]) === true |
729 |
&& ($val_dt[$field] === null |
730 |
|| $val_dt[$field] === ''))) { |
731 |
// |
732 |
$particular_case = true; |
733 |
} |
734 |
} |
735 |
if ($particular_case === true) { |
736 |
if (isset($val_dt['tax_ext_pret']) === true |
737 |
&& $val_dt['tax_ext_pret'] === 'f') { |
738 |
// |
739 |
$val_dt['tax_su_princ_surf1'] = $val_dt['tax_surf_tot_cstr']; |
740 |
$val_dt['tax_su_princ_surf_stat1'] = $val_dt['tax_surf_loc_stat']; |
741 |
} |
742 |
if (isset($val_dt['tax_ext_pret']) === true |
743 |
&& $val_dt['tax_ext_pret'] === 't') { |
744 |
// |
745 |
if (isset($val_dt['tax_ext_desc']) === true) { |
746 |
if (preg_match('/[pP].*[lL].*[aA].*[iI]/', $val_dt['tax_ext_desc']) === 1 |
747 |
|| preg_match('/[lL].*[lL].*[tT].*[sS]/', $val_dt['tax_ext_desc']) === 1) { |
748 |
// |
749 |
$val_dt['tax_su_princ_surf2'] = $val_dt['tax_surf_tot_cstr']; |
750 |
$val_dt['tax_su_princ_surf_stat2'] = $val_dt['tax_surf_loc_stat']; |
751 |
} |
752 |
// if (preg_match('/[pP].*[tT].*[zZ]/', $val_dt['tax_ext_desc']) === 1) { |
753 |
// $val_dt['tax_su_princ_surf4'] = $val_dt['tax_surf_tot_cstr']; |
754 |
// $val_dt['tax_su_princ_surf_stat4'] = $val_dt['tax_surf_loc_stat']; |
755 |
// } |
756 |
// if (preg_match('/[pP].*[lL].*[uU].*[sS]/', $val_dt['tax_ext_desc']) === 1 |
757 |
// || preg_match('/[lL].*[eE].*[sS]/', $val_dt['tax_ext_desc']) === 1 |
758 |
// || preg_match('/[pP].*[sS].*[lL].*[aA]/', $val_dt['tax_ext_desc']) === 1 |
759 |
// || preg_match('/[pP].*[lL].*[sS]/', $val_dt['tax_ext_desc']) === 1 |
760 |
// || preg_match('/[lL].*[lL].*[sS]/', $val_dt['tax_ext_desc']) === 1) { |
761 |
// // |
762 |
// $val_dt['tax_su_princ_surf3'] = $val_dt['tax_surf_tot_cstr']; |
763 |
// $val_dt['tax_su_princ_surf_stat3'] = $val_dt['tax_surf_loc_stat']; |
764 |
// } |
765 |
} |
766 |
} |
767 |
} |
768 |
// Cas particulier de la surface taxable démolie |
769 |
if (isset($val_dt['tax_surf_tot_demo']) === true |
770 |
&& isset($val_dt['tax_surf_tax_demo']) === true |
771 |
&& ($val_dt['tax_surf_tot_demo'] === null |
772 |
|| $val_dt['tax_surf_tot_demo'] === '')) { |
773 |
// |
774 |
$val_dt['tax_surf_tot_demo'] = $val_dt['tax_surf_tax_demo']; |
775 |
} |
776 |
return $val_dt; |
777 |
} |
778 |
|
779 |
/** |
780 |
* Récupère la liste des objets distincts existants dans la table des liens |
781 |
* entre identifiants internes et identifiants externes. |
782 |
* |
783 |
* @return array |
784 |
*/ |
785 |
protected function get_list_distinct_objects_external_link() { |
786 |
$query = sprintf(' |
787 |
SELECT |
788 |
DISTINCT(object) |
789 |
FROM %1$slien_id_interne_uid_externe |
790 |
ORDER BY object ASC |
791 |
', |
792 |
DB_PREFIXE |
793 |
); |
794 |
$res = $this->f->get_all_results_from_db_query($query, true); |
795 |
if ($res['code'] === 'KO') { |
796 |
return array(); |
797 |
} |
798 |
$result = array(); |
799 |
foreach ($res['result'] as $object) { |
800 |
$result[] = $object['object']; |
801 |
} |
802 |
return $result; |
803 |
} |
804 |
|
805 |
protected function get_external_uid($fk_idx, string $fk_idx_2) { |
806 |
$inst_external_uid = $this->f->get_inst__by_other_idx(array( |
807 |
"obj" => "lien_id_interne_uid_externe", |
808 |
"fk_field" => 'object_id', |
809 |
"fk_idx" => $fk_idx, |
810 |
"fk_field_2" => 'object', |
811 |
"fk_idx_2" => $fk_idx_2, |
812 |
)); |
813 |
return $inst_external_uid->getVal('external_uid'); |
814 |
} |
815 |
|
816 |
protected function get_all_external_uids($fk_idx, $link_objects = array()) { |
817 |
if (count($link_objects) == 0) { |
818 |
$link_objects = $this->get_list_distinct_objects_external_link(); |
819 |
} |
820 |
$val_external_uid = array(); |
821 |
foreach ($link_objects as $link_object) { |
822 |
$external_uid = $this->get_external_uid($fk_idx, $link_object); |
823 |
if ($external_uid !== '' && $external_uid !== null) { |
824 |
$val_external_uid[$link_object] = $external_uid; |
825 |
} |
826 |
} |
827 |
return $val_external_uid; |
828 |
} |
829 |
|
830 |
protected function get_demandeurs_data(string $dossier) { |
831 |
$val_demandeur = array(); |
832 |
$inst_di = $this->f->get_inst__om_dbform(array( |
833 |
"obj" => "dossier", |
834 |
"idx" => $dossier, |
835 |
)); |
836 |
$list_demandeurs = $inst_di->get_demandeurs(); |
837 |
foreach ($list_demandeurs as $demandeur) { |
838 |
$inst_demandeur = $this->f->get_inst__om_dbform(array( |
839 |
"obj" => "demandeur", |
840 |
"idx" => $demandeur['demandeur'], |
841 |
)); |
842 |
$val_demandeur[$demandeur['demandeur']] = $inst_demandeur->get_json_data(); |
843 |
$val_demandeur[$demandeur['demandeur']]['petitionnaire_principal'] = $demandeur['petitionnaire_principal']; |
844 |
} |
845 |
return $val_demandeur; |
846 |
} |
847 |
|
848 |
protected function get_architecte_data($architecte = null) { |
849 |
$val_architecte = null; |
850 |
if ($architecte !== null |
851 |
&& $architecte !== '') { |
852 |
// |
853 |
$inst_architecte = $this->f->get_inst__om_dbform(array( |
854 |
"obj" => "architecte", |
855 |
"idx" => $architecte, |
856 |
)); |
857 |
$val_architecte = $inst_architecte->get_json_data(); |
858 |
} |
859 |
return $val_architecte; |
860 |
} |
861 |
|
862 |
protected function get_instruction_data(string $dossier, $type = 'decision', $extra_params = array()) { |
863 |
$val_instruction = null; |
864 |
$instruction_with_doc = null; |
865 |
$inst_di = $this->f->get_inst__om_dbform(array( |
866 |
"obj" => "dossier", |
867 |
"idx" => $dossier, |
868 |
)); |
869 |
$idx = null; |
870 |
if ($type === 'decision') { |
871 |
$idx = $inst_di->get_last_instruction_decision(); |
872 |
} |
873 |
if ($type === 'incompletude') { |
874 |
$idx = $inst_di->get_last_instruction_incompletude(); |
875 |
} |
876 |
// XXX Permet de récupérer l'instruction par son identifiant |
877 |
if ($type === 'with-id') { |
878 |
$idx = $extra_params['with-id']; |
879 |
} |
880 |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
881 |
"obj" => "instruction", |
882 |
"idx" => $idx, |
883 |
)); |
884 |
if (count($inst_instruction->val) > 0) { |
885 |
$val_instruction = array(); |
886 |
$instruction_data = $inst_instruction->get_json_data(); |
887 |
$val_instruction = $this->sort_instruction_data($instruction_data, $val_instruction); |
888 |
if ($instruction_data['om_fichier_instruction'] !== null |
889 |
&& $instruction_data['om_fichier_instruction'] !== '') { |
890 |
// |
891 |
$instruction_with_doc = $inst_instruction->getVal($inst_instruction->clePrimaire); |
892 |
} |
893 |
$inst_ev = $this->f->get_inst__om_dbform(array( |
894 |
"obj" => "evenement", |
895 |
"idx" => $inst_instruction->getVal('evenement'), |
896 |
)); |
897 |
if ($inst_ev->getVal('retour') === 't') { |
898 |
$instructions_related = $inst_instruction->get_related_instructions(); |
899 |
foreach ($instructions_related as $instruction) { |
900 |
if ($instruction !== null && $instruction !== '') { |
901 |
$inst_related_instruction = $this->f->get_inst__om_dbform(array( |
902 |
"obj" => "instruction", |
903 |
"idx" => $instruction, |
904 |
)); |
905 |
$instruction_data = $inst_related_instruction->get_json_data(); |
906 |
$val_instruction = $this->sort_instruction_data($instruction_data, $val_instruction); |
907 |
if ($instruction_data['om_fichier_instruction'] !== null |
908 |
&& $instruction_data['om_fichier_instruction'] !== '') { |
909 |
// |
910 |
$instruction_with_doc = $inst_related_instruction->getVal($inst_related_instruction->clePrimaire); |
911 |
} |
912 |
} |
913 |
} |
914 |
} |
915 |
if ($instruction_with_doc !== null) { |
916 |
// |
917 |
$val_instruction['path'] = sprintf('%s&snippet=%s&obj=%s&champ=%s&id=%s', 'app/index.php?module=form', 'file', 'instruction', 'om_fichier_instruction', $instruction_with_doc); |
918 |
} |
919 |
} |
920 |
return $val_instruction; |
921 |
} |
922 |
|
923 |
protected function sort_instruction_data(array $values, array $res) { |
924 |
$fields = array( |
925 |
"date_evenement", |
926 |
"date_envoi_signature", |
927 |
"date_retour_signature", |
928 |
"date_envoi_rar", |
929 |
"date_retour_rar", |
930 |
"date_envoi_controle_legalite", |
931 |
"date_retour_controle_legalite", |
932 |
"signataire_arrete", |
933 |
"om_fichier_instruction", |
934 |
"tacite", |
935 |
"lettretype", |
936 |
); |
937 |
foreach ($values as $key => $value) { |
938 |
if (in_array($key, $fields) === true) { |
939 |
if (array_key_exists($key, $res) === false |
940 |
&& $value !== null |
941 |
&& $value !== '') { |
942 |
// |
943 |
$res[$key] = $value; |
944 |
} elseif ($key === 'tacite' |
945 |
&& $value === 't') { |
946 |
// |
947 |
$res[$key] = $value; |
948 |
} |
949 |
} |
950 |
} |
951 |
return $res; |
952 |
} |
953 |
|
954 |
protected function get_document_numerise_data(string $dn) { |
955 |
$val_dn = array(); |
956 |
$inst_dn = $this->f->get_inst__om_dbform(array( |
957 |
"obj" => "document_numerise", |
958 |
"idx" => $dn, |
959 |
)); |
960 |
$val_dn = $inst_dn->get_json_data(); |
961 |
$val_dn['path'] = sprintf('%s&snippet=%s&obj=%s&champ=%s&id=%s', 'app/index.php?module=form', 'file', 'document_numerise', 'uid', $this->getVal('object_id')); |
962 |
// Correspond à la nomenclature Plat'AU NATURE_PIECE |
963 |
$val_dn['nature'] = $val_dn['document_numerise_nature_libelle']; |
964 |
return $val_dn; |
965 |
} |
966 |
|
967 |
protected function get_parcelles_data(string $object, string $idx) { |
968 |
$val_dp = array(); |
969 |
$inst_di = $this->f->get_inst__om_dbform(array( |
970 |
"obj" => $object, |
971 |
"idx" => $idx, |
972 |
)); |
973 |
$list_parcelles = $inst_di->get_parcelles(); |
974 |
$no_ordre = 1; |
975 |
foreach ($list_parcelles as $parcelle) { |
976 |
$val_dp[$parcelle[$object.'_parcelle']] = array( |
977 |
$object.'_parcelle' => $parcelle[$object.'_parcelle'], |
978 |
'libelle' => $parcelle['libelle'], |
979 |
'no_ordre' => $no_ordre, |
980 |
); |
981 |
$no_ordre++; |
982 |
} |
983 |
return $val_dp; |
984 |
} |
985 |
|
986 |
protected function get_avis_decision_data(string $dossier) { |
987 |
$inst_di = $this->f->get_inst__om_dbform(array( |
988 |
"obj" => "dossier", |
989 |
"idx" => $dossier, |
990 |
)); |
991 |
$ad = $inst_di->getVal('avis_decision'); |
992 |
$val_ad = array(); |
993 |
$inst_ad = $this->f->get_inst__om_dbform(array( |
994 |
"obj" => "avis_decision", |
995 |
"idx" => $ad, |
996 |
)); |
997 |
$val_ad = $inst_ad->get_json_data(); |
998 |
$val_ad['txAvis'] = "Voir document joint"; |
999 |
if (isset($val_ad['tacite']) === true |
1000 |
&& $val_ad['tacite'] === 't') { |
1001 |
// |
1002 |
$val_ad['txAvis'] = "Sans objet"; |
1003 |
} |
1004 |
return $val_ad; |
1005 |
} |
1006 |
|
1007 |
protected function get_signataire_arrete_data(string $sa) { |
1008 |
$inst_sa = $this->f->get_inst__om_dbform(array( |
1009 |
"obj" => "signataire_arrete", |
1010 |
"idx" => $sa, |
1011 |
)); |
1012 |
$val_sa = array_combine($inst_sa->champs, $inst_sa->val); |
1013 |
foreach ($val_sa as $key => $value) { |
1014 |
$val_sa[$key] = strip_tags($value); |
1015 |
} |
1016 |
return $val_sa; |
1017 |
} |
1018 |
|
1019 |
// XXX WIP |
1020 |
protected function get_consultation_data(string $consultation) { |
1021 |
$val_consultation = array(); |
1022 |
$inst_consultation = $this->f->get_inst__om_dbform(array( |
1023 |
"obj" => "consultation", |
1024 |
"idx" => $consultation, |
1025 |
)); |
1026 |
$val_consultation = $inst_consultation->get_json_data(); |
1027 |
$val_consultation['path_fichier'] = sprintf('%s&snippet=%s&obj=%s&champ=%s&id=%s', 'app/index.php?module=form', 'file', 'consultation', 'fichier', $this->getVal('object_id')); |
1028 |
$val_consultation['path_om_fichier_consultation'] = sprintf('%s&snippet=%s&obj=%s&champ=%s&id=%s', 'app/index.php?module=form', 'file', 'consultation', 'om_fichier_consultation', $this->getVal('object_id')); |
1029 |
return $val_consultation; |
1030 |
} |
1031 |
|
1032 |
// XXX WIP |
1033 |
protected function get_service_data(string $service) { |
1034 |
$val_service = array(); |
1035 |
$inst_service = $this->f->get_inst__om_dbform(array( |
1036 |
"obj" => "service", |
1037 |
"idx" => $service, |
1038 |
)); |
1039 |
$val_service = $inst_service->get_json_data(); |
1040 |
return $val_service; |
1041 |
} |
1042 |
|
1043 |
protected function view_form_json($in_field = false) { |
1044 |
// |
1045 |
if ($this->f->get_submitted_post_value('valid') === null) { |
1046 |
// Liste des valeurs à afficher |
1047 |
$val = array(); |
1048 |
// |
1049 |
$val_task = array_combine($this->champs, $this->val); |
1050 |
foreach ($val_task as $key => $value) { |
1051 |
$val_task[$key] = strip_tags($value); |
1052 |
} |
1053 |
$val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true); |
1054 |
$val['task'] = $val_task; |
1055 |
// |
1056 |
if ($this->getVal('type') === 'creation_DA') { |
1057 |
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id')); |
1058 |
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation'); |
1059 |
$val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']); |
1060 |
$val_external_uid = array(); |
1061 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation'); |
1062 |
$val['external_uids'] = $val_external_uid; |
1063 |
} |
1064 |
// |
1065 |
if ($this->getVal('type') === 'creation_DI' |
1066 |
|| $this->getVal('type') === 'modification_DI' |
1067 |
|| $this->getVal('type') === 'depot_DI') { |
1068 |
// |
1069 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
1070 |
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_instruction'); |
1071 |
$val['demandeur'] = $this->get_demandeurs_data($val['dossier']['dossier']); |
1072 |
$architecte = isset($val['donnees_techniques']['architecte']) === true ? $val['donnees_techniques']['architecte'] : null; |
1073 |
$val['architecte'] = $this->get_architecte_data($architecte); |
1074 |
$val['dossier_parcelle'] = $this->get_parcelles_data('dossier', $val['dossier']['dossier']); |
1075 |
$val_external_uid = array(); |
1076 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1077 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1078 |
$val['external_uids'] = $val_external_uid; |
1079 |
} |
1080 |
// |
1081 |
if ($this->getVal('type') === 'qualification_DI') { |
1082 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
1083 |
$val_external_uid = array(); |
1084 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1085 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1086 |
$val['external_uids'] = $val_external_uid; |
1087 |
} |
1088 |
// |
1089 |
if ($this->getVal('type') === 'ajout_piece') { |
1090 |
$val['document_numerise'] = $this->get_document_numerise_data($this->getVal('object_id')); |
1091 |
$val['dossier'] = $this->get_dossier_data($val['document_numerise']['dossier']); |
1092 |
$val_external_uid = array(); |
1093 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1094 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1095 |
$val_external_uid['document_numerise'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'document_numerise'); |
1096 |
$val['external_uids'] = $val_external_uid; |
1097 |
} |
1098 |
// |
1099 |
if ($this->getVal('type') === 'decision_DI') { |
1100 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1101 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1102 |
$val_external_uid = array(); |
1103 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1104 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1105 |
$val['external_uids'] = $val_external_uid; |
1106 |
} |
1107 |
// |
1108 |
if ($this->getVal('type') === 'incompletude_DI') { |
1109 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1110 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1111 |
$val_external_uid = array(); |
1112 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1113 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1114 |
$val['external_uids'] = $val_external_uid; |
1115 |
} |
1116 |
// |
1117 |
if ($this->getVal('type') === 'completude_DI') { |
1118 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1119 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1120 |
$val_external_uid = array(); |
1121 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1122 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1123 |
$val['external_uids'] = $val_external_uid; |
1124 |
} |
1125 |
// |
1126 |
if ($this->getVal('type') === 'pec_metier_consultation') { |
1127 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1128 |
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1129 |
$val_external_uid = array(); |
1130 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1131 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1132 |
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
1133 |
$val['external_uids'] = $val_external_uid; |
1134 |
} |
1135 |
// |
1136 |
if ($this->getVal('type') === 'avis_consultation') { |
1137 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1138 |
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1139 |
$val['avis_decision'] = $this->get_avis_decision_data($this->getVal('dossier')); |
1140 |
if (isset($val['instruction']['signataire_arrete']) === true) { |
1141 |
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
1142 |
} |
1143 |
$val_external_uid = array(); |
1144 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1145 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1146 |
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
1147 |
$val['external_uids'] = $val_external_uid; |
1148 |
} |
1149 |
// XXX WIP |
1150 |
if ($this->getVal('type') === 'creation_consultation') { |
1151 |
// |
1152 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1153 |
$val['consultation'] = $this->get_consultation_data($this->getVal('object_id')); |
1154 |
$val['service'] = $this->get_service_data($val['consultation']['service']); |
1155 |
$val_external_uid = array(); |
1156 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1157 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1158 |
$val['external_uids'] = $val_external_uid; |
1159 |
} |
1160 |
|
1161 |
if ($in_field === true) { |
1162 |
return json_encode($val, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
1163 |
} else { |
1164 |
// Liste des valeurs affichée en JSON |
1165 |
printf(json_encode($val, JSON_UNESCAPED_SLASHES)); |
1166 |
} |
1167 |
} |
1168 |
} |
1169 |
|
1170 |
function post_update_task() { |
1171 |
// Mise à jour des valeurs |
1172 |
|
1173 |
// Modification de l'état de la tâche |
1174 |
if ($this->f->get_submitted_post_value('state') !== null) { |
1175 |
$params = array( |
1176 |
'val' => array( |
1177 |
'state' => $this->f->get_submitted_post_value('state') |
1178 |
), |
1179 |
); |
1180 |
$update = $this->update_task($params); |
1181 |
$message_class = "valid"; |
1182 |
$message = $this->msg; |
1183 |
if ($update === false) { |
1184 |
$this->addToLog($this->msg, DEBUG_MODE); |
1185 |
$message_class = "error"; |
1186 |
$message = sprintf( |
1187 |
'%s %s', |
1188 |
__('Impossible de mettre à jour la tâche.'), |
1189 |
__('Veuillez contacter votre administrateur.') |
1190 |
); |
1191 |
} |
1192 |
$this->f->displayMessage($message_class, $message); |
1193 |
} |
1194 |
|
1195 |
// Sauvegarde de l'uid externe retourné |
1196 |
if ($this->f->get_submitted_post_value('external_uid') !== null) { |
1197 |
// |
1198 |
$objects = $this->get_objects_by_task_type($this->getVal('type'), $this->getVal('stream')); |
1199 |
foreach ($objects as $object) { |
1200 |
$inst_lien = $this->f->get_inst__om_dbform(array( |
1201 |
"obj" => "lien_id_interne_uid_externe", |
1202 |
"idx" => ']', |
1203 |
)); |
1204 |
if ($inst_lien->is_exists($object, $this->getVal('object_id'), $this->f->get_submitted_post_value('external_uid'), $this->getVal('dossier')) === false) { |
1205 |
$valF = array( |
1206 |
'lien_id_interne_uid_externe' => '', |
1207 |
'object' => $object, |
1208 |
'object_id' => $this->getVal('object_id'), |
1209 |
'external_uid' => $this->f->get_submitted_post_value('external_uid'), |
1210 |
'dossier' => $this->getVal('dossier'), |
1211 |
); |
1212 |
$add = $inst_lien->ajouter($valF); |
1213 |
$message_class = "valid"; |
1214 |
$message = $inst_lien->msg; |
1215 |
if ($add === false) { |
1216 |
$this->addToLog($inst_lien->msg, DEBUG_MODE); |
1217 |
$message_class = "error"; |
1218 |
$message = sprintf( |
1219 |
'%s %s', |
1220 |
__("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."), |
1221 |
__('Veuillez contacter votre administrateur.') |
1222 |
); |
1223 |
} |
1224 |
$this->f->displayMessage($message_class, $message); |
1225 |
} |
1226 |
} |
1227 |
} |
1228 |
} |
1229 |
|
1230 |
function post_add_task() { |
1231 |
// TODO Tester de remplacer la ligne de json_payload par un $_POST |
1232 |
$result = $this->add_task(array( |
1233 |
'val' => array( |
1234 |
'stream' => 'input', |
1235 |
'json_payload' => html_entity_decode($this->f->get_submitted_post_value('json_payload')), |
1236 |
'type' => $this->f->get_submitted_post_value('type'), |
1237 |
) |
1238 |
)); |
1239 |
$message = sprintf( |
1240 |
__("Tâche %s ajoutée avec succès"), |
1241 |
$this->getVal($this->clePrimaire)). |
1242 |
'<br/><br/>'. |
1243 |
$this->msg; |
1244 |
$message_class = "valid"; |
1245 |
if ($result === false){ |
1246 |
$this->addToLog($this->msg, DEBUG_MODE); |
1247 |
$message_class = "error"; |
1248 |
$message = sprintf( |
1249 |
'%s %s', |
1250 |
__('Impossible d\'ajouter la tâche.'), |
1251 |
__('Veuillez contacter votre administrateur.') |
1252 |
); |
1253 |
} |
1254 |
$this->f->displayMessage($message_class, $message); |
1255 |
} |
1256 |
|
1257 |
function setLayout(&$form, $maj) { |
1258 |
|
1259 |
// Récupération du mode de l'action |
1260 |
$crud = $this->get_action_crud($maj); |
1261 |
|
1262 |
// MODE different de CREER |
1263 |
if ($maj != 0 || $crud != 'create') { |
1264 |
$form->setBloc('json_payload', 'D', '', 'col_6'); |
1265 |
$form->setFieldset('json_payload', 'DF', __("json_payload"), "collapsible, startClosed"); |
1266 |
$form->setBloc('json_payload', 'F'); |
1267 |
} |
1268 |
$form->setBloc('timestamp_log', 'DF', '', 'col_9'); |
1269 |
} |
1270 |
|
1271 |
/** |
1272 |
* [get_objects_by_task_type description] |
1273 |
* @param [type] $type [description] |
1274 |
* @return [type] [description] |
1275 |
*/ |
1276 |
function get_objects_by_task_type($type, $stream = 'all') { |
1277 |
$objects = array(); |
1278 |
if (in_array($type, array('creation_DA', )) === true) { |
1279 |
$objects = array('dossier_autorisation', ); |
1280 |
} |
1281 |
if (in_array($type, array('creation_DI', 'depot_DI', 'notification_DI', 'qualification_DI', )) === true) { |
1282 |
$objects = array('dossier', ); |
1283 |
} |
1284 |
if (in_array($type, array('create_DI_for_consultation', )) === true) { |
1285 |
$objects = array('dossier', 'dossier_consultation', ); |
1286 |
} |
1287 |
if (in_array($type, array('decision_DI', 'incompletude_DI', 'completude_DI', )) === true) { |
1288 |
$objects = array('instruction', ); |
1289 |
} |
1290 |
if (in_array($type, array('pec_metier_consultation', )) === true |
1291 |
&& $stream === 'output') { |
1292 |
$objects = array('pec_dossier_consultation', ); |
1293 |
} |
1294 |
if (in_array($type, array('avis_consultation', )) === true |
1295 |
&& $stream === 'output') { |
1296 |
$objects = array('avis_dossier_consultation', ); |
1297 |
} |
1298 |
if (in_array($type, array('ajout_piece', 'add_piece', )) === true) { |
1299 |
$objects = array('piece', ); |
1300 |
} |
1301 |
if (in_array($type, array('creation_consultation', )) === true) { |
1302 |
$objects = array('consultation', ); |
1303 |
} |
1304 |
if (in_array($type, array('pec_metier_consultation', 'avis_consultation', )) === true |
1305 |
&& $stream === 'input') { |
1306 |
$objects = array('consultation', ); |
1307 |
} |
1308 |
return $objects; |
1309 |
} |
1310 |
|
1311 |
} |