From 02c9b8bc07725632fa719e8365790d7c9726bf90 Mon Sep 17 00:00:00 2001 From: Samuel ORTION Date: Sat, 17 Apr 2021 12:20:38 +0200 Subject: [PATCH] Added discussion page --- chiro-canto.conf | 5 + public/analytics/owa.php | 20 ++++ public/database/messages.sql | 69 +++++++++++ public/discussion/messages/index.php | 107 ++++++++++++++++++ public/discussion/messages/sendmessage.php | 54 +++++++++ public/explore/users/index.php | 6 +- public/index.php | 4 + public/larynx/scripts/spectro.js | 2 +- .../records/PaRecAR628069_20200526_040726.wav | Bin public/styles/style.css | 21 ++-- public/upload/submitmetadata.php | 4 +- 11 files changed, 278 insertions(+), 14 deletions(-) create mode 100644 public/analytics/owa.php create mode 100644 public/database/messages.sql create mode 100644 public/discussion/messages/index.php create mode 100644 public/discussion/messages/sendmessage.php mode change 100755 => 100644 public/storage/records/PaRecAR628069_20200526_040726.wav diff --git a/chiro-canto.conf b/chiro-canto.conf index 5d60141..a7fb378 100755 --- a/chiro-canto.conf +++ b/chiro-canto.conf @@ -21,4 +21,9 @@ server { fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } + + location /storage/records { + autoindex on; + autoindex_exact_size on; + } } diff --git a/public/analytics/owa.php b/public/analytics/owa.php new file mode 100644 index 0000000..46d8917 --- /dev/null +++ b/public/analytics/owa.php @@ -0,0 +1,20 @@ + + + + + \ No newline at end of file diff --git a/public/database/messages.sql b/public/database/messages.sql new file mode 100644 index 0000000..de25723 --- /dev/null +++ b/public/database/messages.sql @@ -0,0 +1,69 @@ +-- phpMyAdmin SQL Dump +-- version 5.1.0 +-- https://www.phpmyadmin.net/ +-- +-- Host: localhost +-- Generation Time: Apr 17, 2021 at 10:08 AM +-- Server version: 10.4.18-MariaDB +-- PHP Version: 7.4.16 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +START TRANSACTION; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + +-- +-- Database: `chirocanto` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `messages` +-- + +CREATE TABLE `messages` ( + `id` int(11) NOT NULL, + `message_content` varchar(500) NOT NULL, + `message_by` int(8) NOT NULL, + `message_to` int(8) NOT NULL, + `message_datetime` datetime NOT NULL DEFAULT current_timestamp() +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- +-- Dumping data for table `messages` +-- + +INSERT INTO `messages` (`id`, `message_content`, `message_by`, `message_to`, `message_datetime`) VALUES +(1, 'dsfqsfd', 9, 9, '2021-04-17 10:48:43'), +(2, 'dsfqsfd', 9, 9, '2021-04-17 10:49:50'); + +-- +-- Indexes for dumped tables +-- + +-- +-- Indexes for table `messages` +-- +ALTER TABLE `messages` + ADD PRIMARY KEY (`id`); + +-- +-- AUTO_INCREMENT for dumped tables +-- + +-- +-- AUTO_INCREMENT for table `messages` +-- +ALTER TABLE `messages` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; +COMMIT; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/public/discussion/messages/index.php b/public/discussion/messages/index.php new file mode 100644 index 0000000..632ef52 --- /dev/null +++ b/public/discussion/messages/index.php @@ -0,0 +1,107 @@ + PDO::ERRMODE_EXCEPTION + )); +} catch (Exception $e) { + die("Error : ".$e->getMessage()); +} +if (isset($_SESSION['username'])) { + $req = $db->prepare('SELECT id FROM `authors` WHERE username=:username'); + $req->execute(array( + "username"=>$_SESSION['username'] + )); + if ($data = $req->fetch()) { + $user_id = $data['id']; + } +} else { + $_SESSION['error_msg'] = "You must be logged in to receive an send message."; + header('Location: /auth/login'); +} +if (isset($_GET['author'])) { + $req = $db->prepare('SELECT * FROM `messages` WHERE message_by=:user_id AND message_to=:author_id OR message_by=:author_id AND message_to=:user_id ORDER BY message_datetime ASC'); + $req->execute(array( + "author_id"=>$user_id, + "user_id"=>$_GET['author'] + )); + $result = $req->fetchAll(); +} + +$req = $db->prepare('SELECT username FROM `authors` WHERE id=:id'); +$req->execute(array( + "id"=>$_GET['author'] +)); +if ($data = $req->fetch()) { + $destinator = $data['username']; +} + +?> + + + + + + + Explore | Chiro - Canto + + + + + + +
+

Discussion

