diff --git a/admin/admin_nav.php b/admin/admin_nav.php index e45ddb0..261799a 100644 --- a/admin/admin_nav.php +++ b/admin/admin_nav.php @@ -4,6 +4,7 @@ + @@ -20,10 +21,10 @@ CREATE SAFE ADMIN

 

-

TOURNEY MANAGEMENT

+

DATA MANAGEMENT

 

@@ -31,7 +32,7 @@

 

diff --git a/admin/data_management/add_game.php b/admin/data_management/add_game.php new file mode 100644 index 0000000..3dd3d59 --- /dev/null +++ b/admin/data_management/add_game.php @@ -0,0 +1,189 @@ + + + + + + + + + + no title + + + + setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + echo "

Connected successfully

"; + + + // Need to check if values were sent over POST, otherwise set to N/A + if (isset($_POST["bluePlayer1"])) { + $bluePlayer1 = $_POST["bluePlayer1"]; + } else { + $bluePlayer1 = "N/A"; + } + if (isset($_POST["bluePlayer2"])) { + $bluePlayer2 = $_POST["bluePlayer2"]; + } else { + $bluePlayer2 = "N/A"; + } + if (isset($_POST["bluePlayer3"])) { + $bluePlayer3 = $_POST["bluePlayer3"]; + } else { + $bluePlayer3 = "N/A"; + } + if (isset($_POST["bluePlayer4"])) { + $bluePlayer4 = $_POST["bluePlayer4"]; + } else { + $bluePlayer4 = "N/A"; + } + if (isset($_POST["orangePlayer1"])) { + $orangePlayer1 = $_POST["orangePlayer1"]; + } else { + $orangePlayer1 = "N/A"; + } + + if (isset($_POST["orangePlayer2"])) { + $orangePlayer2 = $_POST["orangePlayer2"]; + } else { + $orangePlayer2 = "N/A"; + } + + if (isset($_POST["orangePlayer3"])) { + $orangePlayer3 = $_POST["orangePlayer3"]; + } else { + $orangePlayer3 = "N/A"; + } + + if (isset($_POST["orangePlayer4"])) { + $orangePlayer4 = $_POST["orangePlayer4"]; + } else { + $orangePlayer4 = "N/A"; + } + + $gameName = $_POST["gameName"]; + $gameDate = $_POST["gameDate"]; + $numPlayers = $_POST["numPlayers"]; + $blueScore = $_POST["blueScore"]; + $blueTeamName = $_POST["blueTeamName"]; + $orangeScore = $_POST["orangeScore"]; + $orangeTeamName = $_POST["orangeTeamName"]; + /* + $bluePlayer1 = $_POST["bluePlayer1"]; + $bluePlayer2 = $_POST["bluePlayer2"]; + $bluePlayer3 = $_POST["bluePlayer3"]; + $bluePlayer4 = $_POST["bluePlayer4"]; + $orangePlayer1 = $_POST["orangePlayer1"]; + $orangePlayer2 = $_POST["orangePlayer2"]; + $orangePlayer3 = $_POST["orangePlayer3"]; + $orangePlayer4 = $_POST["orangePlayer4"]; + */ + $tourneyName = $_POST["tourneyName"]; + $ballchasingID = $_POST["ballchasingID"]; + $notes = $_POST["notes"]; + + $uploadedBy = $_SESSION["username"]; + $uploadedByID = $_SESSION["userID"]; + + if ($blueScore > $orangeScore) { + $winningTeam = "blue"; + } elseif ($blueScore < $orangeScore) { + $winningTeam = "orange"; + } else { + $winningTeam = $_POST["winners"]; + } + + + $insert = $conn->prepare("INSERT INTO " . $gameDataTableName . " ( + gameName, + gameDate, + uploadedBy, + uploadedByID, + numPlayers, + winningTeam, + blueScore, + blueTeamName, + orangeScore, + orangeTeamName, + bluePlayer1, + bluePlayer2, + bluePlayer3, + bluePlayer4, + orangePlayer1, + orangePlayer2, + orangePlayer3, + orangePlayer4, + tournamentName, + ballchasingID, + notes + ) VALUES ( + :gameName, + :gameDate, + :uploadedBy, + :uploadedByID, + :numPlayers, + :winningTeam, + :blueScore, + :blueTeamName, + :orangeScore, + :orangeTeamName, + :bluePlayer1, + :bluePlayer2, + :bluePlayer3, + :bluePlayer4, + :orangePlayer1, + :orangePlayer2, + :orangePlayer3, + :orangePlayer4, + :tournamentName, + :ballchasingID, + :notes + )"); + + + $insert->bindValue(":gameName", $gameName); + $insert->bindValue(":gameDate", $gameDate); + $insert->bindValue(":uploadedBy", $uploadedBy); + $insert->bindValue(":uploadedByID", $uploadedByID); + $insert->bindValue(":numPlayers", $numPlayers); + $insert->bindValue(":winningTeam", $winningTeam); + $insert->bindValue(":blueScore", $blueScore); + $insert->bindValue(":blueTeamName", $blueTeamName); + $insert->bindValue(":orangeScore", $orangeScore); + $insert->bindValue(":orangeTeamName", $orangeTeamName); + $insert->bindValue(":bluePlayer1", $bluePlayer1); + $insert->bindValue(":bluePlayer2", $bluePlayer2); + $insert->bindValue(":bluePlayer3", $bluePlayer3); + $insert->bindValue(":bluePlayer4", $bluePlayer4); + $insert->bindValue(":orangePlayer1", $orangePlayer1); + $insert->bindValue(":orangePlayer2", $orangePlayer2); + $insert->bindValue(":orangePlayer3", $orangePlayer3); + $insert->bindValue(":orangePlayer4", $orangePlayer4); + $insert->bindValue(":tournamentName", $tourneyName); + $insert->bindValue(":ballchasingID", $ballchasingID); + $insert->bindValue(":notes", $notes); + + + + $insert->execute(); + + echo "Successfully uploaded new game record"; + + } catch (PDOException $e) { // failed connection + echo "Connection failed: " . $e->getMessage(); + } + + $conn = null; + + ?> + + + + \ No newline at end of file diff --git a/admin/data_management/add_tourney.php b/admin/data_management/add_tourney.php new file mode 100644 index 0000000..641cbaf --- /dev/null +++ b/admin/data_management/add_tourney.php @@ -0,0 +1,123 @@ + + + + + + + + + + no title + + + + setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + + // Need to check if values were sent over POST, otherwise set to N/A + if (isset($_POST["winningPlayer1"])) { + $winningPlayer1 = $_POST["winningPlayer1"]; + } else { + $winningPlayer1 = "N/A"; + } + if (isset($_POST["winningPlayer2"])) { + $winningPlayer2 = $_POST["winningPlayer2"]; + } else { + $winningPlayer2 = "N/A"; + } + if (isset($_POST["winningPlayer3"])) { + $winningPlayer3 = $_POST["winningPlayer3"]; + } else { + $winningPlayer3 = "N/A"; + } + if (isset($_POST["winningPlayer4"])) { + $winningPlayer4 = $_POST["winningPlayer4"]; + } else { + $winningPlayer4 = "N/A"; + } + + $tourneyName = $_POST["tourneyName"]; + $tourneyDate = $_POST["tourneyDate"]; + $division = $_POST["division"]; + $numPlayers = $_POST["numPlayers"]; + $bestOf = $_POST["bestOf"]; + $winningTeamName = $_POST["winningTeamName"]; + $notes = $_POST["notes"]; + + echo "

