1 |
softime |
9293 |
<?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 |
softime |
9330 |
"identifier" => "json_data", |
19 |
|
|
"view" => "view_json_data", |
20 |
softime |
9293 |
"permission_suffix" => "consulter", |
21 |
|
|
); |
22 |
|
|
} |
23 |
|
|
|
24 |
softime |
9395 |
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 |
softime |
9293 |
/** |
45 |
|
|
* TREATMENT - add_task |
46 |
|
|
* Ajoute un enregistrement. |
47 |
|
|
* |
48 |
|
|
* @param array $params Tableau des paramètres |
49 |
|
|
* @return boolean |
50 |
|
|
*/ |
51 |
|
|
public function add_task($params = array()) { |
52 |
|
|
$this->begin_treatment(__METHOD__); |
53 |
|
|
$timestamp_log = json_encode(array( |
54 |
|
|
'creation_date' => date('Y-m-d H:i:s'), |
55 |
|
|
)); |
56 |
|
|
// Mise à jour du DI |
57 |
|
|
$valF = array( |
58 |
|
|
'task' => '', |
59 |
|
|
'type' => $params['val']['type'], |
60 |
|
|
'timestamp_log' => $timestamp_log, |
61 |
softime |
9385 |
'state' => isset($params['val']['state']) === true ? $params['val']['state'] : 'new', |
62 |
softime |
9389 |
'object_id' => $params['val']['object_id'], |
63 |
softime |
9293 |
); |
64 |
softime |
9395 |
$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 |
softime |
9293 |
$add = $this->ajouter($valF); |
78 |
|
|
if ($add === false) { |
79 |
|
|
$this->addToLog($this->msg, DEBUG_MODE); |
80 |
|
|
return $this->end_treatment(__METHOD__, false); |
81 |
|
|
} |
82 |
|
|
return $this->end_treatment(__METHOD__, true); |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
/** |
86 |
|
|
* TREATMENT - update_task |
87 |
|
|
* Met à jour l'enregistrement instancié. |
88 |
|
|
* |
89 |
|
|
* @param array $params Tableau des paramètres |
90 |
|
|
* @return boolean |
91 |
|
|
*/ |
92 |
|
|
public function update_task($params = array()) { |
93 |
|
|
$this->begin_treatment(__METHOD__); |
94 |
|
|
$timestamp_log = $this->get_timestamp_log(); |
95 |
|
|
if ($timestamp_log === false) { |
96 |
|
|
$this->addToLog(__('XXX'), DEBUG_MODE); |
97 |
|
|
return $this->end_treatment(__METHOD__, false); |
98 |
|
|
} |
99 |
|
|
array_push($timestamp_log, array( |
100 |
|
|
'modification_date' => date('Y-m-d H:i:s'), |
101 |
|
|
'state' => $params['val']['state'], |
102 |
|
|
'prev_state' => $this->getVal('state'), |
103 |
|
|
)); |
104 |
|
|
$timestamp_log = json_encode($timestamp_log); |
105 |
|
|
$valF = array( |
106 |
|
|
'task' => $this->getVal($this->clePrimaire), |
107 |
|
|
'type' => $this->getVal('type'), |
108 |
|
|
'timestamp_log' => $timestamp_log, |
109 |
|
|
'state' => $params['val']['state'], |
110 |
softime |
9389 |
'object_id' => $this->getVal('object_id'), |
111 |
softime |
9293 |
); |
112 |
|
|
$update = $this->modifier($valF); |
113 |
|
|
if ($update === false) { |
114 |
|
|
$this->addToLog($this->msg, DEBUG_MODE); |
115 |
|
|
return $this->end_treatment(__METHOD__, false); |
116 |
|
|
} |
117 |
|
|
return $this->end_treatment(__METHOD__, true); |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
/** |
121 |
|
|
* Récupère le journal d'horodatage dans le champ timestamp_log de |
122 |
|
|
* l'enregistrement instancié. |
123 |
|
|
* |
124 |
|
|
* @param array $params Tableau des paramètres |
125 |
|
|
* @return array sinon false en cas d'erreur |
126 |
|
|
*/ |
127 |
|
|
protected function get_timestamp_log($params = array()) { |
128 |
|
|
$val = $this->getVal('timestamp_log'); |
129 |
|
|
if ($val === '') { |
130 |
|
|
$val = json_encode(array()); |
131 |
|
|
} |
132 |
|
|
if($this->isJson($val) === false) { |
133 |
|
|
return false; |
134 |
|
|
} |
135 |
|
|
return json_decode($val, true); |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
/** |
139 |
softime |
9330 |
* VIEW - view_json_data |
140 |
softime |
9293 |
* Affiche l'enregistrement dans le format JSON. |
141 |
|
|
* |
142 |
|
|
* @return void |
143 |
|
|
*/ |
144 |
softime |
9330 |
public function view_json_data() { |
145 |
softime |
9293 |
$this->checkAccessibility(); |
146 |
softime |
9330 |
$this->f->disableLog(); |
147 |
softime |
9298 |
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 |
softime |
9304 |
$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 |
softime |
9298 |
$query = sprintf(' |
165 |
|
|
SELECT |
166 |
|
|
* |
167 |
|
|
FROM %1$stask |
168 |
softime |
9304 |
%2$s |
169 |
softime |
9298 |
', |
170 |
softime |
9304 |
DB_PREFIXE, |
171 |
|
|
$where |
172 |
softime |
9298 |
); |
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 |
|
|
$list_tasks[$task['task']] = $task; |
180 |
|
|
} |
181 |
|
|
printf(json_encode($list_tasks)); |
182 |
|
|
} |
183 |
|
|
|
184 |
softime |
9395 |
protected function get_dossier_data(string $dossier) { |
185 |
|
|
$val_di = array(); |
186 |
|
|
$inst_di = $this->f->get_inst__om_dbform(array( |
187 |
|
|
"obj" => "dossier", |
188 |
|
|
"idx" => $dossier, |
189 |
|
|
)); |
190 |
|
|
$val_di = json_decode($inst_di->get_json_data(), true); |
191 |
|
|
unset($val_di['initial_dt']); |
192 |
|
|
unset($val_di['log_instructions']); |
193 |
|
|
return $val_di; |
194 |
|
|
} |
195 |
|
|
|
196 |
|
|
protected function get_dossier_autorisation_data(string $da) { |
197 |
|
|
$val_da = array(); |
198 |
|
|
$inst_da = $this->f->get_inst__om_dbform(array( |
199 |
|
|
"obj" => "dossier_autorisation", |
200 |
|
|
"idx" => $da, |
201 |
|
|
)); |
202 |
|
|
$val_da = json_decode($inst_da->get_json_data(), true); |
203 |
|
|
return $val_da; |
204 |
|
|
} |
205 |
|
|
|
206 |
|
|
protected function get_donnees_techniques_data(string $fk_idx, string $fk_field) { |
207 |
|
|
$val_dt = array(); |
208 |
|
|
$inst_dt = $this->f->get_inst__by_other_idx(array( |
209 |
|
|
"obj" => "donnees_techniques", |
210 |
|
|
"fk_field" => $fk_field, |
211 |
|
|
"fk_idx" => $fk_idx, |
212 |
|
|
)); |
213 |
|
|
$val_dt = array( |
214 |
|
|
'donnees_techniques' => $inst_dt->getVal($inst_dt->clePrimaire), |
215 |
|
|
'cerfa' => $inst_dt->getVal('cerfa'), |
216 |
|
|
); |
217 |
|
|
$val_dt = array_merge($val_dt, $inst_dt->get_donnees_techniques_applicables()); |
218 |
|
|
return $val_dt; |
219 |
|
|
} |
220 |
|
|
|
221 |
|
|
protected function get_external_uid($fk_idx, string $fk_idx_2) { |
222 |
|
|
$inst_external_uid_da = $this->f->get_inst__by_other_idx(array( |
223 |
|
|
"obj" => "lien_id_interne_uid_externe", |
224 |
|
|
"fk_field" => 'object_id', |
225 |
|
|
"fk_idx" => $fk_idx, |
226 |
|
|
"fk_field_2" => 'object', |
227 |
|
|
"fk_idx_2" => $fk_idx_2, |
228 |
|
|
)); |
229 |
|
|
return $inst_external_uid_da->getVal('external_uid'); |
230 |
|
|
} |
231 |
|
|
|
232 |
|
|
protected function get_demandeurs_data(string $dossier) { |
233 |
|
|
$val_demandeur = array(); |
234 |
|
|
$inst_di = $this->f->get_inst__om_dbform(array( |
235 |
|
|
"obj" => "dossier", |
236 |
|
|
"idx" => $dossier, |
237 |
|
|
)); |
238 |
|
|
$list_demandeurs = $inst_di->get_demandeurs(); |
239 |
|
|
foreach ($list_demandeurs as $demandeur) { |
240 |
|
|
$inst_demandeur = $this->f->get_inst__om_dbform(array( |
241 |
|
|
"obj" => "demandeur", |
242 |
|
|
"idx" => $demandeur['demandeur'], |
243 |
softime |
9334 |
)); |
244 |
softime |
9395 |
$val_demandeur[$demandeur['demandeur']] = json_decode($inst_demandeur->get_json_data(), true); |
245 |
|
|
$val_demandeur[$demandeur['demandeur']]['petitionnaire_principal'] = $demandeur['petitionnaire_principal']; |
246 |
softime |
9334 |
} |
247 |
softime |
9395 |
return $val_demandeur; |
248 |
|
|
} |
249 |
|
|
|
250 |
|
|
protected function get_architecte_data($architecte = null) { |
251 |
|
|
$val_architecte = array(); |
252 |
|
|
if ($architecte !== null |
253 |
|
|
&& $architecte !== '') { |
254 |
softime |
9334 |
// |
255 |
softime |
9395 |
$inst_architecte = $this->f->get_inst__om_dbform(array( |
256 |
|
|
"obj" => "architecte", |
257 |
|
|
"idx" => $architecte, |
258 |
softime |
9334 |
)); |
259 |
softime |
9395 |
$val_architecte = json_decode($inst_architecte->get_json_data(), true); |
260 |
softime |
9334 |
} |
261 |
softime |
9395 |
return $val_architecte; |
262 |
|
|
} |
263 |
softime |
9334 |
|
264 |
softime |
9395 |
protected function get_instruction_data(string $dossier) { |
265 |
|
|
$val_instruction = array(); |
266 |
|
|
$inst_di = $this->f->get_inst__om_dbform(array( |
267 |
|
|
"obj" => "dossier", |
268 |
|
|
"idx" => $dossier, |
269 |
|
|
)); |
270 |
|
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
271 |
|
|
"obj" => "instruction", |
272 |
|
|
"idx" => $inst_di->get_last_instruction_decision(), |
273 |
|
|
)); |
274 |
|
|
if (count($inst_instruction->val) > 0) { |
275 |
|
|
$val_instruction = json_decode($inst_instruction->get_json_data(), true); |
276 |
softime |
9384 |
} |
277 |
softime |
9395 |
return $val_instruction; |
278 |
|
|
} |
279 |
softime |
9334 |
|
280 |
softime |
9395 |
protected function get_document_numerise_data(string $dn) { |
281 |
|
|
$val_dn = array(); |
282 |
|
|
$inst_dn = $this->f->get_inst__om_dbform(array( |
283 |
|
|
"obj" => "document_numerise", |
284 |
|
|
"idx" => $dn, |
285 |
|
|
)); |
286 |
|
|
$val_dn = json_decode($inst_dn->get_json_data(), true); |
287 |
|
|
$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')); |
288 |
|
|
return $val_dn; |
289 |
|
|
} |
290 |
|
|
|
291 |
|
|
protected function view_form_json() { |
292 |
|
|
// Mise à jour des valeurs |
293 |
softime |
9385 |
if ($this->f->get_submitted_get_value('valid') === 'true' |
294 |
|
|
&& $this->f->get_submitted_get_value('state') !== null) { |
295 |
softime |
9293 |
// |
296 |
|
|
$params = array( |
297 |
|
|
'val' => array( |
298 |
softime |
9385 |
'state' => $this->f->get_submitted_get_value('state') |
299 |
softime |
9293 |
), |
300 |
|
|
); |
301 |
|
|
$update = $this->update_task($params); |
302 |
|
|
$message_class = "valid"; |
303 |
|
|
$message = $this->msg; |
304 |
|
|
if ($update === false) { |
305 |
|
|
$this->addToLog($this->msg, DEBUG_MODE); |
306 |
|
|
$message_class = "error"; |
307 |
|
|
$message = sprintf( |
308 |
|
|
'%s %s', |
309 |
|
|
__('Impossible de mettre à jour la tâche.'), |
310 |
|
|
__('Veuillez contacter votre administrateur.') |
311 |
|
|
); |
312 |
|
|
} |
313 |
|
|
$this->f->displayMessage($message_class, $message); |
314 |
softime |
9389 |
} |
315 |
softime |
9395 |
// |
316 |
softime |
9389 |
if ($this->f->get_submitted_get_value('valid') === 'true' |
317 |
|
|
&& $this->f->get_submitted_get_value('external_uid') !== null) { |
318 |
softime |
9385 |
// |
319 |
softime |
9389 |
$inst_lien = $this->f->get_inst__om_dbform(array( |
320 |
|
|
"obj" => "lien_id_interne_uid_externe", |
321 |
|
|
"idx" => ']', |
322 |
|
|
)); |
323 |
|
|
$valF = array( |
324 |
|
|
'lien_id_interne_uid_externe' => '', |
325 |
|
|
'object' => $this->get_lien_objet_by_type($this->getVal('type')), |
326 |
|
|
'object_id' => $this->getVal('object_id'), |
327 |
|
|
'external_uid' => $this->f->get_submitted_get_value('external_uid'), |
328 |
|
|
); |
329 |
|
|
$add = $inst_lien->ajouter($valF); |
330 |
|
|
$message_class = "valid"; |
331 |
|
|
$message = $inst_lien->msg; |
332 |
|
|
if ($add === false) { |
333 |
|
|
$this->addToLog($inst_lien->msg, DEBUG_MODE); |
334 |
|
|
$message_class = "error"; |
335 |
|
|
$message = sprintf( |
336 |
|
|
'%s %s', |
337 |
|
|
__("Impossible de mettre à jour le lien entre l'identifiant interne et l'identifiant de l'application externe."), |
338 |
|
|
__('Veuillez contacter votre administrateur.') |
339 |
softime |
9385 |
); |
340 |
|
|
} |
341 |
softime |
9389 |
$this->f->displayMessage($message_class, $message); |
342 |
softime |
9293 |
} |
343 |
softime |
9395 |
|
344 |
|
|
// Liste des valeurs à afficher |
345 |
|
|
$val = array(); |
346 |
|
|
// |
347 |
|
|
$val_task = array_combine($this->champs, $this->val); |
348 |
|
|
$val['task'] = $val_task; |
349 |
|
|
// |
350 |
|
|
if ($this->getVal('type') === 'creation_DA') { |
351 |
|
|
$val['dossier_autorisation'] = $this->get_dossier_autorisation_data($this->getVal('object_id')); |
352 |
|
|
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_autorisation'); |
353 |
|
|
$val_external_uid = array(); |
354 |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier_autorisation']['dossier_autorisation'], 'dossier_autorisation'); |
355 |
|
|
$val['external_uid'] = $val_external_uid; |
356 |
|
|
} |
357 |
|
|
// |
358 |
|
|
if ($this->getVal('type') === 'creation_DI' |
359 |
|
|
|| $this->getVal('type') === 'modification_DI') { |
360 |
|
|
// |
361 |
|
|
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
362 |
|
|
$val['donnees_techniques'] = $this->get_donnees_techniques_data($this->getVal('object_id'), 'dossier_instruction'); |
363 |
|
|
$val['demandeur'] = $this->get_demandeurs_data($val['dossier']['dossier']); |
364 |
|
|
$val['architecte'] = $this->get_architecte_data($val['donnees_techniques']['architecte']); |
365 |
|
|
$val_external_uid = array(); |
366 |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
367 |
|
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
368 |
|
|
$val['external_uid'] = $val_external_uid; |
369 |
|
|
} |
370 |
|
|
// |
371 |
|
|
if ($this->getVal('type') === 'qualification_DI') { |
372 |
|
|
$val['dossier'] = $this->get_dossier_data($this->getVal('object_id')); |
373 |
|
|
$val['instruction'] = $this->get_instruction_data($val['dossier']['dossier']); |
374 |
|
|
$val_external_uid = array(); |
375 |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
376 |
|
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
377 |
|
|
$val['external_uid'] = $val_external_uid; |
378 |
|
|
} |
379 |
|
|
// |
380 |
|
|
if ($this->getVal('type') === 'ajout_piece') { |
381 |
|
|
$val['document_numerise'] = $this->get_document_numerise_data($this->getVal('object_id')); |
382 |
|
|
$val['dossier'] = $this->get_dossier_data($val['document_numerise']['dossier']); |
383 |
|
|
$val_external_uid = array(); |
384 |
|
|
$val_external_uid['dossier_autorisation'] = $this->get_external_uid($val['dossier']['dossier_autorisation'], 'dossier_autorisation'); |
385 |
|
|
$val_external_uid['dossier'] = $this->get_external_uid($val['dossier']['dossier'], 'dossier'); |
386 |
|
|
$val_external_uid['document_numerise'] = $this->get_external_uid($val['document_numerise']['document_numerise'], 'document_numerise'); |
387 |
|
|
$val['external_uid'] = $val_external_uid; |
388 |
|
|
} |
389 |
|
|
|
390 |
|
|
// Liste des valeurs affichée en JSON |
391 |
|
|
printf(json_encode($val)); |
392 |
softime |
9293 |
} |
393 |
softime |
9385 |
|
394 |
|
|
protected function get_lien_objet_by_type($type) { |
395 |
|
|
// |
396 |
|
|
$objet = ''; |
397 |
|
|
if ($type === 'creation_DA') { |
398 |
|
|
$objet = 'dossier_autorisation'; |
399 |
|
|
} |
400 |
softime |
9389 |
if ($type === 'creation_DI' || $type = 'modification_DI') { |
401 |
softime |
9385 |
$objet = 'dossier'; |
402 |
|
|
} |
403 |
|
|
if ($type === 'ajout_piece') { |
404 |
|
|
$objet = 'document_numerise'; |
405 |
|
|
} |
406 |
|
|
return $objet; |
407 |
|
|
} |
408 |
softime |
9293 |
} |