230 lines
No EOL
7.2 KiB
PHP
230 lines
No EOL
7.2 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"]);
|
|
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['connected']) || $_SESSION['connected'] == false) {
|
|
header('location: login.php?redirect_to=./admin/');
|
|
exit;
|
|
}
|
|
|
|
$minPoids = 45;
|
|
if (!verifyPoids($bdd, $_SESSION['username'], $minPoids)) {
|
|
header('location: ../index.php');
|
|
exit;
|
|
}
|
|
|
|
$eventId = $_GET['id'] ?? null;
|
|
$titre = getEventName($bdd, $eventId) ?? '';
|
|
$couverture = getEventBigImage($bdd, $eventId) ?? '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && empty($_POST['new'])) {
|
|
if (!empty($_POST['title'])) {
|
|
updateEventTitle($bdd, $eventId, trim($_POST['title']));
|
|
}
|
|
|
|
if (!empty($_FILES['couverture']['name'])) {
|
|
$uploadDir = "../Photos/INTRANET/";
|
|
$fileTmpPath = $_FILES["couverture"]["tmp_name"];
|
|
$fileSize = $_FILES["couverture"]["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["couverture"]["name"], PATHINFO_EXTENSION);
|
|
$newFileName = "event_" . $eventId . "_" . time() . "." . $extension;
|
|
$destination = $uploadDir . $newFileName;
|
|
|
|
if (move_uploaded_file($fileTmpPath, $destination)) {
|
|
if (!empty($couverture) && file_exists($uploadDir . $couverture)) {
|
|
unlink($uploadDir . $couverture);
|
|
}
|
|
updateEventImage($bdd, $eventId, $newFileName);
|
|
}
|
|
}
|
|
}
|
|
header("Location: ?id=" . $eventId);
|
|
exit;
|
|
}
|
|
if (!empty($_POST['new'])) {
|
|
|
|
$uploadDir = "../Photos/INTRANET/";
|
|
$fileTmpPath = $_FILES["couverture"]["tmp_name"];
|
|
$fileSize = $_FILES["couverture"]["size"];
|
|
$site = $_SESSION['site'];
|
|
|
|
$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["couverture"]["name"], PATHINFO_EXTENSION);
|
|
$eventId = createEvent($bdd, $_POST['title'], $_POST['date'], $site);
|
|
|
|
$newFileName = "event_" . $eventId . "_" . time() . "." . $extension;
|
|
|
|
$destination = $uploadDir . $newFileName;
|
|
|
|
if (move_uploaded_file($fileTmpPath, $destination)) {
|
|
updateEventImage($bdd, $eventId, $newFileName);
|
|
}
|
|
}
|
|
|
|
header("Location: ?id=" . $eventId);
|
|
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>
|
|
|
|
<ul class="nav nav-tabs mb-3">
|
|
<li class="nav-item">
|
|
<a class="nav-link active"
|
|
href="modifyEvent.php?id=<?= $eventId ?>">
|
|
Général
|
|
</a>
|
|
</li>
|
|
|
|
<li class="nav-item">
|
|
<a class="nav-link"
|
|
href="modifyGallery.php?id=<?= $eventId ?>">
|
|
Galerie
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
|
|
<div class="card p-4">
|
|
|
|
<form action="" method="post" enctype="multipart/form-data">
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Titre de l'évènement</label>
|
|
<input type="text"
|
|
name="title"
|
|
class="form-control"
|
|
value="<?= htmlspecialchars($titre) ?>">
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Image actuelle</label><br>
|
|
<?php if (!empty($couverture)) : ?>
|
|
<img src="../Photos/INTRANET/<?= htmlspecialchars($couverture) ?>"
|
|
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 couverture</label>
|
|
|
|
<div id="preview" class="preview-box mb-2">
|
|
<span class="text-muted">Aucune image sélectionnée</span>
|
|
</div>
|
|
|
|
<input type="file"
|
|
name="couverture"
|
|
id="couverture"
|
|
class="form-control"
|
|
accept="image/*">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Date de l'évènement</label>
|
|
<input type="date" name="date" class="form-control" value="<?= date('Y-m-d') ?>" required>
|
|
</div>
|
|
<?php if (empty($_GET['id'])): ?>
|
|
<input type="text" name="new" id="new" value="new" style="display: none;">
|
|
<?php endif ?>
|
|
|
|
<button type="button" class="btn btn-danger" onclick="window.location.href='delete.php?type=event&id=<?= $_GET['id'] ?>'">
|
|
Supprimer
|
|
</button>
|
|
|
|
<button type="submit" class="btn btn-primary">
|
|
Enregistrer les modifications
|
|
</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
const input = document.getElementById('couverture');
|
|
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>
|