Updated to use sqlite. Added /update_db.php and example.config.cfg to control sqlite db from a simple bootstrap UI
This commit is contained in:
parent
0684f3eb28
commit
ce42c091cc
|
@ -1 +1 @@
|
||||||
/config.php
|
/config.cfg
|
Binary file not shown.
BIN
db/ddd_db.sqlite
BIN
db/ddd_db.sqlite
Binary file not shown.
|
@ -85,10 +85,14 @@ a img {
|
||||||
|
|
||||||
.even {
|
.even {
|
||||||
background-color: rgba(0, 0, 0, 0.9);
|
background-color: rgba(0, 0, 0, 0.9);
|
||||||
|
border: 1px solid white;
|
||||||
|
border-radius: 10px; /* Adjust the value to get the desired roundness */
|
||||||
}
|
}
|
||||||
|
|
||||||
.odd {
|
.odd {
|
||||||
background-color: rgba(26, 26, 26, 0.9);
|
background-color: rgba(26, 26, 26, 0.9);
|
||||||
|
border: 1px solid white;
|
||||||
|
border-radius: 10px; /* Adjust the value to get the desired roundness */
|
||||||
}
|
}
|
||||||
|
|
||||||
.scoreEntry #player,
|
.scoreEntry #player,
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
password="CHANGE_ME!"
|
||||||
|
|
||||||
|
#To use this file, run the following
|
||||||
|
# cp example.config.cfg config.cfg
|
||||||
|
# Change the password
|
||||||
|
# Access the admin page at yourwebsite.com/update_db.php
|
|
@ -7,6 +7,10 @@
|
||||||
<img src="ddddxhs_files/download.png" alt="DOWNLOAD DASH-DA-DASH DX" title="DOWNLOAD DASH-DA-DASH DX">
|
<img src="ddddxhs_files/download.png" alt="DOWNLOAD DASH-DA-DASH DX" title="DOWNLOAD DASH-DA-DASH DX">
|
||||||
</a>
|
</a>
|
||||||
<br>
|
<br>
|
||||||
|
<li class='even ddd' id='player' style="font-size:12px">
|
||||||
|
SHA256 Checksum: 67ea139fa4721a05a26094d7bba9f3386c8473d7d7450ef762da7bf19ef921e5
|
||||||
|
</li>
|
||||||
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<img class='center' src="ddddxhs_files/features.png" alt="FEATURES DASH-DA-DASH DX" title="FEATURES DASH-DA-DASH DX">
|
<img class='center' src="ddddxhs_files/features.png" alt="FEATURES DASH-DA-DASH DX" title="FEATURES DASH-DA-DASH DX">
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
<?php
|
|
||||||
// Path to the SQLite database file
|
|
||||||
$db_path = 'db/ddd_db.sqlite';
|
|
||||||
|
|
||||||
// Check if the 'db' directory exists, if not, create it
|
|
||||||
if (!is_dir('db')) {
|
|
||||||
if (!mkdir('db', 0777, true)) {
|
|
||||||
die('Failed to create directories...');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
echo 'test1';
|
|
||||||
|
|
||||||
// Check if the database file exists
|
|
||||||
if (!file_exists($db_path)) {
|
|
||||||
try {
|
|
||||||
// Create a new SQLite3 database file
|
|
||||||
echo 'test2';
|
|
||||||
$db = new SQLite3($db_path);
|
|
||||||
echo 'test3';
|
|
||||||
|
|
||||||
// Create the 'scores' table
|
|
||||||
$createTableQuery = "
|
|
||||||
CREATE TABLE IF NOT EXISTS scores (
|
|
||||||
ID INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
Name TEXT NOT NULL,
|
|
||||||
Score INTEGER NOT NULL,
|
|
||||||
Mode TEXT NOT NULL,
|
|
||||||
Bosses TEXT NOT NULL
|
|
||||||
);
|
|
||||||
";
|
|
||||||
|
|
||||||
if ($db->exec($createTableQuery)) {
|
|
||||||
echo "Database and table created successfully.<br>";
|
|
||||||
} else {
|
|
||||||
echo "Error creating table: " . $db->lastErrorMsg() . "<br>";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close the database connection
|
|
||||||
$db->close();
|
|
||||||
} catch (Exception $e) {
|
|
||||||
echo 'Caught exception: ', $e->getMessage(), "<br>";
|
|
||||||
} catch (Error $e) {
|
|
||||||
echo 'Caught error: ', $e->getMessage(), "<br>";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
echo "Database already exists.<br>";
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -0,0 +1,263 @@
|
||||||
|
<?php
|
||||||
|
// Path to the SQLite database file
|
||||||
|
$db_path = 'db/ddd_db.sqlite';
|
||||||
|
$config_path = 'config.cfg';
|
||||||
|
|
||||||
|
// Load password from configuration file
|
||||||
|
$password = '';
|
||||||
|
if (file_exists($config_path)) {
|
||||||
|
$config = parse_ini_file($config_path);
|
||||||
|
if (isset($config['password'])) {
|
||||||
|
$password = $config['password'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to display an alert message
|
||||||
|
function displayAlert($message, $type) {
|
||||||
|
echo '<div class="alert alert-' . $type . '">' . $message . '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the 'db' directory exists, if not, create it
|
||||||
|
if (!is_dir('db')) {
|
||||||
|
if (!mkdir('db', 0777, true)) {
|
||||||
|
die('Failed to create directories...');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle password submission
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['login_password'])) {
|
||||||
|
if ($_POST['login_password'] === $password) {
|
||||||
|
session_start();
|
||||||
|
$_SESSION['logged_in'] = true;
|
||||||
|
} else {
|
||||||
|
displayAlert('Invalid password.', 'danger');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the session
|
||||||
|
session_start();
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Add Score</title>
|
||||||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<?php if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true): ?>
|
||||||
|
<h1 class="mt-5">Enter Password to Access</h1>
|
||||||
|
<form action="" method="post" class="mt-4">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="login_password">Password:</label>
|
||||||
|
<input type="password" class="form-control" id="login_password" name="login_password" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Submit</button>
|
||||||
|
</form>
|
||||||
|
<?php else: ?>
|
||||||
|
<h1 class="mt-5">Add a New Score</h1>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// Process form submission
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action'])) {
|
||||||
|
if ($_POST['action'] == 'add' && isset($_POST['name']) && isset($_POST['score']) && isset($_POST['mode'])) {
|
||||||
|
if (file_exists($db_path)) {
|
||||||
|
try {
|
||||||
|
// Open the SQLite3 database file
|
||||||
|
$db = new SQLite3($db_path);
|
||||||
|
|
||||||
|
// Prepare the insert query
|
||||||
|
$insertQuery = $db->prepare('INSERT INTO scores (Name, Score, Mode, Bosses) VALUES (:name, :score, :mode, :bosses)');
|
||||||
|
$insertQuery->bindValue(':name', $_POST['name'], SQLITE3_TEXT);
|
||||||
|
$insertQuery->bindValue(':score', $_POST['score'], SQLITE3_INTEGER);
|
||||||
|
$insertQuery->bindValue(':mode', $_POST['mode'], SQLITE3_TEXT);
|
||||||
|
$insertQuery->bindValue(':bosses', $_POST['bosses'], SQLITE3_TEXT);
|
||||||
|
|
||||||
|
// Execute the query
|
||||||
|
if ($insertQuery->execute()) {
|
||||||
|
displayAlert('Score added successfully.', 'success');
|
||||||
|
} else {
|
||||||
|
displayAlert('Error adding score: ' . $db->lastErrorMsg(), 'danger');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the database connection
|
||||||
|
$db->close();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
displayAlert('Caught exception: ' . $e->getMessage(), 'danger');
|
||||||
|
} catch (Error $e) {
|
||||||
|
displayAlert('Caught error: ' . $e->getMessage(), 'danger');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
displayAlert('Database does not exist.', 'warning');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_POST['action'] == 'delete' && isset($_POST['delete_id'])) {
|
||||||
|
if (file_exists($db_path)) {
|
||||||
|
try {
|
||||||
|
// Open the SQLite3 database file
|
||||||
|
$db = new SQLite3($db_path);
|
||||||
|
|
||||||
|
// Prepare the delete query
|
||||||
|
$deleteQuery = $db->prepare('DELETE FROM scores WHERE ID = :id');
|
||||||
|
$deleteQuery->bindValue(':id', $_POST['delete_id'], SQLITE3_INTEGER);
|
||||||
|
|
||||||
|
// Execute the query
|
||||||
|
if ($deleteQuery->execute()) {
|
||||||
|
displayAlert('Score deleted successfully.', 'success');
|
||||||
|
} else {
|
||||||
|
displayAlert('Error deleting score: ' . $db->lastErrorMsg(), 'danger');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the database connection
|
||||||
|
$db->close();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
displayAlert('Caught exception: ' . $e->getMessage(), 'danger');
|
||||||
|
} catch (Error $e) {
|
||||||
|
displayAlert('Caught error: ' . $e->getMessage(), 'danger');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
displayAlert('Database does not exist.', 'warning');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form action="" method="post" class="mt-4">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">Name:</label>
|
||||||
|
<input type="text" class="form-control" id="name" name="name" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="score">Score:</label>
|
||||||
|
<input type="number" class="form-control" id="score" name="score" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="mode">Mode:</label>
|
||||||
|
<input type="text" class="form-control" id="mode" name="mode" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="bosses">Bosses:</label>
|
||||||
|
<input type="text" class="form-control" id="bosses" name="bosses">
|
||||||
|
</div>
|
||||||
|
<input type="hidden" name="action" value="add">
|
||||||
|
<button type="submit" class="btn btn-primary">Add Score</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<h2 class="mt-5">Current Scores (DX)</h2>
|
||||||
|
<table class="table table-bordered mt-3">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Score</th>
|
||||||
|
<th>Mode</th>
|
||||||
|
<th>Bosses</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
if (file_exists($db_path)) {
|
||||||
|
try {
|
||||||
|
// Open the SQLite3 database file
|
||||||
|
$db = new SQLite3($db_path);
|
||||||
|
|
||||||
|
// Query to fetch current scores for DX mode ordered by highest score
|
||||||
|
$result = $db->query("SELECT * FROM scores WHERE Mode = 'DX' ORDER BY Score DESC");
|
||||||
|
|
||||||
|
// Display the rows
|
||||||
|
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||||
|
echo "<tr>
|
||||||
|
<td>{$row['ID']}</td>
|
||||||
|
<td>{$row['Name']}</td>
|
||||||
|
<td>{$row['Score']}</td>
|
||||||
|
<td>{$row['Mode']}</td>
|
||||||
|
<td>{$row['Bosses']}</td>
|
||||||
|
<td>
|
||||||
|
<form action='' method='post' style='display:inline-block;'>
|
||||||
|
<input type='hidden' name='delete_id' value='{$row['ID']}'>
|
||||||
|
<input type='hidden' name='action' value='delete'>
|
||||||
|
<button type='submit' class='btn btn-danger btn-sm'>Delete</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the database connection
|
||||||
|
$db->close();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
displayAlert('Caught exception: ' . $e->getMessage(), 'danger');
|
||||||
|
} catch (Error $e) {
|
||||||
|
displayAlert('Caught error: ' . $e->getMessage(), 'danger');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo '<tr><td colspan="6">No scores found. Database does not exist.</td></tr>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h2 class="mt-5">Current Scores (EX)</h2>
|
||||||
|
<table class="table table-bordered mt-3">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Score</th>
|
||||||
|
<th>Mode</th>
|
||||||
|
<th>Bosses</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
if (file_exists($db_path)) {
|
||||||
|
try {
|
||||||
|
// Open the SQLite3 database file
|
||||||
|
$db = new SQLite3($db_path);
|
||||||
|
|
||||||
|
// Query to fetch current scores for EX mode ordered by highest score
|
||||||
|
$result = $db->query("SELECT * FROM scores WHERE Mode = 'EX' ORDER BY Score DESC");
|
||||||
|
|
||||||
|
// Display the rows
|
||||||
|
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||||
|
echo "<tr>
|
||||||
|
<td>{$row['ID']}</td>
|
||||||
|
<td>{$row['Name']}</td>
|
||||||
|
<td>{$row['Score']}</td>
|
||||||
|
<td>{$row['Mode']}</td>
|
||||||
|
<td>{$row['Bosses']}</td>
|
||||||
|
<td>
|
||||||
|
<form action='' method='post' style='display:inline-block;'>
|
||||||
|
<input type='hidden' name='delete_id' value='{$row['ID']}'>
|
||||||
|
<input type='hidden' name='action' value='delete'>
|
||||||
|
<button type='submit' class='btn btn-danger btn-sm'>Delete</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the database connection
|
||||||
|
$db->close();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
displayAlert('Caught exception: ' . $e->getMessage(), 'danger');
|
||||||
|
} catch (Error $e) {
|
||||||
|
displayAlert('Caught error: ' . $e->getMessage(), 'danger');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo '<tr><td colspan="6">No scores found. Database does not exist.</td></tr>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||||
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user