-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrank.php
86 lines (71 loc) · 3.13 KB
/
rank.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Users Ranking</title>
<link rel="icon" href="assets/icon.jpg">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>
<body class="w3-light-grey">
<?php include 'utils/navbar.php'; ?>
<div class="w3-container w3-margin">
<h1 class="w3-center">Ranking</h1>
<?php
require 'utils/security.php';
error_reporting(E_ERROR | E_PARSE);
require 'utils/env.php';
$resultsPerPage = 10;
$currentPage = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$files = glob("users" . DIRECTORY_SEPARATOR . "*");
if ($files === false) {
die('<div class="w3-container w3-red w3-center w3-padding-large w3-round">Error: Error retrieving user files.</div>');
} else {
$fileData = [];
foreach ($files as $file) {
$content = file_get_contents($file);
if ($content === false) {
die('<div class="w3-container w3-red w3-center w3-padding-large w3-round">Error: Error reading file: ' . htmlspecialchars($file) . '</div>');
} else {
$fileData[$file] = floatval($content);
}
}
arsort($fileData);
$totalResults = count($fileData);
$totalPages = ceil($totalResults / $resultsPerPage);
$start = ($currentPage - 1) * $resultsPerPage;
$fileData = array_slice($fileData, $start, $resultsPerPage, true);
$currentRank = $start + 1;
echo "<ul class='w3-ul'>";
foreach ($fileData as $file => $number) {
echo "<div class='w3-card w3-margin w3-white w3-round'>";
echo "<li class='w3-padding-16' style='display: flex; justify-content: space-between;'>
<span style='flex: 1; text-align: left;'> #$currentRank</span>
<span style='flex: 2; text-align: center;";
if ($currentRank == 1) {
echo " color: red;";
} elseif ($currentRank == 2) {
echo " color: orange;";
} elseif ($currentRank == 3) {
echo " color: green;";
}
echo "'><b>" . htmlspecialchars(basename($file)) . "</b></span>
<span style='flex: 1; text-align: right;'>" . htmlspecialchars($number) . " R-Score </span>
</li>";
echo "</div>";
$currentRank++;
}
echo "</ul>";
echo "<div class='w3-bar w3-center'>";
for ($page = 1; $page <= $totalPages; $page++) {
echo "<a href='?page=$page' class='w3-button w3-border w3-round";
if ($page == $currentPage) {
echo " w3-blue";
}
echo "'>$page</a> ";
}
echo "</div>";
}
?>
</div>
</body>
</html>