2023-10-22 19:24:59 +02:00
|
|
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>Document</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<?php
|
|
|
|
session_start();
|
|
|
|
|
|
|
|
?>
|
|
|
|
<a href="javascript:authenticate_user();">connection</a>
|
|
|
|
<a href="javascript:unauthenticate_user();">déconnection</a>
|
|
|
|
|
|
|
|
<div id="user_status">
|
|
|
|
|
|
|
|
</div>
|
2023-11-10 20:03:46 +01:00
|
|
|
|
2023-12-23 12:42:12 +01:00
|
|
|
<form id="recherche_form">
|
2023-11-10 20:03:46 +01:00
|
|
|
<input type="text" id="recherche_input" placeholder="Rechercher une fiche, annale ...">
|
2023-12-23 12:42:12 +01:00
|
|
|
<input type="text" id="themes_input" placeholder="themes (appuyez sur la touche entrée entre chaque thèmes)">
|
2023-11-10 20:03:46 +01:00
|
|
|
<input type="number" id="duree_input" placeholder="durée en minutes">
|
|
|
|
</form>
|
2023-11-11 20:33:14 +01:00
|
|
|
|
|
|
|
<a href="televerser.php">Téléverser des documents</a>
|
2024-01-01 17:53:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
<div id="liste_resultats">
|
|
|
|
</div>
|
|
|
|
|
2023-10-22 19:24:59 +02:00
|
|
|
</body>
|
|
|
|
<script>
|
|
|
|
async function test_auth(){
|
2023-11-10 20:03:46 +01:00
|
|
|
resp = await fetch("/annales/api.php/test_auth");
|
2023-10-22 19:24:59 +02:00
|
|
|
data = await resp.json();
|
|
|
|
document.getElementById("user_status").innerText = data["msg"];
|
|
|
|
}
|
|
|
|
|
|
|
|
// fonction de test, innutile en prod
|
|
|
|
async function authenticate_user(){
|
2023-11-10 20:03:46 +01:00
|
|
|
resp = await fetch("/annales/api.php/auth");
|
2023-10-22 19:24:59 +02:00
|
|
|
data = await resp.json();
|
2023-12-03 16:30:07 +01:00
|
|
|
console.log("test");
|
2023-10-22 19:24:59 +02:00
|
|
|
if(data.status == 1){
|
|
|
|
document.getElementById("user_status").innerText = data["msg"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function unauthenticate_user(){
|
2023-11-10 20:03:46 +01:00
|
|
|
resp = await fetch("/annales/api.php/unauth");
|
2023-10-22 19:24:59 +02:00
|
|
|
data = await resp.json();
|
|
|
|
if(data.status == 1){
|
|
|
|
document.getElementById("user_status").innerText = data["msg"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-10 20:03:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
async function rechercher(){
|
|
|
|
var req = document.getElementById("recherche_input").value;
|
2023-12-23 12:42:12 +01:00
|
|
|
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
|
2023-11-10 20:03:46 +01:00
|
|
|
|
2023-12-23 12:42:12 +01:00
|
|
|
|
|
|
|
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);
|
2023-12-03 16:30:07 +01:00
|
|
|
|
2023-11-10 20:03:46 +01:00
|
|
|
data = await resp.json();
|
2024-01-01 17:53:53 +01:00
|
|
|
|
|
|
|
// vide d'abord les éléments présents dans la liste sur la page
|
|
|
|
document.getElementById("liste_resultats").innerHTML = "";
|
|
|
|
|
2023-11-10 20:03:46 +01:00
|
|
|
if(data.status == 1){
|
|
|
|
data.resultats.forEach(doc => {
|
2024-01-01 17:53:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// on affiche le titre du résultat parce qu'on est pas des sauvages
|
|
|
|
let titre_ensemble;
|
|
|
|
titre_ensemble = document.createElement("h2");
|
|
|
|
titre_ensemble.innerText = doc.titre;
|
|
|
|
document.getElementById("liste_resultats").appendChild(titre_ensemble);
|
|
|
|
|
|
|
|
// images ou pdf ?
|
|
|
|
let ele;
|
|
|
|
if(doc.upload_path.toString().split(".").pop() == "pdf"){
|
|
|
|
ele = document.createElement("embed");
|
|
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
ele = document.createElement("img");
|
|
|
|
}
|
|
|
|
|
|
|
|
ele.src = doc.upload_path;
|
|
|
|
ele.setAttribute("onclick","document.location.href='ens.php?ensemble_id="+doc.ensemble_id.toString()+"'");
|
|
|
|
document.getElementById("liste_resultats").appendChild(ele);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function gen_chronologie(){
|
|
|
|
var url = "/annales/api.php/generer_chronologie";
|
|
|
|
|
|
|
|
console.log(url);
|
|
|
|
|
|
|
|
resp = await fetch(url);
|
|
|
|
|
|
|
|
data = await resp.json();
|
|
|
|
console.log(data);
|
|
|
|
// vide d'abord les éléments présents dans la liste sur la page
|
|
|
|
document.getElementById("liste_resultats").innerHTML = "";
|
|
|
|
|
|
|
|
// ensuite on ajoute un petit titre à la chronologie
|
|
|
|
let titre = document.createElement("h1");
|
|
|
|
titre.innerText = "Documents récemment publiés";
|
|
|
|
document.getElementById("liste_resultats").appendChild(titre);
|
|
|
|
|
|
|
|
// et on remplis avec ce que l'api a généré
|
|
|
|
if(data.status == 1){
|
|
|
|
data.resultats.forEach(ens => {
|
|
|
|
|
|
|
|
ens.documents.forEach(doc=>{
|
|
|
|
// on affiche le titre du résultat parce qu'on est pas des sauvages
|
|
|
|
let titre_ensemble;
|
|
|
|
titre_ensemble = document.createElement("h2");
|
|
|
|
titre_ensemble.innerText = doc.titre;
|
|
|
|
document.getElementById("liste_resultats").appendChild(titre_ensemble);
|
|
|
|
|
|
|
|
// images ou pdf ?
|
|
|
|
let apercu;
|
|
|
|
if(doc.upload_path.toString().split(".").pop() == "pdf"){
|
|
|
|
ele = document.createElement("embed");
|
|
|
|
|
|
|
|
}else{
|
|
|
|
ele = document.createElement("img");
|
|
|
|
}
|
|
|
|
|
|
|
|
ele.src = doc.upload_path;
|
|
|
|
ele.setAttribute("onclick","document.location.href='ens.php?ensemble_id="+doc.ensemble_id.toString()+"'");
|
|
|
|
document.getElementById("liste_resultats").appendChild(ele);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-10 20:03:46 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-01 17:53:53 +01:00
|
|
|
gen_chronologie();
|
|
|
|
|
2023-10-22 19:24:59 +02:00
|
|
|
test_auth();
|
2023-11-10 20:03:46 +01:00
|
|
|
document.getElementById("recherche_input").onkeydown =function(event) {
|
|
|
|
if (event.key === "Enter"){
|
|
|
|
rechercher();
|
|
|
|
}
|
|
|
|
}
|
2023-12-23 12:42:12 +01:00
|
|
|
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;
|
2023-11-10 20:03:46 +01:00
|
|
|
|
2023-12-23 12:42:12 +01:00
|
|
|
document.getElementById("recherche_form").appendChild(theme);
|
|
|
|
document.getElementById("themes_input").value = "";
|
|
|
|
}
|
|
|
|
}
|
2023-11-10 20:03:46 +01:00
|
|
|
|
2024-01-01 17:53:53 +01:00
|
|
|
|
|
|
|
|
2023-11-10 20:03:46 +01:00
|
|
|
|
2023-10-22 19:24:59 +02:00
|
|
|
|
|
|
|
</script>
|
2023-12-23 12:42:12 +01:00
|
|
|
</html>
|