d2tools/test.php
2023-09-10 20:02:58 -06:00

144 lines
4.1 KiB
PHP

<?php
session_start();
ob_start();
require_once './config.php';
require_once './_pdo.php';
require_once './config.php';
require_once './src/D2Functions.php';
require_once './src/D2ByteReader.php';
require_once './src/D2BitReader.php';
error_reporting(E_ALL);
set_time_limit(-1);
ini_set('max_input_time', '-1');
ini_set('max_execution_time', '0');
define('DB_FILE', $_SESSION['modname'] . ".db");
try {
PDO_Connect("sqlite:" . DB_FILE);
} catch (Exception $e) {
echo "Connection error: " . $e->getMessage();
}
$query = "SELECT Id,LevelName FROM levels";
$levels = PDO_FetchAssoc($query);
$query = "SELECT * FROM levels";
$levelsAll = PDO_FetchAll($query);
$query = "SELECT monstats.Id, strings.String AS Name
FROM monstats
LEFT JOIN strings ON monstats.NameStr = strings.Key;";
$monstats = PDO_FetchAssoc($query);
//ddump($monstats);
$query = "SELECT LevelName,Vis0,Vis1,Vis2,Vis3,Vis4,Vis5,Vis6,Vis7 FROM levels";
$res = PDO_FetchAll($query);
$output = [];
foreach ($res as $key => $item) {
$newItem = [];
$newItem['LevelName'] = $item['LevelName']; // Copy the LevelName to new item
foreach ($levelsAll[$key] as $levelsKey => $levelsValue) {
$newItem[$levelsKey] = isset($monstats[$levelsValue]) ? $monstats[$levelsValue] : $levelsValue;
}
$foundLevels = []; // Store found level names to avoid duplicates
foreach ($item as $subKey => $subItem) {
// Check if the key starts with 'Vis', has a corresponding level, is non-empty, and is not a duplicate
if (strpos($subKey, 'Vis') === 0 && isset($levels[$subItem]) && $levels[$subItem] !== '' && !in_array($levels[$subItem], $foundLevels)) {
$newItem[$subKey] = "(" . $subItem . ") " . $levels[$subItem];
$foundLevels[] = $levels[$subItem]; // Add to found levels
}
}
$output[] = array_filter($newItem); // Add the modified item to the output array
}
unset($output[0]);
ddump($output);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Levels Table</title>
<!-- Include Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
/* Colorize alternate rows */
.table-striped tbody tr:nth-child(odd) {
background-color: #f2f2f2; /* Alternate row color */
}
/* Colorize alternate columns */
.table-striped tbody tr td:nth-child(odd) {
background-color: #e6e6e6; /* Alternate column color */
}
.sticky-top th {
position: sticky;
top: 0;
background-color: #ffffff; /* Header background color */
}
</style>
</head>
<body>
<?php
// Start the HTML table with Bootstrap classes
echo "<table id='myTable' class='table table-bordered table-striped'>";
// Display table headers with Bootstrap styling
$headers = ['Id', 'Name', 'LevelName'];
for ($i = 0; $i < 8; $i++) {
$headers[] = "Vis" . $i;
}
for ($i = 1; $i <= 25; $i++) {
$headers[] = "mon" . $i;
}
$headers[] = 'MonDen';
echo "<thead class='thead-dark'>"; // Add thead and use Bootstrap dark theme
echo "<tr class='sticky-top'>";
foreach ($headers as $header) {
echo "<th>" . $header . "</th>";
}
echo '</tr>';
echo "</thead>";
// Display table data with Bootstrap styling
echo "<tbody>";
foreach ($output as $level) {
echo "<tr>";
foreach ($headers as $header) {
if (isset($level[$header])) {
echo "<td>" . $level[$header] . "</td>";
} else {
echo "<td></td>";
}
}
echo "</tr>";
}
echo "</tbody>";
// End the HTML table
echo "</table>";
?>
<!-- Include Bootstrap JS and jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>