<?php
class FrontController
{
    function __construct()
    {
        try { 
            global $error, $view, $rep;
            session_start();
            // Check role permissions
            echo "FrontController1\n";
            if (isset($_SESSION['role'])) {
                $role = $_SESSION['role'];
            } else {
                $role = "visitor";
            }
            // Check if action exists
            echo "FrontController2\n";
            $action = $_REQUEST['action'];
            echo $action . "\n";
            if ($role == "user") {
                if ($action == NULL) {
                    new UserController();
                }
                // else if (method_exists('UserModel', $action) == false) {
                //     $error = "Action non valide " . $action;
                //     require($rep . $view['erreur']);
                else {
                    new UserController();
                }
            } else {
                echo "FrontController3\n";
                new VisitorController();
            }
        } catch (Exception $e) {
            $error = $e->getMessage();
            require($rep . $view['erreur']);
        }
    }
}