1 |
<?php |
2 |
//$Id$ |
3 |
//gen openMairie le 14/04/2020 14:11 |
4 |
|
5 |
require_once "../gen/obj/task.class.php"; |
6 |
|
7 |
class task extends task_gen { |
8 |
|
9 |
/** |
10 |
* Définition des actions disponibles sur la classe. |
11 |
* |
12 |
* @return void |
13 |
*/ |
14 |
public function init_class_actions() { |
15 |
parent::init_class_actions(); |
16 |
// |
17 |
$this->class_actions[998] = array( |
18 |
"identifier" => "json_data", |
19 |
"view" => "view_json_data", |
20 |
"permission_suffix" => "consulter", |
21 |
); |
22 |
} |
23 |
|
24 |
public function setvalF($val = array()) { |
25 |
parent::setvalF($val); |
26 |
// |
27 |
if (array_key_exists('timestamp_log', $val) === true) { |
28 |
$this->valF['timestamp_log'] = str_replace("'", '"', $val['timestamp_log']); |
29 |
} |
30 |
} |
31 |
|
32 |
/** |
33 |
* |
34 |
* @return array |
35 |
*/ |
36 |
function get_var_sql_forminc__champs() { |
37 |
return array( |
38 |
"task", |
39 |
"type", |
40 |
"state", |
41 |
"object_id", |
42 |
"dossier", |
43 |
"timestamp_log", |
44 |
); |
45 |
} |
46 |
|
47 |
function setType(&$form, $maj) { |
48 |
parent::setType($form, $maj); |
49 |
// Récupération du mode de l'action |
50 |
$crud = $this->get_action_crud($maj); |
51 |
|
52 |
if ($maj < 2) { |
53 |
$form->setType("state", "select"); |
54 |
} |
55 |
if ($maj == 3){ |
56 |
$form->setType('dossier', 'link'); |
57 |
} |
58 |
|
59 |
} |
60 |
|
61 |
/** |
62 |
* |
63 |
*/ |
64 |
function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) { |
65 |
if($maj < 2) { |
66 |
$contenu=array(); |
67 |
|
68 |
$contenu[0][0]="draft"; |
69 |
$contenu[1][0]=_('draft'); |
70 |
$contenu[0][1]="new"; |
71 |
$contenu[1][1]=_('new'); |
72 |
$contenu[0][2]="pending"; |
73 |
$contenu[1][2]=_('pending'); |
74 |
$contenu[0][3]="done"; |
75 |
$contenu[1][3]=_('done'); |
76 |
$contenu[0][4]="archived"; |
77 |
$contenu[1][4]=_('archived'); |
78 |
$contenu[0][5]="error"; |
79 |
$contenu[1][5]=_('error'); |
80 |
$contenu[0][6]="debug"; |
81 |
$contenu[1][6]=_('debug'); |
82 |
|
83 |
$form->setSelect("state", $contenu); |
84 |
} |
85 |
|
86 |
if ($maj == 3) { |
87 |
$inst_dossier = $this->f->get_inst__om_dbform(array( |
88 |
"obj" => "dossier", |
89 |
"idx" => $form->val['dossier'], |
90 |
)); |
91 |
|
92 |
if($form->val['type'] == "creation_DA"){ |
93 |
$obj_link = 'dossier_autorisation'; |
94 |
} else { |
95 |
$obj_link = 'dossier_instruction'; |
96 |
} |
97 |
|
98 |
$params = array(); |
99 |
$params['obj'] = $obj_link; |
100 |
$params['libelle'] = $inst_dossier->getVal('dossier'); |
101 |
$params['title'] = "Consulter le dossier"; |
102 |
$params['idx'] = $form->val['dossier']; |
103 |
$form->setSelect("dossier", $params); |
104 |
} |
105 |
} |
106 |
|
107 |
public function verifier($val = array(), &$dnu1 = null, $dnu2 = null) { |
108 |
parent::verifier($val, $dnu1, $dnu2); |
109 |
// |
110 |
if (array_key_exists('timestamp_log', $this->valF) === true |
111 |
&& is_array(json_decode($this->valF['timestamp_log'], true)) === false) { |
112 |
// |
113 |
$this->correct = false; |
114 |
$this->addToMessage(sprintf( |
115 |
__("Le champ %s doit être dans un format JSON valide."), |
116 |
sprintf('<span class="bold">%s</span>', $this->getLibFromField('timestamp_log')) |
117 |
)); |
118 |
} |
119 |
} |
120 |
|
121 |
protected function task_exists(string $type, string $object_id) { |
122 |
$query = sprintf(' |
123 |
SELECT task |
124 |
FROM %1$stask |
125 |
WHERE state != \'%2$s\' |
126 |
AND type = \'%3$s\' |
127 |
AND object_id = \'%4$s\' |
128 |
', |
129 |
DB_PREFIXE, |
130 |
'done', |
131 |
$type, |
132 |
$object_id |
133 |
); |
134 |
$res = $this->f->get_one_result_from_db_query($query); |
135 |
if ($res['result'] !== null && $res['result'] !== '') { |
136 |
return $res['result']; |
137 |
} |
138 |
return false; |
139 |
} |
140 |
|
141 |
/** |
142 |
* TREATMENT - add_task |
143 |
* Ajoute un enregistrement. |
144 |
* |
145 |
* @param array $params Tableau des paramètres |
146 |
* @return boolean |
147 |
*/ |
148 |
public function add_task($params = array()) { |
149 |
$this->begin_treatment(__METHOD__); |
150 |
$timestamp_log = json_encode(array( |
151 |
'creation_date' => date('Y-m-d H:i:s'), |
152 |
)); |
153 |
// Mise à jour du DI |
154 |
$valF = array( |
155 |
'task' => '', |
156 |
'type' => $params['val']['type'], |
157 |
'timestamp_log' => $timestamp_log, |
158 |
'state' => isset($params['val']['state']) === true ? $params['val']['state'] : 'new', |
159 |
'object_id' => $params['val']['object_id'], |
160 |
'dossier' => $params['val']['dossier'], |
161 |
); |
162 |
$task_exists = $this->task_exists($valF['type'], $valF['object_id']); |
163 |
if ($valF['type'] === 'modification_DI' && $task_exists === false) { |
164 |
$task_exists = $this->task_exists('creation_DI', $valF['object_id']); |
165 |
} |
166 |
if ($task_exists !== false) { |
167 |
$inst_task = $this->f->get_inst__om_dbform(array( |
168 |
"obj" => "task", |
169 |
"idx" => $task_exists, |
170 |
)); |
171 |
$update_state = $inst_task->getVal('state'); |
172 |
if (isset($params['update_val']['state']) === true) { |
173 |
$update_state = $params['update_val']['state']; |
174 |
} |
175 |
$update_params = array( |
176 |
'val' => array( |
177 |
'state' => $update_state, |
178 |
), |
179 |
); |
180 |
return $inst_task->update_task($update_params); |
181 |
} |
182 |
$add = $this->ajouter($valF); |
183 |
if ($add === false) { |
184 |
$this->addToLog($this->msg, DEBUG_MODE); |
185 |
return $this->end_treatment(__METHOD__, false); |
186 |
} |
187 |
return $this->end_treatment(__METHOD__, true); |
188 |
} |
189 |
|
190 |
/** |
191 |
* TREATMENT - update_task |
192 |
* Met à jour l'enregistrement instancié. |
193 |
* |
194 |
* @param array $params Tableau des paramètres |
195 |
* @return boolean |
196 |
*/ |
197 |
public function update_task($params = array()) { |
198 |
$this->begin_treatment(__METHOD__); |
199 |
$timestamp_log = $this->get_timestamp_log(); |
200 |
if ($timestamp_log === false) { |
201 |
$this->addToLog(__('XXX'), DEBUG_MODE); |
202 |
return $this->end_treatment(__METHOD__, false); |
203 |
} |
204 |
array_push($timestamp_log, array( |
205 |
'modification_date' => date('Y-m-d H:i:s'), |
206 |
'state' => $params['val']['state'], |
207 |
'prev_state' => $this->getVal('state'), |
208 |
)); |
209 |
$timestamp_log = json_encode($timestamp_log); |
210 |
$valF = array( |
211 |
'task' => $this->getVal($this->clePrimaire), |
212 |
'type' => $this->getVal('type'), |
213 |
'timestamp_log' => $timestamp_log, |
214 |
'state' => $params['val']['state'], |
215 |
'object_id' => $this->getVal('object_id'), |
216 |
'dossier' => $this->getVal('dossier'), |
217 |
); |
218 |
$update = $this->modifier($valF); |
219 |
if ($update === false) { |
220 |
$this->addToLog($this->msg, DEBUG_MODE); |
221 |
return $this->end_treatment(__METHOD__, false); |
222 |
} |
223 |
return $this->end_treatment(__METHOD__, true); |
224 |
} |
225 |
|
226 |
/** |
227 |
* Récupère le journal d'horodatage dans le champ timestamp_log de |
228 |
* l'enregistrement instancié. |
229 |
* |
230 |
* @param array $params Tableau des paramètres |
231 |
* @return array sinon false en cas d'erreur |
232 |
*/ |
233 |
protected function get_timestamp_log($params = array()) { |
234 |
$val = $this->getVal('timestamp_log'); |
235 |
if ($val === '') { |
236 |
$val = json_encode(array()); |
237 |
} |
238 |
if($this->isJson($val) === false) { |
239 |
return false; |
240 |
} |
241 |
return json_decode($val, true); |
242 |
} |
243 |
|
244 |
/** |
245 |
* VIEW - view_json_data |
246 |
* Affiche l'enregistrement dans le format JSON. |
247 |
* |
248 |
* @return void |
249 |
*/ |
250 |
public function view_json_data() { |
251 |
$this->checkAccessibility(); |
252 |
$this->f->disableLog(); |
253 |
if ($this->getParameter('idx') !== ']' |
254 |
&& $this->getParameter('idx') !== '0') { |
255 |
// |
256 |
$this->view_form_json(); |
257 |
} |
258 |
else { |
259 |
$this->view_tab_json(); |
260 |
} |
261 |
} |
262 |
|
263 |
protected function view_tab_json() { |
264 |
$where = ''; |
265 |
if ($this->f->get_submitted_get_value('state') !== null |
266 |
&& $this->f->get_submitted_get_value('state') !== '') { |
267 |
// |
268 |
$where = sprintf(' WHERE state = \'%s\' ', $this->f->get_submitted_get_value('state')); |
269 |
} |
270 |
$query = sprintf(' |
271 |
SELECT |
272 |
* |
273 |
FROM %1$stask |
274 |
%2$s |
275 |
ORDER BY task ASC |
276 |
', |
277 |
DB_PREFIXE, |
278 |
$where |
279 |
); |
280 |
$res = $this->f->get_all_results_from_db_query($query, true); |
281 |
if ($res['code'] === 'KO') { |
282 |
return false; |
283 |
} |
284 |
$list_tasks = array(); |
285 |
foreach ($res['result'] as $task) { |
286 |
$task['timestamp_log'] = json_decode($task['timestamp_log'], true); |
287 |
$task['dossier'] = $task['object_id']; |
288 |
if ($this->get_lien_objet_by_type($task['type']) === 'document_numerise') { |
289 |
$val_dn = $this->get_document_numerise_data($task['object_id']); |
290 |
$task['dossier'] = $val_dn['dossier']; |
291 |
} |
292 |
$list_tasks[$task['task']] = $task; |
293 |
} |
294 |
printf(json_encode($list_tasks)); |
295 |
} |
296 |
|
297 |
protected function get_dossier_data(string $dossier) { |
298 |
$val_di = array(); |
299 |
$inst_di = $this->f->get_inst__om_dbform(array( |
300 |
"obj" => "dossier", |
301 |
"idx" => $dossier, |
302 |
)); |
303 |
$val_di = $inst_di->get_json_data(); |
304 |
if ($val_di['dossier_instruction_type_code'] === 'T') { |
305 |
$val_di['date_decision_transfert'] = $val_di['date_decision']; |
306 |
} |
307 |
unset($val_di['initial_dt']); |
308 |
unset($val_di['log_instructions']); |
309 |
return $val_di; |
310 |
} |
311 |
|
312 |
protected function get_dossier_autorisation_data(string $da) { |
313 |
$val_da = array(); |
314 |
$inst_da = $this->f->get_inst__om_dbform(array( |
315 |
"obj" => "dossier_autorisation", |
316 |
"idx" => $da, |
317 |
)); |
318 |
$val_da = $inst_da->get_json_data(); |
319 |
return $val_da; |
320 |
} |
321 |
|
322 |
protected function get_donnees_techniques_data(string $fk_idx, string $fk_field) { |
323 |
$val_dt = array(); |
324 |
$inst_dt = $this->f->get_inst__by_other_idx(array( |
325 |
"obj" => "donnees_techniques", |
326 |
"fk_field" => $fk_field, |
327 |
"fk_idx" => $fk_idx, |
328 |
)); |
329 |
$val_dt = array( |
330 |
'donnees_techniques' => $inst_dt->getVal($inst_dt->clePrimaire), |
331 |
'cerfa' => $inst_dt->getVal('cerfa'), |
332 |
); |
333 |
$val_dt = array_merge($val_dt, $inst_dt->get_donnees_techniques_applicables()); |
334 |
if (isset($val_dt['am_exist_date']) === true) { |
335 |
$val_dt['am_exist_date_num'] = ''; |
336 |
if (is_numeric($val_dt['am_exist_date']) === true) { |
337 |
$val_dt['am_exist_date_num'] = $val_dt['am_exist_date']; |
338 |
} |
339 |
} |
340 |
// Correspond à la nomenclature de Plat'AU STATUT_INFO |
341 |
$val_dt['tax_statut_info'] = 'Déclaré'; |
342 |
// |
343 |
if ($inst_dt->is_tab_surf_ssdest_enabled() === true) { |
344 |
$fields_tab_surf_dest = $inst_dt->get_fields_tab_surf_dest(); |
345 |
foreach ($fields_tab_surf_dest as $field) { |
346 |
if (isset($val_dt[$field]) === true) { |
347 |
unset($val_dt[$field]); |
348 |
} |
349 |
} |
350 |
} else { |
351 |
$fields_tab_surf_ssdest = $inst_dt->get_fields_tab_surf_ssdest(); |
352 |
foreach ($fields_tab_surf_ssdest as $field) { |
353 |
if (isset($val_dt[$field]) === true) { |
354 |
unset($val_dt[$field]); |
355 |
} |
356 |
} |
357 |
} |
358 |
// Correspond à la nouvelle ligne CERFA v7 dans le DENSI imposition 1.2.3 |
359 |
if (isset($val_dt['tax_su_non_habit_surf2']) === true |
360 |
&& isset($val_dt['tax_su_non_habit_surf3']) === true |
361 |
&& (($val_dt['tax_su_non_habit_surf2'] !== null |
362 |
&& $val_dt['tax_su_non_habit_surf2'] !== '') |
363 |
|| ($val_dt['tax_su_non_habit_surf3'] !== null |
364 |
&& $val_dt['tax_su_non_habit_surf3'] !== ''))) { |
365 |
// |
366 |
$val_dt['tax_su_non_habit_surf8'] = intval($val_dt['tax_su_non_habit_surf2']) + intval($val_dt['tax_su_non_habit_surf3']); |
367 |
} |
368 |
if (isset($val_dt['tax_su_non_habit_surf_stat2']) === true |
369 |
&& isset($val_dt['tax_su_non_habit_surf_stat3']) === true |
370 |
&& (($val_dt['tax_su_non_habit_surf_stat2'] !== null |
371 |
&& $val_dt['tax_su_non_habit_surf_stat2'] !== '') |
372 |
|| ($val_dt['tax_su_non_habit_surf_stat3'] !== null |
373 |
&& $val_dt['tax_su_non_habit_surf_stat3'] !== ''))) { |
374 |
// |
375 |
$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']); |
376 |
} |
377 |
// Cas particulier d'un projet réduit à l'extension d'une habitation existante |
378 |
$particular_case = false; |
379 |
$fields_tab_crea_loc_hab = $inst_dt->get_fields_tab_crea_loc_hab(); |
380 |
foreach ($fields_tab_crea_loc_hab as $field) { |
381 |
if (isset($val_dt[$field]) === false |
382 |
|| (isset($val_dt[$field]) === true |
383 |
&& ($val_dt[$field] === null |
384 |
|| $val_dt[$field] === ''))) { |
385 |
// |
386 |
$particular_case = true; |
387 |
} |
388 |
} |
389 |
if ($particular_case === true) { |
390 |
if (isset($val_dt['tax_ext_pret']) === true |
391 |
&& $val_dt['tax_ext_pret'] === 'f') { |
392 |
// |
393 |
$val_dt['tax_su_princ_surf1'] = $val_dt['tax_surf_tot_cstr']; |
394 |
$val_dt['tax_su_princ_surf_stat1'] = $val_dt['tax_surf_loc_stat']; |
395 |
} |
396 |
if (isset($val_dt['tax_ext_pret']) === true |
397 |
&& $val_dt['tax_ext_pret'] === 't') { |
398 |
// |
399 |
if (isset($val_dt['tax_ext_desc']) === true) { |
400 |
if (preg_match('/[pP].*[lL].*[aA].*[iI]/', $val_dt['tax_ext_desc']) === 1 |
401 |
|| preg_match('/[lL].*[lL].*[tT].*[sS]/', $val_dt['tax_ext_desc']) === 1) { |
402 |
// |
403 |
$val_dt['tax_su_princ_surf2'] = $val_dt['tax_surf_tot_cstr']; |
404 |
$val_dt['tax_su_princ_surf_stat2'] = $val_dt['tax_surf_loc_stat']; |
405 |
} |
406 |
// if (preg_match('/[pP].*[tT].*[zZ]/', $val_dt['tax_ext_desc']) === 1) { |
407 |
// $val_dt['tax_su_princ_surf4'] = $val_dt['tax_surf_tot_cstr']; |
408 |
// $val_dt['tax_su_princ_surf_stat4'] = $val_dt['tax_surf_loc_stat']; |
409 |
// } |
410 |
// if (preg_match('/[pP].*[lL].*[uU].*[sS]/', $val_dt['tax_ext_desc']) === 1 |
411 |
// || preg_match('/[lL].*[eE].*[sS]/', $val_dt['tax_ext_desc']) === 1 |
412 |
// || preg_match('/[pP].*[sS].*[lL].*[aA]/', $val_dt['tax_ext_desc']) === 1 |
413 |
// || preg_match('/[pP].*[lL].*[sS]/', $val_dt['tax_ext_desc']) === 1 |
414 |
// || preg_match('/[lL].*[lL].*[sS]/', $val_dt['tax_ext_desc']) === 1) { |
415 |
// // |
416 |
// $val_dt['tax_su_princ_surf3'] = $val_dt['tax_surf_tot_cstr']; |
417 |
// $val_dt['tax_su_princ_surf_stat3'] = $val_dt['tax_surf_loc_stat']; |
418 |
// } |
419 |
} |
420 |
} |
421 |
} |
422 |
// Cas particulier de la surface taxable démolie |
423 |
if (isset($val_dt['tax_surf_tot_demo']) === true |
424 |
&& isset($val_dt['tax_surf_tax_demo']) === true |
425 |
&& ($val_dt['tax_surf_tot_demo'] === null |
426 |
|| $val_dt['tax_surf_tot_demo'] === '')) { |
427 |
// |
428 |
$val_dt['tax_surf_tot_demo'] = $val_dt['tax_surf_tax_demo']; |
429 |
} |
430 |
return $val_dt; |
431 |
} |
432 |
|
433 |
protected function get_external_uid($fk_idx, string $fk_idx_2) { |
434 |
$inst_external_uid = $this->f->get_inst__by_other_idx(array( |
435 |
"obj" => "lien_id_interne_uid_externe", |
436 |
"fk_field" => 'object_id', |
437 |
"fk_idx" => $fk_idx, |
438 |
"fk_field_2" => 'object', |
439 |
"fk_idx_2" => $fk_idx_2, |
440 |
)); |
441 |
return $inst_external_uid->getVal('external_uid'); |
442 |
} |
443 |
|
444 |
protected function get_demandeurs_data(string $dossier) { |
445 |
$val_demandeur = array(); |
446 |
$inst_di = $this->f->get_inst__om_dbform(array( |
447 |
"obj" => "dossier", |
448 |
"idx" => $dossier, |
449 |
)); |
450 |
$list_demandeurs = $inst_di->get_demandeurs(); |
451 |
foreach ($list_demandeurs as $demandeur) { |
452 |
$inst_demandeur = $this->f->get_inst__om_dbform(array( |
453 |
"obj" => "demandeur", |
454 |
"idx" => $demandeur['demandeur'], |
455 |
)); |
456 |
$val_demandeur[$demandeur['demandeur']] = $inst_demandeur->get_json_data(); |
457 |
$val_demandeur[$demandeur['demandeur']]['petitionnaire_principal'] = $demandeur['petitionnaire_principal']; |
458 |
} |
459 |
return $val_demandeur; |
460 |
} |
461 |
|
462 |
protected function get_architecte_data($architecte = null) { |
463 |
$val_architecte = null; |
464 |
if ($architecte !== null |
465 |
&& $architecte !== '') { |
466 |
// |
467 |
$inst_architecte = $this->f->get_inst__om_dbform(array( |
468 |
"obj" => "architecte", |
469 |
"idx" => $architecte, |
470 |
)); |
471 |
$val_architecte = $inst_architecte->get_json_data(); |
472 |
} |
473 |
return $val_architecte; |
474 |
} |
475 |
|
476 |
protected function get_instruction_data(string $dossier, $type = 'decision') { |
477 |
$val_instruction = null; |
478 |
$instruction_with_doc = null; |
479 |
$inst_di = $this->f->get_inst__om_dbform(array( |
480 |
"obj" => "dossier", |
481 |
"idx" => $dossier, |
482 |
)); |
483 |
$idx = null; |
484 |
if ($type === 'decision') { |
485 |
$idx = $inst_di->get_last_instruction_decision(); |
486 |
} |
487 |
if ($type === 'incompletude') { |
488 |
$idx = $inst_di->get_last_instruction_incompletude(); |
489 |
} |
490 |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
491 |
"obj" => "instruction", |
492 |
"idx" => $idx, |
493 |
)); |
494 |
if (count($inst_instruction->val) > 0) { |
495 |
$val_instruction = array(); |
496 |
$instruction_data = $inst_instruction->get_json_data(); |
497 |
$val_instruction = $this->sort_instruction_data($instruction_data, $val_instruction); |
498 |
if ($instruction_data['om_fichier_instruction'] !== null |
499 |
&& $instruction_data['om_fichier_instruction'] !== '') { |
500 |
// |
501 |
$instruction_with_doc = $inst_instruction->getVal($inst_instruction->clePrimaire); |
502 |
} |
503 |
$inst_ev = $this->f->get_inst__om_dbform(array( |
504 |
"obj" => "evenement", |
505 |
"idx" => $inst_instruction->getVal('evenement'), |
506 |
)); |
507 |
if ($inst_ev->getVal('retour') === 't') { |
508 |
$instructions_related = $inst_instruction->get_related_instructions(); |
509 |
foreach ($instructions_related as $instruction) { |
510 |
if ($instruction !== null && $instruction !== '') { |
511 |
$inst_related_instruction = $this->f->get_inst__om_dbform(array( |
512 |
"obj" => "instruction", |
513 |
"idx" => $instruction, |
514 |
)); |
515 |
$instruction_data = $inst_related_instruction->get_json_data(); |
516 |
$val_instruction = $this->sort_instruction_data($instruction_data, $val_instruction); |
517 |
if ($instruction_data['om_fichier_instruction'] !== null |
518 |
&& $instruction_data['om_fichier_instruction'] !== '') { |
519 |
// |
520 |
$instruction_with_doc = $inst_related_instruction->getVal($inst_related_instruction->clePrimaire); |
521 |
} |
522 |
} |
523 |
} |
524 |
} |
525 |
if ($instruction_with_doc !== null) { |
526 |
// |
527 |
$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); |
528 |
} |
529 |
} |
530 |
return $val_instruction; |
531 |
} |
532 |
|
533 |
protected function sort_instruction_data(array $values, array $res) { |
534 |
$fields = array( |
535 |
"date_envoi_signature", |
536 |
"date_retour_signature", |
537 |
"date_envoi_rar", |
538 |
"date_retour_rar", |
539 |
"date_envoi_controle_legalite", |
540 |
"date_retour_controle_legalite", |
541 |
"signataire_arrete", |
542 |
"om_fichier_instruction", |
543 |
"tacite", |
544 |
); |
545 |
foreach ($values as $key => $value) { |
546 |
if (in_array($key, $fields) === true) { |
547 |
if (array_key_exists($key, $res) === false |
548 |
&& $value !== null |
549 |
&& $value !== '') { |
550 |
// |
551 |
$res[$key] = $value; |
552 |
} elseif ($key === 'tacite' |
553 |
&& $value === 't') { |
554 |
// |
555 |
$res[$key] = $value; |
556 |
} |
557 |
} |
558 |
} |
559 |
return $res; |
560 |
} |
561 |
|
562 |
protected function get_document_numerise_data(string $dn) { |
563 |
$val_dn = array(); |
564 |
$inst_dn = $this->f->get_inst__om_dbform(array( |
565 |
"obj" => "document_numerise", |
566 |
"idx" => $dn, |
567 |
)); |
568 |
$val_dn = $inst_dn->get_json_data(); |
569 |
$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')); |
570 |
// Correspond à la nomenclature Plat'AU NATURE_PIECE |
571 |
$val_dn['nature'] = $val_dn['document_numerise_nature_libelle']; |
572 |
return $val_dn; |
573 |
} |
574 |
|
575 |
protected function get_parcelles_data(string $object, string $idx) { |
576 |
$val_dp = array(); |
577 |
$inst_di = $this->f->get_inst__om_dbform(array( |
578 |
"obj" => $object, |
579 |
"idx" => $idx, |
580 |
)); |
581 |
$list_parcelles = $inst_di->get_parcelles(); |
582 |
$no_ordre = 1; |
583 |
foreach ($list_parcelles as $parcelle) { |
584 |
$val_dp[$parcelle[$object.'_parcelle']] = array( |
585 |
$object.'_parcelle' => $parcelle[$object.'_parcelle'], |
586 |
'libelle' => $parcelle['libelle'], |
587 |
'no_ordre' => $no_ordre, |
588 |
); |
589 |
$no_ordre++; |
590 |
} |
591 |
return $val_dp; |
592 |
} |
593 |
|
594 |
protected function view_form_json() { |
595 |
// Mise à jour des valeurs |
596 |
if ($this->f->get_submitted_post_value('valid') === 'true' |
597 |
&& $this->f->get_submitted_post_value('state') !== null) { |
598 |
// |
599 |
$params = array( |
600 |
'val' => array( |
601 |
'state' => $this->f->get_submitted_post_value('state') |
602 |
), |
603 |
); |
604 |
$update = $this->update_task($params); |
605 |
$message_class = "valid"; |
606 |
$message = $this->msg; |
607 |
if ($update === false) { |
608 |
$this->addToLog($this->msg, DEBUG_MODE); |
609 |
$message_class = "error"; |
610 |
$message = sprintf( |
611 |
'%s %s', |
612 |
__('Impossible de mettre à jour la tâche.'), |
613 |
__('Veuillez contacter votre administrateur.') |
614 |
); |
615 |
} |
616 |
$this->f->displayMessage($message_class, $message); |
617 |
} |
618 |
// |
619 |
if ($this->f->get_submitted_post_value('valid') === 'true' |
620 |
&& $this->f->get_submitted_post_value('external_uid') !== null) { |
621 |
// |
622 |
$inst_lien = $this->f->get_inst__om_dbform(array( |
623 |
"obj" => "lien_id_interne_uid_externe", |
624 |
"idx" => ']', |
625 |
)); |
626 |
$valF = array( |
627 |
'lien_id_interne_uid_externe' => '', |
628 |
'object' => $this->get_lien_objet_by_type($this->getVal('type')), |
629 |
'object_id' => $this->getVal('object_id'), |
630 |
'external_uid' => $this->f->get_submitted_post_value('external_uid'), |
631 |
); |
632 |
$add = $inst_lien->ajouter($valF); |
633 |
$message_class = "valid"; |
634 |
$message = $inst_lien->msg; |
635 |
if ($add === false) { |
636 |
$this->addToLog($inst_lien->msg, DEBUG_MODE); |
637 |
$message_class = "error"; |
638 |
$message = sprintf( |
639 |
'%s %s', |
640 |
__("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."), |
641 |
__('Veuillez contacter votre administrateur.') |
642 |
); |
643 |
} |
644 |
$this->f->displayMessage($message_class, $message); |
645 |
} |
646 |
|
647 |
// |
648 |
if ($this->f->get_submitted_post_value('valid') === null) { |
649 |
// Liste des valeurs à afficher |
650 |
$val = array(); |
651 |
// |
652 |
$val_task = array_combine($this->champs, $this->val); |
653 |
foreach ($val_task as $key => $value) { |
654 |
$val_task[$key] = strip_tags($value); |
655 |
} |
656 |
$val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true); |
657 |
$val['task'] = $val_task; |
658 |
// |
659 |
if ($this->getVal('type') === 'creation_DA') { |
660 |
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id')); |
661 |
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation'); |
662 |
$val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']); |
663 |
$val_external_uid = array(); |
664 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation'); |
665 |
$val['external_uid'] = $val_external_uid; |
666 |
} |
667 |
// |
668 |
if ($this->getVal('type') === 'creation_DI' |
669 |
|| $this->getVal('type') === 'modification_DI' |
670 |
|| $this->getVal('type') === 'depot_DI') { |
671 |
// |
672 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
673 |
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_instruction'); |
674 |
$val['demandeur'] = $this->get_demandeurs_data($val['dossier']['dossier']); |
675 |
$architecte = isset($val['donnees_techniques']['architecte']) === true ? $val['donnees_techniques']['architecte'] : null; |
676 |
$val['architecte'] = $this->get_architecte_data($architecte); |
677 |
$val['dossier_parcelle'] = $this->get_parcelles_data('dossier', $val['dossier']['dossier']); |
678 |
$val_external_uid = array(); |
679 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
680 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
681 |
$val['external_uid'] = $val_external_uid; |
682 |
} |
683 |
// |
684 |
if ($this->getVal('type') === 'qualification_DI') { |
685 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
686 |
$val_external_uid = array(); |
687 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
688 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
689 |
$val['external_uid'] = $val_external_uid; |
690 |
} |
691 |
// |
692 |
if ($this->getVal('type') === 'ajout_piece') { |
693 |
$val['document_numerise'] = $this->get_document_numerise_data($this->getVal('object_id')); |
694 |
$val['dossier'] = $this->get_dossier_data($val['document_numerise']['dossier']); |
695 |
$val_external_uid = array(); |
696 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
697 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
698 |
$val_external_uid['document_numerise'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'document_numerise'); |
699 |
$val['external_uid'] = $val_external_uid; |
700 |
} |
701 |
// |
702 |
if ($this->getVal('type') === 'decision_DI') { |
703 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
704 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier']); |
705 |
$val_external_uid = array(); |
706 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
707 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
708 |
$val['external_uid'] = $val_external_uid; |
709 |
} |
710 |
// |
711 |
if ($this->getVal('type') === 'incompletude_DI') { |
712 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
713 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'incompletude'); |
714 |
$val_external_uid = array(); |
715 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
716 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
717 |
$val['external_uid'] = $val_external_uid; |
718 |
} |
719 |
// |
720 |
if ($this->getVal('type') === 'completude_DI') { |
721 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
722 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'completude'); |
723 |
$val_external_uid = array(); |
724 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
725 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
726 |
$val['external_uid'] = $val_external_uid; |
727 |
} |
728 |
|
729 |
// Liste des valeurs affichée en JSON |
730 |
printf(json_encode($val, JSON_UNESCAPED_SLASHES)); |
731 |
} |
732 |
} |
733 |
|
734 |
protected function get_lien_objet_by_type($type) { |
735 |
// |
736 |
$objet = ''; |
737 |
if ($type === 'creation_DA') { |
738 |
$objet = 'dossier_autorisation'; |
739 |
} |
740 |
if ($type === 'creation_DI' |
741 |
|| $type === 'depot_DI' |
742 |
|| $type === 'modification_DI' |
743 |
|| $type === 'qualification_DI' |
744 |
|| $type === 'decision_DI' |
745 |
|| $type === 'incompletude_DI' |
746 |
|| $type === 'completude_DI') { |
747 |
// |
748 |
$objet = 'dossier'; |
749 |
} |
750 |
if ($type === 'ajout_piece') { |
751 |
$objet = 'document_numerise'; |
752 |
} |
753 |
return $objet; |
754 |
} |
755 |
} |