mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2024-12-02 13:36:03 +00:00
98 lines
2.8 KiB
PHP
98 lines
2.8 KiB
PHP
<?php
|
|
|
|
session_start();
|
|
ob_start();
|
|
|
|
require_once './config.php';
|
|
require_once './_pdo.php';
|
|
|
|
require_once './src/D2Functions.php';
|
|
|
|
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();
|
|
}
|
|
|
|
|
|
$cmd = $_REQUEST['cmd'];
|
|
$tableName = $_REQUEST['tableName'];
|
|
|
|
if ($cmd == "getTable") {
|
|
$query = "SELECT ROWID,* FROM $tableName";
|
|
$rows = PDO_Execute($query);
|
|
|
|
// Start the table with Bootstrap classes
|
|
$tableMarkup = '';
|
|
|
|
// Iterate over the rows
|
|
foreach ($rows as $row) {
|
|
$string = str_replace('\n', " ", $row['String']);
|
|
|
|
$tableMarkup .= "<tr class='row-{$row['rowid']}'>";
|
|
|
|
$tableMarkup .= "<td>{$row['rowid']}</td>";
|
|
|
|
// Display the Key column as a text input with Bootstrap form-control class
|
|
$tableMarkup .= "<td><input type='text' value='{$row['Key']}' class='form-control'><span style='visibility: hidden;'>{$row['Key']}</span></td>";
|
|
|
|
// Display the String column as a textarea with Bootstrap form-control class
|
|
$tableMarkup .= "<td><textarea class='form-control'>{$string}</textarea></td>";
|
|
|
|
// Add the Update and Delete links within a single td element
|
|
$tableMarkup .= "<td><div>";
|
|
|
|
// Add the Update link with Bootstrap btn and btn-primary classes
|
|
$tableMarkup .= "<a href='#' class='update-link btn btn-primary' data-rowid='{$row['rowid']}'>Update</a>";
|
|
|
|
// Add the Delete link with Bootstrap btn and btn-danger classes
|
|
$tableMarkup .= "<a style='float:right' href='#' class='delete-link btn btn-danger' data-rowid='{$row['rowid']}'>Delete</a>";
|
|
|
|
$tableMarkup .= "</div></td>";
|
|
|
|
$tableMarkup .= "</tr>";
|
|
}
|
|
|
|
// Return the table markup
|
|
echo $tableMarkup;
|
|
}
|
|
|
|
|
|
if ($cmd == "update") {
|
|
$query = "UPDATE $tableName SET Key = ?, String = ? WHERE ROWID = ?";
|
|
PDO_Execute($query, [$_REQUEST['key'], $_REQUEST['string'], $_REQUEST['rowid']]);
|
|
|
|
echo $_REQUEST['key'] . " updated";
|
|
}
|
|
|
|
if ($cmd == "delete") {
|
|
$query = "DELETE FROM $tableName WHERE ROWID = ?";
|
|
PDO_Execute($query, [$_REQUEST['rowid']]);
|
|
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);
|
|
|
|
// Retrieve the last inserted rowid from the table
|
|
$query = "SELECT last_insert_rowid() AS rowid";
|
|
$result = PDO_FetchOne($query);
|
|
|
|
echo $result;
|
|
}
|