diff --git a/Assets/functions.php b/Assets/functions.php index 3ef2ad7..8cc18d2 100644 --- a/Assets/functions.php +++ b/Assets/functions.php @@ -21,7 +21,7 @@ function connectBDD($domain, $user, $password, $db) function getActus($bdd, $limit) { - $results = mysqli_query($bdd, "SELECT * FROM actus ORDER BY id DESC LIMIT ".$limit); + $results = mysqli_query($bdd, "SELECT * FROM actus ORDER BY id DESC LIMIT " . $limit); $actus = []; while ($row = mysqli_fetch_assoc($results)) { $actus[] = $row; @@ -189,32 +189,34 @@ function getUserPerms($bdd, $username) return $row ? $row['permissions'] : null; } -function verifyPoids($bdd, $username, $minPoids) { +function verifyPoids($bdd, $username, $minPoids) +{ $sql = "SELECT p.poids FROM utilisateurs u INNER JOIN permissions p ON u.permissions = p.nom WHERE u.username = ?"; - + $stmt = mysqli_prepare($bdd, $sql); - + if ($stmt) { 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); if ($row) { return (int)$row['poids'] >= (int)$minPoids; } } - + return false; } -function updateEventTitle($bdd, $eventid, $titre){ +function updateEventTitle($bdd, $eventid, $titre) +{ $stmt = mysqli_prepare( $bdd, "UPDATE evenements SET titre = ? WHERE id = ?" @@ -230,7 +232,8 @@ function updateEventTitle($bdd, $eventid, $titre){ return $success; } -function updateEventImage($bdd, $eventId, $image){ +function updateEventImage($bdd, $eventId, $image) +{ $stmt = mysqli_prepare( $bdd, "UPDATE evenements SET couverture = ? WHERE id = ?" @@ -257,7 +260,8 @@ function getSpecificActus($bdd, $id) return $return; } -function updateActuImage($bdd, $actuId, $image){ +function updateActuImage($bdd, $actuId, $image) +{ $stmt = mysqli_prepare( $bdd, "UPDATE actus SET image = ? WHERE id = ?" @@ -273,7 +277,8 @@ function updateActuImage($bdd, $actuId, $image){ return $success; } -function updateActuTitle($bdd, $actuId, $titre){ +function updateActuTitle($bdd, $actuId, $titre) +{ $stmt = mysqli_prepare( $bdd, "UPDATE actus SET titre = ? WHERE id = ?" @@ -289,7 +294,8 @@ function updateActuTitle($bdd, $actuId, $titre){ return $success; } -function updateActuContent($bdd, $actuId, $content){ +function updateActuContent($bdd, $actuId, $content) +{ $stmt = mysqli_prepare( $bdd, "UPDATE actus SET actu = ? WHERE id = ?" @@ -305,7 +311,8 @@ function updateActuContent($bdd, $actuId, $content){ return $success; } -function createEvent($bdd, $titre, $date, $site){ +function createEvent($bdd, $titre, $date, $site) +{ $sql = "INSERT INTO evenements (date, titre, couverture, site_id) VALUES (?, ?, '', ?)"; $req = $bdd->prepare($sql); @@ -314,7 +321,8 @@ function createEvent($bdd, $titre, $date, $site){ return $bdd->insert_id; } -function deleteEvent($bdd, $eventId){ +function deleteEvent($bdd, $eventId) +{ $sql = "DELETE FROM evenements WHERE id = ?"; $req = $bdd->prepare($sql); $req->bind_param("i", $eventId); @@ -322,7 +330,8 @@ function deleteEvent($bdd, $eventId){ return $req->affected_rows > 0; } -function deleteActu($bdd, $eventId){ +function deleteActu($bdd, $eventId) +{ $sql = "DELETE FROM actus WHERE id = ?"; $req = $bdd->prepare($sql); $req->bind_param("i", $eventId); @@ -330,7 +339,8 @@ function deleteActu($bdd, $eventId){ return $req->affected_rows > 0; } -function createActu($bdd, $titre, $actu, $date, $idSite){ +function createActu($bdd, $titre, $actu, $date, $idSite) +{ $stmt = mysqli_prepare( $bdd, @@ -341,4 +351,42 @@ function createActu($bdd, $titre, $actu, $date, $idSite){ $actuId = mysqli_insert_id($bdd); mysqli_stmt_close($stmt); return $actuId; -} \ No newline at end of file +} + +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; +} diff --git a/admin/admin.php b/admin/admin.php new file mode 100644 index 0000000..8bf7461 --- /dev/null +++ b/admin/admin.php @@ -0,0 +1,156 @@ + + + + +
+ +