From 62a6dcf4df9065b3db4f79c87b3edc227ee4266e Mon Sep 17 00:00:00 2001 From: Hash Borgir Date: Sun, 10 Sep 2023 17:54:20 -0600 Subject: [PATCH] lvl editor working, testing --- LevelsEditor_Process.php | 80 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 LevelsEditor_Process.php diff --git a/LevelsEditor_Process.php b/LevelsEditor_Process.php new file mode 100644 index 0000000..b06b2f3 --- /dev/null +++ b/LevelsEditor_Process.php @@ -0,0 +1,80 @@ +getMessage(); + exit; // stop further execution because of the error +} + +// Check if all the expected POST data is available +if (isset($_POST['levelId'], $_POST['selectName'], $_POST['selectedValue'])) { + $levelId = $_POST['levelId']; + $selectName = $_POST['selectName']; + $selectedValue = $_POST['selectedValue']; + + // Update the data in the levels table + $query = "UPDATE levels SET $selectName = :selectedValue WHERE Id = :levelId"; + $params = [ + ':selectedValue' => $selectedValue, + ':levelId' => $levelId + ]; + + // Execute the query using the PDO_Execute() function + $result = PDO_Execute($query, $params); + if ($result) { + echo json_encode(['status' => 'success', 'message' => 'Data updated successfully.']); + } else { + echo json_encode(['status' => 'error', 'message' => 'Failed to update data.']); + } +} else { + echo json_encode(['status' => 'error', 'message' => 'Invalid POST data.']); +} + +//$tsvFileName = "Levels"; +//$db = new SQLite3(DB_FILE); +//$message = writeToTsvFile($tsvFileName, $db); +// +//echo $message; + + + +$bin = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? getcwd() . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "sqlite3.exe" : "/usr/bin/sqlite3"; +$dbfile = DB_FILE; +$tablename = "levels"; +$outputFile = $_SESSION['path'] . "Levels.txt"; + +// Build the command to export the SQLite table to a TSV file +$command = sprintf( + '%s %s ".mode tabs" ".headers on" "SELECT * FROM %s;" > "%s"', + $bin, + $dbfile, + $tablename, + $outputFile +); + + +//ddump($command); + +// Execute the command +$commandOutput = shell_exec($command); +if ($commandOutput) { + echo "Error: $commandOutput"; +} else { + echo "Table exported successfully!"; +} + +