Added results display - the new home page

This commit is contained in:
Taylor Courage 2025-03-07 22:00:55 -05:00
parent cb1eb98501
commit 2f57207109
6 changed files with 465 additions and 23 deletions

View File

@ -0,0 +1,115 @@
<?php
session_start();
include("../admin/db_config.php");
try { // Try opening the SQL database connection
$conn = new PDO("mysql:host=$servername; dbname=$dbName", $dbUsername, $dbPassword);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// This checks if we have 'all' months selected
// If not, add a leading 0 to the month so SQL reads it easier
if ($_GET["month"] == "all") {
$getMonth = "";
} else if ($_GET["month"] < 10) {
$getMonth = "MONTH(tournamentDate)=\"0" . $_GET["month"] . "\" AND ";
} else {
$getMonth = "MONTH(tournamentDate)=\"" . $_GET["month"] . "\" AND ";
}
// Grab year and division
$year = $_GET["year"];
$division = $_GET["division"];
// Select all the winners from the table where the month, year, and division all match
$sqlGetTopWinnersList = $conn->prepare("SELECT winner1,winner2,winner3,winner4 FROM " . $tournamentDataTableName . " WHERE $getMonth YEAR(tournamentDate)=\"" . $year . "\" AND tournamentDivision=\"" . $division . "\"");
$sqlGetTopWinnersList->execute();
// Fetch the results
$sqlWinnersList = $sqlGetTopWinnersList->fetchAll(PDO::FETCH_ASSOC);
$winnersList = array();
foreach ($sqlWinnersList as $winner) {
for ($i = 1; $i < 4; $i++) {
if ($winner["winner" . $i] != "N/A") {
$winnersList[] = $winner["winner" . $i];
}
}
}
// Array to store names
$names = array();
$wins = array();
$topWinner = array_count_values($winnersList);
arsort ($topWinner);
// Break the array-count-values down, because our names became the key and the number of wins is the value
foreach ($topWinner as $name=>$numWins) {
$names[] = $name;
$wins[] = $numWins;
}
// Finally we'll display the results below in the proper HTML
for ($i = 0; $i < 10; $i++) {
// Check if we have any data
if (isset($names[$i])) {
$name = $names[$i];
$numWins = $wins[$i];
}
}
} catch (PDOException $e) { // failed connection
echo "Connection failed: " . $e->getMessage();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="/styles/primary.css" />
<link rel="stylesheet" href="/styles/data.css" />
<link rel="stylesheet" href="/styles/data_display.css" />
<script src="/scripts/tools.js"></script>
<script src="/scripts/results.js"></script>
<script>verifyPageInFrame()</script>
<title>GENERAL DATA</title>
</head>
<body id="divisionResultsFrame">
<div class="divisionResultsTable">
<?php
// This latch variable will trigger if we have any data to display
// If we have nothing to display, we'll tell them that
$contentLatch = 0;
for ($i = 0; $i < 10; $i++) {
// Check if we have any data
if (isset($names[$i])) {
$name = $names[$i];
$numWins = $wins[$i];
echo "<p class=\"divisionResultsTableLeft\">$name</p>";
echo "<p class=\"divisionResultsTableRight\">$numWins</p>";
$contentLatch = 1;
}
}
if ($contentLatch == 0) {
echo "<p class=\"noContent\">Nothing yet! Check back later!</p>";
}
?>
</div>
</body>
</html>

View File

@ -12,6 +12,7 @@ session_start();
<link rel="stylesheet" href="/styles/data.css" />
<link rel="stylesheet" href="/styles/data_display.css" />
<script src="/scripts/tools.js"></script>
<script src="/scripts/results.js"></script>
<script>verifyPageInFrame()</script>
<title>GENERAL DATA</title>
</head>
@ -47,6 +48,10 @@ session_start();
$intermediateTourneyWinners = array();
$mainTourneyWinners = array();
// Initialize array to get dates of tourneys
$tourneyYears = array();
$tourneyMonths = array();
// Check the number of players for each entry
// Then, grab that many winners
foreach ($tourneyData as $data) {
@ -63,6 +68,9 @@ session_start();
$mainTourneyWinners[] = $data[$winnerIndex];
}
}
// Grab the year from our tourney date
$tourneyYears[] = date("Y", strtotime($data["tournamentDate"]));
$tourneyMonths[] = date("n", strtotime($data["tournamentDate"]));
}
// Make 'unique' arrays, so we have TOTAL # played vs. # won
@ -71,6 +79,15 @@ session_start();
$intermediateUniqueTourneyWinners = array_unique($intermediateTourneyWinners);
$mainUniqueTourneyWinners = array_unique($mainTourneyWinners);
// Unique-array for tournament years
$years = array();
$tourneyYears = array_unique($tourneyYears);
foreach ($tourneyYears as $year) {
$years[] = $year;
}
sort($years); // Sort the years to put them in order of earliest to latest
// Get counts of rows
$numGames = count($gameData);
@ -90,6 +107,8 @@ session_start();
$mostRecentUser = $userData[$userIndex][0];
} catch (PDOException $e) { // failed connection
echo "Connection failed: " . $e->getMessage();
}
@ -97,23 +116,122 @@ session_start();
?>
<body id="resultsDisplayBody">
<h2>General Information</h2>
<div id="generalResultsDisplayPanel">
<?php
echo "<p>Total registered users: $numUsers</p>";
echo "<p>Most recent user: $mostRecentUser</p>";
echo "<p>Number of Official Tournaments: $numTourneys</p>";
echo "<p>Number of game results uploaded: $numGames</p>";
echo "<p>Total # of titles won: $numTotalTourneyWinners</p>";
echo "<p># of winners: $numUniqueTotalTourneyWinners</p>";
echo "<p>Total 'Open' titles won: $numOpenTourneyWinners</p>";
echo "<p># of winners: $numUniqueOpenTourneyWinners</p>";
echo "<p>Total 'Intermediate' titles won: $numIntermediateTourneyWinners</p>";
echo "<p># of winners: $numUniqueIntermediateTourneyWinners</p>";
echo "<p>Total 'Main' of titles won: $numMainTourneyWinners</p>";
echo "<p># of winners: $numUniqueMainTourneyWinners</p>";
?>
<h2>General Information</h2>
<hr class="tableLine">
<p>&nbsp;</p>
<div id="generalResultsTable">
<p class="generalResultsTableLeft">Number of registered users:</p>
<p class="generalResultsTableRight textBold"><?php echo $numUsers; ?></p>
<hr class="tableLine">
<!-- Next line! -->
<p class="generalResultsTableLeft">Most recently registered user:</p>
<p class="tableSpacer"></p>
<p class="generalResultsTableRight"><?php echo $mostRecentUser; ?></p>
<hr class="tableLine">
<!-- Next line! -->
<p class="generalResultsTableLeft">Number of game results uploaded:</p>
<p class="tableSpacer"></p>
<p class="generalResultsTableRight textBold"><?php echo $numGames; ?></p>
<hr class="tableLine">
<!-- Next line! -->
<p class="generalResultsTableLeft textBold">Number of Official Tournaments:</p>
<p class="tableSpacer"></p>
<p class="generalResultsTableRight textBold"><?php echo $numTourneys; ?></p>
<hr class="tableLineLight">
<!-- Next line! -->
<p class="generalResultsTableLeft">Total # of titles won:</p>
<p class="tableSpacer"></p>
<p class="generalResultsTableRight"><?php echo $numTotalTourneyWinners; ?></p>
<hr class="tableLineLight">
<!-- Next line! -->
<p class="generalResultsTableLeft">Unique winners:</p>
<p class="tableSpacer"></p>
<p class="generalResultsTableRight"><?php echo $numUniqueTotalTourneyWinners; ?></p>
<hr class="tableLine">
<!-- Next line! -->
<p class="generalResultsTableLeft textBold">Total 'Open' titles won:</p>
<p class="tableSpacer"></p>
<p class="generalResultsTableRight textBold"><?php echo $numOpenTourneyWinners; ?></p>
<hr class="tableLineLight">
<!-- Next line! -->
<p class="generalResultsTableLeft">Unique winners:</p>
<p class="tableSpacer"></p>
<p class="generalResultsTableRight"><?php echo $numUniqueOpenTourneyWinners; ?></p>
<hr class="tableLine">
<!-- Next line! -->
<p class="generalResultsTableLeft textBold">Total 'Intermediate' titles won:</p>
<p class="tableSpacer"></p>
<p class="generalResultsTableRight textBold"><?php echo $numIntermediateTourneyWinners; ?></p>
<hr class="tableLineLight">
<!-- Next line! -->
<p class="generalResultsTableLeft">Unique winners:</p>
<p class="tableSpacer"></p>
<p class="generalResultsTableRight"><?php echo $numUniqueIntermediateTourneyWinners; ?></p>
<hr class="tableLine">
<!-- Next line! -->
<p class="generalResultsTableLeft textBold">Total 'Main' titles won:</p>
<p class="tableSpacer"></p>
<p class="generalResultsTableRight textBold"><?php echo $numMainTourneyWinners; ?></p>
<hr class="tableLineLight">
<!-- Next line! -->
<p class="generalResultsTableLeft">Unique winners:</p>
<p class="tableSpacer"></p>
<p class="generalResultsTableRight"><?php echo $numUniqueMainTourneyWinners; ?></p>
<hr class="tableLine">
</div>
<p>&nbsp;</p>
</div>
<div id="divisionDisplayPanel">
<h2>Per-Division Results</h2>
<div class="divisionNavPanel">
<input type="radio" id="openButton" name="division" checked="checked" value="open" onclick="refreshDisplay();">
<label for="openButton" id="openButton">Open</label>
<input type="radio" id="intermediateButton" name="division" value="intermediate" onclick="refreshDisplay();">
<label for="intermediateButton" id="intermediateButton">Intermediate</label>
<input type="radio" id="mainButton" name="division" value="main" onclick="refreshDisplay();">
<label for="mainButton" id="mainButton">Main</label>
</div>
<div class="dateSelector">
<select size="1" name="month" id="month" onchange="refreshDisplay()">
<option value="all">All</option>
<?php
// Automatically write the months using a script
// Also automatically selects the current month
for ($i = 1; $i <= 12; $i++) {
if (date('m', time()) == $i) {
$dateObject = DateTime::createFromFormat("!m", $i);
echo "<option selected value=\"" . $i . "\">" . $dateObject->format('F') . " </option>";
} else {
$dateObject = DateTime::createFromFormat("!m", $i);
echo "<option value=\"" . $i . "\">" . $dateObject->format('F') . " </option>";
}
}
?>
</select>
<select size="1" name="year" id="year" onchange="refreshDisplay()">
<?php
// This uses the years we grabbed earlier and ensures we're only showing
// the years we have entries for
for ($i = 0; $i < count($years); $i++) {
if ($i == (count($years) - 1)) {
echo "<option selected value=\"" . $years[$i] . "\"> " . $years[$i] . "</option>";
} else {
echo "<option value=\"" . $years[$i] . "\"> " . $years[$i] . "</option>";
}
}
?>
</select>
</div>
<p> </p>
<hr class="tableLine">
<p> </p>
<div id="divisionDisplay">
</div>
</div>
<script>refreshDisplay(); // Initial division to load</script>
</body>

