<?php
use \model\user;
session_start();


require_once('class/Autoloader.php');
require_once('vendor/autoload.php');
require('src/config.php');
require('src/functions.php');

$userModel=new user();
$router = new AltoRouter();
$router->setBasePath(__BASEPATH__);//labs.gowie.be/newPrivacy

$router->map( 'POST', '/optin', '\controller\optinController', 'optin' );
$router->map( 'POST', '/delete', '\controller\deleteController', 'delete' );
$router->map( 'GET|POST', '/[a:lang]', '\controller\indexController', 'home' );
$router->map( 'GET|POST', '/[a:lang]/dashboard', '\controller\dashboardController', 'dashboard' );
$router->map( 'GET', '/[a:lang]/confirm-mail', '\controller\mailConfirmController', 'mailConfirm' );


$match = $router->match();
if ($match === false) {
    // here you can handle 404
} else {
    //list( $controller, $action ) = explode( '#', $match['target'] );
    $lang=(!empty($match['params'])&&!empty($match['params']['lang'])&& in_array($match['params']['lang'],array('fr','nl')))?$match['params']['lang']:'fr';
    define('LANG',$lang);
    initialize_i18n(LANG.'_BE');

    if ( is_callable(array($match['target'],'index') )) {
        $class=new $match['target'];
        call_user_func(array($class,'index'));
        //call_user_func_array(array($controller,$action), array($match));
    } else {
        // here your routes are wrong.
        // Throw an exception in debug, send a  500 error in production
		//pre('else');
    }
}