$tourneyName

"; + echo "

$tourneyDate

"; + echo "

$division

"; + echo "

$numPlayers

"; + echo "

$bestOf

"; + echo "

$winningTeamName

"; + echo "

$winningPlayer1

"; + echo "

$winningPlayer2

"; + echo "

$winningPlayer3

"; + echo "

$winningPlayer4

"; + echo "

$notes

"; + + + $insert = $conn->prepare("INSERT INTO " . $tournamentDataTableName . " ( + tournamentName, + tournamentDate, + tournamentDivision, + numPlayers, + bestOf, + winningTeamName, + winner1, + winner2, + winner3, + winner4, + notes + ) VALUES ( + :tournamentName, + :tournamentDate, + :tournamentDivision, + :numPlayers, + :bestOf, + :winningTeamName, + :winner1, + :winner2, + :winner3, + :winner4, + :notes + )"); + + + $insert->bindValue(":tournamentName", $tourneyName); + $insert->bindValue(":tournamentDate", $tourneyDate); + $insert->bindValue(":tournamentDivision", $division); + $insert->bindValue(":numPlayers", $numPlayers); + $insert->bindValue(":bestOf", $bestOf); + $insert->bindValue(":winningTeamName", $winningTeamName); + $insert->bindValue(":winner1", $winningPlayer1); + $insert->bindValue(":winner2", $winningPlayer2); + $insert->bindValue(":winner3", $winningPlayer3); + $insert->bindValue(":winner4", $winningPlayer4); + $insert->bindValue(":notes", $notes); + + + + $insert->execute(); + + echo "Successfully uploaded new tournament record"; + + } catch (PDOException $e) { // failed connection + echo "Connection failed: " . $e->getMessage(); + } + + $conn = null; + + ?> + + + + \ No newline at end of file diff --git a/admin/data_management/game_form.php b/admin/data_management/game_form.php new file mode 100644 index 0000000..8a5e80d --- /dev/null +++ b/admin/data_management/game_form.php @@ -0,0 +1,159 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + // Grab the list of users from the user list + // We will also grab all the people that have been registered/won before + $sqlGetUserData = $conn->prepare("SELECT username FROM " . $userTableName . ""); + $sqlGetTourneyData = $conn->prepare("SELECT tournamentName,winner1,winner2,winner3,winner4 FROM " . $tournamentDataTableName . ""); + + // Execute SQL query + $sqlGetUserData->execute(); + $sqlGetTourneyData->execute(); + + // Get results from the USERS table + $results = $sqlGetUserData->fetchAll(PDO::FETCH_ASSOC); + + // Create new arrays to store values + $userList = array(); + $tourneyList = array(); + + // Move results to their own array, easier to convert for Javascript + foreach ($results as $result) { + $userList[] = $result["username"]; + } + + // Get results from the TOURNEY table + $results = $sqlGetTourneyData->fetchAll(PDO::FETCH_ASSOC); + + // Move results to their own array, easier to convert for Javascript + foreach ($results as $result) { + $userList[] = $result["winner1"]; + $userList[] = $result["winner2"]; + $userList[] = $result["winner3"]; + $userList[] = $result["winner4"]; + $tourneyList[] = $result["tournamentName"]; + } + + // Remove duplicate entries + $userList = array_unique($userList); + + // Sort the array to alphabetical order + sort($userList); + + +} catch (PDOException $e) { // failed connection + echo "Connection failed: " . $e->getMessage(); +} + +?> + + + + + + + + + + + + + + + + + GAME ADDING FORM + + + + +
+
+

