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 |
const STATUS_CANCELED = 'canceled'; |
17 |
|
18 |
/** |
19 |
* Liste des types de tâche concernant les services instructeurs |
20 |
*/ |
21 |
const TASK_TYPE_SI = array( |
22 |
'creation_DA', |
23 |
'creation_DI', |
24 |
'depot_DI', |
25 |
'modification_DI', |
26 |
'qualification_DI', |
27 |
'decision_DI', |
28 |
'incompletude_DI', |
29 |
'completude_DI', |
30 |
'ajout_piece', |
31 |
'add_piece', |
32 |
'creation_consultation', |
33 |
'modification_DA', |
34 |
'create_DI', |
35 |
'envoi_CL', |
36 |
'notification_recepisse', |
37 |
'notification_instruction', |
38 |
'notification_decision', |
39 |
'notification_service_consulte', |
40 |
'notification_tiers_consulte', |
41 |
'notification_depot_demat', |
42 |
'notification_commune' |
43 |
); |
44 |
|
45 |
/** |
46 |
* Liste des types de tâche concernant les services consultés |
47 |
*/ |
48 |
const TASK_TYPE_SC = array( |
49 |
'create_DI_for_consultation', |
50 |
'avis_consultation', |
51 |
'pec_metier_consultation', |
52 |
'create_message', |
53 |
'notification_recepisse', |
54 |
'notification_instruction', |
55 |
'notification_decision', |
56 |
'notification_service_consulte', |
57 |
'notification_tiers_consulte', |
58 |
'notification_depot_demat', |
59 |
'prescription', |
60 |
); |
61 |
|
62 |
/** |
63 |
* Catégorie de la tâche |
64 |
*/ |
65 |
var $category = PLATAU; |
66 |
|
67 |
/** |
68 |
* Définition des actions disponibles sur la classe. |
69 |
* |
70 |
* @return void |
71 |
*/ |
72 |
public function init_class_actions() { |
73 |
parent::init_class_actions(); |
74 |
// |
75 |
$this->class_actions[998] = array( |
76 |
"identifier" => "json_data", |
77 |
"view" => "view_json_data", |
78 |
"permission_suffix" => "consulter", |
79 |
); |
80 |
$this->class_actions[997] = array( |
81 |
"identifier" => "json_data", |
82 |
"view" => "post_update_task", |
83 |
"permission_suffix" => "modifier", |
84 |
); |
85 |
$this->class_actions[996] = array( |
86 |
"identifier" => "json_data", |
87 |
"view" => "post_add_task", |
88 |
"permission_suffix" => "ajouter", |
89 |
); |
90 |
} |
91 |
|
92 |
public function setvalF($val = array()) { |
93 |
|
94 |
// // les guillets doubles sont remplacés automatiquement par des simples |
95 |
// // dans core/om_formulaire.clasS.php::recupererPostvar() |
96 |
// // voir le ticket https://dev.atreal.fr/projets/openmairie/tracker/209 |
97 |
// // ceci est un hack sale temporaire en attendant résolution du ticket |
98 |
// foreach(array('json_payload', 'timestamp_log') as $key) { |
99 |
// if (isset($val[$key]) && ! empty($val[$key]) && |
100 |
// isset($_POST[$key]) && ! empty($_POST[$key])) { |
101 |
// $submited_payload = $_POST[$key]; |
102 |
// if (! empty($submited_payload)) { |
103 |
// $new_payload = str_replace("'", '"', $val[$key]); |
104 |
// if ($new_payload == $submited_payload || |
105 |
// strpos($submited_payload, '"') === false) { |
106 |
// $val[$key] = $new_payload; |
107 |
// } |
108 |
// else { |
109 |
// $error_msg = sprintf( |
110 |
// __("La convertion des guillemets de la payload JSON '%s' ". |
111 |
// "n'est pas idempotente (courante: %s, postée: %s, convertie: %s)"), |
112 |
// $key, var_export($val[$key], true), var_export($submited_payload, true), |
113 |
// var_export($new_payload, true)); |
114 |
// $this->correct = false; |
115 |
// $this->addToMessage($error_msg); |
116 |
// $this->addToLog(__METHOD__."() erreur : $error_msg", DEBUG_MODE); |
117 |
// return false; |
118 |
// } |
119 |
// } |
120 |
// } |
121 |
// } |
122 |
|
123 |
parent::setvalF($val); |
124 |
|
125 |
// XXX Ancien code : permet de ne pas avoir d'erreru lors de la modification d'une task |
126 |
if (array_key_exists('timestamp_log', $val) === true) { |
127 |
$this->valF['timestamp_log'] = str_replace("'", '"', $val['timestamp_log']); |
128 |
} |
129 |
|
130 |
// récupération de l'ID de l'objet existant |
131 |
$id = property_exists($this, 'id') ? $this->id : null; |
132 |
if(isset($val[$this->clePrimaire])) { |
133 |
$id = $val[$this->clePrimaire]; |
134 |
} elseif(isset($this->valF[$this->clePrimaire])) { |
135 |
$id = $this->valF[$this->clePrimaire]; |
136 |
} |
137 |
|
138 |
// MODE MODIFIER |
139 |
if (! empty($id)) { |
140 |
|
141 |
// si aucune payload n'est fourni (devrait toujours être le cas) |
142 |
if (! isset($val['json_payload']) || empty($val['json_payload'])) { |
143 |
|
144 |
// récupère l'objet existant |
145 |
$existing = $this->f->findObjectById('task', $id); |
146 |
if (! empty($existing)) { |
147 |
|
148 |
// récupère la payload de l'objet |
149 |
$val['json_payload'] = $existing->getVal('json_payload'); |
150 |
$this->valF['json_payload'] = $existing->getVal('json_payload'); |
151 |
$this->f->addToLog(__METHOD__."() récupère la payload de la tâche existante ". |
152 |
"'$id': ".$existing->getVal('json_payload'), EXTRA_VERBOSE_MODE); |
153 |
} |
154 |
} |
155 |
} |
156 |
|
157 |
if (array_key_exists('category', $val) === false |
158 |
|| $this->valF['category'] === '' |
159 |
|| $this->valF['category'] === null) { |
160 |
// |
161 |
$this->valF['category'] = $this->category; |
162 |
} |
163 |
|
164 |
// Si last_modification_time est vide, la valeur est remplacée par NULL |
165 |
// pour eviter d'avoir une erreur de base de données car le champ est au format time. |
166 |
if ($val['last_modification_time'] == "") { |
167 |
$this->valF['last_modification_time'] = NULL; |
168 |
} else { |
169 |
$this->valF['last_modification_time'] = $val['last_modification_time']; |
170 |
} |
171 |
|
172 |
// Si creation_time est vide, la valeur est remplacée par NULL |
173 |
// pour eviter d'avoir une erreur de base de données car le champ est au format time. |
174 |
if ($val['creation_time'] == "") { |
175 |
$this->valF['creation_time'] = NULL; |
176 |
} else { |
177 |
$this->valF['creation_time'] = $val['creation_time']; |
178 |
} |
179 |
} |
180 |
|
181 |
/** |
182 |
* |
183 |
* @return array |
184 |
*/ |
185 |
function get_var_sql_forminc__champs() { |
186 |
return array( |
187 |
"task", |
188 |
"type", |
189 |
"state", |
190 |
"object_id", |
191 |
"dossier", |
192 |
"stream", |
193 |
"creation_date", |
194 |
"creation_time", |
195 |
"CONCAT_WS(' ', to_char(task.creation_date, 'DD/MM/YYYY'), task.creation_time) AS date_creation", |
196 |
'last_modification_date', |
197 |
'last_modification_time', |
198 |
"CONCAT_WS(' ', to_char(task.last_modification_date, 'DD/MM/YYYY'), task.last_modification_time) AS date_modification", |
199 |
"comment", |
200 |
"json_payload", |
201 |
"timestamp_log", |
202 |
"timestamp_log AS timestamp_log_hidden", |
203 |
"category", |
204 |
); |
205 |
} |
206 |
|
207 |
function setType(&$form, $maj) { |
208 |
parent::setType($form, $maj); |
209 |
|
210 |
// Récupération du mode de l'action |
211 |
$crud = $this->get_action_crud($maj); |
212 |
|
213 |
// ALL |
214 |
$form->setType("category", "hidden"); |
215 |
$form->setType("timestamp_log_hidden", "hidden"); |
216 |
|
217 |
// MODE CREER |
218 |
if ($maj == 0 || $crud == 'create') { |
219 |
$form->setType("type", "select"); |
220 |
$form->setType("state", "select"); |
221 |
$form->setType("stream", "select"); |
222 |
$form->setType("json_payload", "textarea"); |
223 |
} |
224 |
// MODE MODIFIER |
225 |
if ($maj == 1 || $crud == 'update') { |
226 |
$form->setType("task", "hiddenstatic"); |
227 |
$form->setType("state", "select"); |
228 |
$form->setType("stream", "hiddenstatic"); |
229 |
$form->setType("json_payload", "jsonprettyprint"); |
230 |
$form->setType("timestamp_log", "jsontotab"); |
231 |
$form->setType("type", "hiddenstatic"); |
232 |
$form->setType("creation_date", "hidden"); |
233 |
$form->setType("creation_time", "hidden"); |
234 |
$form->setType("object_id", "hiddenstatic"); |
235 |
$form->setType("dossier", "hiddenstatic"); |
236 |
$form->setType("date_creation", "hiddenstatic"); |
237 |
$form->setType("last_modification_date", "hidden"); |
238 |
$form->setType("last_modification_time", "hidden"); |
239 |
$form->setType("date_modification", "static"); |
240 |
} |
241 |
// MODE CONSULTER |
242 |
if ($maj == 3 || $crud == 'read') { |
243 |
$form->setType("state", "selecthiddenstatic"); |
244 |
$form->setType("stream", "selecthiddenstatic"); |
245 |
$form->setType('dossier', 'link'); |
246 |
$form->setType('json_payload', 'jsonprettyprint'); |
247 |
$form->setType("type", "selecthiddenstatic"); |
248 |
$form->setType("creation_date", "hidden"); |
249 |
$form->setType("creation_time", "hidden"); |
250 |
$form->setType("date_creation", "static"); |
251 |
$form->setType("last_modification_date", "hidden"); |
252 |
$form->setType("last_modification_time", "hidden"); |
253 |
$form->setType("date_modification", "static"); |
254 |
$form->setType("timestamp_log", "jsontotab"); |
255 |
} |
256 |
} |
257 |
|
258 |
function stateTranslation ($currentState) { |
259 |
switch ($currentState){ |
260 |
case "draft": |
261 |
return __('brouillon'); |
262 |
break; |
263 |
case "new": |
264 |
return __('à traiter'); |
265 |
break; |
266 |
case "pending": |
267 |
return __('en cours'); |
268 |
break; |
269 |
case "done": |
270 |
return __('terminé'); |
271 |
break; |
272 |
case "archived": |
273 |
return __('archivé'); |
274 |
break; |
275 |
case "error": |
276 |
return __('erreur'); |
277 |
break; |
278 |
case "debug": |
279 |
return __('debug'); |
280 |
break; |
281 |
case "canceled": |
282 |
return __('annulé'); |
283 |
break; |
284 |
} |
285 |
} |
286 |
/** |
287 |
* |
288 |
*/ |
289 |
function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) { |
290 |
if($maj <= 3) { |
291 |
$contenu = array(); |
292 |
foreach(array('DRAFT', 'NEW', 'PENDING', 'DONE', 'ERROR', 'DEBUG', 'ARCHIVED', 'CANCELED') as $key) { |
293 |
$const_name = 'STATUS_'.$key; |
294 |
$const_value = constant("self::$const_name"); |
295 |
$contenu[0][] = $const_value; |
296 |
|
297 |
|
298 |
$contenu[1][] = $this->stateTranslation($const_value); |
299 |
|
300 |
} |
301 |
|
302 |
$form->setSelect("state", $contenu); |
303 |
|
304 |
$contenu_stream =array(); |
305 |
$contenu_stream[0][0]="input"; |
306 |
$contenu_stream[1][0]=__('input'); |
307 |
$contenu_stream[0][1]="output"; |
308 |
$contenu_stream[1][1]=__('output'); |
309 |
$form->setSelect("stream", $contenu_stream); |
310 |
|
311 |
$tab_type = array_unique(array_merge(self::TASK_TYPE_SI, self::TASK_TYPE_SC)); |
312 |
|
313 |
foreach ($tab_type as $type) { |
314 |
|
315 |
$contenu_type[0][] = $type; |
316 |
|
317 |
switch ($type) { |
318 |
case "creation_DA": |
319 |
$value_type = __('Création DA'); |
320 |
break; |
321 |
case "create_DI": |
322 |
$value_type = __('Création demande'); |
323 |
break; |
324 |
case "creation_DI": |
325 |
$value_type = __('Création DI'); |
326 |
break; |
327 |
case "modification_DA": |
328 |
$value_type = __('Modification DA'); |
329 |
break; |
330 |
case "modification_DI": |
331 |
$value_type = __('Modification DI'); |
332 |
break; |
333 |
case "ajout_piece": |
334 |
$value_type = __('Ajout pièce (sortant)'); |
335 |
break; |
336 |
case "add_piece": |
337 |
$value_type = __('Ajout pièce (entrant)'); |
338 |
break; |
339 |
case "depot_DI": |
340 |
$value_type = __('Dépôt DI'); |
341 |
break; |
342 |
case "qualification_DI": |
343 |
$value_type = __('Qualification DI'); |
344 |
break; |
345 |
case "creation_consultation": |
346 |
$value_type = __('Création consultation'); |
347 |
break; |
348 |
case "decision_DI": |
349 |
$value_type = __('Décision DI'); |
350 |
break; |
351 |
case "envoi_CL": |
352 |
$value_type = __('Envoi contrôle de légalité'); |
353 |
break; |
354 |
case "pec_metier_consultation": |
355 |
$value_type = __('PeC consultation'); |
356 |
break; |
357 |
case "avis_consultation": |
358 |
$value_type = __('Avis'); |
359 |
break; |
360 |
case "prescription": |
361 |
$value_type = __('Prescription'); |
362 |
break; |
363 |
case "create_DI_for_consultation": |
364 |
$value_type = __('Création DI pour consultation'); |
365 |
break; |
366 |
case "create_message": |
367 |
$value_type = __('Message'); |
368 |
break; |
369 |
case "notification_recepisse": |
370 |
$value_type = __('Notification récépissé'); |
371 |
break; |
372 |
case "notification_instruction": |
373 |
$value_type = __('Notification instruction'); |
374 |
break; |
375 |
case "notification_decision": |
376 |
$value_type = __('Notification décision'); |
377 |
break; |
378 |
case "notification_service_consulte": |
379 |
$value_type = __('Notification service consulté'); |
380 |
break; |
381 |
case "notification_tiers_consulte": |
382 |
$value_type = __('Notification tiers consulté'); |
383 |
break; |
384 |
case "completude_DI": |
385 |
$value_type = __('complétude DI'); |
386 |
break; |
387 |
case "incompletude_DI": |
388 |
$value_type = __('incomplétude DI'); |
389 |
break; |
390 |
} |
391 |
|
392 |
$contenu_type[1][] = $value_type; |
393 |
} |
394 |
|
395 |
$form->setselect('type', $contenu_type); |
396 |
} |
397 |
|
398 |
if ($maj == 3) { |
399 |
// Récupération du numéro du dossier si il n'est pas renseigné dans la tâche |
400 |
if ($form->val['dossier'] == '' || $form->val['dossier'] == null) { |
401 |
// Récupération de la payload de la taĉhe. |
402 |
// Si la tâche est une tâche input la payload est associée à la tâche. |
403 |
// Si la tâche est une tâche en output la payload est "calculé" à l'ouverture |
404 |
// du formulaire. |
405 |
if ($this->getVal('stream') == 'input') { |
406 |
$json_payload = json_decode($this->getVal('json_payload'), true); |
407 |
} else { |
408 |
$json_payload = json_decode($form->val['json_payload'], true); |
409 |
} |
410 |
// A partir de la payload de la tâche ont récupère les externals uid |
411 |
// Si un external uid de DI (dossier) existe ont le récupère et on stocke le numéro |
412 |
// pour l'afficher sur le formulaire. |
413 |
// Si l'external UID du DI n'existe pas on récupère celui du DA |
414 |
$external_uid = ''; |
415 |
if (array_key_exists('external_uids', $json_payload) |
416 |
&& array_key_exists('dossier', $json_payload['external_uids']) |
417 |
) { |
418 |
$external_uid = $json_payload['external_uids']['dossier']; |
419 |
} elseif (array_key_exists('external_uids', $json_payload) |
420 |
&& array_key_exists('dossier', $json_payload['external_uids'])) { |
421 |
$external_uid = $json_payload['external_uids']['dossier']; |
422 |
} |
423 |
// Recherche l'external uid dans la base de données pour récupèrer le numéro de |
424 |
// DI / DA correspondant. On stocke le numéro de dossier dans la propriété val |
425 |
// du formulaire pour pouvoir l'afficher |
426 |
if ($external_uid != '') { |
427 |
$qres = $this->f->get_one_result_from_db_query( |
428 |
sprintf( |
429 |
'SELECT |
430 |
lien_id_interne_uid_externe.dossier |
431 |
FROM |
432 |
%1$slien_id_interne_uid_externe |
433 |
WHERE |
434 |
lien_id_interne_uid_externe.external_uid = \'%2$s\'', |
435 |
DB_PREFIXE, |
436 |
$this->f->db->escapeSimple($external_uid) |
437 |
), |
438 |
array( |
439 |
"origin" => __METHOD__, |
440 |
) |
441 |
); |
442 |
if (! empty($qres["result"])) { |
443 |
$form->val['dossier'] = $qres["result"]; |
444 |
} |
445 |
} |
446 |
} |
447 |
|
448 |
// Vérifie si le numéro de dossier associé à la tâche existe dans la base. |
449 |
// Si c'est le cas ce numéro sera lié au dossier (DI ou DA) correspondant |
450 |
// TODO : vérifier la liste des tâches lié à des DA |
451 |
$obj_link = ''; |
452 |
if ($form->val['type'] == "creation_DA" || $form->val['type'] == "modification_DA") { |
453 |
// Vérification que le numéro de DA affiché dans le formulaire existe |
454 |
$qres = $this->f->get_one_result_from_db_query( |
455 |
sprintf( |
456 |
'SELECT |
457 |
dossier_autorisation.dossier_autorisation |
458 |
FROM |
459 |
%1$sdossier_autorisation |
460 |
WHERE |
461 |
dossier_autorisation.dossier_autorisation = \'%2$s\'', |
462 |
DB_PREFIXE, |
463 |
$this->f->db->escapeSimple($form->val['dossier']) |
464 |
), |
465 |
array( |
466 |
"origin" => __METHOD__, |
467 |
) |
468 |
); |
469 |
// Si on a un résultat c'est que le dossier existe, il faut afficher le lien |
470 |
if (! empty($qres["result"])) { |
471 |
$obj_link = 'dossier_autorisation'; |
472 |
} |
473 |
} else { |
474 |
// Vérification que le numéro de DI affiché dans le formulaire existe |
475 |
$qres = $this->f->get_one_result_from_db_query( |
476 |
sprintf( |
477 |
'SELECT |
478 |
dossier.dossier |
479 |
FROM |
480 |
%1$sdossier |
481 |
WHERE |
482 |
dossier.dossier = \'%2$s\'', |
483 |
DB_PREFIXE, |
484 |
$this->f->db->escapeSimple($form->val['dossier']) |
485 |
), |
486 |
array( |
487 |
"origin" => __METHOD__, |
488 |
) |
489 |
); |
490 |
// Si on a un résultat c'est que le dossier existe, il faut afficher le lien |
491 |
if (! empty($qres["result"])) { |
492 |
$obj_link = 'dossier_instruction'; |
493 |
} |
494 |
} |
495 |
// Pour afficher le lien vers un dossier ont utilise un champ de type "link". |
496 |
// Pour paramétrer ce champs on a besoin de savoir : |
497 |
// - quel objet est visé par le lien |
498 |
// - le label (libellé) du lien |
499 |
// - l'identifiant de l'objet qui sera utilisé dans le lien |
500 |
// - le titre associé au lien |
501 |
// Pour cela on remplit le champs comme un select et les valeurs du select |
502 |
// contiennent les informations nécessaire à l'affichage du champs. |
503 |
$params = array( |
504 |
'obj' => $obj_link, |
505 |
'libelle' => $form->val['dossier'], |
506 |
'title' => "Consulter le dossier", |
507 |
'idx' => $form->val['dossier'] |
508 |
); |
509 |
$form->setSelect("dossier", $params); |
510 |
} |
511 |
} |
512 |
|
513 |
/** |
514 |
* SETTER_FORM - setVal (setVal). |
515 |
* |
516 |
* @return void |
517 |
*/ |
518 |
function setVal(&$form, $maj, $validation, &$dnu1 = null, $dnu2 = null) { |
519 |
// parent::setVal($form, $maj, $validation); |
520 |
// |
521 |
if ($this->getVal('stream') == "output" |
522 |
&& $this->getVal('state') !== self::STATUS_DONE) { |
523 |
// |
524 |
$form->setVal('json_payload', $this->view_form_json(true)); |
525 |
} else { |
526 |
$form->setVal('json_payload', json_encode(json_decode($this->getVal('json_payload'), true), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); |
527 |
} |
528 |
} |
529 |
|
530 |
function setLib(&$form, $maj) { |
531 |
parent::setLib($form, $maj); |
532 |
|
533 |
// Récupération du mode de l'action |
534 |
$crud = $this->get_action_crud($maj); |
535 |
|
536 |
$form->setLib('date_creation', __("Date de création")); |
537 |
$form->setLib('date_modification', __("Date de dernière modification")); |
538 |
$form->setLib('comment', __("commentaire")); |
539 |
|
540 |
// MODE different de CREER |
541 |
if ($maj != 0 || $crud != 'create') { |
542 |
$form->setLib('json_payload', ''); |
543 |
$form->setLib("task", __("identifiant")); |
544 |
$form->setLib("Task_portal", __("task_portal")); |
545 |
$form->setLib("type", __("type")); |
546 |
$form->setLib("object_id", __("Réf. interne")); |
547 |
$form->setLib("stream", __("flux")); |
548 |
$form->setLib("timestamp_log", __("Historique")); |
549 |
} |
550 |
} |
551 |
|
552 |
public function verifier($val = array(), &$dnu1 = null, $dnu2 = null) { |
553 |
$ret = parent::verifier($val, $dnu1, $dnu2); |
554 |
|
555 |
// une tâche entrante doit avoir un type et une payload non-vide |
556 |
if (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') { |
557 |
if (isset($this->valF['type']) === false) { |
558 |
$this->correct = false; |
559 |
$this->addToMessage(sprintf( |
560 |
__("Le champ %s est obligatoire pour une tâche entrante."), |
561 |
sprintf('<span class="bold">%s</span>', $this->getLibFromField('type')) |
562 |
)); |
563 |
$this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE); |
564 |
} |
565 |
if (isset($this->valF['json_payload']) === false) { |
566 |
$this->correct = false; |
567 |
$this->addToMessage(sprintf( |
568 |
__("Le champ %s est obligatoire pour une tâche entrante."), |
569 |
sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload')) |
570 |
)); |
571 |
$this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE); |
572 |
} |
573 |
} |
574 |
|
575 |
// les JSONs doivent être décodables |
576 |
foreach(array('json_payload', 'timestamp_log') as $key) { |
577 |
if (isset($this->valF[$key]) && ! empty($this->valF[$key]) && ( |
578 |
is_array(json_decode($this->valF[$key], true)) === false |
579 |
|| json_last_error() !== JSON_ERROR_NONE)) { |
580 |
$this->correct = false; |
581 |
$champ_text = sprintf('<span class="bold">%s</span>', $this->getLibFromField($key)); |
582 |
$this->addToMessage(sprintf( |
583 |
__("Le champ %s doit être dans un format JSON valide (erreur: %s).". |
584 |
"<p>%s valF:</br><pre>%s</pre></p>". |
585 |
"<p>%s val:</br><pre>%s</pre></p>". |
586 |
"<p>%s POST:</br><pre>%s</pre></p>". |
587 |
"<p>%s submitted POST value:</br><pre>%s</pre></p>"), |
588 |
$champ_text, |
589 |
json_last_error() !== JSON_ERROR_NONE ? json_last_error_msg() : __('invalide'), |
590 |
$champ_text, |
591 |
$this->valF[$key], |
592 |
$champ_text, |
593 |
$val[$key], |
594 |
$champ_text, |
595 |
isset($_POST[$key]) ? $_POST[$key] : '', |
596 |
$champ_text, |
597 |
$this->f->get_submitted_post_value($key) |
598 |
)); |
599 |
$this->addToLog(__METHOD__.'(): erreur JSON: '.$this->msg, DEBUG_MODE); |
600 |
} |
601 |
} |
602 |
|
603 |
// une tâche entrante doit avoir une payload avec les clés requises |
604 |
if ($this->correct && (isset($this->valF['stream']) === false || |
605 |
$this->valF['stream'] == 'input')) { |
606 |
|
607 |
// décode la payload JSON |
608 |
// TODO : COMMENTER |
609 |
$json_payload = json_decode($this->valF['json_payload'], true); |
610 |
|
611 |
// défini une liste de chemin de clés requises |
612 |
$paths = array(); |
613 |
if ($this->valF['category'] === PLATAU) { |
614 |
$paths = array( |
615 |
'external_uids/dossier' |
616 |
); |
617 |
} |
618 |
|
619 |
// tâche de type création de DI/DA |
620 |
if (isset($this->valF['type']) !== false && $this->valF['type'] == 'create_DI_for_consultation') { |
621 |
|
622 |
$paths = array_merge($paths, array( |
623 |
'dossier/dossier', |
624 |
'dossier/dossier_autorisation_type_detaille_code', |
625 |
'dossier/date_demande', |
626 |
'dossier/depot_electronique', |
627 |
)); |
628 |
|
629 |
// si l'option commune est activée (mode MC) |
630 |
if ($this->f->is_option_dossier_commune_enabled()) { |
631 |
$paths[] = 'dossier/insee'; |
632 |
} |
633 |
|
634 |
// présence d'un moyen d'identifier la collectivité/le service |
635 |
if (! isset($json_payload['external_uids']['acteur']) && |
636 |
! isset($json_payload['dossier']['om_collectivite'])) { |
637 |
$this->correct = false; |
638 |
$this->addToMessage(sprintf( |
639 |
__("L'une des clés %s ou %s est obligatoire dans le contenu du champ %s pour une tâche entrante."), |
640 |
sprintf('<span class="bold">%s</span>', 'external_uids/acteur'), |
641 |
sprintf('<span class="bold">%s</span>', 'dossier/om_collectivite'), |
642 |
sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload')) |
643 |
)); |
644 |
$this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE); |
645 |
} |
646 |
} |
647 |
|
648 |
// pas d'erreur déjà trouvée |
649 |
if($this->correct) { |
650 |
|
651 |
// pour chaque chemin |
652 |
foreach($paths as $path) { |
653 |
|
654 |
// décompose le chemin |
655 |
$tokens = explode('/', $path); |
656 |
$cur_depth = $json_payload; |
657 |
|
658 |
// descend au et à mesure dans l'arborescence du chemin |
659 |
foreach($tokens as $token) { |
660 |
|
661 |
// en vérifiant que chaque élément du chemin est défini et non-nul |
662 |
if (isset($cur_depth[$token]) === false) { |
663 |
|
664 |
// sinon on produit une erreur |
665 |
$this->correct = false; |
666 |
$this->addToMessage(sprintf( |
667 |
__("La clé %s est obligatoire dans le contenu du champ %s pour une tâche entrante."), |
668 |
sprintf('<span class="bold">%s</span>', $path), |
669 |
sprintf('<span class="bold">%s</span>', $this->getLibFromField('json_payload')) |
670 |
)); |
671 |
$this->addToLog(__METHOD__.'(): erreur: '.$this->msg, DEBUG_MODE); |
672 |
break 2; |
673 |
} |
674 |
$cur_depth = $cur_depth[$token]; |
675 |
} |
676 |
} |
677 |
} |
678 |
} |
679 |
|
680 |
return $ret && $this->correct; |
681 |
} |
682 |
|
683 |
/** |
684 |
* [task_exists description] |
685 |
* @param string $type [description] |
686 |
* @param string $object_id [description] |
687 |
* @param bool $is_not_done [description] |
688 |
* @return [type] [description] |
689 |
*/ |
690 |
public function task_exists(string $type, string $object_id, string $dossier = null, bool $is_not_done = true) { |
691 |
$qres = $this->f->get_one_result_from_db_query( |
692 |
sprintf( |
693 |
'SELECT |
694 |
task |
695 |
FROM |
696 |
%1$stask |
697 |
WHERE |
698 |
%2$s |
699 |
type = \'%3$s\' |
700 |
AND ( |
701 |
object_id = \'%4$s\' |
702 |
%5$s |
703 |
) |
704 |
AND state != \'%6$s\'', |
705 |
DB_PREFIXE, |
706 |
$is_not_done == true ? 'state != \''.self::STATUS_DONE.'\' AND' : '', |
707 |
$type, |
708 |
$object_id, |
709 |
$dossier !== null ? sprintf('OR dossier = \'%s\'', $dossier) : '', |
710 |
self::STATUS_CANCELED |
711 |
), |
712 |
array( |
713 |
"origin" => __METHOD__, |
714 |
) |
715 |
); |
716 |
if ($qres["result"] !== null && $qres["result"] !== "") { |
717 |
return $qres["result"]; |
718 |
} |
719 |
return false; |
720 |
} |
721 |
|
722 |
/** |
723 |
* Permet la recherche multi-critères des tasks. |
724 |
* |
725 |
* @param array $search_values Chaque entrée du tableau est une ligne dans le WHERE |
726 |
* @return mixed Retourne le résultat de la requête ou false |
727 |
*/ |
728 |
public function task_exists_multi_search(array $search_values) { |
729 |
$query = sprintf(' |
730 |
SELECT * |
731 |
FROM %1$stask |
732 |
%2$s |
733 |
%3$s |
734 |
', |
735 |
DB_PREFIXE, |
736 |
empty($search_values) === false ? ' WHERE ' : '', |
737 |
implode(' AND ', $search_values) |
738 |
); |
739 |
$res = $this->f->get_all_results_from_db_query( |
740 |
$query, |
741 |
array( |
742 |
"origin" => __METHOD__, |
743 |
) |
744 |
); |
745 |
if (count($res['result']) > 0) { |
746 |
return $res['result']; |
747 |
} |
748 |
return false; |
749 |
} |
750 |
|
751 |
/** |
752 |
* TRIGGER - triggerajouter. |
753 |
* |
754 |
* @param string $id |
755 |
* @param null &$dnu1 @deprecated Ne pas utiliser. |
756 |
* @param array $val Tableau des valeurs brutes. |
757 |
* @param null $dnu2 @deprecated Ne pas utiliser. |
758 |
* |
759 |
* @return boolean |
760 |
*/ |
761 |
function triggerajouter($id, &$dnu1 = null, $val = array(), $dnu2 = null) { |
762 |
|
763 |
// tâche entrante |
764 |
if (isset($this->valF['stream']) === false || $this->valF['stream'] == 'input') { |
765 |
|
766 |
// décode la paylod JSON pour extraire les données métiers à ajouter |
767 |
// en tant que métadonnées de la tâche |
768 |
$json_payload = json_decode($this->valF['json_payload'], true); |
769 |
|
770 |
// si la tâche possède déjà une clé dossier |
771 |
if (isset($json_payload['dossier']['dossier']) && |
772 |
! empty($json_payload['dossier']['dossier'])) { |
773 |
$this->valF["dossier"] = $json_payload['dossier']['dossier']; |
774 |
} |
775 |
} |
776 |
|
777 |
// gestion d'une tache de type notification et de category mail |
778 |
if (isset($val['type']) |
779 |
&& (($val['type'] === 'notification_instruction' || $val['type'] === 'notification_decision') |
780 |
&& isset($val['category']) |
781 |
&& $val['category'] === 'mail') |
782 |
|| $val['type'] === 'notification_service_consulte' |
783 |
|| $val['type'] === 'notification_tiers_consulte' |
784 |
|| $val['type'] === 'notification_depot_demat' |
785 |
|| $val['type'] === 'notification_commune' |
786 |
) { |
787 |
// Récupère la payload de la tache |
788 |
$data = array(); |
789 |
$data['instruction_notification'] = $this->get_instruction_notification_data( |
790 |
$this->valF['category'], |
791 |
'with-id', |
792 |
array('with-id' => $this->valF['object_id']) |
793 |
); |
794 |
$data['dossier'] = $this->get_dossier_data($this->valF['dossier']); |
795 |
|
796 |
// Récupère l'instance de la notification |
797 |
$inst_notif = $this->f->get_inst__om_dbform(array( |
798 |
"obj" => "instruction_notification", |
799 |
"idx" => $val['object_id'], |
800 |
)); |
801 |
// Envoi le mail et met à jour le suivi |
802 |
$envoiMail = $inst_notif->send_mail_notification($data, $val['type']); |
803 |
// Passage de la tache à done si elle a réussi et à error |
804 |
// si l'envoi a échoué |
805 |
$this->valF['state'] = 'done'; |
806 |
if ($envoiMail === false) { |
807 |
$this->valF['state'] = 'error'; |
808 |
} |
809 |
} |
810 |
} |
811 |
|
812 |
/** |
813 |
* TRIGGER - triggermodifier. |
814 |
* |
815 |
* @param string $id |
816 |
* @param null &$dnu1 @deprecated Ne pas utiliser. |
817 |
* @param array $val Tableau des valeurs brutes. |
818 |
* @param null $dnu2 @deprecated Ne pas utiliser. |
819 |
* |
820 |
* @return boolean |
821 |
*/ |
822 |
function triggermodifier($id, &$dnu1 = null, $val = array(), $dnu2 = null) { |
823 |
parent::triggermodifier($id, $dnu1, $val, $dnu2); |
824 |
$this->addToLog(__METHOD__."(): start", EXTRA_VERBOSE_MODE); |
825 |
|
826 |
// Mise à jour des valeurs, notamment du timestamp_log en fonction de plusieurs critères |
827 |
$values = array( |
828 |
'state' => $this->valF['state'], |
829 |
'object_id' => $this->valF['object_id'], |
830 |
'comment' => $this->valF['comment'], |
831 |
); |
832 |
$new_values = $this->set_values_for_update($values); |
833 |
if ($new_values === false) { |
834 |
$this->addToLog(__METHOD__."(): erreur timestamp log", DEBUG_MODE); |
835 |
return false; |
836 |
} |
837 |
|
838 |
// Mise à jour des valeurs |
839 |
$this->valF['timestamp_log'] = $new_values['timestamp_log']; |
840 |
$this->valF['state'] = $new_values['state']; |
841 |
$this->valF['object_id'] = $new_values['object_id']; |
842 |
$this->valF['last_modification_date'] = date('Y-m-d'); |
843 |
$this->valF['last_modification_time'] = date('H:i:s'); |
844 |
if ($val['stream'] === 'output') { |
845 |
$this->valF['json_payload'] = "{}"; |
846 |
if ($this->getVal("state") !== self::STATUS_DONE |
847 |
&& $this->valF['state'] === self::STATUS_DONE) { |
848 |
// |
849 |
$this->valF['json_payload'] = $this->view_form_json(true); |
850 |
} |
851 |
} |
852 |
|
853 |
return true; |
854 |
} |
855 |
|
856 |
|
857 |
/** |
858 |
* Applique nouvelle valeur après traitement. |
859 |
* |
860 |
* @param array $params Tableau des valeurs en entrées |
861 |
* @return array Tableau des valeurs en sorties |
862 |
*/ |
863 |
public function set_values_for_update($params = array()) { |
864 |
|
865 |
// Récupération du timestamp_log existant |
866 |
$timestamp_log = $this->get_timestamp_log(); |
867 |
if ($timestamp_log === false) { |
868 |
return false; |
869 |
} |
870 |
|
871 |
// Vérification des object_id précédent en cas de tentative d'appliquer |
872 |
// l'état CANCELED sur la tâche |
873 |
if (isset($params['state']) === true |
874 |
&& $params['state'] === self::STATUS_CANCELED) { |
875 |
// Récupération du journal d'activité de la tâche sous forme de tableau |
876 |
// trié par ordre décroissant |
877 |
$log = $timestamp_log; |
878 |
krsort($log); |
879 |
// Pour chaque entrée dans le journal d'activité de la tâche : |
880 |
// - vérification de la présence de l'object_id précédent |
881 |
// - vérification que l'object_id précédent existe toujours dans la base de données |
882 |
// - l'object_id est mise à jour avec la valeur de l'object_id précédent |
883 |
// - le state n'est pas modifié |
884 |
// - sortie du traitement dès que le premier object_id précédent existant est trouvé |
885 |
// - si aucun object_id précédent existant n'est trouvé alors ni le state, ni l'object_id n'est modifiés |
886 |
foreach ($log as $key => $value) { |
887 |
// |
888 |
if (isset($value['prev_object_id']) === true |
889 |
&& $this->getVal('object_id') !== $value['prev_object_id']) { |
890 |
// Récupère la liste des tables potentielles pour un type de tâche |
891 |
$tables = $this->get_tables_by_task_type($this->getVal('type'), $this->getVal('stream')); |
892 |
foreach ($tables as $table) { |
893 |
// Vérifie s'il y a un ou aucun résultat |
894 |
$qres = $this->f->get_one_result_from_db_query( |
895 |
sprintf( |
896 |
'SELECT |
897 |
COUNT(%2$s) |
898 |
FROM |
899 |
%1$s%2$s |
900 |
WHERE |
901 |
%2$s::CHARACTER VARYING = \'%3$s\'', |
902 |
DB_PREFIXE, |
903 |
$table, |
904 |
$value['prev_object_id'] |
905 |
), |
906 |
array( |
907 |
"origin" => __METHOD__, |
908 |
"force_return" => true, |
909 |
) |
910 |
); |
911 |
if ($qres["code"] !== "OK") { |
912 |
return $this->end_treatment(__METHOD__, false); |
913 |
} |
914 |
// Affectation des valeurs et sortie de la boucle |
915 |
if ($qres["result"] == '1') { |
916 |
$params['object_id'] = $value['prev_object_id']; |
917 |
$params['state'] = $this->getVal('state'); |
918 |
break; |
919 |
} |
920 |
} |
921 |
// Sortie de la boucle si les valeurs sont affectées |
922 |
if ($params['object_id'] !== null |
923 |
&& $params['object_id'] === $value['prev_object_id']) { |
924 |
// |
925 |
break; |
926 |
} |
927 |
} |
928 |
} |
929 |
} |
930 |
|
931 |
// Mise à jour du journal d'activité de la tâche |
932 |
array_push($timestamp_log, array( |
933 |
'modification_date' => date('Y-m-d H:i:s'), |
934 |
'object_id' => $params['object_id'] !== null ? $params['object_id'] : $this->getVal('object_id'), |
935 |
'prev_object_id' => $this->getVal('object_id'), |
936 |
'state' => $params['state'], |
937 |
'prev_state' => $this->getVal('state'), |
938 |
'comment' => isset($params['comment']) ? $params['comment'] : $this->getVal('comment'), |
939 |
)); |
940 |
// |
941 |
$timestamp_log = json_encode($timestamp_log); |
942 |
|
943 |
|
944 |
// Les nouvelles valeurs après vérification des critères |
945 |
$result = array( |
946 |
'timestamp_log' => $timestamp_log, |
947 |
'object_id' => $params['object_id'], |
948 |
'state' => $params['state'], |
949 |
'comment' => $params['comment'], |
950 |
); |
951 |
return $result; |
952 |
} |
953 |
|
954 |
|
955 |
/** |
956 |
* TRIGGER - triggermodifierapres. |
957 |
* |
958 |
* @param string $id |
959 |
* @param null &$dnu1 @deprecated Ne pas utiliser. |
960 |
* @param array $val Tableau des valeurs brutes. |
961 |
* @param null $dnu2 @deprecated Ne pas utiliser. |
962 |
* |
963 |
* @return boolean |
964 |
*/ |
965 |
public function triggermodifierapres($id, &$dnu1 = null, $val = array(), $dnu2 = null) { |
966 |
parent::triggermodifierapres($id, $dnu1, $val, $dnu2); |
967 |
|
968 |
// Suivi des notificiations |
969 |
// En cas de changement de l'état de la tâche de notification, alors |
970 |
// le suivi des dates de la notification et de l'instruction, est effectué |
971 |
if (isset($val['category']) === true |
972 |
&& $val['category'] === PORTAL |
973 |
&& isset($val['type']) === true |
974 |
&& ($val['type'] === 'notification_recepisse' |
975 |
|| $val['type'] === 'notification_instruction' |
976 |
|| $val['type'] === 'notification_decision' |
977 |
|| $val['type'] === 'notification_service_consulte' |
978 |
|| $val['type'] === 'notification_tiers_consulte')) { |
979 |
// |
980 |
if (isset($this->valF['state']) === true |
981 |
&& $this->valF['state'] !== $this->getVal('state') |
982 |
&& $this->valF['state'] !== self::STATUS_CANCELED) { |
983 |
// |
984 |
$inst_in = $this->f->get_inst__om_dbform(array( |
985 |
"obj" => "instruction_notification", |
986 |
"idx" => $val['object_id'], |
987 |
)); |
988 |
$valF_in = array(); |
989 |
foreach ($inst_in->champs as $champ) { |
990 |
$valF_in[$champ] = $inst_in->getVal($champ); |
991 |
} |
992 |
// Par défaut la date d'envoi et la date de premier accès sur |
993 |
// la notification ne sont pas renseignées |
994 |
$valF_in['date_envoi'] = null; |
995 |
$valF_in['date_premier_acces'] = null; |
996 |
// Lorsque la tâche est correctement traitée |
997 |
if ($this->valF['state'] === self::STATUS_DONE) { |
998 |
// |
999 |
$valF_in['statut'] = __("envoyé"); |
1000 |
$valF_in['commentaire'] = __("Notification traitée"); |
1001 |
$valF_in['date_envoi'] = date('d/m/Y H:i:s'); |
1002 |
// Si l'instruction possède un document lié, alors ses dates |
1003 |
// de suivi sont mises à jour |
1004 |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
1005 |
"obj" => "instruction", |
1006 |
"idx" => $inst_in->getVal('instruction'), |
1007 |
)); |
1008 |
if ($inst_instruction->has_an_edition() === true) { |
1009 |
$valF_instruction = array(); |
1010 |
foreach ($inst_instruction->champs as $champ) { |
1011 |
$valF_instruction[$champ] = $inst_instruction->getVal($champ); |
1012 |
} |
1013 |
$valF_instruction['date_envoi_rar'] = date('d/m/Y'); |
1014 |
$valF_instruction['date_retour_rar'] = date('d/m/Y', strtotime('now + 1 day')); |
1015 |
// Action spécifique pour identifier que la modification |
1016 |
// est une nootification de demandeur |
1017 |
$inst_instruction->setParameter('maj', 175); |
1018 |
$update_instruction = $inst_instruction->modifier($valF_instruction); |
1019 |
if ($update_instruction === false) { |
1020 |
$this->addToLog(__METHOD__."(): ".$inst_instruction->msg, DEBUG_MODE); |
1021 |
return false; |
1022 |
} |
1023 |
} |
1024 |
} |
1025 |
// En cas d'erreur lors du traitement de la task |
1026 |
if ($this->valF['state'] === self::STATUS_ERROR) { |
1027 |
$valF_in['statut'] = __("échec"); |
1028 |
$valF_in['commentaire'] = __("Le traitement de la notification a échoué"); |
1029 |
} |
1030 |
// Met à jour la notification |
1031 |
$inst_in->setParameter('maj', 1); |
1032 |
$update_in = $inst_in->modifier($valF_in); |
1033 |
if ($update_in === false) { |
1034 |
$this->addToLog(__METHOD__."(): ".$inst_in->msg, DEBUG_MODE); |
1035 |
return false; |
1036 |
} |
1037 |
} |
1038 |
} |
1039 |
|
1040 |
// Envoi au contrôle de légalité |
1041 |
// En cas de changement de l'état de la tâche envoi_CL, alors le suivi |
1042 |
// des dates de l'instruction est effectué |
1043 |
if ($val['type'] === 'envoi_CL' |
1044 |
&& isset($this->valF['state']) === true |
1045 |
&& $this->valF['state'] === self::STATUS_DONE) { |
1046 |
// |
1047 |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
1048 |
"obj" => "instruction", |
1049 |
"idx" => $this->getVal('object_id'), |
1050 |
)); |
1051 |
if ($inst_instruction->has_an_edition() === true) { |
1052 |
$valF_instruction = array(); |
1053 |
foreach ($inst_instruction->champs as $champ) { |
1054 |
$valF_instruction[$champ] = $inst_instruction->getVal($champ); |
1055 |
} |
1056 |
} |
1057 |
$valF_instruction['date_envoi_controle_legalite'] = date("Y-m-d"); |
1058 |
$inst_instruction->setParameter('maj', 1); |
1059 |
$update_instruction = $inst_instruction->modifier($valF_instruction); |
1060 |
if ($update_instruction === false) { |
1061 |
$this->addToLog(__METHOD__."(): ".$inst_instruction->msg, DEBUG_MODE); |
1062 |
return false; |
1063 |
} |
1064 |
} |
1065 |
|
1066 |
// |
1067 |
return true; |
1068 |
} |
1069 |
|
1070 |
/** |
1071 |
* TREATMENT - add_task |
1072 |
* Ajoute un enregistrement. |
1073 |
* |
1074 |
* @param array $params Tableau des paramètres |
1075 |
* @return boolean |
1076 |
*/ |
1077 |
public function add_task($params = array()) { |
1078 |
$this->begin_treatment(__METHOD__); |
1079 |
|
1080 |
// Vérifie si la task doit être ajoutée en fonction du mode de l'application, |
1081 |
// seulement pour les tasks output |
1082 |
$task_types_si = self::TASK_TYPE_SI; |
1083 |
$task_types_sc = self::TASK_TYPE_SC; |
1084 |
$stream = isset($params['val']['stream']) === true ? $params['val']['stream'] : 'output'; |
1085 |
if ($stream === 'output' |
1086 |
&& isset($params['val']['type']) === true |
1087 |
&& $this->f->is_option_mode_service_consulte_enabled() === true |
1088 |
&& in_array($params['val']['type'], $task_types_sc) === false) { |
1089 |
// |
1090 |
return $this->end_treatment(__METHOD__, true); |
1091 |
} |
1092 |
if ($stream === 'output' |
1093 |
&& isset($params['val']['type']) === true |
1094 |
&& $this->f->is_option_mode_service_consulte_enabled() === false |
1095 |
&& in_array($params['val']['type'], $task_types_si) === false) { |
1096 |
// |
1097 |
return $this->end_treatment(__METHOD__, true); |
1098 |
} |
1099 |
|
1100 |
// |
1101 |
$timestamp_log = json_encode(array()); |
1102 |
|
1103 |
// |
1104 |
$category = isset($params['val']['category']) === true ? $params['val']['category'] : $this->category; |
1105 |
|
1106 |
// Si la tâche est de type ajout_piece et de stream input alors on ajoute le fichier |
1107 |
// et on ajoute l'uid dans le champ json_payload avant l'ajout de la tâche |
1108 |
if (isset($params['val']['type']) |
1109 |
&& ($params['val']['type'] == "add_piece" || $params['val']['type'] == "avis_consultation") |
1110 |
&& isset($params['val']['stream']) |
1111 |
&& $params['val']['stream'] == "input" ) { |
1112 |
// |
1113 |
$json_payload = json_decode($params['val']['json_payload'], true); |
1114 |
if (json_last_error() !== JSON_ERROR_NONE) { |
1115 |
$this->addToMessage(__("Le contenu JSON de la tâche n'est pas valide.")); |
1116 |
return $this->end_treatment(__METHOD__, false); |
1117 |
} |
1118 |
if (isset($json_payload['document_numerise']["file_content"]) === true |
1119 |
&& empty($json_payload['document_numerise']["file_content"]) === false) { |
1120 |
// |
1121 |
$document_numerise = $json_payload['document_numerise']; |
1122 |
$file_content = base64_decode($document_numerise["file_content"]); |
1123 |
if ($file_content === false){ |
1124 |
$this->addToMessage(__("Le contenu du fichier lié à la tâche n'a pas pu etre recupere.")); |
1125 |
return $this->end_treatment(__METHOD__, false); |
1126 |
} |
1127 |
$metadata = array( |
1128 |
"filename" => $document_numerise['nom_fichier'], |
1129 |
"size" => strlen($file_content), |
1130 |
"mimetype" => $document_numerise['file_content_type'], |
1131 |
"date_creation" => isset($document_numerise['date_creation']) === true ? $document_numerise['date_creation'] : date("Y-m-d"), |
1132 |
); |
1133 |
$uid_fichier = $this->f->storage->create($file_content, $metadata, "from_content", "task.uid_fichier"); |
1134 |
if ($uid_fichier === OP_FAILURE) { |
1135 |
$this->addToMessage(__("Erreur lors de la creation du fichier lié à la tâche.")); |
1136 |
return $this->end_treatment(__METHOD__, false); |
1137 |
} |
1138 |
$json_payload["document_numerise"]["uid"] = $uid_fichier; |
1139 |
// Le fichier a été ajouté nous n'avons plus besoin du champ file_content dans la payload |
1140 |
unset($json_payload["document_numerise"]["file_content"]); |
1141 |
$params['val']['json_payload'] = json_encode($json_payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
1142 |
} |
1143 |
} |
1144 |
|
1145 |
// Mise à jour du DI |
1146 |
$valF = array( |
1147 |
'task' => '', |
1148 |
'type' => $params['val']['type'], |
1149 |
'timestamp_log' => $timestamp_log, |
1150 |
'state' => isset($params['val']['state']) === true ? $params['val']['state'] : self::STATUS_NEW, |
1151 |
'object_id' => isset($params['val']['object_id']) ? $params['val']['object_id'] : '', |
1152 |
'dossier' => isset($params['val']['dossier']) ? $params['val']['dossier'] : '', |
1153 |
'stream' => $stream, |
1154 |
'json_payload' => isset($params['val']['json_payload']) === true ? $params['val']['json_payload'] : '{}', |
1155 |
'category' => $category, |
1156 |
'creation_date' => date('Y-m-d'), |
1157 |
'creation_time' => date('H:i:s'), |
1158 |
'last_modification_date' => null, |
1159 |
'last_modification_time' => null, |
1160 |
'comment' => null, |
1161 |
); |
1162 |
|
1163 |
// tâche sortante |
1164 |
$typeNonConcerne = array( |
1165 |
'notification_recepisse', |
1166 |
'notification_instruction', |
1167 |
'notification_decision', |
1168 |
'notification_service_consulte', |
1169 |
'notification_tiers_consulte' |
1170 |
); |
1171 |
if ($valF["stream"] == "output" |
1172 |
&& ! in_array($valF['type'], $typeNonConcerne)) { |
1173 |
// TODO expliquer ce code |
1174 |
$task_exists = $this->task_exists($valF['type'], $valF['object_id'], $valF['dossier']); |
1175 |
if ($valF['type'] === 'modification_DI' && $task_exists === false) { |
1176 |
$task_exists = $this->task_exists('creation_DI', $valF['object_id']); |
1177 |
} |
1178 |
if ($valF['type'] === 'modification_DA' && $task_exists === false) { |
1179 |
$task_exists = $this->task_exists('creation_DA', $valF['object_id']); |
1180 |
} |
1181 |
if ($valF['type'] === 'ajout_piece') { |
1182 |
$task_exists = $this->task_exists('ajout_piece', $valF['object_id']); |
1183 |
} |
1184 |
if ($valF['type'] === 'creation_consultation') { |
1185 |
$task_exists = $this->task_exists('creation_consultation', $valF['object_id']); |
1186 |
} |
1187 |
if ($task_exists !== false) { |
1188 |
$inst_task = $this->f->get_inst__om_dbform(array( |
1189 |
"obj" => "task", |
1190 |
"idx" => $task_exists, |
1191 |
)); |
1192 |
$update_state = $inst_task->getVal('state'); |
1193 |
if (isset($params['update_val']['state']) === true) { |
1194 |
$update_state = $params['update_val']['state']; |
1195 |
} |
1196 |
$update_params = array( |
1197 |
'val' => array( |
1198 |
'state' => $update_state, |
1199 |
), |
1200 |
'object_id' => $valF['object_id'], |
1201 |
); |
1202 |
return $inst_task->update_task($update_params); |
1203 |
} |
1204 |
} |
1205 |
$add = $this->ajouter($valF); |
1206 |
$this->addToLog(__METHOD__."(): retour de l'ajout de tâche: ".var_export($add, true), VERBOSE_MODE); |
1207 |
if ($add === false) { |
1208 |
$this->addToLog(__METHOD__."(): ".$this->msg, DEBUG_MODE); |
1209 |
return $this->end_treatment(__METHOD__, false); |
1210 |
} |
1211 |
return $this->end_treatment(__METHOD__, true); |
1212 |
} |
1213 |
|
1214 |
/** |
1215 |
* TREATMENT - update_task |
1216 |
* Met à jour l'enregistrement instancié. |
1217 |
* |
1218 |
* @param array $params Tableau des paramètres |
1219 |
* @return boolean |
1220 |
*/ |
1221 |
public function update_task($params = array()) { |
1222 |
$this->begin_treatment(__METHOD__); |
1223 |
|
1224 |
// Mise à jour de la tâche |
1225 |
$valF = array( |
1226 |
'task' => $this->getVal($this->clePrimaire), |
1227 |
'type' => $this->getVal('type'), |
1228 |
'timestamp_log' => '[]', |
1229 |
'state' => $params['val']['state'], |
1230 |
'object_id' => isset($params['object_id']) == true ? $params['object_id'] : $this->getVal('object_id'), |
1231 |
'stream' => $this->getVal('stream'), |
1232 |
'dossier' => $this->getVal('dossier'), |
1233 |
'json_payload' => $this->getVal('json_payload'), |
1234 |
'category' => $this->getVal('category'), |
1235 |
'creation_date' => $this->getVal('creation_date'), |
1236 |
'creation_time' => $this->getVal('creation_time'), |
1237 |
'last_modification_date' => date('Y-m-d'), |
1238 |
'last_modification_time' => date('H:i:s'), |
1239 |
'comment' => $this->getVal('comment'), |
1240 |
); |
1241 |
$update = $this->modifier($valF); |
1242 |
if ($update === false) { |
1243 |
$this->addToLog($this->msg, DEBUG_MODE); |
1244 |
return $this->end_treatment(__METHOD__, false); |
1245 |
} |
1246 |
return $this->end_treatment(__METHOD__, true); |
1247 |
} |
1248 |
|
1249 |
/** |
1250 |
* Récupère le journal d'horodatage dans le champ timestamp_log de |
1251 |
* l'enregistrement instancié. |
1252 |
* |
1253 |
* @param array $params Tableau des paramètres |
1254 |
* @return array sinon false en cas d'erreur |
1255 |
*/ |
1256 |
protected function get_timestamp_log($params = array()) { |
1257 |
$val = $this->getVal('timestamp_log'); |
1258 |
if ($val === '') { |
1259 |
$val = json_encode(array()); |
1260 |
} |
1261 |
if($this->isJson($val) === false) { |
1262 |
return false; |
1263 |
} |
1264 |
return json_decode($val, true); |
1265 |
} |
1266 |
|
1267 |
/** |
1268 |
* VIEW - view_json_data |
1269 |
* Affiche l'enregistrement dans le format JSON. |
1270 |
* |
1271 |
* @return void |
1272 |
*/ |
1273 |
public function view_json_data() { |
1274 |
$this->checkAccessibility(); |
1275 |
$this->f->disableLog(); |
1276 |
if ($this->getParameter('idx') !== ']' |
1277 |
&& $this->getParameter('idx') !== '0') { |
1278 |
// |
1279 |
$this->view_form_json(); |
1280 |
} |
1281 |
else { |
1282 |
$this->view_tab_json(); |
1283 |
} |
1284 |
} |
1285 |
|
1286 |
protected function view_tab_json() { |
1287 |
$where = ''; |
1288 |
$category = null; |
1289 |
// Liste des paramètres possibles pour la recherche des tâches |
1290 |
$params = array( |
1291 |
'task', |
1292 |
'type', |
1293 |
'state', |
1294 |
'object_id', |
1295 |
'dossier', |
1296 |
'stream', |
1297 |
'category', |
1298 |
'lien_id_interne_uid_externe', |
1299 |
'object', |
1300 |
'external_uid', |
1301 |
); |
1302 |
// Pour chaque paramètre possible, vérification de son existance et de sa |
1303 |
// valeur pour compléter la requête de recherche |
1304 |
foreach ($params as $param) { |
1305 |
// |
1306 |
if ($this->f->get_submitted_get_value($param) !== null |
1307 |
&& $this->f->get_submitted_get_value($param) !== '') { |
1308 |
// Condition spécifique au champ 'category' |
1309 |
if ($param === 'category') { |
1310 |
$category = $this->f->get_submitted_get_value('category'); |
1311 |
} |
1312 |
// |
1313 |
$where_or_and = 'WHERE'; |
1314 |
if ($where !== '') { |
1315 |
$where_or_and = 'AND'; |
1316 |
} |
1317 |
$table = 'task'; |
1318 |
if ($param === 'lien_id_interne_uid_externe' |
1319 |
|| $param === 'object' |
1320 |
|| $param === 'external_uid') { |
1321 |
// |
1322 |
$table = 'lien_id_interne_uid_externe'; |
1323 |
} |
1324 |
$where .= sprintf(' %s %s.%s = \'%s\' ', $where_or_and, $table, $param, $this->f->get_submitted_get_value($param)); |
1325 |
} |
1326 |
} |
1327 |
// |
1328 |
$query = sprintf(' |
1329 |
SELECT |
1330 |
task.* |
1331 |
FROM %1$stask |
1332 |
LEFT JOIN %1$slien_id_interne_uid_externe |
1333 |
ON task.object_id = lien_id_interne_uid_externe.object_id |
1334 |
AND task.category = lien_id_interne_uid_externe.category |
1335 |
%2$s |
1336 |
ORDER BY task ASC |
1337 |
', |
1338 |
DB_PREFIXE, |
1339 |
$where |
1340 |
); |
1341 |
$res = $this->f->get_all_results_from_db_query( |
1342 |
$query, |
1343 |
array( |
1344 |
"origin" => __METHOD__, |
1345 |
"force_return" => true, |
1346 |
) |
1347 |
); |
1348 |
if ($res['code'] === 'KO') { |
1349 |
return false; |
1350 |
} |
1351 |
$list_tasks = array(); |
1352 |
foreach ($res['result'] as $task) { |
1353 |
unset($task['timestamp_log']); |
1354 |
unset($task['json_payload']); |
1355 |
if ($task['type'] === 'ajout_piece') { |
1356 |
$val_dn = $this->get_document_numerise_data($task['object_id']); |
1357 |
} |
1358 |
if ($task['stream'] === 'output') { |
1359 |
$task['external_uids'] = array_merge( |
1360 |
$this->get_all_external_uids($task['dossier'], array(), $category !== null ? $category : $task['category']), |
1361 |
$this->get_all_external_uids($task['object_id'], array(), $category !== null ? $category : $task['category']) |
1362 |
); |
1363 |
} |
1364 |
$list_tasks[$task['task']] = $task; |
1365 |
} |
1366 |
echo(json_encode($list_tasks)); |
1367 |
} |
1368 |
|
1369 |
protected function get_dossier_data(string $dossier) { |
1370 |
$val_di = array(); |
1371 |
$inst_di = $this->f->get_inst__om_dbform(array( |
1372 |
"obj" => "dossier", |
1373 |
"idx" => $dossier, |
1374 |
)); |
1375 |
if (empty($inst_di->val) === true) { |
1376 |
return $val_di; |
1377 |
} |
1378 |
$val_di = $inst_di->get_json_data(); |
1379 |
if ($val_di['dossier_instruction_type_code'] === 'T') { |
1380 |
$val_di['date_decision_transfert'] = $val_di['date_decision']; |
1381 |
} |
1382 |
unset($val_di['initial_dt']); |
1383 |
unset($val_di['log_instructions']); |
1384 |
return $val_di; |
1385 |
} |
1386 |
|
1387 |
protected function get_dossier_autorisation_data(string $da) { |
1388 |
$val_da = array(); |
1389 |
$inst_da = $this->f->get_inst__om_dbform(array( |
1390 |
"obj" => "dossier_autorisation", |
1391 |
"idx" => $da, |
1392 |
)); |
1393 |
$val_da = $inst_da->get_json_data(); |
1394 |
return $val_da; |
1395 |
} |
1396 |
|
1397 |
protected function get_donnees_techniques_data(string $fk_idx, string $fk_field) { |
1398 |
$val_dt = array(); |
1399 |
$inst_dt = $this->f->get_inst__by_other_idx(array( |
1400 |
"obj" => "donnees_techniques", |
1401 |
"fk_field" => $fk_field, |
1402 |
"fk_idx" => $fk_idx, |
1403 |
)); |
1404 |
$val_dt = array( |
1405 |
'donnees_techniques' => $inst_dt->getVal($inst_dt->clePrimaire), |
1406 |
'cerfa' => $inst_dt->getVal('cerfa'), |
1407 |
); |
1408 |
$val_dt = array_merge($val_dt, $inst_dt->get_donnees_techniques_applicables()); |
1409 |
if (isset($val_dt['am_exist_date']) === true) { |
1410 |
$val_dt['am_exist_date_num'] = ''; |
1411 |
if (is_numeric($val_dt['am_exist_date']) === true) { |
1412 |
$val_dt['am_exist_date_num'] = $val_dt['am_exist_date']; |
1413 |
} |
1414 |
} |
1415 |
// Correspond à la nomenclature de Plat'AU STATUT_INFO |
1416 |
$val_dt['tax_statut_info'] = 'Déclaré'; |
1417 |
// |
1418 |
if ($inst_dt->is_tab_surf_ssdest_enabled() === true) { |
1419 |
$fields_tab_surf_dest = $inst_dt->get_fields_tab_surf_dest(); |
1420 |
foreach ($fields_tab_surf_dest as $field) { |
1421 |
if (isset($val_dt[$field]) === true) { |
1422 |
unset($val_dt[$field]); |
1423 |
} |
1424 |
} |
1425 |
} else { |
1426 |
$fields_tab_surf_ssdest = $inst_dt->get_fields_tab_surf_ssdest(); |
1427 |
foreach ($fields_tab_surf_ssdest as $field) { |
1428 |
if (isset($val_dt[$field]) === true) { |
1429 |
unset($val_dt[$field]); |
1430 |
} |
1431 |
} |
1432 |
} |
1433 |
// Correspond à la nouvelle ligne CERFA v7 dans le DENSI imposition 1.2.3 |
1434 |
if (isset($val_dt['tax_su_non_habit_surf2']) === true |
1435 |
&& isset($val_dt['tax_su_non_habit_surf3']) === true |
1436 |
&& (($val_dt['tax_su_non_habit_surf2'] !== null |
1437 |
&& $val_dt['tax_su_non_habit_surf2'] !== '') |
1438 |
|| ($val_dt['tax_su_non_habit_surf3'] !== null |
1439 |
&& $val_dt['tax_su_non_habit_surf3'] !== ''))) { |
1440 |
// |
1441 |
$val_dt['tax_su_non_habit_surf8'] = intval($val_dt['tax_su_non_habit_surf2']) + intval($val_dt['tax_su_non_habit_surf3']); |
1442 |
} |
1443 |
if (isset($val_dt['tax_su_non_habit_surf_stat2']) === true |
1444 |
&& isset($val_dt['tax_su_non_habit_surf_stat3']) === true |
1445 |
&& (($val_dt['tax_su_non_habit_surf_stat2'] !== null |
1446 |
&& $val_dt['tax_su_non_habit_surf_stat2'] !== '') |
1447 |
|| ($val_dt['tax_su_non_habit_surf_stat3'] !== null |
1448 |
&& $val_dt['tax_su_non_habit_surf_stat3'] !== ''))) { |
1449 |
// |
1450 |
$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']); |
1451 |
} |
1452 |
// Cas particulier d'un projet réduit à l'extension d'une habitation existante |
1453 |
$particular_case = false; |
1454 |
$fields_tab_crea_loc_hab = $inst_dt->get_fields_tab_crea_loc_hab(); |
1455 |
foreach ($fields_tab_crea_loc_hab as $field) { |
1456 |
if (isset($val_dt[$field]) === false |
1457 |
|| (isset($val_dt[$field]) === true |
1458 |
&& ($val_dt[$field] === null |
1459 |
|| $val_dt[$field] === ''))) { |
1460 |
// |
1461 |
$particular_case = true; |
1462 |
} |
1463 |
} |
1464 |
if ($particular_case === true) { |
1465 |
if (isset($val_dt['tax_ext_pret']) === true |
1466 |
&& $val_dt['tax_ext_pret'] === 'f') { |
1467 |
// |
1468 |
$val_dt['tax_su_princ_surf1'] = $val_dt['tax_surf_tot_cstr']; |
1469 |
$val_dt['tax_su_princ_surf_stat1'] = $val_dt['tax_surf_loc_stat']; |
1470 |
} |
1471 |
if (isset($val_dt['tax_ext_pret']) === true |
1472 |
&& $val_dt['tax_ext_pret'] === 't') { |
1473 |
// |
1474 |
if (isset($val_dt['tax_ext_desc']) === true) { |
1475 |
if (preg_match('/[pP].*[lL].*[aA].*[iI]/', $val_dt['tax_ext_desc']) === 1 |
1476 |
|| preg_match('/[lL].*[lL].*[tT].*[sS]/', $val_dt['tax_ext_desc']) === 1) { |
1477 |
// |
1478 |
$val_dt['tax_su_princ_surf2'] = $val_dt['tax_surf_tot_cstr']; |
1479 |
$val_dt['tax_su_princ_surf_stat2'] = $val_dt['tax_surf_loc_stat']; |
1480 |
} |
1481 |
// if (preg_match('/[pP].*[tT].*[zZ]/', $val_dt['tax_ext_desc']) === 1) { |
1482 |
// $val_dt['tax_su_princ_surf4'] = $val_dt['tax_surf_tot_cstr']; |
1483 |
// $val_dt['tax_su_princ_surf_stat4'] = $val_dt['tax_surf_loc_stat']; |
1484 |
// } |
1485 |
// if (preg_match('/[pP].*[lL].*[uU].*[sS]/', $val_dt['tax_ext_desc']) === 1 |
1486 |
// || preg_match('/[lL].*[eE].*[sS]/', $val_dt['tax_ext_desc']) === 1 |
1487 |
// || preg_match('/[pP].*[sS].*[lL].*[aA]/', $val_dt['tax_ext_desc']) === 1 |
1488 |
// || preg_match('/[pP].*[lL].*[sS]/', $val_dt['tax_ext_desc']) === 1 |
1489 |
// || preg_match('/[lL].*[lL].*[sS]/', $val_dt['tax_ext_desc']) === 1) { |
1490 |
// // |
1491 |
// $val_dt['tax_su_princ_surf3'] = $val_dt['tax_surf_tot_cstr']; |
1492 |
// $val_dt['tax_su_princ_surf_stat3'] = $val_dt['tax_surf_loc_stat']; |
1493 |
// } |
1494 |
} |
1495 |
} |
1496 |
} |
1497 |
// Cas particulier de la surface taxable démolie |
1498 |
if (isset($val_dt['tax_surf_tot_demo']) === true |
1499 |
&& isset($val_dt['tax_surf_tax_demo']) === true |
1500 |
&& ($val_dt['tax_surf_tot_demo'] === null |
1501 |
|| $val_dt['tax_surf_tot_demo'] === '')) { |
1502 |
// |
1503 |
$val_dt['tax_surf_tot_demo'] = $val_dt['tax_surf_tax_demo']; |
1504 |
} |
1505 |
return $val_dt; |
1506 |
} |
1507 |
|
1508 |
/** |
1509 |
* Récupère la liste des objets distincts existants dans la table des liens |
1510 |
* entre identifiants internes et identifiants externes. |
1511 |
* |
1512 |
* @return array |
1513 |
*/ |
1514 |
protected function get_list_distinct_objects_external_link() { |
1515 |
$query = sprintf(' |
1516 |
SELECT |
1517 |
DISTINCT(object) |
1518 |
FROM %1$slien_id_interne_uid_externe |
1519 |
ORDER BY object ASC |
1520 |
', |
1521 |
DB_PREFIXE |
1522 |
); |
1523 |
$res = $this->f->get_all_results_from_db_query( |
1524 |
$query, |
1525 |
array( |
1526 |
"origin" => __METHOD__, |
1527 |
"force_return" => true, |
1528 |
) |
1529 |
); |
1530 |
if ($res['code'] === 'KO') { |
1531 |
return array(); |
1532 |
} |
1533 |
$result = array(); |
1534 |
foreach ($res['result'] as $object) { |
1535 |
$result[] = $object['object']; |
1536 |
} |
1537 |
return $result; |
1538 |
} |
1539 |
|
1540 |
protected function get_external_uid($fk_idx, string $fk_idx_2, $fk_idx_3 = PLATAU, $order_asc_desc = 'DESC') { |
1541 |
$inst_external_uid = $this->f->get_inst__by_other_idx(array( |
1542 |
"obj" => "lien_id_interne_uid_externe", |
1543 |
"fk_field" => 'object_id', |
1544 |
"fk_idx" => $fk_idx, |
1545 |
"fk_field_2" => 'object', |
1546 |
"fk_idx_2" => $fk_idx_2, |
1547 |
"fk_field_3" => 'category', |
1548 |
"fk_idx_3" => $fk_idx_3, |
1549 |
"order_field" => 'lien_id_interne_uid_externe', |
1550 |
"order_asc_desc" => $order_asc_desc, |
1551 |
)); |
1552 |
return $inst_external_uid->getVal('external_uid'); |
1553 |
} |
1554 |
|
1555 |
protected function get_all_external_uids($fk_idx, $link_objects = array(), $category=PLATAU) { |
1556 |
if (count($link_objects) == 0) { |
1557 |
$link_objects = $this->get_list_distinct_objects_external_link(); |
1558 |
} |
1559 |
$val_external_uid = array(); |
1560 |
foreach ($link_objects as $link_object) { |
1561 |
$external_uid = $this->get_external_uid($fk_idx, $link_object, $category); |
1562 |
if ($external_uid !== '' && $external_uid !== null) { |
1563 |
$val_external_uid[$link_object] = $external_uid; |
1564 |
} |
1565 |
} |
1566 |
return $val_external_uid; |
1567 |
} |
1568 |
|
1569 |
protected function get_demandeurs_data($dossier) { |
1570 |
$val_demandeur = array(); |
1571 |
if ($dossier === null) { |
1572 |
return $val_demandeur; |
1573 |
} |
1574 |
$inst_di = $this->f->get_inst__om_dbform(array( |
1575 |
"obj" => "dossier", |
1576 |
"idx" => $dossier, |
1577 |
)); |
1578 |
$list_demandeurs = $inst_di->get_demandeurs(); |
1579 |
foreach ($list_demandeurs as $demandeur) { |
1580 |
$inst_demandeur = $this->f->get_inst__om_dbform(array( |
1581 |
"obj" => "demandeur", |
1582 |
"idx" => $demandeur['demandeur'], |
1583 |
)); |
1584 |
$val_demandeur[$demandeur['demandeur']] = $inst_demandeur->get_json_data(); |
1585 |
$val_demandeur[$demandeur['demandeur']]['petitionnaire_principal'] = $demandeur['petitionnaire_principal']; |
1586 |
} |
1587 |
return $val_demandeur; |
1588 |
} |
1589 |
|
1590 |
protected function get_architecte_data($architecte = null) { |
1591 |
$val_architecte = null; |
1592 |
if ($architecte !== null |
1593 |
&& $architecte !== '') { |
1594 |
// |
1595 |
$inst_architecte = $this->f->get_inst__om_dbform(array( |
1596 |
"obj" => "architecte", |
1597 |
"idx" => $architecte, |
1598 |
)); |
1599 |
$val_architecte = $inst_architecte->get_json_data(); |
1600 |
} |
1601 |
return $val_architecte; |
1602 |
} |
1603 |
|
1604 |
protected function get_instruction_data($dossier, $type = 'decision', $extra_params = array()) { |
1605 |
$val_instruction = null; |
1606 |
if ($dossier === null) { |
1607 |
return $val_instruction; |
1608 |
} |
1609 |
$instruction_with_doc = null; |
1610 |
$inst_di = $this->f->get_inst__om_dbform(array( |
1611 |
"obj" => "dossier", |
1612 |
"idx" => $dossier, |
1613 |
)); |
1614 |
$idx = null; |
1615 |
if ($type === 'decision') { |
1616 |
$idx = $inst_di->get_last_instruction_decision(); |
1617 |
} |
1618 |
if ($type === 'incompletude') { |
1619 |
$idx = $inst_di->get_last_instruction_incompletude(); |
1620 |
} |
1621 |
// XXX Permet de récupérer l'instruction par son identifiant |
1622 |
if ($type === 'with-id') { |
1623 |
$idx = $extra_params['with-id']; |
1624 |
} |
1625 |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
1626 |
"obj" => "instruction", |
1627 |
"idx" => $idx, |
1628 |
)); |
1629 |
if (count($inst_instruction->val) > 0) { |
1630 |
$val_instruction = array(); |
1631 |
$instruction_data = $inst_instruction->get_json_data(); |
1632 |
$val_instruction = $this->sort_instruction_data($instruction_data, $val_instruction); |
1633 |
if ($instruction_data['om_fichier_instruction'] !== null |
1634 |
&& $instruction_data['om_fichier_instruction'] !== '') { |
1635 |
// |
1636 |
$instruction_with_doc = $inst_instruction->getVal($inst_instruction->clePrimaire); |
1637 |
} |
1638 |
$inst_ev = $this->f->get_inst__om_dbform(array( |
1639 |
"obj" => "evenement", |
1640 |
"idx" => $inst_instruction->getVal('evenement'), |
1641 |
)); |
1642 |
if ($inst_ev->getVal('retour') === 't') { |
1643 |
$instructions_related = $inst_instruction->get_related_instructions(); |
1644 |
foreach ($instructions_related as $instruction) { |
1645 |
if ($instruction !== null && $instruction !== '') { |
1646 |
$inst_related_instruction = $this->f->get_inst__om_dbform(array( |
1647 |
"obj" => "instruction", |
1648 |
"idx" => $instruction, |
1649 |
)); |
1650 |
$instruction_data = $inst_related_instruction->get_json_data(); |
1651 |
$val_instruction = $this->sort_instruction_data($instruction_data, $val_instruction); |
1652 |
if ($instruction_data['om_fichier_instruction'] !== null |
1653 |
&& $instruction_data['om_fichier_instruction'] !== '') { |
1654 |
// |
1655 |
$instruction_with_doc = $inst_related_instruction->getVal($inst_related_instruction->clePrimaire); |
1656 |
} |
1657 |
} |
1658 |
} |
1659 |
} |
1660 |
if ($instruction_with_doc !== null) { |
1661 |
// |
1662 |
$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); |
1663 |
} |
1664 |
} |
1665 |
return $val_instruction; |
1666 |
} |
1667 |
|
1668 |
|
1669 |
/** |
1670 |
* Récupère les informations pour les notifications ayant plusieurs annexe |
1671 |
*/ |
1672 |
protected function get_instruction_notification_data($category, $type = '', $extra_params = array()) { |
1673 |
$val_in = null; |
1674 |
|
1675 |
$idx = null; |
1676 |
if ($type === 'with-id') { |
1677 |
$idx = $extra_params['with-id']; |
1678 |
} |
1679 |
|
1680 |
// Récupération du type de notification. Le type est nécessaire pour récupérer |
1681 |
// le message et le titre de notification. |
1682 |
$typeNotification = $this->getVal('type'); |
1683 |
if (isset($this->valF['type'])) { |
1684 |
$typeNotification = $this->valF['type']; |
1685 |
} |
1686 |
|
1687 |
// récupére les données à intégrer à la payload |
1688 |
$inst_in = $this->f->get_inst__om_dbform(array( |
1689 |
"obj" => "instruction_notification", |
1690 |
"idx" => $idx, |
1691 |
)); |
1692 |
if (count($inst_in->val) > 0) { |
1693 |
$val_in = $inst_in->get_json_data(); |
1694 |
|
1695 |
$val_in['parametre_courriel_type_titre'] = ''; |
1696 |
$val_in['parametre_courriel_type_message'] = ''; |
1697 |
// Récupération du message et du titre |
1698 |
if ($category === 'mail') { |
1699 |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
1700 |
"obj" => "instruction", |
1701 |
"idx" => $inst_in->getVal('instruction'), |
1702 |
)); |
1703 |
$collectivite_id = $inst_instruction->get_dossier_instruction_om_collectivite($inst_instruction->getVal('dossier')); |
1704 |
$phrase_type_notification = $this->f->get_notification_parametre_courriel_type($collectivite_id, $typeNotification); |
1705 |
$val_in['parametre_courriel_type_titre'] = $phrase_type_notification['parametre_courriel_type_titre']; |
1706 |
$val_in['parametre_courriel_type_message'] = $phrase_type_notification['parametre_courriel_type_message']; |
1707 |
} |
1708 |
|
1709 |
// Récupération des liens vers les documents et des id et type des annexes |
1710 |
$infoDocNotif = $inst_in->getInfosDocumentsNotif($inst_in->getVal($inst_in->clePrimaire), $category); |
1711 |
$cle = $category == PORTAL ? 'path' : 'lien_telechargement_document'; |
1712 |
$val_in[$cle] = $infoDocNotif['document']['path']; |
1713 |
$val_in['annexes'] = $infoDocNotif['annexes']; |
1714 |
} |
1715 |
return $val_in; |
1716 |
} |
1717 |
|
1718 |
protected function sort_instruction_data(array $values, array $res) { |
1719 |
$fields = array( |
1720 |
"date_evenement", |
1721 |
"date_envoi_signature", |
1722 |
"date_retour_signature", |
1723 |
"date_envoi_rar", |
1724 |
"date_retour_rar", |
1725 |
"date_envoi_controle_legalite", |
1726 |
"date_retour_controle_legalite", |
1727 |
"signataire_arrete", |
1728 |
"om_fichier_instruction", |
1729 |
"tacite", |
1730 |
"lettretype", |
1731 |
"commentaire", |
1732 |
"complement_om_html", |
1733 |
); |
1734 |
foreach ($values as $key => $value) { |
1735 |
if (in_array($key, $fields) === true) { |
1736 |
if (array_key_exists($key, $res) === false |
1737 |
&& $value !== null |
1738 |
&& $value !== '') { |
1739 |
// |
1740 |
$res[$key] = $value; |
1741 |
} elseif ($key === 'tacite' |
1742 |
&& $value === 't') { |
1743 |
// |
1744 |
$res[$key] = $value; |
1745 |
} |
1746 |
} |
1747 |
} |
1748 |
return $res; |
1749 |
} |
1750 |
|
1751 |
/** |
1752 |
* Permet de définir si l'instruction passée en paramètre est une instruction |
1753 |
* récépissé d'une demande et si la demande en question a générée un dossier d'instruction. |
1754 |
* |
1755 |
* @param integer $instruction Identifiant de l'instruction |
1756 |
* @return boolean |
1757 |
*/ |
1758 |
protected function is_demande_instruction_recepisse_without_dossier($instruction) { |
1759 |
if ($instruction === null) { |
1760 |
return false; |
1761 |
} |
1762 |
$qres = $this->f->get_one_result_from_db_query( |
1763 |
sprintf( |
1764 |
'SELECT |
1765 |
demande_type.dossier_instruction_type |
1766 |
FROM |
1767 |
%1$sdemande |
1768 |
INNER JOIN %1$sdemande_type |
1769 |
ON demande.demande_type = demande_type.demande_type |
1770 |
WHERE |
1771 |
demande.instruction_recepisse = %2$s', |
1772 |
DB_PREFIXE, |
1773 |
intval($instruction) |
1774 |
), |
1775 |
array( |
1776 |
"origin" => __METHOD__, |
1777 |
"force_return" => true, |
1778 |
) |
1779 |
); |
1780 |
if ($qres["code"] !== "OK") { |
1781 |
return null; |
1782 |
} |
1783 |
if ($qres["result"] === "") { |
1784 |
return true; |
1785 |
} |
1786 |
return false; |
1787 |
} |
1788 |
|
1789 |
protected function get_document_numerise_data(string $dn) { |
1790 |
$val_dn = array(); |
1791 |
$inst_dn = $this->f->get_inst__om_dbform(array( |
1792 |
"obj" => "document_numerise", |
1793 |
"idx" => $dn, |
1794 |
)); |
1795 |
$val_dn = $inst_dn->get_json_data(); |
1796 |
$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')); |
1797 |
// Correspond à la nomenclature Plat'AU NATURE_PIECE |
1798 |
$val_dn['nature'] = $val_dn['document_numerise_nature_libelle']; |
1799 |
return $val_dn; |
1800 |
} |
1801 |
|
1802 |
protected function get_parcelles_data(string $object, string $idx) { |
1803 |
$val_dp = array(); |
1804 |
$inst_di = $this->f->get_inst__om_dbform(array( |
1805 |
"obj" => $object, |
1806 |
"idx" => $idx, |
1807 |
)); |
1808 |
$list_parcelles = $inst_di->get_parcelles(); |
1809 |
$no_ordre = 1; |
1810 |
foreach ($list_parcelles as $parcelle) { |
1811 |
$val_dp[$parcelle[$object.'_parcelle']] = array( |
1812 |
$object.'_parcelle' => $parcelle[$object.'_parcelle'], |
1813 |
'libelle' => $parcelle['libelle'], |
1814 |
'no_ordre' => $no_ordre, |
1815 |
); |
1816 |
$no_ordre++; |
1817 |
} |
1818 |
return $val_dp; |
1819 |
} |
1820 |
|
1821 |
protected function get_avis_decision_data(string $dossier) { |
1822 |
$inst_di = $this->f->get_inst__om_dbform(array( |
1823 |
"obj" => "dossier", |
1824 |
"idx" => $dossier, |
1825 |
)); |
1826 |
$ad = $inst_di->getVal('avis_decision'); |
1827 |
$val_ad = array(); |
1828 |
if ($ad !== null) { |
1829 |
$inst_ad = $this->f->get_inst__om_dbform(array( |
1830 |
"obj" => "avis_decision", |
1831 |
"idx" => $ad, |
1832 |
)); |
1833 |
$val_ad = $inst_ad->get_json_data(); |
1834 |
$val_ad['txAvis'] = "Voir document joint"; |
1835 |
if (isset($val_ad['tacite']) === true |
1836 |
&& $val_ad['tacite'] === 't') { |
1837 |
// |
1838 |
$val_ad['txAvis'] = "Sans objet"; |
1839 |
} |
1840 |
} |
1841 |
return $val_ad; |
1842 |
} |
1843 |
|
1844 |
protected function get_signataire_arrete_data(string $sa) { |
1845 |
$inst_sa = $this->f->get_inst__om_dbform(array( |
1846 |
"obj" => "signataire_arrete", |
1847 |
"idx" => $sa, |
1848 |
)); |
1849 |
$val_sa = array_combine($inst_sa->champs, $inst_sa->val); |
1850 |
foreach ($val_sa as $key => $value) { |
1851 |
$val_sa[$key] = strip_tags($value); |
1852 |
} |
1853 |
return $val_sa; |
1854 |
} |
1855 |
|
1856 |
// XXX WIP |
1857 |
protected function get_consultation_data(string $consultation) { |
1858 |
$val_consultation = array(); |
1859 |
$inst_consultation = $this->f->get_inst__om_dbform(array( |
1860 |
"obj" => "consultation", |
1861 |
"idx" => $consultation, |
1862 |
)); |
1863 |
$val_consultation = $inst_consultation->get_json_data(); |
1864 |
if (isset($val_consultation['fichier']) === true |
1865 |
&& $val_consultation['fichier'] !== '') { |
1866 |
// |
1867 |
$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')); |
1868 |
} |
1869 |
if (isset($val_consultation['om_fichier_consultation']) === true |
1870 |
&& $val_consultation['om_fichier_consultation'] !== '') { |
1871 |
// |
1872 |
$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')); |
1873 |
} |
1874 |
return $val_consultation; |
1875 |
} |
1876 |
|
1877 |
// XXX WIP |
1878 |
protected function get_service_data(string $service) { |
1879 |
$val_service = array(); |
1880 |
$inst_service = $this->f->get_inst__om_dbform(array( |
1881 |
"obj" => "service", |
1882 |
"idx" => $service, |
1883 |
)); |
1884 |
$val_service = $inst_service->get_json_data(); |
1885 |
return $val_service; |
1886 |
} |
1887 |
|
1888 |
protected function view_form_json($in_field = false) { |
1889 |
// |
1890 |
if ($this->f->get_submitted_post_value('valid') === null |
1891 |
&& $this->getVal('state') !== self::STATUS_CANCELED) { |
1892 |
// Liste des valeurs à afficher |
1893 |
$val = array(); |
1894 |
// |
1895 |
$val_task = array_combine($this->champs, $this->val); |
1896 |
foreach ($val_task as $key => $value) { |
1897 |
$val_task[$key] = strip_tags($value); |
1898 |
} |
1899 |
$val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true); |
1900 |
unset($val_task['timestamp_log_hidden']); |
1901 |
$val['task'] = $val_task; |
1902 |
// |
1903 |
if ($this->getVal('type') === 'creation_DA' |
1904 |
|| $this->getVal('type') === 'modification_DA') { |
1905 |
// |
1906 |
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id')); |
1907 |
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation'); |
1908 |
$val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']); |
1909 |
$val_external_uid = array(); |
1910 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation'); |
1911 |
$val['external_uids'] = $val_external_uid; |
1912 |
} |
1913 |
// |
1914 |
if ($this->getVal('type') === 'creation_DI' |
1915 |
|| $this->getVal('type') === 'modification_DI' |
1916 |
|| $this->getVal('type') === 'depot_DI') { |
1917 |
// |
1918 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
1919 |
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_instruction'); |
1920 |
$val['demandeur'] = $this->get_demandeurs_data($val['dossier']['dossier']); |
1921 |
$architecte = isset($val['donnees_techniques']['architecte']) === true ? $val['donnees_techniques']['architecte'] : null; |
1922 |
$val['architecte'] = $this->get_architecte_data($architecte); |
1923 |
$val['dossier_parcelle'] = $this->get_parcelles_data('dossier', $val['dossier']['dossier']); |
1924 |
$val_external_uid = array(); |
1925 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1926 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1927 |
$val['external_uids'] = $val_external_uid; |
1928 |
} |
1929 |
// |
1930 |
if ($this->getVal('type') === 'qualification_DI') { |
1931 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1932 |
$val_external_uid = array(); |
1933 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1934 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1935 |
$val['external_uids'] = $val_external_uid; |
1936 |
} |
1937 |
// |
1938 |
if ($this->getVal('type') === 'ajout_piece') { |
1939 |
$val['document_numerise'] = $this->get_document_numerise_data($this->getVal('object_id')); |
1940 |
$val['dossier'] = $this->get_dossier_data($val['document_numerise']['dossier']); |
1941 |
$val_external_uid = array(); |
1942 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1943 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1944 |
$val_external_uid['piece'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'piece'); |
1945 |
$val['external_uids'] = $val_external_uid; |
1946 |
} |
1947 |
// |
1948 |
if ($this->getVal('type') === 'decision_DI') { |
1949 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1950 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1951 |
$val['instruction']['final'] = 't'; |
1952 |
if (isset($val['instruction']['signataire_arrete']) === true) { |
1953 |
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
1954 |
} |
1955 |
$val_external_uid = array(); |
1956 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1957 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1958 |
$val['external_uids'] = $val_external_uid; |
1959 |
} |
1960 |
// |
1961 |
if ($this->getVal('type') === 'incompletude_DI') { |
1962 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1963 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1964 |
$val_external_uid = array(); |
1965 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1966 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1967 |
$val['external_uids'] = $val_external_uid; |
1968 |
} |
1969 |
// |
1970 |
if ($this->getVal('type') === 'completude_DI') { |
1971 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1972 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'with-id', array('with-id' => $this->getVal('object_id'))); |
1973 |
$val_external_uid = array(); |
1974 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1975 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1976 |
$val['external_uids'] = $val_external_uid; |
1977 |
} |
1978 |
// |
1979 |
if ($this->getVal('type') === 'pec_metier_consultation') { |
1980 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1981 |
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1982 |
$val_external_uid = array(); |
1983 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1984 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1985 |
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
1986 |
$val['external_uids'] = $val_external_uid; |
1987 |
} |
1988 |
// |
1989 |
if ($this->getVal('type') === 'avis_consultation') { |
1990 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
1991 |
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
1992 |
$val['avis_decision'] = $this->get_avis_decision_data($this->getVal('dossier')); |
1993 |
if (isset($val['instruction']['signataire_arrete']) === true) { |
1994 |
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
1995 |
} |
1996 |
$val_external_uid = array(); |
1997 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
1998 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
1999 |
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
2000 |
$val_external_uid['avis_dossier_consultation'] = $this->get_external_uid($this->getVal('object_id'), 'avis_dossier_consultation'); |
2001 |
$val['external_uids'] = $val_external_uid; |
2002 |
} |
2003 |
// XXX WIP |
2004 |
if ($this->getVal('type') === 'creation_consultation') { |
2005 |
// |
2006 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2007 |
$val['consultation'] = $this->get_consultation_data($this->getVal('object_id')); |
2008 |
$val['service'] = $this->get_service_data($val['consultation']['service']); |
2009 |
$val_external_uid = array(); |
2010 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2011 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2012 |
$val['external_uids'] = $val_external_uid; |
2013 |
} |
2014 |
// |
2015 |
if ($this->getVal('type') === 'envoi_CL') { |
2016 |
// |
2017 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2018 |
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
2019 |
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($val['dossier']['dossier_autorisation']); |
2020 |
$val_external_uid = array(); |
2021 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2022 |
$val_external_uid['dossier'] = $this->get_external_uid($this->getVal('dossier'), 'dossier'); |
2023 |
$val_external_uid['decision'] = $this->get_external_uid($this->getVal('object_id'), 'instruction'); |
2024 |
if ($val_external_uid['decision'] === '') { |
2025 |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
2026 |
"obj" => "instruction", |
2027 |
"idx" => $this->getVal('object_id'), |
2028 |
)); |
2029 |
$val_external_uid['decision'] = $this->get_external_uid($inst_instruction->get_related_instructions_next('retour_signature'), 'instruction'); |
2030 |
} |
2031 |
$val['external_uids'] = $val_external_uid; |
2032 |
} |
2033 |
if ($this->getVal('type') === 'notification_instruction' |
2034 |
|| $this->getVal('type') === 'notification_recepisse' |
2035 |
|| $this->getVal('type') === 'notification_decision' |
2036 |
|| $this->getVal('type') === 'notification_service_consulte' |
2037 |
|| $this->getVal('type') === 'notification_tiers_consulte') { |
2038 |
// |
2039 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2040 |
$dossier_id = isset($val['dossier']['dossier']) === true ? $val['dossier']['dossier'] : null; |
2041 |
$val['demandeur'] = $this->get_demandeurs_data($dossier_id); |
2042 |
$val['instruction_notification'] = $this->get_instruction_notification_data($this->getVal('category'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
2043 |
$instruction_id = isset($val['instruction_notification']['instruction']) === true ? $val['instruction_notification']['instruction'] : null; |
2044 |
$instruction_annexes = isset($val['instruction_notification']['annexes']) === true ? $val['instruction_notification']['annexes'] : null; |
2045 |
$val['instruction'] = $this->get_instruction_data($dossier_id, 'with-id', array('with-id' => $instruction_id)); |
2046 |
// Précise qu'il s'agit d'une instruction final si l'instruction est liée à une |
2047 |
// demande dont le type ne génère pas de dossier |
2048 |
if ($this->is_demande_instruction_recepisse_without_dossier($instruction_id) === true) { |
2049 |
$val['instruction']['final'] = 't'; |
2050 |
} |
2051 |
$val_external_uid = array(); |
2052 |
// Affiche l'identifiant externe lié à l'instruction si cette combinaison existe, sinon celui lié au dossier |
2053 |
$val_external_uid['demande'] = $this->get_external_uid($instruction_id, 'demande') !== '' ? $this->get_external_uid($instruction_id, 'demande') : $this->get_external_uid($dossier_id, 'demande'); |
2054 |
$val_external_uid['demande (instruction)'] = $this->get_external_uid($instruction_id, 'demande', PORTAL, 'ASC'); |
2055 |
$val_external_uid['instruction_notification'] = $this->get_external_uid($this->getVal('object_id'), 'instruction_notification', PORTAL); |
2056 |
$val['external_uids'] = $val_external_uid; |
2057 |
} |
2058 |
// |
2059 |
if ($this->getVal('type') === 'prescription') { |
2060 |
$val['dossier'] = $this->get_dossier_data($this->getVal('dossier')); |
2061 |
$val['instruction'] = $this->get_instruction_data($this->getVal('dossier'), 'with-id', array('with-id' => $this->getVal('object_id'))); |
2062 |
$val['avis_decision'] = $this->get_avis_decision_data($this->getVal('dossier')); |
2063 |
if (isset($val['instruction']['signataire_arrete']) === true) { |
2064 |
$val['signataire_arrete'] = $this->get_signataire_arrete_data($val['instruction']['signataire_arrete']); |
2065 |
} |
2066 |
$val_external_uid = array(); |
2067 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
2068 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
2069 |
$val_external_uid['dossier_consultation'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier_consultation'); |
2070 |
$val_external_uid['prescription'] = $this->get_external_uid($this->getVal('object_id'), 'prescription'); |
2071 |
$val['external_uids'] = $val_external_uid; |
2072 |
} |
2073 |
|
2074 |
if ($in_field === true) { |
2075 |
return json_encode($val, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
2076 |
} else { |
2077 |
// Liste des valeurs affichée en JSON |
2078 |
echo(json_encode($val, JSON_UNESCAPED_SLASHES)); |
2079 |
} |
2080 |
} |
2081 |
} |
2082 |
|
2083 |
function post_update_task() { |
2084 |
// Mise à jour des valeurs |
2085 |
|
2086 |
// Modification de l'état de la tâche |
2087 |
if ($this->f->get_submitted_post_value('state') !== null) { |
2088 |
$params = array( |
2089 |
'val' => array( |
2090 |
'state' => $this->f->get_submitted_post_value('state') |
2091 |
), |
2092 |
); |
2093 |
$update = $this->update_task($params); |
2094 |
$message_class = "valid"; |
2095 |
$message = $this->msg; |
2096 |
if ($update === false) { |
2097 |
$this->addToLog($this->msg, DEBUG_MODE); |
2098 |
$message_class = "error"; |
2099 |
$message = sprintf( |
2100 |
'%s %s', |
2101 |
__('Impossible de mettre à jour la tâche.'), |
2102 |
__('Veuillez contacter votre administrateur.') |
2103 |
); |
2104 |
} |
2105 |
$this->f->displayMessage($message_class, $message); |
2106 |
} |
2107 |
|
2108 |
// Sauvegarde de l'uid externe retourné |
2109 |
if ($this->f->get_submitted_post_value('external_uid') !== null) { |
2110 |
// |
2111 |
$objects = $this->get_objects_by_task_type($this->getVal('type'), $this->getVal('stream')); |
2112 |
foreach ($objects as $object) { |
2113 |
$inst_lien = $this->f->get_inst__om_dbform(array( |
2114 |
"obj" => "lien_id_interne_uid_externe", |
2115 |
"idx" => ']', |
2116 |
)); |
2117 |
$object_id = $this->getVal('object_id'); |
2118 |
$is_exists = $inst_lien->is_exists($object, $object_id, $this->f->get_submitted_post_value('external_uid'), $this->getVal('dossier')); |
2119 |
// Dans le cas spécifique de la mise à jour d'une notification |
2120 |
// et de la création d'une liaison d'identifiant pour l'objet demande, |
2121 |
// l'identifiant de l'objet n'est plus celui de la notification |
2122 |
// d'instruction mais celui du dossier d'instruction |
2123 |
if ($object === 'demande' |
2124 |
&& ($this->getVal('type') === 'notification_recepisse' |
2125 |
|| $this->getVal('type') === 'notification_instruction' |
2126 |
|| $this->getVal('type') === 'notification_decision' |
2127 |
|| $this->getVal('type') === 'notification_service_consulte' |
2128 |
|| $this->getVal('type') === 'notification_tiers_consulte')) { |
2129 |
// |
2130 |
$object_id = $this->getVal('dossier'); |
2131 |
// Il ne doit y avoir qu'une liaison entre le numéro du dossier interne et un uid externe de "demande" |
2132 |
$is_exists = $inst_lien->is_exists($object, $object_id, null, $this->getVal('dossier')); |
2133 |
} |
2134 |
if ($is_exists === false) { |
2135 |
$valF = array( |
2136 |
'lien_id_interne_uid_externe' => '', |
2137 |
'object' => $object, |
2138 |
'object_id' => $object_id, |
2139 |
'external_uid' => $this->f->get_submitted_post_value('external_uid'), |
2140 |
'dossier' => $this->getVal('dossier'), |
2141 |
'category' => $this->getVal('category'), |
2142 |
); |
2143 |
$add = $inst_lien->ajouter($valF); |
2144 |
$message_class = "valid"; |
2145 |
$message = $inst_lien->msg; |
2146 |
if ($add === false) { |
2147 |
$this->addToLog($inst_lien->msg, DEBUG_MODE); |
2148 |
$message_class = "error"; |
2149 |
$message = sprintf( |
2150 |
'%s %s', |
2151 |
__("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."), |
2152 |
__('Veuillez contacter votre administrateur.') |
2153 |
); |
2154 |
} |
2155 |
$this->f->displayMessage($message_class, $message); |
2156 |
} |
2157 |
} |
2158 |
} |
2159 |
} |
2160 |
|
2161 |
function post_add_task() { |
2162 |
// TODO Tester de remplacer la ligne de json_payload par un $_POST |
2163 |
$result = $this->add_task(array( |
2164 |
'val' => array( |
2165 |
'stream' => 'input', |
2166 |
'json_payload' => html_entity_decode($this->f->get_submitted_post_value('json_payload')), |
2167 |
'type' => $this->f->get_submitted_post_value('type'), |
2168 |
'category' => $this->f->get_submitted_post_value('category'), |
2169 |
) |
2170 |
)); |
2171 |
$message = sprintf( |
2172 |
__("Tâche %s ajoutée avec succès"), |
2173 |
$this->getVal($this->clePrimaire)). |
2174 |
'<br/><br/>'. |
2175 |
$this->msg; |
2176 |
$message_class = "valid"; |
2177 |
if ($result === false){ |
2178 |
$this->addToLog($this->msg, DEBUG_MODE); |
2179 |
$message_class = "error"; |
2180 |
$message = sprintf( |
2181 |
'%s %s', |
2182 |
__('Impossible d\'ajouter la tâche.'), |
2183 |
__('Veuillez contacter votre administrateur.') |
2184 |
); |
2185 |
} |
2186 |
$this->f->displayMessage($message_class, $message); |
2187 |
} |
2188 |
|
2189 |
function setLayout(&$form, $maj) { |
2190 |
// |
2191 |
$form->setBloc('json_payload', 'D', '', 'col_6'); |
2192 |
$form->setFieldset('json_payload', 'DF', __("json_payload"), "collapsible, startClosed"); |
2193 |
$form->setBloc('json_payload', 'F'); |
2194 |
$form->setBloc('timestamp_log', 'DF', __("historique"), 'col_9 timestamp_log_jsontotab'); |
2195 |
} |
2196 |
|
2197 |
/** |
2198 |
* Récupère le nom de l'objet à mentionner dans la table lien_id_interne_uid_externe |
2199 |
* en fonction du type et du stream de la tâche. |
2200 |
* |
2201 |
* @param string $type Type de la tâche |
2202 |
* @param string $stream Stream de la tâche |
2203 |
* |
2204 |
* @return array |
2205 |
*/ |
2206 |
function get_objects_by_task_type($type, $stream = 'all') { |
2207 |
$objects = array(); |
2208 |
if (in_array($type, array('creation_DA', 'modification_DA', )) === true) { |
2209 |
$objects = array('dossier_autorisation', ); |
2210 |
} |
2211 |
if (in_array($type, array('creation_DI', 'depot_DI', 'notification_DI', 'qualification_DI', )) === true) { |
2212 |
$objects = array('dossier', ); |
2213 |
} |
2214 |
if (in_array($type, array('create_DI_for_consultation', )) === true) { |
2215 |
$objects = array('dossier', 'dossier_consultation', ); |
2216 |
} |
2217 |
if (in_array($type, array('create_DI', )) === true |
2218 |
&& $stream === 'input') { |
2219 |
$objects = array('dossier', 'dossier_autorisation', 'demande', ); |
2220 |
} |
2221 |
if (in_array($type, array('decision_DI', 'incompletude_DI', 'completude_DI', )) === true) { |
2222 |
$objects = array('instruction', ); |
2223 |
} |
2224 |
if (in_array($type, array('envoi_CL', )) === true) { |
2225 |
$objects = array('instruction_action_cl', ); |
2226 |
} |
2227 |
if (in_array($type, array('pec_metier_consultation', )) === true |
2228 |
&& $stream === 'output') { |
2229 |
$objects = array('pec_dossier_consultation', ); |
2230 |
} |
2231 |
if (in_array($type, array('avis_consultation', )) === true |
2232 |
&& $stream === 'output') { |
2233 |
$objects = array('avis_dossier_consultation', ); |
2234 |
} |
2235 |
if (in_array($type, array('prescription', )) === true |
2236 |
&& $stream === 'output') { |
2237 |
$objects = array('prescription', ); |
2238 |
} |
2239 |
if (in_array($type, array('ajout_piece', 'add_piece', )) === true) { |
2240 |
$objects = array('piece', ); |
2241 |
} |
2242 |
if (in_array($type, array('creation_consultation', )) === true) { |
2243 |
$objects = array('consultation', ); |
2244 |
} |
2245 |
if (in_array($type, array('pec_metier_consultation', )) === true |
2246 |
&& $stream === 'input') { |
2247 |
$objects = array('pec_metier_consultation', ); |
2248 |
} |
2249 |
if (in_array($type, array('avis_consultation', )) === true |
2250 |
&& $stream === 'input') { |
2251 |
$objects = array('avis_consultation', ); |
2252 |
} |
2253 |
if (in_array($type, array('create_message', )) === true |
2254 |
&& $stream === 'input') { |
2255 |
$objects = array('dossier_message', ); |
2256 |
} |
2257 |
if (in_array( |
2258 |
$type, |
2259 |
array( |
2260 |
'notification_recepisse', |
2261 |
'notification_instruction', |
2262 |
'notification_decision', |
2263 |
'notification_service_consulte', |
2264 |
'notification_tiers_consulte', |
2265 |
) |
2266 |
) === true) { |
2267 |
$objects = array('instruction_notification', 'demande', ); |
2268 |
} |
2269 |
return $objects; |
2270 |
} |
2271 |
|
2272 |
/** |
2273 |
* Récupère les tables auxquelles pourrait être rattaché l'objet lié à la tâche, |
2274 |
* par rapport à son type. |
2275 |
* |
2276 |
* @param string $type Type de la tâche |
2277 |
* @param string $stream input ou output |
2278 |
* @return array |
2279 |
*/ |
2280 |
function get_tables_by_task_type($type, $stream = 'all') { |
2281 |
$tables = array(); |
2282 |
if (in_array($type, array('creation_DA', 'modification_DA', )) === true) { |
2283 |
$tables = array('dossier_autorisation', ); |
2284 |
} |
2285 |
if (in_array($type, array('creation_DI', 'depot_DI', )) === true) { |
2286 |
$tables = array('dossier', ); |
2287 |
} |
2288 |
if (in_array($type, array('qualification_DI', )) === true) { |
2289 |
$tables = array('instruction', 'dossier', ); |
2290 |
} |
2291 |
if (in_array($type, array('create_DI_for_consultation', )) === true) { |
2292 |
$tables = array('dossier', ); |
2293 |
} |
2294 |
if (in_array($type, array('create_DI', )) === true |
2295 |
&& $stream === 'input') { |
2296 |
$tables = array('dossier', 'dossier_autorisation', 'demande', ); |
2297 |
} |
2298 |
if (in_array($type, array('decision_DI', 'incompletude_DI', 'completude_DI', )) === true) { |
2299 |
$tables = array('instruction', ); |
2300 |
} |
2301 |
if (in_array($type, array('pec_metier_consultation', )) === true |
2302 |
&& $stream === 'output') { |
2303 |
$tables = array('instruction', ); |
2304 |
} |
2305 |
if (in_array($type, array('avis_consultation', )) === true |
2306 |
&& $stream === 'output') { |
2307 |
$tables = array('instruction', ); |
2308 |
} |
2309 |
if (in_array($type, array('prescription', )) === true |
2310 |
&& $stream === 'output') { |
2311 |
$tables = array('instruction', ); |
2312 |
} |
2313 |
if (in_array($type, array('ajout_piece', 'add_piece', )) === true) { |
2314 |
$tables = array('document_numerise', ); |
2315 |
} |
2316 |
if (in_array($type, array('creation_consultation', )) === true) { |
2317 |
$tables = array('consultation', ); |
2318 |
} |
2319 |
if (in_array($type, array('pec_metier_consultation', )) === true |
2320 |
&& $stream === 'input') { |
2321 |
$tables = array('consultation', ); |
2322 |
} |
2323 |
if (in_array($type, array('avis_consultation', )) === true |
2324 |
&& $stream === 'input') { |
2325 |
$tables = array('consultation', ); |
2326 |
} |
2327 |
if (in_array($type, array('create_message', )) === true |
2328 |
&& $stream === 'input') { |
2329 |
$tables = array('dossier_message', ); |
2330 |
} |
2331 |
if (in_array( |
2332 |
$type, |
2333 |
array( |
2334 |
'notification_recepisse', |
2335 |
'notification_instruction', |
2336 |
'notification_decision', |
2337 |
'notification_service_consulte', |
2338 |
'notification_tiers_consulte' |
2339 |
) |
2340 |
) === true) { |
2341 |
$tables = array('instruction_notification', ); |
2342 |
} |
2343 |
return $tables; |
2344 |
} |
2345 |
|
2346 |
} |