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