ADD GAME RESULTS

+

Add a recently-played game and save the results!

+
+

+
+ + +

+ + " tabindex="1" required> +

+
+
+ + + + +
+

+
+ +
+ +

+
+

+
+

If this game was part of a tournament, enter the name of it below

+ +

If you have uploaded a replay of this game to ballchasing.com, enter the ID code below.

+ +

+

If you have any notes about the game, leave them below

+ +
+ +

+ + +
+

+ +
+

+
+
+ + + \ No newline at end of file diff --git a/admin/data_management/game_management.css b/admin/data_management/game_management.css new file mode 100644 index 0000000..26e574d --- /dev/null +++ b/admin/data_management/game_management.css @@ -0,0 +1,197 @@ +#gameFormPanel { + width: 500px; + min-height: 1000px; +} + +#gameFormPanel { + margin: auto; + text-align: center; +} + + +#textInputArea { + padding-left: 10px; + display: flex; + flex-wrap: wrap; + flex-direction: row; + margin: auto; + text-align: center; +} + +.optionsArea { + display: flex; + flex-wrap: wrap; + flex-direction: row; + margin: auto; + text-align: center; + justify-content: center; +} + +#userForm input { + background-color: rgba(255, 255, 255, 0.6); + border-style: 1px solid blue; +} + +#userForm label { + text-align: left; + font-weight: bold; +} + +#userForm input[type="submit"] { + margin: auto; + padding: 8px 25px; + font-size: 150%; + font-weight: bold; + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; + background-color: rgba(255, 255, 255, 0); + border-radius: 6px; + border: 1px solid blue; + box-shadow: 0px 2px 4px; +} + +#userForm input[type="submit"]:hover { + color: black; + background-color: rgba(255, 165, 0, .6); +} + +#userForm input[type="submit"]:active { + box-shadow: 0px 0px 2px; + transform: translateY(2px); +} + +#userForm input[type="text"] { + flex: 1; + align-items: flex-end; + border-radius: 2px; + padding: 3px 10px; + margin: 0 6%; +} + +#userForm input[type="date"] { + flex: 1; + border-radius: 2px; + width: 100px; + padding: 3px 10px; + margin: 0 6%; + text-align: center; + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; +} + +#userForm select { + border: 1px solid black; + border-radius: 2px; + background-color: rgba(255, 255, 255, 0.6); + padding: 3px 10px; + margin: 0 3%; +} +.playerInput input[type="text"]{ + flex: 1; + width: 150px; +} +.teamInput input[type="text"]{ + flex: 1; + width: 175px; +} + +#playerDataInputArea { + height: 370px; + width: 85%; + border: 1px solid black; + border-radius: 5px; + margin: auto; +} + +#playerData { + margin: auto; +} + +#playerData input[type="text"]{ + width: 90%; + border-radius: 2px; + padding: 3px 0; + margin: 0 0; + text-align: center; +} + +#playerTableMiddleSpacer { + width: 15%; +} + +.tableSubHeader { + font-size: 70%; +} +#teamNameHeader { + font-size: 85%; +} +#scoreHeader { + font-size: 85%; +} +#scoreRow { + font-size: 120%; + font-weight: bold; +} + +#scoreRow input[type="text"] { + width: 50px; + border-radius: 6px; + padding: 6px 6px; + margin: 0 0; + text-align: center; + font-size: 130%; +} + +.tableHeader { + font-weight: bold; + font-size: 125%; +} + +#submitButtonDiv { + display: flex; + flex-direction: column; + bottom: 10px; +} + +#submitButton { + margin: auto; +} + +#tourneyName { + width:100%; + padding: 3px 0; + margin: 0 0; + text-align: center; +} + +#ballchasingID { + width:100%; + padding: 3px 0; + margin: 0 0; + text-align: center; +} + +#notes { + width: 80%; + height: 100px; + background-color: rgba(255, 255, 255, 0.6); + resize: none; +} + +.showTeamSelector { + visibility: hidden; +} + +/* + This section affects the auto-complete menu for player names +*/ +.ui-menu { + background-color: rgba(255, 255, 255, 0.6); + border: 1px solid black; + border-radius: 2px; +} + +.ui-autocomplete { + max-height: 200px; + overflow-y: scroll; + overflow-x: hidden; + width: 120px; +} diff --git a/admin/data_management/tourney_form.php b/admin/data_management/tourney_form.php new file mode 100644 index 0000000..dbf7589 --- /dev/null +++ b/admin/data_management/tourney_form.php @@ -0,0 +1,152 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + // Grab the list of users from the user list + // We will also grab all the people that have been registered/won before + $sqlGetUserData = $conn->prepare("SELECT username FROM " . $userTableName . ""); + $sqlGetTourneyData = $conn->prepare("SELECT winner1,winner2,winner3,winner4 FROM " . $tournamentDataTableName . ""); + + // Execute SQL query + $sqlGetUserData->execute(); + $sqlGetTourneyData->execute(); + + // Get results from the USERS table + $results = $sqlGetUserData->fetchAll(PDO::FETCH_ASSOC); + + // Create array to store values + $userList = array(); + + // Move results to their own array, easier to convert for Javascript + foreach ($results as $result) { + $userList[] = $result["username"]; + } + + + // Get results from the TOURNEY table + $results = $sqlGetTourneyData->fetchAll(PDO::FETCH_ASSOC); + + // Move results to their own array, easier to convert for Javascript + foreach ($results as $result) { + $userList[] = $result["winner1"]; + $userList[] = $result["winner2"]; + $userList[] = $result["winner3"]; + $userList[] = $result["winner4"]; + } + + + $userList = array_unique($userList); + // Sort the array to alphabetical order + sort($userList); + +} catch (PDOException $e) { // failed connection + echo "Connection failed: " . $e->getMessage(); +} + +?> + + + + + + + + + + + + + + + + + TOURNAMENT ADDING FORM + + + + +
+
+

