système de validation des ensembles et meilleur chemin

This commit is contained in:
thaaoblues 2023-11-10 22:38:52 +01:00
parent 24da539d65
commit 2ca7fbe1c4
2 changed files with 122 additions and 11 deletions

14
bdd.php
View file

@ -121,14 +121,14 @@ function saveFilesFromPost($postData,$id_ensemble) {
global $max_val_type;
if ($safe_type < 1|| $safe_type > $max_val_type) {
if ($safe_type < 1 || $safe_type > $max_val_type) {
echo(json_encode(['status'=> '2','msg'=>"Le type de document spécifié n'existe pas."]));
exit;
}
// pour tester, pas implémenté les commentaires globaux ni les themes
$sql="INSERT INTO documents (titre,type,upload_path,commentaire_auteur,ensemble_id) VALUES(?,?,?,?,?)";
$conn->execute_query($sql,array($safe_titre,$safe_type,"archives/"+$uniqueFileName,$postData['commentaire_doc_'.$i],$id_ensemble));
$conn->execute_query($sql,array($safe_titre,$safe_type,"archives/".$uniqueFileName,$postData['commentaire_doc_'.$i],$id_ensemble));
}catch(Exception $e){
echo(json_encode(['status'=> '0','msg'=>$e->getMessage()]));
//exit;
@ -146,7 +146,6 @@ function saveFilesFromPost($postData,$id_ensemble) {
if($safe_type == 1){
$exercices = json_decode($postData['exercices'],true);
foreach ($exercices as $key => $ex) {
// premièrement, on enregistre l'exercice
$sql= 'INSERT INTO exercices (commentaire_auteur,ensemble_id,duree) VALUES(?,?,?)';
@ -156,7 +155,6 @@ function saveFilesFromPost($postData,$id_ensemble) {
// on recherche pour chaque thème s'il n'existe pas déjà,
// si non, on en créer un nouveau
foreach($ex["themes"] as $theme){
// pour l'instant un match complet mais on va essayer d'ameliorer ça avec
@ -205,11 +203,7 @@ function RechercheExercices($query, $length, $tags)
global $conn;
// Build the SQL query based on the search parameters
$sql = "SELECT * FROM documents";
if (!empty($query) || !empty($length) || !empty($tags)) {
$sql .= " WHERE ";
}
$sql = "SELECT * FROM documents AS d INNER JOIN ensembles AS e ON d.ensemble_id = e.id WHERE e.valide=TRUE";
$conditions = [];
@ -225,7 +219,7 @@ function RechercheExercices($query, $length, $tags)
if (!empty($tags)) {
$tagConditions = array_map(function ($tag) {
$tag = htmlspecialchars($tag);
return "EXISTS (SELECT * FROM exercices_themes AS et INNER JOIN themes AS t ON et.exercice_id = t.id WHERE et.theme_id = t.id AND t.name = '$tag')";
return "EXISTS (SELECT * FROM exercices_themes AS et INNER JOIN themes AS t ON et.exercice_id = t.id WHERE et.theme_id = t.id AND t.name = '$tag' AND)";
}, $tags);
$conditions[] = implode(" AND ", $tagConditions);

117
validation.php Normal file
View file

@ -0,0 +1,117 @@
<?php
// Include your database connection code here
include("test_creds.php");
$conn = new mysqli($servername, $username, $password,$dbname);
// Function to fetch and display documents
function displayDocuments() {
global $conn;
// Fetch documents associated with non-validated ensembles
// You need to customize the SQL query based on your actual database structure
$query = "SELECT * FROM documents
INNER JOIN ensembles ON documents.ensemble_id = ensembles.id
WHERE ensembles.valide = FALSE";
// Execute the query and fetch results
$result = $conn->query($query);
// Display all documents information
// Fini le div et met le bouton uniquement
// quand on finit d'itérer un ensemble donné
$ens_id = -1;
while($row = $result->fetch_assoc()) {
if (($row["ensemble_id"] != $ens_id) && ($ens_id != -1) ) {
echo "<p><a href='#' onclick='validateDocument({$ens_id})'>Valider l'ensembre</a></p>";
echo "</div>";
$ens_id = $row["ensemble_id"];
}
// initialisation pour la première itération
if ($ens_id == -1){
$ens_id = $row["ensemble_id"];
}
echo "<div>";
echo "<h3>{$row['titre']}</h3>";
echo "<p>Type: {$row['type']}</p>";
echo "<p>Upload Path: {$row['upload_path']}</p>";
echo "<p>Ensemble ID: {$row['ensemble_id']}</p>";
echo "<p>Theme ID: {$row['theme_id']}</p>";
echo "<img src=\"{$row['upload_path']}\">";
}
// complète le formulaire du dernier ensemble itéré
echo "<p><a href='#' onclick='validateDocument({$ens_id})'>Valider l'ensembre</a></p>";
echo "</div>";
}
// Function to validate documents in an ensemble
function valider_ensemble($ensembleId) {
// Update the "valide" status in the "ensembles" table
// You need to customize the SQL query based on your actual database structure
$updateQuery = "UPDATE ensembles SET valide = 1 WHERE id = $ensembleId";
// Execute the update query
global $conn;
$conn->execute_query($updateQuery);
}
// Check if the form is submitted for ensemble validation
if (isset($_POST['ensemble_id'])) {
$ensembleId = $_POST['ensemble_id'];
valider_ensemble($ensembleId);
}
// Include your HTML, CSS, and JavaScript for the frontend
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document Validation Dashboard</title>
<!-- Include your CSS styles here -->
</head>
<body>
<h2>Document Validation Dashboard</h2>
<!-- Display documents -->
<?php displayDocuments(); ?>
<!-- Include your JavaScript for document validation here -->
<script>
function validateDocument(ensembleId) {
// Send an AJAX request to validate the ensemble
// You can use fetch or jQuery.ajax
// Example using fetch:
fetch('validate_ensemble.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'ensemble_id=' + ensembleId,
})
.then(response => response.json())
.then(data => {
if (data.status == 1) {
// oui
}
})
.catch(error => {
console.error('Error:', error);
});
}
</script>
<!-- Include your HTML and CSS styles for the form to add documents here -->
</body>
</html>