diff --git a/TblEditor.php b/TblEditor.php index ef08898..bc5e186 100644 --- a/TblEditor.php +++ b/TblEditor.php @@ -33,38 +33,39 @@ if ($cmd == "getTable") { // Iterate over the rows foreach ($rows as $row) { - $tableMarkup .= ''; + $string = str_replace('\n', " ", $row['String']); + + $tableMarkup .= ""; $tableMarkup .= "{$row['rowid']}"; // Display the Key column as a text input with Bootstrap form-control class - $tableMarkup .= ''; + $tableMarkup .= "{$row['Key']}"; // Display the String column as a textarea with Bootstrap form-control class - $tableMarkup .= ''; + $tableMarkup .= ""; // Add the Update and Delete links within a single td element - $tableMarkup .= '
'; + $tableMarkup .= "
"; // Add the Update link with Bootstrap btn and btn-primary classes - $tableMarkup .= 'Update'; + $tableMarkup .= "Update"; // Add the Delete link with Bootstrap btn and btn-danger classes - $tableMarkup .= 'Delete'; + $tableMarkup .= "Delete"; - $tableMarkup .= '
'; + $tableMarkup .= "
"; - $tableMarkup .= ''; + $tableMarkup .= ""; } - // Return the table markup echo $tableMarkup; } if ($cmd == "update") { - $query = "UPDATE patchstring SET Key = ?, String = ? WHERE ROWID = ?"; + $query = "UPDATE $tableName SET Key = ?, String = ? WHERE ROWID = ?"; PDO_Execute($query, [$_REQUEST['key'], $_REQUEST['string'], $_REQUEST['rowid']]); echo $_REQUEST['key'] . " updated"; @@ -87,13 +88,10 @@ if ($cmd == "add") { // Execute the insert statement $result = PDO_Execute($query, $params); - - + // Retrieve the last inserted rowid from the table $query = "SELECT last_insert_rowid() AS rowid"; $result = PDO_FetchOne($query); - - + echo $result; - } diff --git a/TblEditorGUI.php b/TblEditorGUI.php index d75ad61..eecd42b 100644 --- a/TblEditorGUI.php +++ b/TblEditorGUI.php @@ -35,7 +35,7 @@ foreach (glob($tbl . "*.tbl") as $filename) { - + @@ -51,6 +51,7 @@ foreach (glob($tbl . "*.tbl") as $filename) { Editable Tables +
@@ -115,6 +116,8 @@ foreach (glob($tbl . "*.tbl") as $filename) { // Select element change event handler $('#tableName').change(function () { + $('.table').DataTable().destroy(); + var selectedTable = $(this).val(); // Send GET request to TblEditor.php?getTable with selected table name @@ -172,6 +175,9 @@ foreach (glob($tbl . "*.tbl") as $filename) { // Get the updated values from the corresponding input and textarea var key = $('.row-' + rowid + ' input').val(); var string = $('.row-' + rowid + ' textarea').val(); + string = string.replace(/ /g, '\\n'); + string = string.replace(/\n/g, '\\n'); + // Send POST request to TblEditor.php with the updated values $.post('TblEditor.php', {cmd: 'update', tableName: selectedTable, rowid: rowid, key: key, string: string}, function (response) { @@ -179,8 +185,6 @@ foreach (glob($tbl . "*.tbl") as $filename) { // Optional: Update any UI elements if needed - // Update DataTable - $('.table').DataTable().draw(); }); }); @@ -195,23 +199,23 @@ foreach (glob($tbl . "*.tbl") as $filename) { // Handle the response here rowid = response; // Create the HTML markup for the new row -var newRow = '' + - '' + rowid + '' + - '' + - '' + - '
' + - 'Update' + - 'Delete' + - '
' + - ''; -; + var newRow = '' + + '' + rowid + '' + + '' + + '' + + '
' + + 'Update' + + 'Delete' + + '
' + + ''; + ; // Append the new row to the table $('.table').DataTable().destroy(); - + $('.table tbody').append(newRow); - + $('.table').DataTable(); }); }); @@ -220,7 +224,18 @@ var newRow = '' + }); + $(document).ready(function () { + // Iterate over each div with the form-control class + $('.form-control').each(function () { + // Get the text content of the div + var text = $(this).val(); + // Set the height of the div to fit the text content + $(this).height('auto'); // Reset the height to auto + var contentHeight = $(this).prop('scrollHeight'); + $(this).height(contentHeight); + }); + });