]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Starting column select to idatabase probe code.
authorJean-Marc Pigeon <jmp@safe.c>
Tue, 16 Dec 2025 15:37:11 +0000 (10:37 -0500)
committerJean-Marc Pigeon <jmp@safe.c>
Tue, 16 Dec 2025 15:37:11 +0000 (10:37 -0500)
www/coloration.js
www/coloration.js.org [new file with mode: 0644]
www/gessql.php
www/lvlmai.php

index 1468c03afbb8d9f86f59b1d6320a4f3afe97c86f..e286874f80227bddf79ed5609594380db1e06fe3 100644 (file)
@@ -1,65 +1,84 @@
 // vim: smarttab tabstop=8 shiftwidth=2 expandtab
 // to change columne header colors
 //
-let columns=[];
-let currentSearch="";
+let columns = [];
+let currentSearch = "";
 
+// Récupération des éléments
 const searchInput = document.getElementById("searchInput");
 const limitSelect = document.getElementById("limitSelect");
 
 // Header click pour multi-colonnes
-document.querySelectorAll(".filter-col").forEach(th=>{
-  th.addEventListener("click",()=>{
-  const col = th.getAttribute("trkey");
-  if (columns.includes(col)){
-    columns = columns.filter(c=>c!==col);
-    th.classList.remove("active");
-    }
-  else {
-    columns.push(col);
-    th.classList.add("active");
-    }
-  refresh();
-  });
+document.querySelectorAll(".filter-col").forEach(th => {
+    th.addEventListener("click", () => {
+        const col = th.getAttribute("trkey");
+        if (columns.includes(col)) {
+            columns = columns.filter(c => c !== col);
+            th.classList.remove("active");
+        } else {
+            columns.push(col);
+            th.classList.add("active");
+        }
+        refresh();
+    });
 });
 
 // Recherche et changement de limit
-searchInput.addEventListener("input",refresh);
-limitSelect.addEventListener("change",refresh);
+if (searchInput) {
+    searchInput.addEventListener("input", refresh);
+}
+if (limitSelect) {
+    limitSelect.addEventListener("change", refresh);
+}
 
 // AJAX vers le même fichier
-function refresh(){
-currentSearch = searchInput.value.trim();
-const form = new FormData();
-form.append("search", currentSearch);
-form.append("limit", limitSelect.value);
+function refresh() {
+    const form = new FormData();
+
+    currentSearch = searchInput ? searchInput.value.trim() : "";
+    form.append("search", currentSearch);
+
+    const limitValue = limitSelect ? limitSelect.value : 0;
+    form.append("limit", limitValue);
 
-const activeColumns = columns.length ? columns : ["remoteip","reverse","creation"];
-activeColumns.forEach(c=>form.append("columns[]",c));
+    const activeColumns = columns.length ? columns : ["remoteip", "reverse", "creation"];
+    activeColumns.forEach(c => form.append("columns[]", c));
+
+    fetch("", { method: "POST", body: form })
+    .then(r => r.text())    // <- récupère le texte brut
+    .then(text => { 
+        console.log("Server response:", text); 
+        try {
+            const json = JSON.parse(text);
+            renderTable(json.rows, json.search);
+        } catch(e) {
+            console.error("JSON parse error:", e);
+        }
+    });
 
-fetch("", {method:"POST", body:form})
-     .then(r=>r.json())
-     .then(json=>renderTable(json.rows,json.search));
 }
 
 // Remplissage tableau avec surbrillance
-function renderTable(rows,search){
-console.log("AJAX: nombre de lignes reçues =", rows.length);
-const tbody=document.querySelector("#dataTable tbody");
-tbody.innerHTML="";
-const re = search ? new RegExp(search,"gi") : null;
-for(const row of rows){
-  const tr=document.createElement("tr");
-  const cells = ["remoteip","reverse","creation"].map(c=>{
-   // NULL -> "NULL"
-    let val = row[c] === null ? "NULL" : row[c];
-    if(re) val = val.replace(re,m=>`<span class="highlight">${m}</span>`);
-      return `<td>${val}</td>`;
-    });
-  tr.innerHTML=cells.join("");
-  tbody.appendChild(tr);
-  }
+function renderTable(rows, search) {
+    console.log("AJAX: nombre de lignes reçues =", rows.length);
+    const tbody = document.querySelector("#dataTable tbody");
+    if (!tbody) return;
+
+    tbody.innerHTML = "";
+    const re = search ? new RegExp(search, "gi") : null;
+
+    for (const row of rows) {
+        const tr = document.createElement("tr");
+        const cells = ["remoteip", "reverse", "creation"].map(c => {
+            let val = row[c] === null ? "NULL" : row[c];
+            if (re) val = val.replace(re, m => `<span class="highlight">${m}</span>`);
+            return `<td>${val}</td>`;
+        });
+        tr.innerHTML = cells.join("");
+        tbody.appendChild(tr);
+    }
 }
 
 // Load initial
 refresh();
+
diff --git a/www/coloration.js.org b/www/coloration.js.org
new file mode 100644 (file)
index 0000000..1468c03
--- /dev/null
@@ -0,0 +1,65 @@
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+// to change columne header colors
+//
+let columns=[];
+let currentSearch="";
+
+const searchInput = document.getElementById("searchInput");
+const limitSelect = document.getElementById("limitSelect");
+
+// Header click pour multi-colonnes
+document.querySelectorAll(".filter-col").forEach(th=>{
+  th.addEventListener("click",()=>{
+  const col = th.getAttribute("trkey");
+  if (columns.includes(col)){
+    columns = columns.filter(c=>c!==col);
+    th.classList.remove("active");
+    }
+  else {
+    columns.push(col);
+    th.classList.add("active");
+    }
+  refresh();
+  });
+});
+
+// Recherche et changement de limit
+searchInput.addEventListener("input",refresh);
+limitSelect.addEventListener("change",refresh);
+
+// AJAX vers le même fichier
+function refresh(){
+currentSearch = searchInput.value.trim();
+const form = new FormData();
+form.append("search", currentSearch);
+form.append("limit", limitSelect.value);
+
+const activeColumns = columns.length ? columns : ["remoteip","reverse","creation"];
+activeColumns.forEach(c=>form.append("columns[]",c));
+
+fetch("", {method:"POST", body:form})
+     .then(r=>r.json())
+     .then(json=>renderTable(json.rows,json.search));
+}
+
+// Remplissage tableau avec surbrillance
+function renderTable(rows,search){
+console.log("AJAX: nombre de lignes reçues =", rows.length);
+const tbody=document.querySelector("#dataTable tbody");
+tbody.innerHTML="";
+const re = search ? new RegExp(search,"gi") : null;
+for(const row of rows){
+  const tr=document.createElement("tr");
+  const cells = ["remoteip","reverse","creation"].map(c=>{
+   // NULL -> "NULL"
+    let val = row[c] === null ? "NULL" : row[c];
+    if(re) val = val.replace(re,m=>`<span class="highlight">${m}</span>`);
+      return `<td>${val}</td>`;
+    });
+  tr.innerHTML=cells.join("");
+  tbody.appendChild(tr);
+  }
+}
+
+// Load initial
+refresh();
index 7374b4174094d90cfc5581ceeaf009fe6ae0e5df..729724f71ae3c7f1a08faa28892b9ea39a49e28d 100644 (file)
@@ -17,6 +17,7 @@ class probe       {
     private ?string $order = null;      // ORDER BY clause
     private ?int $limit = null;         // LIMIT for pagination
     private int $offset = 0;            // OFFSET for pagination, internal only
+    private ?string $columns = null;    // request specific colunn(s)
     private string $OPEP="gessql.php:class_probe";
 
     /**
@@ -65,12 +66,20 @@ class probe       {
       return $this;
       }
 
+    /**
+     * Set Column selection
+     **/
+    public function columns(array $cols): self {
+      $this->columns = implode(', ', $cols);
+      return $this;
+      }
+
     /**
      * Execute the query and return results
      */
     public function get(): array {
 
-     $sql = "SELECT * FROM {$this->table}";
+     $sql = "SELECT " . ($this->columns ?? "*") . " FROM {$this->table}";
      if ($this->where) {
        $sql .= " WHERE {$this->where}";
        }
index 1ec1c4a1823dc5f03c6e3b90456cb03f67039ecb..2c80cfb3c0c203f214842e8bab9a9c64392c3354 100644 (file)
@@ -6,6 +6,22 @@
 //
 //==============================================================
 
+/* ============================================================
+ * AJAX MODE (JSON only)
+ * ============================================================ */
+if (isset($_POST['columns'])) {
+
+    // (temporaire, pour test)
+    header('Content-Type: application/json; charset=utf-8');
+
+    echo json_encode([
+        'rows'   => [],   // on remplira plus tard
+        'search' => $_POST['search'] ?? ''
+    ]);
+
+    exit; // <<< CRITIQUE
+}
+
 include_once "subrou.php";
 include_once "unienv.php";
 include_once "gesdis.php";
@@ -85,9 +101,6 @@ $STR  = <<<EOT
 <FONT SIZE=+1>
     <span class="translatable" trkey="Search">Search</span>
     <input type="text" id="searchInput" value="{$dsearchHtml}" name="dsearch" size=20 style="font-size: 100%;">
-    <select name="filterfield" style="font-size:100%;">
-        $optionsHtml
-    </select>
     <input type="submit" style="display:none"/>
 </FONT>
 </FORM>
@@ -97,7 +110,7 @@ $STR  = <<<EOT
 <input type="hidden" name="dsearch" value="$dsearch"/>
 <input type="hidden" name="offset" value="$offset"/>
 <input type="hidden" name="limit" value="$limit"/>
-<select name="limit" style="font-size: 130%;" onchange='if (this.value!=0) {this.form.submit();}'>
+<select id="limitSelect" name="limit" style="font-size: 130%;" onchange='if (this.value!=0) {this.form.submit();}'>
 <option selected="selected">$limit</option>
 <option value=20>20</option>
 <option value=40>40</option>
@@ -132,11 +145,13 @@ if (isset($_POST['limit']))
   $limit=intval($_POST['limit']);
 if (isset($_POST['offset']))
   $offset=intval($_POST['offset']);
-if (isset($_POST['filterfield']))
-  $selectedField = $_POST['filterfield'];
 
 $rqst = new probe("actions",$limit,$offset);
 
+if (isset($_POST['columns'])) {   //selected database columns name
+  $cols=intval($_POST['columns']);
+  $rqst->columns($cols);
+  }
 if (isset($_POST['dsearch'])) {
   $dsearch=trim($_POST['dsearch']);
   if (strlen($dsearch)>0) {