2016-04-04 09:47:17 +00:00
|
|
|
<?php define('__ROOT__', dirname(__FILE__) );
|
2016-04-18 06:42:26 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
require_once __ROOT__.'/manager/autoloader.php';
|
|
|
|
|
|
|
|
use \router\Router;
|
|
|
|
use \manager\ModuleRequest;
|
2016-06-04 09:06:36 +00:00
|
|
|
use \manager\ModuleResponse;
|
2016-04-12 15:46:34 +00:00
|
|
|
use \manager\ManagerError;
|
|
|
|
use \manager\Database;
|
2016-09-12 15:03:48 +00:00
|
|
|
use \manager\Checker;
|
2016-04-13 15:06:16 +00:00
|
|
|
use \manager\MenuManager;
|
2016-04-12 15:46:34 +00:00
|
|
|
|
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
/*******************************************/
|
|
|
|
/* DEBUGGER */
|
|
|
|
/*******************************************/
|
|
|
|
debug();
|
|
|
|
/*******************************************/
|
|
|
|
|
|
|
|
|
2016-06-02 16:52:12 +00:00
|
|
|
define('__REDIRECT__', 'Location: /dashboard/');
|
|
|
|
|
2016-04-13 11:36:49 +00:00
|
|
|
|
|
|
|
/* [x] Gestion des utilisateurs
|
2016-04-12 15:46:34 +00:00
|
|
|
=========================================================*/
|
|
|
|
/* (1) Valeurs par defaut */
|
|
|
|
if( !isset($_SESSION['userid']) ) $_SESSION['userid'] = null;
|
|
|
|
if( !isset($_SESSION['username']) ) $_SESSION['username'] = null;
|
|
|
|
if( !isset($_SESSION['permission']) ) $_SESSION['permission'] = array();
|
|
|
|
|
2016-04-13 11:36:49 +00:00
|
|
|
|
2016-04-12 15:46:34 +00:00
|
|
|
/* (2) Gestion de la connection */
|
2016-04-13 13:20:57 +00:00
|
|
|
$login_vars = isset($_POST['login-sub']);
|
2016-09-12 15:03:48 +00:00
|
|
|
$login_vars = $login_vars && isset($_POST['login']) && Checker::run('varchar(3,50)', $_POST['login']);
|
|
|
|
$login_vars = $login_vars && isset($_POST['password']) && Checker::run('text', $_POST['password']);
|
2016-04-12 15:46:34 +00:00
|
|
|
|
|
|
|
// Status de login
|
|
|
|
$_SESSION['login_status'] = 'no';
|
|
|
|
|
|
|
|
// Si les parametres de connection, on essaie de connecter
|
|
|
|
if( $login_vars ){
|
2016-04-17 16:01:23 +00:00
|
|
|
|
2016-04-14 10:45:54 +00:00
|
|
|
$login = new ModuleRequest('user/login', array( 'login' => $_POST['login'], 'password' => $_POST['password'] ));
|
2016-04-12 15:46:34 +00:00
|
|
|
$login_ans = $login->dispatch();
|
|
|
|
|
2016-06-02 16:52:12 +00:00
|
|
|
// Si aucune erreur, on dit qu'on vient de se connecter
|
2016-04-12 22:29:18 +00:00
|
|
|
if( $login_ans->error == ManagerError::Success )
|
2016-04-12 15:46:34 +00:00
|
|
|
$_SESSION['login_status'] = 'logged';
|
2016-04-13 11:36:49 +00:00
|
|
|
else // Si on n'a pas les bonnes donnees
|
2016-04-12 15:46:34 +00:00
|
|
|
$_SESSION['login_status'] = 'error';
|
|
|
|
}
|
2016-04-04 12:04:36 +00:00
|
|
|
|
|
|
|
|
2016-04-13 11:36:49 +00:00
|
|
|
/* (3) Gestion de le deconnexion */
|
2016-04-13 13:20:57 +00:00
|
|
|
$logout_vars = isset($_POST['logout-sub']);
|
|
|
|
|
2016-06-02 16:52:12 +00:00
|
|
|
// Si on se deconnecte
|
2016-04-13 13:20:57 +00:00
|
|
|
if( $logout_vars ){
|
2016-04-14 10:45:54 +00:00
|
|
|
$logout = new ModuleRequest('user/logout');
|
2016-04-13 13:20:57 +00:00
|
|
|
$logout_ans = $logout->dispatch();
|
|
|
|
|
|
|
|
// Si aucune erreur, on dit qu'on vient de se deconnecter
|
|
|
|
if( $logout_ans->error == ManagerError::Success )
|
|
|
|
$_SESSION['login_status'] = 'unlogged';
|
|
|
|
}
|
2016-04-13 11:36:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-17 16:01:23 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
/* [0] On initialise le routeur
|
|
|
|
===================================================*/
|
|
|
|
$R = new Router( $_GET['url'] );
|
2016-04-13 11:36:49 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-09-11 10:06:40 +00:00
|
|
|
/* (2) Gestion des SVG avec couleur modifiée */
|
2016-09-11 10:22:35 +00:00
|
|
|
// path/to/resource/filename@HEXADE.svg
|
2016-09-11 10:06:40 +00:00
|
|
|
$R->get('(.+)@([a-f0-9]{6})(\.svg)', function($matches){
|
|
|
|
$path = __ROOT__.'/'.$matches[0].$matches[2];
|
|
|
|
|
|
|
|
header('Content-Type: image/svg+xml');
|
|
|
|
|
|
|
|
// On crée la partie ajoutée
|
|
|
|
$stylesheet = "\n<style type='text/css'>\n";
|
|
|
|
$stylesheet .= "\t#stylisable{\n";
|
|
|
|
$stylesheet .= "\t\tfill: #".$matches[1]." !important;\n";
|
|
|
|
$stylesheet .= "\t\tfill-opacity: 1 !important;\n";
|
|
|
|
$stylesheet .= "\t}\n";
|
|
|
|
$stylesheet .= "</style></svg>";
|
|
|
|
|
|
|
|
// On récupère le fichier
|
|
|
|
$file = file_get_contents($path);
|
|
|
|
|
|
|
|
// On ajoute le style
|
|
|
|
$file = str_replace('</svg>', $stylesheet, $file);
|
|
|
|
|
|
|
|
echo $file;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
/* [1] On cree les regles de routage
|
|
|
|
===================================================*/
|
|
|
|
// Racine -> page d'accueil
|
2016-06-02 16:52:12 +00:00
|
|
|
$R->get('/?', function(){ header(__REDIRECT__); });
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-04 12:04:36 +00:00
|
|
|
|
|
|
|
/* [2] On recupere la liste des pages du site
|
|
|
|
=========================================================*/
|
2016-04-13 15:06:16 +00:00
|
|
|
$temporaryMenuInflater = new MenuManager();
|
|
|
|
$views = $temporaryMenuInflater->getCategories();
|
2016-04-04 12:04:36 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
// nomPage/arg1/arg2 -> inclusion de la page
|
2016-04-04 12:04:36 +00:00
|
|
|
$R->get('(?:'.implode('|', $views).')(?:/[\w-]+)*/?', function(){ include __ROOT__.'/view.php'; });
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-13 11:36:49 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-13 11:36:49 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
// Api
|
2016-06-03 08:06:47 +00:00
|
|
|
$R->post('api(?:/(.*))?', function($url){
|
|
|
|
$request = ModuleRequest::fromPost($url, $_POST);
|
2016-06-03 08:58:01 +00:00
|
|
|
$answer = $request->dispatch();
|
|
|
|
|
|
|
|
// Si c'est une réponse
|
2016-06-04 09:06:36 +00:00
|
|
|
if( $answer instanceof ModuleResponse )
|
2016-06-03 08:58:01 +00:00
|
|
|
echo $answer->serialize();
|
2016-04-18 06:42:26 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
});
|
|
|
|
|
2016-04-13 11:36:49 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
// N'importe -> page d'accueil
|
2016-06-02 16:52:12 +00:00
|
|
|
$R->get('.+', function(){ header(__REDIRECT__); });
|
|
|
|
$R->post('.+', function(){ header(__REDIRECT__); });
|
2016-04-18 06:42:26 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
|
2016-04-13 11:36:49 +00:00
|
|
|
|
2016-04-04 12:04:36 +00:00
|
|
|
/* [3] On lance le routeur
|
2016-04-04 09:47:17 +00:00
|
|
|
===================================================*/
|
|
|
|
$R->run();
|
|
|
|
|
2016-04-18 06:42:26 +00:00
|
|
|
?>
|