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 |
} |
} |
23 |
|
|
24 |
|
protected function task_exists(string $type, string $object_id) { |
25 |
|
$query = sprintf(' |
26 |
|
SELECT task |
27 |
|
FROM %1$stask |
28 |
|
WHERE state != \'%2$s\' |
29 |
|
AND type = \'%3$s\' |
30 |
|
AND object_id = \'%4$s\' |
31 |
|
', |
32 |
|
DB_PREFIXE, |
33 |
|
'done', |
34 |
|
$type, |
35 |
|
$object_id |
36 |
|
); |
37 |
|
$res = $this->f->get_one_result_from_db_query($query); |
38 |
|
if ($res['result'] !== null && $res['result'] !== '') { |
39 |
|
return $res['result']; |
40 |
|
} |
41 |
|
return false; |
42 |
|
} |
43 |
|
|
44 |
/** |
/** |
45 |
* TREATMENT - add_task |
* TREATMENT - add_task |
46 |
* Ajoute un enregistrement. |
* Ajoute un enregistrement. |
58 |
'task' => '', |
'task' => '', |
59 |
'type' => $params['val']['type'], |
'type' => $params['val']['type'], |
60 |
'timestamp_log' => $timestamp_log, |
'timestamp_log' => $timestamp_log, |
61 |
'state' => 'draft', |
'state' => isset($params['val']['state']) === true ? $params['val']['state'] : 'new', |
62 |
'id' => $params['val']['id'], |
'object_id' => $params['val']['object_id'], |
63 |
); |
); |
64 |
|
$task_exists = $this->task_exists($valF['type'], $valF['object_id']); |
65 |
|
if ($task_exists !== false) { |
66 |
|
$inst_task = $this->f->get_inst__om_dbform(array( |
67 |
|
"obj" => "task", |
68 |
|
"idx" => $task_exists, |
69 |
|
)); |
70 |
|
$update_params = array( |
71 |
|
'val' => array( |
72 |
|
'state' => $inst_task->getVal('state'), |
73 |
|
), |
74 |
|
); |
75 |
|
return $inst_task->update_task($update_params); |
76 |
|
} |
77 |
$add = $this->ajouter($valF); |
$add = $this->ajouter($valF); |
78 |
if ($add === false) { |
if ($add === false) { |
79 |
$this->addToLog($this->msg, DEBUG_MODE); |
$this->addToLog($this->msg, DEBUG_MODE); |
107 |
'type' => $this->getVal('type'), |
'type' => $this->getVal('type'), |
108 |
'timestamp_log' => $timestamp_log, |
'timestamp_log' => $timestamp_log, |
109 |
'state' => $params['val']['state'], |
'state' => $params['val']['state'], |
110 |
'id' => $this->getVal('id'), |
'object_id' => $this->getVal('object_id'), |
111 |
); |
); |
112 |
$update = $this->modifier($valF); |
$update = $this->modifier($valF); |
113 |
if ($update === false) { |
if ($update === false) { |
136 |
} |
} |
137 |
|
|
138 |
/** |
/** |
139 |
* VIEW - view_json |
* VIEW - view_json_data |
140 |
* Affiche l'enregistrement dans le format JSON. |
* Affiche l'enregistrement dans le format JSON. |
141 |
* |
* |
142 |
* @return void |
* @return void |
143 |
*/ |
*/ |
144 |
public function view_json() { |
public function view_json_data() { |
145 |
$this->checkAccessibility(); |
$this->checkAccessibility(); |
146 |
$val = array_combine($this->champs, $this->val); |
$this->f->disableLog(); |
147 |
printf(json_encode($val)); |
if ($this->getParameter('idx') !== ']' |
148 |
|
&& $this->getParameter('idx') !== '0') { |
149 |
|
// |
150 |
|
$this->view_form_json(); |
151 |
|
} |
152 |
|
else { |
153 |
|
$this->view_tab_json(); |
154 |
|
} |
155 |
|
} |
156 |
|
|
157 |
|
protected function view_tab_json() { |
158 |
|
$where = ''; |
159 |
|
if ($this->f->get_submitted_get_value('state') !== null |
160 |
|
&& $this->f->get_submitted_get_value('state') !== '') { |
161 |
|
// |
162 |
|
$where = sprintf(' WHERE state = \'%s\' ', $this->f->get_submitted_get_value('state')); |
163 |
|
} |
164 |
|
$query = sprintf(' |
165 |
|
SELECT |
166 |
|
* |
167 |
|
FROM %1$stask |
168 |
|
%2$s |
169 |
|
', |
170 |
|
DB_PREFIXE, |
171 |
|
$where |
172 |
|
); |
173 |
|
$res = $this->f->get_all_results_from_db_query($query, true); |
174 |
|
if ($res['code'] === 'KO') { |
175 |
|
return false; |
176 |
|
} |
177 |
|
$list_tasks = array(); |
178 |
|
foreach ($res['result'] as $task) { |
179 |
|
$task['timestamp_log'] = json_decode($task['timestamp_log'], true); |
180 |
|
$list_tasks[$task['task']] = $task; |
181 |
|
} |
182 |
|
printf(json_encode($list_tasks)); |
183 |
|
} |
184 |
|
|
185 |
|
protected function get_dossier_data(string $dossier) { |
186 |
|
$val_di = array(); |
187 |
|
$inst_di = $this->f->get_inst__om_dbform(array( |
188 |
|
"obj" => "dossier", |
189 |
|
"idx" => $dossier, |
190 |
|
)); |
191 |
|
$val_di = $inst_di->get_json_data(); |
192 |
|
if ($val_di['dossier_instruction_type_code'] === 'T') { |
193 |
|
$val_di['date_decision_transfert'] = $val_di['date_decision']; |
194 |
|
} |
195 |
|
unset($val_di['initial_dt']); |
196 |
|
unset($val_di['log_instructions']); |
197 |
|
return $val_di; |
198 |
|
} |
199 |
|
|
200 |
|
protected function get_dossier_autorisation_data(string $da) { |
201 |
|
$val_da = array(); |
202 |
|
$inst_da = $this->f->get_inst__om_dbform(array( |
203 |
|
"obj" => "dossier_autorisation", |
204 |
|
"idx" => $da, |
205 |
|
)); |
206 |
|
$val_da = $inst_da->get_json_data(); |
207 |
|
return $val_da; |
208 |
|
} |
209 |
|
|
210 |
|
protected function get_donnees_techniques_data(string $fk_idx, string $fk_field) { |
211 |
|
$val_dt = array(); |
212 |
|
$inst_dt = $this->f->get_inst__by_other_idx(array( |
213 |
|
"obj" => "donnees_techniques", |
214 |
|
"fk_field" => $fk_field, |
215 |
|
"fk_idx" => $fk_idx, |
216 |
|
)); |
217 |
|
$val_dt = array( |
218 |
|
'donnees_techniques' => $inst_dt->getVal($inst_dt->clePrimaire), |
219 |
|
'cerfa' => $inst_dt->getVal('cerfa'), |
220 |
|
); |
221 |
|
$val_dt = array_merge($val_dt, $inst_dt->get_donnees_techniques_applicables()); |
222 |
|
if (isset($val_dt['am_exist_date']) === true) { |
223 |
|
$val_dt['am_exist_date_num'] = ''; |
224 |
|
if (is_numeric($val_dt['am_exist_date']) === true) { |
225 |
|
$val_dt['am_exist_date_num'] = $val_dt['am_exist_date']; |
226 |
|
} |
227 |
|
} |
228 |
|
// Correspond à la nomenclature de Plat'AU STATUT_INFO |
229 |
|
$val_dt['tax_statut_info'] = 'Déclaré'; |
230 |
|
return $val_dt; |
231 |
|
} |
232 |
|
|
233 |
|
protected function get_external_uid($fk_idx, string $fk_idx_2) { |
234 |
|
$inst_external_uid = $this->f->get_inst__by_other_idx(array( |
235 |
|
"obj" => "lien_id_interne_uid_externe", |
236 |
|
"fk_field" => 'object_id', |
237 |
|
"fk_idx" => $fk_idx, |
238 |
|
"fk_field_2" => 'object', |
239 |
|
"fk_idx_2" => $fk_idx_2, |
240 |
|
)); |
241 |
|
return $inst_external_uid->getVal('external_uid'); |
242 |
|
} |
243 |
|
|
244 |
|
protected function get_demandeurs_data(string $dossier) { |
245 |
|
$val_demandeur = array(); |
246 |
|
$inst_di = $this->f->get_inst__om_dbform(array( |
247 |
|
"obj" => "dossier", |
248 |
|
"idx" => $dossier, |
249 |
|
)); |
250 |
|
$list_demandeurs = $inst_di->get_demandeurs(); |
251 |
|
foreach ($list_demandeurs as $demandeur) { |
252 |
|
$inst_demandeur = $this->f->get_inst__om_dbform(array( |
253 |
|
"obj" => "demandeur", |
254 |
|
"idx" => $demandeur['demandeur'], |
255 |
|
)); |
256 |
|
$val_demandeur[$demandeur['demandeur']] = $inst_demandeur->get_json_data(); |
257 |
|
$val_demandeur[$demandeur['demandeur']]['petitionnaire_principal'] = $demandeur['petitionnaire_principal']; |
258 |
|
} |
259 |
|
return $val_demandeur; |
260 |
|
} |
261 |
|
|
262 |
|
protected function get_architecte_data($architecte = null) { |
263 |
|
$val_architecte = array(); |
264 |
|
if ($architecte !== null |
265 |
|
&& $architecte !== '') { |
266 |
|
// |
267 |
|
$inst_architecte = $this->f->get_inst__om_dbform(array( |
268 |
|
"obj" => "architecte", |
269 |
|
"idx" => $architecte, |
270 |
|
)); |
271 |
|
$val_architecte = $inst_architecte->get_json_data(); |
272 |
|
} |
273 |
|
return $val_architecte; |
274 |
|
} |
275 |
|
|
276 |
|
protected function get_instruction_data(string $dossier) { |
277 |
|
$val_instruction = array(); |
278 |
|
$inst_di = $this->f->get_inst__om_dbform(array( |
279 |
|
"obj" => "dossier", |
280 |
|
"idx" => $dossier, |
281 |
|
)); |
282 |
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
283 |
|
"obj" => "instruction", |
284 |
|
"idx" => $inst_di->get_last_instruction_decision(), |
285 |
|
)); |
286 |
|
if (count($inst_instruction->val) > 0) { |
287 |
|
$val_instruction = $inst_instruction->get_json_data(); |
288 |
|
} |
289 |
|
return $val_instruction; |
290 |
|
} |
291 |
|
|
292 |
|
protected function get_document_numerise_data(string $dn) { |
293 |
|
$val_dn = array(); |
294 |
|
$inst_dn = $this->f->get_inst__om_dbform(array( |
295 |
|
"obj" => "document_numerise", |
296 |
|
"idx" => $dn, |
297 |
|
)); |
298 |
|
$val_dn = $inst_dn->get_json_data(); |
299 |
|
$val_dn['path'] = sprintf('%s/%s&snippet=%s&obj=%s&champ=%s&id=%s', $_SERVER['HTTP_HOST'], 'openads/app/index.php?module=form', 'file', 'document_numerise', 'uid', $this->getVal('object_id')); |
300 |
|
// Correspond à la nomenclature Plat'AU NATURE_PIECE |
301 |
|
$val_dn['nature'] = 'Initiale'; |
302 |
|
return $val_dn; |
303 |
|
} |
304 |
|
|
305 |
|
protected function get_parcelles_data(string $object, string $idx) { |
306 |
|
$val_dp = array(); |
307 |
|
$inst_di = $this->f->get_inst__om_dbform(array( |
308 |
|
"obj" => $object, |
309 |
|
"idx" => $idx, |
310 |
|
)); |
311 |
|
$list_parcelles = $inst_di->get_parcelles(); |
312 |
|
$no_ordre = 1; |
313 |
|
foreach ($list_parcelles as $parcelle) { |
314 |
|
$val_dp[$parcelle[$object.'_parcelle']] = array( |
315 |
|
$object.'_parcelle' => $parcelle[$object.'_parcelle'], |
316 |
|
'libelle' => $parcelle['libelle'], |
317 |
|
'no_ordre' => $no_ordre, |
318 |
|
); |
319 |
|
$no_ordre++; |
320 |
|
} |
321 |
|
return $val_dp; |
322 |
|
} |
323 |
|
|
324 |
|
protected function view_form_json() { |
325 |
|
// Mise à jour des valeurs |
326 |
if ($this->f->get_submitted_post_value('valid') === 'true' |
if ($this->f->get_submitted_post_value('valid') === 'true' |
327 |
&& $this->f->get_submitted_post_value('state') !== null) { |
&& $this->f->get_submitted_post_value('state') !== null) { |
328 |
// |
// |
345 |
} |
} |
346 |
$this->f->displayMessage($message_class, $message); |
$this->f->displayMessage($message_class, $message); |
347 |
} |
} |
348 |
|
// |
349 |
|
if ($this->f->get_submitted_post_value('valid') === 'true' |
350 |
|
&& $this->f->get_submitted_post_value('external_uid') !== null) { |
351 |
|
// |
352 |
|
$inst_lien = $this->f->get_inst__om_dbform(array( |
353 |
|
"obj" => "lien_id_interne_uid_externe", |
354 |
|
"idx" => ']', |
355 |
|
)); |
356 |
|
$valF = array( |
357 |
|
'lien_id_interne_uid_externe' => '', |
358 |
|
'object' => $this->get_lien_objet_by_type($this->getVal('type')), |
359 |
|
'object_id' => $this->getVal('object_id'), |
360 |
|
'external_uid' => $this->f->get_submitted_post_value('external_uid'), |
361 |
|
); |
362 |
|
$add = $inst_lien->ajouter($valF); |
363 |
|
$message_class = "valid"; |
364 |
|
$message = $inst_lien->msg; |
365 |
|
if ($add === false) { |
366 |
|
$this->addToLog($inst_lien->msg, DEBUG_MODE); |
367 |
|
$message_class = "error"; |
368 |
|
$message = sprintf( |
369 |
|
'%s %s', |
370 |
|
__("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."), |
371 |
|
__('Veuillez contacter votre administrateur.') |
372 |
|
); |
373 |
|
} |
374 |
|
$this->f->displayMessage($message_class, $message); |
375 |
|
} |
376 |
|
|
377 |
|
// |
378 |
|
if ($this->f->get_submitted_post_value('valid') === null) { |
379 |
|
// Liste des valeurs à afficher |
380 |
|
$val = array(); |
381 |
|
// |
382 |
|
$val_task = array_combine($this->champs, $this->val); |
383 |
|
foreach ($val_task as $key => $value) { |
384 |
|
$val_task[$key] = strip_tags($value); |
385 |
|
} |
386 |
|
$val_task['timestamp_log'] = json_decode($val_task['timestamp_log'], true); |
387 |
|
$val['task'] = $val_task; |
388 |
|
// |
389 |
|
if ($this->getVal('type') === 'creation_DA') { |
390 |
|
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id')); |
391 |
|
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation'); |
392 |
|
$val['dossier_autorisation_parcelle'] = $this->get_parcelles_data('dossier_autorisation', $val['dossier_autorisation']['dossier_autorisation']); |
393 |
|
$val_external_uid = array(); |
394 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation'); |
395 |
|
$val['external_uid'] = $val_external_uid; |
396 |
|
} |
397 |
|
// |
398 |
|
if ($this->getVal('type') === 'creation_DI' |
399 |
|
|| $this->getVal('type') === 'modification_DI') { |
400 |
|
// |
401 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
402 |
|
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_instruction'); |
403 |
|
$val['demandeur'] = $this->get_demandeurs_data($val['dossier']['dossier']); |
404 |
|
$architecte = isset($val['donnees_techniques']['architecte']) === true ? $val['donnees_techniques']['architecte'] : null; |
405 |
|
$val['architecte'] = $this->get_architecte_data($architecte); |
406 |
|
$val['dossier_parcelle'] = $this->get_parcelles_data('dossier', $val['dossier']['dossier']); |
407 |
|
$val_external_uid = array(); |
408 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
409 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
410 |
|
$val['external_uid'] = $val_external_uid; |
411 |
|
} |
412 |
|
// |
413 |
|
if ($this->getVal('type') === 'qualification_DI') { |
414 |
|
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
415 |
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier']); |
416 |
|
$val_external_uid = array(); |
417 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
418 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
419 |
|
$val['external_uid'] = $val_external_uid; |
420 |
|
} |
421 |
|
// |
422 |
|
if ($this->getVal('type') === 'ajout_piece') { |
423 |
|
$val['document_numerise'] = $this->get_document_numerise_data($this->getVal('object_id')); |
424 |
|
$val['dossier'] = $this->get_dossier_data($val['document_numerise']['dossier']); |
425 |
|
$val_external_uid = array(); |
426 |
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
427 |
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
428 |
|
$val_external_uid['document_numerise'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'document_numerise'); |
429 |
|
$val['external_uid'] = $val_external_uid; |
430 |
|
} |
431 |
|
|
432 |
|
// Liste des valeurs affichée en JSON |
433 |
|
printf(json_encode($val)); |
434 |
|
} |
435 |
|
} |
436 |
|
|
437 |
|
protected function get_lien_objet_by_type($type) { |
438 |
|
// |
439 |
|
$objet = ''; |
440 |
|
if ($type === 'creation_DA') { |
441 |
|
$objet = 'dossier_autorisation'; |
442 |
|
} |
443 |
|
if ($type === 'creation_DI' || $type === 'modification_DI') { |
444 |
|
$objet = 'dossier'; |
445 |
|
} |
446 |
|
if ($type === 'ajout_piece') { |
447 |
|
$objet = 'document_numerise'; |
448 |
|
} |
449 |
|
return $objet; |
450 |
} |
} |
451 |
} |
} |