2023-06-02 05:35:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
session_start();
|
|
|
|
ob_start();
|
|
|
|
|
|
|
|
require_once './config.php';
|
|
|
|
require_once './_pdo.php';
|
|
|
|
|
|
|
|
require_once './src/D2Functions.php';
|
|
|
|
|
2023-06-13 07:14:37 +00:00
|
|
|
error_reporting(E_ALL);
|
2023-06-02 05:35:10 +00:00
|
|
|
set_time_limit(-1);
|
|
|
|
ini_set('max_input_time', '-1');
|
|
|
|
ini_set('max_execution_time', '0');
|
|
|
|
|
|
|
|
define('DB_FILE', $_SESSION['modname'] . ".db");
|
2023-06-13 07:14:37 +00:00
|
|
|
try {
|
|
|
|
PDO_Connect("sqlite:" . DB_FILE);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo "Connection error: " . $e->getMessage();
|
2023-06-02 05:35:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-13 07:14:37 +00:00
|
|
|
$cmd = $_REQUEST['cmd'];
|
|
|
|
$tableName = $_REQUEST['tableName'];
|
|
|
|
|
2023-06-14 08:40:21 +00:00
|
|
|
//function dumpAndProcessTable($tableName) {
|
|
|
|
// // Set the path to the SQLite3 executable
|
|
|
|
// $sqlitePath = "bin\sqlite3.exe";
|
|
|
|
//
|
|
|
|
// // Dump the SQLite table to a TSV file
|
|
|
|
// $tsvFile = $tableName . ".txt";
|
|
|
|
// $dumpCommand = "bin\sqlite3.exe {$_SESSION['modname']}.db \"SELECT * FROM string\" -separator \"\t\" -cmd \".mode tabs\" -cmd \".headers off\" > \"{$_SESSION['tbl']}{$tsvFile}\"";
|
|
|
|
// shell_exec($dumpCommand);
|
|
|
|
//
|
|
|
|
// die();
|
|
|
|
//
|
|
|
|
// // Convert TSV to TBL
|
|
|
|
// // Run the executable with the TSV file as input
|
|
|
|
// $executablePath = "bin\EnquettarM.exe";
|
|
|
|
// $processCommand = "{$executablePath} -i \"{$_SESSION['tbl']}{$tsvFile}\"";
|
|
|
|
//
|
|
|
|
// // will be saved into ModString.tbl
|
|
|
|
//
|
|
|
|
// $etxt = 'ModString.txt';
|
|
|
|
// $etbl = 'ModString.tbl';
|
|
|
|
//
|
|
|
|
// shell_exec($processCommand);
|
|
|
|
//
|
|
|
|
// // now file is generated in rootdir, etbl, which we need to move to session tbl
|
|
|
|
// rename($etbl, "{$_SESSION['tbl']}/$tableName.tbl");
|
|
|
|
//
|
|
|
|
// // Remove the generated ModString.tbl
|
|
|
|
// //unlink($etbl);
|
|
|
|
//}
|
2023-06-14 03:15:23 +00:00
|
|
|
|
2023-06-14 08:40:21 +00:00
|
|
|
if ($cmd == "getTable") {
|
|
|
|
$filePath = "{$_SESSION['tbl']}/$tableName.tbl";
|
|
|
|
$executablePath = getcwd() . "\bin\EnquettarM.exe";
|
|
|
|
$processCommand = "{$executablePath} -e \"$filePath\"";
|
2023-06-14 03:15:23 +00:00
|
|
|
shell_exec($processCommand);
|
|
|
|
|
2023-06-14 08:40:21 +00:00
|
|
|
rename(getcwd() . "\ModString.txt", "{$_SESSION['tbl']}/$tableName.txt");
|
|
|
|
|
|
|
|
$filePath = "{$_SESSION['tbl']}/$tableName.txt";
|
|
|
|
|
|
|
|
$fileLines = file($filePath);
|
|
|
|
|
|
|
|
$rows = [];
|
|
|
|
$rowid = 1; // Starting rowid value
|
|
|
|
|
|
|
|
foreach ($fileLines as $line) {
|
|
|
|
$row = explode("\t", $line);
|
|
|
|
$key = $row[0];
|
2023-06-14 09:21:42 +00:00
|
|
|
$string = trim($row[1]);
|
2023-06-14 08:40:21 +00:00
|
|
|
|
|
|
|
$rowData = [
|
|
|
|
'rowid' => $rowid,
|
|
|
|
'Key' => $key,
|
|
|
|
'String' => $string
|
|
|
|
];
|
|
|
|
|
|
|
|
$rows[] = $rowData;
|
|
|
|
$rowid++;
|
|
|
|
}
|
|
|
|
|
2023-06-13 07:14:37 +00:00
|
|
|
|
|
|
|
// Start the table with Bootstrap classes
|
|
|
|
$tableMarkup = '';
|
|
|
|
|
|
|
|
// Iterate over the rows
|
|
|
|
foreach ($rows as $row) {
|
2023-06-14 09:44:04 +00:00
|
|
|
|
|
|
|
$row['String'] = str_replace('}', ' ', $row['String']);
|
|
|
|
|
2023-06-13 17:48:19 +00:00
|
|
|
$tableMarkup .= "<tr class='row-{$row['rowid']}'>";
|
2023-06-13 07:14:37 +00:00
|
|
|
|
2023-06-14 03:15:23 +00:00
|
|
|
$tableMarkup .= "<td style='width: 64px;'>{$row['rowid']}</td>";
|
2023-06-13 07:14:37 +00:00
|
|
|
|
|
|
|
// Display the Key column as a text input with Bootstrap form-control class
|
2023-06-14 03:15:23 +00:00
|
|
|
$tableMarkup .= "<td style='width: 20%;'><input type='text' value='{$row['Key']}' class='form-control'><span style='visibility: hidden;'>{$row['Key']}</span></td>";
|
2023-06-13 07:14:37 +00:00
|
|
|
|
|
|
|
// Display the String column as a textarea with Bootstrap form-control class
|
2023-06-14 08:40:21 +00:00
|
|
|
$tableMarkup .= "<td><textarea class='form-control'>{$row['String']}</textarea></td>";
|
2023-06-13 07:14:37 +00:00
|
|
|
|
|
|
|
// Add the Update and Delete links within a single td element
|
2023-06-14 03:15:23 +00:00
|
|
|
$tableMarkup .= "<td style='width: 100px;'><div>";
|
2023-06-13 07:14:37 +00:00
|
|
|
|
|
|
|
// Add the Update link with Bootstrap btn and btn-primary classes
|
2023-06-13 17:48:19 +00:00
|
|
|
$tableMarkup .= "<a href='#' class='update-link btn btn-primary' data-rowid='{$row['rowid']}'>Update</a>";
|
2023-06-13 07:14:37 +00:00
|
|
|
|
|
|
|
// Add the Delete link with Bootstrap btn and btn-danger classes
|
2023-06-14 08:40:21 +00:00
|
|
|
$tableMarkup .= "<a style='' href='#' class='delete-link btn btn-danger' data-rowid='{$row['rowid']}'>Delete</a>";
|
2023-06-13 07:14:37 +00:00
|
|
|
|
2023-06-13 17:48:19 +00:00
|
|
|
$tableMarkup .= "</div></td>";
|
2023-06-13 07:14:37 +00:00
|
|
|
|
2023-06-13 17:48:19 +00:00
|
|
|
$tableMarkup .= "</tr>";
|
2023-06-02 05:35:10 +00:00
|
|
|
}
|
2023-06-13 07:14:37 +00:00
|
|
|
|
|
|
|
// Return the table markup
|
|
|
|
echo $tableMarkup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($cmd == "update") {
|
2023-06-14 09:44:04 +00:00
|
|
|
|
|
|
|
//ddump($_REQUEST);
|
|
|
|
|
|
|
|
$string = str_replace('\n', '}', $_REQUEST['string']);
|
|
|
|
|
|
|
|
|
2023-06-14 08:40:21 +00:00
|
|
|
$query = "UPDATE $tableName SET Key = ?, String = ? WHERE Key = ?";
|
2023-06-14 09:44:04 +00:00
|
|
|
PDO_Execute($query, [$_REQUEST['key'], $string, $_REQUEST['key']]);
|
2023-06-14 08:40:21 +00:00
|
|
|
|
|
|
|
// Update the corresponding row in the text file
|
|
|
|
$filePath = "{$_SESSION['tbl']}/$tableName.txt";
|
|
|
|
$fileLines = file($filePath);
|
|
|
|
|
|
|
|
// Calculate the line number to update based on the rowid
|
|
|
|
$lineNumber = $_REQUEST['rowid'];
|
|
|
|
|
|
|
|
// Update the line in the file with the new key and string values
|
2023-06-14 09:44:04 +00:00
|
|
|
$fileLines[$lineNumber - 1] = "{$_REQUEST['key']}\t{$string}\n";
|
2023-06-14 08:40:21 +00:00
|
|
|
|
|
|
|
// Save the updated content back to the text file
|
|
|
|
file_put_contents($filePath, implode("", array_filter($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");
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
// Trim empty lines from the end of the array
|
|
|
|
while (!empty($lines) && trim(end($lines)) === '') {
|
|
|
|
array_pop($lines);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the updated content back to the file
|
|
|
|
file_put_contents($filePath, implode(PHP_EOL, $lines));
|
2023-06-13 07:14:37 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 08:40:21 +00:00
|
|
|
|
2023-06-13 07:14:37 +00:00
|
|
|
if ($cmd == "delete") {
|
2023-06-14 08:40:21 +00:00
|
|
|
$query = "DELETE FROM $tableName WHERE Key = ?";
|
|
|
|
PDO_Execute($query, [$_REQUEST['key']]);
|
|
|
|
$rowid = $_REQUEST['rowid'];
|
|
|
|
$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);
|
|
|
|
|
|
|
|
// Remove the line at the specified line number
|
|
|
|
if (isset($fileLines[$lineNumber])) {
|
|
|
|
unset($fileLines[$lineNumber]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
|
|
|
|
|
2023-06-13 07:14:37 +00:00
|
|
|
echo $_REQUEST['rowid'] . " deleted";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($cmd == "add") {
|
|
|
|
$tableName = $_POST['tableName'];
|
|
|
|
$key = $_POST['Key'];
|
|
|
|
$string = $_POST['String'];
|
|
|
|
|
|
|
|
// Create your insert statement using the provided values
|
|
|
|
$query = "INSERT INTO $tableName (Key, String) VALUES (?, ?)";
|
|
|
|
$params = array($key, $string);
|
|
|
|
|
|
|
|
// Execute the insert statement
|
|
|
|
$result = PDO_Execute($query, $params);
|
2023-06-13 17:48:19 +00:00
|
|
|
|
2023-06-13 07:14:37 +00:00
|
|
|
// Retrieve the last inserted rowid from the table
|
|
|
|
$query = "SELECT last_insert_rowid() AS rowid";
|
|
|
|
$result = PDO_FetchOne($query);
|
2023-06-14 08:40:21 +00:00
|
|
|
|
|
|
|
// Append the new row to the text file
|
|
|
|
$newLine = "{$key}\t{$string}";
|
|
|
|
file_put_contents($filePath, $newLine . PHP_EOL, FILE_APPEND);
|
2023-06-14 03:15:23 +00:00
|
|
|
|
2023-06-13 07:14:37 +00:00
|
|
|
echo $result;
|
2023-06-14 08:40:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-13 07:14:37 +00:00
|
|
|
}
|