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 |
|
|
/** |
25 |
|
|
* TREATMENT - add_task |
26 |
|
|
* Ajoute un enregistrement. |
27 |
|
|
* |
28 |
|
|
* @param array $params Tableau des paramètres |
29 |
|
|
* @return boolean |
30 |
|
|
*/ |
31 |
|
|
public function add_task($params = array()) { |
32 |
|
|
$this->begin_treatment(__METHOD__); |
33 |
|
|
$timestamp_log = json_encode(array( |
34 |
|
|
'creation_date' => date('Y-m-d H:i:s'), |
35 |
|
|
)); |
36 |
|
|
// Mise à jour du DI |
37 |
|
|
$valF = array( |
38 |
|
|
'task' => '', |
39 |
|
|
'type' => $params['val']['type'], |
40 |
|
|
'timestamp_log' => $timestamp_log, |
41 |
softime |
9330 |
'state' => isset($params['val']['state']) === true ? $params['val']['state'] : 'draft', |
42 |
softime |
9293 |
'id' => $params['val']['id'], |
43 |
|
|
); |
44 |
|
|
$add = $this->ajouter($valF); |
45 |
|
|
if ($add === false) { |
46 |
|
|
$this->addToLog($this->msg, DEBUG_MODE); |
47 |
|
|
return $this->end_treatment(__METHOD__, false); |
48 |
|
|
} |
49 |
|
|
return $this->end_treatment(__METHOD__, true); |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
/** |
53 |
|
|
* TREATMENT - update_task |
54 |
|
|
* Met à jour l'enregistrement instancié. |
55 |
|
|
* |
56 |
|
|
* @param array $params Tableau des paramètres |
57 |
|
|
* @return boolean |
58 |
|
|
*/ |
59 |
|
|
public function update_task($params = array()) { |
60 |
|
|
$this->begin_treatment(__METHOD__); |
61 |
|
|
$timestamp_log = $this->get_timestamp_log(); |
62 |
|
|
if ($timestamp_log === false) { |
63 |
|
|
$this->addToLog(__('XXX'), DEBUG_MODE); |
64 |
|
|
return $this->end_treatment(__METHOD__, false); |
65 |
|
|
} |
66 |
|
|
array_push($timestamp_log, array( |
67 |
|
|
'modification_date' => date('Y-m-d H:i:s'), |
68 |
|
|
'state' => $params['val']['state'], |
69 |
|
|
'prev_state' => $this->getVal('state'), |
70 |
|
|
)); |
71 |
|
|
$timestamp_log = json_encode($timestamp_log); |
72 |
|
|
$valF = array( |
73 |
|
|
'task' => $this->getVal($this->clePrimaire), |
74 |
|
|
'type' => $this->getVal('type'), |
75 |
|
|
'timestamp_log' => $timestamp_log, |
76 |
|
|
'state' => $params['val']['state'], |
77 |
|
|
'id' => $this->getVal('id'), |
78 |
|
|
); |
79 |
|
|
$update = $this->modifier($valF); |
80 |
|
|
if ($update === false) { |
81 |
|
|
$this->addToLog($this->msg, DEBUG_MODE); |
82 |
|
|
return $this->end_treatment(__METHOD__, false); |
83 |
|
|
} |
84 |
|
|
return $this->end_treatment(__METHOD__, true); |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
/** |
88 |
|
|
* Récupère le journal d'horodatage dans le champ timestamp_log de |
89 |
|
|
* l'enregistrement instancié. |
90 |
|
|
* |
91 |
|
|
* @param array $params Tableau des paramètres |
92 |
|
|
* @return array sinon false en cas d'erreur |
93 |
|
|
*/ |
94 |
|
|
protected function get_timestamp_log($params = array()) { |
95 |
|
|
$val = $this->getVal('timestamp_log'); |
96 |
|
|
if ($val === '') { |
97 |
|
|
$val = json_encode(array()); |
98 |
|
|
} |
99 |
|
|
if($this->isJson($val) === false) { |
100 |
|
|
return false; |
101 |
|
|
} |
102 |
|
|
return json_decode($val, true); |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
/** |
106 |
softime |
9330 |
* VIEW - view_json_data |
107 |
softime |
9293 |
* Affiche l'enregistrement dans le format JSON. |
108 |
|
|
* |
109 |
|
|
* @return void |
110 |
|
|
*/ |
111 |
softime |
9330 |
public function view_json_data() { |
112 |
softime |
9293 |
$this->checkAccessibility(); |
113 |
softime |
9330 |
$this->f->disableLog(); |
114 |
softime |
9298 |
if ($this->getParameter('idx') !== ']' |
115 |
|
|
&& $this->getParameter('idx') !== '0') { |
116 |
|
|
// |
117 |
|
|
$this->view_form_json(); |
118 |
|
|
} |
119 |
|
|
else { |
120 |
|
|
$this->view_tab_json(); |
121 |
|
|
} |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
protected function view_tab_json() { |
125 |
softime |
9304 |
$where = ''; |
126 |
|
|
if ($this->f->get_submitted_get_value('state') !== null |
127 |
|
|
&& $this->f->get_submitted_get_value('state') !== '') { |
128 |
|
|
// |
129 |
|
|
$where = sprintf(' WHERE state = \'%s\' ', $this->f->get_submitted_get_value('state')); |
130 |
|
|
} |
131 |
softime |
9298 |
$query = sprintf(' |
132 |
|
|
SELECT |
133 |
|
|
* |
134 |
|
|
FROM %1$stask |
135 |
softime |
9304 |
%2$s |
136 |
softime |
9298 |
', |
137 |
softime |
9304 |
DB_PREFIXE, |
138 |
|
|
$where |
139 |
softime |
9298 |
); |
140 |
|
|
$res = $this->f->get_all_results_from_db_query($query, true); |
141 |
|
|
if ($res['code'] === 'KO') { |
142 |
|
|
return false; |
143 |
|
|
} |
144 |
|
|
$list_tasks = array(); |
145 |
|
|
foreach ($res['result'] as $task) { |
146 |
|
|
$list_tasks[$task['task']] = $task; |
147 |
|
|
} |
148 |
|
|
printf(json_encode($list_tasks)); |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
protected function view_form_json() { |
152 |
softime |
9334 |
// Liste des valeurs à afficher |
153 |
|
|
$val = array(); |
154 |
|
|
// |
155 |
|
|
$val_task = array_combine($this->champs, $this->val); |
156 |
|
|
$val['task'] = $val_task; |
157 |
|
|
// |
158 |
|
|
if ($this->getVal('type') === 'projetsPOST') { |
159 |
|
|
$inst_da = $this->f->get_inst__om_dbform(array( |
160 |
|
|
"obj" => "dossier_autorisation", |
161 |
|
|
"idx" => $this->getVal('id'), |
162 |
|
|
)); |
163 |
|
|
$val_da = array_combine($inst_da->champs, $inst_da->val); |
164 |
|
|
$val['dossier_autorisation'] = $val_da; |
165 |
|
|
$inst_dt_da = $this->f->get_inst__by_other_idx(array( |
166 |
|
|
"obj" => "donnees_techniques", |
167 |
|
|
"fk_field" => 'dossier_autorisation', |
168 |
|
|
"fk_idx" => $this->getVal('id'), |
169 |
|
|
)); |
170 |
|
|
$val_dt_da = array_combine($inst_dt_da->champs, $inst_dt_da->val); |
171 |
|
|
$val['donnees_techniques'] = $val_dt_da; |
172 |
|
|
} |
173 |
|
|
// |
174 |
|
|
if ($this->getVal('type') === 'dossiersPOST' |
175 |
|
|
|| $this->getVal('type') === 'dossiersPUT') { |
176 |
|
|
// |
177 |
|
|
$inst_di = $this->f->get_inst__om_dbform(array( |
178 |
|
|
"obj" => "dossier", |
179 |
|
|
"idx" => $this->getVal('id'), |
180 |
|
|
)); |
181 |
|
|
$val_di = array_combine($inst_di->champs, $inst_di->val); |
182 |
softime |
9343 |
unset($val_di['initial_dt']); |
183 |
|
|
unset($val_di['log_instructions']); |
184 |
softime |
9334 |
$val['dossier'] = $val_di; |
185 |
|
|
$inst_dt_di = $this->f->get_inst__by_other_idx(array( |
186 |
|
|
"obj" => "donnees_techniques", |
187 |
|
|
"fk_field" => 'dossier_instruction', |
188 |
|
|
"fk_idx" => $this->getVal('id'), |
189 |
|
|
)); |
190 |
softime |
9343 |
$val_dt_di = array( |
191 |
|
|
'donnees_techniques' => $inst_dt_di->getVal($inst_dt_di->clePrimaire), |
192 |
|
|
'cerfa' => $inst_dt_di->getVal('cerfa'), |
193 |
|
|
); |
194 |
|
|
$val['donnees_techniques'] = array_merge($val_dt_di, $inst_dt_di->get_donnees_techniques_applicables()); |
195 |
softime |
9334 |
$val_demandeur = array(); |
196 |
|
|
$list_demandeurs = $inst_di->get_demandeurs(); |
197 |
|
|
foreach ($list_demandeurs as $demandeur) { |
198 |
|
|
$inst_demandeur = $this->f->get_inst__om_dbform(array( |
199 |
|
|
"obj" => "demandeur", |
200 |
|
|
"idx" => $demandeur['demandeur'], |
201 |
|
|
)); |
202 |
|
|
$val_demandeur[$demandeur['demandeur']] = array_combine($inst_demandeur->champs, $inst_demandeur->val); |
203 |
|
|
$val_demandeur[$demandeur['demandeur']]['petitionnaire_principal'] = $demandeur['petitionnaire_principal']; |
204 |
|
|
} |
205 |
|
|
$val['demandeur'] = $val_demandeur; |
206 |
|
|
} |
207 |
|
|
// |
208 |
|
|
if ($this->getVal('type') === 'dossiersQualificationPUT') { |
209 |
|
|
$inst_di = $this->f->get_inst__om_dbform(array( |
210 |
|
|
"obj" => "dossier", |
211 |
|
|
"idx" => $this->getVal('id'), |
212 |
|
|
)); |
213 |
|
|
$val_di = array_combine($inst_di->champs, $inst_di->val); |
214 |
softime |
9343 |
unset($val_di['initial_dt']); |
215 |
|
|
unset($val_di['log_instructions']); |
216 |
softime |
9334 |
$val['dossier'] = $val_di; |
217 |
|
|
$inst_instruction = $this->f->get_inst__om_dbform(array( |
218 |
|
|
"obj" => "instruction", |
219 |
|
|
"idx" => $inst_di->get_last_instruction_decision(), |
220 |
|
|
)); |
221 |
softime |
9343 |
$val_instruction = array(); |
222 |
|
|
if (count($inst_instruction->val) > 0) { |
223 |
|
|
$val_instruction = array_combine($inst_instruction->champs, $inst_instruction->val); |
224 |
|
|
} |
225 |
softime |
9334 |
$val['instruction'] = $val_instruction; |
226 |
|
|
} |
227 |
|
|
// |
228 |
|
|
if ($this->getVal('type') === 'piecesPOST') { |
229 |
|
|
$inst_di = $this->f->get_inst__om_dbform(array( |
230 |
|
|
"obj" => "dossier", |
231 |
|
|
"idx" => $this->getVal('id'), |
232 |
|
|
)); |
233 |
|
|
$val_di = array_combine($inst_di->champs, $inst_di->val); |
234 |
softime |
9343 |
unset($val_di['initial_dt']); |
235 |
|
|
unset($val_di['log_instructions']); |
236 |
softime |
9334 |
$val['dossier'] = $val_di; |
237 |
|
|
$inst_dn = $this->f->get_inst__by_other_idx(array( |
238 |
|
|
"obj" => "document_numerise", |
239 |
|
|
"fk_field" => 'dossier', |
240 |
|
|
"fk_idx" => $this->getVal('id'), |
241 |
|
|
)); |
242 |
|
|
$val_dn = array_combine($inst_dn->champs, $inst_dn->val); |
243 |
|
|
$val['document_numerise'] = $val_dn; |
244 |
|
|
} |
245 |
|
|
|
246 |
|
|
// Liste des valeurs affichée en JSON |
247 |
softime |
9293 |
printf(json_encode($val)); |
248 |
softime |
9334 |
|
249 |
|
|
// |
250 |
softime |
9297 |
if ($this->f->get_submitted_post_value('valid') === 'true' |
251 |
|
|
&& $this->f->get_submitted_post_value('state') !== null) { |
252 |
softime |
9293 |
// |
253 |
|
|
$params = array( |
254 |
|
|
'val' => array( |
255 |
softime |
9297 |
'state' => $this->f->get_submitted_post_value('state') |
256 |
softime |
9293 |
), |
257 |
|
|
); |
258 |
|
|
$update = $this->update_task($params); |
259 |
|
|
$message_class = "valid"; |
260 |
|
|
$message = $this->msg; |
261 |
|
|
if ($update === false) { |
262 |
|
|
$this->addToLog($this->msg, DEBUG_MODE); |
263 |
|
|
$message_class = "error"; |
264 |
|
|
$message = sprintf( |
265 |
|
|
'%s %s', |
266 |
|
|
__('Impossible de mettre à jour la tâche.'), |
267 |
|
|
__('Veuillez contacter votre administrateur.') |
268 |
|
|
); |
269 |
|
|
} |
270 |
|
|
$this->f->displayMessage($message_class, $message); |
271 |
|
|
} |
272 |
|
|
} |
273 |
|
|
} |