petites améliorations

This commit is contained in:
thaaoblues 2024-01-16 20:43:18 +01:00
parent ea47fc9efe
commit e5b1676d82
3 changed files with 39 additions and 12 deletions

39
bdd.php
View file

@ -217,13 +217,19 @@ function RechercheExercices($query, $length, $tags)
global $conn; global $conn;
// Build the SQL query based on the search parameters // 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 = []; $conditions = [];
if (!empty($query)) { if (!empty($query)) {
// va essayer de retrouver tout les mots de la requête dans le titre
$query = htmlspecialchars($query); $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)) { if (!empty($length)) {
@ -274,11 +280,28 @@ function valider_ensemble($ensembleId) {
$conn->execute_query($sql); $conn->execute_query($sql);
} }
function supprimer_ensemble($ensembleId){ function supprimer_ensemble($ensemble_id){
$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"; global $conn;
$sql = "DELETE FROM ensembles WHERE id=$ensembleId";
// 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; global $conn;
// on va choper les 10 derniers trucs televerses par les gens // 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); $res = $conn->execute_query($sql);
$i = 0; $i = 0;

View file

@ -19,8 +19,10 @@ $csrf = new CSRF();
<form id="uploadForm"> <form id="uploadForm">
<input type="file" id="fileInput" multiple> <input type="file" id="fileInput" multiple>
<br>
<input type="text" placeholder="titre" id="titre"></input> <input type="text" placeholder="titre" id="titre"></input>
<label for="titre">N'hésitez pas à bien mettre 1A, 2A, ... et la maitère concernée dans le titre.</label>
<br>
<select id="select_type" onchange="changer_mode()"> <select id="select_type" onchange="changer_mode()">
<option value="1" >annale</option> <option value="1" >annale</option>
<option value="2" >fiche_revision</option> <option value="2" >fiche_revision</option>
@ -28,6 +30,7 @@ $csrf = new CSRF();
</select> </select>
<input type="text" placeholder="commentaires généraux sur l'ensemble des documents" id="commentaire_auteur"></input> <input type="text" placeholder="commentaires généraux sur l'ensemble des documents" id="commentaire_auteur"></input>
<br>
<div id="selectedImages"></div> <div id="selectedImages"></div>
<div id="corrige_checkbox_wrapper"> <div id="corrige_checkbox_wrapper">
@ -43,8 +46,7 @@ $csrf = new CSRF();
<button onclick="ajouter_details_exo()">Ajouter les détails d'un exercice</button> <button onclick="ajouter_details_exo()">Ajouter les détails d'un exercice</button>
</div> </div>
<!-- Button to open the camera --> <button onclick="openCamera()">Prendre des photos</button>
<button onclick="openCamera()">Open Camera</button>

View file

@ -37,7 +37,8 @@ function displayDocuments() {
if (($row["ensemble_id"] != $ens_id) && ($ens_id != -1) ) { if (($row["ensemble_id"] != $ens_id) && ($ens_id != -1) ) {
echo "<p><a href='#' onclick='valider_ensemble({$ens_id})'>Valider l'ensembre</a></p>"; echo "<p><a href='#' onclick='valider_ensemble({$ens_id})'>Valider l'ensemble</a></p>";
echo "<p><a href='#' onclick='supprimer_ensemble({$ens_id})'>Supprimer l'ensemble</a></p>";
echo "</div>"; echo "</div>";
$ens_id = $row["ensemble_id"]; $ens_id = $row["ensemble_id"];
} }
@ -131,6 +132,7 @@ function displayDocuments() {
.then(data => { .then(data => {
if (data.status == 1) { if (data.status == 1) {
alert(data.msg) alert(data.msg)
document.location.reload();
}else{ }else{
alert(data.msg) alert(data.msg)
} }