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

View File

@ -264,10 +264,14 @@ class DataBase {
* *
* @return array An array of objects representing the records in the "soshot" table. * @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) {
$stmt = $this->db->prepare("SELECT * FROM soshot ORDER BY created DESC limit :start, :end;"); 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)); $stmt->execute(array(':start' => $start, ':end' => $end));
$result = $stmt->fetchAll(PDO::FETCH_OBJ); $result = $stmt->fetchAll(PDO::FETCH_OBJ);
return $result; return $result;
} }
} }

View File

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