|
252 | 252 | $smarty->assign('formulaire', genererFormulaire($formulaire)); |
253 | 253 | } |
254 | 254 |
|
255 | | -/* |
256 | | - * This action is used in AJAX in order to update "compta" data. |
257 | | - * Only 4 columns are available for update: |
258 | | - * - categorie |
259 | | - * - reglement |
260 | | - * - evenement |
261 | | - * - comment |
262 | | - * - attachment_required |
263 | | - * The new value is passed with the `val` variable (POST). |
264 | | - * The column and the "compta" identifier are passed with GET vars. |
265 | | - * |
266 | | - * There is no content return on failure, only headers. |
267 | | - * If the update succeed we display a simple JSON element with a 200 status code. |
268 | | - * |
269 | | - * This action is added to perform Ajax updates directly on the "journal" list |
270 | | - * in order to improve utilization. |
271 | | - */ elseif ($action === 'modifier_colonne') { |
272 | | - try { |
273 | | - // Bad request? |
274 | | - if (!isset($_POST['val']) || !isset($_GET['column']) || !isset($_GET['id']) || !($line = $compta->obtenir((int) $_GET['id']))) { |
275 | | - throw new Exception("Please verify parameters", 400); |
276 | | - } |
277 | | - |
278 | | - // Test line existence |
279 | | - if (!$line['id']) { |
280 | | - throw new Exception("Not found", 404); |
281 | | - } |
282 | | - |
283 | | - $allowEmpty = false; |
284 | | - |
285 | | - switch ($_GET['column']) { |
286 | | - case 'categorie': |
287 | | - $column = 'idcategorie'; |
288 | | - $value = (int) $_POST['val']; |
289 | | - break; |
290 | | - case 'reglement': |
291 | | - $column = 'idmode_regl'; |
292 | | - $value = (int) $_POST['val']; |
293 | | - break; |
294 | | - case 'evenement': |
295 | | - $column = 'idevenement'; |
296 | | - $value = (int) $_POST['val']; |
297 | | - break; |
298 | | - case 'comment': |
299 | | - $column = 'comment'; |
300 | | - $value = (string) $_POST['val']; |
301 | | - $allowEmpty = true; |
302 | | - break; |
303 | | - case 'attachment_required': |
304 | | - $column = 'attachment_required'; |
305 | | - $value = (int) $_POST['val']; |
306 | | - $allowEmpty = true; |
307 | | - break; |
308 | | - default: |
309 | | - throw new Exception("Bad column name", 400); |
310 | | - } |
311 | | - |
312 | | - // No value? |
313 | | - if (!$allowEmpty && !$value) { |
314 | | - throw new Exception("Bad value", 400); |
315 | | - } |
316 | | - |
317 | | - if ($compta->modifierColonne($line['id'], $column, $value)) { |
318 | | - $response = [ |
319 | | - 'success' => true, |
320 | | - ]; |
321 | | - |
322 | | - // Done! |
323 | | - header('Content-Type: application/json; charset=utf-8'); |
324 | | - header('HTTP/1.1 200 OK'); |
325 | | - die(json_encode($response)); |
326 | | - } else { |
327 | | - throw new Exception("An error occurred", 409); |
328 | | - } |
329 | | - } catch (Exception $e) { |
330 | | - switch ($e->getCode()) { |
331 | | - case 404: |
332 | | - $httpStatus = "Not Found"; |
333 | | - break; |
334 | | - case 409: |
335 | | - $httpStatus = "Conflict"; |
336 | | - break; |
337 | | - case 400: |
338 | | - default: |
339 | | - $httpStatus = "Bad Request"; |
340 | | - break; |
341 | | - } |
342 | | - header('HTTP/1.1 ' . $e->getCode() . ' ' . $httpStatus); |
343 | | - header('X-Info: ' . $e->getMessage()); |
344 | | - exit; |
345 | | - } |
346 | | -} |
347 | | - |
348 | 255 | /** |
349 | 256 | * Upload an attachment and save it on the specific line. |
350 | 257 | * We save the uploads in a directory at the same month of the line |
|
0 commit comments