193 lines
No EOL
5.8 KiB
PHP
193 lines
No EOL
5.8 KiB
PHP
<?php
|
|
include("../Assets/functions.php");
|
|
|
|
$config = json_decode(file_get_contents("../Assets/config.json"), true);
|
|
$bdd = connectBDD("localhost", $config["BDD_USER"], $config["BDD_PASSWD"], $config["BDD_NAME"]);
|
|
$page = 'photos';
|
|
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['connected']) || $_SESSION['connected'] == false) {
|
|
header('location: login.php?redirect_to=./admin/');
|
|
exit;
|
|
}
|
|
|
|
$minPoids = 50;
|
|
if (!verifyPoids($bdd, $_SESSION['username'], $minPoids)) {
|
|
header('location: ../index.php');
|
|
exit;
|
|
}
|
|
|
|
$actuId = $_GET['id'] ?? null;
|
|
if (!$actuId) {
|
|
die("ID évènement manquant.");
|
|
}
|
|
$actu = getSpecificActus($bdd, $actuId);
|
|
|
|
$titre = $actu[0]['titre'] ?? '';
|
|
$image = $actu[0]['image'] ?? '';
|
|
$contenu = $actu[0]['actu'];
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (!empty($_POST['title'])) {
|
|
updateActuTitle($bdd, $actuId, $_POST['title']);
|
|
}
|
|
|
|
if(!empty($_POST['content'])){
|
|
updateActuContent($bdd, $actuId, $_POST['content']);
|
|
}
|
|
|
|
if (!empty($_FILES['image']['name'])) {
|
|
$uploadDir = "../Photos/INTRANET/actus/";
|
|
$fileTmpPath = $_FILES["image"]["tmp_name"];
|
|
$fileSize = $_FILES["image"]["size"];
|
|
|
|
/* Vérification MIME réelle */
|
|
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
|
$mime = finfo_file($finfo, $fileTmpPath);
|
|
finfo_close($finfo);
|
|
|
|
$allowedTypes = ['image/jpeg', 'image/png', 'image/gif'];
|
|
|
|
if (in_array($mime, $allowedTypes) && $fileSize <= 5 * 1024 * 1024) {
|
|
|
|
$extension = pathinfo($_FILES["image"]["name"], PATHINFO_EXTENSION);
|
|
$newFileName = "actu_" . $actuId . "_" . time() . "." . $extension;
|
|
$destination = $uploadDir . $newFileName;
|
|
|
|
if (move_uploaded_file($fileTmpPath, $destination)) {
|
|
if (!empty($image) && file_exists($uploadDir . $image)) {
|
|
unlink($uploadDir . $image);
|
|
}
|
|
updateActuImage($bdd, $actuId, $newFileName);
|
|
}
|
|
}
|
|
}
|
|
header("Location: ?id=" . $actuId);
|
|
exit;
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Gestion Intranet</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
|
|
<style>
|
|
.preview-box {
|
|
height: 220px;
|
|
border: 2px dashed #ddd;
|
|
border-radius: 8px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
overflow: hidden;
|
|
background: #fafafa;
|
|
}
|
|
|
|
.preview-box img {
|
|
max-height: 100%;
|
|
max-width: 100%;
|
|
}
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body class="container py-4">
|
|
|
|
<h1>Gestion de l'intranet</h1>
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-light mb-4">
|
|
<div class="collapse navbar-collapse">
|
|
<ul class="navbar-nav mr-auto">
|
|
<li class="nav-item">
|
|
<a href="./index.php" class="nav-link">Évènements</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a href="#" class="nav-link">Actualités</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a href="#" class="nav-link disabled">Administration</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="card p-4">
|
|
<form action="" method="post" enctype="multipart/form-data">
|
|
<div class="mb-3">
|
|
<label class="form-label">Titre de l'actualité</label>
|
|
<input type="text"
|
|
name="title"
|
|
class="form-control"
|
|
value="<?= htmlspecialchars($titre) ?>">
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form_label">Nouveau contenu de l'actualité</label>
|
|
<textarea name="content" id="content"><?= $contenu ?></textarea>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Image actuelle</label><br>
|
|
<?php if (!empty($image)) : ?>
|
|
<img src="../Photos/INTRANET/actus/<?= htmlspecialchars($image) ?>"
|
|
style="max-width:300px; margin-bottom:15px;">
|
|
<?php else : ?>
|
|
<p class="text-muted">Aucune image définie</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Nouvelle image de l'actu</label>
|
|
|
|
<div id="preview" class="preview-box mb-2">
|
|
<span class="text-muted">Aucune image sélectionnée</span>
|
|
</div>
|
|
|
|
<input type="file"
|
|
name="image"
|
|
id="image"
|
|
class="form-control"
|
|
accept="image/*">
|
|
</div>
|
|
|
|
<button type="button" class="btn btn-danger" onclick="window.location.href='delete.php?type=actu&id=<?= $_GET['id'] ?>'">
|
|
Supprimer
|
|
</button>
|
|
|
|
<button type="submit" class="btn btn-primary">
|
|
Enregistrer les modifications
|
|
</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
const input = document.getElementById('image');
|
|
const preview = document.getElementById('preview');
|
|
|
|
input.addEventListener('change', function() {
|
|
const file = this.files[0];
|
|
|
|
if (file) {
|
|
const reader = new FileReader();
|
|
|
|
reader.onload = function(e) {
|
|
preview.innerHTML =
|
|
`<img src="${e.target.result}" alt="Preview">`;
|
|
};
|
|
|
|
reader.readAsDataURL(file);
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
|
|
</html>
|