From 0a06add2c4e9c86bfb8ab20295817b0ee0877ea9 Mon Sep 17 00:00:00 2001 From: Samuel ORTION Date: Tue, 30 Mar 2021 07:31:22 +0200 Subject: [PATCH] Functionnal .wav observation upload --- public/auth/login/login.php | 3 --- public/auth/register/register.php | 2 -- public/index.php | 1 + public/menu.php | 5 +++++ public/styles/style.css | 2 +- public/upload/index.php | 11 +--------- public/upload/submitlocation.php | 6 +++++- public/upload/submitmetadata.php | 2 +- public/upload/submitobservation.php | 33 +++++++++++++++++++++++++++-- public/upload/verify.php | 2 +- 10 files changed, 46 insertions(+), 21 deletions(-) diff --git a/public/auth/login/login.php b/public/auth/login/login.php index f16228e..e72f46d 100644 --- a/public/auth/login/login.php +++ b/public/auth/login/login.php @@ -27,14 +27,11 @@ function check_credentials($username, $userpw) { if ($data = $req->fetch()){ $password_hash = $data['password']; if (password_verify($userpw, $password_hash)) { - echo "Error 1"; return True; } else { - echo "Error"; return False; } } else { - echo "Error 0"; return False; } diff --git a/public/auth/register/register.php b/public/auth/register/register.php index 4092825..87b88ac 100644 --- a/public/auth/register/register.php +++ b/public/auth/register/register.php @@ -5,8 +5,6 @@ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); - - function database_entry($fname, $lname, $username, $password_hash, $email, $website) { $root = realpath($_SERVER["DOCUMENT_ROOT"]); require($root."/database/credentials.php"); diff --git a/public/index.php b/public/index.php index 7e5f2bf..ad5c9f3 100644 --- a/public/index.php +++ b/public/index.php @@ -2,6 +2,7 @@ // ini_set('display_errors', 1); // ini_set('display_startup_errors', 1); // error_reporting(E_ALL); +session_start(); ?> diff --git a/public/menu.php b/public/menu.php index 038e6be..92e32de 100644 --- a/public/menu.php +++ b/public/menu.php @@ -1,4 +1,5 @@ \ No newline at end of file diff --git a/public/styles/style.css b/public/styles/style.css index ae79add..22aea58 100644 --- a/public/styles/style.css +++ b/public/styles/style.css @@ -13,7 +13,7 @@ header { margin-top: 1em; } -header .container { +header .container, nav .container { display: flex; justify-content: space-between; } diff --git a/public/upload/index.php b/public/upload/index.php index e006018..ae40ede 100644 --- a/public/upload/index.php +++ b/public/upload/index.php @@ -28,16 +28,7 @@ $root = realpath($_SERVER["DOCUMENT_ROOT"]);

Upload Your Recording

- -
- -
- '.$_SESSION['error_msg'].'' : ""; if (isset($_GET['step'])) { if ($_GET['step'] == 'location') { diff --git a/public/upload/submitlocation.php b/public/upload/submitlocation.php index 0ab0c87..a980fc7 100644 --- a/public/upload/submitlocation.php +++ b/public/upload/submitlocation.php @@ -3,7 +3,11 @@ session_start(); $_SESSION['error_msg'] = ""; if (isset($_POST['latlng'])) { - $_SESSION['observation']['latlng'] = $_POST['latlng']; + $latlng = $_POST['latlng']; + $_SESSION['observation']['latlng'] = $latlng; + $_SESSION['observation']['lat'] = explode(',', $latlng)[0]; + $_SESSION['observation']['lng'] = explode(',', $latlng)[1]; + } else { $_SESSION['error_msg'].= "Incorrect coordinates, please try again."; } diff --git a/public/upload/submitmetadata.php b/public/upload/submitmetadata.php index 949364d..1f54d59 100644 --- a/public/upload/submitmetadata.php +++ b/public/upload/submitmetadata.php @@ -61,7 +61,7 @@ if (isset($_POST['submit'])) } if (isset($_POST['name'])) { - $_SESSION['observation']['name'] = $_POST['name']; + $_SESSION['observation']['recordist-name'] = $_POST['name']; setcookie('name', $_SESSION['observation']['name'], time() + 86400 * 365.2, "/"); } else { $_SESSION['error_msg'] .= "Incorrect Recordist Name.\n"; diff --git a/public/upload/submitobservation.php b/public/upload/submitobservation.php index 472b03f..e3cf650 100644 --- a/public/upload/submitobservation.php +++ b/public/upload/submitobservation.php @@ -8,13 +8,13 @@ ini_set('display_startup_errors', 1); error_reporting(E_ALL); // Connect the database -try{ +try { $db = new PDO("mysql:host=$host;dbname=$database;charset=utf8", $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION )); -}catch (Exception $e){ +}catch (Exception $e) { die("Error : ".$e->getMessage()); } @@ -22,5 +22,34 @@ try{ // $sql = file_get_contents($root."/database/create_record.sql"); // $db->exec($sql); +$req = $db->prepare('SELECT id FROM `authors` WHERE username=:username'); +$req->execute(array( + "username"=>$_SESSION['username'] +)); +if ($data = $req->fetch()) +{ + $id = $data['id']; +} +try { + $req = $db->prepare('INSERT INTO `records` (author_id, recordist_name, file_name, license, species, subspecies, sound_type, country, lat, lng, date, time, remarks) VALUES ( :id, :recordist_name, :file_name, :license, :species, :subspecies, :sound_type, :country, :lat, :lng, :date, :time, :remarks)'); + $req->execute(array( + "id"=>$id, + "recordist_name"=>$_SESSION['observation']['recordist-name'], + "file_name"=>$_SESSION['observation']['file'], + "license"=>$_SESSION['observation']['license'], + "species" => $_SESSION['observation']['species'], + "subspecies"=>$_SESSION['observation']['subspecies'], + "sound_type"=>implode(',', $_SESSION['observation']['type']), + "country"=>$_SESSION['observation']['country'], + "lat"=>$_SESSION['observation']['lat'], + "lng"=>$_SESSION['observation']['lng'], + "date"=>$_SESSION['observation']['date'], + "time"=>$_SESSION['observation']['time'], + "remarks"=>$_SESSION['observation']['remarks'], + )); +} catch (Exception $e) { + die("Error : ".$e->getMessage()); +} +header('Location: '."/"); ?> diff --git a/public/upload/verify.php b/public/upload/verify.php index 5924134..e8049ae 100644 --- a/public/upload/verify.php +++ b/public/upload/verify.php @@ -25,7 +25,7 @@ Recordist - + Date