From 3357f757ea1eb30e8c484f4b28f97b1b248dd6cd Mon Sep 17 00:00:00 2001 From: Hash Borgir Date: Thu, 1 Jun 2023 23:35:10 -0600 Subject: [PATCH] Started a new TBL editor --- TblEditor.php | 61 ++++++++++++++++++ TblEditorGUI.php | 165 +++++++++++++++++++++++++++++++++++++++++++++++ src/D2Crud.php | 83 ++++++++++++++++++++++++ 3 files changed, 309 insertions(+) create mode 100644 TblEditor.php create mode 100644 TblEditorGUI.php create mode 100644 src/D2Crud.php diff --git a/TblEditor.php b/TblEditor.php new file mode 100644 index 0000000..bb695cc --- /dev/null +++ b/TblEditor.php @@ -0,0 +1,61 @@ +getMessage(); +} + +$tbl = $_SESSION['tbl']; +$tableNames = []; +foreach (glob($tbl . "*.tbl") as $filename) { + $tableInfo = pathinfo($filename); + $tableNames[] = $tableInfo['filename']; +} + +$tableNames = ['patchstring']; + +// Create an associative array to store rows for each table +$tableRows = []; + +// Iterate over the table names +foreach ($tableNames as $tableName) { + $crud = new CRUD($tableName); + $tableRows[$tableName] = $crud->readAll(); +} +?> + + + + + + + + + Editable Tables + + +
+

Editable Tables

+ +
+ + +
+
+
+
+ + +
+
+ +
+
+ +
+
+
+
+ + + + + + + + + + + $row){ ?> + + + + + + + + +
IDKeyStringActions
+ + + + +
+
+
+ + +
+
+ + + + + \ No newline at end of file diff --git a/src/D2Crud.php b/src/D2Crud.php new file mode 100644 index 0000000..7a4dfdc --- /dev/null +++ b/src/D2Crud.php @@ -0,0 +1,83 @@ +table = $table; + } + + /** + * Insert a new row into the table + * + * @param array $data Associative array of column names and values + * @return bool True on success, false on failure + */ + public function create($data) { + $keys = implode(', ', array_keys($data)); + $values = implode(', ', array_fill(0, count($data), '?')); + + $query = "INSERT INTO {$this->table} ($keys) VALUES ($values)"; + $params = array_values($data); + + return PDO_Execute($query, $params); + } + + /** + * Retrieve a row by its ROWID + * + * @param int $rowid The ROWID of the row to retrieve + * @return mixed|null The row as an associative array, or null if not found + */ + public function read($rowid) { + $query = "SELECT * FROM {$this->table} WHERE ROWID = ?"; + $params = [$rowid]; + + return PDO_FetchRow($query, $params); + } + + /** + * Retrieve all rows from the table + * + * @return array An array of rows, each represented as an associative array + */ + public function readAll() { + $query = "SELECT ROWID,* FROM {$this->table}"; + return PDO_FetchAll($query); + } + + /** + * Update a row by its ROWID + * + * @param int $rowid The ROWID of the row to update + * @param array $data Associative array of column names and new values + * @return bool True on success, false on failure + */ + public function update($rowid, $data) { + $setStatements = []; + $params = [$rowid]; + + foreach ($data as $key => $value) { + $setStatements[] = "$key = ?"; + $params[] = $value; + } + + $setClause = implode(', ', $setStatements); + $query = "UPDATE {$this->table} SET $setClause WHERE ROWID = ?"; + + return PDO_Execute($query, $params); + } + + /** + * Delete a row by its ROWID + * + * @param int $rowid The ROWID of the row to delete + * @return bool True on success, false on failure + */ + public function delete($rowid) { + $query = "DELETE FROM {$this->table} WHERE ROWID = ?"; + $params = [$rowid]; + + return PDO_Execute($query, $params); + } +}