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-dialog modal-lg modal-dialog-centered shadow-lg">
<div class="modal-content border-0">
@ -13,7 +8,7 @@
<i class="fas fa-face-viewfinder fa-lg text-white"></i>
</div>
<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>
@ -21,14 +16,14 @@
<div class="row g-3 mb-4">
<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();">
<i class="fas fa-camera me-2"></i><?= _("PRENDRE UNE PHOTO") ?>
<i class="fas fa-camera me-2"></i><?= _("CAPTURER L'IMAGE") ?>
</button>
</div>
<div class="col-md-6">
<?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();">
<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>
<?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();">
@ -39,49 +34,49 @@
</div>
<div class="row g-4">
<div class="col-md-6">
<div class="text-center mb-2">
<span class="badge bg-dark px-3 py-2 rounded-pill small fw-bold text-uppercase"><?= _("Webcam en direct") ?></span>
</div>
<div class="ratio ratio-4x3 bg-dark rounded shadow-inner overflow-hidden border border-3 border-white">
<div class="col-md-6 text-center">
<span class="badge bg-dark px-3 py-2 rounded-pill mb-2 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">
<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 class="col-md-6">
<div class="text-center mb-2">
<span class="badge bg-secondary px-3 py-2 rounded-pill small fw-bold text-uppercase"><?= _("Capture figée") ?></span>
</div>
<div class="ratio ratio-4x3 bg-white border border-3 border-white rounded shadow-inner overflow-hidden">
<img id="photo_face" src="" class="w-100 h-100 object-fit-cover" alt="<?= _("Photo capturée") ?>" />
<div class="col-md-6 text-center">
<span class="badge bg-secondary px-3 py-2 rounded-pill mb-2 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 id="placeholder_icon" class="position-absolute text-muted opacity-25 text-center">
<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>
<form id="form_face" name="form_face" enctype="multipart/form-data" method="post" action="Fichebeneficiaire/ebeneenregistrerface">
<input type="hidden" id="compare_face" name="compare_face" value="<?= $faceRegistered ?>">
<input type="hidden" id="del_face" name="del_face" value="0">
<input type="hidden" id="image_face" name="image_face" class="image-tag">
<input type="hidden" id="photo_succes" name="photo_succes" value="0">
<form id="form_face" class="visually-hidden">
<input type="hidden" id="compare_face" value="<?= $faceRegistered ?>">
<input type="hidden" id="image_face" name="image_face">
</form>
<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">
<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">
<?= _("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>
</div>
</div>
<div id="div_wait_face_ebene" class="mt-3"></div>
<canvas id="canvas" style="display: none;"></canvas>
</div>
<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") ?>
</button>
</div>
@ -91,12 +86,22 @@
</div>
<style>
/* Miroir pour la vidéo (plus naturel pour l'utilisateur) */
#video_face { transform: scaleX(-1); }
/* Styles spécifiques */
#video_face { transform: scaleX(-1); } /* Effet miroir */
.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); }
.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>
<script type="text/javascript">
@ -104,81 +109,67 @@
var canvas = document.getElementById('canvas');
var photo = document.getElementById('photo_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() {
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
try {
const stream = await navigator.mediaDevices.getUserMedia({
video: {
facingMode: 'user',
width: { ideal: 1280 },
height: { ideal: 720 }
},
audio: false
});
video.srcObject = stream;
} catch (err) {
console.error("Erreur caméra:", err);
alert("Impossible d'accéder à la caméra. Vérifiez les autorisations.");
}
try {
const stream = await navigator.mediaDevices.getUserMedia({
video: { facingMode: 'user', width: 640, height: 480 },
audio: false
});
video.srcObject = stream;
} catch (err) {
console.error("Caméra inaccessible:", err);
alert("Erreur : Impossible d'accéder à la caméra.");
}
}
/**
* Capture de la photo
* Prend la photo
*/
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');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
// Dessiner l'image
// Capture
context.drawImage(video, 0, 0, canvas.width, canvas.height);
// Extraire en Base64
var data = canvas.toDataURL('image/jpeg', 0.8);
// Mettre à jour l'aperçu et le champ caché
photo.setAttribute('src', data);
// Mise à jour de l'image (l'événement onload du HTML gère l'icône)
photo.src = data;
image_input.value = data;
// Gestion des boutons
var faceRegistered = $("#compare_face").val();
$("#ebene_enregistrer_photo_face").prop('disabled', false);
// Effet visuel
document.getElementById('container_photo').classList.add('flash-effect');
setTimeout(() => document.getElementById('container_photo').classList.remove('flash-effect'), 400);
if(faceRegistered === "1") {
// Débloquer les boutons
var isRegistered = document.getElementById('compare_face').value;
$("#ebene_enregistrer_photo_face").prop('disabled', false);
if(isRegistered === "1") {
$("#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
var myModalEl = document.getElementById('pop_rec_faciale');
// Gestion de la modal Bootstrap
var faceModal = document.getElementById('pop_rec_faciale');
// Allumer la caméra quand la modal s'affiche
myModalEl.addEventListener('shown.bs.modal', function () {
faceModal.addEventListener('shown.bs.modal', function () {
initCamera();
});
// Éteindre la caméra quand on ferme la modal (important !)
myModalEl.addEventListener('hidden.bs.modal', function () {
faceModal.addEventListener('hidden.bs.modal', function () {
if (video.srcObject) {
const tracks = video.srcObject.getTracks();
tracks.forEach(track => track.stop());
video.srcObject.getTracks().forEach(track => track.stop());
video.srcObject = null;
}
// Reset de l'aperçu si on ferme
photo.src = "";
photo.style.opacity = 0;
placeholder.style.display = 'block';
});
</script>