// 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();
+
--- /dev/null
+// 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();
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";
/**
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}";
}
//
//==============================================================
+/* ============================================================
+ * 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";
<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>
<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>
$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) {