mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2024-11-30 04:26:03 +00:00
TBL Editor working
This commit is contained in:
parent
2362e336f6
commit
90cd6b6cd8
@ -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,
|
||||
@ -91,7 +91,7 @@ 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']}'>";
|
||||
|
||||
@ -126,7 +126,6 @@ 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']]);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -191,7 +191,6 @@ if ($cmd == "delete") {
|
||||
|
||||
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);
|
||||
|
||||
// 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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -177,8 +177,10 @@ foreach (glob($tbl . "*.tbl") as $filename) {
|
||||
// Remove the deleted row from the table
|
||||
$('.row-' + rowid).remove();
|
||||
|
||||
var key = $(this).parent().parent().parent().find('input').val();
|
||||
|
||||
// Send GET request to TblEditor.php?cmd=delete&rowid={rowid}
|
||||
$.get('TblEditor.php', {cmd: 'delete', tableName: selectedTable, rowid: rowid}, function (response) {
|
||||
$.get('TblEditor.php?key=' + key + '&', {cmd: 'delete', tableName: selectedTable, rowid: rowid}, function (response) {
|
||||
// Handle the response here
|
||||
|
||||
// Wait until the response is loaded, then remove the row
|
||||
@ -226,31 +228,45 @@ foreach (glob($tbl . "*.tbl") as $filename) {
|
||||
// Send POST request to TblEditor.php with parameters
|
||||
$.post('TblEditor.php', {cmd: 'add', tableName: selectedTable, Key: key, String: string}, function (response) {
|
||||
// Handle the response here
|
||||
rowid = response;
|
||||
// Create the HTML markup for the new row
|
||||
var newRow = '<tr class="row-' + rowid + '">' +
|
||||
'<td>' + rowid + '</td>' +
|
||||
'<td><input type="text" value="' + key + '" class="form-control"></td>' +
|
||||
'<td><textarea class="form-control">' + string + '</textarea></td>' +
|
||||
'<td><div>' +
|
||||
'<a href="#" class="update-link btn btn-primary" data-rowid="' + rowid + '">Update</a>' +
|
||||
'<a style="float:right" href="#" class="delete-link btn btn-danger" data-rowid="' + rowid + '">Delete</a>' +
|
||||
'</div></td>' +
|
||||
'</tr>';
|
||||
;
|
||||
});
|
||||
|
||||
|
||||
// Append the new row to the table
|
||||
$('.table').DataTable().destroy();
|
||||
$('.table tbody').html('');--
|
||||
// Send GET request to TblEditor.php?getTable with selected table name
|
||||
var request = $.get('TblEditor.php', {cmd: 'getTable', tableName: selectedTable});
|
||||
|
||||
$('.table tbody').append(newRow);
|
||||
request.done(function (response) {
|
||||
hideLoadingSpinner();
|
||||
// Handle the response here
|
||||
$('.tablediv tbody').html(response).promise().done(function () {
|
||||
// Callback function after HTML content is loaded
|
||||
|
||||
// Initialize DataTables on the table
|
||||
var table = $('.table').DataTable();
|
||||
$('.table').DataTable();
|
||||
|
||||
// Go to the last page after loading the table
|
||||
var table = $('.table').DataTable();
|
||||
table.page( 'last' ).draw( 'page' );
|
||||
|
||||
// Resize textareas on page load
|
||||
$('textarea').each(resizeTextarea);
|
||||
|
||||
// Resize textareas on input
|
||||
$('textarea').on('input', resizeTextarea);
|
||||
|
||||
// Resize textareas on custom select change
|
||||
$('.custom-select').change(function () {
|
||||
$('textarea').each(resizeTextarea);
|
||||
});
|
||||
$('.page-link').click(function () {
|
||||
$('textarea').each(resizeTextarea);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user