chiro-canto/public/explore/list/index.php

84 lines
3.2 KiB
PHP
Raw Normal View History

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
$version = "1.0";
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());
}
$req = $db->prepare('SELECT * FROM records ORDER BY date');
$req->execute();
$result = $req->fetchAll();
?>
<!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">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<?php include("$root/analytics/matomo.php");?>
<body>
<?php include("$root/menu.php");?>
<?php include("$root/header.php");?>
<section>
<h2>Explore</h2>
<h3>Recording List</h3>
<table id="list">
<thead>
<tr>
<th>Datetime</th>
<th>Species</th>
<th>File Name</th>
<th>Author</th>
<th>License</th>
<th>Audio</th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $row) {
$author_id = $row['author_id'];
$req = $db->prepare('SELECT * FROM authors WHERE id=:id');
$req->execute(array(
"id"=>$author_id
));
if ($data = $req->fetch()) {
$username = $data['username'];
}
?>
<tr>
<td><?=$row['date']?> <?=$row['time']?></td>
<td><em><?=$row['species']?></em></td>
<td>
<a href="/explore/spectrograms/?record=<?=$row['id']?>"><?=$row['file_name']?></a>
<a href="/storage/records/<?=$row['file_name']?>" title="Download file"><i class="fa fa-download"></i></a>
<a href="/larynx/?record=<?=$row['id']?>"><img src="/media/icons/wave.svg" alt="spectro analysis" title="Open with Larynx"></a>
</td>
<td><?=$username?></td>
<td><?=$row['license']?></td>
<td><audio src="/storage/records/<?=$row['file_name']?>" controls></audio></td>
</tr>
<?php
}
?>
</tbody>
</table>
</section>
<?php include("$root/footer.php");?>
</body>
<script src="/scripts/script.js"></script>
</html>