diff --git a/bdd.php b/bdd.php index 1473897..23d324c 100644 --- a/bdd.php +++ b/bdd.php @@ -122,9 +122,7 @@ function saveFilesFromPost($postData,$id_ensemble) { fclose($f); - if (move_uploaded_file($file['tmp_name'], $filePath)) { - echo(json_encode(["status"=>"1","msg" =>"File '$uniqueFileName' has been saved successfully."])); - } else { + if (!move_uploaded_file($file['tmp_name'], $filePath)) { echo(json_encode(["status"=>"0","msg"=>"Error saving file '$uniqueFileName'"])); exit; @@ -187,7 +185,7 @@ function saveFilesFromPost($postData,$id_ensemble) { $row = mysqli_fetch_assoc($result); $id_theme = $row["id"]; }else{ - echo("creation d'un theme"); + //echo("creation d'un theme"); $sql = "INSERT INTO themes (name) VALUES(?)"; $conn->execute_query($sql,array($theme)); @@ -198,7 +196,7 @@ function saveFilesFromPost($postData,$id_ensemble) { // ensuite, on enregistre les qui lui sont associés $sql= 'INSERT INTO exercices_themes (exercice_id,ensemble_id,theme_id) VALUES(?,?,?)'; $result = $conn->execute_query($sql,array($id_exo,$id_ensemble,$id_theme)); - echo("enregistrement d'un exercice"); + //echo("enregistrement d'un exercice"); } } @@ -211,6 +209,7 @@ function saveFilesFromPost($postData,$id_ensemble) { } + echo(json_encode(["status"=>"1","msg" =>"Files has/have been saved successfully."])); } else { diff --git a/index.php b/index.php index 72dd386..8bc94e9 100644 --- a/index.php +++ b/index.php @@ -47,7 +47,7 @@ -
+
diff --git a/js/index.js b/js/index.js index f486247..c97dc49 100644 --- a/js/index.js +++ b/js/index.js @@ -26,13 +26,13 @@ async function unauthenticate_user(){ async function rechercher(){ - var req = document.body.getElementById("recherche_input").value; + var req = document.getElementById("recherche_input").value; var themes = []; - Array.from(document.body.getElementsByClassName("theme")).forEach(function (el) { + 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.body.getElementById("duree_input").value + var duree =document.getElementById("duree_input").value var url = "api.php/rechercher?req="+req; @@ -51,7 +51,7 @@ async function rechercher(){ data = await resp.json(); // vide d'abord les éléments présents dans la liste sur la page - document.body.getElementById("liste_resultats").innerHTML = ""; + document.getElementById("liste_resultats").innerHTML = ""; if(data.status == 1){ data.resultats.forEach(doc => { diff --git a/js/televerser.js b/js/televerser.js index 51a1780..245bcef 100644 --- a/js/televerser.js +++ b/js/televerser.js @@ -1,9 +1,15 @@ +var camera_open = false; +var video; + + + function televerser_fichiers() { const fileInput = document.getElementById('fileInput'); // Create FormData object to append files const formData = new FormData(); + formData.append("type",document.getElementById("select_type").value); formData.append("titre",document.getElementById("titre").value); formData.append("commentaire_auteur",document.getElementById("commentaire_auteur").value); @@ -64,6 +70,7 @@ function televerser_fichiers() { }) .then(response => response.json()) .then(data => { + //console.log(data); if(data.status == 1){ alert("le document a bien été envoyé ! Merci de votre participation :D") }else{ @@ -76,13 +83,35 @@ function televerser_fichiers() { } function ouvrir_camera() { + // test if camera is already open, in that case juste take a regular picture + if(camera_open){ + const canvas = document.createElement('canvas'); + canvas.width = video.videoWidth; + canvas.height = video.videoHeight; + const context = canvas.getContext('2d'); + context.drawImage(video, 0, 0, canvas.width, canvas.height); + + // Convert the canvas content to a data URL + const imageDataUrl = canvas.toDataURL('image/jpeg'); + + // Display the captured image + const img = document.createElement('img'); + img.src = imageDataUrl; + img.style.maxWidth = '100px'; + document.getElementById('selectedImages').appendChild(img); + return; + } + + // Open the camera and take pictures // You can use the MediaDevices API to access the camera navigator.mediaDevices.getUserMedia({ video: true }) .then(mediaStream => { - const video = document.createElement('video'); + video = document.createElement('video'); document.body.appendChild(video); + camera_open = true; + // Display the camera stream in a video element video.srcObject = mediaStream; video.play(); @@ -221,6 +250,8 @@ function init_date(){ document.addEventListener("DOMContentLoaded", (event) => { + + init_date(); document.getElementById("select_type").addEventListener("change", (event) => { changer_mode();