<?PHP 
require_once('core.php');
if(!isset($_SESSION['id']))
{
header("Location: index.php");
exit();
}
$menu = "commu";
$page = "articles";
if(isset($_GET['id'])) {
$id = intval(htmlspecialchars($_GET['id']));
$SelectArticles = $bdd->prepare('SELECT * FROM pluscms_articles WHERE id = ?');
$SelectArticles->execute(array($id));
if ($SelectArticles->rowCount() == 1) {
$info = $SelectArticles->fetch();
} else {
$SelectArticles = $bdd->prepare('SELECT * FROM pluscms_articles ORDER BY id DESC LIMIT 1');
$SelectArticles->execute();
$info = $SelectArticles->fetch();
header('Location: articles?id='.$info['id']);
exit();
}
} else {
$SelectArticles = $bdd->prepare('SELECT * FROM pluscms_articles ORDER BY id DESC LIMIT 1');
$SelectArticles->execute();
$info = $SelectArticles->fetch();
header('Location: articles?id='.$info['id']);
exit();
}
?>
<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title><?PHP echo htmlentities(trim($cms['nom_hotel'])); ?> - <?PHP echo htmlspecialchars_decode($info['titre']); ?> </title>
        <link type="text/css" href="<?PHP echo htmlspecialchars(trim($cms['lien'])); ?>/web/css/material.css" rel="stylesheet">
        <link rel="stylesheet" type="text/css" href="<?PHP echo htmlspecialchars(trim($cms['lien'])); ?>/web/css/nav.css">
        <script src="<?PHP echo htmlspecialchars(trim($cms['lien'])); ?>/web/js/jquery.js"></script>
        <script type="text/javascript" src="<?PHP echo htmlspecialchars(trim($cms['lien'])); ?>/web/js/smoothscroll.js"></script>
    </head> 
    <body>
    <?PHP require_once('template/header/template_header.php'); ?>
        <div class="container_24">
        <?PHP require_once('template/header/template_nav.php'); ?>
            <div class="grid_6">
                <div id="contentBox" class="activity" style="overflow: hidden;">
                    <div class="head">
                        <div class="badgeImage habbo"></div>
                        Lire aussi..
                        <br>
                    </div>
                    <div class="text">
                    <?PHP 
                    $Select15 = $bdd->prepare('SELECT * FROM pluscms_articles LIMIT 15');
                    $Select15->execute();
                    while($all = $Select15->fetch()) { ?>
                        <a style="text-decoration: none;font-weight: 600;color: #373737;" href="articles?id=<?PHP echo htmlspecialchars(trim($all['id'])); ?>">- <?PHP echo htmlspecialchars_decode($all['titre']); ?></a><br>
                    <?PHP } ?>
                    </div>

                </div>
            </div>
            <div class="grid_18">
                <div id="contentBox" class="activity" style="overflow: hidden;">
                    <div class="head">
                        <div class="badgeImage <?PHP echo htmlspecialchars(trim($info['categorie'])); ?>"></div>
                        <?PHP echo htmlspecialchars(trim($info['titre'])); ?>
                        <br>
                        <span class="date"><?PHP echo htmlspecialchars(trim($info['titre'])); ?></span>
                        <br>
                        <span class="date">Posté le <?PHP echo date('d.m.Y à H:i', $info['date']); ?> par <?PHP echo htmlspecialchars(trim($info['par'])); ?> dans la catégorie <?PHP echo htmlspecialchars(trim($info['categorie'])); ?></span>
                    </div>
                    <div class="text">
                        <?PHP echo htmlspecialchars_decode($info['contenu']); ?>
                    </div>

                </div>
            </div>
            
            <div class="grid_24">
                <div id="contentBox">
                    <div class="title red">
                        <?PHP echo htmlentities(trim($cms['nom_hotel'])); ?> est propulsé par PlusCMS par Dodone.
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>