Close #467 : Add search in backend

This commit is contained in:
Knah Tsaeb 2024-03-19 15:26:10 +01:00
parent 1571c30c38
commit 8002d0fd35
3 changed files with 26 additions and 7 deletions

View file

@ -22,6 +22,7 @@ class Backend {
private $conf;
private $title = 'Settings';
private $passwordRequired = false;
private $search = null;
/**
* Handles the index action for the controller.
@ -107,6 +108,15 @@ class Backend {
* @return void
*/
private function showInfos() {
if (!empty($this->params->search)) {
$search = htmlspecialchars(trim($this->params->search));
if (!empty($search)) {
$this->search = $search;
} else {
$this->search = null;
}
}
if (!empty($this->params->start)) {
$this->start = $this->params->start;
}
@ -116,7 +126,7 @@ class Backend {
}
$conx = new DataBase();
$genList = $conx->getList($this->start, $this->end);
$genList = $conx->getList($this->start, $this->end, $this->search);
$total = $conx->getTotal();
$inError = $conx->getInError();
$inQueue = $this->getInQueue();
@ -124,6 +134,7 @@ class Backend {
$max = $this->max;
$next = $start + $max;
$previous = $start - ($max);
$search = $this->search;
if (count($genList) < $this->max) {
$next = $start;

View file

@ -264,8 +264,12 @@ class DataBase {
*
* @return array An array of objects representing the records in the "soshot" table.
*/
public function getList(int $start, int $end) {
public function getList(int $start, int $end, string $search = null) {
if ($search != null) {
$stmt = $this->db->prepare("SELECT * FROM soshot WHERE url like '%$search%' ORDER BY created DESC limit :start, :end;");
} else {
$stmt = $this->db->prepare("SELECT * FROM soshot ORDER BY created DESC limit :start, :end;");
}
$stmt->execute(array(':start' => $start, ':end' => $end));
$result = $stmt->fetchAll(PDO::FETCH_OBJ);
return $result;

View file

@ -3,7 +3,6 @@
use App\Utils\ConvertStatus;
use App\Utils\Domains;
//require_once 'nav.php';
?>
<div class="w3-row soshot-main w3-margin-bottom">
<div class="w3-container">
@ -15,6 +14,11 @@ use App\Utils\Domains;
<li>Error : <?= $inError; ?></li>
</ul>
<form>
<input type="text" name="search" value="<?= $search ;?>">
<input type="submit" value="Rechercher">
</form>
<table class="w3-table-all w3-hoverable">
<thead>
<tr>
@ -50,8 +54,8 @@ use App\Utils\Domains;
<div class="w3-center w3-margin-top">
<div class="w3-bar">
<a href="?page=infos&start=<?= $previous; ?>" class="w3-teal w3-button">&laquo; Previous</a>
<a href="?page=infos&start=<?= $next; ?>" class="w3-teal w3-button">Next &raquo; </a>
<a href="?page=infos&start=<?= $previous; ?>&search=<?= $search ;?>" class="w3-teal w3-button">&laquo; Previous</a>
<a href="?page=infos&start=<?= $next; ?>&search=<?= $search ;?>" class="w3-teal w3-button">Next &raquo; </a>
</div>
</div>
</div>