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