ADD NEW TOURNAMENT

+

Add a recently-played tournament and record the victors.

+

Users will be able to add their own replays and information to the tournaments (later).

+

This is also how trophies will be tracked!

+
+

+
+ + +

+ + " tabindex="1" required> +

+
+
+ + +

+ + + + +
+

+
+

WINNING TEAM NAME:

+ +

Roster

+ +
+ +

+
+

+
+

+

If you have any notes about the tournament, leave them below

+ +

+

Once the tournament is created, users will be able to attribute their games to it through the game creation/editing screen.

+
+ +

+ + +
+

+ +
+

+
+
+ + + \ No newline at end of file diff --git a/admin/data_management/tourney_management.css b/admin/data_management/tourney_management.css new file mode 100644 index 0000000..ccd9ea2 --- /dev/null +++ b/admin/data_management/tourney_management.css @@ -0,0 +1,193 @@ +#tourneyFormPanel { + width: 500px; + min-height: 1000px; +} + +#tourneyFormPanel { + margin: auto; + text-align: center; +} + + +#textInputArea { + padding-left: 10px; + display: flex; + flex-wrap: wrap; + flex-direction: row; + margin: auto; + text-align: center; +} + +.optionsArea { + display: flex; + flex-wrap: wrap; + flex-direction: row; + margin: auto; + text-align: center; + justify-content: center; +} + +#userForm input { + background-color: rgba(255, 255, 255, 0.6); + border-style: 1px solid blue; +} + +#userForm label { + text-align: left; + font-weight: bold; +} + +#userForm input[type="submit"] { + margin: auto; + padding: 8px 25px; + font-size: 150%; + font-weight: bold; + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; + background-color: rgba(255, 255, 255, 0); + border-radius: 6px; + border: 1px solid blue; + box-shadow: 0px 2px 4px; +} + +#userForm input[type="submit"]:hover { + color: black; + background-color: rgba(255, 165, 0, .6); +} + +#userForm input[type="submit"]:active { + box-shadow: 0px 0px 2px; + transform: translateY(2px); +} + +#userForm input[type="text"] { + flex: 1; + align-items: flex-end; + border-radius: 2px; + padding: 3px 10px; + margin: 0 6%; +} + +#userForm input[type="date"] { + flex: 1; + border-radius: 2px; + width: 100px; + padding: 3px 10px; + margin: 0 6%; + text-align: center; + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; +} + +#userForm select { + border: 1px solid black; + border-radius: 2px; + background-color: rgba(255, 255, 255, 0.6); + padding: 3px 10px; + margin: 0 3%; +} +.playerInput input[type="text"]{ + flex: 1; + width: 150px; +} +.teamInput input[type="text"]{ + flex: 1; + width: 60%; +} +.teamInput input[type="text"]{ + flex: 1; + width: 60%; +} +.teamInput { + width: 60%; + text-align: center; +} +#playerDataInputArea { + height: 280px; + width: 75%; + border: 1px solid black; + border-radius: 5px; + margin: auto; +} + +#playerData { + margin: auto; + width: 80%; +} + +#playerData input[type="text"]{ + width: 90%; + border-radius: 2px; + padding: 3px 0; + margin: 0 0; + text-align: center; +} + +#playerTableMiddleSpacer { + width: 10%; +} + +.tableSubHeader { + font-size: 100%; +} +#teamNameHeader { + font-size: 100%; +} + +.tableHeader { + font-weight: bold; + font-size: 125%; +} + +#submitButtonDiv { + display: flex; + flex-direction: column; + bottom: 10px; +} + +#submitButton { + margin: auto; +} + +#tourneyName { + width:100%; + padding: 3px 0; + margin: 0 0; + text-align: center; +} + +#ballchasingID { + width:100%; + padding: 3px 0; + margin: 0 0; + text-align: center; +} + +#notes { + width: 80%; + height: 100px; + background-color: rgba(255, 255, 255, 0.6); + resize: none; +} + +.showTeamSelector { + visibility: hidden; +} + +#teamNameHeader { + font-weight: bold; +} + +/* + This section affects the auto-complete menu for player names +*/ +.ui-menu { + background-color: rgba(255, 255, 255, 0.6); + border: 1px solid black; + border-radius: 2px; +} + +.ui-autocomplete { + max-height: 200px; + overflow-y: scroll; + overflow-x: hidden; + width: 120px; +} diff --git a/admin/db_config.php b/admin/db_config.php index ee86881..0a3a6e4 100644 --- a/admin/db_config.php +++ b/admin/db_config.php @@ -25,7 +25,8 @@ include ("dev_db_config.php"); $userTableName = "users"; // name of the table containing user data -$dataTableName = "replays"; // table containing replay data +$gameDataTableName = "games"; // table containing replay data +$tournamentDataTableName = "tournaments"; // tournament data table $trophyTableName = "trophies"; // trophy data table $adminUserTableName = "safeadmins"; @@ -75,23 +76,53 @@ userUpdated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP )"; -// REPLAYS DATA TABLE +// GAME DATA TABLE $sqlCreateDataTable = " -CREATE TABLE " . $dataTableName . " ( -replayID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, -ballchasingID VARCHAR(100), -replayName VARCHAR(150), +CREATE TABLE " . $gameDataTableName . " ( +gameID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, +gameName VARCHAR(100), +gameDate DATE, uploadedBy VARCHAR(30), +uploadedByID INT(8) UNSIGNED, numPlayers TINYINT UNSIGNED, -player1 VARCHAR(30), -player2 VARCHAR(30), -player3 VARCHAR(30), -player4 VARCHAR(30), -player5 VARCHAR(30), -player6 VARCHAR(30), -player7 VARCHAR(30), -player8 VARCHAR(30), -notes VARCHAR(1000) +winningTeam VARCHAR(6), +blueTeamName VARCHAR(35), +blueScore INT(3), +orangeTeamName VARCHAR(35), +orangeScore INT(3), +bluePlayer1 VARCHAR(30), +bluePlayer2 VARCHAR(30), +bluePlayer3 VARCHAR(30), +bluePlayer4 VARCHAR(30), +orangePlayer1 VARCHAR(30), +orangePlayer2 VARCHAR(30), +orangePlayer3 VARCHAR(30), +orangePlayer4 VARCHAR(30), +tournamentName VARCHAR(150), +ballchasingID VARCHAR(50), +notes VARCHAR(1000), +created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, +updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +)"; + + +// TOURNAMENT DATA TABLE +$sqlCreateTournamentTable = " +CREATE TABLE " . $tournamentDataTableName . " ( +tournamentID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, +tournamentName VARCHAR(150), +tournamentDate DATE, +tournamentDivision VARCHAR(20), +numPlayers TINYINT UNSIGNED, +bestOf TINYINT UNSIGNED, +winningTeamName VARCHAR(35), +winner1 VARCHAR(30), +winner2 VARCHAR(30), +winner3 VARCHAR(30), +winner4 VARCHAR(30), +notes VARCHAR(1000), +created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, +updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP )"; diff --git a/admin/db_management/initialize.php b/admin/db_management/initialize.php index ed56bbc..f4dbe60 100644 --- a/admin/db_management/initialize.php +++ b/admin/db_management/initialize.php @@ -27,7 +27,6 @@ ////////// USER DATA /////////// - echo "

