diff --git a/api.php b/api.php index 4f4b582..fabf305 100644 --- a/api.php +++ b/api.php @@ -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."])); } diff --git a/bdd.php b/bdd.php index 9b06372..63f20c5 100644 --- a/bdd.php +++ b/bdd.php @@ -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); } ?> \ No newline at end of file diff --git a/index.php b/index.php index 9aa2c7c..b7477ec 100644 --- a/index.php +++ b/index.php @@ -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 => { diff --git a/readme.md b/readme.md index b41f387..267697b 100644 --- a/readme.md +++ b/readme.md @@ -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 diff --git a/session_verif.php b/session_verif.php index 194444c..a18e31a 100644 --- a/session_verif.php +++ b/session_verif.php @@ -1,16 +1,19 @@ 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; } + ?> \ No newline at end of file diff --git a/televerser.php b/televerser.php index c6264c7..918f229 100644 --- a/televerser.php +++ b/televerser.php @@ -6,6 +6,10 @@