init
[garradin.git] / www / admin / membres / cotisations / supprimer.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 $membre = false;
12
13 $cotisations = new Cotisations;
14 $m_cotisations = new Cotisations_Membres;
15
16 if (empty($_GET['id']) || !is_numeric($_GET['id']))
17 {
18 throw new UserException("Argument du numéro de cotisation membre manquant.");
19 }
20
21 $id = (int) $_GET['id'];
22
23 $co = $m_cotisations->get($id);
24
25 if (!$co)
26 {
27 throw new UserException("Cette cotisation membre n'existe pas.");
28 }
29
30 $membre = $membres->get($co['id_membre']);
31
32 if (!$membre)
33 {
34 throw new UserException("Le membre lié à la cotisation n'existe pas ou plus.");
35 }
36
37 $error = false;
38
39 if (!empty($_POST['delete']))
40 {
41 if (!utils::CSRF_check('del_cotisation_' . $co['id']))
42 {
43 $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
44 }
45 else
46 {
47 try {
48 $m_cotisations->delete($co['id']);
49 utils::redirect('/admin/membres/cotisations.php?id=' . $membre['id']);
50 }
51 catch (UserException $e)
52 {
53 $error = $e->getMessage();
54 }
55 }
56 }
57
58 $tpl->assign('error', $error);
59 $tpl->assign('membre', $membre);
60 $tpl->assign('cotisation', $co);
61
62 $tpl->display('admin/membres/cotisations/supprimer.tpl');
63
64 ?>