MSIN-4464 — Refactor audit event selection in admin interface. Update SQL query to improve sorting logic for events and enhance the event selection form with a live search feature. Adjust layout and add direct input for event IDs, improving usability and accessibility for users managing audit logs.

This commit is contained in:
2026-07-15 13:06:05 -04:00
parent c8aa6394f5
commit ffb679626e
2 changed files with 59 additions and 10 deletions

View File

@ -405,13 +405,15 @@ function fxFicheAuditAdminListEvents()
return array();
}
// Pas de LIMIT : le select admin a une recherche (bootstrap-select).
$sql = 'SELECT e.eve_id, e.eve_nom_fr, e.eve_date_debut,'
. ' (SELECT COUNT(*) FROM inscriptions_fiche_audit_log l WHERE l.eve_id = e.eve_id) AS fal_nb'
. ' FROM inscriptions_evenements e'
. ' WHERE e.eve_actif = 1'
. ' OR EXISTS (SELECT 1 FROM inscriptions_fiche_audit_log l2 WHERE l2.eve_id = e.eve_id)'
. ' ORDER BY e.eve_date_debut DESC, e.eve_id DESC'
. ' LIMIT 300';
. ' ORDER BY'
. ' CASE WHEN EXISTS (SELECT 1 FROM inscriptions_fiche_audit_log lx WHERE lx.eve_id = e.eve_id) THEN 0 ELSE 1 END,'
. ' e.eve_date_debut DESC, e.eve_id DESC';
$arrRows = $objDatabase->fxGetResults($sql);
return is_array($arrRows) ? $arrRows : array();

View File

@ -156,11 +156,19 @@ function fxFicheAuditAdminRenderPage($strFlash = '', $strError = '')
<?php if (!$blnTablesOk) { ?>
<p class="text-muted mb-0">Tables absentes — impossible d'afficher les logs.</p>
<?php } else { ?>
<form method="get" action="fiche_audit.php" class="form-row align-items-end">
<form method="get" action="fiche_audit.php" class="form-row align-items-end" id="form-fiche-audit-logs">
<input type="hidden" name="voir_logs" value="1">
<div class="form-group col-md-6 mb-2">
<div class="form-group col-md-7 mb-2">
<label for="eve_id_logs">Événement</label>
<select class="form-control" id="eve_id_logs" name="eve_id" required>
<select class="form-control selectpicker"
id="eve_id_logs"
name="eve_id"
data-live-search="true"
data-size="12"
data-width="100%"
data-none-results-text="Aucun événement pour {0}"
title="Rechercher un événement…"
required>
<option value="">— choisir —</option>
<?php foreach ($arrEvents as $arrEve) {
$intEveOpt = intval($arrEve['eve_id'] ?? 0);
@ -177,22 +185,61 @@ function fxFicheAuditAdminRenderPage($strFlash = '', $strError = '')
. ($strDate !== '' && $strDate !== '0000-00-00' ? ' (' . $strDate . ')' : '')
. ' — #' . $intEveOpt
. ($intNb > 0 ? ' · ' . $intNb . ' log(s)' : '');
// data-tokens : recherche aussi par #id / numéro
$strTokens = $strNomEve . ' ' . $intEveOpt;
?>
<option value="<?= $intEveOpt ?>"<?= $intEveLogs === $intEveOpt ? ' selected' : '' ?>>
<option value="<?= $intEveOpt ?>"
data-tokens="<?= htmlspecialchars($strTokens, ENT_QUOTES, 'UTF-8') ?>"
<?= $intEveLogs === $intEveOpt ? ' selected' : '' ?>>
<?= htmlspecialchars($strLabel, ENT_QUOTES, 'UTF-8') ?>
</option>
<?php } ?>
</select>
<small class="form-text text-muted">Tape un nom ou un #id pour filtrer la liste.</small>
</div>
<div class="form-group col-md-6 mb-2">
<button type="submit" name="limit" value="100" class="btn btn-outline-primary mr-2">
100 derniers
<div class="form-group col-md-2 mb-2">
<label for="eve_id_direct">ou # eve_id</label>
<input type="number" class="form-control" id="eve_id_direct" min="1" step="1"
placeholder="ex. 1234"
value="<?= $intEveLogs > 0 ? intval($intEveLogs) : '' ?>">
</div>
<div class="form-group col-md-3 mb-2">
<button type="submit" name="limit" value="100" class="btn btn-outline-primary mr-1">
100
</button>
<button type="submit" name="limit" value="200" class="btn btn-outline-primary">
200 derniers
200
</button>
</div>
</form>
<script>
(function ($) {
if (!$) { return; }
$(function () {
var $sel = $('#eve_id_logs');
var $direct = $('#eve_id_direct');
var $form = $('#form-fiche-audit-logs');
if ($sel.length && $.fn.selectpicker) {
$sel.selectpicker({ liveSearch: true, size: 12 });
}
function syncDirectToSelect() {
var n = parseInt($direct.val(), 10) || 0;
if (n <= 0) { return; }
if ($sel.find('option[value="' + n + '"]').length === 0) {
$sel.append($('<option>', { value: n, text: 'Événement #' + n }));
}
$sel.val(String(n));
if ($sel.data('selectpicker')) {
$sel.selectpicker('refresh');
}
}
$direct.on('change blur', syncDirectToSelect);
$form.on('submit', function () {
syncDirectToSelect();
});
});
})(window.jQuery);
</script>
<?php } ?>
</div>
</div>