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