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