init
[garradin.git] / www / admin / compta / categories / modifier.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 $cats = new Compta_Categories;
12
13 $id = (int)utils::get('id');
14 $cat = $cats->get($id);
15
16 if (!$cat)
17 {
18 throw new UserException('Cette catégorie n\'existe pas.');
19 }
20
21 $error = false;
22
23 if (!empty($_POST['save']))
24 {
25 if (!utils::CSRF_check('compta_edit_cat_'.$cat['id']))
26 {
27 $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
28 }
29 else
30 {
31 try
32 {
33 $id = $cats->edit($id, [
34 'intitule' => utils::post('intitule'),
35 'description' => utils::post('description'),
36 ]);
37
38 if ($cat['type'] == Compta_Categories::DEPENSES)
39 $type = 'depenses';
40 elseif ($cat['type'] == Compta_Categories::AUTRES)
41 $type = 'autres';
42 else
43 $type = 'recettes';
44
45 utils::redirect('/admin/compta/categories/?'.$type);
46 }
47 catch (UserException $e)
48 {
49 $error = $e->getMessage();
50 }
51 }
52 }
53
54 $tpl->assign('error', $error);
55 $tpl->assign('cat', $cat);
56
57 $tpl->display('admin/compta/categories/modifier.tpl');
58
59 ?>