TblEditor working

This commit is contained in:
Hash Borgir
2023-06-13 21:15:23 -06:00
parent 3ce842b52d
commit 29621fa46c
1779 changed files with 888 additions and 157 deletions

View File

@@ -24,6 +24,32 @@ try {
$cmd = $_REQUEST['cmd'];
$tableName = $_REQUEST['tableName'];
function dumpAndProcessTable($tableName) {
// Set the path to the SQLite3 executable
$sqlitePath = "bin\sqlite3.exe";
// Dump the SQLite table to a TSV file
$tsvFile = $tableName . ".txt";
$dumpCommand = "bin\sqlite3.exe {$_SESSION['modname']}.db \"SELECT * FROM string\" -separator \"\t\" -cmd \".mode tabs\" -cmd \".headers off\" > \"{$_SESSION['tbl']}{$tsvFile}\"";
shell_exec($dumpCommand);
// Run the executable with the TSV file as input
$executablePath = "bin\EnquettarM.exe";
$processCommand = "{$executablePath} -i \"{$_SESSION['tbl']}{$tsvFile}\"";
$etxt = 'ModString.txt';
$etbl = 'ModString.tbl';
shell_exec($processCommand);
// now file is generated in rootdir, etbl, which we need to move to session tbl
rename($etbl, "{$_SESSION['tbl']}/$tableName.tbl");
// Remove the generated ModString.tbl
//unlink($etbl);
}
if ($cmd == "getTable") {
$query = "SELECT ROWID,* FROM $tableName";
$rows = PDO_Execute($query);
@@ -37,16 +63,16 @@ if ($cmd == "getTable") {
$tableMarkup .= "<tr class='row-{$row['rowid']}'>";
$tableMarkup .= "<td>{$row['rowid']}</td>";
$tableMarkup .= "<td style='width: 64px;'>{$row['rowid']}</td>";
// Display the Key column as a text input with Bootstrap form-control class
$tableMarkup .= "<td><input type='text' value='{$row['Key']}' class='form-control'><span style='visibility: hidden;'>{$row['Key']}</span></td>";
$tableMarkup .= "<td style='width: 20%;'><input type='text' value='{$row['Key']}' class='form-control'><span style='visibility: hidden;'>{$row['Key']}</span></td>";
// Display the String column as a textarea with Bootstrap form-control class
$tableMarkup .= "<td><textarea class='form-control'>{$string}</textarea></td>";
// Add the Update and Delete links within a single td element
$tableMarkup .= "<td><div>";
$tableMarkup .= "<td style='width: 100px;'><div>";
// Add the Update link with Bootstrap btn and btn-primary classes
$tableMarkup .= "<a href='#' class='update-link btn btn-primary' data-rowid='{$row['rowid']}'>Update</a>";
@@ -67,13 +93,14 @@ if ($cmd == "getTable") {
if ($cmd == "update") {
$query = "UPDATE $tableName SET Key = ?, String = ? WHERE ROWID = ?";
PDO_Execute($query, [$_REQUEST['key'], $_REQUEST['string'], $_REQUEST['rowid']]);
dumpAndProcessTable($tableName);
echo $_REQUEST['key'] . " updated";
}
if ($cmd == "delete") {
$query = "DELETE FROM $tableName WHERE ROWID = ?";
PDO_Execute($query, [$_REQUEST['rowid']]);
dumpAndProcessTable($tableName);
echo $_REQUEST['rowid'] . " deleted";
}
@@ -92,6 +119,7 @@ if ($cmd == "add") {
// Retrieve the last inserted rowid from the table
$query = "SELECT last_insert_rowid() AS rowid";
$result = PDO_FetchOne($query);
echo $result;
dumpAndProcessTable($tableName);
}