ça c'est de la recherche qui recherche (pas fini)

This commit is contained in:
thaaoblues 2023-12-03 16:30:07 +01:00
parent b54bb08826
commit 06394bb1a8
7 changed files with 57 additions and 37 deletions

13
api.php
View file

@ -61,7 +61,9 @@
case 'rechercher':
// Exemple URL: /api.php/chercher?req=math&duree=30&themes=algebre,geometrie
$query = isset($_GET["req"]) ? $_GET["req"] : "";
$length = isset($_GET["duree"]) ? $_GET["duree"] : "";
$themes = isset($_GET["themes"]) ? explode(",", $_GET["themes"]) : [];
@ -88,7 +90,7 @@
if($_SERVER['REQUEST_METHOD'] === 'POST'){
verifier_session();
switch(array_pop($url_parts)){
case "aj_doc":
try{
@ -98,6 +100,15 @@
echo( json_encode(["status"=> "0","msg"=> $e->getMessage() ]) );
}
break;
case "valider_ensemble":
try{
valider_ensemble($_POST["ensemble_id"]);
echo(json_encode(["status"=>"1","msg"=>"Ensemble validé."]));
}catch(Exception $e){
echo( json_encode(["status"=> "0","msg"=> $e->getMessage() ]) );
}
break;
default:
echo(json_encode(["status"=> "2","msg"=> "Opération inconnue."]));
}

17
bdd.php
View file

@ -203,7 +203,7 @@ function RechercheExercices($query, $length, $tags)
global $conn;
// 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";
$sql = "SELECT * FROM documents AS d INNER JOIN ensembles AS e ON d.ensemble_id = e.id WHERE e.valide=TRUE AND ";
$conditions = [];
@ -225,6 +225,8 @@ function RechercheExercices($query, $length, $tags)
$conditions[] = implode(" AND ", $tagConditions);
}
$sql .= implode(" AND ", $conditions);
//echo $sql;
// Execute the query
@ -243,6 +245,19 @@ function RechercheExercices($query, $length, $tags)
$conn->close();
return $exercises;
}
function valider_ensemble($ensembleId) {
$updateQuery = "UPDATE ensembles SET valide = 1 WHERE id = $ensembleId";
global $conn;
$conn->execute_query($updateQuery);
}
?>

View file

@ -37,7 +37,9 @@
async function authenticate_user(){
resp = await fetch("/annales/api.php/auth");
data = await resp.json();
console.log("test");
if(data.status == 1){
alert(1);
document.getElementById("user_status").innerText = data["msg"];
}
}
@ -58,6 +60,7 @@
resp = await fetch("/annales/api.php/rechercher?req="+req);
data = await resp.json();
if(data.status == 1){
data.resultats.forEach(doc => {

View file

@ -55,6 +55,8 @@ D'autres fonctionnalités seront ajoutées petit à petit. (si vous avez des sug
## TOUDOU :
### téléverser.php :
- ajouter un element "commentaire_doc_< i >" pour chaque document

View file

@ -1,16 +1,19 @@
<?php
session_start();
if(isset($_SESSION["utilisateur_authentifie"])){
// vérifie que la session ne dépasse pas 4h
if((time() - $_SESSION["heure_debut"]) > 3600*4){
session_destroy();
session_abort();
echo(json_encode(array("status"=> "3","msg"=>"Session expirée, veuillez vous reconnecter.")));
function verifier_session(){
if(isset($_SESSION["utilisateur_authentifie"])){
// vérifie que la session ne dépasse pas 4h
if((time() - $_SESSION["heure_debut"]) > 3600*4){
session_destroy();
session_abort();
echo(json_encode(array("status"=> "3","msg"=>"Session expirée, veuillez vous reconnecter.")));
}
}else{
echo(json_encode(array("status"=> "0","msg"=> "Utilisateur non connecté.")));
exit;
}
}else{
echo(json_encode(array("status"=> "0","msg"=> "Utilisateur non connecté.")));
exit;
}
?>

View file

@ -6,6 +6,10 @@
<title>File Upload</title>
</head>
<body>
<?php
include("session_verif.php");
verifier_session();
?>
<!-- Input to choose files -->

View file

@ -33,7 +33,7 @@ function displayDocuments() {
if (($row["ensemble_id"] != $ens_id) && ($ens_id != -1) ) {
echo "<p><a href='#' onclick='validateDocument({$ens_id})'>Valider l'ensembre</a></p>";
echo "<p><a href='#' onclick='valider_ensemble({$ens_id})'>Valider l'ensembre</a></p>";
echo "</div>";
$ens_id = $row["ensemble_id"];
}
@ -65,28 +65,12 @@ function displayDocuments() {
// complète le formulaire du dernier ensemble itéré
echo "<p><a href='#' onclick='validateDocument({$ens_id})'>Valider l'ensembre</a></p>";
echo "<p><a href='#' onclick='valider_ensemble({$ens_id})'>Valider l'ensemble</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">
@ -103,13 +87,10 @@ if (isset($_POST['ensemble_id'])) {
<!-- 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', {
function valider_ensemble(ensembleId) {
fetch('api.php/valider_ensemble', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
@ -119,7 +100,9 @@ if (isset($_POST['ensemble_id'])) {
.then(response => response.json())
.then(data => {
if (data.status == 1) {
// oui
alert(data.msg)
}else{
alert(data.msg)
}
})
.catch(error => {
@ -128,7 +111,6 @@ if (isset($_POST['ensemble_id'])) {
}
</script>
<!-- Include your HTML and CSS styles for the form to add documents here -->
</body>
</html>