]> git.agnieray.net Git - galette.git/commitdiff
Add import and export routes; fix session, DI
authorJohan Cwiklinski <johan@x-tnd.be>
Fri, 19 Feb 2016 05:53:26 +0000 (06:53 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Mon, 17 Oct 2016 20:39:18 +0000 (22:39 +0200)
15 files changed:
galette/import.php [deleted file]
galette/import_model.php [deleted file]
galette/includes/dependencies.php
galette/includes/galette.inc.php
galette/includes/main.inc.php
galette/includes/routes/authentication.routes.php
galette/includes/routes/contributions.routes.php
galette/includes/routes/main.routes.php
galette/includes/routes/management.routes.php
galette/includes/routes/members.routes.php
galette/includes/routes/public_pages.routes.php
galette/templates/default/export.tpl
galette/templates/default/import.tpl
galette/templates/default/import_model.tpl
galette/templates/default/page.tpl

diff --git a/galette/import.php b/galette/import.php
deleted file mode 100644 (file)
index cd48f9b..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-<?php
-
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-
-/**
- * Import members from CSV file
- *
- * PHP version 5
- *
- * Copyright © 2013-2014 The Galette Team
- *
- * This file is part of Galette (http://galette.tuxfamily.org).
- *
- * Galette is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Galette is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Galette. If not, see <http://www.gnu.org/licenses/>.
- *
- * @category  Main
- * @package   Galette
- *
- * @author    Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2013-2014 The Galette Team
- * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
- * @link      http://galette.tuxfamily.org
- * @since     Available since 0.7ev - 2013-08-27
- */
-
-require_once 'includes/galette.inc.php';
-
-if ( !$login->isLogged() ) {
-    header('location: index.php');
-    die();
-}
-if ( !$login->isAdmin() && !$login->isStaff() ) {
-    header('location: voir_adherent.php');
-    die();
-}
-
-use Galette\IO\Csv;
-use Galette\IO\CsvIn;
-use Galette\Entity\Adherent;
-use Galette\Repository\Members;
-
-$csv = new CsvIn();
-
-$written = array();
-$dryrun = true;
-
-if ( isset($_GET['sup']) ) {
-    $res = $csv->remove($_GET['sup']);
-    if ( $res === true ) {
-        $success_detected[] = str_replace(
-            '%export',
-            $_GET['sup'],
-            _T("'%export' file has been removed from disk.")
-        );
-    } else {
-        $error_detected[] = str_replace(
-            '%export',
-            $_GET['sup'],
-            _T("Cannot remove '%export' from disk :/")
-        );
-    }
-}
-
-
-// CSV file upload
-if ( isset($_FILES['new_file']) ) {
-    if ( $_FILES['new_file']['error'] === UPLOAD_ERR_OK ) {
-        if ( $_FILES['new_file']['tmp_name'] !='' ) {
-            if ( is_uploaded_file($_FILES['new_file']['tmp_name']) ) {
-                $res = $csv->store($_FILES['new_file']);
-                if ( $res < 0 ) {
-                    $error_detected[] = $csv->getErrorMessage($res);
-                }
-            }
-        }
-    } else if ($_FILES['new_file']['error'] !== UPLOAD_ERR_NO_FILE) {
-        Analog::log(
-            $csv->getPhpErrorMessage($_FILES['new_file']['error']),
-            Analog::WARNING
-        );
-        $error_detected[] = $csv->getPhpErrorMessage(
-            $_FILES['new_file']['error']
-        );
-    } else if ( isset($_POST['upload']) ) {
-        $error_detected[] = _T("No files has been seleted for upload!");
-    }
-}
-
-if ( isset($_POST['import']) && isset($_POST['import_file']) ) {
-    if ( isset($_POST['dryrun']) ) {
-        $dryrun = true;
-    } else {
-        $dryrun = false;
-    }
-    $res = $csv->import($zdb, $_POST['import_file'], $members_fields, $members_fields_cats, $dryrun);
-    if ( $res !== true ) {
-        if ( $res < 0 ) {
-            $error_detected[] = $csv->getErrorMessage($res);
-            if ( count($csv->getErrors()) > 0 ) {
-                $error_detected = array_merge($error_detected, $csv->getErrors());
-            }
-        } else {
-            $error_detected[] = _T("An error occured importing the file :(");
-        }
-        $tpl->assign('import_file', $_POST['import_file']);
-    } else {
-        $success_detected[] = str_replace(
-            '%filename%',
-            $_POST['import_file'],
-            _T("File '%filename%' has been successfully imported :)")
-        );
-    }
-}
-
-$tpl->assign('dryrun', $dryrun);
-$existing = $csv->getExisting();
-
-$tpl->assign('page_title', _T("CVS members import"));
-$tpl->assign('require_dialog', true);
-//$tpl->assign('written', $written);
-$tpl->assign('existing', $existing);
-$tpl->assign('success_detected', $success_detected);
-$tpl->assign('error_detected', $error_detected);
-$tpl->assign('warning_detected', $warning_detected);
-$content = $tpl->fetch('import.tpl');
-$tpl->assign('content', $content);
-
-$tpl->display('page.tpl');
diff --git a/galette/import_model.php b/galette/import_model.php
deleted file mode 100644 (file)
index 3cebcbe..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-<?php
-
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-
-/**
- * CSV import model
- *
- * PHP version 5
- *
- * Copyright © 2013-2014 The Galette Team
- *
- * This file is part of Galette (http://galette.tuxfamily.org).
- *
- * Galette is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Galette is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Galette. If not, see <http://www.gnu.org/licenses/>.
- *
- * @category  Main
- * @package   Galette
- *
- * @author    Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2013-2014 The Galette Team
- * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
- * @version   SVN: $Id$
- * @link      http://galette.tuxfamily.org
- * @since     Availaible since 0.7.6dev - 2013-09-26
- */
-
-use Analog\Analog;
-use Galette\IO\Csv;
-use Galette\IO\CsvIn;
-use Galette\IO\CsvOut;
-use Galette\Entity\ImportModel;
-
-require_once 'includes/galette.inc.php';
-
-if ( !$login->isLogged() ) {
-    header("location: index.php");
-    die();
-}
-if ( !$login->isAdmin() ) {
-    header("location: voir_adherent.php");
-    die();
-}
-
-$model = new ImportModel();
-$model->load();
-
-if ( isset($_POST['fields']) ) {
-    $model->setFields($_POST['fields']);
-    $res = $model->store($zdb);
-    if ( $res === true ) {
-        $success_detected[] = _T("Import model has been successfully stored :)");
-        $model->load();
-    } else {
-        $error_detected[] = _T("Import model has not been stored :(");
-    }
-}
-
-if ( isset($_GET['remove']) ) {
-    $model->remove($zdb);
-    $model->load();
-}
-
-$csv = new CsvIn();
-
-/** FIXME: 
- * - set fields that should not be part of import
- * - set fields that must be part of import, and visually disable them in the list
- */
-
-$fields = $model->getFields();
-$defaults = $csv->getDefaultFields();
-$defaults_loaded = false;
-
-if ( $fields === null ) {
-    $fields = $defaults;
-    $defaults_loaded = true;
-}
-
-if ( isset($_GET['generate'] ) ) {
-    $ocsv = new CsvOut();
-    $res = $ocsv->export(
-        $fields,
-        Csv::DEFAULT_SEPARATOR,
-        Csv::DEFAULT_QUOTE,
-        $fields
-    );
-    $filename = _T("galette_import_model.csv");
-    header('Content-Type: text/csv');
-    header('Content-Disposition: attachment; filename="' . $filename . '";');
-    header('Pragma: no-cache');
-    echo $res;
-} else {
-    $tpl->assign('success_detected', $success_detected);
-    $tpl->assign('error_detected', $error_detected);
-
-    $tpl->assign('fields', $fields);
-    $tpl->assign('model', $model);
-    $tpl->assign('defaults', $defaults);
-    $import_fields = $members_fields;
-    //we do not want to import id_adh. Never.
-    unset($import_fields['id_adh']);
-    $tpl->assign('members_fields', $import_fields);
-    $tpl->assign('defaults_loaded', $defaults_loaded);
-
-    $tpl->assign('require_tabs', true);
-    $tpl->assign('require_dialog', true);
-    $tpl->assign('page_title', _T("CVS import model"));
-    $content = $tpl->fetch('import_model.tpl');
-    $tpl->assign('content', $content);
-    $tpl->display('page.tpl');
-}
-
index d7a99948c95e95390237c8b32d6a8b04b70a85ee..9d6df6ea1c9cc362c6ded7b81e20c5dd072e9e03 100644 (file)
@@ -122,24 +122,8 @@ $container['preferences'] = function ($c) {
 };
 
 $container['login'] = function ($c) use ($session_name) {
-    $session = &$_SESSION['galette'][$session_name];
-    if (isset($session['login'])) {
-        $login = unserialize(
-            $session['login']
-        );
-        $login->setDb($c->get('zdb'));
-    } else {
-        $login = new Galette\Core\Login(
-            $c->get('zdb'),
-            $c->get('i18n'),
-            $session
-        );
-    }
-
-    if (PHP_SAPI === 'cli') {
-        $login->logCron(basename($argv[0], '.php'));
-    }
-
+    $login = $c->get('session')->login;
+    $login->setDb($c->get('zdb'));
     return $login;
 };
 
@@ -188,8 +172,14 @@ $container['acls'] = function ($c) {
         'reminders'         => 'staff',
         'export'            => 'staff',
         'doExport'          => 'staff',
-        'removeExport'      => 'staff',
-        'getExport'         => 'staff'
+        'removeCsv'         => 'staff',
+        'getCsv'            => 'staff',
+        'import'            => 'staff',
+        'doImport'          => 'staff',
+        'importModel'       => 'staff',
+        'getImportModel'    => 'staff',
+        'storeImportModel'  => 'staff',
+        'uploadImportFile'  => 'staff'
     ];
 
     //load user defined ACLs
@@ -205,6 +195,21 @@ $container['texts_fields'] = function ($c) {
     return $texts_fields;
 };
 
+$container['members_fields'] = function ($c) {
+    include_once GALETTE_ROOT . 'includes/fields_defs/members_fields.php';
+    return $members_fields;
+};
+
+$container['members_fields_cats'] = function ($c) {
+    include_once GALETTE_ROOT . 'includes/fields_defs/members_fields_cats.php';
+    return $members_fields_cats;
+};
+
+$container['pdfmodels_fields'] = function ($c) {
+    include_once GALETTE_ROOT . 'includes/fields_defs/pdfmodels_fields.php';
+    return $pdfmodels_fields;
+};
+
 // -----------------------------------------------------------------------------
 // Service factories
 // -----------------------------------------------------------------------------
index c7c4c71ea1059cb3914952d270772e059b160e03..9ccaa9c207f32799b892d4d3dbdcfebfe103ae84 100644 (file)
@@ -349,46 +349,11 @@ if (!$installer and !defined('GALETTE_TESTS')) {
             $login->logCron(basename($argv[0], '.php'));
         }
 
-        /**
-         * Plugins
-         */
-        /*$plugins = new Core\Plugins($preferences);*/
-
-        /**
-         * Instanciate history object
-         */
-        if ( isset($session['history'])
-            && !GALETTE_MODE == 'DEV'
-        ) {
-            $hist = unserialize(
-                $session['history']
-            );
-        } else {
-            $hist = new Core\History();
-        }
-
-        /**
-         * Logo
-         */
-        if ( isset($session['logo'])
-            && !GALETTE_MODE == 'DEV'
-        ) {
-            $logo = unserialize(
-                $session['logo']
-            );
-        } else {
-            $logo = new Core\Logo();
-        }
-
         /**
          * Now that all objects are correctly setted,
          * we can include files that need it
          */
         include_once GALETTE_ROOT . 'includes/session.inc.php';
-        include_once GALETTE_ROOT . 'includes/fields_defs/members_fields.php';
-        include_once GALETTE_ROOT . 'includes/fields_defs/members_fields_cats.php';
-        include_once GALETTE_ROOT . 'includes/fields_defs/texts_fields.php';
-        include_once GALETTE_ROOT . 'includes/fields_defs/pdfmodels_fields.php';
     } else {
         $needs_update = true;
     }
