diff --git a/TblEditor.php b/TblEditor.php index 77d8075..4ecb3dc 100644 --- a/TblEditor.php +++ b/TblEditor.php @@ -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 .= ""; $tableMarkup .= "{$row['rowid']}"; @@ -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; - - - - - } diff --git a/TblEditorGUI_TAB.php b/TblEditorGUI_TAB.php index b7b473c..7a5de7f 100644 --- a/TblEditorGUI_TAB.php +++ b/TblEditorGUI_TAB.php @@ -28,266 +28,282 @@ foreach (glob($tbl . "*.tbl") as $filename) { } ?> - - - - - + + + + + - + - - - + + + - - + + - + - - + + -
-
-
-
- -
-
- -
+
+
+
+
+
- -
-
- - -
-
- - -
- +
+
-
-
- -
- - - - - - - - - - - - -
IDKeyString
+
+
+ + +
+
+ + +
+
- -
- - - + + + \ No newline at end of file