Creating user data table...

"; // Check if the users table exists already $sqlCheckUserTable = $conn->prepare("SHOW TABLES LIKE '" . $userTableName . "'"); @@ -67,11 +66,10 @@ echo "

Copied!

"; - //////// REPLAY DATA //////// - echo "

Creating replay data table...

"; - + //////// GAME DATA //////// + // Check if the replay data table exists already - $sqlCheckDataTable = $conn->prepare("SHOW TABLES LIKE '" . $dataTableName . "'"); + $sqlCheckDataTable = $conn->prepare("SHOW TABLES LIKE '" . $gameDataTableName . "'"); // Run the query $sqlCheckDataTable->execute(); @@ -80,26 +78,61 @@ $count = $sqlCheckDataTable->rowCount(); if ($count != 0) { - echo "

Deleting exsiting table '" . $dataTableName . "'...

"; + echo "

Deleting exsiting table '" . $gameDataTableName . "'...

"; // Create the query to drop the table - $sqlDropDataTable = "DROP TABLE " . $dataTableName; + $sqlDropDataTable = "DROP TABLE " . $gameDataTableName; $conn->exec($sqlDropDataTable); // drop the table - echo "

Deleted!

Creating new table '" . $dataTableName . "'...

"; + echo "

Deleted!

Creating new table '" . $gameDataTableName . "'...

