init
[garradin.git] / www / admin / compta / exercices / cloturer.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 $error = false;
21
22 if (!empty($_POST['close']))
23 {
24 if (!utils::CSRF_check('compta_cloturer_exercice_'.$exercice['id']))
25 {
26 $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
27 }
28 else
29 {
30 try
31 {
32 $id = $e->close($exercice['id'], utils::post('fin'));
33
34 if ($id && utils::post('reports'))
35 {
36 $e->doReports($exercice['id'], utils::modifyDate(utils::post('fin'), '+1 day'));
37 }
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/cloturer.tpl');
52
53 ?>