chiro-canto/public/home/status.php

47 lines
1.4 KiB
PHP
Executable File

<?php
$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());
}
$req = $db->prepare('SELECT COUNT(*) AS counter FROM `records`');
$req->execute();
if ($data = $req->fetch()) {
$record_counter = $data['counter'];
}
$req = $db->prepare('SELECT COUNT(*) AS counter FROM `authors`');
$req->execute();
if ($data = $req->fetch()) {
$user_counter = $data['counter'];
}
$req = $db->prepare('SELECT COUNT(*) AS counter FROM `taxa`');
$req->execute();
if ($data = $req->fetch()) {
$taxa_counter = $data['counter'];
}
?>
<div id="status">
<?=$record_counter?> <?=_('records_uploaded')?><br>
<?=$user_counter?> <?=_('users_registered')?><br>
<?=$taxa_counter?> <?=_('taxa_available')?><br>
<?php
$bytes = disk_free_space("$root/storage/records");
$total = disk_total_space("$root/storage/records");
$si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' );
$base = 1024;
$class = min((int)log($bytes , $base) , count($si_prefix) - 1);
echo sprintf('%1.2f', $bytes / pow($base,$class)).' '.$si_prefix[$class];?> <?=_('free_space')?> <br>
<progress id="space" max="<?=$total?>" value="<?=$total-$bytes?>"> <?=$bytes?> </progress>
</div>