+
+
+ +
+ +
+
+ +
+
+ +
+
+ +
+ +
+ + + + +
+ +
+ + + + \ No newline at end of file diff --git a/public/discussion/messages/sendmessage.php b/public/discussion/messages/sendmessage.php new file mode 100644 index 0000000..a2da28b --- /dev/null +++ b/public/discussion/messages/sendmessage.php @@ -0,0 +1,54 @@ +prepare('INSERT INTO `messages` (message_content, message_by, message_to, message_datetime) VALUES (:message_content, :message_by, :message_to, NOW())'); + $req->execute(array( + "message_content"=>$message_content, + "message_by"=>$message_by, + "message_to"=>$message_to + )); +} + + +session_reset(); +session_start(); +ini_set('display_errors', 1); +ini_set('display_startup_errors', 1); +error_reporting(E_ALL); +$root = realpath($_SERVER["DOCUMENT_ROOT"]); +require "$root/database/credentials.php"; +// Connect the database +try { + $db = new PDO("mysql:host=$host;dbname=$database;charset=utf8", + $user, + $password, + array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION + )); +} catch (Exception $e) { + die("Error : ".$e->getMessage()); +} +$_SESSION['error_msg'] = ""; +if (isset($_POST['submit'])) { + if (isset($_POST['message_by'])) { + $message_by = $_POST['message_by']; + } else { + $_SESSION['error_msg'] .= "Error: No message author.\n"; + } + if (isset($_POST['message_to'])) { + $message_to = $_POST['message_to']; + } else { + $_SESSION['error_msg'] .= "Error: No message destinator.\n"; + } if (isset($_POST['message_content'])) { + $message_content = $_POST['message_content']; + } else { + $_SESSION['error_msg'] .= "Error: No message content.\n"; + } + + if (isset($_SESSION['error_msg']) and $_SESSION['error_msg'] != "") { + header('Location: /discussion'); + } else { + sendmessage($message_content, $message_by, $message_to); + header('Location: /discussion/messages/?author='.$message_to); + } +} diff --git a/public/explore/users/index.php b/public/explore/users/index.php index 4670e8c..25b15c7 100644 --- a/public/explore/users/index.php +++ b/public/explore/users/index.php @@ -53,9 +53,9 @@ include("$root/analytics/matomo.php"); foreach($result as $row) { ?> - - - message bubble + + + message bubble Chiro - Canto + diff --git a/public/larynx/scripts/spectro.js b/public/larynx/scripts/spectro.js index 95ca77d..877097b 100755 --- a/public/larynx/scripts/spectro.js +++ b/public/larynx/scripts/spectro.js @@ -65,7 +65,7 @@ function measure(x, y) { x = (x - spectro_x); y = -(-(-y + spectro_y) - spectro_height); let t = (x / spectro_width) * audio.duration; - let f = (y / spectro_height) * 24; + let f = (y / spectro_height) * 12; let frequency_factor = 1; if (document.getElementById('exp_x10').checked) { frequency_factor = 10; diff --git a/public/storage/records/PaRecAR628069_20200526_040726.wav b/public/storage/records/PaRecAR628069_20200526_040726.wav old mode 100755 new mode 100644 diff --git a/public/styles/style.css b/public/styles/style.css index e6c7bc7..fb5632f 100755 --- a/public/styles/style.css +++ b/public/styles/style.css @@ -233,13 +233,13 @@ iframe html body { padding-bottom: 0; } -.container.row { +/* .container.row { flex-direction: row; } .container.column { flex-direction: column; -} +} */ h3, p { @@ -357,8 +357,9 @@ table#replies td { margin: 0; color: white; padding: 1em; - width: 1840px; - height: 500px; + max-width: 100vw; + height: 10vh; + text-align: center; overflow: auto; } @@ -366,10 +367,6 @@ table#replies td { text-align: center; } -#larynx { - text-align: center; -} - #larynx .license { text-align: left; } @@ -626,3 +623,11 @@ i, .fa { height: 0.1em; color: black; } + +.message .content { + display: flex; + flex-direction: row; + width: auto; + background-color: lightgreen; + border-radius: 8px 8px 0px 8px; +} diff --git a/public/upload/submitmetadata.php b/public/upload/submitmetadata.php index eb66fe2..2e7c341 100755 --- a/public/upload/submitmetadata.php +++ b/public/upload/submitmetadata.php @@ -142,9 +142,9 @@ if (isset($_POST['submit'])) if ($_SESSION['error_msg'] == "") { - // header('Location: '.'index.php?step=verify'); + header('Location: '.'index.php?step=verify'); } else{ $_SESSION['error_msg'] .= "Please try again.\n"; - // header('Location: '.'index.php?step=metadata'); + header('Location: '.'index.php?step=metadata'); }