4 require_once __DIR__
. '/_inc.php';
6 if ($user['droits']['compta'] < Membres
::DROIT_ADMIN
)
8 throw new UserException("Vous n'avez pas le droit d'accéder à cette page.");
11 $e = new Compta_Exercices
;
12 $import = new Compta_Import
;
13 $comptes = new Compta_Comptes
;
15 if (isset($_GET['export']))
17 header('Content-type: application/csv');
18 header('Content-Disposition: attachment; filename="Export comptabilité - ' . $config->get('nom_asso') . ' - ' . date('Y-m-d') . '.csv"');
19 $import->toCSV($e->getCurrentId());
25 if (!empty($_POST['import']))
27 if (!utils
::CSRF_check('compta_import'))
29 $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
31 if (empty($_FILES['upload']['tmp_name']))
33 $error = 'Aucun fichier fourni.';
39 if (isset($_FILES['upload-plan-comptable']))
41 if (!$comptes->importPlan($_FILES['upload-plan-comptable']['tmp_name']))
43 throw new UserException('Erreur lors de l’import du plan comptable');
46 if (utils
::post('type') == 'citizen')
48 $import->fromCitizen($_FILES['upload']['tmp_name']);
50 elseif (utils
::post('type') == 'garradin')
52 if (!$import->fromCSV($_FILES['upload']['tmp_name']))
54 throw new UserException('Erreur lors de l’import');
59 throw new UserException('Import inconnu.');
62 utils
::redirect('/admin/compta/import.php?ok');
64 catch (UserException
$e)
66 $error = $e->getMessage();
71 $tpl->assign('error', $error);
72 $tpl->assign('ok', isset($_GET['ok']) ?
true : false);
74 $tpl->display('admin/compta/import.tpl');