]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Mise en reserve de gestbl.
authorJean-Marc Pigeon <jmp@safe.c>
Thu, 11 Dec 2025 14:50:06 +0000 (09:50 -0500)
committerJean-Marc Pigeon <jmp@safe.c>
Thu, 11 Dec 2025 14:50:06 +0000 (09:50 -0500)
www/gestbl.php [deleted file]
www/lvlmai.php
www/res/gestbl.php [new file with mode: 0644]

diff --git a/www/gestbl.php b/www/gestbl.php
deleted file mode 100644 (file)
index 06391b1..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-/* =======================================================
-   TableFilter.php -->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);
-    }
-}
-
index 36560e95db1451ba5e9e832a600450afb4f64c74..5c079dfef5d1694d9637c92acdb7f60f80a511fb 100644 (file)
@@ -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
 <TR>
 <TH align=center>Num</TH>
 <TH align=center>Status</TH>
-<TH align=center>$date</TH>
+<TH align=center>$hdate</TH>
 <TH align=center>IP</TH>
 <TH align=center>Reverse Address</TH>
-<TH align=center>$originator</TH>
-<TH align=center>$recipient</TH>
+<TH align=center>$horiginator</TH>
+<TH align=center>$hrecipient</TH>
 <TH align=center>Subject</TH>
 </TR>
 $line
diff --git a/www/res/gestbl.php b/www/res/gestbl.php
new file mode 100644 (file)
index 0000000..d64cf41
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+/* =======================================================
+   TableFilter.php -->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);
+  }
+}
+