init
[garradin.git] / www / admin / membres / cotisations / index.php
1 <?php
2 namespace Garradin;
3
4 require_once __DIR__ . '/../../_inc.php';
5
6 if ($user['droits']['membres'] < Membres::DROIT_ECRITURE)
7 {
8 throw new UserException("Vous n'avez pas le droit d'accéder à cette page.");
9 }
10
11 $cotisations = new Cotisations;
12
13 if ($user['droits']['membres'] >= Membres::DROIT_ADMIN)
14 {
15 $cats = new Compta_Categories;
16
17 $error = false;
18
19 if (!empty($_POST['save']))
20 {
21 if (!utils::CSRF_check('new_cotisation'))
22 {
23 $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
24 }
25 else
26 {
27 try {
28 $duree = utils::post('periodicite') == 'jours' ? (int) utils::post('duree') : null;
29 $debut = utils::post('periodicite') == 'date' ? utils::post('debut') : null;
30 $fin = utils::post('periodicite') == 'date' ? utils::post('fin') : null;
31 $id_cat = utils::post('categorie') ? (int) utils::post('id_categorie_compta') : null;
32
33 $cotisations->add([
34 'intitule' => utils::post('intitule'),
35 'description' => utils::post('description'),
36 'montant' => (float) utils::post('montant'),
37 'duree' => $duree,
38 'debut' => $debut,
39 'fin' => $fin,
40 'id_categorie_compta'=> $id_cat,
41 ]);
42
43 utils::redirect('/admin/membres/cotisations/');
44 }
45 catch (UserException $e)
46 {
47 $error = $e->getMessage();
48 }
49 }
50 }
51
52 $tpl->assign('error', $error);
53 $tpl->assign('categories', $cats->getList(Compta_Categories::RECETTES));
54 }
55
56
57 $tpl->assign('liste', $cotisations->listCurrentWithStats());
58
59 $tpl->display('admin/membres/cotisations/index.tpl');
60
61 ?>