"; try { // Create the new table $conn->query($sqlCreateDataTable); - echo "

Table '" . $dataTableName . "' successfully created (replay data)

"; + echo "

Table '" . $gameDataTableName . "' successfully created (saved game data)

"; } catch (PDOException $e) { echo $sqlCreateDataTable . "
" . $e->getMessage(); } } else { // If the table doesn't already exist, we'll just create it try { $conn->query($sqlCreateDataTable); - echo "

Table '" . $dataTableName . "' successfully created (replay data)

"; + echo "

Table '" . $gameDataTableName . "' successfully created (saved game data)

"; } catch (PDOException $e) { echo $sqlCreateDataTable . "
" . $e->getMessage(); } } + //////// TOURNAMENT DATA //////// + + + // Check if the replay data table exists already + $sqlCheckTournamentTable = $conn->prepare("SHOW TABLES LIKE '" . $tournamentDataTableName . "'"); + + // Run the query + $sqlCheckTournamentTable->execute(); + + //Check if any rows exist - if not, create the table, if yes, destroy it first, then create it + $count = $sqlCheckTournamentTable->rowCount(); + + if ($count != 0) { + echo "

Deleting exsiting table '" . $tournamentDataTableName . "'...

"; + // Create the query to drop the table + $sqlDropTournamentTable = "DROP TABLE " . $tournamentDataTableName; + $conn->exec($sqlDropTournamentTable); // drop the table + echo "

