ajout d'un bouton de suppression dans les pages de modifications

This commit is contained in:
Erwann PHILIPPE 2026-03-06 10:37:50 +01:00
parent d4f4d70a45
commit 7ae0d37599
5 changed files with 60 additions and 1 deletions

View file

@ -309,4 +309,20 @@ function createEvent($bdd, $titre, $date, $site){
$req->bind_param("ssi", $date, $titre, $site); $req->bind_param("ssi", $date, $titre, $site);
$req->execute(); $req->execute();
return $bdd->insert_id; return $bdd->insert_id;
}
function deleteEvent($bdd, $eventId){
$sql = "DELETE FROM evenements WHERE id = ?";
$req = $bdd->prepare($sql);
$req->bind_param("i", $eventId);
$req->execute();
return $req->affected_rows > 0;
}
function deleteActu($bdd, $eventId){
$sql = "DELETE FROM actus WHERE id = ?";
$req = $bdd->prepare($sql);
$req->bind_param("i", $eventId);
$req->execute();
return $req->affected_rows > 0;
} }

36
admin/delete.php Normal file
View file

@ -0,0 +1,36 @@
<?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';
/* Gestion de la connexion */
session_start();
if (!isset($_SESSION['connected']) || $_SESSION['connected'] == false) {
header('location: ../login.php?redirect_to=./admin/');
}
/* Récupération des infos */
$permissions = $_SESSION['permission'];
$site = $_SESSION['site'];
/* Gestion de l'accès à la page */
$minPoids = 45;
if (!verifyPoids($bdd, $_SESSION['username'], $minPoids)) {
die("Vous n'avez pas l'autorisation");
header('location: ../index.php');
}
if(!empty($_GET['type'])){
$type = $_GET['type'];
$id = $_GET['id'];
if($type == 'event'){
$success = deleteEvent($bdd, $id);
}elseif($type == 'actu'){
$success = deleteActu($bdd, $id);
}
header('location: index.php');
exit();
}

View file

@ -72,7 +72,6 @@ $uploadDir = "../Photos/INTRANET/";
</div> </div>
<button type="button" class="btn btn-primary" style="position: fixed; bottom: 20px; right: 20px;" onclick="window.location.href='./modifyEvent.php'">Créer évènement</button> <button type="button" class="btn btn-primary" style="position: fixed; bottom: 20px; right: 20px;" onclick="window.location.href='./modifyEvent.php'">Créer évènement</button>
<button type="button" class="btn btn-danger" style="position: fixed; bottom: 20px;" onclick="window.location.href=''">Supprimer</button>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body> </body>

View file

@ -192,6 +192,10 @@ if (!empty($_POST['new'])) {
<input type="text" name="new" id="new" value="new" style="display: none;"> <input type="text" name="new" id="new" value="new" style="display: none;">
<?php endif ?> <?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"> <button type="submit" class="btn btn-primary">
Enregistrer les modifications Enregistrer les modifications
</button> </button>

View file

@ -155,6 +155,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
accept="image/*"> accept="image/*">
</div> </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"> <button type="submit" class="btn btn-primary">
Enregistrer les modifications Enregistrer les modifications
</button> </button>