From 2eb6f5fe41b17cc97ad883b439e868edbb5d19a5 Mon Sep 17 00:00:00 2001 From: Jean-Marc Pigeon Date: Tue, 16 Dec 2025 10:37:11 -0500 Subject: [PATCH] Starting column select to idatabase probe code. --- www/coloration.js | 105 +++++++++++++++++++++++++----------------- www/coloration.js.org | 65 ++++++++++++++++++++++++++ www/gessql.php | 11 ++++- www/lvlmai.php | 27 ++++++++--- 4 files changed, 158 insertions(+), 50 deletions(-) create mode 100644 www/coloration.js.org diff --git a/www/coloration.js b/www/coloration.js index 1468c03..e286874 100644 --- a/www/coloration.js +++ b/www/coloration.js @@ -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=>`${m}`); - return `${val}`; - }); - 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 => `${m}`); + return `${val}`; + }); + 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 index 0000000..1468c03 --- /dev/null +++ b/www/coloration.js.org @@ -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=>`${m}`); + return `${val}`; + }); + tr.innerHTML=cells.join(""); + tbody.appendChild(tr); + } +} + +// Load initial +refresh(); diff --git a/www/gessql.php b/www/gessql.php index 7374b41..729724f 100644 --- a/www/gessql.php +++ b/www/gessql.php @@ -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}"; } diff --git a/www/lvlmai.php b/www/lvlmai.php index 1ec1c4a..2c80cfb 100644 --- a/www/lvlmai.php +++ b/www/lvlmai.php @@ -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 = << Search - @@ -97,7 +110,7 @@ $STR = << - @@ -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) { -- 2.47.3