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 |
$this->class_actions[997] = array( |
23 |
"identifier" => "json_data", |
24 |
"view" => "view_update_json_data", |
25 |
"permission_suffix" => "modifier", |
26 |
); |
27 |
$this->class_actions[996] = array( |
28 |
"identifier" => "json_data", |
29 |
"view" => "view_add_json_data", |
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 |
/** |
196 |
* TREATMENT - add_task |
197 |
* Ajoute un enregistrement. |
198 |
* |
199 |
* @param array $params Tableau des paramètres |
200 |
* @return boolean |
201 |
*/ |
202 |
public function add_task($params = array()) { |
203 |
$this->begin_treatment(__METHOD__); |
204 |
$timestamp_log = json_encode(array( |
205 |
'creation_date' => date('Y-m-d H:i:s'), |
206 |
)); |
207 |
// Mise à jour du DI |
208 |
$valF = array( |
209 |
'task' => '', |
210 |
'type' => $params['val']['type'], |
211 |
'timestamp_log' => $timestamp_log, |
212 |
'state' => isset($params['val']['state']) === true ? $params['val']['state'] : 'new', |
213 |
'object_id' => $params['val']['object_id'], |
214 |
'dossier' => $params['val']['dossier'], |
215 |
'stream' => isset($params['val']['stream']) === true ? $params['val']['stream'] : 'output', |
216 |
'json_payload' => isset($params['val']['json_payload']) === true ? $params['val']['json_payload'] : '{}', |
217 |
); |
218 |
if($valF["stream"] != "input"){ |
219 |
$task_exists = $this->task_exists($valF['type'], $valF['object_id']); |
220 |
if ($valF['type'] === 'modification_DI' && $task_exists === false) { |
221 |
$task_exists = $this->task_exists('creation_DI', $valF['object_id']); |
222 |
} |
223 |
if ($task_exists !== false) { |
224 |
$inst_task = $this->f->get_inst__om_dbform(array( |
225 |
"obj" => "task", |
226 |
"idx" => $task_exists, |
227 |
)); |
228 |
$update_state = $inst_task->getVal('state'); |
229 |
if (isset($params['update_val']['state']) === true) { |
230 |
$update_state = $params['update_val']['state']; |
231 |
} |
232 |
$update_params = array( |
233 |
'val' => array( |
234 |
'state' => $update_state, |
235 |
), |
236 |
); |
237 |
return $inst_task->update_task($update_params); |
238 |
} |
239 |
} |
240 |
$add = $this->ajouter($valF); |
241 |
if ($add === false) { |
242 |
$this->addToLog($this->msg, DEBUG_MODE); |
243 |
return $this->end_treatment(__METHOD__, false); |
244 |
} |
245 |
return $this->end_treatment(__METHOD__, true); |
246 |
} |
247 |
|
248 |
/** |
249 |
* TREATMENT - update_task |
250 |
* Met à jour l'enregistrement instancié. |
251 |
* |
252 |
* @param array $params Tableau des paramètres |
253 |
* @return boolean |
254 |
*/ |
255 |
public function update_task($params = array()) { |
256 |
$this->begin_treatment(__METHOD__); |
257 |
$timestamp_log = $this->get_timestamp_log(); |
258 |
if ($timestamp_log === false) { |
259 |
$this->addToLog(__('XXX'), DEBUG_MODE); |
260 |
return $this->end_treatment(__METHOD__, false); |
261 |
} |
262 |
array_push($timestamp_log, array( |
263 |
'modification_date' => date('Y-m-d H:i:s'), |
264 |
'state' => $params['val']['state'], |
265 |
'prev_state' => $this->getVal('state'), |
266 |
)); |
267 |
$timestamp_log = json_encode($timestamp_log); |
268 |
$valF = array( |
269 |
'task' => $this->getVal($this->clePrimaire), |
270 |
'type' => $this->getVal('type'), |
271 |
'timestamp_log' => $timestamp_log, |
272 |
'state' => $params['val']['state'], |
273 |
'object_id' => $this->getVal('object_id'), |
274 |
'stream' => $this->getVal('stream'), |
275 |
'dossier' => $this->getVal('dossier'), |
276 |
'json_payload' => $this->getVal('json_payload'), |
277 |
); |
278 |
$update = $this->modifier($valF); |
279 |
if ($update === false) { |
280 |
$this->addToLog($this->msg, DEBUG_MODE); |
281 |
return $this->end_treatment(__METHOD__, false); |
282 |
} |
283 |
return $this->end_treatment(__METHOD__, true); |
284 |
} |
285 |
|
286 |
/** |
287 |
* Récupère le journal d'horodatage dans le champ timestamp_log de |
288 |
* l'enregistrement instancié. |
289 |
* |
290 |
* @param array $params Tableau des paramètres |
291 |
* @return array sinon false en cas d'erreur |
292 |
*/ |
293 |
protected function get_timestamp_log($params = array()) { |
294 |
$val = $this->getVal('timestamp_log'); |
295 |
if ($val === '') { |
296 |
$val = json_encode(array()); |
297 |
} |
298 |
if($this->isJson($val) === false) { |
299 |
return false; |
300 |
} |
301 |
return json_decode($val, true); |
302 |
} |
303 |
|
304 |
/** |
305 |
* VIEW - view_json_data |
306 |
* Affiche l'enregistrement dans le format JSON. |
307 |
* |
308 |
* @return void |
309 |
*/ |
310 |
public function view_json_data() { |
311 |
$this->checkAccessibility(); |
312 |
$this->f->disableLog(); |
313 |
if ($this->getParameter('idx') !== ']' |
314 |
&& $this->getParameter('idx') !== '0') { |
315 |
// |
316 |
$this->view_form_json(); |
317 |
} |
318 |
else { |
319 |
$this->view_tab_json(); |
320 |
} |
321 |
} |
322 |
|
323 |
protected function view_tab_json() { |
324 |
$where = ''; |
325 |
if ($this->f->get_submitted_get_value('state') !== null |
326 |
&& $this->f->get_submitted_get_value('state') !== '') { |
327 |
// |
328 |
$where = sprintf(' WHERE state = \'%s\' ', $this->f->get_submitted_get_value('state')); |
329 |
} |
330 |
$query = sprintf(' |
331 |
SELECT |
332 |
* |
333 |
FROM %1$stask |
334 |
%2$s |
335 |
ORDER BY task ASC |
336 |
', |
337 |
DB_PREFIXE, |
338 |
$where |
339 |
); |
340 |
$res = $this->f->get_all_results_from_db_query($query, true); |
341 |
if ($res['code'] === 'KO') { |
342 |
return false; |
343 |
} |
344 |
$list_tasks = array(); |
345 |
foreach ($res['result'] as $task) { |
346 |
$task['timestamp_log'] = json_decode($task['timestamp_log'], true); |
347 |
$task['dossier'] = $task['object_id']; |
348 |
if ($this->get_lien_objet_by_type($task['type']) === 'document_numerise') { |
349 |
$val_dn = $this->get_document_numerise_data($task['object_id']); |
350 |
$task['dossier'] = $val_dn['dossier']; |
351 |
} |
352 |
$list_tasks[$task['task']] = $task; |
353 |
} |
354 |
printf(json_encode($list_tasks)); |
355 |
} |
356 |
|
357 |
protected function get_dossier_data(string $dossier) { |
358 |
$val_di = array(); |
359 |
$inst_di = $this->f->get_inst__om_dbform(array( |
360 |
"obj" => "dossier", |
361 |
"idx" => $dossier, |
362 |
)); |
363 |
$val_di = $inst_di->get_json_data(); |
364 |
if ($val_di['dossier_instruction_type_code'] === 'T') { |
365 |
$val_di['date_decision_transfert'] = $val_di['date_decision']; |
366 |
} |
367 |
unset($val_di['initial_dt']); |
368 |
unset($val_di['log_instructions']); |
369 |
return $val_di; |
370 |
} |
371 |
|
372 |
protected function get_dossier_autorisation_data(string $da) { |
373 |
$val_da = array(); |
374 |
$inst_da = $this->f->get_inst__om_dbform(array( |
375 |
"obj" => "dossier_autorisation", |
376 |
"idx" => $da, |
377 |
)); |
378 |
$val_da = $inst_da->get_json_data(); |
379 |
return $val_da; |
380 |
} |
381 |
|
382 |
protected function get_donnees_techniques_data(string $fk_idx, string $fk_field) { |
383 |
$val_dt = array(); |
384 |
$inst_dt = $this->f->get_inst__by_other_idx(array( |
385 |
"obj" => "donnees_techniques", |
386 |
"fk_field" => $fk_field, |
387 |
"fk_idx" => $fk_idx, |
388 |
)); |
389 |
$val_dt = array( |
390 |
'donnees_techniques' => $inst_dt->getVal($inst_dt->clePrimaire), |
391 |
'cerfa' => $inst_dt->getVal('cerfa'), |
392 |
); |
393 |
$val_dt = array_merge($val_dt, $inst_dt->get_donnees_techniques_applicables()); |
394 |
if (isset($val_dt['am_exist_date']) === true) { |
395 |
$val_dt['am_exist_date_num'] = ''; |
396 |
if (is_numeric($val_dt['am_exist_date']) === true) { |
397 |
$val_dt['am_exist_date_num'] = $val_dt['am_exist_date']; |
398 |
} |
399 |
} |
400 |
// Correspond à la nomenclature de Plat'AU STATUT_INFO |
401 |
$val_dt['tax_statut_info'] = 'Déclaré'; |
402 |
// |
403 |
if ($inst_dt->is_tab_surf_ssdest_enabled() === true) { |
404 |
$fields_tab_surf_dest = $inst_dt->get_fields_tab_surf_dest(); |
405 |
foreach ($fields_tab_surf_dest as $field) { |
406 |
if (isset($val_dt[$field]) === true) { |
407 |
unset($val_dt[$field]); |
408 |
} |
409 |
} |
410 |
} else { |
411 |
$fields_tab_surf_ssdest = $inst_dt->get_fields_tab_surf_ssdest(); |
412 |
foreach ($fields_tab_surf_ssdest as $field) { |
413 |
if (isset($val_dt[$field]) === true) { |
414 |
unset($val_dt[$field]); |
415 |
} |
416 |
} |
417 |
} |
418 |
// Correspond à la nouvelle ligne CERFA v7 dans le DENSI imposition 1.2.3 |
419 |
if (isset($val_dt['tax_su_non_habit_surf2']) === true |
420 |
&& isset($val_dt['tax_su_non_habit_surf3']) === true |
421 |
&& (($val_dt['tax_su_non_habit_surf2'] !== null |
422 |
&& $val_dt['tax_su_non_habit_surf2'] !== '') |
423 |
|| ($val_dt['tax_su_non_habit_surf3'] !== null |
424 |
&& $val_dt['tax_su_non_habit_surf3'] !== ''))) { |
425 |
// |
426 |
$val_dt['tax_su_non_habit_surf8'] = intval($val_dt['tax_su_non_habit_surf2']) + intval($val_dt['tax_su_non_habit_surf3']); |
427 |
} |
428 |
if (isset($val_dt['tax_su_non_habit_surf_stat2']) === true |
429 |
&& isset($val_dt['tax_su_non_habit_surf_stat3']) === true |
430 |
&& (($val_dt['tax_su_non_habit_surf_stat2'] !== null |
431 |
&& $val_dt['tax_su_non_habit_surf_stat2'] !== '') |
432 |
|| ($val_dt['tax_su_non_habit_surf_stat3'] !== null |
433 |
&& $val_dt['tax_su_non_habit_surf_stat3'] !== ''))) { |
434 |
// |
435 |
$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']); |
436 |
} |
437 |
// Cas particulier d'un projet réduit à l'extension d'une habitation existante |
438 |
$particular_case = false; |
439 |
$fields_tab_crea_loc_hab = $inst_dt->get_fields_tab_crea_loc_hab(); |
440 |
foreach ($fields_tab_crea_loc_hab as $field) { |
441 |
if (isset($val_dt[$field]) === false |
442 |
|| (isset($val_dt[$field]) === true |
443 |
&& ($val_dt[$field] === null |
444 |
|| $val_dt[$field] === ''))) { |
445 |
// |
446 |
$particular_case = true; |
447 |
} |
448 |
} |
449 |
if ($particular_case === true) { |
450 |
if (isset($val_dt['tax_ext_pret']) === true |
451 |
&& $val_dt['tax_ext_pret'] === 'f') { |
452 |
// |
453 |
$val_dt['tax_su_princ_surf1'] = $val_dt['tax_surf_tot_cstr']; |
454 |
$val_dt['tax_su_princ_surf_stat1'] = $val_dt['tax_surf_loc_stat']; |
455 |
} |
456 |
if (isset($val_dt['tax_ext_pret']) === true |
457 |
&& $val_dt['tax_ext_pret'] === 't') { |
458 |
// |
459 |
if (isset($val_dt['tax_ext_desc']) === true) { |
460 |
if (preg_match('/[pP].*[lL].*[aA].*[iI]/', $val_dt['tax_ext_desc']) === 1 |
461 |
|| preg_match('/[lL].*[lL].*[tT].*[sS]/', $val_dt['tax_ext_desc']) === 1) { |
462 |
// |
463 |
$val_dt['tax_su_princ_surf2'] = $val_dt['tax_surf_tot_cstr']; |
464 |
$val_dt['tax_su_princ_surf_stat2'] = $val_dt['tax_surf_loc_stat']; |
465 |
} |
466 |
// if (preg_match('/[pP].*[tT].*[zZ]/', $val_dt['tax_ext_desc']) === 1) { |
467 |
// $val_dt['tax_su_princ_surf4'] = $val_dt['tax_surf_tot_cstr']; |
468 |
// $val_dt['tax_su_princ_surf_stat4'] = $val_dt['tax_surf_loc_stat']; |
469 |
// } |
470 |
// if (preg_match('/[pP].*[lL].*[uU].*[sS]/', $val_dt['tax_ext_desc']) === 1 |
471 |
// || preg_match('/[lL].*[eE].*[sS]/', $val_dt['tax_ext_desc']) === 1 |
472 |
// || preg_match('/[pP].*[sS].*[lL].*[aA]/', $val_dt['tax_ext_desc']) === 1 |
473 |
// || preg_match('/[pP].*[lL].*[sS]/', $val_dt['tax_ext_desc']) === 1 |
474 |
// || preg_match('/[lL].*[lL].*[sS]/', $val_dt['tax_ext_desc']) === 1) { |
475 |
// // |
476 |
// $val_dt['tax_su_princ_surf3'] = $val_dt['tax_surf_tot_cstr']; |
477 |
// $val_dt['tax_su_princ_surf_stat3'] = $val_dt['tax_surf_loc_stat']; |
478 |
// } |
479 |
} |
480 |
} |
481 |
} |
482 |
// Cas particulier de la surface taxable démolie |
483 |
if (isset($val_dt['tax_surf_tot_demo']) === true |
484 |
&& isset($val_dt['tax_surf_tax_demo']) === true |
485 |
&& ($val_dt['tax_surf_tot_demo'] === null |
486 |
|| $val_dt['tax_surf_tot_demo'] === '')) { |
487 |
// |
488 |
$val_dt['tax_surf_tot_demo'] = $val_dt['tax_surf_tax_demo']; |
489 |
} |
490 |
return $val_dt; |
491 |
} |
492 |
|
493 |
protected function get_external_uid($fk_idx, string $fk_idx_2) { |
494 |
$inst_external_uid = $this->f->get_inst__by_other_idx(array( |
495 |
"obj" => "lien_id_interne_uid_externe", |
496 |
"fk_field" => 'object_id', |
497 |
"fk_idx" => $fk_idx, |
498 |
"fk_field_2" => 'object', |
499 |
"fk_idx_2" => $fk_idx_2, |
500 |
)); |
501 |
return $inst_external_uid->getVal('external_uid'); |
502 |
} |
503 |
|
504 |
protected function get_demandeurs_data(string $dossier) { |
505 |
$val_demandeur = array(); |
506 |
$inst_di = $this->f->get_inst__om_dbform(array( |
507 |
"obj" => "dossier", |
508 |
"idx" => $dossier, |
509 |
)); |
510 |
$list_demandeurs = $inst_di->get_demandeurs(); |
511 |
foreach ($list_demandeurs as $demandeur) { |
512 |
$inst_demandeur = $this->f->get_inst__om_dbform(array( |
513 |
"obj" => "demandeur", |
514 |
"idx" => $demandeur['demandeur'], |
515 |
)); |
516 |
$val_demandeur[$demandeur['demandeur']] = $inst_demandeur->get_json_data(); |
517 |
$val_demandeur[$demandeur['demandeur']]['petitionnaire_principal'] = $demandeur['petitionnaire_principal']; |
518 |
} |
519 |
return $val_demandeur; |
520 |
} |
521 |
|
522 |
protected function get_architecte_data($architecte = null) { |
523 |
$val_architecte = null; |
524 |
if ($architecte !== null |
525 |
&& $architecte !== '') { |
526 |
// |
527 |
$inst_architecte = $this->f->get_inst__om_dbform(array( |
528 |
"obj" => "architecte", |
529 |
"idx" => $architecte, |
530 |
)); |
531 |
$val_architecte = $inst_architecte->get_json_data(); |
532 |
} |
533 |
return $val_architecte; |
534 |
} |
535 |
|
536 |
protected function get_instruction_data(string $dossier, $type = 'decision') { |
537 |
$val_instruction = null; |
538 |
$instruction_with_doc = null; |
539 |
$inst_di = $this->f->get_inst__om_dbform(array( |
540 |
"obj" => "dossier", |
541 |
"idx" => $dossier, |
542 |
)); |
543 |
$idx = null; |
544 |
if ($type === 'decision') { |
545 |
$idx = $inst_di->get_last_instruction_decision(); |
546 |
} |
547 |
if ($type === 'incompletude') { |
548 |
$idx = $inst_di->get_last_instruction_incompletude(); |
549 |
} |
550 |
$inst_instruction = $this->f->get_inst__om_dbform(array( |
551 |
"obj" => "instruction", |
552 |
"idx" => $idx, |
553 |
)); |
554 |
if (count($inst_instruction->val) > 0) { |
555 |
$val_instruction = array(); |
556 |
$instruction_data = $inst_instruction->get_json_data(); |
557 |
$val_instruction = $this->sort_instruction_data($instruction_data, $val_instruction); |
558 |
if ($instruction_data['om_fichier_instruction'] !== null |
559 |
&& $instruction_data['om_fichier_instruction'] !== '') { |
560 |
// |
561 |
$instruction_with_doc = $inst_instruction->getVal($inst_instruction->clePrimaire); |
562 |
} |
563 |
$inst_ev = $this->f->get_inst__om_dbform(array( |
564 |
"obj" => "evenement", |
565 |
"idx" => $inst_instruction->getVal('evenement'), |
566 |
)); |
567 |
if ($inst_ev->getVal('retour') === 't') { |
568 |
$instructions_related = $inst_instruction->get_related_instructions(); |
569 |
foreach ($instructions_related as $instruction) { |
570 |
if ($instruction !== null && $instruction !== '') { |
571 |
$inst_related_instruction = $this->f->get_inst__om_dbform(array( |
572 |
"obj" => "instruction", |
573 |
"idx" => $instruction, |
574 |
)); |
575 |
$instruction_data = $inst_related_instruction->get_json_data(); |
576 |
$val_instruction = $this->sort_instruction_data($instruction_data, $val_instruction); |
577 |
if ($instruction_data['om_fichier_instruction'] !== null |
578 |
&& $instruction_data['om_fichier_instruction'] !== '') { |
579 |
// |
580 |
$instruction_with_doc = $inst_related_instruction->getVal($inst_related_instruction->clePrimaire); |
581 |
} |
582 |
} |
583 |
} |
584 |
} |
585 |
if ($instruction_with_doc !== null) { |
586 |
// |
587 |
$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); |
588 |
} |
589 |
} |
590 |
return $val_instruction; |
591 |
} |
592 |
|
593 |
protected function sort_instruction_data(array $values, array $res) { |
594 |
$fields = array( |
595 |
"date_envoi_signature", |
596 |
"date_retour_signature", |
597 |
"date_envoi_rar", |
598 |
"date_retour_rar", |
599 |
"date_envoi_controle_legalite", |
600 |
"date_retour_controle_legalite", |
601 |
"signataire_arrete", |
602 |
"om_fichier_instruction", |
603 |
"tacite", |
604 |
"lettretype", |
605 |
); |
606 |
foreach ($values as $key => $value) { |
607 |
if (in_array($key, $fields) === true) { |
608 |
if (array_key_exists($key, $res) === false |
609 |
&& $value !== null |
610 |
&& $value !== '') { |
611 |
// |
612 |
$res[$key] = $value; |
613 |
} elseif ($key === 'tacite' |
614 |
&& $value === 't') { |
615 |
// |
616 |
$res[$key] = $value; |
617 |
} |
618 |
} |
619 |
} |
620 |
return $res; |
621 |
} |
622 |
|
623 |
protected function get_document_numerise_data(string $dn) { |
624 |
$val_dn = array(); |
625 |
$inst_dn = $this->f->get_inst__om_dbform(array( |
626 |
"obj" => "document_numerise", |
627 |
"idx" => $dn, |
628 |
)); |
629 |
$val_dn = $inst_dn->get_json_data(); |
630 |
$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')); |
631 |
// Correspond à la nomenclature Plat'AU NATURE_PIECE |
632 |
$val_dn['nature'] = $val_dn['document_numerise_nature_libelle']; |
633 |
return $val_dn; |
634 |
} |
635 |
|
636 |
protected function get_parcelles_data(string $object, string $idx) { |
637 |
$val_dp = array(); |
638 |
$inst_di = $this->f->get_inst__om_dbform(array( |
639 |
"obj" => $object, |
640 |
"idx" => $idx, |
641 |
)); |
642 |
$list_parcelles = $inst_di->get_parcelles(); |
643 |
$no_ordre = 1; |
644 |
foreach ($list_parcelles as $parcelle) { |
645 |
$val_dp[$parcelle[$object.'_parcelle']] = array( |
646 |
$object.'_parcelle' => $parcelle[$object.'_parcelle'], |
647 |
'libelle' => $parcelle['libelle'], |
648 |
'no_ordre' => $no_ordre, |
649 |
); |
650 |
$no_ordre++; |
651 |
} |
652 |
return $val_dp; |
653 |
} |
654 |
|
655 |
protected function view_form_json($in_field = false) { |
656 |
// |
657 |
if ($this->f->get_submitted_post_value('valid') === null) { |
658 |
// Liste des valeurs à afficher |
659 |
$val = array(); |
660 |
// |
661 |
$val_task = array_combine($this->champs, $this->val); |
662 |
foreach ($val_task as $key => $value) { |
663 |
$val_task[$key] = strip_tags($value); |
664 |
} |
665 |
$val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true); |
666 |
$val['task'] = $val_task; |
667 |
// |
668 |
if ($this->getVal('type') === 'creation_DA') { |
669 |
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id')); |
670 |
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation'); |
671 |
$val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']); |
672 |
$val_external_uid = array(); |
673 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation'); |
674 |
$val['external_uid'] = $val_external_uid; |
675 |
} |
676 |
// |
677 |
if ($this->getVal('type') === 'creation_DI' |
678 |
|| $this->getVal('type') === 'modification_DI' |
679 |
|| $this->getVal('type') === 'depot_DI') { |
680 |
// |
681 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
682 |
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_instruction'); |
683 |
$val['demandeur'] = $this->get_demandeurs_data($val['dossier']['dossier']); |
684 |
$architecte = isset($val['donnees_techniques']['architecte']) === true ? $val['donnees_techniques']['architecte'] : null; |
685 |
$val['architecte'] = $this->get_architecte_data($architecte); |
686 |
$val['dossier_parcelle'] = $this->get_parcelles_data('dossier', $val['dossier']['dossier']); |
687 |
$val_external_uid = array(); |
688 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
689 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
690 |
$val['external_uid'] = $val_external_uid; |
691 |
} |
692 |
// |
693 |
if ($this->getVal('type') === 'qualification_DI') { |
694 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
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'] = $val_external_uid; |
699 |
} |
700 |
// |
701 |
if ($this->getVal('type') === 'ajout_piece') { |
702 |
$val['document_numerise'] = $this->get_document_numerise_data($this->getVal('object_id')); |
703 |
$val['dossier'] = $this->get_dossier_data($val['document_numerise']['dossier']); |
704 |
$val_external_uid = array(); |
705 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
706 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
707 |
$val_external_uid['document_numerise'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'document_numerise'); |
708 |
$val['external_uid'] = $val_external_uid; |
709 |
} |
710 |
// |
711 |
if ($this->getVal('type') === 'decision_DI') { |
712 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
713 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier']); |
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') === 'incompletude_DI') { |
721 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
722 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'incompletude'); |
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 |
if ($this->getVal('type') === 'completude_DI') { |
730 |
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
731 |
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier'], 'completude'); |
732 |
$val_external_uid = array(); |
733 |
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
734 |
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
735 |
$val['external_uid'] = $val_external_uid; |
736 |
} |
737 |
|
738 |
if ($in_field === true) { |
739 |
return json_encode($val, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
740 |
} else { |
741 |
// Liste des valeurs affichée en JSON |
742 |
printf(json_encode($val, JSON_UNESCAPED_SLASHES)); |
743 |
} |
744 |
} |
745 |
} |
746 |
|
747 |
function view_update_json_data() { |
748 |
// Mise à jour des valeurs |
749 |
// |
750 |
$params = array( |
751 |
'val' => array( |
752 |
'state' => $this->f->get_submitted_post_value('state') |
753 |
), |
754 |
); |
755 |
$update = $this->update_task($params); |
756 |
$message_class = "valid"; |
757 |
$message = $this->msg; |
758 |
if ($update === false) { |
759 |
$this->addToLog($this->msg, DEBUG_MODE); |
760 |
$message_class = "error"; |
761 |
$message = sprintf( |
762 |
'%s %s', |
763 |
__('Impossible de mettre à jour la tâche.'), |
764 |
__('Veuillez contacter votre administrateur.') |
765 |
); |
766 |
} |
767 |
$this->f->displayMessage($message_class, $message); |
768 |
// |
769 |
$inst_lien = $this->f->get_inst__om_dbform(array( |
770 |
"obj" => "lien_id_interne_uid_externe", |
771 |
"idx" => ']', |
772 |
)); |
773 |
$valF = array( |
774 |
'lien_id_interne_uid_externe' => '', |
775 |
'object' => $this->get_lien_objet_by_type($this->getVal('type')), |
776 |
'object_id' => $this->getVal('object_id'), |
777 |
'external_uid' => $this->f->get_submitted_post_value('external_uid'), |
778 |
); |
779 |
$add = $inst_lien->ajouter($valF); |
780 |
$message_class = "valid"; |
781 |
$message = $inst_lien->msg; |
782 |
if ($add === false) { |
783 |
$this->addToLog($inst_lien->msg, DEBUG_MODE); |
784 |
$message_class = "error"; |
785 |
$message = sprintf( |
786 |
'%s %s', |
787 |
__("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."), |
788 |
__('Veuillez contacter votre administrateur.') |
789 |
); |
790 |
} |
791 |
$this->f->displayMessage($message_class, $message); |
792 |
} |
793 |
|
794 |
function view_add_json_data() { |
795 |
$params = array(); |
796 |
$params['val']['stream'] = 'input'; |
797 |
$params['val']['json_payload'] = $this->f->get_submitted_post_value('json_payload'); |
798 |
$json_payload = json_decode($params['val']['json_payload'], true); |
799 |
$params['val']['type'] = $json_payload['task']['type']; |
800 |
$params['val']['dossier'] = $json_payload['task']['dossier']; |
801 |
$params['val']['object_id'] = ""; |
802 |
if ($params['val']['type'] == 'ajout_piece') { |
803 |
$document_numerise = $json_payload['document_numerise']; |
804 |
$file_content = base64_decode($document_numerise["file_content"]); |
805 |
if ($file_content === false){ |
806 |
$this->addToMessage(__("Le contenu du fichier lié à la tâche n'a pas pu etre recupere.")); |
807 |
return false; |
808 |
} |
809 |
$metadata = array( |
810 |
"filename" => $document_numerise['nom_fichier'], |
811 |
"size" => strlen($file_content), |
812 |
"mimetype" => $document_numerise['file_content_type'], |
813 |
"date_creation" => $document_numerise['date_creation'], |
814 |
); |
815 |
$uid_fichier = $this->f->storage->create($file_content, $metadata, "from_content"); |
816 |
if ($uid_fichier === OP_FAILURE) { |
817 |
$this->addToMessage(__("Erreur lors de la creation du fichier lié à la tâche.")); |
818 |
return false; |
819 |
} |
820 |
$json_payload["document_numerise"]["uid"] = $uid_fichier; |
821 |
$params['val']['json_payload'] = json_encode($json_payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); |
822 |
} |
823 |
$this->add_task($params); |
824 |
} |
825 |
|
826 |
protected function get_lien_objet_by_type($type) { |
827 |
// |
828 |
$objet = ''; |
829 |
if ($type === 'creation_DA') { |
830 |
$objet = 'dossier_autorisation'; |
831 |
} |
832 |
if ($type === 'creation_DI' |
833 |
|| $type === 'depot_DI' |
834 |
|| $type === 'modification_DI' |
835 |
|| $type === 'qualification_DI' |
836 |
|| $type === 'decision_DI' |
837 |
|| $type === 'incompletude_DI' |
838 |
|| $type === 'completude_DI') { |
839 |
// |
840 |
$objet = 'dossier'; |
841 |
} |
842 |
if ($type === 'ajout_piece') { |
843 |
$objet = 'document_numerise'; |
844 |
} |
845 |
return $objet; |
846 |
} |
847 |
|
848 |
function setLayout(&$form, $maj) { |
849 |
$form->setBloc('json_payload', 'D', '', 'col_6'); |
850 |
$form->setFieldset('json_payload', 'DF', __("json_payload"), "collapsible, startClosed"); |
851 |
$form->setBloc('json_payload', 'F'); |
852 |
$form->setBloc('timestamp_log', 'DF', '', 'col_9'); |
853 |
} |
854 |
|
855 |
} |