Added discussion page

This commit is contained in:
Samuel Ortion 2021-04-17 12:20:38 +02:00
parent 692ba38598
commit 02c9b8bc07
11 changed files with 278 additions and 14 deletions

View File

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

20
public/analytics/owa.php Normal file
View File

@ -0,0 +1,20 @@
<!-- Start Open Web Analytics Tracker -->
<script type="text/javascript">
//<![CDATA[
var owa_baseUrl = 'https://owa.ortion.xyz/';
var owa_cmds = owa_cmds || [];
owa_cmds.push(['setSiteId', '3ac90ef71ec02f86b4e72262bc3513b1']);
owa_cmds.push(['trackPageView']);
owa_cmds.push(['trackClicks']);
(function() {
var _owa = document.createElement('script'); _owa.type = 'text/javascript'; _owa.async = true;
owa_baseUrl = ('https:' == document.location.protocol ? window.owa_baseSecUrl || owa_baseUrl.replace(/http:/, 'https:') : owa_baseUrl );
_owa.src = owa_baseUrl + 'modules/base/js/owa.tracker-combined-min.js';
var _owa_s = document.getElementsByTagName('script')[0]; _owa_s.parentNode.insertBefore(_owa, _owa_s);
}());
//]]>
</script>
<!-- End Open Web Analytics Code -->

View File

@ -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 */;

View File

@ -0,0 +1,107 @@
<?php
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());
}
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'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Explore | Chiro - Canto</title>
<link rel="stylesheet" type="text/css" href="/styles/style.css">
</head>
<?php
include("$root/analytics/owa.php");
include("$root/analytics/matomo.php");
?>
<body>
<?php include("$root/menu.php");?>
<?php include("$root/header.php");?>
<section>
<h2>Discussion</h2>
<div class="messages">
<div class="author">
<?=$destinator?>
</div>
<?php
foreach($result as $message) {
if ($message['message_by'] == $_SESSION['username']) {
$class = "right";
} else {
$class = "left";
}
?>
<div class="message <?=$class?>">
<div class="datetime">
<?=$message['message_datetime']?>
</div>
<div class="content">
<?=$message['message_content']?>
</div>
</div>
<?php
}
?>
</div>
<?php
if (isset($user_id) and isset($_GET['author'])) {
?>
<form action="sendmessage.php" method="post">
<input type="hidden" name="message_by" value="<?=$user_id?>">
<input type="hidden" name="message_to" value="<?=$_GET['author']?>">
<input type="text" name="message_content" id="message_content" placeholder="Enter your message..">
<input type="submit" name="submit" value="Send">
</form>
<?php
}
?>
</section>
<?php include("$root/footer.php");?>
</body>
<script src="/scripts/script.js"></script>
</html>

View File

@ -0,0 +1,54 @@
<?php
function sendmessage($message_content, $message_by, $message_to) {
global $db;
$req = $db->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);
}
}

View File

@ -53,9 +53,9 @@ include("$root/analytics/matomo.php");
foreach($result as $row) {
?>
<tr>
<th><?=$row['firstname']?> <?=$row['lastname']?></th>
<th><?=$row['username']?></th>
<th><a href="/discussion/messages/?author=<?=$row['id']?>"><img src="/media/icons/bubble.png" alt="message bubble"></a></th>
<td><?=$row['firstname']?> <?=$row['lastname']?></td>
<td><?=$row['username']?></td>
<td><a href="/discussion/messages/?author=<?=$row['id']?>"><img src="/media/icons/bubble.png" alt="message bubble"></a></td>
</tr>
<?php
}

View File

@ -16,6 +16,10 @@ $root = realpath($_SERVER["DOCUMENT_ROOT"]);
<title>Chiro - Canto</title>
<link rel="stylesheet" type="text/css" href="styles/style.css">
</head>
<?php
include("$root/analytics/owa.php");
include("$root/analytics/matomo.php");
?>
<body>
<?php include("menu.php");?>
<?php include("header.php");?>

View File

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

View File

View File

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

View File

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