22a11375d9af2ca1fb9eb6bc18837a2b0438356c
[garradin.git] / www / admin / compta / import.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 $e = new Compta_Exercices;
12 $import = new Compta_Import;
13
14 if (isset($_GET['export']))
15 {
16 header('Content-type: application/csv');
17 header('Content-Disposition: attachment; filename="Export comptabilité - ' . $config->get('nom_asso') . ' - ' . date('Y-m-d') . '.csv"');
18 $import->toCSV($e->getCurrentId());
19 exit;
20 }
21
22 $error = false;
23
24 if (!empty($_POST['import']))
25 {
26 if (!utils::CSRF_check('compta_import'))
27 {
28 $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
29 }
30 elseif (empty($_FILES['upload']['tmp_name']))
31 {
32 $error = 'Aucun fichier fourni.';
33 }
34 else
35 {
36 try
37 {
38 if (utils::post('type') == 'citizen')
39 {
40 $import->fromCitizen($_FILES['upload']['tmp_name']);
41 }
42 elseif (utils::post('type') == 'garradin')
43 {
44 $import->fromCSV($_FILES['upload']['tmp_name']);
45 }
46 else
47 {
48 throw new UserException('Import inconnu.');
49 }
50
51 utils::redirect('/admin/compta/import.php?ok');
52 }
53 catch (UserException $e)
54 {
55 $error = $e->getMessage();
56 }
57 }
58 }
59
60 $tpl->assign('error', $error);
61 $tpl->assign('ok', isset($_GET['ok']) ? true : false);
62
63 $tpl->display('admin/compta/import.tpl');
64
65 ?>