mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2024-11-30 04:26:03 +00:00
lvl editor working, testing
This commit is contained in:
parent
b26715aea2
commit
62a6dcf4df
80
LevelsEditor_Process.php
Normal file
80
LevelsEditor_Process.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// Include necessary files
|
||||
require_once './config.php';
|
||||
require_once './_pdo.php';
|
||||
require_once './src/D2Functions.php';
|
||||
|
||||
// Define the database connection
|
||||
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();
|
||||
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!";
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user