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