44
scripts/results.js Normal file
View File

@ -0,0 +1,44 @@
function refreshDisplay() {
var divisionButtons = document.getElementsByName("division");
var currentDivision = "";
for (var i = 0; i < divisionButtons.length; i++) {
if (divisionButtons[i].checked) {
currentDivision = divisionButtons[i].value;
}
}
var displayDiv = document.getElementById("divisionDisplay");
document.getElementById("divisionDisplay").innerHTML = currentDivision;
console.log(currentDivision);
var html = "";
var image = ""; //get trophy image
html += "<div class=\"divisionPanel\">";
// Based on the selected division, show some results
if (currentDivision == "open") {
image = "/assets/trophy_open.png";
html += "<h2><img src=" + image + " class=\"lineImage\" alt=\"" + currentDivision + " division trophy\" style=\"float:left;\">Open<img src=" + image + " class=\"lineImage\" alt=\"" + currentDivision + " division trophy\" style=\"float:right;\"></h2>";
} else if (currentDivision == "intermediate") {
image = "/assets/trophy_intermediate.png";
html += "<h2><img src=" + image + " class=\"lineImage\" alt=\"" + currentDivision + " division trophy\" style=\"float:left;\">Intermediate<img src=" + image + " class=\"lineImage\" alt=\"" + currentDivision + " division trophy\" style=\"float:right;\"></h2>";
} else if (currentDivision == "main") {
image = "/assets/trophy_main.png";
html += "<h2><img src=" + image + " class=\"lineImage\" alt=\"" + currentDivision + " division trophy\" style=\"float:left;\">Main<img src=" + image + " class=\"lineImage\" alt=\"" + currentDivision + " division trophy\" style=\"float:right;\"></h2>";
}
html += "<p>Top 10 Winners</p>"
html += "<hr class=\"tableLineLightCentre\">";
html += "<iframe src=\"/display/division_results.php?division=" + currentDivision + "&month=" + document.getElementById("month").value + "&year=" + document.getElementById("year").value + "\" name=\"divisionFrame\" class=\"divisionFrame\" id=\"divisionFrame\" onload=\"resizeIframe(this);\"></iframe>";
html += "</div>";
// TODO;
// CREATE OUTPUT DISPLAY
document.getElementById("divisionDisplay").innerHTML = html;
}

