<?php
require("../include/variables.php");
require("../include/functions.php");
$pdo = sqlConnect($sqlDatabaseHost, $sqlDatabaseName, $sqlDatabaseUser, $sqlDatabasePass);
?>

<!DOCTYPE html>
<html lang="fr">

    <head>
        <?php fillHead($rootPageURL, $pageTitle, $darkTheme, $lightTheme);?>
        <style></style>
    </head>

    <body class="body">

        <header>
            <div class="panel-content">
                <?php fillHeader($rootPageURL, $headerTitle, $headerSubtitle);?>
            </div>
        </header>

        <nav>
            <div class="panel-content">
                <?php fillNav($rootPageURL);?>
            </div>
        </nav>

        <main>
            <div class="content">
                
                <div class="markdown-text">
                    <?php
                        $pageContent = markdownContent('../content/pages/index.md', $rootFilePath);
                        echo($pageContent);
                    ?>
                </div>

                <div class="articles-list">
                <?php
                    $sqlRequest = "SELECT articles.ID, articles.title, articles.date, articles.miniature, articles.resume, users.username, users.display_name FROM articles JOIN users ON articles.author = users.ID WHERE articles.classification <= :userAccreditation ORDER BY date DESC LIMIT 3";
                    $request = $pdo->prepare($sqlRequest);
                    $request->bindParam(":userAccreditation", $_SESSION['userAccreditation']);
                    $request->execute();
                    $result = $request->fetchAll(PDO::FETCH_ASSOC);
                    if ($result) {
                        listArticles($result, $rootPageURL);
                    }
                ?>
            </div>
        </main>
        <footer>
            <div class="panel-content">
                <?php fillFooter($footerText);?>
            </div>
        </footer>
    </body>
</html>