<?php
require_once 'Config/database.php';
require_once 'Controllers/FileController.php';
require_once 'Controllers/AuthController.php';
require_once 'Controllers/MateriaController.php';  

$authController = new AuthController($conn);
$fileController = new FileController($conn);
$materiaController = new MateriaController($conn);


session_start();


if (isset($_GET['action'])) {
   if (isset($_GET['action'])) {
    if ($_GET['action'] === 'authenticate') {
        
        $authController->authenticate();
        exit;
    } elseif ($_GET['action'] === 'logout') {
        
        $authController->logout();
        exit;
    } elseif ($_GET['action'] === 'showDocumentForm') {
        
        $materiaId = $_GET['materia_id'];
        $fileController->showDocumentForm($materiaId);
        exit;
    } elseif ($_GET['action'] === 'uploadDocument') {
        
        $materiaId = $_GET['materia_id'];
        $fileController->upload($materiaId);
        exit;
    } elseif ($_GET['action'] === 'download') {
        
        $fileName = $_GET['file'];
        $fileController->download($fileName);
        exit;
    }
}

}


if (!isset($_SESSION['user_id'])) {
    
    $authController->login();
    exit;  
} 


$materiaController->showMaterias();
?>
