This commit is contained in:
KONE SOREL 2026-01-19 14:05:20 +00:00
parent d923250285
commit bfcb579339

View File

@ -1,8 +1,3 @@
<?php
$_SESSION['messageFace'] = "";
?>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<div class="modal fade animate__animated animate__zoomIn" id="pop_rec_faciale" tabindex="-1" role="dialog" data-bs-backdrop="static" data-bs-keyboard="false"> <div class="modal fade animate__animated animate__zoomIn" id="pop_rec_faciale" tabindex="-1" role="dialog" data-bs-backdrop="static" data-bs-keyboard="false">
<div class="modal-dialog modal-lg modal-dialog-centered shadow-lg"> <div class="modal-dialog modal-lg modal-dialog-centered shadow-lg">
<div class="modal-content border-0"> <div class="modal-content border-0">
@ -13,7 +8,7 @@
<i class="fas fa-face-viewfinder fa-lg text-white"></i> <i class="fas fa-face-viewfinder fa-lg text-white"></i>
</div> </div>
<h5 class="modal-title fw-bold mb-0"><?= _("Reconnaissance Faciale") ?></h5> <h5 class="modal-title fw-bold mb-0"><?= _("Reconnaissance Faciale") ?></h5>
<button id="btn_close_pop_rec_faciale" type="button" class="btn-close btn-close-white ms-auto" data-bs-dismiss="modal" onclick="javascript:fiche_beneficiaire();" aria-label="Fermer"></button> <button id="btn_close_pop_rec_faciale" type="button" class="btn-close btn-close-white ms-auto" data-bs-dismiss="modal" onclick="javascript:fiche_beneficiaire();"></button>
</div> </div>
</div> </div>
@ -21,14 +16,14 @@
<div class="row g-3 mb-4"> <div class="row g-3 mb-4">
<div class="col-md-6"> <div class="col-md-6">
<button id="ebene_take_photo_face" type="button" class="btn btn-primary w-100 py-3 fw-bold shadow-sm" onclick="takephoto();"> <button id="ebene_take_photo_face" type="button" class="btn btn-primary w-100 py-3 fw-bold shadow-sm" onclick="takephoto();">
<i class="fas fa-camera me-2"></i><?= _("PRENDRE UNE PHOTO") ?> <i class="fas fa-camera me-2"></i><?= _("CAPTURER L'IMAGE") ?>
</button> </button>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<?php if ($faceRegistered == "1") : ?> <?php if ($faceRegistered == "1") : ?>
<button disabled id="ebene_confirmer_photo_face" type="button" class="btn btn-success w-100 py-3 fw-bold shadow-sm" onclick="ebene_confirmer_photo_face();"> <button disabled id="ebene_confirmer_photo_face" type="button" class="btn btn-success w-100 py-3 fw-bold shadow-sm" onclick="ebene_confirmer_photo_face();">
<i class="fas fa-check-circle me-2"></i><?= _("CONFIRMER LA PHOTO") ?> <i class="fas fa-check-circle me-2"></i><?= _("VÉRIFIER L'IDENTITÉ") ?>
</button> </button>
<?php else : ?> <?php else : ?>
<button disabled id="ebene_enregistrer_photo_face" type="button" class="btn btn-info text-white w-100 py-3 fw-bold shadow-sm" onclick="ebene_enregistrer_photo_face();"> <button disabled id="ebene_enregistrer_photo_face" type="button" class="btn btn-info text-white w-100 py-3 fw-bold shadow-sm" onclick="ebene_enregistrer_photo_face();">
@ -39,49 +34,49 @@
</div> </div>
<div class="row g-4"> <div class="row g-4">
<div class="col-md-6"> <div class="col-md-6 text-center">
<div class="text-center mb-2"> <span class="badge bg-dark px-3 py-2 rounded-pill mb-2 small fw-bold text-uppercase"><?= _("Webcam en direct") ?></span>
<span class="badge bg-dark px-3 py-2 rounded-pill small fw-bold text-uppercase"><?= _("Webcam en direct") ?></span> <div class="ratio ratio-4x3 bg-dark rounded shadow-inner overflow-hidden border border-3 border-white position-relative">
</div>
<div class="ratio ratio-4x3 bg-dark rounded shadow-inner overflow-hidden border border-3 border-white">
<video id="video_face" autoplay playsinline class="w-100 h-100 object-fit-cover"></video> <video id="video_face" autoplay playsinline class="w-100 h-100 object-fit-cover"></video>
<div class="position-absolute top-50 start-50 translate-middle border border-2 border-primary border-opacity-25 rounded-circle" style="width: 60%; height: 80%; pointer-events: none;"></div> <div class="position-absolute top-50 start-50 translate-middle border border-2 border-primary border-opacity-25 rounded-circle" style="width: 65%; height: 85%; pointer-events: none;"></div>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6 text-center">
<div class="text-center mb-2"> <span class="badge bg-secondary px-3 py-2 rounded-pill mb-2 small fw-bold text-uppercase"><?= _("Capture figée") ?></span>
<span class="badge bg-secondary px-3 py-2 rounded-pill small fw-bold text-uppercase"><?= _("Capture figée") ?></span> <div id="container_photo" class="ratio ratio-4x3 bg-white border border-3 border-white rounded shadow-inner overflow-hidden d-flex align-items-center justify-content-center position-relative">
</div>
<div class="ratio ratio-4x3 bg-white border border-3 border-white rounded shadow-inner overflow-hidden"> <div id="placeholder_icon" class="position-absolute text-muted opacity-25 text-center">
<img id="photo_face" src="" class="w-100 h-100 object-fit-cover" alt="<?= _("Photo capturée") ?>" /> <i class="fas fa-user-astronaut fa-5x"></i>
<p class="small mt-2 fw-bold text-uppercase mb-0"><?= _("En attente") ?></p>
</div>
<img id="photo_face" src="" class="w-100 h-100 object-fit-cover position-relative"
style="opacity: 0; transition: opacity 0.4s ease-in-out; z-index: 2;"
onload="this.style.opacity=1; document.getElementById('placeholder_icon').style.display='none';" />
</div> </div>
</div> </div>
</div> </div>
<form id="form_face" name="form_face" enctype="multipart/form-data" method="post" action="Fichebeneficiaire/ebeneenregistrerface"> <form id="form_face" class="visually-hidden">
<input type="hidden" id="compare_face" name="compare_face" value="<?= $faceRegistered ?>"> <input type="hidden" id="compare_face" value="<?= $faceRegistered ?>">
<input type="hidden" id="del_face" name="del_face" value="0"> <input type="hidden" id="image_face" name="image_face">
<input type="hidden" id="image_face" name="image_face" class="image-tag">
<input type="hidden" id="photo_succes" name="photo_succes" value="0">
</form> </form>
<div id="message_face" class="mt-4"> <div id="message_face" class="mt-4">
<div class="alert alert-warning mb-0 shadow-xs border-0 rounded-pill d-flex align-items-center px-4"> <div class="alert alert-warning mb-0 shadow-xs border-0 rounded-pill d-flex align-items-center px-4">
<i class="fas fa-lightbulb me-3 fa-lg text-primary"></i> <i class="fas fa-info-circle me-3 text-primary"></i>
<marquee behavior="scroll" direction="left" scrollamount="3" class="small fw-bold m-0"> <marquee behavior="scroll" direction="left" scrollamount="3" class="small fw-bold m-0">
<?= _("Positionnez votre visage au centre du cadre. Assurez-vous d'être dans un endroit bien éclairé pour une meilleure précision.") ?> <?= _("Positionnez votre visage au centre du cadre pour une détection optimale.") ?>
</marquee> </marquee>
</div> </div>
</div> </div>
<div id="div_wait_face_ebene" class="mt-3"></div>
<canvas id="canvas" style="display: none;"></canvas> <canvas id="canvas" style="display: none;"></canvas>
</div> </div>
<div class="modal-footer bg-light border-0 p-3"> <div class="modal-footer bg-light border-0 p-3">
<button id="close_poprec_faciane" type="button" class="btn btn-outline-secondary fw-bold px-4 rounded-pill" data-bs-dismiss="modal" onclick="fiche_beneficiaire();"> <button type="button" class="btn btn-outline-secondary fw-bold px-4 rounded-pill" data-bs-dismiss="modal" onclick="fiche_beneficiaire();">
<i class="fas fa-times me-2"></i><?= _("Fermer") ?> <i class="fas fa-times me-2"></i><?= _("Fermer") ?>
</button> </button>
</div> </div>
@ -91,12 +86,22 @@
</div> </div>
<style> <style>
/* Miroir pour la vidéo (plus naturel pour l'utilisateur) */ /* Styles spécifiques */
#video_face { transform: scaleX(-1); } #video_face { transform: scaleX(-1); } /* Effet miroir */
.object-fit-cover { object-fit: cover; } .object-fit-cover { object-fit: cover; }
.shadow-inner { box-shadow: inset 0 2px 10px rgba(0,0,0,0.2); } .shadow-inner { box-shadow: inset 0 2px 8px rgba(0,0,0,0.15); }
.shadow-xs { box-shadow: 0 2px 4px rgba(0,0,0,0.05); } .shadow-xs { box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
.modal-content { border-radius: 1.5rem; overflow: hidden; } .modal-content { border-radius: 1.2rem; }
/* Animation de flash lors de la capture */
.flash-effect {
animation: flash 0.4s ease-out;
}
@keyframes flash {
0% { filter: brightness(1); }
50% { filter: brightness(2); }
100% { filter: brightness(1); }
}
</style> </style>
<script type="text/javascript"> <script type="text/javascript">
@ -104,81 +109,67 @@
var canvas = document.getElementById('canvas'); var canvas = document.getElementById('canvas');
var photo = document.getElementById('photo_face'); var photo = document.getElementById('photo_face');
var image_input = document.getElementById('image_face'); var image_input = document.getElementById('image_face');
var placeholder = document.getElementById('placeholder_icon');
/** /**
* Initialisation de la caméra * Démarre la webcam
*/ */
async function initCamera() { async function initCamera() {
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { try {
try { const stream = await navigator.mediaDevices.getUserMedia({
const stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'user', width: 640, height: 480 },
video: { audio: false
facingMode: 'user', });
width: { ideal: 1280 }, video.srcObject = stream;
height: { ideal: 720 } } catch (err) {
}, console.error("Caméra inaccessible:", err);
audio: false alert("Erreur : Impossible d'accéder à la caméra.");
});
video.srcObject = stream;
} catch (err) {
console.error("Erreur caméra:", err);
alert("Impossible d'accéder à la caméra. Vérifiez les autorisations.");
}
} }
} }
/** /**
* Capture de la photo * Prend la photo
*/ */
function takephoto() { function takephoto() {
// Effacer les anciens messages
$("#div_wait_face_ebene").html('');
// Configurer le canvas selon la source vidéo réelle
var context = canvas.getContext('2d'); var context = canvas.getContext('2d');
canvas.width = video.videoWidth; canvas.width = video.videoWidth;
canvas.height = video.videoHeight; canvas.height = video.videoHeight;
// Dessiner l'image // Capture
context.drawImage(video, 0, 0, canvas.width, canvas.height); context.drawImage(video, 0, 0, canvas.width, canvas.height);
// Extraire en Base64
var data = canvas.toDataURL('image/jpeg', 0.8); var data = canvas.toDataURL('image/jpeg', 0.8);
// Mettre à jour l'aperçu et le champ caché // Mise à jour de l'image (l'événement onload du HTML gère l'icône)
photo.setAttribute('src', data); photo.src = data;
image_input.value = data; image_input.value = data;
// Gestion des boutons // Effet visuel
var faceRegistered = $("#compare_face").val(); document.getElementById('container_photo').classList.add('flash-effect');
setTimeout(() => document.getElementById('container_photo').classList.remove('flash-effect'), 400);
// Débloquer les boutons
var isRegistered = document.getElementById('compare_face').value;
$("#ebene_enregistrer_photo_face").prop('disabled', false); $("#ebene_enregistrer_photo_face").prop('disabled', false);
if(isRegistered === "1") {
if(faceRegistered === "1") {
$("#ebene_confirmer_photo_face").prop('disabled', false); $("#ebene_confirmer_photo_face").prop('disabled', false);
} }
// Effet visuel de flash
photo.parentElement.classList.add('animate__animated', 'animate__flash');
setTimeout(() => {
photo.parentElement.classList.remove('animate__animated', 'animate__flash');
}, 500);
} }
// Gestionnaires d'événements pour la modal Bootstrap 5 // Gestion de la modal Bootstrap
var myModalEl = document.getElementById('pop_rec_faciale'); var faceModal = document.getElementById('pop_rec_faciale');
// Allumer la caméra quand la modal s'affiche faceModal.addEventListener('shown.bs.modal', function () {
myModalEl.addEventListener('shown.bs.modal', function () {
initCamera(); initCamera();
}); });
// Éteindre la caméra quand on ferme la modal (important !) faceModal.addEventListener('hidden.bs.modal', function () {
myModalEl.addEventListener('hidden.bs.modal', function () {
if (video.srcObject) { if (video.srcObject) {
const tracks = video.srcObject.getTracks(); video.srcObject.getTracks().forEach(track => track.stop());
tracks.forEach(track => track.stop());
video.srcObject = null; video.srcObject = null;
} }
// Reset de l'aperçu si on ferme
photo.src = "";
photo.style.opacity = 0;
placeholder.style.display = 'block';
}); });
</script> </script>