init
[garradin.git] / www / admin / compta / exercices / supprimer.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 supprimer un exercice clôturé.');
23 }
24
25 $error = false;
26
27 if (!empty($_POST['delete']))
28 {
29 if (!utils::CSRF_check('compta_supprimer_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->delete($exercice['id']);
38
39 utils::redirect('/admin/compta/exercices/');
40 }
41 catch (UserException $e)
42 {
43 $error = $e->getMessage();
44 }
45 }
46 }
47
48 $tpl->assign('error', $error);
49 $tpl->assign('exercice', $exercice);
50
51 $tpl->display('admin/compta/exercices/supprimer.tpl');
52
53 ?>