init
[garradin.git] / www / admin / compta / exercices / modifier.php
1 <?php
2 namespace Garradin;
3
4 require_once __DIR__ . '/../_inc.php';
5
6 if ($user['droits']['compta'] < Membres::DROIT_ADMIN)
7 {
8 throw new UserException("Vous n'avez pas le droit d'accéder à cette page.");
9 }
10
11 $e = new Compta_Exercices;
12
13 $exercice = $e->get((int)utils::get('id'));
14
15 if (!$exercice)
16 {
17 throw new UserException('Exercice inconnu.');
18 }
19
20 if ($exercice['cloture'])
21 {
22 throw new UserException('Impossible de modifier un exercice clôturé.');
23 }
24
25 $error = false;
26
27 if (!empty($_POST['edit']))
28 {
29 if (!utils::CSRF_check('compta_modif_exercice_'.$exercice['id']))
30 {
31 $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
32 }
33 else
34 {
35 try
36 {
37 $id = $e->edit($exercice['id'], [
38 'libelle' => utils::post('libelle'),
39 'debut' => utils::post('debut'),
40 'fin' => utils::post('fin'),
41 ]);
42
43 utils::redirect('/admin/compta/exercices/');
44 }
45 catch (UserException $e)
46 {
47 $error = $e->getMessage();
48 }
49 }
50 }
51
52 $tpl->assign('error', $error);
53 $tpl->assign('exercice', $exercice);
54
55 $tpl->display('admin/compta/exercices/modifier.tpl');
56
57 ?>