<?php
/**
 * Gestion des rôles - StayManager
 */

session_start();

// Inclure la configuration
require_once __DIR__ . '/config/config.php';
require_once __DIR__ . '/config/functions.php';
require_once __DIR__ . '/controllers/RoleController.php';

// Vérifier l'authentification
if (!isLoggedIn()) {
    redirect(getBaseUrl() . '/login.php');
}

// Vérifier les permissions
if (!hasPermission('roles.view')) {
    redirect(getBaseUrl() . '/error.php?code=403');
}

// Récupérer l'action
$action = isset($_GET['action']) ? $_GET['action'] : 'index';

// Router les actions
$controller = new RoleController();

switch ($action) {
    case 'index':
        $controller->index();
        break;
    case 'create':
        $controller->create();
        break;
    case 'edit':
        $controller->edit();
        break;
    case 'show':
        $controller->show();
        break;
    case 'delete':
        $controller->delete();
        break;
    default:
        $controller->index();
        break;
}
?>
