e59-website/html/editpage.php
Jan BELLON 39f8085492 Update 5 files
- /include/variables.php
- /html/upload.php
- /html/journal.php
- /html/editpage.php
- /html/admin.php
2024-03-07 20:43:19 +00:00

155 lines
6.0 KiB
PHP

<?php
require "../include/variables.php";
require "../include/functions.php";
if($role < 3) {
header("Location: login.php");
http_response_code(404);
die();
}
$filetypes = [
0 => "article",
1 => "page"
];
$repertoire = "/var/www/e59/";
if(isset($_GET['article']) && filter_var($_GET['article'], FILTER_VALIDATE_INT)) {
if(file_exists($repertoire . "content/journal/" . $_GET['article'] . ".md")){
$fichier = $repertoire . "content/journal/" . $_GET['article'] . ".md";
$filename = $_GET['article'];
$filetype = 0;
}
}
if(isset($_GET['page']) && strpos($_GET['page'], "..") == false) {
if(file_exists($repertoire . "content/" . $_GET['page'] . ".md")){
$fichier = $repertoire . "content/" . $_GET['page'] . ".md";
$filename = $_GET['page'];
$filetype = 1;
}
}
if(isset($fichier)) {
if(isset($_GET['article']) && isset($_POST['deletefile']) && $_POST['deletefile'] == "Supprimer") {
if(unlink($fichier)) {
$bdd = connect($dbhost, $dbname, $dbuser, $dbpass);
$upload = $bdd->prepare("DELETE FROM articles WHERE ID = :filename");
$upload->bindParam(':filename', $filename);
if($upload->execute()) {
header("Location: editpage.php");
echo "Fichier supprimé";
exit();
} else {
die("Erreur SQL");
}
} else {
die("Erreur : Le fichier n'a pas pu être supprimé");
}
}
if(isset($_POST['page-content'])) {
file_put_contents($fichier, nl2br($_POST['page-content']));
}
$contenu = file_get_contents($fichier);
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./src/css/style.css">
<link rel="icon" href="src/img/favicon.ico">
<title><?=$title?></title>
<style>
textarea {
width: 100%;
min-height: 50em;
}
</style>
</head>
<body>
<header>
<div class="pancontent">
<div class="athena-container">
<a href="/">
<img src="./src/img/athena-mono.png" class="athena">
</a>
</div>
<div class="content">
<div>
<div class="main-title">
<div class="title"><?=$header_title?></div>
<div class="subtitle"><?=$header_subtitle?></div>
</div>
</div>
</div>
</div>
</header>
<nav>
<div class="pancontent">
<?php nav($nav);?>
</div>
</nav>
<main>
<div class="content">
<div>
<form action="?<?php echo $filetypes[$filetype] . "=" . $filename?>" method="post">
<div>
<?php
if(isset($contenu)) {
echo "<div><div><a href='editpage.php'>Retour</a></div>";
echo "<div><div><a href='journal.php?article=" . $filename . "'>Voir l'article</a></div>";
echo "<div><h1>" . $filename . "</h1></div>";
echo '<div><textarea name="page-content">' . $texte = str_replace("<br />", "", $contenu) . '</textarea></div>';
echo '<div><input type="submit" value="Publier"></div>';
} else {
echo "<div><div><h2>Pages</h2></div>";
echo "<div>";
$pages = scandir($repertoire . "content/");
foreach($pages as $page) {
if($page != "." && $page != "..") {
if (is_file($repertoire . "content/" . $page)) {
echo "<a href='?page=" . pathinfo($page, PATHINFO_FILENAME) . "' class='article-link'><div class='article'><div class='article-content'>" . pathinfo($page, PATHINFO_FILENAME) . "</div></div></a>";
}
}
}
echo "</div></div><div>";
echo "<div><h2>Articles</h2></div>";
$bdd = connect($dbhost, $dbname, $dbuser, $dbpass);
$req = $bdd->prepare("SELECT ID, titre, auteur, date FROM articles WHERE classification <= :role ORDER BY date DESC LIMIT 10");
$req->bindParam(":role", $_SESSION['role']);
$req->execute();
$resultat = $req->fetchAll(PDO::FETCH_ASSOC);
$date = new Datetime($row['date']);
if ($resultat) {
foreach($resultat as $row) {
echo "<a href='?article=" . $row['ID'] . "' class='article-link'><div class='article'><div class='article-content'><div><h1>" . $row['titre'] . "</h1></div><div><h2>" . $row['auteur'] . "</h2></div><div>" . $date->format('d/m/Y') . "</div></div></div></a>";
}
}
echo "</div>";
}
?>
</div>
</form>
<?php
if(isset($contenu)) {
echo '<form action=?article=' . $filename . ' method="post"><div><input type="submit" name="deletefile" value="Supprimer"></div></form>';
}
?>
</div>
</div>
</main>
<footer>
<div class="content">
<div>
<div><?=$copyright?></div>
</div>
</div>
</footer>
</body>
</html>