From: Jean-Marc Pigeon Date: Tue, 16 Dec 2025 20:00:59 +0000 (-0500) Subject: lvlmai.php, json start to be connected to php. X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=7243cc280ffaf3779f2121ff9cbe8131e723027e;p=jmp%2Fmailleur lvlmai.php, json start to be connected to php. --- diff --git a/www/devsql.php b/www/devsql.php index 19aba76..b84501b 100644 --- a/www/devsql.php +++ b/www/devsql.php @@ -45,7 +45,8 @@ class devsql { } } - // Update a row/s in a Database Table + +// Update a row/s in a Database Table public function Update( ) { } diff --git a/www/gesdis.php b/www/gesdis.php index df27b48..93d0c84 100644 --- a/www/gesdis.php +++ b/www/gesdis.php @@ -188,6 +188,7 @@ $STR = << + diff --git a/www/gessql.php b/www/gessql.php index 729724f..017cc0f 100644 --- a/www/gessql.php +++ b/www/gessql.php @@ -9,7 +9,7 @@ include_once "subrou.php"; include_once "devsql.php"; class probe { - private devsql $db; // devsql database instance + protected $db; // devsql database instance private string $table; // table name private ?string $where = null; // WHERE conditions @@ -30,6 +30,10 @@ class probe { $this->offset = $offset; } + // protecting data format + public function quote($value) { + return $this->db->quote($value); + } /** * Add the release function **/ diff --git a/www/lvlmai.php b/www/lvlmai.php index 363d5cd..98cede3 100644 --- a/www/lvlmai.php +++ b/www/lvlmai.php @@ -97,7 +97,7 @@ $STR = << -
+ Search @@ -141,6 +141,7 @@ $offset=0; $dsearch=""; $selectedField = 'rcptto'; + if (isset($_POST['limit'])) $limit=intval($_POST['limit']); if (isset($_POST['offset'])) @@ -162,7 +163,7 @@ if (isset($_POST['dsearch'])) { $selectedField = 'rcptto'; // filtrage selon le champ choisi - $safeSearch = $this->db->quote('%' . $dsearch . '%'); + $safeSearch = $rqst->quote('%' . $dsearch . '%'); if ($selectedField === 'creation') { // pour la date, on peut filtrer par LIKE $rqst->where("$selectedField::text LIKE $safeSearch"); @@ -199,6 +200,16 @@ $actions=$rqst->order("creation desc") ->limit($limit) ->GET(); +if(isset($_POST['ajax']) && $_POST['ajax'] == 1) { + header('Content-Type: application/json'); + echo json_encode([ + 'rows' => $actions, + 'search' => $dsearch + ]); + exit; // très important pour ne pas générer le reste de la page + } + + $line=""; $count=$offset+1; foreach($actions as $action) { @@ -267,6 +278,7 @@ $top
$tblheader + + + $line +
Num @@ -291,7 +303,10 @@ $tblheader Subject
$tblfooter
diff --git a/www/selectajax.js b/www/selectajax.js new file mode 100644 index 0000000..fcfc7ef --- /dev/null +++ b/www/selectajax.js @@ -0,0 +1,63 @@ +/** + * selectajax.js + * + * Gère l'envoi POST AJAX pour la sélection de colonnes et la recherche, + * puis met à jour dynamiquement le tableau HTML dans lvlmai.php. + * + * Dépendances : aucun framework nécessaire (vanilla JS) + */ + +document.addEventListener('DOMContentLoaded', function(){ + + // Sélection du formulaire + const form = document.getElementById('searchForm'); + if(!form) return; // sécurité si formulaire non présent + + form.addEventListener('submit', function(e){ + e.preventDefault(); // empêche le rechargement de la page + + // Construction du FormData pour POST + const formData = new FormData(form); + + // Indiquer au backend qu'on veut du JSON + formData.set('ajax', '1'); + + // Envoi POST via fetch + fetch('lvlmai.php', { + method: 'POST', + body: formData + }) + .then(response => response.json()) + .then(data => { + const headerRow = document.getElementById('headerRow'); + const bodyRows = document.getElementById('bodyRows'); + + // Vider le tableau précédent + headerRow.innerHTML = ''; + bodyRows.innerHTML = ''; + + if(data.length === 0) return; + + // Générer les en-têtes dynamiques + Object.keys(data[0]).forEach(col => { + const th = document.createElement('th'); + th.textContent = col; + headerRow.appendChild(th); + }); + + // Générer les lignes + data.forEach(row => { + const tr = document.createElement('tr'); + Object.values(row).forEach(val => { + const td = document.createElement('td'); + td.textContent = val; + tr.appendChild(td); + }); + bodyRows.appendChild(tr); + }); + }) + .catch(err => console.error('Erreur AJAX:', err)); + }); + +}); +