Close #468 : Add remove option in backend

This commit is contained in:
Knah Tsaeb 2024-03-22 13:48:19 +01:00
parent 4d7c3dbbc5
commit 24bc73c3ad
6 changed files with 70 additions and 5 deletions

View file

@ -7,6 +7,7 @@ if (session_status() === PHP_SESSION_NONE) {
} }
use App\DataBase\DataBase; use App\DataBase\DataBase;
use App\Utils\DeleteGen;
use App\Utils\Page; use App\Utils\Page;
use App\Utils\ShowImg; use App\Utils\ShowImg;
use Noodlehaus\Config; use Noodlehaus\Config;
@ -66,6 +67,13 @@ class Backend {
exit(); exit();
} }
if (!empty($params->deleteGen)) {
$deleteGen = new DeleteGen();
$deleteGen->deleteGen($params->deleteGen);
$reset = new DataBase();
$reset->reset($params->deleteGen);
}
$this->conf = $conf; $this->conf = $conf;
$this->params = $params; $this->params = $params;

View file

@ -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. * Checks if a record with the given ID exists in the database.
* *

18
app/Utils/DeleteGen.php Normal file
View file

@ -0,0 +1,18 @@
<?php
namespace App\Utils;
class DeleteGen {
function deleteGen(string $hashFile) {
$dir = __DIR__ . '/../../cache/img/' . substr($hashFile, 0, 4) . '/';
if (is_dir($dir)) {
$listFile = glob($dir . '*');
foreach ($listFile as $file) {
if (is_file($file)) {
unlink($file);
}
}
}
}
}

View file

@ -17,7 +17,7 @@ class ShowImg {
echo file_get_contents($img); echo file_get_contents($img);
} else { } else {
// todo not gen // todo not gen
echo file_get_contents(__DIR__ . '/../../src/images/error_thumb.png'); echo file_get_contents(__DIR__ . '/../../src/images/hd_generation_in_progress.jpg');
} }
exit(); exit();
} }

View file

@ -36,7 +36,7 @@ $router = new Router();
$router->addRoute(['/', '/index.php', '/index'], 'App\Controllers\Home', 'GET'); $router->addRoute(['/', '/index.php', '/index'], 'App\Controllers\Home', 'GET');
$router->addRoute('/api', 'App\Controllers\Result', 'GET'); $router->addRoute('/api', 'App\Controllers\Result', 'GET');
$router->addRoute('/hmac', 'App\Controllers\GenHmac', '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('/backend', 'App\Controllers\Backend', 'GET');
$router->addRoute('/logout', 'App\Controllers\Logout', 'GET'); $router->addRoute('/logout', 'App\Controllers\Logout', 'GET');

View file

@ -37,7 +37,14 @@ use App\Utils\Domains;
<tbody> <tbody>
<?php foreach ($genList as $value) : ?> <?php foreach ($genList as $value) : ?>
<tr> <tr>
<td><a href="#" class="linkDetail" data-hmac="<?= $value->id; ?>" data-href="<?= $value->url; ?>"><?= Domains::getDomain($value->url); ?></a></td> <td>
<span class="w3-left ">
<a href="#" class="linkDetail" data-hmac="<?= $value->id; ?>" data-href="<?= $value->url; ?>"><?= Domains::getDomain($value->url); ?></a>
</span>
<span class="w3-right" style="width:40px">
<a href="?page=infos&deleteGen=<?= $value->id; ?>"><i class="fa fa-trash-o w3-text-red" aria-hidden="true"></i></a>
</span>
</td>
<td><?= $value->created; ?></td> <td><?= $value->created; ?></td>
<td><?= ConvertStatus::convertToIcon($value->complete); ?></td> <td><?= ConvertStatus::convertToIcon($value->complete); ?></td>
<td><?= ConvertStatus::convertToIcon($value->full); ?></td> <td><?= ConvertStatus::convertToIcon($value->full); ?></td>
@ -67,7 +74,7 @@ use App\Utils\Domains;
<div id="detail" class="w3-modal"> <div id="detail" class="w3-modal">
<div class="w3-modal-content w3-animate-opacity"> <div class="w3-modal-content w3-animate-opacity">
<div class="w3-container"> <div class="w3-container">
<span onclick="document.getElementById('detail').style.display='none'" class="w3-button w3-display-topright">&times;</span> <span onclick="document.getElementById('detail').style.display='none'" class="w3-button w3-display-topright w3-xxlarge">&times;</span>
<p> <p>
<img src="" id="fav" height="32px"> <img src="" id="fav" height="32px">
<a href="" id="titlePreview" target="_blanck"></a> <a href="" id="titlePreview" target="_blanck"></a>