From 24bc73c3add4b784c18ddc76c8380f0d945d4180 Mon Sep 17 00:00:00 2001 From: Knah Tsaeb Date: Fri, 22 Mar 2024 13:48:19 +0100 Subject: [PATCH] Close #468 : Add remove option in backend --- app/Controllers/Backend.php | 8 ++++++++ app/DataBase/DataBase.php | 34 +++++++++++++++++++++++++++++++++- app/Utils/DeleteGen.php | 18 ++++++++++++++++++ app/Utils/ShowImg.php | 2 +- public/index.php | 2 +- tpl/infos.php | 11 +++++++++-- 6 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 app/Utils/DeleteGen.php diff --git a/app/Controllers/Backend.php b/app/Controllers/Backend.php index 72debde..87612bd 100644 --- a/app/Controllers/Backend.php +++ b/app/Controllers/Backend.php @@ -7,6 +7,7 @@ if (session_status() === PHP_SESSION_NONE) { } use App\DataBase\DataBase; +use App\Utils\DeleteGen; use App\Utils\Page; use App\Utils\ShowImg; use Noodlehaus\Config; @@ -66,6 +67,13 @@ class Backend { exit(); } + if (!empty($params->deleteGen)) { + $deleteGen = new DeleteGen(); + $deleteGen->deleteGen($params->deleteGen); + $reset = new DataBase(); + $reset->reset($params->deleteGen); + } + $this->conf = $conf; $this->params = $params; diff --git a/app/DataBase/DataBase.php b/app/DataBase/DataBase.php index a125420..5543808 100644 --- a/app/DataBase/DataBase.php +++ b/app/DataBase/DataBase.php @@ -192,6 +192,38 @@ class DataBase { ]); } + /** + * Reset . + * + * This method prepares an SQL UPDATE statement using the provided parameters, and + * executes it to update a record in the "soshot" table in the database. + * + * @param string $update The value to update in the type column of the record. + * + * @return void + */ + public function reset(string $id) { + + $resetParam = []; + + $updateParams = $this->params; + unset($updateParams['id'], $updateParams['url'], $updateParams['created']); + + foreach ($updateParams as $key => $value) { + $resetParam[] = $key . ' = null'; + } + + $strUpdateParam = implode(',', $resetParam); + + $stmt = $this->db->prepare("UPDATE soshot + SET $strUpdateParam + WHERE id=:id;"); + + $result = $stmt->execute([ + ':id' => $id + ]); + } + /** * Checks if a record with the given ID exists in the database. * @@ -274,4 +306,4 @@ class DataBase { $result = $stmt->fetchAll(PDO::FETCH_OBJ); return $result; } -} \ No newline at end of file +} diff --git a/app/Utils/DeleteGen.php b/app/Utils/DeleteGen.php new file mode 100644 index 0000000..1d880cf --- /dev/null +++ b/app/Utils/DeleteGen.php @@ -0,0 +1,18 @@ +addRoute(['/', '/index.php', '/index'], 'App\Controllers\Home', 'GET'); $router->addRoute('/api', 'App\Controllers\Result', 'GET'); $router->addRoute('/hmac', 'App\Controllers\GenHmac', 'GET'); -//$router->addRoute('/debug', 'App\Bin\ThumbShoter', 'GET'); +$router->addRoute('/debug', 'App\Bin\ThumbShoter', 'GET'); $router->addRoute('/backend', 'App\Controllers\Backend', 'GET'); $router->addRoute('/logout', 'App\Controllers\Logout', 'GET'); diff --git a/tpl/infos.php b/tpl/infos.php index 5f9ba64..baa1dce 100644 --- a/tpl/infos.php +++ b/tpl/infos.php @@ -37,7 +37,14 @@ use App\Utils\Domains; - url); ?> + + + url); ?> + + + + + created; ?> complete); ?> full); ?> @@ -67,7 +74,7 @@ use App\Utils\Domains;
- × + ×