diff --git a/admin/admin_nav.php b/admin/admin_nav.php index 8a54c09..e45ddb0 100644 --- a/admin/admin_nav.php +++ b/admin/admin_nav.php @@ -16,7 +16,8 @@

 

TOURNEY MANAGEMENT

@@ -31,7 +32,6 @@ CHECK DB CONNECTION RE-INITIALIZE DB SHOW RAW DB - FOUR

 

diff --git a/admin/db_config.php b/admin/db_config.php index 75e25a7..ee86881 100644 --- a/admin/db_config.php +++ b/admin/db_config.php @@ -6,6 +6,15 @@ $username = "USERNAME"; $password = "PASSWORD"; $dbName = "DBNAME"; +//////////////////////////// DEVELOPER /////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +// THIS IS ONLY TO REPLACE THE ABOVE DEFAULTS WITH OUR DEV-ENVIRONMENT DETAILS +include ("dev_db_config.php"); +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + /*////// USER-CONFIGURABLE VARIABLES HERE ///////// @@ -17,6 +26,8 @@ $dbName = "DBNAME"; $userTableName = "users"; // name of the table containing user data $dataTableName = "replays"; // table containing replay data +$trophyTableName = "trophies"; // trophy data table +$adminUserTableName = "safeadmins"; $passwordLength = 8; // default minimum random password length @@ -34,6 +45,21 @@ $passwordLength = 8; // default minimum random password length ////////////////////////////////////////////*/ +// ADMIN DATA TABLE +$sqlCreateAdminTable = " +CREATE TABLE " . $adminUserTableName . " ( +userID INT(8) UNSIGNED AUTO_INCREMENT PRIMARY KEY, +isAdmin BOOL, +username VARCHAR(30) NOT NULL, +password VARCHAR(255), +discord VARCHAR(50), +twitch VARCHAR(50), +youtube VARCHAR(50), +userCreated TIMESTAMP DEFAULT CURRENT_TIMESTAMP, +userUpdated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +)"; + + // USER DATA TABLE $sqlCreateUserTable = " CREATE TABLE " . $userTableName . " ( @@ -53,10 +79,10 @@ userUpdated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP $sqlCreateDataTable = " CREATE TABLE " . $dataTableName . " ( replayID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, -ballchasingID VARCHAR(100) NOT NULL, -replayName VARCHAR(150) NOT NULL, +ballchasingID VARCHAR(100), +replayName VARCHAR(150), uploadedBy VARCHAR(30), -numPlayers TINYINT UNSIGNED NOT NULL, +numPlayers TINYINT UNSIGNED, player1 VARCHAR(30), player2 VARCHAR(30), player3 VARCHAR(30), @@ -67,4 +93,18 @@ player7 VARCHAR(30), player8 VARCHAR(30), notes VARCHAR(1000) )"; + + +// TROPHY DATA TABLE +$sqlCreateTrophyTable = " +CREATE TABLE " . $trophyTableName . " ( +trophyID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, +replayID INT UNSIGNED, +trophyType VARCHAR(25), +winner1 VARCHAR(30), +winner2 VARCHAR(30), +winner3 VARCHAR(30), +numPlayers TINYINT UNSIGNED, +notes VARCHAR(1000) +)"; ?> \ No newline at end of file diff --git a/admin/db_management/initialize.php b/admin/db_management/initialize.php index 534e24a..ed56bbc 100644 --- a/admin/db_management/initialize.php +++ b/admin/db_management/initialize.php @@ -13,7 +13,7 @@ getMessage(); } + ////////// USER DATA /////////// + + echo "

Creating user data table...

"; // Check if the users table exists already $sqlCheckUserTable = $conn->prepare("SHOW TABLES LIKE '" . $userTableName . "'"); @@ -55,7 +58,19 @@ } } - // Check if the users table exists already + // Next we're going to copy any safe admins into the users table. + // This will make userlists easier to work with + echo "

Copying users from safe admins...

"; + $copyAdmins = $conn->prepare("INSERT INTO " . $userTableName . " SELECT * FROM " . $adminUserTableName); + + $copyAdmins->execute(); + echo "

Copied!

"; + + + //////// REPLAY DATA //////// + echo "

Creating replay data table...

"; + + // Check if the replay data table exists already $sqlCheckDataTable = $conn->prepare("SHOW TABLES LIKE '" . $dataTableName . "'"); // Run the query @@ -85,6 +100,39 @@ } } + //////// TROPHY DATA //////// + echo "

Creating trophy data table...

"; + + // Check if the replay data table exists already + $sqlCheckTrophyTable = $conn->prepare("SHOW TABLES LIKE '" . $trophyTableName . "'"); + + // Run the query + $sqlCheckTrophyTable->execute(); + + //Check if any rows exist - if not, create the table, if yes, destroy it first, then create it + $count = $sqlCheckTrophyTable->rowCount(); + + if ($count != 0) { + echo "

Deleting exsiting table '" . $trophyTableName . "'...

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

Deleted!

Creating new table '" . $trophyTableName . "'...

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

Table '" . $trophyTableName . "' successfully created (trophy data)

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

Table '" . $trophyTableName . "' successfully created (trophy data)

"; + } catch (PDOException $e) { + 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 new file mode 100644 index 0000000..bbcc764 --- /dev/null +++ b/admin/dev_db_config.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/admin/index.php b/admin/index.php index ed02d62..adda3da 100644 --- a/admin/index.php +++ b/admin/index.php @@ -14,7 +14,47 @@

Trojan's Trophy Room

ADMIN PANEL

- + + setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } catch (PDOException $e) { // failed connection + echo "SQL connection failed: " . $e->getMessage(); + } + + // Check if the admin table exists + $sqlCheckAdminTable = $conn->prepare("SHOW TABLES LIKE '" . $adminUserTableName . "'"); + + // Run the query + $sqlCheckAdminTable->execute(); + + //Check if any rows exist + $count = $sqlCheckAdminTable->rowCount(); + + $count = 1; + + // EVENTUALLY WE NEED TO MAKE SURE THE PERSON LOGGED IN IS AN ADMIN + + + if ($count == 0) { // If no safe admins are found, we'll force creation of one + echo ""; + } else { // Otherwise we'll show the nav page + echo ""; + } + + ?> + +
diff --git a/styles/admin_nav.css b/styles/admin_nav.css index fa8f4ad..dacb951 100644 --- a/styles/admin_nav.css +++ b/styles/admin_nav.css @@ -46,6 +46,7 @@ padding: 10px; padding-left: 30px; padding-right: 30px; + margin-top: 10px; } #dbManagementPanel {