index f4fe55b16a8f438f614837b991bef059bfbf17a1..d49485a179a0d1760099e7b4d9d9bf414abfd343 100644 (file)
@@ -198,12 +198,12 @@ if (file_exists(GALETTE_CONFIG_PATH  . 'local_acls.inc.php')) {
 }*/
 
 
-$authenticate = function ($request, $response, $next) use ($container, &$session) {
-    $login = $container->login;
+$authenticate = function ($request, $response, $next) use ($container) {
+    $login = $container->session->login;
 
     if (!$login->isLogged()) {
-        $session['urlRedirect'] = $request->getPathInfo();
-        $this->flash->addMessage('error', _T("Login required"));
+        //$this->session->urlRedirect = $request->getPathInfo();
+        $this->flash->addMessage('error_detected', _T("Login required"));
         return $response
             ->withStatus(403)
             ->withHeader('Location', $this->router->pathFor('slash'));
@@ -377,16 +377,17 @@ $app->i18n          = $i18n;
 $app->preferences   = $preferences;
 $app->login         = $login;
 
-$baseRedirect = function ($request, $response, $args = []) use ($app, $container, &$session) {
+$baseRedirect = function ($request, $response, $args = []) use ($app, $container) {
     $login = $container->get('login');
     $router = $container->get('router');
+    $session = $container->get('session');
 
     //$app->flashKeep();
     if ($login->isLogged()) {
         $urlRedirect = null;
-        if (isset($session['urlRedirect'])) {
-            $urlRedirect = $app->request()->getRootUri() . $session['urlRedirect'];
-            unset($session['urlRedirect']);
+        if ($session->urlRedirect !== null) {
+            $urlRedirect = $app->request()->getRootUri() . $session->urlRedirect;
+            $session->urlRedirect = null;
         }
 
         if ($urlRedirect !== null) {
@@ -398,10 +399,9 @@ $baseRedirect = function ($request, $response, $args = []) use ($app, $container
                 || $login->isAdmin()
                 || $login->isStaff()
             ) {
-                if (!isset($_COOKIE['show_galette_dashboard'])
+               if (!isset($_COOKIE['show_galette_dashboard'])
                     || $_COOKIE['show_galette_dashboard'] == 1
-                ) {
-
+               ) {
                     return $response
                         ->withStatus(301)
                         ->withHeader('Location', $router->pathFor('dashboard'));
index 6d774fa24000ee7b0858ba70e5663189f8e69707..232542f9fcb9380f86efca6535cf66631965301b 100644 (file)
@@ -46,7 +46,7 @@ $app->get(
             && $args['r'] != '/logout'
             && $args['r'] != '/login'
         ) {
-            $this->session['urlRedirect'] = $args['r'];
+            $this->session->urlRedirect = $args['r'];
         }
 
         if (!$this->login->isLogged()) {
@@ -100,11 +100,11 @@ $app->post(
         }
 
         if ($this->login->isLogged()) {
-            $this->session['login'] = serialize($this->login);
+               $this->session->login = $this->login;
             $this->history->add(_T("Login"));
-            return $baseRedirect($request, $response, $args);
+            return $baseRedirect($request, $response, []);
         } else {
-            $this->flash->addMessage('loginfault', _T("Login failed."));
+            $this->flash->addMessage('error_detected', _T("Login failed."));
             $this->history->add(_T("Authentication failed"), $nick);
             return $response->withStatus(301)->withHeader('Location', $this->router->pathFor('login'));
         }
@@ -114,10 +114,9 @@ $app->post(
 //logout procedure
 $app->get(
     '/logout',
-    function ($request, $response) use ($app, $login, &$session) {
+    function ($request, $response) use ($app, $login) {
         $this->login->logOut();
-        $session['login'] = null;
-        unset($this->session['login']);
+        \RKA\Session::destroy();
         return $response
             ->withStatus(301)
             ->withHeader('Location', $this->router->pathFor('slash'));
index 70987377cd0b28560c289d5b0d5f7427780bc3e6..a5640ce82484d5458acbaeb1ee58482f98582ea2 100644 (file)
@@ -51,8 +51,8 @@ $app->get(
             $value = $args['value'];
         }
 
-        if (isset($this->session['contributions'])) {
-            $contribs = unserialize($this->session['contributions']);
+        if ($this->session->contributions !== null) {
+            $contribs = $this->session->contributions;
         } else {
             $contribs = new Contributions();
         }
@@ -99,7 +99,7 @@ $app->get(
             }
         }*/
 
-        //$this->session['contributions'] = serialize($contribs);
+        $this->session->contributions = $contribs;
         $list_contribs = $contribs->getContributionsList(true);
 
         //assign pagination variables to the template and add pagination links
@@ -143,8 +143,8 @@ $app->get(
 
         $filtre_id_adh = '';
 
-        if (isset($this->session['transactions'])) {
-            $trans = unserialize($this->session['transactions']);
+        if ($this->session->transactions !== null) {
+            $trans = $this->session->transactions;
         } else {
             $trans = new Galette\Repository\Transactions();
         }
@@ -193,7 +193,7 @@ $app->get(
             }
         }*/
 
-        $this->session['transactions'] = serialize($trans);
+        $this->session->transactions = $trans;
         $list_trans = $trans->getTransactionsList(true);
 
         //assign pagination variables to the template and add pagination links
@@ -229,8 +229,8 @@ $app->post(
         $type = $args['type'];
         $post = $request->getParsedBody();
 
-        if (isset($this->session[$type])) {
-            $contribs = unserialize($this->session[$type]);
+        if ($this->session->$type !== null) {
+            $contribs = $this->session->$type;
         } else {
             $contribs = new Contributions();
         }
@@ -310,7 +310,7 @@ $app->post(
             }
         }*/
 
-        $this->session[$type] = serialize($contribs);
+        $this->session->$type = $contribs;
 
         return $response
             ->withStatus(301)
index f6946857e786c64f816bab3d72b22e1b2ac3d463..faea88b8f11eeaed6d1b6e86e6e952357cf4dfbb 100644 (file)
@@ -108,7 +108,7 @@ $app->get(
         $success = $login->impersonate($id);
 
         if ($success === true) {
-            $this->session['login'] = serialize($login);
+            $this->session->login = $login;
             $this->login = $login;
             $msg = str_replace(
                 '%login',
@@ -146,7 +146,7 @@ $app->get(
         $login = new \Galette\Core\Login($this->zdb, $this->i18n, $this->session);
         $login->logAdmin($this->preferences->pref_admin_login, $this->preferences);
         $this->history->add(_T("Impersonating ended"));
-        $this->session['login'] = serialize($login);
+        $this->session->login = $login;
         $this->login = $login;
         $this->flash->addMessage(
             'success_detected',
index dddfbb0a44c3d0aa9dc7f10ac64d0ba6f0d48308..9ee3a052866b47afed8c4e9d57ef489cb84996b4 100644 (file)
@@ -47,10 +47,13 @@ use Galette\IO\Charts;
 use \Analog\Analog;
 use Galette\IO\Csv;
 use Galette\IO\CsvOut;
+use Galette\IO\CsvIn;
+use Galette\Entity\ImportModel;
 
 //galette's dashboard
 $app->get(
-    '/' . _T("dashboard"),
+    '/dashboard',
+    /*'/' . _T("dashboard"),*/
     function ($request, $response, $args = []) {
         $news = new News($this->preferences->pref_rss_url);
 
@@ -157,7 +160,7 @@ $app->get(
 //preferences procedure
 $app->post(
     '/preferences',
-    function ($request, $response) use ($app, &$session) {
+    function ($request, $response) {
         // Validation
         if (isset($_POST['valid']) && $_POST['valid'] == '1') {
             // verification de champs
@@ -487,7 +490,6 @@ $app->post(
                                 } else {
                                     $this->logo = new Logo();
                                 }
-                                $this->session['logo'] = serialize($this->logo);
                             }
                         }
                     } elseif ($_FILES['logo']['error'] !== UPLOAD_ERR_NO_FILE) {
@@ -512,7 +514,6 @@ $app->post(
                         );
                     } else {
                         $this->logo = new Logo(); //get default Logo
-                        $this->session['logo'] = serialize($this->logo);
                     }
                 }
 
@@ -825,9 +826,9 @@ $app->get(
 )->add($authenticate);
 
 $app->get(
-    '/export/remove/{file}',
+    '/{type:export|import}/remove/{file}',
     function ($request, $response, $args) {
-        $csv = new CsvOut();
+        $csv = $args['type'] === 'export' ? new CsvOut() : new CsvIn;
         $res = $csv->remove($args['file']);
         if ($res === true) {
             $this->flash->addMessage(
@@ -851,9 +852,9 @@ $app->get(
 
         return $response
             ->withStatus(301)
-            ->withHeader('Location', $this->router->pathFor('export'));
+            ->withHeader('Location', $this->router->pathFor($args['type']));
     }
-)->setName('removeExport')->add($authenticate);
+)->setName('removeCsv')->add($authenticate);
 
 $app->post(
     '/export',
@@ -956,21 +957,23 @@ $app->post(
 )->setName('doExport')->add($authenticate);
 
 $app->get(
-    '/export/get/{file}',
+    '/{type:export|import}/get/{file}',
     function ($request, $response, $args) {
         $filename = $args['file'];
+
         //Exports main contain user confidential data, they're accessible only for
         //admins or staff members
         if ($this->login->isAdmin() || $this->login->isStaff()) {
-
-            if (file_exists(CsvOut::DEFAULT_DIRECTORY . $filename)) {
+            $filepath = $args['type'] === 'export' ? CsvOut::DEFAULT_DIRECTORY : CsvIn::DEFAULT_DIRECTORY;
+            $filepath .= $filename;
+            if (file_exists($filepath)) {
                 header('Content-Type: text/csv');
                 header('Content-Disposition: attachment; filename="' . $filename . '";');
                 header('Pragma: no-cache');
-                readfile(CsvOut::DEFAULT_DIRECTORY . $filename);
+                readfile($filepath);
             } else {
                 Analog::log(
-                    'A request has been made to get an exported file named `' .
+                    'A request has been made to get an ' . $args['type'] . 'ed file named `' .
                     $filename .'` that does not exists.',
                     Analog::WARNING
                 );
@@ -978,11 +981,248 @@ $app->get(
             }
         } else {
             Analog::log(
-                'A non authorized person asked to retrieve exported file named `' .
+                'A non authorized person asked to retrieve ' . $args['type'] . 'ed file named `' .
                 $filename . '`. Access has not been granted.',
                 Analog::WARNING
             );
             header('HTTP/1.0 403 Forbidden');
         }
     }
-)->setName('getExport')->add($authenticate);
+)->setName('getCsv')->add($authenticate);
+
+$app->get(
+    '/import',
+    function ($request, $response) {
+        $csv = new CsvIn();
+        $existing = $csv->getExisting();
+        $dryrun = true;
+
+        // display page
+        $this->view->render(
+            $response,
+            'import.tpl',
+            array(
+                'page_title'        => _T("CSV members import"),
+                'require_dialog'    => true,
+                'existing'          => $existing,
+                'dryrun'            => $dryrun,
+                'import_file'       => $this->flash->getMessage('import_file')[0]
+            )
+        );
+        return $response;
+    }
+)->setName('import')->add($authenticate);
+
+$app->post(
+    '/import',
+    function ($request, $response) {
+        $csv = new CsvIn();
+        $post = $request->getParsedBody();
+        $dryrun = isset($post['dryrun']);
+        $res = $csv->import($post['import_file'], $this->members_fields, $dryrun);
+        if ($res !== true) {
+            if ($res < 0) {
+                $this->flash->addMessage(
+                    'error_detected',
+                    $csv->getErrorMessage($res)
+                );
+                if (count($csv->getErrors()) > 0) {
+                    foreach ($csv->getErrors() as $error) {
+                        $this->flash->addMessage(
+                            'error_detected',
+                            $error
+                        );
+                    }
+                }
+            } else {
+                $this->flash->addMessage(
+                    'error_detected',
+                    _T("An error occured importing the file :(")
+                );
+            }
+
+            $this->flash->addMessage(
+                'import_file',
+                $post['import_file']
+            );
+        } else {
+            $this->flash->addMessage(
+                'success_detected',
+                str_replace(
+                    '%filename%',
+                    $post['import_file'],
+                    _T("File '%filename%' has been successfully imported :)")
+                )
+            );
+        }
+        return $response
+            ->withStatus(301)
+            ->withHeader('Location', $this->router->pathFor('import'));
+    }
+)->setName('doImport')->add($authenticate);
+
+$app->post(
+    '/import/upload',
+    function ($request, $response) {
+        $csv = new CsvIn();
+        if (isset($_FILES['new_file'])) {
+            if ($_FILES['new_file']['error'] === UPLOAD_ERR_OK) {
+                if ($_FILES['new_file']['tmp_name'] !='') {
+                    if (is_uploaded_file($_FILES['new_file']['tmp_name'])) {
+                        $res = $csv->store($_FILES['new_file']);
+                        if ($res < 0) {
+                            $this->flash->addMessage(
+                                'error_detected',
+                                $csv->getErrorMessage($res)
+                            );
+                        } else {
+                            $this->flash->addMessage(
+                                'success_detected',
+                                _T("Your file has been successfully uploaded!")
+                            );
+                        }
+                    }
+                }
+            } elseif ($_FILES['new_file']['error'] !== UPLOAD_ERR_NO_FILE) {
+                Analog::log(
+                    $csv->getPhpErrorMessage($_FILES['new_file']['error']),
+                    Analog::WARNING
+                );
+                $this->flash->addMessage(
+                    'error_detected',
+                    $csv->getPhpErrorMessage(
+                        $_FILES['new_file']['error']
+                    )
+                );
+            } elseif (isset($_POST['upload'])) {
+                $this->flash->addMessage(
+                    'error_detected',
+                    _T("No files has been seleted for upload!")
+                );
+            }
+        } else {
+            $this->flash->addMessage(
+                'warning_detected',
+                _T("No files has been uploaded!")
+            );
+        }
+
+        return $response
+            ->withStatus(301)
+            ->withHeader('Location', $this->router->pathFor('import'));
+    }
+)->setname('uploadImportFile')->add($authenticate);
+
+$app->get(
+    '/import/model',
+    function ($request, $response) {
+        $model = new ImportModel();
+        $model->load();
+
+        if (isset($request->getQueryParams()['remove'])) {
+            $model->remove($this->zdb);
+            $model->load();
+        }
+
+        $csv = new CsvIn();
+
+        /** FIXME:
+        * - set fields that should not be part of import
+        * - set fields that must be part of import, and visually disable them in the list
+        */
+
+        $fields = $model->getFields();
+        $defaults = $csv->getDefaultFields();
+        $defaults_loaded = false;
+
+        if ($fields === null) {
+            $fields = $defaults;
+            $defaults_loaded = true;
+        }
+
+        $import_fields = $this->members_fields;
+        //we do not want to import id_adh. Never.
+        unset($import_fields['id_adh']);
+
+        // display page
+        $this->view->render(
+            $response,
+            'import_model.tpl',
+            array(
+                'page_title'        => _T("CSV import model"),
+                'require_dialog'    => true,
+                'fields'            => $fields,
+                'model'             => $model,
+                'defaults'          => $defaults,
+                'members_fields'    => $import_fields,
+                'defaults_loaded'   => $defaults_loaded,
+                'require_tabs'      => true
+            )
+        );
+        return $response;
+
+    }
+)->setName('importModel')->add($authenticate);
+
+$app->get(
+    '/import/model/get',
+    function ($request, $response) {
+        $model = new ImportModel();
+        $model->load();
+
+        $csv = new CsvIn();
+
+        /** FIXME:
+        * - set fields that should not be part of import
+        * - set fields that must be part of import, and visually disable them in the list
+        */
+
+        $fields = $model->getFields();
+        $defaults = $csv->getDefaultFields();
+        $defaults_loaded = false;
+
+        if ($fields === null) {
+            $fields = $defaults;
+            $defaults_loaded = true;
+        }
+
+        $ocsv = new CsvOut();
+        $res = $ocsv->export(
+            $fields,
+            Csv::DEFAULT_SEPARATOR,
+            Csv::DEFAULT_QUOTE,
+            $fields
+        );
+        $filename = _T("galette_import_model.csv");
+        header('Content-Type: text/csv');
+        header('Content-Disposition: attachment; filename="' . $filename . '";');
+        header('Pragma: no-cache');
+        echo $res;
+    }
+)->setName('getImportModel')->add($authenticate);
+
+$app->post(
+    '/import/model/store',
+    function ($request, $response) {
+        $model = new ImportModel();
+        $model->load();
+
+        $model->setFields($request->getParsedBody()['fields']);
+        $res = $model->store($this->zdb);
+        if ($res === true) {
+            $this->flash->addMessage(
+                'success_detected',
+                _T("Import model has been successfully stored :)")
+            );
+        } else {
+            $this->flash->addMessage(
+                'error_detected',
+                _T("Import model has not been stored :(")
+            );
+        }
+
+        return $response
+            ->withStatus(301)
+            ->withHeader('Location', $this->router->pathFor('importModel'));
+    }
+)->setName('storeImportModel')->add($authenticate);
index b377bea7929f19b79581d6e20758fd714fc197e3..c93a30e2bb945bb47fe8d36dad74a8310373000d 100644 (file)
@@ -58,11 +58,8 @@ use Galette\Entity\Texts;
 //self subscription
 $app->get(
     '/subscribe',
-    function () use ($app, $zdb, $i18n,
-        $members_fields, $members_fields_cats
-    ) {
-        if ( !$this->preferences->pref_bool_selfsubscribe || $this->login->isLogged() ) {
-
+    function ($request, $response) {
+        if (!$this->preferences->pref_bool_selfsubscribe || $this->login->isLogged()) {
             return $response
                 ->withStatus(301)
                 ->withHeader('Location', $this->router->pathFor('slash'));
@@ -77,8 +74,8 @@ $app->get(
         // flagging required fields
         $fc = new FieldsConfig(
             Adherent::TABLE,
-            $members_fields,
-            $members_fields_cats
+            $this->members_fields,
+            $this->members_fields_cats
         );
         $required = $fc->getRequired();
         // flagging fields visibility
@@ -96,7 +93,7 @@ $app->get(
 
         // - declare dynamic fields for display
         $disabled['dyn'] = array();
-        if ( !isset($adherent['dyn']) ) {
+        if (!isset($adherent['dyn'])) {
             $adherent['dyn'] = array();
         }
 
@@ -106,7 +103,10 @@ $app->get(
         $spam_img = $spam->getImage();
 
         $dynamic_fields = $dyn_fields->prepareForDisplay(
-            'adh', $adherent['dyn'], $disabled['dyn'], 1
+            'adh',
+            $adherent['dyn'],
+            $disabled['dyn'],
+            1
         );
 
         /*if ( $has_register ) {
@@ -132,7 +132,7 @@ $app->get(
                     'member'            => $member,
                     'self_adh'          => true,
                     'dynamic_fields'    => $dynamic_fields,
-                    'languages'         => $i18n->getList(),
+                    'languages'         => $this->i18n->getList(),
                     'require_calendar'  => true,
                     // pseudo random int
                     'time'              => time(),
@@ -152,9 +152,7 @@ $app->get(
 //members list CSV export
 $app->get(
     '/members/export/csv',
-    function () use ($app, $zdb,
-        $members_fields, $members_fields_cats
-    ) {
+    function () use ($app, $zdb) {
         $csv = new CsvOut();
 
         if ( isset($this->session->filter_members) ) {
@@ -173,21 +171,21 @@ $app->get(
         // fields visibility
         $fc = new FieldsConfig(
             Adherent::TABLE,
-            $members_fields,
-            $members_fields_cats
+            $this->members_fields,
+            $this->members_fields_cats
         );
         $visibles = $fc->getVisibilities();
         $fields = array();
         $headers = array();
-        foreach ( $members_fields as $k=>$f ) {
-            if ( $k !== 'mdp_adh'
+        foreach ($this->members_fields as $k => $f) {
+            if ($k !== 'mdp_adh'
                 && $export_fields === null
                 || (is_array($export_fields) && in_array($k, $export_fields))
             ) {
-                if ( $visibles[$k] == FieldsConfig::VISIBLE ) {
+                if ($visibles[$k] == FieldsConfig::VISIBLE) {
                     $fields[] = $k;
                     $labels[] = $f['label'];
-                } else if ( ($this->login->isAdmin()
+                } elseif (($this->login->isAdmin()
                     || $this->login->isStaff()
                     || $this->login->isSuperAdmin())
                     && $visibles[$k] == FieldsConfig::ADMIN
@@ -214,20 +212,20 @@ $app->get(
         $t = new Titles();
         $titles = $t->getList($zdb);
 
-        foreach ($members_list as &$member ) {
-            if ( isset($member->id_statut) ) {
+        foreach ($members_list as &$member) {
+            if (isset($member->id_statut)) {
                 //add textual status
                 $member->id_statut = $statuses[$member->id_statut];
             }
 
-            if ( isset($member->titre_adh) ) {
+            if (isset($member->titre_adh)) {
                 //add textuel title
                 $member->titre_adh = $titles[$member->titre_adh]->short;
             }
 
             //handle dates
-            if (isset($member->date_crea_adh) ) {
-                if ( $member->date_crea_adh != ''
+            if (isset($member->date_crea_adh)) {
+                if ($member->date_crea_adh != ''
                     && $member->date_crea_adh != '1901-01-01'
                 ) {
                     $dcrea = new DateTime($member->date_crea_adh);
@@ -237,8 +235,8 @@ $app->get(
                 }
             }
 
-            if ( isset($member->date_modif_adh) ) {
-                if ( $member->date_modif_adh != ''
+            if (isset($member->date_modif_adh)) {
+                if ($member->date_modif_adh != ''
                     && $member->date_modif_adh != '1901-01-01'
                 ) {
                     $dmodif = new DateTime($member->date_modif_adh);
@@ -248,8 +246,8 @@ $app->get(
                 }
             }
 
-            if ( isset($member->date_echeance) ) {
-                if ( $member->date_echeance != ''
+            if (isset($member->date_echeance)) {
+                if ($member->date_echeance != ''
                     && $member->date_echeance != '1901-01-01'
                 ) {
                     $dech = new DateTime($member->date_echeance);
@@ -259,8 +257,8 @@ $app->get(
                 }
             }
 
-            if ( isset($member->ddn_adh) ) {
-                if ( $member->ddn_adh != ''
+            if (isset($member->ddn_adh)) {
+                if ($member->ddn_adh != ''
                     && $member->ddn_adh != '1901-01-01'
                 ) {
                     $ddn = new DateTime($member->ddn_adh);
@@ -270,35 +268,35 @@ $app->get(
                 }
             }
 
-            if ( isset($member->sexe_adh) ) {
+            if (isset($member->sexe_adh)) {
                 //handle gender
-                switch ( $member->sexe_adh ) {
-                case Adherent::MAN:
-                    $member->sexe_adh = _T("Man");
-                    break;
-                case Adherent::WOMAN:
-                    $member->sexe_adh = _T("Woman");
-                    break;
-                case Adherent::NC:
-                    $member->sexe_adh = _T("Unspecified");
-                    break;
+                switch ($member->sexe_adh) {
+                    case Adherent::MAN:
+                        $member->sexe_adh = _T("Man");
+                        break;
+                    case Adherent::WOMAN:
+                        $member->sexe_adh = _T("Woman");
+                        break;
+                    case Adherent::NC:
+                        $member->sexe_adh = _T("Unspecified");
+                        break;
                 }
             }
 
             //handle booleans
-            if ( isset($member->activite_adh) ) {
+            if (isset($member->activite_adh)) {
                 $member->activite_adh
                     = ($member->activite_adh) ? _T("Yes") : _T("No");
             }
-            if ( isset($member->bool_admin_adh) ) {
+            if (isset($member->bool_admin_adh)) {
                 $member->bool_admin_adh
                     = ($member->bool_admin_adh) ? _T("Yes") : _T("No");
             }
-            if ( isset($member->bool_exempt_adh) ) {
+            if (isset($member->bool_exempt_adh)) {
                 $member->bool_exempt_adh
                     = ($member->bool_exempt_adh) ? _T("Yes") : _T("No");
             }
-            if ( isset($member->bool_display_info) ) {
+            if (isset($member->bool_display_info)) {
                 $member->bool_display_info
                     = ($member->bool_display_info) ? _T("Yes") : _T("No");
             }
@@ -306,7 +304,7 @@ $app->get(
         $filename = 'filtered_memberslist.csv';
         $filepath = CsvOut::DEFAULT_DIRECTORY . $filename;
         $fp = fopen($filepath, 'w');
-        if ( $fp ) {
+        if ($fp) {
             $res = $csv->export(
                 $members_list,
                 Csv::DEFAULT_SEPARATOR,
@@ -322,7 +320,7 @@ $app->get(
         }
 
         $response = $app->response;
-        if (file_exists(CsvOut::DEFAULT_DIRECTORY . $filename) ) {
+        if (file_exists(CsvOut::DEFAULT_DIRECTORY . $filename)) {
             $response->headers->set('Content-Type', 'text/csv');
             $response->headers->set(
                 'Content-Disposition',
@@ -582,7 +580,7 @@ $app->get(
 //members card
 $app->get(
     '/member/{id:\d+}',
-    function ($request, $response, $args) use ($members_fields, $members_fields_cats) {
+    function ($request, $response, $args) {
         $id = $args['id'];
         $dyn_fields = new DynamicFields();
 
@@ -648,7 +646,7 @@ $app->get(
         }
 
         //Set caller page ref for cards error reporting
-        //$this->session['caller'] = 'voir_adherent.php?id_adh='.$id_adh;
+        //$this->session->caller = 'voir_adherent.php?id_adh='.$id_adh;
 
         // declare dynamic field values
         $adherent['dyn'] = $dyn_fields->getFields('adh', $id, true);
@@ -675,7 +673,7 @@ $app->get(
         }*/
 
         // flagging fields visibility
-        $fc = new FieldsConfig(Adherent::TABLE, $members_fields, $members_fields_cats);
+        $fc = new FieldsConfig(Adherent::TABLE, $this->members_fields, $this->members_fields_cats);
         $visibles = $fc->getVisibilities();
 
         $display_elements = $fc->getDisplayElements();
@@ -706,7 +704,7 @@ $app->get(
 
 $app->get(
     '/member/{action:edit|add}[/{id:\d+}]',
-    function ($request, $response, $args) use ($members_fields, $members_fields_cats) {
+    function ($request, $response, $args) {
         $action = $args['action'];
         $id = null;
         if (isset($args['id'])) {
@@ -783,7 +781,7 @@ $app->get(
         }
 
         // flagging required fields
-        $fc = new FieldsConfig(Adherent::TABLE, $members_fields, $members_fields_cats);
+        $fc = new FieldsConfig(Adherent::TABLE, $this->members_fields, $this->members_fields_cats);
 
         //address and mail fields are not required if member has a parent
         $no_parent_required = array(
@@ -925,8 +923,6 @@ $app->post(
     '/member/store',
     function () use (
         $app,
-        $members_fields,
-        $members_fields_cats,
         &$success_detected,
         &$warning_detected,
         &$error_detected
@@ -993,7 +989,7 @@ $app->post(
         }
 
         // flagging required fields
-        $fc = new FieldsConfig(Adherent::TABLE, $members_fields, $members_fields_cats);
+        $fc = new FieldsConfig(Adherent::TABLE, $this->members_fields, $this->members_fields_cats);
 
         // password required if we create a new member
         if ( $member->id != '' ) {
@@ -1317,7 +1313,7 @@ $app->post(
 //advanced search page
 $app->get(
     '/advanced-search',
-    function ($request, $response) use ($app, $members_fields, $members_fields_cats) {
+    function ($request, $response) {
         if (isset($this->session->filter_members)) {
             $filters = $this->session->filter_members;
             if (!$filters instanceof AdvancedMembersList) {
@@ -1331,11 +1327,11 @@ $app->get(
         $groups_list = $groups->getList();
 
         //we want only visibles fields
-        $fields = $members_fields;
+        $fields = $this->members_fields;
         $fc = new FieldsConfig(
             Adherent::TABLE,
-            $members_fields,
-            $members_fields_cats
+            $this->members_fields,
+            $this->members_fields_cats
         );
         $visibles = $fc->getVisibilities();
 
@@ -1875,7 +1871,7 @@ $app->get(
                     if (count($labels_members) > 0) {
                         $labels_filters = new MembersList();
                         $labels_filters->selected = $labels_members;
-                        $session['filters']['reminders_labels'] = serialize($labels_filters);
+                        $session->filters_reminders_labels = $labels_filters;
                         header('location: etiquettes_adherents.php');
                         die();
                     } else {
index 7107bc72e0f9e9e4ac3e10f8b3e1c18e5b84005c..f60573f35288267037f0442ca5106dbf0ca82d37 100644 (file)
@@ -68,8 +68,8 @@ $app->group('/public', function () {
     $this->get(
         '/members',
         function ($request, $response) {
-            if (isset($this->session['public_filters']['members'])) {
-                $filters = unserialize($this->session['public_filters']['members']);
+            if (isset($this->session->public_filters_members)) {
+                $filters = $this->session->public_filters_members;
             } else {
                 $filters = new MembersList();
             }
@@ -98,7 +98,7 @@ $app->group('/public', function () {
             $members = $m->getPublicList(false, null);
 
             $session = $this->session;
-            $session['public_filters']['members'] = serialize($filters);
+            $session->public_filters_members = $filters;
             $this->session = $session;
 
             //assign pagination variables to the template and add pagination links
index 8f9ab6af725cd492f2df908098b931b7a1c24c56..abc14ee4f3322b07c8bb3f34000058a144ec67c5 100644 (file)
@@ -8,7 +8,7 @@
             <p>{_T string="The following files have been written on disk:"}</p>
             <ul>
 {foreach item=ex from=$written}
-                <li><a href="{path_for name="getExport" data=["file" => $ex.name]}">{$ex.name} ({$ex.file})</a></li>
+                <li><a href="{path_for name="getCsv" data=["type" => "export", "file" => $ex.name]}">{$ex.name} ({$ex.file})</a></li>
 {/foreach}
             </ul>
         </div>
@@ -31,7 +31,7 @@
     {foreach item=export from=$existing name=existing_list}
                             <tr class="{if $smarty.foreach.existing_list.iteration % 2 eq 0}even{else}odd{/if}">
                                 <td >
-                                    <a href="{path_for name="getExport" data=["file" => $export.name]}">{$export.name}</a>
+                                    <a href="{path_for name="getCsv" data=["type" => "export", "file" => $export.name]}">{$export.name}</a>
                                 </td>
                                 <td>
                                     {$export.date}
@@ -40,7 +40,7 @@
                                     {$export.size}
                                 </td>
                                 <td class="actions_row">
-                                    <a href="{path_for name="removeExport" data=["file" => $export.name]}" title="{_T string="Remove '%file' from disk" pattern="/%file/" replace=$export.name}"><img src="{$template_subdir}images/delete.png" alt="{_T string="Delete"}"/></a>
+                                    <a href="{path_for name="removeCsv" data=["type" => "export", "file" => $export.name]}" title="{_T string="Remove '%file' from disk" pattern="/%file/" replace=$export.name}"><img src="{$template_subdir}images/delete.png" alt="{_T string="Delete"}"/></a>
                                 </td>
                             </tr>
     {/foreach}
index 7dd051baeb15d3fd00bd0dbf72bf622d66ecf527..57e2d4e8fc26301289643a8c55245cbeeea1fe7a 100644 (file)
@@ -1,7 +1,10 @@
+{extends file="page.tpl"}
+
+{block name="content"}
         <p class="center">
-            <a class="button" id="preferences" href="import_model.php">{_T string="Configure import model"}</a>
+            <a class="button" id="preferences" href="{path_for name="importModel"}">{_T string="Configure import model"}</a>
         </p>
-        <form class="form" action="import.php" method="post" enctype="multipart/form-data">
+        <form class="form" action="{path_for name="doImport"}" method="post">
             <fieldset>
                 <legend class="ui-state-active ui-corner-top">{_T string="Existing files"}</legend>
                 <div class="warningbox">
@@ -24,7 +27,7 @@
                             <tr class="{if $smarty.foreach.existing_list.iteration % 2 eq 0}even{else}odd{/if}">
                                 <td>
                                     <input type="radio" name="import_file" id="file{$smarty.foreach.existing_list.iteration}" value="{$import.name}"{if isset($import_file) and $import_file eq $import.name} checked="checked"{/if}/>
-                                    <label for="file{$smarty.foreach.existing_list.iteration}">{$import.name}</label> (<a href="get_import.php?file={$import.name}">{_T string="see"}</a>)
+                                    <label for="file{$smarty.foreach.existing_list.iteration}">{$import.name}</label> (<a href="{path_for name="getCsv" data=["type" => "import", "file" => $import.name]}">{_T string="see"}</a>)
                                 </td>
                                 <td>
                                     {$import.date}
@@ -33,7 +36,7 @@
                                     {$import.size}
                                 </td>
                                 <td class="actions_row">
-                                    <a href="import.php?sup={$import.name}" title="{_T string="Remove '%file' from disk" pattern="/%file/" replace=$import.name}"><img src="{$template_subdir}images/delete.png" alt="{_T string="Delete"}"/></a>
+                                    <a href="{path_for name="removeCsv" data=["type" => "import", "file" => $import.name]}" title="{_T string="Remove '%file' from disk" pattern="/%file/" replace=$import.name}"><img src="{$template_subdir}images/delete.png" alt="{_T string="Delete"}"/></a>
                                 </td>
                             </tr>
     {/foreach}
@@ -49,7 +52,8 @@
 {/if}
                 </div>
             </fieldset>
-
+        </form>
+        <form class="form" action="{path_for name="uploadImportFile"}" method="post" enctype="multipart/form-data">
             <fieldset>
                 <legend class="ui-state-active ui-corner-top">{_T string="Upload new file"}</legend>
                 <div>
@@ -63,7 +67,9 @@
                 </div>
             </fieldset>
         </form>
+{/block}
 
+{block name="javascripts"}
         <script type="text/javascript">
             $(function() {
                 _collapsibleFieldsets();
                 });
             });
         </script>
+{/block}
index 1b29fd6bc06aa1beac42be25576acbdbd19079d9..b674103ae9f735a210d168ccc8a18fac162289ae 100644 (file)
@@ -1,3 +1,6 @@
+{extends file="page.tpl"}
+
+{block name="content"}
 <div id="model_tabs" class="tabbed">
     <ul>
         <li><a href="#current">{_T string="Current model"}</a></li>
         {/foreach}
         </table>
         <div class="button-container">
-            <a id="memberslist" class="button" href="import_model.php?generate=true">{_T string="Generate empty CSV file"}</a>
+            <a id="memberslist" class="button" href="{path_for name="getImportModel"}">{_T string="Generate empty CSV file"}</a>
             {if !$defaults_loaded}
-            <a id="delete" class="button" href="import_model.php?remove=true">{_T string="Remove model and back to defaults"}</a>
+            <a id="delete" class="button" href="{path_for name="importModel"}?remove=true">{_T string="Remove model and back to defaults"}</a>
             {/if}
         </div>
     </div>
     <div id="change">
-        <form action="import_model.php" method="POST">
+        <form action="{path_for name="storeImportModel"}" method="POST">
         <table class="listing">
             <thead>
                 <tr>
     </div>
 </div>
 <p class="center">
-    <a class="button" id="btnback" href="import.php">{_T string="Go back to import page"}</a>
+    <a class="button" id="btnback" href="{path_for name="import"}">{_T string="Go back to import page"}</a>
 </p>
+{/block}
 
+{block name="javascripts"}
 <script type="text/javascript">
     $(function(){
         $('#model_tabs').tabs();
@@ -86,3 +91,4 @@
         });
     });
 </script>
+{/block}
index d4ed11100509b4e24d28445bf33c2abe548824a4..8792dd01191a2debdb0845489430b23c5b0b6437 100644 (file)
@@ -122,8 +122,8 @@ We have to use a template file, so Smarty will do its work (like replacing varia
             <li{if $PAGENAME eq "reminder.php"} class="selected"{/if}><a href="{$galette_base_path}reminder.php" title="{_T string="Send reminders to late members"}">{_T string="Reminders"}</a></li>
             <li{if $cur_route eq "history"} class="selected"{/if}><a href="{path_for name="history"}" title="{_T string="View application's logs"}">{_T string="Logs"}</a></li>
             <li{if $cur_route eq "mailings"} class="selected"{/if}><a href="{path_for name="mailings"}" title="{_T string="Manage mailings that has been sent"}">{_T string="Manage mailings"}</a></li>
-            <li{if $PAGENAME eq "export.php"} class="selected"{/if}><a href="{$galette_base_path}export.php" title="{_T string="Export some data in various formats"}">{_T string="Exports"}</a></li>
-            <li{if $PAGENAME eq "import.php" or $PAGENAME eq "import_model.php"} class="selected"{/if}><a href="{$galette_base_path}import.php" title="{_T string="Import members from CSV files"}">{_T string="Imports"}</a></li>
+            <li{if $cur_route eq "export"} class="selected"{/if}><a href="{path_for name="export"}" title="{_T string="Export some data in various formats"}">{_T string="Exports"}</a></li>
+            <li{if $cur_route eq "import" or $cur_route eq "importModel"} class="selected"{/if}><a href="{path_for name="import"}" title="{_T string="Import members from CSV files"}">{_T string="Imports"}</a></li>
             <li class="mnu_last{if $cur_route eq "charts"} selected{/if}"><a href="{path_for name="charts"}" title="{_T string="Various charts"}">{_T string="Charts"}</a></li>
   {else}
             <li{if $cur_route eq "contributions"} class="selected"{/if}><a href="{path_for name="contributions"}" title="{_T string="View and filter all my contributions"}">{_T string="My contributions"}</a></li>