mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2025-10-13 16:34:23 -05:00
TBL Editor working
This commit is contained in:
@@ -72,7 +72,7 @@ if ($cmd == "getTable") {
|
||||
foreach ($fileLines as $line) {
|
||||
$row = explode("\t", $line);
|
||||
$key = $row[0];
|
||||
$string = trim($row[1]);
|
||||
$string = ($row[1]);
|
||||
|
||||
$rowData = [
|
||||
'rowid' => $rowid,
|
||||
@@ -90,9 +90,9 @@ if ($cmd == "getTable") {
|
||||
|
||||
// Iterate over the rows
|
||||
foreach ($rows as $row) {
|
||||
|
||||
$row['String'] = str_replace('}', ' ', $row['String']);
|
||||
|
||||
|
||||
$row['String'] = trim(str_replace('}', ' ', $row['String']));
|
||||
|
||||
$tableMarkup .= "<tr class='row-{$row['rowid']}'>";
|
||||
|
||||
$tableMarkup .= "<td style='width: 64px;'>{$row['rowid']}</td>";
|
||||
@@ -123,10 +123,9 @@ if ($cmd == "getTable") {
|
||||
|
||||
|
||||
if ($cmd == "update") {
|
||||
|
||||
|
||||
$string = str_replace('\n', '}', $_REQUEST['string']);
|
||||
|
||||
|
||||
|
||||
$query = "UPDATE $tableName SET Key = ?, String = ? WHERE Key = ?";
|
||||
PDO_Execute($query, [$_REQUEST['key'], $string, $_REQUEST['key']]);
|
||||
|
||||
@@ -150,7 +149,7 @@ if ($cmd == "update") {
|
||||
shell_exec($processCommand);
|
||||
|
||||
rename(getcwd() . "\ModString.tbl", "{$_SESSION['tbl']}/$tableName.tbl");
|
||||
|
||||
|
||||
// Remove empty lines from end of file
|
||||
// Read the file contents into an array of lines
|
||||
$lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
@@ -172,6 +171,7 @@ if ($cmd == "delete") {
|
||||
$filePath = "{$_SESSION['tbl']}/$tableName.txt";
|
||||
// Calculate the line number to delete based on the rowid
|
||||
$lineNumber = $rowid - 1; // Assuming zero-indexed line numbers
|
||||
|
||||
// Read the lines of the text file into an array
|
||||
$fileLines = file($filePath, FILE_IGNORE_NEW_LINES);
|
||||
|
||||
@@ -182,16 +182,15 @@ if ($cmd == "delete") {
|
||||
|
||||
// Save the updated content back to the text file
|
||||
file_put_contents($filePath, implode("\n", $fileLines));
|
||||
|
||||
|
||||
// Convert TXT to TBL
|
||||
$executablePath = "bin\EnquettarM.exe";
|
||||
$processCommand = "{$executablePath} -i \"{$_SESSION['tbl']}/$tableName.txt\"";
|
||||
|
||||
shell_exec($processCommand);
|
||||
|
||||
rename(getcwd() . "\ModString.tbl", "{$_SESSION['tbl']}/$tableName.tbl");
|
||||
|
||||
|
||||
rename(getcwd() . "\ModString.tbl", "{$_SESSION['tbl']}/$tableName.tbl");
|
||||
|
||||
echo $_REQUEST['rowid'] . " deleted";
|
||||
}
|
||||
|
||||
@@ -199,7 +198,7 @@ if ($cmd == "add") {
|
||||
$tableName = $_POST['tableName'];
|
||||
$key = $_POST['Key'];
|
||||
$string = $_POST['String'];
|
||||
|
||||
$filePath = "{$_SESSION['tbl']}/$tableName.txt";
|
||||
// Create your insert statement using the provided values
|
||||
$query = "INSERT INTO $tableName (Key, String) VALUES (?, ?)";
|
||||
$params = array($key, $string);
|
||||
@@ -208,17 +207,24 @@ if ($cmd == "add") {
|
||||
$result = PDO_Execute($query, $params);
|
||||
|
||||
// Retrieve the last inserted rowid from the table
|
||||
$query = "SELECT last_insert_rowid() AS rowid";
|
||||
$result = PDO_FetchOne($query);
|
||||
|
||||
// $query = "SELECT last_insert_rowid() AS rowid";
|
||||
// $result = PDO_FetchOne($query);
|
||||
// Append the new row to the text file
|
||||
$newLine = "{$key}\t{$string}";
|
||||
file_put_contents($filePath, $newLine . PHP_EOL, FILE_APPEND);
|
||||
|
||||
file_put_contents($filePath, $newLine . PHP_EOL, FILE_APPEND);
|
||||
|
||||
// Get the line number of the newly inserted line
|
||||
$fileContents = file_get_contents($filePath);
|
||||
$linesArray = explode(PHP_EOL, $fileContents);
|
||||
$result = count($linesArray) - 1;
|
||||
|
||||
// Convert TXT to TBL
|
||||
$executablePath = "bin\EnquettarM.exe";
|
||||
$processCommand = "{$executablePath} -i \"{$_SESSION['tbl']}/$tableName.txt\"";
|
||||
|
||||
shell_exec($processCommand);
|
||||
|
||||
rename(getcwd() . "\ModString.tbl", "{$_SESSION['tbl']}/$tableName.tbl");
|
||||
|
||||
echo $result;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user