diff --git a/api.php b/api.php index 8310e7e..f56f9df 100644 --- a/api.php +++ b/api.php @@ -181,6 +181,15 @@ echo( json_encode(["status"=> "0","msg"=> $e->getMessage() ]) ); } break; + + case "supprimer_ensemble": + try{ + supprimer_ensemble($_POST["ensemble_id"]); + echo(json_encode(["status"=>"1","msg"=>"Ensemble supprimé."])); + }catch(Exception $e){ + echo( json_encode(["status"=> "0","msg"=> $e->getMessage() ]) ); + } + break; default: echo(json_encode(["status"=> "2","msg"=> "Opération inconnue."])); } diff --git a/bdd.php b/bdd.php index 56a75a8..cbd45c1 100644 --- a/bdd.php +++ b/bdd.php @@ -176,8 +176,8 @@ function saveFilesFromPost($postData,$id_ensemble) { } // ensuite, on enregistre les qui lui sont associés - $sql= 'INSERT INTO exercices_themes (exercice_id,theme_id) VALUES(?,?)'; - $result = $conn->execute_query($sql,array($id_exo,$id_theme)); + $sql= 'INSERT INTO exercices_themes (exercice_id,ensemble_id,theme_id) VALUES(?,?,?)'; + $result = $conn->execute_query($sql,array($id_exo,$id_ensemble,$id_theme)); echo("enregistrement d'un exercice"); } } @@ -256,9 +256,16 @@ function RechercheExercices($query, $length, $tags) function valider_ensemble($ensembleId) { - $updateQuery = "UPDATE ensembles SET valide = 1 WHERE id = $ensembleId"; + $sql = "UPDATE ensembles SET valide = 1 WHERE id = $ensembleId"; global $conn; - $conn->execute_query($updateQuery); + $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"; } ?> diff --git a/init_db.php b/init_db.php index a4c85f9..a8fca4b 100644 --- a/init_db.php +++ b/init_db.php @@ -51,8 +51,10 @@ $sql = " CREATE TABLE IF NOT EXISTS exercices_themes ( id INT AUTO_INCREMENT PRIMARY KEY, exercice_id INT, + ensemble_id INT, theme_id INT, FOREIGN KEY (exercice_id) REFERENCES exercices(id), + FOREIGN KEY (ensemble_id) REFERENCES ensembles(id), FOREIGN KEY (theme_id) REFERENCES themes(id) ); diff --git a/readme.md b/readme.md index 91fd9db..e1f0e05 100644 --- a/readme.md +++ b/readme.md @@ -16,6 +16,7 @@ D'autres fonctionnalités seront ajoutées petit à petit. (si vous avez des sug | Column | Type | Constraints | |--------------|--------|-------------------------------------------| | exercice_id | INT | FOREIGN KEY (exercice_id) REFERENCES exercises(id) | +| ensemble_id | INT | FOREIGN KEY (ensemble_id) REFERENCES ensembles(id) | | theme_id | INT | FOREIGN KEY (theme_id) REFERENCES themes(id) | | id | INT | AUTO_INCREMENT, PRIMARY KEY | diff --git a/validation.php b/validation.php index 657a6bb..e197822 100644 --- a/validation.php +++ b/validation.php @@ -66,6 +66,8 @@ function displayDocuments() { // complète le formulaire du dernier ensemble itéré echo "

Valider l'ensemble

"; + echo "

Supprimer l'ensemble

"; + echo ""; } @@ -77,12 +79,12 @@ function displayDocuments() { - Document Validation Dashboard + Validation des documents -

Document Validation Dashboard

+

Validation des documents

@@ -109,6 +111,29 @@ function displayDocuments() { console.error('Error:', error); }); } + + + function supprimer_ensemble(ensembleId) { + + fetch('api.php/supprimer_ensemble', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: 'ensemble_id=' + ensembleId, + }) + .then(response => response.json()) + .then(data => { + if (data.status == 1) { + alert(data.msg) + }else{ + alert(data.msg) + } + }) + .catch(error => { + console.error('Error:', error); + }); + }