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

72 lines
2.1 KiB
PHP
Executable File

<?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"]);
$lang = isset($_COOKIE['lang']) ? $_COOKIE['lang'] : 'en';
require("$root/lang/$lang/lang.php");
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 RAND() ASC LIMIT 1');
$req->execute();
if ($data = $req->fetch())
{
?>
<!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/matomo.php");
?>
<body>
<?php include("$root/menu.php");?>
<?php include("$root/header.php");?>
<section>
<h3><?=_('Explore')?></h3>
<h4><?=_('Random Record')?></h4>
<table>
<thead>
<tr>
<th><?=_('Species')?></th>
<th><?=_('File name')?></th>
<th><?=_('Author')?></th>
<th><?=_('License')?></th>
<th><?=_('Audio')?></th>
</tr>
</thead>
<tbody>
<tr>
<td><em><?=$data['species']." ".$data['subspecies']?></em></td>
<td><a href="../spectrograms/?record=<?=$data['id']?>"><?=$data['file_name']?></a></td>
<td><?=$data['recordist_name']?></td>
<td><?=$data['license']?></td>
<td><audio src="/storage/records/<?=$data['file_name']?>" controls></audio></td>
</tr>
</tbody>
</table>
<p><?=_('Click on the file name to go to the spectrogram view.')?></p>
</section>
<?php include("$root/footer.php");?>
</body>
<script src="/scripts/script.js"></script>
</html>
<?php
}