Functionnal .wav observation upload

This commit is contained in:
Samuel Ortion 2021-03-30 07:31:22 +02:00
parent 2d8d09b0f3
commit 0a06add2c4
10 changed files with 46 additions and 21 deletions

View File

@ -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;
}

View File

@ -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");

View File

@ -2,6 +2,7 @@
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
session_start();
?>
<!DOCTYPE html>

View File

@ -1,4 +1,5 @@
<nav>
<div class="container">
<ul>
<a href="/about">
<li>about</li>
@ -19,4 +20,8 @@
<li>articles</li>
</a>
</ul>
<div>
<?=isset($_SESSION['username']) ? "Welcome ".$_SESSION['username']. " !" : '<a href="/auth/login">sign in</a> <a href=/auth/register">sign up</a>'?>
</div>
</div>
</nav>

View File

@ -13,7 +13,7 @@ header {
margin-top: 1em;
}
header .container {
header .container, nav .container {
display: flex;
justify-content: space-between;
}

View File

@ -28,16 +28,7 @@ $root = realpath($_SERVER["DOCUMENT_ROOT"]);
<?php include("$root/header.php");?>
<section>
<h2>Upload Your Recording</h2>
<?php
echo $_SESSION['error_msg'];
if (isset($_SESSION['error_msg']))
{
?>
<div class="error">
<?=$_SESSION['error_msg']?>
</div>
<?php
}
<?php echo (isset($_SESSION['error_msg']) and ! $_SESSION['error_msg'] == "" ) ? '<div class="error">'.$_SESSION['error_msg'].'</div>' : "";
if (isset($_GET['step']))
{
if ($_GET['step'] == 'location') {

View File

@ -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.";
}

View File

@ -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";

View File

@ -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: '."/");
?>

View File

@ -25,7 +25,7 @@
</tr>
<tr>
<td>Recordist</td>
<td><?=$_SESSION['observation']['name']?></td>
<td><?=$_SESSION['observation']['recordist-name']?></td>
</tr>
<tr>
<td>Date</td>