2026-02-24 14:26:25 +00:00
|
|
|
<?php
|
2026-02-27 13:56:12 +00:00
|
|
|
function getRaccourcis($bdd)
|
|
|
|
|
{
|
2026-02-24 14:26:25 +00:00
|
|
|
$results = mysqli_query($bdd, "SELECT * FROM `raccourcis`");
|
|
|
|
|
$return = [];
|
|
|
|
|
return $results;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-27 13:56:12 +00:00
|
|
|
function connectBDD($domain, $user, $password, $db)
|
|
|
|
|
{
|
2026-02-24 14:26:25 +00:00
|
|
|
$link = mysqli_connect($domain, $user, $password, $db);
|
|
|
|
|
|
|
|
|
|
if (!$link) {
|
|
|
|
|
die('Erreur de connexion');
|
|
|
|
|
} else {
|
|
|
|
|
mysqli_set_charset($link, "utf8");
|
|
|
|
|
|
|
|
|
|
return $link;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 10:30:23 +00:00
|
|
|
function getActus($bdd, $limit)
|
2026-02-27 13:56:12 +00:00
|
|
|
{
|
2026-03-06 16:23:04 +00:00
|
|
|
$results = mysqli_query($bdd, "SELECT * FROM actus ORDER BY id DESC LIMIT " . $limit);
|
2026-03-06 10:30:23 +00:00
|
|
|
$actus = [];
|
|
|
|
|
while ($row = mysqli_fetch_assoc($results)) {
|
|
|
|
|
$actus[] = $row;
|
|
|
|
|
}
|
|
|
|
|
return $actus;
|
2026-02-24 14:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-27 13:56:12 +00:00
|
|
|
function validateCSRFToken($csrf_server, $csrf_client)
|
|
|
|
|
{
|
2026-02-24 14:26:25 +00:00
|
|
|
if (!hash_equals($csrf_server, $csrf_client)) {
|
2026-02-27 13:56:12 +00:00
|
|
|
echo ($csrf_client . " " . $csrf_server);
|
2026-02-24 14:26:25 +00:00
|
|
|
die('CSRF token validation failed');
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-27 13:56:12 +00:00
|
|
|
function verifyPassword($hash_password, $tryPassword)
|
|
|
|
|
{
|
2026-02-24 14:26:25 +00:00
|
|
|
$hashTry = hash('sha256', $tryPassword);
|
2026-02-27 13:56:12 +00:00
|
|
|
if ($hash_password == $hashTry) {
|
2026-02-24 14:26:25 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-27 13:56:12 +00:00
|
|
|
function getHashPwd($bdd, $username)
|
|
|
|
|
{
|
2026-02-24 14:26:25 +00:00
|
|
|
|
|
|
|
|
$stmt = mysqli_prepare(
|
|
|
|
|
$bdd,
|
|
|
|
|
"SELECT password FROM utilisateurs WHERE username = ? LIMIT 1"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_bind_param($stmt, "s", $username);
|
|
|
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
|
|
|
|
|
|
$result = mysqli_stmt_get_result($stmt);
|
|
|
|
|
$user = mysqli_fetch_assoc($result);
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
|
|
|
|
|
|
return $user; // retourne un tableau ou null
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-27 13:56:12 +00:00
|
|
|
function getEvenements($bdd, $site)
|
|
|
|
|
{
|
2026-02-24 14:26:25 +00:00
|
|
|
|
|
|
|
|
$results = mysqli_query(
|
|
|
|
|
$bdd,
|
|
|
|
|
"SELECT * FROM evenements WHERE `site_id`='" . $site . "' ORDER BY date DESC"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$evenements = [];
|
|
|
|
|
|
|
|
|
|
while ($row = mysqli_fetch_assoc($results)) {
|
|
|
|
|
$evenements[] = $row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $evenements;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-27 13:56:12 +00:00
|
|
|
function getSite($bdd, $username)
|
|
|
|
|
{
|
2026-02-24 14:26:25 +00:00
|
|
|
$stmt = mysqli_prepare(
|
|
|
|
|
$bdd,
|
|
|
|
|
"SELECT site_id FROM utilisateurs WHERE username = ? LIMIT 1"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_bind_param($stmt, "s", $username);
|
|
|
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
|
|
|
|
|
|
$result = mysqli_stmt_get_result($stmt);
|
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
|
|
|
|
|
|
return $row ? $row['site_id'] : null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-27 13:56:12 +00:00
|
|
|
function getSiteName($bdd, $site)
|
|
|
|
|
{
|
2026-02-24 14:26:25 +00:00
|
|
|
$stmt = mysqli_prepare(
|
|
|
|
|
$bdd,
|
|
|
|
|
"SELECT nom FROM site WHERE site_id = ? LIMIT 1"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_bind_param($stmt, "s", $site);
|
|
|
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
|
|
|
|
|
|
$result = mysqli_stmt_get_result($stmt);
|
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
|
|
|
|
|
|
return $row ? $row['nom'] : null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-27 13:56:12 +00:00
|
|
|
function getEventName($bdd, $event)
|
|
|
|
|
{
|
2026-02-24 14:26:25 +00:00
|
|
|
$stmt = mysqli_prepare(
|
|
|
|
|
$bdd,
|
|
|
|
|
"SELECT titre FROM evenements WHERE id = ? LIMIT 1"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_bind_param($stmt, "s", $event);
|
|
|
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
|
|
|
|
|
|
$result = mysqli_stmt_get_result($stmt);
|
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
|
|
|
|
|
|
return $row ? $row['titre'] : null;
|
2026-02-24 15:43:05 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-27 13:56:12 +00:00
|
|
|
function getEventImages($bdd, $event)
|
|
|
|
|
{
|
2026-02-24 15:43:05 +00:00
|
|
|
$results = mysqli_query(
|
|
|
|
|
$bdd,
|
|
|
|
|
"SELECT * FROM gallerie WHERE `event_id`='" . $event . "'"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$evenements = [];
|
|
|
|
|
|
|
|
|
|
while ($row = mysqli_fetch_assoc($results)) {
|
|
|
|
|
$evenements[] = $row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $evenements;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-27 13:56:12 +00:00
|
|
|
function getEventBigImage($bdd, $event)
|
|
|
|
|
{
|
2026-02-24 15:43:05 +00:00
|
|
|
$stmt = mysqli_prepare(
|
|
|
|
|
$bdd,
|
|
|
|
|
"SELECT couverture FROM evenements WHERE id = ? LIMIT 1"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_bind_param($stmt, "s", $event);
|
|
|
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
|
|
|
|
|
|
$result = mysqli_stmt_get_result($stmt);
|
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
|
|
|
|
|
|
return $row ? $row['couverture'] : null;
|
2026-02-27 13:56:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getUserPerms($bdd, $username)
|
|
|
|
|
{
|
|
|
|
|
$stmt = mysqli_prepare(
|
|
|
|
|
$bdd,
|
|
|
|
|
"SELECT permissions FROM utilisateurs WHERE username = ? LIMIT 1"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_bind_param($stmt, "s", $username);
|
|
|
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
|
|
|
|
|
|
$result = mysqli_stmt_get_result($stmt);
|
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
|
|
|
|
|
|
return $row ? $row['permissions'] : null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 16:23:04 +00:00
|
|
|
function verifyPoids($bdd, $username, $minPoids)
|
|
|
|
|
{
|
2026-02-27 13:56:12 +00:00
|
|
|
$sql = "SELECT p.poids
|
|
|
|
|
FROM utilisateurs u
|
|
|
|
|
INNER JOIN permissions p ON u.permissions = p.nom
|
|
|
|
|
WHERE u.username = ?";
|
2026-03-06 16:23:04 +00:00
|
|
|
|
2026-02-27 13:56:12 +00:00
|
|
|
$stmt = mysqli_prepare($bdd, $sql);
|
2026-03-06 16:23:04 +00:00
|
|
|
|
2026-02-27 13:56:12 +00:00
|
|
|
if ($stmt) {
|
|
|
|
|
mysqli_stmt_bind_param($stmt, "s", $username);
|
|
|
|
|
mysqli_stmt_execute($stmt);
|
2026-03-06 16:23:04 +00:00
|
|
|
|
2026-02-27 13:56:12 +00:00
|
|
|
$result = mysqli_stmt_get_result($stmt);
|
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
2026-03-06 16:23:04 +00:00
|
|
|
|
2026-02-27 13:56:12 +00:00
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
|
|
|
|
|
|
if ($row) {
|
|
|
|
|
return (int)$row['poids'] >= (int)$minPoids;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-06 16:23:04 +00:00
|
|
|
|
2026-02-27 13:56:12 +00:00
|
|
|
return false;
|
2026-03-04 13:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-06 16:23:04 +00:00
|
|
|
function updateEventTitle($bdd, $eventid, $titre)
|
|
|
|
|
{
|
2026-03-04 13:26:06 +00:00
|
|
|
$stmt = mysqli_prepare(
|
|
|
|
|
$bdd,
|
|
|
|
|
"UPDATE evenements SET titre = ? WHERE id = ?"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_bind_param($stmt, "si", $titre, $eventid);
|
|
|
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
|
|
|
|
|
|
$success = mysqli_stmt_affected_rows($stmt) >= 0;
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
|
|
|
|
|
|
return $success;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 16:23:04 +00:00
|
|
|
function updateEventImage($bdd, $eventId, $image)
|
|
|
|
|
{
|
2026-03-04 13:26:06 +00:00
|
|
|
$stmt = mysqli_prepare(
|
|
|
|
|
$bdd,
|
|
|
|
|
"UPDATE evenements SET couverture = ? WHERE id = ?"
|
|
|
|
|
);
|
|
|
|
|
|
2026-03-06 10:30:23 +00:00
|
|
|
mysqli_stmt_bind_param($stmt, "si", $image, $eventId);
|
2026-03-04 13:26:06 +00:00
|
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
|
|
|
|
|
|
$success = mysqli_stmt_affected_rows($stmt) >= 0;
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
|
|
2026-03-04 16:34:46 +00:00
|
|
|
return $success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSpecificActus($bdd, $id)
|
|
|
|
|
{
|
|
|
|
|
$results = mysqli_query($bdd, "SELECT * FROM `actus` WHERE `id`=" . $id);
|
|
|
|
|
$return = [];
|
|
|
|
|
|
|
|
|
|
while ($row = mysqli_fetch_assoc($results)) {
|
|
|
|
|
$return[] = $row;
|
|
|
|
|
}
|
|
|
|
|
return $return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 16:23:04 +00:00
|
|
|
function updateActuImage($bdd, $actuId, $image)
|
|
|
|
|
{
|
2026-03-04 16:34:46 +00:00
|
|
|
$stmt = mysqli_prepare(
|
|
|
|
|
$bdd,
|
|
|
|
|
"UPDATE actus SET image = ? WHERE id = ?"
|
|
|
|
|
);
|
|
|
|
|
|
2026-03-06 10:30:23 +00:00
|
|
|
mysqli_stmt_bind_param($stmt, "si", $image, $actuId);
|
2026-03-04 16:34:46 +00:00
|
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
|
|
|
|
|
|
$success = mysqli_stmt_affected_rows($stmt) >= 0;
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
|
|
|
|
|
|
return $success;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 16:23:04 +00:00
|
|
|
function updateActuTitle($bdd, $actuId, $titre)
|
|
|
|
|
{
|
2026-03-04 16:34:46 +00:00
|
|
|
$stmt = mysqli_prepare(
|
|
|
|
|
$bdd,
|
|
|
|
|
"UPDATE actus SET titre = ? WHERE id = ?"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_bind_param($stmt, "si", $titre, $actuId);
|
|
|
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
|
|
|
|
|
|
$success = mysqli_stmt_affected_rows($stmt) >= 0;
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
|
|
|
|
|
|
return $success;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 16:23:04 +00:00
|
|
|
function updateActuContent($bdd, $actuId, $content)
|
|
|
|
|
{
|
2026-03-04 16:34:46 +00:00
|
|
|
$stmt = mysqli_prepare(
|
|
|
|
|
$bdd,
|
|
|
|
|
"UPDATE actus SET actu = ? WHERE id = ?"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_bind_param($stmt, "si", $content, $actuId);
|
|
|
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
|
|
|
|
|
|
$success = mysqli_stmt_affected_rows($stmt) >= 0;
|
|
|
|
|
|
|
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
|
|
2026-03-04 13:26:06 +00:00
|
|
|
return $success;
|
2026-03-06 08:50:19 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-06 16:23:04 +00:00
|
|
|
function createEvent($bdd, $titre, $date, $site)
|
|
|
|
|
{
|
2026-03-06 08:50:19 +00:00
|
|
|
|
|
|
|
|
$sql = "INSERT INTO evenements (date, titre, couverture, site_id) VALUES (?, ?, '', ?)";
|
|
|
|
|
$req = $bdd->prepare($sql);
|
|
|
|
|
$req->bind_param("ssi", $date, $titre, $site);
|
|
|
|
|
$req->execute();
|
|
|
|
|
return $bdd->insert_id;
|
2026-03-06 09:37:50 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-06 16:23:04 +00:00
|
|
|
function deleteEvent($bdd, $eventId)
|
|
|
|
|
{
|
2026-03-06 09:37:50 +00:00
|
|
|
$sql = "DELETE FROM evenements WHERE id = ?";
|
|
|
|
|
$req = $bdd->prepare($sql);
|
|
|
|
|
$req->bind_param("i", $eventId);
|
|
|
|
|
$req->execute();
|
|
|
|
|
return $req->affected_rows > 0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 16:23:04 +00:00
|
|
|
function deleteActu($bdd, $eventId)
|
|
|
|
|
{
|
2026-03-06 09:37:50 +00:00
|
|
|
$sql = "DELETE FROM actus WHERE id = ?";
|
|
|
|
|
$req = $bdd->prepare($sql);
|
|
|
|
|
$req->bind_param("i", $eventId);
|
|
|
|
|
$req->execute();
|
|
|
|
|
return $req->affected_rows > 0;
|
2026-03-06 10:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-06 16:23:04 +00:00
|
|
|
function createActu($bdd, $titre, $actu, $date, $idSite)
|
|
|
|
|
{
|
2026-03-06 10:30:23 +00:00
|
|
|
|
|
|
|
|
$stmt = mysqli_prepare(
|
|
|
|
|
$bdd,
|
|
|
|
|
"INSERT INTO actus (titre, actu, date, idSite) VALUES (?, ?, ?, ?)"
|
|
|
|
|
);
|
|
|
|
|
mysqli_stmt_bind_param($stmt, "sssi", $titre, $actu, $date, $idSite);
|
|
|
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
|
$actuId = mysqli_insert_id($bdd);
|
|
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
|
return $actuId;
|
2026-03-06 16:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createShortcut($bdd, $nom, $image, $shortcut)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$stmt = mysqli_prepare(
|
|
|
|
|
$bdd,
|
|
|
|
|
"INSERT INTO raccourcis (nom, image, url) VALUES (?, ?, ?)"
|
|
|
|
|
);
|
|
|
|
|
mysqli_stmt_bind_param($stmt, "sss", $nom, $image, $shortcut);
|
|
|
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
|
$actuId = mysqli_insert_id($bdd);
|
|
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
|
return $actuId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateRaccourcis($bdd, $idRaccourcis, $nom, $image, $url)
|
|
|
|
|
{
|
|
|
|
|
$stmt = mysqli_prepare(
|
|
|
|
|
$bdd,
|
|
|
|
|
"UPDATE raccourcis SET nom = ?, image = ?, url = ? WHERE id = ?"
|
|
|
|
|
);
|
|
|
|
|
mysqli_stmt_bind_param($stmt, "sssi", $nom, $image, $url, $idRaccourcis);
|
|
|
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
|
$success = mysqli_stmt_affected_rows($stmt) >= 0;
|
|
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
|
return $success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSpecificRaccourcis($bdd, $id)
|
|
|
|
|
{
|
|
|
|
|
$results = mysqli_query($bdd, "SELECT * FROM `raccourcis` WHERE `id`=" . $id);
|
|
|
|
|
$return = [];
|
|
|
|
|
|
|
|
|
|
while ($row = mysqli_fetch_assoc($results)) {
|
|
|
|
|
$return[] = $row;
|
|
|
|
|
}
|
|
|
|
|
return $return;
|
|
|
|
|
}
|
2026-03-10 09:37:35 +00:00
|
|
|
|
|
|
|
|
function getGuides($bdd) {
|
|
|
|
|
$results = mysqli_query($bdd, "SELECT * FROM `guides`");
|
|
|
|
|
|
|
|
|
|
$return = [];
|
|
|
|
|
|
|
|
|
|
while ($row = mysqli_fetch_assoc($results)) {
|
|
|
|
|
$return[] = $row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
|
}
|