bouton suppression d'ensembles en attente de validation

This commit is contained in:
thaaoblues 2023-12-23 22:02:14 +01:00
parent c867505f42
commit 94e777d031
5 changed files with 50 additions and 6 deletions

View file

@ -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."]));
}

15
bdd.php
View file

@ -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";
}
?>

View file

@ -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)
);

View file

@ -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 |

View file

@ -66,6 +66,8 @@ function displayDocuments() {
// complète le formulaire du dernier ensemble itéré
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>";
}
@ -77,12 +79,12 @@ function displayDocuments() {
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document Validation Dashboard</title>
<title>Validation des documents</title>
<!-- Include your CSS styles here -->
</head>
<body>
<h2>Document Validation Dashboard</h2>
<h2>Validation des documents</h2>
<!-- Display documents -->
<?php displayDocuments(); ?>
@ -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);
});
}
</script>