forked from mougnibas/archinsa
bon mistral écrit de la merde on va faire le sql à la main
This commit is contained in:
parent
06394bb1a8
commit
0cff7402b3
3 changed files with 116 additions and 9 deletions
6
bdd.php
6
bdd.php
|
@ -66,7 +66,7 @@ function ajouter_doc($request){
|
|||
function saveFilesFromPost($postData,$id_ensemble) {
|
||||
|
||||
global $conn;
|
||||
|
||||
|
||||
|
||||
// Check if the $_POST variable is set and contains files
|
||||
//echo(print_r($_FILES,true));
|
||||
|
@ -219,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' AND)";
|
||||
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')";
|
||||
}, $tags);
|
||||
|
||||
$conditions[] = implode(" AND ", $tagConditions);
|
||||
|
@ -260,4 +260,4 @@ function valider_ensemble($ensembleId) {
|
|||
$conn->execute_query($updateQuery);
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
81
ens.php
Normal file
81
ens.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
include("session_verif.php");
|
||||
include("test_creds.php");
|
||||
|
||||
|
||||
try {
|
||||
$conn = new mysqli($servername, $username, $password,$dbname);
|
||||
} catch (Exception $e) {
|
||||
echo "Erreur : " . $e->getMessage();
|
||||
}
|
||||
|
||||
// Récupération de l'ID de l'ensemble et du thème depuis l'URL ou autrement
|
||||
$ensembleId = isset($_GET['ensemble_id']) ? intval($_GET['ensemble_id']) : '';
|
||||
$themeId = isset($_GET['theme_id']) ? intval($_GET['theme_id']) : '';
|
||||
|
||||
// Vérification de la validité de l'ID de l'ensemble
|
||||
if (!empty($ensembleId)) {
|
||||
// Préparation de la requête SQL pour obtenir les informations sur l'ensemble
|
||||
$sqlEnsemble = 'SELECT * FROM ensembles WHERE id = ?';
|
||||
$stmtEnsemble = $conn->prepare($sqlEnsemble);
|
||||
$stmtEnsemble->bind_param('i', $ensembleId);
|
||||
$stmtEnsemble->execute();
|
||||
$resultEnsemble = $stmtEnsemble->get_result();
|
||||
$ensemble = $resultEnsemble->fetch_assoc();
|
||||
|
||||
if ($ensemble && $ensemble['valide'] == true) {
|
||||
// Affichage de l'intitulé de l'ensemble
|
||||
echo '<h1>' . htmlspecialchars($ensemble['commentaire_auteur']) . '</h1>';
|
||||
|
||||
|
||||
// Préparation de la requête SQL pour obtenir les informations sur les exercices sélectionnés
|
||||
$sqlExos = 'SELECT e.*, t.name AS theme_name, te.id AS exotheme_id FROM exercices e '.
|
||||
'JOIN themes t ON e.ensemble_id = ?'.
|
||||
'LEFT JOIN exercices_themes te ON e.id = te.exercice_id ORDER BY te.id ASC';
|
||||
$stmtExos = $conn->prepare($sqlExos);
|
||||
echo($sqlExos);
|
||||
$stmtExos->bind_param('i', $ensembleId);
|
||||
$stmtExos->execute();
|
||||
$resultExos = $stmtExos->get_result();
|
||||
|
||||
while ($exo = $resultExos->fetch_assoc()) {
|
||||
switch ($exo['type']) {
|
||||
case 1:
|
||||
// Traiter les annales
|
||||
echo '<div class="document">';
|
||||
echo '<h2>' . htmlspecialchars($exo['titre']) . '</h2>';
|
||||
echo '<p>' . nl2br(htmlspecialchars($exo['commentaire_auteur'])) . '</p>';
|
||||
echo '<p>Durée estimée : ' . gmdate('H:i:s', $exo['duree']) . '</p>';
|
||||
echo '<a href="' . htmlspecialchars($exo['upload_path']) . '" target="_blank">Télécharger</a>';
|
||||
echo '</div>';
|
||||
break;
|
||||
case 2:
|
||||
// Traiter les textes à trous
|
||||
break;
|
||||
case 3:
|
||||
// Traiter les fiches de révision
|
||||
echo '<div class="document">';
|
||||
echo '<h2>' . htmlspecialchars($exo['titre']) . '</h2>';
|
||||
echo '<p>' . nl2br(htmlspecialchars($exo['commentaire_auteur'])) . '</p>';
|
||||
echo '<a href="' . htmlspecialchars($exo['upload_path']) . '" target="_blank">Télécharger</a>';
|
||||
echo '</div>';
|
||||
break;
|
||||
case 4:
|
||||
// Traiter les QCM
|
||||
echo "oui";
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo 'L\'ensemble demandé n\'existe pas ou il n\'est pas encore validé.';
|
||||
}
|
||||
} else {
|
||||
echo 'Aucun identifiant d\'ensemble fourni.';
|
||||
}
|
||||
|
||||
// Fermeture de la connexion à la base de données
|
||||
$conn->close();
|
||||
?>
|
||||
|
||||
|
||||
?>
|
38
index.php
38
index.php
|
@ -18,9 +18,9 @@
|
|||
|
||||
</div>
|
||||
|
||||
<form>
|
||||
<form id="recherche_form">
|
||||
<input type="text" id="recherche_input" placeholder="Rechercher une fiche, annale ...">
|
||||
<input type="text" id="themes_input" placeholder="themes séparés par une virgule">
|
||||
<input type="text" id="themes_input" placeholder="themes (appuyez sur la touche entrée entre chaque thèmes)">
|
||||
<input type="number" id="duree_input" placeholder="durée en minutes">
|
||||
</form>
|
||||
|
||||
|
@ -39,7 +39,6 @@
|
|||
data = await resp.json();
|
||||
console.log("test");
|
||||
if(data.status == 1){
|
||||
alert(1);
|
||||
document.getElementById("user_status").innerText = data["msg"];
|
||||
}
|
||||
}
|
||||
|
@ -57,15 +56,33 @@
|
|||
|
||||
async function rechercher(){
|
||||
var req = document.getElementById("recherche_input").value;
|
||||
|
||||
var themes = [];
|
||||
Array.from(document.getElementsByClassName("theme")).forEach(function (el) {
|
||||
// on encode en url pour pouvoir le passer dans la requete GET
|
||||
themes.push(encodeURIComponent(el.innerText));
|
||||
});
|
||||
var duree =document.getElementById("duree_input").value
|
||||
|
||||
resp = await fetch("/annales/api.php/rechercher?req="+req);
|
||||
|
||||
var url = "/annales/api.php/rechercher?req="+req;
|
||||
if(themes.toString() != ""){
|
||||
url = url +"&themes="+themes.toString();
|
||||
}
|
||||
|
||||
if(duree != ""){
|
||||
url = url +"duree="+duree;
|
||||
|
||||
}
|
||||
console.log(url);
|
||||
|
||||
resp = await fetch(url);
|
||||
|
||||
data = await resp.json();
|
||||
if(data.status == 1){
|
||||
data.resultats.forEach(doc => {
|
||||
const img = document.createElement("img");
|
||||
img.src = doc.upload_path;
|
||||
img.setAttribute("onclick","document.location.href='ens.php?ensemble_id="+doc.ensemble_id.toString()+"'");
|
||||
document.body.appendChild(img);
|
||||
});
|
||||
}
|
||||
|
@ -78,9 +95,18 @@
|
|||
rechercher();
|
||||
}
|
||||
}
|
||||
document.getElementById("themes_input").onkeydown =function(event) {
|
||||
if (event.key === "Enter"){
|
||||
var theme = document.createElement("div");
|
||||
theme.setAttribute("class","theme");
|
||||
theme.innerText = document.getElementById("themes_input").value;
|
||||
|
||||
document.getElementById("recherche_form").appendChild(theme);
|
||||
document.getElementById("themes_input").value = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
</html>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue