e59-website/html/upload.php
Jan BELLON cc74c9a421 Update 13 files
- /html/about.php
- /html/admin.php
- /html/compte.php
- /html/editpage.php
- /html/index.php
- /html/login.php
- /html/news.php
- /html/register.php
- /html/upload.php
- /html/users.php
- /config/global.ini
- /include/functions.php
- /include/variables.php
2024-03-08 21:50:10 +00:00

112 lines
3.4 KiB
PHP

<?php
require "../include/variables.php";
require "../include/functions.php";
$repertoire = "/var/www/e59/";
if($_SESSION['role'] < 3) {
header("Location: login.php");
http_response_code(404);
die();
}
if(isset($_POST['page-content'])) {
$filename = rand(100000, 999999);
while(file_exists($repertoire . "content/journal/" . $filename . ".md")) {
$filename = rand(100000, 999999);
}
file_put_contents($repertoire . "content/journal/" . $filename . ".md", nl2br($_POST['page-content']));
$bdd = connect($dbhost, $dbname, $dbuser, $dbpass);
$upload = $bdd->prepare("INSERT INTO articles (ID, titre, auteur, classification) VALUES (:filename, :titre, :auteur, :classification)");
$upload->bindParam(':filename', $filename);
$upload->bindParam(':titre', htmlspecialchars($_POST['titre']));
$upload->bindParam(':auteur', $_SESSION['display_name']);
$upload->bindParam(':classification', $_POST['classification']);
if($upload->execute()) {
$status = "Article Publié";
} else {
$status = "Erreur SQL";
}
header("Location: editpage.php?article=" . $filename);
exit();
}
?>
<!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">
<style>
@media (prefers-color-scheme: dark) {
.body {
<?=$theme_dark?>
}
}
@media (prefers-color-scheme: light) {
.body {
<?=$theme_light?>
}
}
</style>
<link rel="icon" href="src/img/favicon.ico">
<title><?=$title?></title>
<style>
textarea {
width: 100%;
min-height: 50em;
}
</style>
</head>
<body class="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="?article=<?=$filename?>" method="post">
<div>
<div><div><h1>Publier un article</h1></div>
<div><input type="text" name="titre" placeholder="Titre"></div>
<div><textarea name="page-content"></textarea></div>
<div>
<select name="classification" required>
<?php foreach($classifications as $id => $nom) { echo '<option value="' . $id .'">' . $nom . '</option>'; }?>
</select>
</div>
<div><input type="submit" value="Publier"></div>
</div>
</form>
</div>
</div>
</main>
<footer>
<div class="content">
<div>
<div><?=$copyright?></div>
</div>
</div>
</footer>
</body>
</html>