From 2f57207109cea8f7abe139b807f2d7aef1956c3d Mon Sep 17 00:00:00 2001 From: Taylor Courage Date: Fri, 7 Mar 2025 22:00:55 -0500 Subject: [PATCH] Added results display - the new home page --- display/division_results.php | 115 ++++++++++++++++++++++++ display/general_results.php | 154 +++++++++++++++++++++++++++---- scripts/results.js | 44 +++++++++ scripts/tools.js | 1 - styles/data_display.css | 170 ++++++++++++++++++++++++++++++++++- styles/primary.css | 4 +- 6 files changed, 465 insertions(+), 23 deletions(-) create mode 100644 display/division_results.php create mode 100644 scripts/results.js diff --git a/display/division_results.php b/display/division_results.php new file mode 100644 index 0000000..abdd2d0 --- /dev/null +++ b/display/division_results.php @@ -0,0 +1,115 @@ +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(); +} + +?> + + + + + + + + + + + + + + + + GENERAL DATA + + + +
+ $name

"; + echo "

$numWins

"; + $contentLatch = 1; + } + } + if ($contentLatch == 0) { + echo "

Nothing yet! Check back later!

"; + } + + + ?> +
+ + + \ No newline at end of file diff --git a/display/general_results.php b/display/general_results.php index ec0e19c..9775d50 100644 --- a/display/general_results.php +++ b/display/general_results.php @@ -1,4 +1,4 @@ - @@ -12,6 +12,7 @@ session_start(); + GENERAL DATA @@ -21,8 +22,8 @@ session_start(); 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); + // set the PDO error mode to exception + $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Grab all our tourney and game results // Prepare SQL @@ -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(); ?> -

General Information

- Total registered users: $numUsers

"; - echo "

Most recent user: $mostRecentUser

"; - echo "

Number of Official Tournaments: $numTourneys

"; - echo "

Number of game results uploaded: $numGames

"; - echo "

Total # of titles won: $numTotalTourneyWinners

"; - echo "

# of winners: $numUniqueTotalTourneyWinners

"; - echo "

Total 'Open' titles won: $numOpenTourneyWinners

"; - echo "

# of winners: $numUniqueOpenTourneyWinners

"; - echo "

Total 'Intermediate' titles won: $numIntermediateTourneyWinners

"; - echo "

# of winners: $numUniqueIntermediateTourneyWinners

"; - echo "

Total 'Main' of titles won: $numMainTourneyWinners

"; - echo "

# of winners: $numUniqueMainTourneyWinners

"; - ?> +

General Information

+
+

 

+
+

Number of registered users:

+

+
+ +

Most recently registered user:

+

+

+
+ +

Number of game results uploaded:

+

+

+
+ +

Number of Official Tournaments:

+

+

+
+ +

Total # of titles won:

+

+

+
+ +

Unique winners:

+

+

+
+ +

Total 'Open' titles won:

+

+

+
+ +

Unique winners:

+

+

+
+ +

Total 'Intermediate' titles won:

+

+

+
+ +

Unique winners:

+

+

+
+ +

Total 'Main' titles won:

+

+

+
+ +

Unique winners:

+

+

+
+
+

 

+ +
+

Per-Division Results

+
+ + + + + + +
+
+ + +
+

+
+

+
+ +
+
+ diff --git a/scripts/results.js b/scripts/results.js new file mode 100644 index 0000000..a13898c --- /dev/null +++ b/scripts/results.js @@ -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 += "
"; + + // Based on the selected division, show some results + if (currentDivision == "open") { + image = "/assets/trophy_open.png"; + html += "

\""Open\""

"; + } else if (currentDivision == "intermediate") { + image = "/assets/trophy_intermediate.png"; + html += "

\""Intermediate\""

"; + } else if (currentDivision == "main") { + image = "/assets/trophy_main.png"; + html += "

\""Main\""

"; + } + html += "

Top 10 Winners

" + html += "
"; + + + html += ""; + + html += "
"; + // TODO; + + // CREATE OUTPUT DISPLAY + + + document.getElementById("divisionDisplay").innerHTML = html; +} \ No newline at end of file diff --git a/scripts/tools.js b/scripts/tools.js index fa8c30c..6ba7f62 100644 --- a/scripts/tools.js +++ b/scripts/tools.js @@ -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 { diff --git a/styles/data_display.css b/styles/data_display.css index 2724c39..58c6d99 100644 --- a/styles/data_display.css +++ b/styles/data_display.css @@ -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); } \ No newline at end of file diff --git a/styles/primary.css b/styles/primary.css index 44ad748..9a3db46 100644 --- a/styles/primary.css +++ b/styles/primary.css @@ -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%; }