Deleted!

Creating new table '" . $tournamentDataTableName . "'...

"; + try { // Create the new table + $conn->query($sqlCreateTournamentTable); + echo "

Table '" . $tournamentDataTableName . "' successfully created (tournament data)

"; + } catch (PDOException $e) { + echo $sqlCreateTournamentTable . "
" . $e->getMessage(); + } + } else { // If the table doesn't already exist, we'll just create it + try { + $conn->query($sqlCreateTournamentTable); + echo "

Table '" . $tournamentDataTableName . "' successfully created (tournament data)

"; + } catch (PDOException $e) { + echo $sqlCreateTournamentTable . "
" . $e->getMessage(); + } + } + + +/* //////// TROPHY DATA //////// echo "

Creating trophy data table...

"; @@ -132,7 +165,7 @@ echo $sqlCreateTrophyTable . "
" . $e->getMessage(); } } - +*/ $conn = null; // Close the connection // Tell the use we're done diff --git a/admin/dev_db_config.php b/admin/dev_db_config.php deleted file mode 100644 index bbcc764..0000000 --- a/admin/dev_db_config.php +++ /dev/null @@ -1,12 +0,0 @@ - \ No newline at end of file diff --git a/admin/index.php b/admin/index.php index 3f34586..98c1905 100644 --- a/admin/index.php +++ b/admin/index.php @@ -10,7 +10,6 @@ session_start(); - ADMIN PANEL - Trojan's Trophy Room @@ -47,10 +46,21 @@ session_start(); //Check if any rows exist $count = $sqlCheckAdminTable->rowCount(); - $count = 1; - - // EVENTUALLY WE NEED TO MAKE SURE THE PERSON LOGGED IN IS AN ADMIN - + + /* This if-statement controls the display of the admin page + // First we check if there's actually gonna be an admin user + // - we do this by checking the safe-admin database, because + // if there's at least one user there, they would have been + // copied into the primary user database upon initialization + // + // Then we check if the person is logged in or not - if not, + // we re-direct them to the login page, where we'll be + // brought back after logging in + // + // We are also checking if the person is an admin user - + // if they are NOT, then we show the 'not_admin' page, + // telling the user they're not allowed to view the content + */ if ($count == 0) { // If no safe admins are found, we'll force creation of one echo ""; @@ -66,17 +76,17 @@ session_start(); ?> -