init
[garradin.git] / www / admin / membres / cotisations / gestion / rappel_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 rappel manquant.");
14 }
15
16 $rappels = new Rappels;
17
18 $rappel = $rappels->get(utils::get('id'));
19
20 if (!$rappel)
21 {
22 throw new UserException("Ce rappel n'existe pas.");
23 }
24
25 $cotisations = new Cotisations;
26
27 $error = false;
28
29 if (!empty($_POST['save']))
30 {
31 if (!utils::CSRF_check('edit_rappel_' . $rappel['id']))
32 {
33 $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
34 }
35 else
36 {
37 try {
38 if (utils::post('delai_choix') == 0)
39 $delai = 0;
40 elseif (utils::post('delai_choix') > 0)
41 $delai = (int) utils::post('delai_post');
42 else
43 $delai = -(int) utils::post('delai_pre');
44
45 $rappels->edit($rappel['id'], [
46 'sujet' => utils::post('sujet'),
47 'texte' => utils::post('texte'),
48 'delai' => $delai,
49 'id_cotisation' => utils::post('id_cotisation'),
50 ]);
51
52 utils::redirect('/admin/membres/cotisations/gestion/rappels.php');
53 }
54 catch (UserException $e)
55 {
56 $error = $e->getMessage();
57 }
58 }
59 }
60
61 $tpl->assign('error', $error);
62
63 $rappel['delai_pre'] = $rappel['delai_post'] = abs($rappel['delai']) ?: 30;
64 $rappel['delai_choix'] = $rappel['delai'] == 0 ? 0 : ($rappel['delai'] > 0 ? 1 : -1);
65
66 $tpl->assign('rappel', $rappel);
67 $tpl->assign('cotisations', $cotisations->listCurrent());
68
69 $tpl->display('admin/membres/cotisations/gestion/rappel_modifier.tpl');
70
71 ?>