View File

@ -17,7 +17,6 @@ function verifyPageInFrame() {
// Verify that the page was loaded in an iFrame
// Otherwise back to the homepage they go!
var mainURL = window.location.origin;
console.log(mainURL);
if (window.self !== window.top) {
} else {

View File

@ -1,7 +1,173 @@
.textBold {
font-weight: bold;
}
.tableSpacer {
width: 100%;
}
.tableLine {
border: 1px solid black;
width: 100%;
}
.tableLineLight {
border: 1px solid rgba(0, 0, 0, .25);
width: 40%;
margin: auto 60%
}
.tableLineLightCentre {
border: 1px solid rgba(0, 0, 0, .25);
width: 40%;
margin: auto;
}
#resultsDisplayBody {
width:800px;
display: flex;
flex-direction: row;
width:850px;
overflow: hidden;
font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
#resultsDisplayBody h2 {
text-align: center;
}
#generalResultsDisplayPanel {
width: 400px;
width: 40%;
border: 1px solid black;
border-radius: 6px;
padding-left: 5%;
padding-right: 5%;
margin-right: 1%;
}
#generalResultsTable {
margin: auto;
}
.generalResultsTableLeft {
text-align: left;
width: 100%;
line-height: 0.5;
}
.generalResultsTableRight {
text-align: right;
width: 100%;
line-height: 0.3;
}
#divisionDisplayPanel {
width: 44%;
border: 1px solid black;
border-radius: 6px;
padding-left: 3%;
padding-right: 3%;
margin-left: 1%;
}
.divisionNavPanel {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: center;
}
.divisionNavPanel label, .divisionNavPanel input {
text-align: center;
align-items: center;
justify-content: center;
display: flex;
width: 100px;
height: 40px;
padding: 0;
cursor: pointer;
}
.divisionNavPanel label {
border: 1px solid black;
border-radius: 3px;
z-index: 90;
margin: 1%;
}
.divisionNavPanel input[type="radio"] {
display: none;
}
.divisionNavPanel input[type="radio"]:checked + label {
background-color: rgba(0, 40, 255, .4);
}
.divisionNavPanel label:hover {
background-color: rgba(255, 165, 0, .6);
}
.dateSelector {
display: flex;
flex-direction: row;
justify-content: center;
width:100%;
}
.dateSelector select {
border: 1px solid blue;
border-radius: 3px;
padding: 6px 20px;
margin-right: 1%;
margin-left: 1%;
background-color: rgba(255, 255, 255, 0.4);
cursor: pointer;
}
.divisionPanel {
margin: auto;
text-align: center;
}
#divisionResultsFrame {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.divisionResultsTableLeft {
text-align: left;
width: 80%;
}
.divisionResultsTableRight {
text-align: right;
width: 14%;
}
.divisionResultsTable {
margin: auto;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
width: 300px;
}
.lineImage {
object-fit: contain;
}
.divisionFrame {
flex-grow: 1;
flex-shrink: 1;
margin: auto;
padding: 0;
border: none;
max-width: 100%;
}
.noContent {
text-align: center;
font-style: italic;
color: rgba(0, 0, 0, .35);
}

View File

@ -31,7 +31,7 @@ Modifies and defines the iFrame that's holding the content shown to the user
border: 1px solid black;
border-radius: 5px;
background-color: rgba(255, 255, 255, .2);
width:80%;
width:100%;
max-width: 900px;
min-height: 0px;
padding-top: 20px;
@ -96,7 +96,7 @@ For upper/primary controls
margin: auto;
padding: 0;
border: none;
max-width: 90%;
max-width: 100%;
}