From e5b1676d82f8b115634e330a5c2db6da4220364d Mon Sep 17 00:00:00 2001 From: thaaoblues Date: Tue, 16 Jan 2024 20:43:18 +0100 Subject: [PATCH] =?UTF-8?q?petites=20am=C3=A9liorations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bdd.php | 39 +++++++++++++++++++++++++++++++-------- televerser.php | 8 +++++--- validation.php | 4 +++- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/bdd.php b/bdd.php index 610c4b3..765f9d8 100644 --- a/bdd.php +++ b/bdd.php @@ -217,13 +217,19 @@ function RechercheExercices($query, $length, $tags) global $conn; // Build the SQL query based on the search parameters - $sql = "SELECT * FROM documents AS d INNER JOIN ensembles AS e ON d.ensemble_id = e.id WHERE e.valide=TRUE AND "; + $sql = "SELECT * FROM documents AS d INNER JOIN ensembles AS e ON d.ensemble_id = e.id WHERE e.valide=TRUE "; $conditions = []; if (!empty($query)) { + + // va essayer de retrouver tout les mots de la requête dans le titre $query = htmlspecialchars($query); - $conditions[] = "titre LIKE '%$query%'"; + $query_words = preg_split("[ ]",$query); + + foreach ($query_words as $word) { + $conditions[] = "AND titre LIKE '%$word%'"; + } } if (!empty($length)) { @@ -274,11 +280,28 @@ function valider_ensemble($ensembleId) { $conn->execute_query($sql); } -function supprimer_ensemble($ensembleId){ - $sql = "DELETE FROM exercices WHERE ensemble_id=$ensembleId"; - $sql = "DELETE FROM documents WHERE ensemble_id=$ensembleId"; - $sql = "DELETE FROM exercices_themes WHERE ensemble_id=$ensembleId"; - $sql = "DELETE FROM ensembles WHERE id=$ensembleId"; +function supprimer_ensemble($ensemble_id){ + + + global $conn; + + // premièrement, enlever tout les documents téléversés appartenant à l'ensemble + $sql = "SELECT upload_path FROM documents WHERE ensemble_id=?"; + $res = $conn->execute_query($sql,array($ensemble_id)); + + while($tmp=$res->fetch_assoc()){ + unlink($tmp["upload_path"]); + } + + // deuxièmement, supprimer toutes les traces de l'ensemble dans la bdd + $sql = "DELETE FROM exercices_themes WHERE ensemble_id=$ensemble_id"; + $conn->execute_query($sql); + $sql = "DELETE FROM exercices WHERE ensemble_id=$ensemble_id"; + $conn->execute_query($sql); + $sql = "DELETE FROM documents WHERE ensemble_id=$ensemble_id"; + $conn->execute_query($sql); + $sql = "DELETE FROM ensembles WHERE id=$ensemble_id"; + $conn->execute_query($sql); } @@ -287,7 +310,7 @@ function generer_chronologie(){ global $conn; // on va choper les 10 derniers trucs televerses par les gens - $sql = "SELECT * FROM ensembles ORDER BY date_televersement DESC"; + $sql = "SELECT * FROM ensembles WHERE valide=1 ORDER BY date_televersement DESC "; $res = $conn->execute_query($sql); $i = 0; diff --git a/televerser.php b/televerser.php index e61fe50..9142512 100644 --- a/televerser.php +++ b/televerser.php @@ -19,8 +19,10 @@ $csrf = new CSRF();
+
- + +
+
@@ -43,8 +46,7 @@ $csrf = new CSRF();
- - + diff --git a/validation.php b/validation.php index 954f7eb..c4e0467 100644 --- a/validation.php +++ b/validation.php @@ -37,7 +37,8 @@ function displayDocuments() { if (($row["ensemble_id"] != $ens_id) && ($ens_id != -1) ) { - echo "

Valider l'ensembre

"; + echo "

Valider l'ensemble

"; + echo "

Supprimer l'ensemble

"; echo ""; $ens_id = $row["ensemble_id"]; } @@ -131,6 +132,7 @@ function displayDocuments() { .then(data => { if (data.status == 1) { alert(data.msg) + document.location.reload(); }else{ alert(data.msg) }