From 8158f4f3fa6895da39b5c2cda770ee51dff87b1a Mon Sep 17 00:00:00 2001 From: thaaoblues Date: Sun, 22 Oct 2023 20:01:47 +0200 Subject: [PATCH] =?UTF-8?q?bon=20=C3=A7a=20marche=20pas=20mais=20c'est=20l?= =?UTF-8?q?e=20d=C3=A9but?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.php | 11 ++++++++--- bdd.php | 44 ++++++++++++++++++++++++++++++-------------- televerser.php | 15 +++++++++++++-- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/api.php b/api.php index 8657633..241c3bd 100644 --- a/api.php +++ b/api.php @@ -12,7 +12,6 @@ */ include("session_verif.php"); - include("test_creds.php"); include("bdd.php"); @@ -62,9 +61,15 @@ if($_SERVER['REQUEST_METHOD'] === 'POST'){ - switch(array_shift($url_parts)){ + + switch(array_pop($url_parts)){ case "aj_doc": - ajouter_doc($_POST); + try{ + ajouter_doc($_POST); + + }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 76a0d9b..d93a56d 100644 --- a/bdd.php +++ b/bdd.php @@ -1,26 +1,33 @@ connect_error) { - die("Connection failed: " . $conn->connect_error); -} - +include("annales/test_creds.php"); +$servername = "127.0.0.1"; +$username = "root"; +$password = ""; +$dbname = "archivinsa"; function ajouter_doc($request){ - - saveFilesFromPost($request); - if (isset($request['files']) && is_array($request['files'])) { - foreach ($request['files'] as $file) { - $sql="INSERT INTO "; - } + $conn = new mysqli($GLOBALS["servername"], $GLOBALS["username"], $GLOBALS["password"], $GLOBALS["dbname"]); + + // Check connection + if ($conn->connect_error) { + die("Connection failed: " . $conn->connect_error); + } + + $sql = "INSERT INTO ensemble (commentaire_auteur) VALUES(\"\")"; + + + try{ + $conn->execute_query($sql,array("",)); + saveFilesFromPost($request,mysqli_insert_id($conn),$conn); + }catch(Exception $e){ + echo(json_encode(["status"=>"0","msg"=>$e])); } } -function saveFilesFromPost($postData) { +function saveFilesFromPost($postData,$id_ensemble,$conn) { // Check if the $_POST variable is set and contains files if (isset($postData['files']) && is_array($postData['files'])) { // Directory to save the files @@ -47,6 +54,15 @@ function saveFilesFromPost($postData) { } else { echo(json_encode(["status"=>"0","msg"=>"Error saving file '$uniqueFileName'"])); } + + //update the database + $safe_titre = htmlspecialchars($postData['titre']); + $safe_type = htmlspecialchars($postData['type']); + + // pour tester, pas implémenté les commentaires globaux ni les themes + $sql="INSERT INTO documents (titre,type,upload_path,commentaire_auteur,ensemble_id) VALUES(?,?,?,?,?)"; + $conn->execute_query($sql, array("titre"=> $safe_titre,"type"=>$safe_type,"upload_path"=> $uploadDir,"commentaire_auteur"=>"","ensemble_id"=>$id_ensemble)); + } } else { echo(json_encode(["status"=>"2","msg"=>"No files in the POST data."])); diff --git a/televerser.php b/televerser.php index 4ea28bb..3924b85 100644 --- a/televerser.php +++ b/televerser.php @@ -14,6 +14,14 @@ + + + +