From: Jean-Marc Pigeon Date: Thu, 11 Dec 2025 14:50:06 +0000 (-0500) Subject: Mise en reserve de gestbl. X-Git-Tag: tag-0.19~11 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=a08488e4469901d9bbb03e09ddd88ec3a8eecf7a;p=jmp%2Fmailleur Mise en reserve de gestbl. --- diff --git a/www/gestbl.php b/www/gestbl.php deleted file mode 100644 index 06391b1..0000000 --- a/www/gestbl.php +++ /dev/null @@ -1,73 +0,0 @@ -gestbl.php - Generic and autonomous class for Mailleur - ======================================================= */ -class TableFilter -{ - private PDO $pdo; - private string $table; - private array $columns; - - /** - * Constructor - * @param PDO $pdo PDO connection - * @param string $table Table name - * @param array $columns Columns available for filtering - */ - public function __construct(PDO $pdo, string $table, array $columns) - { - $this->pdo = $pdo; - $this->table = $table; - $this->columns = $columns; - } - - /** - * Fetch filtered rows from the table - * - * @param array $selectedColumns Columns to filter (subset of $this->columns) - * @param string $search Search text - * @param int $limit Number of rows to return - * @return array Associative array of rows - */ - public function fetchFiltered(array $selectedColumns, string $search = '', int $limit = 20): array - { - // If no columns selected, use all - if (empty($selectedColumns)) $selectedColumns = $this->columns; - - // If search is empty, just SELECT with LIMIT - if (trim($search) === '') { - $sql = "SELECT * FROM {$this->table} ORDER BY 1 LIMIT :limit"; - $stmt = $this->pdo->prepare($sql); - $stmt->bindValue(':limit', $limit, PDO::PARAM_INT); - $stmt->execute(); - return $stmt->fetchAll(PDO::FETCH_ASSOC); - } - - // Build WHERE clause for multiple columns - $whereParts = []; - $params = []; - foreach ($selectedColumns as $i => $col) { - if (!in_array($col, $this->columns, true)) continue; - $key = ":s$i"; - $whereParts[] = "$col ILIKE $key"; - $params[$key] = "%$search%"; - } - $where = implode(" OR ", $whereParts); - - // Prepare and execute statement - $sql = "SELECT * FROM {$this->table} WHERE $where ORDER BY 1 LIMIT :limit"; - $stmt = $this->pdo->prepare($sql); - - foreach ($params as $k => $v) { - $stmt->bindValue($k, $v, PDO::PARAM_STR); - } - $stmt->bindValue(':limit', $limit, PDO::PARAM_INT); - - $stmt->execute(); - - // Return associative array - return $stmt->fetchAll(PDO::FETCH_ASSOC); - } -} - diff --git a/www/lvlmai.php b/www/lvlmai.php index 36560e9..5c079df 100644 --- a/www/lvlmai.php +++ b/www/lvlmai.php @@ -106,14 +106,14 @@ global $userlang; global $isadmin; global $myfilename; -$originator=gettranslate($userlang,"Originator"); -$recipient=gettranslate($userlang,"Recipient"); -$date=gettranslate($userlang,"Date"); +$horiginator=gettranslate($userlang,"Originator"); +$hrecipient=gettranslate($userlang,"Recipient"); +$hdate=gettranslate($userlang,"Date"); $limit=20; $offset=0; $dsearch=""; -$selectedField = $recipient; +$selectedField = $hrecipient; if (isset($_POST['limit'])) $limit=intval($_POST['limit']); @@ -128,7 +128,7 @@ if (isset($_POST['dsearch'])) { $dsearch=trim($_POST['dsearch']); if (strlen($dsearch)>0) { // sécuriser le champ sélectionné - $allowedFields = [$originator,$recipient,$date]; + $allowedFields = [$horiginator,$hrecipient,$hdate]; if (!in_array($selectedField,$allowedFields)) $selectedField = 'rcptto'; @@ -238,11 +238,11 @@ $tblheader Num Status -$date +$hdate IP Reverse Address -$originator -$recipient +$horiginator +$hrecipient Subject $line diff --git a/www/res/gestbl.php b/www/res/gestbl.php new file mode 100644 index 0000000..d64cf41 --- /dev/null +++ b/www/res/gestbl.php @@ -0,0 +1,75 @@ +gestbl.php + Generic and autonomous class to search an filter table + contents. + ======================================================= */ + +class TableFilter { + +private PDO $pdo; +private string $table; +private array $columns; +private int $limit; + +/** + * Constructor + * @param PDO $pdo PDO connection + * @param string $table Table name + * @param array $columns Columns available for filtering + **/ +public function __construct(PDO $pdo, string $table, array $columns) { + $this->pdo=$pdo; + $this->table=$table; + $this->columns=$columns; + $this->limit=20; + } + +/** + * Set LIMIT for extraction and filtering + **/ + +/** + * Fetch filtered rows from the table + * + * @param array $selectedColumns Columns to filter (subset of $this->columns) + * @param string $search Search text + * @param int $limit Number of rows to return + * @return array Associative array of rows + **/ +public function fetchFiltered(array $selectedColumns,string $search=''): array { + // If no columns selected, use all + if (empty($selectedColumns)) $selectedColumns = $this->columns; + + // If search is empty, just SELECT with LIMIT + if (trim($search) === '') { + $sql = "SELECT * FROM {$this->table} ORDER BY 1 LIMIT :limit"; + $stmt = $this->pdo->prepare($sql); + $stmt->bindValue(':limit', $this->limit, PDO::PARAM_INT); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } + + // Build WHERE clause for multiple columns + $whereParts = []; + $params = []; + foreach ($selectedColumns as $i => $col) { + if (!in_array($col, $this->columns, true)) continue; + $key = ":s$i"; + $whereParts[] = "$col ILIKE $key"; + $params[$key] = "%$search%"; + } + $where = implode(" OR ", $whereParts); + // Prepare and execute statement + $sql = "SELECT * FROM {$this->table} WHERE $where ORDER BY 1 LIMIT :limit"; + $stmt = $this->pdo->prepare($sql); + foreach ($params as $k => $v) { + $stmt->bindValue($k, $v, PDO::PARAM_STR); + } + $stmt->bindValue(':limit', $this->limit, PDO::PARAM_INT); + $stmt->execute(); + // Return associative array + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } +} +