2025-03-02 21:14:28 -05:00
< ? php
session_start ();
include ( " ../db_config.php " ); // Include database stuff
try { // Try opening the SQL database connection
2025-03-05 21:08:39 -05:00
$conn = new PDO ( " mysql:host= $servername ; dbname= $dbName " , $dbUsername , $dbPassword );
2025-03-02 21:14:28 -05:00
// set the PDO error mode to exception
$conn -> 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 ();
}
?>
2025-03-05 21:08:39 -05:00
2025-03-02 21:14:28 -05:00
<! DOCTYPE html >
< html >
< head >
< meta charset = " UTF-8 " />
< meta name = " viewport " content = " width=device-width, initial-scale=1, user-scalable=no " />
2025-03-03 21:46:44 -05:00
< link rel = " stylesheet " href = " /styles/primary.css " />
< link rel = " stylesheet " href = " /styles/admin.css " />
< link rel = " stylesheet " href = " /styles/admin_nav.css " />
< link rel = " stylesheet " href = " /styles/game_management.css " />
2025-03-02 21:14:28 -05:00
< link rel = " stylesheet " href = " https://code.jquery.com/ui/1.14.1/themes/base/jquery-ui.css " >
< script src = " https://code.jquery.com/jquery-3.7.1.js " ></ script >
< script src = " https://code.jquery.com/ui/1.14.1/jquery-ui.js " ></ script >
2025-03-08 11:28:55 -05:00
< script src = " /scripts/game_management.js " ></ script >
< script src = " /scripts/tools.js " ></ script >
2025-03-08 16:38:13 -05:00
< script > verifyPageInFrame () </ script >
2025-03-10 12:39:39 -04:00
< script >
if ( parent . window . screen . width >= 360 && window . screen . width <= 1024 ) {
// If mobile, get the mobile version
window . location . replace ( " /admin/data_management/game_form_mobile.php " );
}
</ script >
2025-03-02 21:14:28 -05:00
< title > GAME ADDING FORM </ title >
< script >
$ ( function () {
var userList = < ? php echo json_encode ( $userList ); ?> ;
$ ( " .playerInput " ) . autocomplete ({
source : userList ,
});
} );
$ ( function () {
var tournamentList = < ? php echo json_encode ( $tourneyList ); ?> ;
$ ( " #tourneyName " ) . autocomplete ({
source : tournamentList ,
2025-03-03 21:46:44 -05:00
// Change the direction of the autoselector if it's gonna hit the bottom
2025-03-02 21:14:28 -05:00
position : {
collision : " flip "
},
2025-03-03 21:46:44 -05:00
// This only allows listed items to be chosen
2025-03-02 21:14:28 -05:00
change : function ( event , ui ) {
if ( ! ui . item ) {
$ ( " #tourneyName " ) . val ( " " );
}
}
});
} );
</ script >
</ head >
2025-03-10 12:39:39 -04:00
< body id = " gameFormBody " >
2025-03-02 21:14:28 -05:00
< div id = " gameFormPanel " >
< form id = " userForm " action = " add_game.php " method = " POST " autocomplete = " off " >
< h2 > ADD GAME RESULTS </ h2 >
< p > Add a recently - played game and save the results !</ p >
< hr >
< p ></ p >
< div id = " textInputArea " >
< label for = " gameName " > Game name </ label >
< input type = " text " id = " gameName " name = " gameName " maxlength = " 100 " tabindex = " 1 " required >
< p class = " newLine " ></ p >
< label for = " gameName " > Game date </ label >
< input type = " date " id = " gameDate " name = " gameDate " max = " <?php echo date( " Y - m - d " ); ?> " tabindex = " 1 " required >
< p class = " newLine " ></ p >
</ div >
< div class = " optionsArea " >
< label for = " numPlayers " > Players :</ label >
2025-03-08 11:28:55 -05:00
< select id = " numPlayers " name = " numPlayers " tabindex = " 1 " onchange = " changePlayers() " >
2025-03-02 21:14:28 -05:00
< option value = " 1 " > 1 v1 </ option >
< option value = " 2 " selected = " selected " > 2 v2 </ option >
< option value = " 3 " > 3 v3 </ option >
< option value = " 4 " > 4 v4 </ option >
</ select >
< label for = " winners " class = " showTeamSelector " > Winning team :</ label >
< select id = " winners " name = " winners " class = " showTeamSelector " tabindex = " 1 " >
< option value = " blue " > Blue </ option >
< option value = " orange " > Orange </ option >
</ select >
</ div >
< p class = " newLine " ></ p >
< div id = " playerDataInputArea " >
< table id = " playerData " >
</ table >
< script > addPlayers (); </ script >
< p class = " newLine " ></ p >
</ div >
< p class = " newLine " ></ p >
< div class = " optionsArea " >
2025-03-08 08:44:44 -05:00
< p class = " newLine " > If this game was part of a tournament , select it below </ p >
2025-03-02 21:14:28 -05:00
< input type = " text " name = " tourneyName " id = " tourneyName " maxlength = " 150 " tabindex = " 4 " >
2025-03-08 08:44:44 -05:00
< p class = " newLine " >If you have uploaded a replay of this game to <a href= " #" onclick="redirect('ballchasing', 'https://ballchasing.com')" class="plainLinkBlue">ballchasing.com</a>, enter the ID code below.</p>
2025-03-08 11:28:55 -05:00
< input type = " text " name = " ballchasingID " id = " ballchasingID " maxlength = " 100 " tabindex = " 4 " >
2025-03-02 21:14:28 -05:00
< p class = " newLine " ></ p >
< p > If you have any notes about the game , leave them below </ p >
< textarea name = " notes " id = " notes " tabindex = " 4 " ></ textarea >
</ div >
< p class = " newLine " ></ p >
< div id = " submitButtonDiv " >
< p class = " newLine " ></ p >
< input type = " submit " value = " Submit " id = " submitButton " tabindex = " 4 " >
</ div >
< p class = " newLine " ></ p >
</ form >
</ div >
</ body >
</ html >