archinsa/index.php

83 lines
2.1 KiB
PHP
Raw Normal View History

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
<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="number" id="duree_input" placeholder="durée en minutes">
</form>
<a href="televerser.php">Téléverser des documents</a>
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();
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;
resp = await fetch("/annales/api.php/rechercher?req="+req);
data = await resp.json();
if(data.status == 1){
data.resultats.forEach(doc => {
const img = document.createElement("img");
img.src = doc.upload_path;
document.body.appendChild(img);
});
}
}
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-10-22 19:24:59 +02:00
</script>
</html>