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