<?php
	include("connexion_inc.php");
	include("form_date.php");
	if(isset($_GET["id"]) && !empty($_GET["id"]))
	{
		$id=$_GET["id"];
		$sql_article="SELECT * FROM Article WHERE id=$id";
		$ret_article=$connexion->query($sql_article);
		$res_article=$ret_article->fetch(PDO::FETCH_ASSOC);
		if(empty($res_article))
		{
			header("Location:../index.php");
		}
	}
	else { header("Location:../index.php"); }
?>
<!DOCTYPE html>
<html lang="fr">
	<head>
		<meta charset="utf-8" />
		<meta name="description" content="" />
		<meta name="author" content="Édouard Lumet" />
		<meta name="copyright" content="CC BY-NC-SA 4.0" />
		<meta name="viewport" content="width=799" />
		<link rel="stylesheet" href="../css/reset.css" />
		<link rel="stylesheet" href="../css/style.css" />
		<link rel="stylesheet" href="../css/article.css" />
		<title>TheRedUnicorn | <?php echo $res_article["nom"]; ?></title>
	</head>

	<body>
	<div id="contBody">
		<header>
			<?php include("header.php"); ?>
		</header>

		<main>
			<?php
			echo "<h2>". $res_article["nom"] ."</h2>";
			echo "<h3>". $res_article["description"] ."</h3>";

			echo "<div id=\"contHead\">";

			echo "<div id=\"contDate\">";
			echo "<p class=\"date\">Cr&eacute;&eacute; le ". format_date($res_article["dateCrea"]) ."</p>";
			echo "<p class=\"date\">Derni&egrave;re modification le ". format_timestamp($res_article["dateModif"]) ."</p>";
			echo "</div>";

			echo "<div id=\"navArt\">";
			echo "<p class=\"btnNav\"><a href=\"https://news.the-redunicorn.fr\">Retour aux news</a></p>";
			echo "</div>";

			include("". $res_article["url"] ."");
			echo "</div>";
			?>

			<p class="btnNav"><a href="#contBody">Retour en haut de page</a></p>
		</main>

		<footer>
			<?php include("../html/footer.html"); ?>
		</footer>
	</div>
	</body>
</html>
