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